1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#define PLOG_MESSAGE_PREFIX ""
#include "Common.h"
SCENARIO("message prefix")
{
GIVEN("logger is initialised")
{
plog::TestAppender testAppender;
plog::Logger<PLOG_DEFAULT_INSTANCE_ID> logger(plog::info);
logger.addAppender(&testAppender);
WHEN("set PLOG_MESSAGE_PREFIX and print a message")
{
#undef PLOG_MESSAGE_PREFIX
#define PLOG_MESSAGE_PREFIX "[test] "
PLOGI << "message";
THEN("the message is printed with the prefix")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[test] message"));
}
}
WHEN("set PLOG_MESSAGE_PREFIX to an empty string and print a message")
{
#undef PLOG_MESSAGE_PREFIX
#define PLOG_MESSAGE_PREFIX ""
PLOGI << "message";
THEN("the message is printed without the prefix as it's empty")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("message"));
}
}
}
GIVEN("logger is initialised and PLOG_MESSAGE_PREFIX is set to a variable")
{
plog::TestAppender testAppender;
plog::Logger<PLOG_DEFAULT_INSTANCE_ID> logger(plog::info);
logger.addAppender(&testAppender);
#undef PLOG_MESSAGE_PREFIX
#define PLOG_MESSAGE_PREFIX plogPrefix
std::string plogPrefix = "[value] ";
WHEN("print a message")
{
PLOGI << "message";
THEN("the message is printed with the prefix")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[value] message"));
}
AND_WHEN("change the variable and print a new message")
{
plogPrefix = "***";
PLOGI << "new message";
THEN("the new message is printed with the new prefix")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("***new message"));
}
}
}
}
}
|