Skip to content

Commit

Permalink
Adding unittest for unformatted message
Browse files Browse the repository at this point in the history
  • Loading branch information
noizebox committed Mar 22, 2024
1 parent 0179cb4 commit 0196aeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions include/elklog/rtlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class RtLogger
template<typename... Args>
void log_debug(spdlog::format_string_t<Args...> format_str, Args&&... args)
{
log<RtLogLevel::DBG>(format_str, args...);
log<RtLogLevel::DBG>(format_str, std::forward<Args>(args)...);
}

void log_debug(spdlog::string_view_t msg)
Expand All @@ -138,7 +138,7 @@ class RtLogger
template<typename... Args>
void log_info(spdlog::format_string_t<Args...> format_str, Args&&... args)
{
log<RtLogLevel::INFO>(format_str, args...);
log<RtLogLevel::INFO>(format_str, std::forward<Args>(args)...);
}

void log_info(spdlog::string_view_t msg)
Expand All @@ -160,7 +160,7 @@ class RtLogger
template<typename... Args>
void log_error(spdlog::format_string_t<Args...> format_str, Args&&... args)
{
log<RtLogLevel::ERROR>(format_str, args...);
log<RtLogLevel::ERROR>(format_str, std::forward<Args>(args)...);
}

void log_error(spdlog::string_view_t msg)
Expand Down
14 changes: 13 additions & 1 deletion test/unittests/rtlogmessage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(RtLogMessageTest, TestCreation)
ASSERT_STREQ("", module_under_test.message());
}

TEST(RtLogMessageTest, TestCopyingAndAssignment)
TEST(RtLogMessageTest, TestCopyingAndAssignmentFormatted)
{
RtLogMessage<512> module_under_test;

Expand All @@ -33,6 +33,18 @@ TEST(RtLogMessageTest, TestCopyingAndAssignment)
EXPECT_STREQ(module_under_test.message(), msg_2.message());
}

TEST(RtLogMessageTest, TestCopyingAndAssignment)
{
RtLogMessage<512> module_under_test;

module_under_test.set_message(RtLogLevel::INFO, std::chrono::nanoseconds(456), "Test single message");

EXPECT_STREQ("Test single message", module_under_test.message());
EXPECT_EQ(std::chrono::nanoseconds(456), module_under_test.timestamp());
EXPECT_EQ(RtLogLevel::INFO, module_under_test.level());
EXPECT_EQ(20, module_under_test.length());
}

TEST(RtLogMessageTest, TestMaxSize)
{
RtLogMessage<24> module_under_test;
Expand Down

0 comments on commit 0196aeb

Please sign in to comment.