Jon Test
C++ Unit Test Tool. Not for production -- sample code only
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1#ifndef JON_TEST_LOGGER_H
2#define JON_TEST_LOGGER_H
3
4#include "JonTest/Count.h"
5
6#include <exception>
7#include <ostream>
8#include <string>
9
10namespace JonTest
11{
12
13class TestFailure;
14
17class Logger
18{
19public:
21 virtual ~Logger();
22
24 virtual void start() = 0;
25
27 virtual void startSuite(
28 const std::string& suiteName
29 ) = 0;
30
32 virtual void startCase(
33 const std::string& suiteName,
34 const std::string& caseName
35 ) = 0;
36
38 virtual void errorCase(
39 const std::string& suiteName,
40 const std::string& caseName,
41 const std::string& casePart,
42 const std::string& message
43 ) = 0;
44
46 virtual void failCase(
47 const std::string& suiteName,
48 const std::string& caseName,
49 const std::string& casePart,
50 const TestFailure& failure
51 ) = 0;
52
54 virtual void exceptionCase(
55 const std::string& suiteName,
56 const std::string& caseName,
57 const std::string& casePart,
58 const std::exception& unexpected
59 ) = 0;
60
62 virtual void endCase(
63 const std::string& suiteName,
64 const std::string& caseName,
65 const bool pass
66 ) = 0;
67
69 virtual void endSuite(
70 const std::string& suiteName,
71 const Count& count
72 ) = 0;
73
75 virtual void end(
76 const Count& count
77 ) = 0;
78};
79
88class StreamLogger : public Logger
89{
90protected:
92 std::ostream& out;
93
95 const bool verbose;
96
97public:
101 std::ostream& out,
102 bool verbose
103 );
104
106 virtual ~StreamLogger();
107
108 virtual void start();
109
110 virtual void startSuite(
111 const std::string& suiteName
112 );
113
114 virtual void startCase(
115 const std::string& suiteName,
116 const std::string& caseName
117 );
118
119 virtual void errorCase(
120 const std::string& suiteName,
121 const std::string& caseName,
122 const std::string& casePart,
123 const std::string& message
124 );
125
126 virtual void failCase(
127 const std::string& suiteName,
128 const std::string& caseName,
129 const std::string& casePart,
130 const TestFailure& failure
131 );
132
134 virtual void exceptionCase(
135 const std::string& suiteName,
136 const std::string& caseName,
137 const std::string& casePart,
138 const std::exception& unexpected
139 );
140
141 virtual void endCase(
142 const std::string& suiteName,
143 const std::string& caseName,
144 const bool pass
145 );
146
147 virtual void endSuite(
148 const std::string& suiteName,
149 const Count& count
150 );
151
152 virtual void end(
153 const Count& count
154 );
155};
156
157}
158
159#endif
Count of tests run, and fails.
Definition Count.h:10
Interface for logging events while running tests.
Definition Logger.h:18
virtual void exceptionCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const std::exception &unexpected)=0
Unexpected exception occurred during a part of the case.
virtual void end(const Count &count)=0
End of all testing, suitable to output.
virtual void startCase(const std::string &suiteName, const std::string &caseName)=0
Start of test case.
virtual void failCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const TestFailure &failure)=0
Test failure occurred during a part of the case.
virtual void start()=0
Start of all testing.
virtual void endSuite(const std::string &suiteName, const Count &count)=0
End of test suite, with count of tests run and failed for that suite alone.
virtual void startSuite(const std::string &suiteName)=0
Start of test suite.
virtual void endCase(const std::string &suiteName, const std::string &caseName, const bool pass)=0
End of test case, with record pass or fail.
virtual ~Logger()
Destructor – does nothing.
Definition Logger.cpp:11
virtual void errorCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const std::string &message)=0
Unexpected error occurred during a part of the test case.
Stream-based Logger for events while running tests.
Definition Logger.h:89
virtual void end(const Count &count)
End of all testing, suitable to output.
Definition Logger.cpp:117
virtual void endSuite(const std::string &suiteName, const Count &count)
End of test suite, with count of tests run and failed for that suite alone.
Definition Logger.cpp:105
const bool verbose
Simple level of verbosity: true for all events, false for critical.
Definition Logger.h:95
virtual void failCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const TestFailure &failure)
Test failure occurred during a part of the case.
Definition Logger.cpp:70
virtual void start()
Start of all testing.
Definition Logger.cpp:30
virtual ~StreamLogger()
Destructor – does nothing.
Definition Logger.cpp:25
virtual void startCase(const std::string &suiteName, const std::string &caseName)
Start of test case.
Definition Logger.cpp:48
virtual void startSuite(const std::string &suiteName)
Start of test suite.
Definition Logger.cpp:38
virtual void exceptionCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const std::exception &unexpected)
Unexpected exception occurred during a part of the case.
Definition Logger.cpp:81
virtual void errorCase(const std::string &suiteName, const std::string &caseName, const std::string &casePart, const std::string &message)
Unexpected error occurred during a part of the test case.
Definition Logger.cpp:59
std::ostream & out
Stream to write to.
Definition Logger.h:92
virtual void endCase(const std::string &suiteName, const std::string &caseName, const bool pass)
End of test case, with record pass or fail.
Definition Logger.cpp:92
Exception thrown when a test fails an assert and should fail (unless wrapped in expectedFailure()).
Definition TestFailure.h:17
Definition Count.h:5