xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
beast
Journal.cpp
1
#include <xrpl/beast/utility/Journal.h>
2
3
#include <gtest/gtest.h>
4
5
#include <
cstddef
>
6
#include <
string
>
7
8
namespace
beast
{
9
namespace
{
10
11
// Counts the messages that actually reach the sink, so the tests can assert on
12
// which severities the journal let through.
13
class
CountingSink :
public
Journal::Sink
14
{
15
std::size_t count_{0};
16
17
public
:
18
CountingSink() : Sink(
Severity
::
Warning
, false)
19
{
20
}
21
22
[[nodiscard]] std::size_t
23
count
()
const
24
{
25
return
count_;
26
}
27
28
void
29
write
(
Severity
level, std::string
const
&)
override
30
{
31
if
(level >= threshold())
32
++count_;
33
}
34
35
void
36
writeAlways(
Severity
, std::string
const
&)
override
37
{
38
++count_;
39
}
40
};
41
42
}
// namespace
43
44
TEST
(
Journal
, info_threshold)
45
{
46
CountingSink sink;
47
sink.threshold(
Severity::Info
);
48
Journal
const
j(sink);
49
50
j.
trace
() <<
" "
;
51
EXPECT_EQ(sink.count(), 0uz);
52
j.
debug
() <<
" "
;
53
EXPECT_EQ(sink.count(), 0uz);
54
j.
info
() <<
" "
;
55
EXPECT_EQ(sink.count(), 1uz);
56
j.
warn
() <<
" "
;
57
EXPECT_EQ(sink.count(), 2uz);
58
j.
error
() <<
" "
;
59
EXPECT_EQ(sink.count(), 3uz);
60
j.
fatal
() <<
" "
;
61
EXPECT_EQ(sink.count(), 4uz);
62
}
63
64
TEST
(
Journal
, debug_threshold)
65
{
66
CountingSink sink;
67
sink.threshold(
Severity::Debug
);
68
Journal
const
j(sink);
69
70
j.
trace
() <<
" "
;
71
EXPECT_EQ(sink.count(), 0uz);
72
j.
debug
() <<
" "
;
73
EXPECT_EQ(sink.count(), 1uz);
74
j.
info
() <<
" "
;
75
EXPECT_EQ(sink.count(), 2uz);
76
j.
warn
() <<
" "
;
77
EXPECT_EQ(sink.count(), 3uz);
78
j.
error
() <<
" "
;
79
EXPECT_EQ(sink.count(), 4uz);
80
j.
fatal
() <<
" "
;
81
EXPECT_EQ(sink.count(), 5uz);
82
}
83
84
// A Journal holds a reference to its sink rather than a copy of the threshold,
85
// so lowering the threshold has to take effect on a Journal that already exists.
86
// The two tests above each build the Journal after setting the threshold, so
87
// neither of them would notice if that stopped working.
88
TEST
(
Journal
, threshold_change_applies_to_an_existing_journal)
89
{
90
CountingSink sink;
91
sink.threshold(
Severity::Info
);
92
Journal
const
j(sink);
93
94
j.
debug
() <<
" "
;
95
EXPECT_EQ(sink.count(), 0uz);
96
97
sink.threshold(
Severity::Debug
);
98
99
j.
debug
() <<
" "
;
100
EXPECT_EQ(sink.count(), 1uz);
101
}
102
103
}
// namespace beast
beast::Journal::Sink
Abstraction for the underlying message destination.
Definition
Journal.h:59
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::Journal::fatal
Stream fatal() const
Definition
Journal.h:368
beast::Journal::error
Stream error() const
Definition
Journal.h:362
beast::Journal::debug
Stream debug() const
Definition
Journal.h:344
beast::Journal::info
Stream info() const
Definition
Journal.h:350
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition
Journal.h:338
beast::Journal::warn
Stream warn() const
Definition
Journal.h:356
std::count
T count(T... args)
cstddef
beast
Definition
base_uint.h:697
beast::Severity
Severity
Severity level / threshold of a Journal message.
Definition
Journal.h:16
beast::Severity::Warning
@ Warning
Definition
Journal.h:22
beast::Severity::Info
@ Info
Definition
Journal.h:21
beast::Severity::Debug
@ Debug
Definition
Journal.h:20
beast::TEST
TEST(BasicSecondsClock, now)
Definition
tests/libxrpl/beast/basic_seconds_clock.cpp:9
xrpl::node_store::write
void write(nudb::detail::ostream &os, std::size_t t)
Definition
Varint.h:120
string
Generated by
1.17.0