Skip to content

Commit

Permalink
Add new tests for Logger::Logv(). (#13)
Browse files Browse the repository at this point in the history
A leftover task from #12 - add a
test.
  • Loading branch information
atsushieno authored Oct 4, 2024
1 parent 5774ba0 commit c440a89
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/test_rtlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ TEST_CASE("va_args works as intended")
{
rtlog::Logger<ExampleLogData, MAX_NUM_LOG_MESSAGES, MAX_LOG_MESSAGE_LENGTH, gSequenceNumber> logger;

logger.Log({ExampleLogLevel::Debug, ExampleLogRegion::Engine}, "Hello, %lu!", 123l);
logger.Log({ExampleLogLevel::Debug, ExampleLogRegion::Engine}, "Hello, %lu!", 123l);
logger.Log({ExampleLogLevel::Info, ExampleLogRegion::Game}, "Hello, %f!", 123.0f);
logger.Log({ExampleLogLevel::Warning, ExampleLogRegion::Network}, "Hello, %lf!", 123.0);
logger.Log({ExampleLogLevel::Critical, ExampleLogRegion::Audio}, "Hello, %p!", (void*)123);
Expand All @@ -112,6 +112,28 @@ TEST_CASE("va_args works as intended")
CHECK(logger.PrintAndClearLogQueue(PrintMessage) == 6);
}

void vaArgsTest(rtlog::Logger<ExampleLogData, MAX_NUM_LOG_MESSAGES, MAX_LOG_MESSAGE_LENGTH, gSequenceNumber>& logger, ExampleLogData&& data, const char* format, ...)
{
va_list args;
va_start(args, format);
logger.Logv(std::move(data), format, args);
va_end(args);
}

TEST_CASE("Logv version works as well")
{
rtlog::Logger<ExampleLogData, MAX_NUM_LOG_MESSAGES, MAX_LOG_MESSAGE_LENGTH, gSequenceNumber> logger;

vaArgsTest(logger, {ExampleLogLevel::Debug, ExampleLogRegion::Engine}, "Hello, %lu!", 123l);
vaArgsTest(logger, {ExampleLogLevel::Info, ExampleLogRegion::Game}, "Hello, %f!", 123.0f);
vaArgsTest(logger, {ExampleLogLevel::Warning, ExampleLogRegion::Network}, "Hello, %lf!", 123.0);
vaArgsTest(logger, {ExampleLogLevel::Critical, ExampleLogRegion::Audio}, "Hello, %p!", (void*)123);
vaArgsTest(logger, {ExampleLogLevel::Debug, ExampleLogRegion::Engine}, "Hello, %d!", 123);
vaArgsTest(logger, {ExampleLogLevel::Critical, ExampleLogRegion::Audio}, "Hello, %s!", "world");

CHECK(logger.PrintAndClearLogQueue(PrintMessage) == 6);
}

TEST_CASE("LoggerThread does it's job")
{
rtlog::Logger<ExampleLogData, MAX_NUM_LOG_MESSAGES, MAX_LOG_MESSAGE_LENGTH, gSequenceNumber> logger;
Expand Down

0 comments on commit c440a89

Please sign in to comment.