rippled
Loading...
Searching...
No Matches
results.h
1//
2// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7
8#ifndef BEAST_UNIT_TEST_RESULTS_HPP
9#define BEAST_UNIT_TEST_RESULTS_HPP
10
11#include <xrpl/beast/unit_test/detail/const_container.h>
12
13#include <string>
14#include <vector>
15
16namespace beast {
17namespace unit_test {
18
21{
22public:
24 struct test
25 {
26 explicit test(bool pass_) : pass(pass_)
27 {
28 }
29
30 test(bool pass_, std::string const& reason_)
31 : pass(pass_), reason(reason_)
32 {
33 }
34
35 bool pass;
37 };
38
39private:
40 class tests_t : public detail::const_container<std::vector<test>>
41 {
42 private:
44
45 public:
47 {
48 }
49
52 total() const
53 {
54 return cont().size();
55 }
56
59 failed() const
60 {
61 return failed_;
62 }
63
65 void
67 {
68 cont().emplace_back(true);
69 }
70
72 void
73 fail(std::string const& reason = "")
74 {
75 ++failed_;
76 cont().emplace_back(false, reason);
77 }
78 };
79
80 class log_t : public detail::const_container<std::vector<std::string>>
81 {
82 public:
84 void
86 {
87 cont().push_back(s);
88 }
89 };
90
92
93public:
94 explicit case_results(std::string const& name = "") : name_(name)
95 {
96 }
97
99 std::string const&
100 name() const
101 {
102 return name_;
103 }
104
107
110};
111
112//--------------------------------------------------------------------------
113
115class suite_results : public detail::const_container<std::vector<case_results>>
116{
117private:
121
122public:
123 explicit suite_results(std::string const& name = "") : name_(name)
124 {
125 }
126
128 std::string const&
129 name() const
130 {
131 return name_;
132 }
133
136 total() const
137 {
138 return total_;
139 }
140
143 failed() const
144 {
145 return failed_;
146 }
147
150 void
152 {
153 cont().emplace_back(std::move(r));
154 total_ += r.tests.total();
155 failed_ += r.tests.failed();
156 }
157
158 void
160 {
161 cont().push_back(r);
162 total_ += r.tests.total();
163 failed_ += r.tests.failed();
164 }
166};
167
168//------------------------------------------------------------------------------
169
170// VFALCO TODO Make this a template class using scoped allocators
172class results : public detail::const_container<std::vector<suite_results>>
173{
174private:
178
179public:
181 {
182 }
183
186 cases() const
187 {
188 return m_cases;
189 }
190
193 total() const
194 {
195 return total_;
196 }
197
200 failed() const
201 {
202 return failed_;
203 }
204
207 void
209 {
210 m_cases += r.size();
211 total_ += r.total();
212 failed_ += r.failed();
213 cont().emplace_back(std::move(r));
214 }
215
216 void
218 {
219 m_cases += r.size();
220 total_ += r.total();
221 failed_ += r.failed();
222 cont().push_back(r);
223 }
225};
226
227} // namespace unit_test
228} // namespace beast
229
230#endif
void insert(std::string const &s)
Insert a string into the log.
Definition: results.h:85
std::size_t failed() const
Returns the number of failed test conditions.
Definition: results.h:59
void pass()
Register a successful test condition.
Definition: results.h:66
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:73
Holds a set of test condition outcomes in a testcase.
Definition: results.h:21
case_results(std::string const &name="")
Definition: results.h:94
tests_t tests
Memberspace for a container of test condition outcomes.
Definition: results.h:106
log_t log
Memberspace for a container of testcase log messages.
Definition: results.h:109
std::string const & name() const
Returns the name of this testcase.
Definition: results.h:100
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:173
void insert(suite_results const &r)
Definition: results.h:217
std::size_t failed() const
Returns the number of failures.
Definition: results.h:200
std::size_t cases() const
Returns the total number of test cases.
Definition: results.h:186
void insert(suite_results &&r)
Insert a set of suite results.
Definition: results.h:208
std::size_t total() const
Returns the total number of test conditions.
Definition: results.h:193
Holds the set of testcase results in a suite.
Definition: results.h:116
std::string const & name() const
Returns the name of this suite.
Definition: results.h:129
std::size_t total() const
Returns the total number of test conditions.
Definition: results.h:136
std::size_t failed() const
Returns the number of failures.
Definition: results.h:143
void insert(case_results const &r)
Definition: results.h:159
void insert(case_results &&r)
Insert a set of testcase results.
Definition: results.h:151
suite_results(std::string const &name="")
Definition: results.h:123
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:25
test(bool pass_, std::string const &reason_)
Definition: results.h:30