Belle II Software light-2406-ragdoll
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
15using namespace std;
16using namespace Belle2;
17
18namespace {
19 TEST(LoggingTest, B2ASSERT)
20 {
21#ifndef LOG_NO_B2ASSERT
22 B2ASSERT("this shouldn't happen", true);
23 EXPECT_B2FATAL(B2ASSERT("This is just a test, ignore this message", false));
24#else
25 B2ASSERT("this should be compiled out", true);
26 B2ASSERT("this should be compiled out", false);
27#endif
28
29 }
30
31 TEST(LoggingTest, LogMethod)
32 {
33 B2METHOD();
34 }
35
36 //mostly to test compilation when some logging macros are compiled out.
37 TEST(LoggingTest, MacroSyntax)
38 {
39 B2DEBUG(100, "test");
40 B2WARNING("test");
41
42 //these only work if the macros themselves don't include ';' at the end
43 if (true)
44 B2WARNING("test");
45 else { /* ... */ }
46
47 if (true)
48 B2DEBUG(100, "test");
49 else { /* .. */ }
50
51 }
52
53 TEST(LoggingTest, VariableLogging)
54 {
56 lv << "Some Text" << endl << "which is constant" << LogVar("intVar", 23) << LogVar("floatVar", 3.14) << LogVar("strVar",
57 "someString");
58 EXPECT_EQ("Some Text\nwhich is constant\n\tintVar = 23\n\tfloatVar = 3.1400000000000001\n\tstrVar = someString", lv.str());
59
60 // test if copy and assignment works as expected
61 LogVariableStream lv_copyconst(lv);
62 LogVariableStream lv_assign;
63 lv_assign = lv;
64 EXPECT_EQ("Some Text\nwhich is constant\n\tintVar = 23\n\tfloatVar = 3.1400000000000001\n\tstrVar = someString", lv_assign.str());
65 EXPECT_EQ("Some Text\nwhich is constant\n\tintVar = 23\n\tfloatVar = 3.1400000000000001\n\tstrVar = someString",
66 lv_copyconst.str());
67 }
68
69} // 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.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.