rippled
beast_Journal_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of Beast: https://github.com/vinniefalco/Beast
4  Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/beast/utility/Journal.h>
21 #include <ripple/beast/unit_test.h>
22 
23 namespace beast {
24 
25 class Journal_test : public unit_test::suite
26 {
27 public:
28  class TestSink : public Journal::Sink
29  {
30  private:
31  int m_count;
32 
33  public:
35  : Sink (severities::kWarning, false)
36  , m_count(0)
37  {
38  }
39 
40  int
41  count() const
42  {
43  return m_count;
44  }
45 
46  void
48  {
49  m_count = 0;
50  }
51 
52  void
53  write (severities::Severity level, std::string const&) override
54  {
55  if (level >= threshold())
56  ++m_count;
57  }
58  };
59 
60  void run () override
61  {
62  TestSink sink;
63 
64  using namespace beast::severities;
65  sink.threshold(kInfo);
66 
67  Journal j(sink);
68 
69  j.trace() << " ";
70  BEAST_EXPECT(sink.count() == 0);
71  j.debug() << " ";
72  BEAST_EXPECT(sink.count() == 0);
73  j.info() << " ";
74  BEAST_EXPECT(sink.count() == 1);
75  j.warn() << " ";
76  BEAST_EXPECT(sink.count() == 2);
77  j.error() << " ";
78  BEAST_EXPECT(sink.count() == 3);
79  j.fatal() << " ";
80  BEAST_EXPECT(sink.count() == 4);
81 
82  sink.reset();
83 
84  sink.threshold(kDebug);
85 
86  j.trace() << " ";
87  BEAST_EXPECT(sink.count() == 0);
88  j.debug() << " ";
89  BEAST_EXPECT(sink.count() == 1);
90  j.info() << " ";
91  BEAST_EXPECT(sink.count() == 2);
92  j.warn() << " ";
93  BEAST_EXPECT(sink.count() == 3);
94  j.error() << " ";
95  BEAST_EXPECT(sink.count() == 4);
96  j.fatal() << " ";
97  BEAST_EXPECT(sink.count() == 5);
98  }
99 };
100 
101 BEAST_DEFINE_TESTSUITE(Journal,utility,beast);
102 
103 } // beast
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:312
beast::Journal::Sink
Abstraction for the underlying message destination.
Definition: Journal.h:76
std::string
STL class.
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:287
beast::Journal_test
Definition: beast_Journal_test.cpp:25
beast::Journal::warn
Stream warn() const
Definition: Journal.h:302
beast::severities
A namespace for easy access to logging severity values.
Definition: Journal.h:29
beast::Journal_test::TestSink::reset
void reset()
Definition: beast_Journal_test.cpp:47
beast::Journal_test::TestSink::m_count
int m_count
Definition: beast_Journal_test.cpp:31
beast::Journal::Sink::Sink
Sink()=delete
beast::Journal::error
Stream error() const
Definition: Journal.h:307
beast::Journal::info
Stream info() const
Definition: Journal.h:297
beast::Journal_test::TestSink::write
void write(severities::Severity level, std::string const &) override
Write text to the sink at the specified severity.
Definition: beast_Journal_test.cpp:53
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
beast::severities::kInfo
@ kInfo
Definition: Journal.h:38
beast::Journal::Sink::threshold
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Definition: beast_Journal.cpp:98
beast::severities::Severity
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:32
beast::Journal_test::TestSink
Definition: beast_Journal_test.cpp:28
beast::severities::kDebug
@ kDebug
Definition: Journal.h:37
beast::Journal::debug
Stream debug() const
Definition: Journal.h:292
beast::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(aged_set, container, beast)
beast::Journal_test::TestSink::count
int count() const
Definition: beast_Journal_test.cpp:41
beast::Journal_test::TestSink::TestSink
TestSink()
Definition: beast_Journal_test.cpp:34
beast::Journal_test::run
void run() override
Definition: beast_Journal_test.cpp:60
beast
Definition: base_uint.h:582