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/unit_test.h>
21 #include <ripple/beast/utility/Journal.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:
34  TestSink() : Sink(severities::kWarning, false), m_count(0)
35  {
36  }
37 
38  int
39  count() const
40  {
41  return m_count;
42  }
43 
44  void
46  {
47  m_count = 0;
48  }
49 
50  void
51  write(severities::Severity level, std::string const&) override
52  {
53  if (level >= threshold())
54  ++m_count;
55  }
56  };
57 
58  void
59  run() override
60  {
61  TestSink sink;
62 
63  using namespace beast::severities;
64  sink.threshold(kInfo);
65 
66  Journal j(sink);
67 
68  j.trace() << " ";
69  BEAST_EXPECT(sink.count() == 0);
70  j.debug() << " ";
71  BEAST_EXPECT(sink.count() == 0);
72  j.info() << " ";
73  BEAST_EXPECT(sink.count() == 1);
74  j.warn() << " ";
75  BEAST_EXPECT(sink.count() == 2);
76  j.error() << " ";
77  BEAST_EXPECT(sink.count() == 3);
78  j.fatal() << " ";
79  BEAST_EXPECT(sink.count() == 4);
80 
81  sink.reset();
82 
83  sink.threshold(kDebug);
84 
85  j.trace() << " ";
86  BEAST_EXPECT(sink.count() == 0);
87  j.debug() << " ";
88  BEAST_EXPECT(sink.count() == 1);
89  j.info() << " ";
90  BEAST_EXPECT(sink.count() == 2);
91  j.warn() << " ";
92  BEAST_EXPECT(sink.count() == 3);
93  j.error() << " ";
94  BEAST_EXPECT(sink.count() == 4);
95  j.fatal() << " ";
96  BEAST_EXPECT(sink.count() == 5);
97  }
98 };
99 
100 BEAST_DEFINE_TESTSUITE(Journal, utility, beast);
101 
102 } // namespace beast
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:339
beast::Journal::Sink
Abstraction for the underlying message destination.
Definition: Journal.h:74
std::string
STL class.
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
beast::Journal_test
Definition: beast_Journal_test.cpp:25
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
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:45
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:333
beast::Journal::info
Stream info() const
Definition: Journal.h:321
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:51
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
beast::severities::kInfo
@ kInfo
Definition: Journal.h:36
beast::Journal::Sink::threshold
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Definition: beast_Journal.cpp:106
beast::severities::Severity
Severity
Severity level / threshold of a Journal message.
Definition: Journal.h:31
beast::Journal_test::TestSink
Definition: beast_Journal_test.cpp:28
beast::severities::kDebug
@ kDebug
Definition: Journal.h:35
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
beast::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(aged_set, container, beast)
beast::Journal_test::TestSink::count
int count() const
Definition: beast_Journal_test.cpp:39
beast::Journal_test::TestSink::TestSink
TestSink()
Definition: beast_Journal_test.cpp:34
beast::Journal_test::run
void run() override
Definition: beast_Journal_test.cpp:59
beast
Definition: base_uint.h:641