xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
beast
unit_test
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
14
namespace
beast::unit_test
{
15
19
class
CaseResults
20
{
21
public
:
25
struct
Test
26
{
27
explicit
Test
(
bool
pass
) :
pass
(
pass
)
28
{
29
}
30
31
Test
(
bool
pass
,
std::string
reason
) :
pass
(
pass
),
reason
(
std
::move(
reason
))
32
{
33
}
34
35
bool
pass
;
36
std::string
reason
;
37
};
38
39
private
:
40
class
TestsT
:
public
detail::ConstContainer
<std::vector<Test>>
41
{
42
private
:
43
std::size_t
failed_
{0};
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
70
pass
()
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
93
insert
(
std::string
const
& s)
94
{
95
cont
().
push_back
(s);
96
}
97
};
98
99
std::string
name_
;
100
101
public
:
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
118
TestsT
tests
;
119
123
LogT
log
;
124
};
125
126
//--------------------------------------------------------------------------
127
131
class
SuiteResults
:
public
detail::ConstContainer
<std::vector<CaseResults>>
132
{
133
private
:
134
std::string
name_
;
135
std::size_t
total_
= 0;
136
std::size_t
failed_
= 0;
137
138
public
:
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
175
insert
(
CaseResults
&& r)
176
{
177
total_
+= r.tests.total();
178
failed_
+= r.tests.failed();
179
cont
().
emplace_back
(std::move(r));
180
}
181
182
void
183
insert
(
CaseResults
const
& r)
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
198
class
Results
:
public
detail::ConstContainer
<std::vector<SuiteResults>>
199
{
200
private
:
201
std::size_t
cases_
{0};
202
std::size_t
total_
{0};
203
std::size_t
failed_
{0};
204
205
public
:
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
240
insert
(
SuiteResults
&& r)
241
{
242
cases_
+= r.size();
243
total_
+= r.total();
244
failed_
+= r.failed();
245
cont
().
emplace_back
(std::move(r));
246
}
247
248
void
249
insert
(
SuiteResults
const
& r)
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
std::string
beast::unit_test::CaseResults::LogT
Definition
results.h:87
beast::unit_test::CaseResults::LogT::insert
void insert(std::string const &s)
Insert a string into the log.
Definition
results.h:93
beast::unit_test::CaseResults::TestsT
Definition
results.h:41
beast::unit_test::CaseResults::TestsT::failed_
std::size_t failed_
Definition
results.h:43
beast::unit_test::CaseResults::TestsT::total
std::size_t total() const
Returns the total number of test conditions.
Definition
results.h:52
beast::unit_test::CaseResults::TestsT::fail
void fail(std::string const &reason="")
Register a failed test condition.
Definition
results.h:79
beast::unit_test::CaseResults::TestsT::TestsT
TestsT()=default
beast::unit_test::CaseResults::TestsT::failed
std::size_t failed() const
Returns the number of failed test conditions.
Definition
results.h:61
beast::unit_test::CaseResults::TestsT::pass
void pass()
Register a successful test condition.
Definition
results.h:70
beast::unit_test::CaseResults
Holds a set of test condition outcomes in a testcase.
Definition
results.h:20
beast::unit_test::CaseResults::name
std::string const & name() const
Returns the name of this testcase.
Definition
results.h:110
beast::unit_test::CaseResults::tests
TestsT tests
Memberspace for a container of test condition outcomes.
Definition
results.h:118
beast::unit_test::CaseResults::CaseResults
CaseResults(std::string name="")
Definition
results.h:102
beast::unit_test::CaseResults::name_
std::string name_
Definition
results.h:99
beast::unit_test::CaseResults::log
LogT log
Memberspace for a container of testcase log messages.
Definition
results.h:123
beast::unit_test::Results::total
std::size_t total() const
Returns the total number of test conditions.
Definition
results.h:221
beast::unit_test::Results::cases
std::size_t cases() const
Returns the total number of test cases.
Definition
results.h:212
beast::unit_test::Results::insert
void insert(SuiteResults &&r)
Insert a set of suite results.
Definition
results.h:240
beast::unit_test::Results::Results
Results()=default
beast::unit_test::Results::cases_
std::size_t cases_
Definition
results.h:201
beast::unit_test::Results::total_
std::size_t total_
Definition
results.h:202
beast::unit_test::Results::failed_
std::size_t failed_
Definition
results.h:203
beast::unit_test::Results::failed
std::size_t failed() const
Returns the number of failures.
Definition
results.h:230
beast::unit_test::Results::insert
void insert(SuiteResults const &r)
Definition
results.h:249
beast::unit_test::SuiteResults
Holds the set of testcase results in a suite.
Definition
results.h:132
beast::unit_test::SuiteResults::total_
std::size_t total_
Definition
results.h:135
beast::unit_test::SuiteResults::insert
void insert(CaseResults &&r)
Insert a set of testcase results.
Definition
results.h:175
beast::unit_test::SuiteResults::name_
std::string name_
Definition
results.h:134
beast::unit_test::SuiteResults::SuiteResults
SuiteResults(std::string name="")
Definition
results.h:139
beast::unit_test::SuiteResults::total
std::size_t total() const
Returns the total number of test conditions.
Definition
results.h:156
beast::unit_test::SuiteResults::name
std::string const & name() const
Returns the name of this suite.
Definition
results.h:147
beast::unit_test::SuiteResults::failed
std::size_t failed() const
Returns the number of failures.
Definition
results.h:165
beast::unit_test::SuiteResults::failed_
std::size_t failed_
Definition
results.h:136
beast::unit_test::SuiteResults::insert
void insert(CaseResults const &r)
Definition
results.h:183
beast::unit_test::detail::ConstContainer
Adapter to constrain a container interface.
Definition
const_container.h:16
beast::unit_test::detail::ConstContainer::size
size_type size() const
Returns the number of items in the container.
Definition
const_container.h:55
beast::unit_test::detail::ConstContainer< std::vector< Test > >::cont
ContType & cont()
Definition
const_container.h:24
cstddef
std::vector::emplace_back
T emplace_back(T... args)
beast::unit_test
Definition
include/xrpl/beast/unit_test/amount.h:11
std
STL namespace.
std::vector::push_back
T push_back(T... args)
std::vector::size
T size(T... args)
std::size_t
string
beast::unit_test::CaseResults::Test::Test
Test(bool pass, std::string reason)
Definition
results.h:31
beast::unit_test::CaseResults::Test::pass
bool pass
Definition
results.h:35
beast::unit_test::CaseResults::Test::reason
std::string reason
Definition
results.h:36
beast::unit_test::CaseResults::Test::Test
Test(bool pass)
Definition
results.h:27
utility
vector
Generated by
1.17.0