1 | /*
|
---|
2 | * Copyright (c) 2018 Jaroslav Jindrak
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef LIBCPP_TESTS
|
---|
30 | #define LIBCPP_TESTS
|
---|
31 |
|
---|
32 | #include <cstdio>
|
---|
33 | #include <__bits/test/test.hpp>
|
---|
34 | #include <vector>
|
---|
35 |
|
---|
36 | namespace std::test
|
---|
37 | {
|
---|
38 | class test_set
|
---|
39 | {
|
---|
40 | public:
|
---|
41 | test_set() = default;
|
---|
42 |
|
---|
43 | template<class T>
|
---|
44 | void add()
|
---|
45 | {
|
---|
46 | tests_.push_back(new T{});
|
---|
47 | }
|
---|
48 |
|
---|
49 | bool run(bool report)
|
---|
50 | {
|
---|
51 | bool res{true};
|
---|
52 | unsigned int succeeded{};
|
---|
53 | unsigned int failed{};
|
---|
54 |
|
---|
55 | for (auto test: tests_)
|
---|
56 | {
|
---|
57 | res &= test->run(report);
|
---|
58 | succeeded += test->get_succeeded();
|
---|
59 | failed += test->get_failed();
|
---|
60 | }
|
---|
61 |
|
---|
62 | if (report)
|
---|
63 | {
|
---|
64 | std::printf("\n");
|
---|
65 | if (res)
|
---|
66 | std::printf("[TESTS SUCCEEDED!]");
|
---|
67 | else
|
---|
68 | std::printf("[TESTS FAILED]");
|
---|
69 | std::printf("[%u OK][%u FAIL][%u TOTAL]\n",
|
---|
70 | succeeded, failed, (succeeded + failed));
|
---|
71 | }
|
---|
72 |
|
---|
73 | return res;
|
---|
74 | }
|
---|
75 |
|
---|
76 | ~test_set()
|
---|
77 | {
|
---|
78 | for (auto ptr: tests_)
|
---|
79 | delete ptr;
|
---|
80 | }
|
---|
81 | private:
|
---|
82 | std::vector<test_suite*> tests_{};
|
---|
83 | };
|
---|
84 |
|
---|
85 | class array_test: public test_suite
|
---|
86 | {
|
---|
87 | public:
|
---|
88 | bool run(bool) override;
|
---|
89 | const char* name() override;
|
---|
90 |
|
---|
91 | array_test() = default;
|
---|
92 | ~array_test() = default;
|
---|
93 | };
|
---|
94 |
|
---|
95 | class vector_test: public test_suite
|
---|
96 | {
|
---|
97 | public:
|
---|
98 | bool run(bool) override;
|
---|
99 | const char* name() override;
|
---|
100 |
|
---|
101 | vector_test() = default;
|
---|
102 | ~vector_test() = default;
|
---|
103 |
|
---|
104 | private:
|
---|
105 | void test_construction_and_assignment();
|
---|
106 | void test_insert();
|
---|
107 | void test_erase();
|
---|
108 | };
|
---|
109 |
|
---|
110 | class string_test: public test_suite
|
---|
111 | {
|
---|
112 | public:
|
---|
113 | bool run(bool) override;
|
---|
114 | const char* name() override;
|
---|
115 |
|
---|
116 | private:
|
---|
117 | void test_construction_and_assignment();
|
---|
118 | void test_append();
|
---|
119 | void test_insert();
|
---|
120 | void test_erase();
|
---|
121 | void test_replace();
|
---|
122 | void test_copy();
|
---|
123 | void test_find();
|
---|
124 | void test_substr();
|
---|
125 | void test_compare();
|
---|
126 | };
|
---|
127 |
|
---|
128 | class bitset_test: public test_suite
|
---|
129 | {
|
---|
130 | public:
|
---|
131 | bool run(bool) override;
|
---|
132 | const char* name() override;
|
---|
133 |
|
---|
134 | private:
|
---|
135 | void test_constructors_and_assignment();
|
---|
136 | void test_strings();
|
---|
137 | void test_operations();
|
---|
138 | };
|
---|
139 |
|
---|
140 | class deque_test: public test_suite
|
---|
141 | {
|
---|
142 | public:
|
---|
143 | bool run(bool) override;
|
---|
144 | const char* name() override;
|
---|
145 |
|
---|
146 | private:
|
---|
147 | void test_constructors_and_assignment();
|
---|
148 | void test_resizing();
|
---|
149 | void test_push_pop();
|
---|
150 | void test_operations();
|
---|
151 | };
|
---|
152 |
|
---|
153 | class tuple_test: public test_suite
|
---|
154 | {
|
---|
155 | public:
|
---|
156 | bool run(bool) override;
|
---|
157 | const char* name() override;
|
---|
158 |
|
---|
159 | private:
|
---|
160 | void test_constructors_and_assignment();
|
---|
161 | void test_creation();
|
---|
162 | void test_tie_and_structured_bindings();
|
---|
163 | void test_tuple_ops();
|
---|
164 | };
|
---|
165 |
|
---|
166 | class map_test: public test_suite
|
---|
167 | {
|
---|
168 | public:
|
---|
169 | bool run(bool) override;
|
---|
170 | const char* name() override;
|
---|
171 |
|
---|
172 | private:
|
---|
173 | void test_constructors_and_assignment();
|
---|
174 | void test_histogram();
|
---|
175 | void test_emplace_insert();
|
---|
176 | void test_bounds_and_ranges();
|
---|
177 | void test_multi();
|
---|
178 | void test_reverse_iterators();
|
---|
179 | void test_multi_bounds_and_ranges();
|
---|
180 | };
|
---|
181 |
|
---|
182 | class set_test: public test_suite
|
---|
183 | {
|
---|
184 | public:
|
---|
185 | bool run(bool) override;
|
---|
186 | const char* name() override;
|
---|
187 |
|
---|
188 | private:
|
---|
189 | void test_constructors_and_assignment();
|
---|
190 | void test_emplace_insert();
|
---|
191 | void test_bounds_and_ranges();
|
---|
192 | void test_multi();
|
---|
193 | void test_reverse_iterators();
|
---|
194 | void test_multi_bounds_and_ranges();
|
---|
195 | };
|
---|
196 |
|
---|
197 | class unordered_map_test: public test_suite
|
---|
198 | {
|
---|
199 | public:
|
---|
200 | bool run(bool) override;
|
---|
201 | const char* name() override;
|
---|
202 |
|
---|
203 | private:
|
---|
204 | void test_constructors_and_assignment();
|
---|
205 | void test_histogram();
|
---|
206 | void test_emplace_insert();
|
---|
207 | void test_multi();
|
---|
208 | };
|
---|
209 |
|
---|
210 | class unordered_set_test: public test_suite
|
---|
211 | {
|
---|
212 | public:
|
---|
213 | bool run(bool) override;
|
---|
214 | const char* name() override;
|
---|
215 |
|
---|
216 | private:
|
---|
217 | void test_constructors_and_assignment();
|
---|
218 | void test_emplace_insert();
|
---|
219 | void test_multi();
|
---|
220 | };
|
---|
221 |
|
---|
222 | class numeric_test: public test_suite
|
---|
223 | {
|
---|
224 | public:
|
---|
225 | bool run(bool) override;
|
---|
226 | const char* name() override;
|
---|
227 |
|
---|
228 | private:
|
---|
229 | void test_algorithms();
|
---|
230 | void test_complex();
|
---|
231 | };
|
---|
232 |
|
---|
233 | class adaptors_test: public test_suite
|
---|
234 | {
|
---|
235 | public:
|
---|
236 | bool run(bool) override;
|
---|
237 | const char* name() override;
|
---|
238 |
|
---|
239 | private:
|
---|
240 | void test_queue();
|
---|
241 | void test_priority_queue();
|
---|
242 | void test_stack();
|
---|
243 | };
|
---|
244 |
|
---|
245 | class memory_test: public test_suite
|
---|
246 | {
|
---|
247 | public:
|
---|
248 | bool run(bool) override;
|
---|
249 | const char* name() override;
|
---|
250 |
|
---|
251 | private:
|
---|
252 | void test_unique_ptr();
|
---|
253 | void test_shared_ptr();
|
---|
254 | void test_weak_ptr();
|
---|
255 | void test_allocators();
|
---|
256 | void test_pointers();
|
---|
257 | };
|
---|
258 |
|
---|
259 | class list_test: public test_suite
|
---|
260 | {
|
---|
261 | public:
|
---|
262 | bool run(bool) override;
|
---|
263 | const char* name() override;
|
---|
264 |
|
---|
265 | private:
|
---|
266 | void test_construction_and_assignment();
|
---|
267 | void test_modifiers();
|
---|
268 | };
|
---|
269 |
|
---|
270 | class ratio_test: public test_suite
|
---|
271 | {
|
---|
272 | public:
|
---|
273 | bool run(bool) override;
|
---|
274 | const char* name() override;
|
---|
275 | };
|
---|
276 |
|
---|
277 | class functional_test: public test_suite
|
---|
278 | {
|
---|
279 | public:
|
---|
280 | bool run(bool) override;
|
---|
281 | const char* name() override;
|
---|
282 | private:
|
---|
283 | void test_reference_wrapper();
|
---|
284 | void test_function();
|
---|
285 | void test_bind();
|
---|
286 | };
|
---|
287 | }
|
---|
288 |
|
---|
289 | #endif
|
---|