Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
3d420a3b
Commit
3d420a3b
authored
Dec 13, 2015
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests refactoring
parent
6feaa29c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
43 deletions
+46
-43
tests/file_helper.cpp
tests/file_helper.cpp
+1
-10
tests/file_log.cpp
tests/file_log.cpp
+0
-33
tests/utils.cpp
tests/utils.cpp
+34
-0
tests/utils.h
tests/utils.h
+11
-0
No files found.
tests/file_helper.cpp
View file @
3d420a3b
...
...
@@ -7,15 +7,6 @@ using namespace spdlog::details;
static
const
std
::
string
filename
=
"logs/file_helper_test.txt"
;
size_t
filesize2
(
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
,
std
::
ifstream
::
ate
|
std
::
ifstream
::
binary
);
if
(
!
ifs
)
throw
std
::
runtime_error
(
"Failed open file "
);
return
(
size_t
)
ifs
.
tellg
();
}
static
void
write_with_helper
(
file_helper
&
helper
,
size_t
howmany
)
{
log_msg
msg
;
...
...
@@ -45,7 +36,7 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]")
write_with_helper
(
helper
,
expected_size
);
REQUIRE
(
helper
.
size
()
==
expected_size
);
}
REQUIRE
(
filesize
2
(
filename
)
==
expected_size
);
REQUIRE
(
filesize
(
filename
)
==
expected_size
);
}
...
...
tests/file_log.cpp
View file @
3d420a3b
...
...
@@ -3,39 +3,6 @@
*/
#include "includes.h"
static
std
::
string
file_contents
(
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
);
if
(
!
ifs
)
throw
std
::
runtime_error
(
"Failed open file "
);
return
std
::
string
((
std
::
istreambuf_iterator
<
char
>
(
ifs
)),
(
std
::
istreambuf_iterator
<
char
>
()));
}
static
std
::
size_t
count_lines
(
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
);
if
(
!
ifs
)
throw
std
::
runtime_error
(
"Failed open file "
);
std
::
string
line
;
size_t
counter
=
0
;
while
(
std
::
getline
(
ifs
,
line
))
counter
++
;
return
counter
;
}
std
::
ifstream
::
pos_type
filesize
(
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
,
std
::
ifstream
::
ate
|
std
::
ifstream
::
binary
);
if
(
!
ifs
)
throw
std
::
runtime_error
(
"Failed open file "
);
return
ifs
.
tellg
();
}
TEST_CASE
(
"simple_file_logger"
,
"[simple_logger]]"
)
{
...
...
tests/utils.cpp
View file @
3d420a3b
...
...
@@ -9,3 +9,37 @@ void prepare_logdir()
auto
rv
=
system
(
"rm -f logs/*"
);
#endif
}
std
::
string
file_contents
(
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
);
if
(
!
ifs
)
throw
std
::
runtime_error
(
"Failed open file "
);
return
std
::
string
((
std
::
istreambuf_iterator
<
char
>
(
ifs
)),
(
std
::
istreambuf_iterator
<
char
>
()));
}
std
::
size_t
count_lines
(
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
);
if
(
!
ifs
)
throw
std
::
runtime_error
(
"Failed open file "
);
std
::
string
line
;
size_t
counter
=
0
;
while
(
std
::
getline
(
ifs
,
line
))
counter
++
;
return
counter
;
}
std
::
ifstream
::
pos_type
filesize
(
const
std
::
string
&
filename
)
{
std
::
ifstream
ifs
(
filename
,
std
::
ifstream
::
ate
|
std
::
ifstream
::
binary
);
if
(
!
ifs
)
throw
std
::
runtime_error
(
"Failed open file "
);
return
ifs
.
tellg
();
}
tests/utils.h
View file @
3d420a3b
#pragma once
#include <string>
#include<cstddef>
std
::
size_t
count_lines
(
const
std
::
string
&
filename
);
void
prepare_logdir
();
std
::
string
file_contents
(
const
std
::
string
&
filename
);
std
::
size_t
count_lines
(
const
std
::
string
&
filename
);
std
::
ifstream
::
pos_type
filesize
(
const
std
::
string
&
filename
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment