From 90454a93b215032964bb72756ecae4ed711e19b7 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 10 Feb 2020 00:37:48 +0200 Subject: [PATCH] Update test_eventlog.cpp --- tests/test_eventlog.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_eventlog.cpp b/tests/test_eventlog.cpp index a8e06255..4a3d3fce 100644 --- a/tests/test_eventlog.cpp +++ b/tests/test_eventlog.cpp @@ -1,20 +1,17 @@ #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 do_print, std::string const& expectedContents, WORD expectedEventType) +static void test_single_print(std::function do_log, std::string const& expected_contents, WORD expected_ev_type) { - do_print(expectedContents); - using namespace std::chrono; - const auto expectedTimeGenerated = duration_cast(system_clock::now().time_since_epoch()).count(); + do_log(expected_contents); + const auto expected_time_generated = duration_cast(system_clock::now().time_since_epoch()).count(); struct handle_t { @@ -23,29 +20,31 @@ static void test_single_print(std::function do_print, ~handle_t() { if (handle_) + { REQUIRE(CloseEventLog(handle_)); + } } - } eventLog {OpenEventLog(nullptr, TEST_SOURCE)}; + } event_log {::OpenEventLog(nullptr, TEST_SOURCE)}; - REQUIRE(eventLog.handle_); + REQUIRE(event_log.handle_); - DWORD readBytes {}, sizeNeeded {}; - auto ok = ReadEventLog(eventLog.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &readBytes, 0, &readBytes, &sizeNeeded); + DWORD read_bytes {}, size_needed{}; + auto ok = ::ReadEventLog(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0, &read_bytes, &size_needed); REQUIRE(!ok); - REQUIRE(GetLastError() == ERROR_INSUFFICIENT_BUFFER); + REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER); - std::vector recordBuffer(sizeNeeded); - PEVENTLOGRECORD record = (PEVENTLOGRECORD)recordBuffer.data(); + std::vector record_buffer(size_needed); + PEVENTLOGRECORD record = (PEVENTLOGRECORD)record_buffer.data(); - ok = ReadEventLog(eventLog.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, record, sizeNeeded, &readBytes, &sizeNeeded); + ok = ::ReadEventLog(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, record, size_needed, &read_bytes, &size_needed); REQUIRE(ok); REQUIRE(record->NumStrings == 1); - REQUIRE(record->EventType == expectedEventType); - REQUIRE(record->TimeGenerated == expectedTimeGenerated); + REQUIRE(record->EventType == expected_ev_type); + REQUIRE(record->TimeGenerated == expected_time_generated); std::string message_in_log(((char*) record + record->StringOffset)); - REQUIRE(message_in_log == expectedContents + "\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);