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 <string>
10#include <utility>
11#include <vector>
12
13namespace beast::unit_test {
14
17{
18public:
20 struct Test
21 {
22 explicit Test(bool pass) : pass(pass)
23 {
24 }
25
27 {
28 }
29
30 bool pass;
32 };
33
34private:
35 class TestsT : public detail::ConstContainer<std::vector<Test>>
36 {
37 private:
39
40 public:
41 TestsT() = default;
42
44 [[nodiscard]] std::size_t
45 total() const
46 {
47 return cont().size();
48 }
49
51 [[nodiscard]] std::size_t
52 failed() const
53 {
54 return failed_;
55 }
56
58 void
60 {
61 cont().emplace_back(true);
62 }
63
65 void
66 fail(std::string const& reason = "")
67 {
68 ++failed_;
69 cont().emplace_back(false, reason);
70 }
71 };
72
73 class LogT : public detail::ConstContainer<std::vector<std::string>>
74 {
75 public:
77 void
79 {
80 cont().push_back(s);
81 }
82 };
83
85
86public:
87 explicit CaseResults(std::string name = "") : name_(std::move(name))
88 {
89 }
90
92 [[nodiscard]] std::string const&
93 name() const
94 {
95 return name_;
96 }
97
100
103};
104
105//--------------------------------------------------------------------------
106
108class SuiteResults : public detail::ConstContainer<std::vector<CaseResults>>
109{
110private:
114
115public:
116 explicit SuiteResults(std::string name = "") : name_(std::move(name))
117 {
118 }
119
121 [[nodiscard]] std::string const&
122 name() const
123 {
124 return name_;
125 }
126
128 [[nodiscard]] std::size_t
129 total() const
130 {
131 return total_;
132 }
133
135 [[nodiscard]] std::size_t
136 failed() const
137 {
138 return failed_;
139 }
140
143 void
145 {
146 total_ += r.tests.total();
147 failed_ += r.tests.failed();
148 cont().emplace_back(std::move(r));
149 }
150
151 void
153 {
154 cont().push_back(r);
155 total_ += r.tests.total();
156 failed_ += r.tests.failed();
157 }
158
159};
160
161//------------------------------------------------------------------------------
162
163// VFALCO TODO Make this a template class using scoped allocators
165class Results : public detail::ConstContainer<std::vector<SuiteResults>>
166{
167private:
171
172public:
173 Results() = default;
174
176 [[nodiscard]] std::size_t
177 cases() const
178 {
179 return cases_;
180 }
181
183 [[nodiscard]] std::size_t
184 total() const
185 {
186 return total_;
187 }
188
190 [[nodiscard]] std::size_t
191 failed() const
192 {
193 return failed_;
194 }
195
198 void
200 {
201 cases_ += r.size();
202 total_ += r.total();
203 failed_ += r.failed();
204 cont().emplace_back(std::move(r));
205 }
206
207 void
209 {
210 cases_ += r.size();
211 total_ += r.total();
212 failed_ += r.failed();
213 cont().push_back(r);
214 }
215
216};
217
218} // namespace beast::unit_test
void insert(std::string const &s)
Insert a string into the log.
Definition results.h:78
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:45
void fail(std::string const &reason="")
Register a failed test condition.
Definition results.h:66
std::size_t failed() const
Returns the number of failed test conditions.
Definition results.h:52
void pass()
Register a successful test condition.
Definition results.h:59
Holds a set of test condition outcomes in a testcase.
Definition results.h:17
std::string const & name() const
Returns the name of this testcase.
Definition results.h:93
TestsT tests
Memberspace for a container of test condition outcomes.
Definition results.h:99
CaseResults(std::string name="")
Definition results.h:87
LogT log
Memberspace for a container of testcase log messages.
Definition results.h:102
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:184
std::size_t cases() const
Returns the total number of test cases.
Definition results.h:177
void insert(SuiteResults &&r)
Insert a set of suite results.
Definition results.h:199
std::size_t failed() const
Returns the number of failures.
Definition results.h:191
void insert(SuiteResults const &r)
Definition results.h:208
Holds the set of testcase results in a suite.
Definition results.h:109
void insert(CaseResults &&r)
Insert a set of testcase results.
Definition results.h:144
SuiteResults(std::string name="")
Definition results.h:116
std::size_t total() const
Returns the total number of test conditions.
Definition results.h:129
std::string const & name() const
Returns the name of this suite.
Definition results.h:122
std::size_t failed() const
Returns the number of failures.
Definition results.h:136
void insert(CaseResults const &r)
Definition results.h:152
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:26