-
Notifications
You must be signed in to change notification settings - Fork 532
Expand file tree
/
Copy pathLoggingTest.cpp
More file actions
131 lines (114 loc) · 4.21 KB
/
LoggingTest.cpp
File metadata and controls
131 lines (114 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) Meta Platforms, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#include "esp/core/Logging.h"
#include <sstream>
#include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Containers/StringView.h>
#include <Corrade/TestSuite/Tester.h>
namespace Cr = Corrade;
namespace esp {
namespace sim {
namespace test {
namespace {
void debug(const Cr::Containers::StringView statement) {
ESP_DEBUG() << statement;
}
void warning(const Cr::Containers::StringView statement) {
ESP_WARNING() << statement;
}
} // namespace
} // namespace test
} // namespace sim
namespace gfx {
namespace test {
namespace {
void debug(const Cr::Containers::StringView statement) {
ESP_DEBUG() << statement;
}
void warning(const Cr::Containers::StringView statement) {
ESP_WARNING() << statement;
}
} // namespace
} // namespace test
} // namespace gfx
} // namespace esp
namespace {
struct LoggingTest : Cr::TestSuite::Tester {
explicit LoggingTest();
void envVarTest();
};
constexpr const struct {
const char* envString;
const char* defaultDebug;
const char* defaultWarning;
const char* simDebug;
const char* simWarning;
const char* gfxDebug;
const char* gfxWarning;
} EnvVarTestData[]{
{"verbose", "[Default] LoggingTest.cpp(103)::envVarTest : DebugDefault\n",
"[Default] LoggingTest.cpp(107)::envVarTest : WarningDefault\n",
"[Sim] LoggingTest.cpp(23)::debug : DebugSim\n",
"[Sim] LoggingTest.cpp(26)::warning : WarningSim\n",
"[Gfx] LoggingTest.cpp(36)::debug : DebugGfx\n",
"[Gfx] LoggingTest.cpp(39)::warning : WarningGfx\n"},
{"debug", "[Default] LoggingTest.cpp(103)::envVarTest : DebugDefault\n",
"[Default] LoggingTest.cpp(107)::envVarTest : WarningDefault\n",
"[Sim] LoggingTest.cpp(23)::debug : DebugSim\n",
"[Sim] LoggingTest.cpp(26)::warning : WarningSim\n",
"[Gfx] LoggingTest.cpp(36)::debug : DebugGfx\n",
"[Gfx] LoggingTest.cpp(39)::warning : WarningGfx\n"},
{"quiet", "", "", "", "", "", ""},
{"error", "", "", "", "", "", ""},
{"quiet:Sim,Gfx=verbose", "", "",
"[Sim] LoggingTest.cpp(23)::debug : DebugSim\n",
"[Sim] LoggingTest.cpp(26)::warning : WarningSim\n",
"[Gfx] LoggingTest.cpp(36)::debug : DebugGfx\n",
"[Gfx] LoggingTest.cpp(39)::warning : WarningGfx\n"},
{"warning:Gfx=debug", "",
"[Default] LoggingTest.cpp(107)::envVarTest : WarningDefault\n", "",
"[Sim] LoggingTest.cpp(26)::warning : WarningSim\n",
"[Gfx] LoggingTest.cpp(36)::debug : DebugGfx\n",
"[Gfx] LoggingTest.cpp(39)::warning : WarningGfx\n"},
}; // EnvVarTestData
LoggingTest::LoggingTest() {
addInstancedTests({&LoggingTest::envVarTest},
Cr::Containers::arraySize(EnvVarTestData));
}
void LoggingTest::envVarTest() {
auto&& data = EnvVarTestData[testCaseInstanceId()];
esp::logging::LoggingContext ctx{data.envString};
std::ostringstream out;
Cr::Utility::Debug debugCapture{&out};
Cr::Utility::Warning warnCapture{&out};
// use contains to bypass issue with timestamp
ESP_DEBUG() << "DebugDefault";
CORRADE_VERIFY(Cr::Containers::StringView{out.str()}.contains(
Cr::Containers::StringView{data.defaultDebug}));
out.str("");
ESP_WARNING() << "WarningDefault";
CORRADE_VERIFY(Cr::Containers::StringView{out.str()}.contains(
Cr::Containers::StringView{data.defaultWarning}));
out.str("");
esp::sim::test::debug("DebugSim");
CORRADE_VERIFY(Cr::Containers::StringView{out.str()}.contains(
Cr::Containers::StringView{data.simDebug}));
out.str("");
esp::sim::test::warning("WarningSim");
CORRADE_VERIFY(Cr::Containers::StringView{out.str()}.contains(
Cr::Containers::StringView{data.simWarning}));
out.str("");
esp::gfx::test::debug("DebugGfx");
CORRADE_VERIFY(Cr::Containers::StringView{out.str()}.contains(
Cr::Containers::StringView{data.gfxDebug}));
out.str("");
esp::gfx::test::warning("WarningGfx");
CORRADE_VERIFY(Cr::Containers::StringView{out.str()}.contains(
Cr::Containers::StringView{data.gfxWarning}));
out.str("");
}
} // namespace
CORRADE_TEST_MAIN(LoggingTest)