]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/extras/beast/unit_test/results.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / extras / beast / unit_test / results.hpp
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 <beast/unit_test/detail/const_container.hpp>
12
13 #include <string>
14 #include <vector>
15
16 namespace beast {
17 namespace unit_test {
18
19 /** Holds a set of test condition outcomes in a testcase. */
20 class case_results
21 {
22 public:
23 /** Holds the result of evaluating one test condition. */
24 struct test
25 {
26 explicit test(bool pass_)
27 : pass(pass_)
28 {
29 }
30
31 test(bool pass_, std::string const& reason_)
32 : pass(pass_)
33 , reason(reason_)
34 {
35 }
36
37 bool pass;
38 std::string reason;
39 };
40
41 private:
42 class tests_t
43 : public detail::const_container <std::vector <test>>
44 {
45 private:
46 std::size_t failed_;
47
48 public:
49 tests_t()
50 : failed_(0)
51 {
52 }
53
54 /** Returns the total number of test conditions. */
55 std::size_t
56 total() const
57 {
58 return cont().size();
59 }
60
61 /** Returns the number of failed test conditions. */
62 std::size_t
63 failed() const
64 {
65 return failed_;
66 }
67
68 /** Register a successful test condition. */
69 void
70 pass()
71 {
72 cont().emplace_back(true);
73 }
74
75 /** Register a failed test condition. */
76 void
77 fail(std::string const& reason = "")
78 {
79 ++failed_;
80 cont().emplace_back(false, reason);
81 }
82 };
83
84 class log_t
85 : public detail::const_container <std::vector <std::string>>
86 {
87 public:
88 /** Insert a string into the log. */
89 void
90 insert(std::string const& s)
91 {
92 cont().push_back(s);
93 }
94 };
95
96 std::string name_;
97
98 public:
99 explicit case_results(std::string const& name = "")
100 : name_(name)
101 {
102 }
103
104 /** Returns the name of this testcase. */
105 std::string const&
106 name() const
107 {
108 return name_;
109 }
110
111 /** Memberspace for a container of test condition outcomes. */
112 tests_t tests;
113
114 /** Memberspace for a container of testcase log messages. */
115 log_t log;
116 };
117
118 //--------------------------------------------------------------------------
119
120 /** Holds the set of testcase results in a suite. */
121 class suite_results
122 : public detail::const_container <std::vector <case_results>>
123 {
124 private:
125 std::string name_;
126 std::size_t total_ = 0;
127 std::size_t failed_ = 0;
128
129 public:
130 explicit suite_results(std::string const& name = "")
131 : name_(name)
132 {
133 }
134
135 /** Returns the name of this suite. */
136 std::string const&
137 name() const
138 {
139 return name_;
140 }
141
142 /** Returns the total number of test conditions. */
143 std::size_t
144 total() const
145 {
146 return total_;
147 }
148
149 /** Returns the number of failures. */
150 std::size_t
151 failed() const
152 {
153 return failed_;
154 }
155
156 /** Insert a set of testcase results. */
157 /** @{ */
158 void
159 insert(case_results&& r)
160 {
161 cont().emplace_back(std::move(r));
162 total_ += r.tests.total();
163 failed_ += r.tests.failed();
164 }
165
166 void
167 insert(case_results const& r)
168 {
169 cont().push_back(r);
170 total_ += r.tests.total();
171 failed_ += r.tests.failed();
172 }
173 /** @} */
174 };
175
176 //------------------------------------------------------------------------------
177
178 // VFALCO TODO Make this a template class using scoped allocators
179 /** Holds the results of running a set of testsuites. */
180 class results
181 : public detail::const_container <std::vector <suite_results>>
182 {
183 private:
184 std::size_t m_cases;
185 std::size_t total_;
186 std::size_t failed_;
187
188 public:
189 results()
190 : m_cases(0)
191 , total_(0)
192 , failed_(0)
193 {
194 }
195
196 /** Returns the total number of test cases. */
197 std::size_t
198 cases() const
199 {
200 return m_cases;
201 }
202
203 /** Returns the total number of test conditions. */
204 std::size_t
205 total() const
206 {
207 return total_;
208 }
209
210 /** Returns the number of failures. */
211 std::size_t
212 failed() const
213 {
214 return failed_;
215 }
216
217 /** Insert a set of suite results. */
218 /** @{ */
219 void
220 insert(suite_results&& r)
221 {
222 m_cases += r.size();
223 total_ += r.total();
224 failed_ += r.failed();
225 cont().emplace_back(std::move(r));
226 }
227
228 void
229 insert(suite_results const& r)
230 {
231 m_cases += r.size();
232 total_ += r.total();
233 failed_ += r.failed();
234 cont().push_back(r);
235 }
236 /** @} */
237 };
238
239 } // unit_test
240 } // beast
241
242 #endif