29 #include <gtest/gtest.h>
57 "Exclusive debug flag for the trace tests");
65 auto buf =
os.rdbuf();
66 std::ostringstream oss;
79 TEST(TraceTest, LogSimpleMessage)
85 ASSERT_EQ(
getString(&logger),
" 100: Test message");
89 TEST(TraceTest, LogMessageName)
95 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
99 TEST(TraceTest, LogMessageMaxTick)
101 std::stringstream
ss;
105 ASSERT_EQ(
getString(&logger),
"Foo: Test message");
109 TEST(TraceTest, LogMessageFlagDisabled)
111 std::stringstream
ss;
115 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
122 TEST(TraceTest, LogMessageTickDisabledAndEnableDisable)
124 std::stringstream
ss;
128 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
135 ASSERT_EQ(
getString(&logger),
"Foo: Test message");
137 ASSERT_EQ(
getString(&logger),
" 200: Foo: Test message");
144 ASSERT_EQ(
getString(&logger),
" 300: Foo: Test message");
151 TEST(TraceTest, LogMessageFlagEnabled)
153 std::stringstream
ss;
160 ASSERT_EQ(
getString(&logger),
" 100: Bar: Foo: Test message");
162 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
170 TEST(TraceTest, LogMessageIgnoreOne)
172 std::stringstream
ss;
183 ASSERT_EQ(
getString(&logger),
" 100: Bar: Test message");
188 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
194 TEST(TraceTest, LogMessageIgnoreMultiple)
196 std::stringstream
ss;
211 ASSERT_EQ(
getString(&logger),
" 100: Thy: Test message");
217 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
219 ASSERT_EQ(
getString(&logger),
" 100: Bar: Test message");
227 std::stringstream
ss;
232 std::string message =
"Test message";
233 logger.
dump(
Tick(100),
"Foo", message.c_str(), message.size(),
"");
246 std::stringstream
ss;
251 std::string message =
"Test message";
252 logger.
dump(
Tick(100),
"Foo", message.c_str(), message.size(),
"Bar");
260 "54 65 73 74 20 6d 65 73 73 61 67 65 "
270 "54 65 73 74 20 6d 65 73 73 61 67 65 "
284 std::stringstream
ss;
287 std::string message =
288 "This is a very long line that will span over multiple lines";
289 logger.
dump(
Tick(100),
"Foo", message.c_str(), message.size(),
"");
291 " 100: Foo: 00000000 "
292 "54 68 69 73 20 69 73 20 61 20 76 65 72 79 20 6c This is a very l\n"
293 " 100: Foo: 00000010 "
294 "6f 6e 67 20 6c 69 6e 65 20 74 68 61 74 20 77 69 ong line that wi\n"
295 " 100: Foo: 00000020 "
296 "6c 6c 20 73 70 61 6e 20 6f 76 65 72 20 6d 75 6c ll span over mul\n"
297 " 100: Foo: 00000030 "
298 "74 69 70 6c 65 20 6c 69 6e 65 73 tiple lines\n");
305 TEST(TraceTest, DISABLED_GetNullLogger)
308 ASSERT_FALSE(logger ==
nullptr);
327 ASSERT_EQ(
getString(logger_from_getter),
" 100: Foo: Test message");
338 TEST(TraceTest, DprintfFlagIgnore)
340 std::stringstream
ss;
350 TEST(TraceTest, DprintfFlagZeroArgs)
352 std::stringstream
ss;
356 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
360 TEST(TraceTest, DprintfFlagOneArg)
362 std::stringstream
ss;
366 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
370 TEST(TraceTest, DprintfFlagMultipleArgs)
372 std::stringstream
ss;
376 "message",
'A', 217, 0x30);
377 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message A 217 30");
381 TEST(TraceTest, DprintfFlagEnabled)
383 std::stringstream
ss;
390 ASSERT_EQ(
getString(&logger),
" 100: Bar: Foo: Test message");
392 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
401 std::stringstream
ss;
411 TEST(TraceTest, DprintfEnabled)
413 std::stringstream
ss;
418 logger.
dprintf(
Tick(100),
"Foo",
"Test %s",
"message");
419 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
425 TEST(TraceTest, DprintfWrapper)
427 std::stringstream
ss, ss_flag;
431 logger.
dprintf(
Tick(100),
"Foo",
"Test %s %c %d %x",
432 "message",
'A', 217, 0x30);
434 "message",
'A', 217, 0x30);
442 std::string message =
"Test message";
451 " 0: TraceTestDebugFlag: Foo: 00000000 "
452 "54 65 73 74 20 6d 65 73 73 61 67 65 Test message\n");
476 " 0: TraceTestDebugFlag: Foo: Test message");
493 Named *named_ptr = &named;
503 " 0: TraceTestDebugFlag: Foo: Test message");
549 TEST(TraceTest, MacroDPRINTFNR)
560 TEST(TraceTest, MacroDPRINTF_UNCONDITIONAL)
571 " 0: TraceTestDebugFlag: Foo: Test message");
600 " 0: TraceTestDebugFlag: global: Test message");