Belle II Software  release-05-02-19
logging.cc
1 #include <framework/logging/Logger.h>
2 #include <framework/logging/LogMethod.h>
3 #include <framework/utilities/TestHelpers.h>
4 #include <framework/logging/LogVariableStream.h>
5 
6 #include <gtest/gtest.h>
7 
8 using namespace std;
9 using namespace Belle2;
10 
11 namespace {
12  TEST(LoggingTest, B2ASSERT)
13  {
14 #ifndef LOG_NO_B2ASSERT
15  B2ASSERT("this shouldn't happen", true);
16  // cppcheck-suppress internalAstError ; this confuses cppcheck ...
17  EXPECT_B2FATAL(B2ASSERT("This is just a test, ignore this message", false));
18 #else
19  B2ASSERT("this should be compiled out", true);
20  B2ASSERT("this should be compiled out", false);
21 #endif
22 
23  }
24 
25  TEST(LoggingTest, LogMethod)
26  {
27  B2METHOD();
28  }
29 
30  //mostly to test compilation when some logging macros are compiled out.
31  TEST(LoggingTest, MacroSyntax)
32  {
33  B2DEBUG(100, "test");
34  B2WARNING("test");
35 
36  //these only work if the macros themselves don't include ';' at the end
37  if (true)
38  B2WARNING("test");
39  else { /* ... */ }
40 
41  if (true)
42  B2DEBUG(100, "test");
43  else { /* .. */ }
44 
45  }
46 
47  TEST(LoggingTest, VariableLogging)
48  {
50  lv << "Some Text" << endl << "which is constant" << LogVar("intVar", 23) << LogVar("floatVar", 3.14) << LogVar("strVar",
51  "someString");
52  EXPECT_EQ("Some Text\nwhich is constant\n\tintVar = 23\n\tfloatVar = 3.1400000000000001\n\tstrVar = someString", lv.str());
53 
54  // test if copy and assignment works as expected
55  LogVariableStream lv_copyconst(lv);
56  LogVariableStream lv_assign;
57  lv_assign = lv;
58  EXPECT_EQ("Some Text\nwhich is constant\n\tintVar = 23\n\tfloatVar = 3.1400000000000001\n\tstrVar = someString", lv_assign.str());
59  EXPECT_EQ("Some Text\nwhich is constant\n\tintVar = 23\n\tfloatVar = 3.1400000000000001\n\tstrVar = someString",
60  lv_copyconst.str());
61  }
62 
63 } // namespace
LogVariableStream
Specialized implementation of an ostream-like class where the << operator can be used to insert value...
Definition: LogVariableStream.h:87
Belle2::LogMethod
The LogMethod class.
Definition: LogMethod.h:41
LogVariableStream::str
std::string str(bool showVariables=true) const
Return the content of the stream as string.
Definition: LogVariableStream.h:189
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
LogVar
Class to store variables with their name which were sent to the logging service.
Definition: LogVariableStream.h:24
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18