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