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#pragma once
6
7#include <xrpl/beast/unit_test/detail/const_container.h>
8
9#include <string>
10#include <vector>
11
12namespace beast {
13namespace unit_test {
14
17{
18public:
20 struct test
21 {
22 explicit test(bool pass_) : pass(pass_)
23 {
24 }
25
26 test(bool pass_, std::string const& reason_) : pass(pass_), reason(reason_)
27 {
28 }
29
30 bool pass;
32 };
33
34private:
35 class tests_t : public detail::const_container<std::vector<test>>
36 {
37 private:
39
40 public:
42 {
43 }
44
47 total() const
48 {
49 return cont().size();
50 }
51
54 failed() const
55 {
56 return failed_;
57 }
58
60 void
62 {
63 cont().emplace_back(true);
64 }
65
67 void
68 fail(std::string const& reason = "")
69 {
70 ++failed_;
71 cont().emplace_back(false, reason);
72 }
73 };
74
75 class log_t : public detail::const_container<std::vector<std::string>>
76 {
77 public:
79 void
81 {
82 cont().push_back(s);
83 }
84 };
85
87
88public:
89 explicit case_results(std::string const& name = "") : name_(name)
90 {
91 }
92
94 std::string const&
95 name() const
96 {
97 return name_;
98 }
99
102
105};
106
107//--------------------------------------------------------------------------
108
110class suite_results : public detail::const_container<std::vector<case_results>>
111{
112private:
116
117public:
118 explicit suite_results(std::string const& name = "") : name_(name)
119 {
120 }
121
123 std::string const&
124 name() const
125 {
126 return name_;
127 }
128
131 total() const
132 {
133 return total_;
134 }
135
138 failed() const
139 {
140 return failed_;
141 }
142
145 void
147 {
148 cont().emplace_back(std::move(r));
149 total_ += r.tests.total();
150 failed_ += r.tests.failed();
151 }
152
153 void
155 {
156 cont().push_back(r);
157 total_ += r.tests.total();
158 failed_ += r.tests.failed();
159 }
161};
162
163//------------------------------------------------------------------------------
164
165// VFALCO TODO Make this a template class using scoped allocators
167class results : public detail::const_container<std::vector<suite_results>>
168{
169private:
173
174public:
176 {
177 }
178
181 cases() const
182 {
183 return m_cases;
184 }
185
188 total() const
189 {
190 return total_;
191 }
192
195 failed() const
196 {
197 return failed_;
198 }
199
202 void
204 {
205 m_cases += r.size();
206 total_ += r.total();
207 failed_ += r.failed();
208 cont().emplace_back(std::move(r));
209 }
210
211 void
213 {
214 m_cases += r.size();
215 total_ += r.total();
216 failed_ += r.failed();
217 cont().push_back(r);
218 }
220};
221
222} // namespace unit_test
223} // namespace beast
void insert(std::string const &s)
Insert a string into the log.
Definition results.h:80
std::size_t failed() const
Returns the number of failed test conditions.
Definition results.h:54
void pass()
Register a successful test condition.
Definition results.h:61
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:47
void fail(std::string const &reason="")
Register a failed test condition.
Definition results.h:68
Holds a set of test condition outcomes in a testcase.
Definition results.h:17
case_results(std::string const &name="")
Definition results.h:89
tests_t tests
Memberspace for a container of test condition outcomes.
Definition results.h:101
log_t log
Memberspace for a container of testcase log messages.
Definition results.h:104
std::string const & name() const
Returns the name of this testcase.
Definition results.h:95
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:168
void insert(suite_results const &r)
Definition results.h:212
std::size_t failed() const
Returns the number of failures.
Definition results.h:195
std::size_t cases() const
Returns the total number of test cases.
Definition results.h:181
void insert(suite_results &&r)
Insert a set of suite results.
Definition results.h:203
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:188
Holds the set of testcase results in a suite.
Definition results.h:111
std::string const & name() const
Returns the name of this suite.
Definition results.h:124
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:131
std::size_t failed() const
Returns the number of failures.
Definition results.h:138
void insert(case_results const &r)
Definition results.h:154
void insert(case_results &&r)
Insert a set of testcase results.
Definition results.h:146
suite_results(std::string const &name="")
Definition results.h:118
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:21
test(bool pass_, std::string const &reason_)
Definition results.h:26