rippled
Loading...
Searching...
No Matches
results.h
1// Distributed under the Boost Software License, Version 1.0. (See accompanying
2// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
3//
4
5#ifndef BEAST_UNIT_TEST_RESULTS_HPP
6#define BEAST_UNIT_TEST_RESULTS_HPP
7
8#include <xrpl/beast/unit_test/detail/const_container.h>
9
10#include <string>
11#include <vector>
12
13namespace beast {
14namespace unit_test {
15
18{
19public:
21 struct test
22 {
23 explicit test(bool pass_) : pass(pass_)
24 {
25 }
26
27 test(bool pass_, std::string const& reason_)
28 : pass(pass_), reason(reason_)
29 {
30 }
31
32 bool pass;
34 };
35
36private:
37 class tests_t : public detail::const_container<std::vector<test>>
38 {
39 private:
41
42 public:
44 {
45 }
46
49 total() const
50 {
51 return cont().size();
52 }
53
56 failed() const
57 {
58 return failed_;
59 }
60
62 void
64 {
65 cont().emplace_back(true);
66 }
67
69 void
70 fail(std::string const& reason = "")
71 {
72 ++failed_;
73 cont().emplace_back(false, reason);
74 }
75 };
76
77 class log_t : public detail::const_container<std::vector<std::string>>
78 {
79 public:
81 void
83 {
84 cont().push_back(s);
85 }
86 };
87
89
90public:
91 explicit case_results(std::string const& name = "") : name_(name)
92 {
93 }
94
96 std::string const&
97 name() const
98 {
99 return name_;
100 }
101
104
107};
108
109//--------------------------------------------------------------------------
110
112class suite_results : public detail::const_container<std::vector<case_results>>
113{
114private:
118
119public:
120 explicit suite_results(std::string const& name = "") : name_(name)
121 {
122 }
123
125 std::string const&
126 name() const
127 {
128 return name_;
129 }
130
133 total() const
134 {
135 return total_;
136 }
137
140 failed() const
141 {
142 return failed_;
143 }
144
147 void
149 {
150 cont().emplace_back(std::move(r));
151 total_ += r.tests.total();
152 failed_ += r.tests.failed();
153 }
154
155 void
157 {
158 cont().push_back(r);
159 total_ += r.tests.total();
160 failed_ += r.tests.failed();
161 }
163};
164
165//------------------------------------------------------------------------------
166
167// VFALCO TODO Make this a template class using scoped allocators
169class results : public detail::const_container<std::vector<suite_results>>
170{
171private:
175
176public:
178 {
179 }
180
183 cases() const
184 {
185 return m_cases;
186 }
187
190 total() const
191 {
192 return total_;
193 }
194
197 failed() const
198 {
199 return failed_;
200 }
201
204 void
206 {
207 m_cases += r.size();
208 total_ += r.total();
209 failed_ += r.failed();
210 cont().emplace_back(std::move(r));
211 }
212
213 void
215 {
216 m_cases += r.size();
217 total_ += r.total();
218 failed_ += r.failed();
219 cont().push_back(r);
220 }
222};
223
224} // namespace unit_test
225} // namespace beast
226
227#endif
void insert(std::string const &s)
Insert a string into the log.
Definition results.h:82
std::size_t failed() const
Returns the number of failed test conditions.
Definition results.h:56
void pass()
Register a successful test condition.
Definition results.h:63
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:49
void fail(std::string const &reason="")
Register a failed test condition.
Definition results.h:70
Holds a set of test condition outcomes in a testcase.
Definition results.h:18
case_results(std::string const &name="")
Definition results.h:91
tests_t tests
Memberspace for a container of test condition outcomes.
Definition results.h:103
log_t log
Memberspace for a container of testcase log messages.
Definition results.h:106
std::string const & name() const
Returns the name of this testcase.
Definition results.h:97
Adapter to constrain a container interface.
size_type size() const
Returns the number of items in the container.
Holds the results of running a set of testsuites.
Definition results.h:170
void insert(suite_results const &r)
Definition results.h:214
std::size_t failed() const
Returns the number of failures.
Definition results.h:197
std::size_t cases() const
Returns the total number of test cases.
Definition results.h:183
void insert(suite_results &&r)
Insert a set of suite results.
Definition results.h:205
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:190
Holds the set of testcase results in a suite.
Definition results.h:113
std::string const & name() const
Returns the name of this suite.
Definition results.h:126
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:133
std::size_t failed() const
Returns the number of failures.
Definition results.h:140
void insert(case_results const &r)
Definition results.h:156
void insert(case_results &&r)
Insert a set of testcase results.
Definition results.h:148
suite_results(std::string const &name="")
Definition results.h:120
T emplace_back(T... args)
T push_back(T... args)
T size(T... args)
Holds the result of evaluating one test condition.
Definition results.h:22
test(bool pass_, std::string const &reason_)
Definition results.h:27