30 TEST_CASE(
"The Logger level can be set and retrieved with the static 'level' " 35 for (
unsigned int i = 0; i <= 10; i++)
45 TEST_CASE(
"The Logger can log to stdout with the static 'log' method if the " 46 " logger's level is the same or higher than the loglevel of the " 47 "message.",
"[Logger]")
50 SECTION(
"No message can be logged if the logger's level is 0.")
54 REQUIRE(mock_cout.
buffer().empty());
57 REQUIRE(mock_cout.
buffer().empty());
59 SECTION(
"The default level of the 'log' method is 1.")
63 REQUIRE(mock_cout.
buffer().empty());
66 REQUIRE(mock_cout.
buffer().substr(21) ==
"a log message\n");
69 REQUIRE(mock_cout.
buffer().substr(21) ==
"another log message\n");
71 SECTION(
"A level of 0 will be changed to level 1.")
75 REQUIRE(mock_cout.
buffer().empty());
78 REQUIRE(mock_cout.
buffer().substr(21) ==
"a log message\n");
81 REQUIRE(mock_cout.
buffer().substr(21) ==
"another log message\n");
83 SECTION(
"The level can be set from 1 to 65535.")
87 REQUIRE(mock_cout.
buffer().empty());
90 REQUIRE(mock_cout.
buffer().substr(21) ==
"a log message\n");
93 REQUIRE(mock_cout.
buffer().substr(21) ==
"another log message\n");
99 TEST_CASE(
"All logged messages have a timestamp (this can sometimes fail if " 100 "the clock ticks over a second during the test).",
"[Logger]")
104 auto t = std::time(
nullptr);
105 auto tm = *std::localtime(&t);
109 str(std::put_time(&tm,
"%Y-%m-%d %H:%M:%S")) +
110 " timestamped log message\n");
std::string str(const T &object)
static void log(std::string message)
static unsigned int level()
TEST_CASE("The Logger level can be set and retrieved with the static 'level' " "method", "[Logger]")