[b9f897c] | 1 | /*
|
---|
[b96e87e] | 2 | * Copyright (c) 2019 Jaroslav Jindrak
|
---|
[b9f897c] | 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 |
|
---|
[b57a3ee] | 29 | #ifndef LIBCPP_BITS_TEST_TESTS
|
---|
| 30 | #define LIBCPP_BITS_TEST_TESTS
|
---|
[b9f897c] | 31 |
|
---|
[7bbf91e] | 32 | #include <__bits/test/test.hpp>
|
---|
[b57a3ee] | 33 | #include <cstdio>
|
---|
[471e313] | 34 | #include <vector>
|
---|
[b9f897c] | 35 |
|
---|
| 36 | namespace std::test
|
---|
| 37 | {
|
---|
[471e313] | 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 |
|
---|
[96ae12b] | 49 | bool run(bool report)
|
---|
[471e313] | 50 | {
|
---|
| 51 | bool res{true};
|
---|
| 52 | unsigned int succeeded{};
|
---|
| 53 | unsigned int failed{};
|
---|
| 54 |
|
---|
| 55 | for (auto test: tests_)
|
---|
| 56 | {
|
---|
[96ae12b] | 57 | res &= test->run(report);
|
---|
[471e313] | 58 | succeeded += test->get_succeeded();
|
---|
| 59 | failed += test->get_failed();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[96ae12b] | 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 | }
|
---|
[471e313] | 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 |
|
---|
[ad09a52] | 85 | class array_test: public test_suite
|
---|
| 86 | {
|
---|
| 87 | public:
|
---|
[96ae12b] | 88 | bool run(bool) override;
|
---|
[ad09a52] | 89 | const char* name() override;
|
---|
| 90 |
|
---|
| 91 | array_test() = default;
|
---|
| 92 | ~array_test() = default;
|
---|
| 93 | };
|
---|
| 94 |
|
---|
[b9f897c] | 95 | class vector_test: public test_suite
|
---|
| 96 | {
|
---|
| 97 | public:
|
---|
[96ae12b] | 98 | bool run(bool) override;
|
---|
[b9f897c] | 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 | };
|
---|
[ad09a52] | 109 |
|
---|
| 110 | class string_test: public test_suite
|
---|
| 111 | {
|
---|
| 112 | public:
|
---|
[96ae12b] | 113 | bool run(bool) override;
|
---|
[ad09a52] | 114 | const char* name() override;
|
---|
| 115 |
|
---|
| 116 | private:
|
---|
| 117 | void test_construction_and_assignment();
|
---|
[9315761] | 118 | void test_append();
|
---|
[d7f0b3f7] | 119 | void test_insert();
|
---|
[e502572b] | 120 | void test_erase();
|
---|
[d466d284] | 121 | void test_replace();
|
---|
[173a246] | 122 | void test_copy();
|
---|
[923b0c8f] | 123 | void test_find();
|
---|
[d49bae9] | 124 | void test_substr();
|
---|
[035a35c] | 125 | void test_compare();
|
---|
[ad09a52] | 126 | };
|
---|
[fceeb93] | 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 | };
|
---|
[c075647a] | 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 | };
|
---|
[f6f636f] | 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 | };
|
---|
[5608106c] | 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 | };
|
---|
[0fe0f32] | 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 | };
|
---|
[f2ba4c79] | 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();
|
---|
[323ae805] | 208 | };
|
---|
[f2ba4c79] | 209 |
|
---|
[323ae805] | 210 | class unordered_set_test: public test_suite
|
---|
| 211 | {
|
---|
| 212 | public:
|
---|
| 213 | bool run(bool) override;
|
---|
| 214 | const char* name() override;
|
---|
[f2ba4c79] | 215 |
|
---|
[323ae805] | 216 | private:
|
---|
| 217 | void test_constructors_and_assignment();
|
---|
| 218 | void test_emplace_insert();
|
---|
| 219 | void test_multi();
|
---|
[f2ba4c79] | 220 | };
|
---|
[ee8c5ec] | 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();
|
---|
[25709c3] | 230 | void test_complex();
|
---|
[ee8c5ec] | 231 | };
|
---|
[a4b8b28] | 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 | };
|
---|
[8349334] | 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();
|
---|
[bfc972e] | 253 | void test_shared_ptr();
|
---|
| 254 | void test_weak_ptr();
|
---|
| 255 | void test_allocators();
|
---|
| 256 | void test_pointers();
|
---|
[8349334] | 257 | };
|
---|
[2e53e83d] | 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();
|
---|
[c300bb5] | 267 | void test_modifiers();
|
---|
[2e53e83d] | 268 | };
|
---|
[4960254] | 269 |
|
---|
| 270 | class ratio_test: public test_suite
|
---|
| 271 | {
|
---|
| 272 | public:
|
---|
| 273 | bool run(bool) override;
|
---|
| 274 | const char* name() override;
|
---|
| 275 | };
|
---|
[69cc156] | 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 | };
|
---|
[09416c12] | 287 |
|
---|
| 288 | class algorithm_test: public test_suite
|
---|
| 289 | {
|
---|
| 290 | public:
|
---|
| 291 | bool run(bool) override;
|
---|
| 292 | const char* name() override;
|
---|
| 293 | private:
|
---|
| 294 | void test_non_modifying();
|
---|
[d9a9e7b] | 295 | void test_mutating();
|
---|
[09416c12] | 296 | };
|
---|
[b96e87e] | 297 |
|
---|
| 298 | class future_test: public test_suite
|
---|
| 299 | {
|
---|
| 300 | public:
|
---|
| 301 | bool run(bool) override;
|
---|
| 302 | const char* name() override;
|
---|
| 303 | private:
|
---|
| 304 | void test_future();
|
---|
| 305 | void test_promise();
|
---|
[8e24583] | 306 | void test_future_promise();
|
---|
[b96e87e] | 307 | void test_async();
|
---|
| 308 | void test_packaged_task();
|
---|
| 309 | void test_shared_future();
|
---|
| 310 | };
|
---|
[b9f897c] | 311 | }
|
---|
| 312 |
|
---|
| 313 | #endif
|
---|