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 <internal/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 | // TODO: Gimme unique_ptr!
|
---|
79 | for (auto ptr: tests_)
|
---|
80 | delete ptr;
|
---|
81 | }
|
---|
82 | private:
|
---|
83 | std::vector<test_suite*> tests_{};
|
---|
84 | };
|
---|
85 |
|
---|
86 | class array_test: public test_suite
|
---|
87 | {
|
---|
88 | public:
|
---|
89 | bool run(bool) override;
|
---|
90 | const char* name() override;
|
---|
91 |
|
---|
92 | array_test() = default;
|
---|
93 | ~array_test() = default;
|
---|
94 | };
|
---|
95 |
|
---|
96 | class vector_test: public test_suite
|
---|
97 | {
|
---|
98 | public:
|
---|
99 | bool run(bool) override;
|
---|
100 | const char* name() override;
|
---|
101 |
|
---|
102 | vector_test() = default;
|
---|
103 | ~vector_test() = default;
|
---|
104 |
|
---|
105 | private:
|
---|
106 | void test_construction_and_assignment();
|
---|
107 | void test_insert();
|
---|
108 | void test_erase();
|
---|
109 | };
|
---|
110 |
|
---|
111 | class string_test: public test_suite
|
---|
112 | {
|
---|
113 | public:
|
---|
114 | bool run(bool) override;
|
---|
115 | const char* name() override;
|
---|
116 |
|
---|
117 | private:
|
---|
118 | void test_construction_and_assignment();
|
---|
119 | void test_append();
|
---|
120 | void test_insert();
|
---|
121 | void test_erase();
|
---|
122 | void test_replace();
|
---|
123 | void test_copy();
|
---|
124 | void test_find();
|
---|
125 | void test_substr();
|
---|
126 | void test_compare();
|
---|
127 | };
|
---|
128 |
|
---|
129 | class bitset_test: public test_suite
|
---|
130 | {
|
---|
131 | public:
|
---|
132 | bool run(bool) override;
|
---|
133 | const char* name() override;
|
---|
134 |
|
---|
135 | private:
|
---|
136 | void test_constructors_and_assignment();
|
---|
137 | void test_strings();
|
---|
138 | void test_operations();
|
---|
139 | };
|
---|
140 |
|
---|
141 | class deque_test: public test_suite
|
---|
142 | {
|
---|
143 | public:
|
---|
144 | bool run(bool) override;
|
---|
145 | const char* name() override;
|
---|
146 |
|
---|
147 | private:
|
---|
148 | void test_constructors_and_assignment();
|
---|
149 | void test_resizing();
|
---|
150 | void test_push_pop();
|
---|
151 | void test_operations();
|
---|
152 | };
|
---|
153 |
|
---|
154 | class tuple_test: public test_suite
|
---|
155 | {
|
---|
156 | public:
|
---|
157 | bool run(bool) override;
|
---|
158 | const char* name() override;
|
---|
159 |
|
---|
160 | private:
|
---|
161 | void test_constructors_and_assignment();
|
---|
162 | void test_creation();
|
---|
163 | void test_tie_and_structured_bindings();
|
---|
164 | void test_tuple_ops();
|
---|
165 | };
|
---|
166 |
|
---|
167 | class map_test: public test_suite
|
---|
168 | {
|
---|
169 | public:
|
---|
170 | bool run(bool) override;
|
---|
171 | const char* name() override;
|
---|
172 |
|
---|
173 | private:
|
---|
174 | void test_constructors_and_assignment();
|
---|
175 | void test_histogram();
|
---|
176 | void test_emplace_insert();
|
---|
177 | void test_bounds_and_ranges();
|
---|
178 | void test_multi();
|
---|
179 | void test_reverse_iterators();
|
---|
180 | void test_multi_bounds_and_ranges();
|
---|
181 | };
|
---|
182 |
|
---|
183 | class set_test: public test_suite
|
---|
184 | {
|
---|
185 | public:
|
---|
186 | bool run(bool) override;
|
---|
187 | const char* name() override;
|
---|
188 |
|
---|
189 | private:
|
---|
190 | void test_constructors_and_assignment();
|
---|
191 | void test_emplace_insert();
|
---|
192 | void test_bounds_and_ranges();
|
---|
193 | void test_multi();
|
---|
194 | void test_reverse_iterators();
|
---|
195 | void test_multi_bounds_and_ranges();
|
---|
196 | };
|
---|
197 |
|
---|
198 | class unordered_map_test: public test_suite
|
---|
199 | {
|
---|
200 | public:
|
---|
201 | bool run(bool) override;
|
---|
202 | const char* name() override;
|
---|
203 |
|
---|
204 | private:
|
---|
205 | void test_constructors_and_assignment();
|
---|
206 | void test_histogram();
|
---|
207 | void test_emplace_insert();
|
---|
208 | void test_multi();
|
---|
209 | };
|
---|
210 |
|
---|
211 | class unordered_set_test: public test_suite
|
---|
212 | {
|
---|
213 | public:
|
---|
214 | bool run(bool) override;
|
---|
215 | const char* name() override;
|
---|
216 |
|
---|
217 | private:
|
---|
218 | void test_constructors_and_assignment();
|
---|
219 | void test_emplace_insert();
|
---|
220 | void test_multi();
|
---|
221 | };
|
---|
222 |
|
---|
223 | class numeric_test: public test_suite
|
---|
224 | {
|
---|
225 | public:
|
---|
226 | bool run(bool) override;
|
---|
227 | const char* name() override;
|
---|
228 |
|
---|
229 | private:
|
---|
230 | void test_algorithms();
|
---|
231 | void test_complex();
|
---|
232 | };
|
---|
233 |
|
---|
234 | class adaptors_test: public test_suite
|
---|
235 | {
|
---|
236 | public:
|
---|
237 | bool run(bool) override;
|
---|
238 | const char* name() override;
|
---|
239 |
|
---|
240 | private:
|
---|
241 | void test_queue();
|
---|
242 | void test_priority_queue();
|
---|
243 | void test_stack();
|
---|
244 | };
|
---|
245 |
|
---|
246 | class memory_test: public test_suite
|
---|
247 | {
|
---|
248 | public:
|
---|
249 | bool run(bool) override;
|
---|
250 | const char* name() override;
|
---|
251 |
|
---|
252 | private:
|
---|
253 | void test_unique_ptr();
|
---|
254 | };
|
---|
255 | }
|
---|
256 |
|
---|
257 | #endif
|
---|