xrpld
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 <cstddef>
10#include <string>
11#include <utility>
12#include <vector>
13
14namespace beast::unit_test {
15
20{
21public:
25 struct Test
26 {
27 explicit Test(bool pass) : pass(pass)
28 {
29 }
30
32 {
33 }
34
35 bool pass;
37 };
38
39private:
40 class TestsT : public detail::ConstContainer<std::vector<Test>>
41 {
42 private:
44
45 public:
46 TestsT() = default;
47
51 [[nodiscard]] std::size_t
52 total() const
53 {
54 return cont().size();
55 }
56
60 [[nodiscard]] std::size_t
61 failed() const
62 {
63 return failed_;
64 }
65
69 void
71 {
72 cont().emplace_back(true);
73 }
74
78 void
79 fail(std::string const& reason = "")
80 {
81 ++failed_;
82 cont().emplace_back(false, reason);
83 }
84 };
85
86 class LogT : public detail::ConstContainer<std::vector<std::string>>
87 {
88 public:
92 void
94 {
95 cont().push_back(s);
96 }
97 };
98
100
101public:
102 explicit CaseResults(std::string name = "") : name_(std::move(name))
103 {
104 }
105
109 [[nodiscard]] std::string const&
110 name() const
111 {
112 return name_;
113 }
114
119
124};
125
126//--------------------------------------------------------------------------
127
131class SuiteResults : public detail::ConstContainer<std::vector<CaseResults>>
132{
133private:
137
138public:
139 explicit SuiteResults(std::string name = "") : name_(std::move(name))
140 {
141 }
142
146 [[nodiscard]] std::string const&
147 name() const
148 {
149 return name_;
150 }
151
155 [[nodiscard]] std::size_t
156 total() const
157 {
158 return total_;
159 }
160
164 [[nodiscard]] std::size_t
165 failed() const
166 {
167 return failed_;
168 }
169
174 void
176 {
177 total_ += r.tests.total();
178 failed_ += r.tests.failed();
179 cont().emplace_back(std::move(r));
180 }
181
182 void
184 {
185 cont().push_back(r);
186 total_ += r.tests.total();
187 failed_ += r.tests.failed();
188 }
189
190};
191
192//------------------------------------------------------------------------------
193
194// VFALCO TODO Make this a template class using scoped allocators
198class Results : public detail::ConstContainer<std::vector<SuiteResults>>
199{
200private:
204
205public:
206 Results() = default;
207
211 [[nodiscard]] std::size_t
212 cases() const
213 {
214 return cases_;
215 }
216
220 [[nodiscard]] std::size_t
221 total() const
222 {
223 return total_;
224 }
225
229 [[nodiscard]] std::size_t
230 failed() const
231 {
232 return failed_;
233 }
234
239 void
241 {
242 cases_ += r.size();
243 total_ += r.total();
244 failed_ += r.failed();
245 cont().emplace_back(std::move(r));
246 }
247
248 void
250 {
251 cases_ += r.size();
252 total_ += r.total();
253 failed_ += r.failed();
254 cont().push_back(r);
255 }
256
257};
258
259} // namespace beast::unit_test
void insert(std::string const &s)
Insert a string into the log.
Definition results.h:93
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:52
void fail(std::string const &reason="")
Register a failed test condition.
Definition results.h:79
std::size_t failed() const
Returns the number of failed test conditions.
Definition results.h:61
void pass()
Register a successful test condition.
Definition results.h:70
Holds a set of test condition outcomes in a testcase.
Definition results.h:20
std::string const & name() const
Returns the name of this testcase.
Definition results.h:110
TestsT tests
Memberspace for a container of test condition outcomes.
Definition results.h:118
CaseResults(std::string name="")
Definition results.h:102
LogT log
Memberspace for a container of testcase log messages.
Definition results.h:123
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:221
std::size_t cases() const
Returns the total number of test cases.
Definition results.h:212
void insert(SuiteResults &&r)
Insert a set of suite results.
Definition results.h:240
std::size_t failed() const
Returns the number of failures.
Definition results.h:230
void insert(SuiteResults const &r)
Definition results.h:249
Holds the set of testcase results in a suite.
Definition results.h:132
void insert(CaseResults &&r)
Insert a set of testcase results.
Definition results.h:175
SuiteResults(std::string name="")
Definition results.h:139
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:156
std::string const & name() const
Returns the name of this suite.
Definition results.h:147
std::size_t failed() const
Returns the number of failures.
Definition results.h:165
void insert(CaseResults const &r)
Definition results.h:183
Adapter to constrain a container interface.
size_type size() const
Returns the number of items in the container.
T emplace_back(T... args)
STL namespace.
T push_back(T... args)
T size(T... args)
Test(bool pass, std::string reason)
Definition results.h:31