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
90454a93
Commit
90454a93
authored
Feb 10, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update test_eventlog.cpp
parent
640921cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
tests/test_eventlog.cpp
tests/test_eventlog.cpp
+18
-18
No files found.
tests/test_eventlog.cpp
View file @
90454a93
#include "includes.h"
#include "test_sink.h"
#include "spdlog/fmt/bin_to_hex.h"
#if _WIN32
#include "spdlog/sinks/win_eventlog_sink.h"
static
const
LPCSTR
TEST_LOG
=
"my log"
;
static
const
LPCSTR
TEST_SOURCE
=
"my source"
;
static
const
LPCSTR
TEST_SOURCE
=
"spdlog_test"
;
static
void
test_single_print
(
std
::
function
<
void
(
std
::
string
const
&
)
>
do_
print
,
std
::
string
const
&
expectedContents
,
WORD
expectedEventT
ype
)
static
void
test_single_print
(
std
::
function
<
void
(
std
::
string
const
&
)
>
do_
log
,
std
::
string
const
&
expected_contents
,
WORD
expected_ev_t
ype
)
{
do_print
(
expectedContents
);
using
namespace
std
::
chrono
;
const
auto
expectedTimeGenerated
=
duration_cast
<
seconds
>
(
system_clock
::
now
().
time_since_epoch
()).
count
();
do_log
(
expected_contents
);
const
auto
expected_time_generated
=
duration_cast
<
seconds
>
(
system_clock
::
now
().
time_since_epoch
()).
count
();
struct
handle_t
{
...
...
@@ -23,29 +20,31 @@ static void test_single_print(std::function<void(std::string const&)> do_print,
~
handle_t
()
{
if
(
handle_
)
{
REQUIRE
(
CloseEventLog
(
handle_
));
}
}
}
event
Log
{
OpenEventLog
(
nullptr
,
TEST_SOURCE
)};
}
event
_log
{
::
OpenEventLog
(
nullptr
,
TEST_SOURCE
)};
REQUIRE
(
event
L
og
.
handle_
);
REQUIRE
(
event
_l
og
.
handle_
);
DWORD
read
Bytes
{},
sizeNeeded
{};
auto
ok
=
ReadEventLog
(
eventLog
.
handle_
,
EVENTLOG_SEQUENTIAL_READ
|
EVENTLOG_BACKWARDS_READ
,
0
,
&
readBytes
,
0
,
&
readBytes
,
&
sizeN
eeded
);
DWORD
read
_bytes
{},
size_needed
{};
auto
ok
=
::
ReadEventLog
(
event_log
.
handle_
,
EVENTLOG_SEQUENTIAL_READ
|
EVENTLOG_BACKWARDS_READ
,
0
,
&
read_bytes
,
0
,
&
read_bytes
,
&
size_n
eeded
);
REQUIRE
(
!
ok
);
REQUIRE
(
GetLastError
()
==
ERROR_INSUFFICIENT_BUFFER
);
REQUIRE
(
::
GetLastError
()
==
ERROR_INSUFFICIENT_BUFFER
);
std
::
vector
<
char
>
record
Buffer
(
sizeN
eeded
);
PEVENTLOGRECORD
record
=
(
PEVENTLOGRECORD
)
record
B
uffer
.
data
();
std
::
vector
<
char
>
record
_buffer
(
size_n
eeded
);
PEVENTLOGRECORD
record
=
(
PEVENTLOGRECORD
)
record
_b
uffer
.
data
();
ok
=
ReadEventLog
(
eventLog
.
handle_
,
EVENTLOG_SEQUENTIAL_READ
|
EVENTLOG_BACKWARDS_READ
,
0
,
record
,
sizeNeeded
,
&
readBytes
,
&
sizeN
eeded
);
ok
=
::
ReadEventLog
(
event_log
.
handle_
,
EVENTLOG_SEQUENTIAL_READ
|
EVENTLOG_BACKWARDS_READ
,
0
,
record
,
size_needed
,
&
read_bytes
,
&
size_n
eeded
);
REQUIRE
(
ok
);
REQUIRE
(
record
->
NumStrings
==
1
);
REQUIRE
(
record
->
EventType
==
expected
EventT
ype
);
REQUIRE
(
record
->
TimeGenerated
==
expected
TimeG
enerated
);
REQUIRE
(
record
->
EventType
==
expected
_ev_t
ype
);
REQUIRE
(
record
->
TimeGenerated
==
expected
_time_g
enerated
);
std
::
string
message_in_log
(((
char
*
)
record
+
record
->
StringOffset
));
REQUIRE
(
message_in_log
==
expected
Contents
+
"
\r\n
"
);
REQUIRE
(
message_in_log
==
expected
_contents
+
spdlog
::
details
::
os
::
default_eol
);
}
TEST_CASE
(
"eventlog"
,
"[eventlog]"
)
...
...
@@ -59,6 +58,7 @@ TEST_CASE("eventlog", "[eventlog]")
test_sink
->
set_pattern
(
"%v"
);
test_single_print
([
&
test_logger
]
(
std
::
string
const
&
msg
)
{
test_logger
.
trace
(
msg
);
},
"my trace message"
,
EVENTLOG_SUCCESS
);
test_single_print
([
&
test_logger
]
(
std
::
string
const
&
msg
)
{
test_logger
.
debug
(
msg
);
},
"my debug message"
,
EVENTLOG_SUCCESS
);
test_single_print
([
&
test_logger
]
(
std
::
string
const
&
msg
)
{
test_logger
.
info
(
msg
);
},
"my info message"
,
EVENTLOG_INFORMATION_TYPE
);
test_single_print
([
&
test_logger
]
(
std
::
string
const
&
msg
)
{
test_logger
.
warn
(
msg
);
},
"my warn message"
,
EVENTLOG_WARNING_TYPE
);
...
...
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