[b9f897c] | 1 | /*
|
---|
[96ae12b] | 2 | * Copyright (c) 2018 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 |
|
---|
[ad09a52] | 29 | #ifndef LIBCPP_TESTS
|
---|
| 30 | #define LIBCPP_TESTS
|
---|
[b9f897c] | 31 |
|
---|
[471e313] | 32 | #include <cstdio>
|
---|
[b9f897c] | 33 | #include <internal/test/test.hpp>
|
---|
[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 | // TODO: Gimme unique_ptr!
|
---|
| 79 | for (auto ptr: tests_)
|
---|
| 80 | delete ptr;
|
---|
| 81 | }
|
---|
| 82 | private:
|
---|
| 83 | std::vector<test_suite*> tests_{};
|
---|
| 84 | };
|
---|
| 85 |
|
---|
[ad09a52] | 86 | class array_test: public test_suite
|
---|
| 87 | {
|
---|
| 88 | public:
|
---|
[96ae12b] | 89 | bool run(bool) override;
|
---|
[ad09a52] | 90 | const char* name() override;
|
---|
| 91 |
|
---|
| 92 | array_test() = default;
|
---|
| 93 | ~array_test() = default;
|
---|
| 94 | };
|
---|
| 95 |
|
---|
[b9f897c] | 96 | class vector_test: public test_suite
|
---|
| 97 | {
|
---|
| 98 | public:
|
---|
[96ae12b] | 99 | bool run(bool) override;
|
---|
[b9f897c] | 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 | };
|
---|
[ad09a52] | 110 |
|
---|
| 111 | class string_test: public test_suite
|
---|
| 112 | {
|
---|
| 113 | public:
|
---|
[96ae12b] | 114 | bool run(bool) override;
|
---|
[ad09a52] | 115 | const char* name() override;
|
---|
| 116 |
|
---|
| 117 | private:
|
---|
| 118 | void test_construction_and_assignment();
|
---|
[9315761] | 119 | void test_append();
|
---|
[d7f0b3f7] | 120 | void test_insert();
|
---|
[e502572b] | 121 | void test_erase();
|
---|
[d466d284] | 122 | void test_replace();
|
---|
[173a246] | 123 | void test_copy();
|
---|
[923b0c8f] | 124 | void test_find();
|
---|
[d49bae9] | 125 | void test_substr();
|
---|
[035a35c] | 126 | void test_compare();
|
---|
[ad09a52] | 127 | };
|
---|
[fceeb93] | 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 | };
|
---|
[c075647a] | 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 | };
|
---|
[f6f636f] | 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 | };
|
---|
[5608106c] | 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 | };
|
---|
[0fe0f32] | 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 | };
|
---|
[f2ba4c79] | 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();
|
---|
[323ae805] | 209 | };
|
---|
[f2ba4c79] | 210 |
|
---|
[323ae805] | 211 | class unordered_set_test: public test_suite
|
---|
| 212 | {
|
---|
| 213 | public:
|
---|
| 214 | bool run(bool) override;
|
---|
| 215 | const char* name() override;
|
---|
[f2ba4c79] | 216 |
|
---|
[323ae805] | 217 | private:
|
---|
| 218 | void test_constructors_and_assignment();
|
---|
| 219 | void test_emplace_insert();
|
---|
| 220 | void test_multi();
|
---|
[f2ba4c79] | 221 | };
|
---|
[ee8c5ec] | 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();
|
---|
[25709c3] | 231 | void test_complex();
|
---|
[ee8c5ec] | 232 | };
|
---|
[a4b8b28] | 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 | };
|
---|
[8349334] | 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 | };
|
---|
[b9f897c] | 255 | }
|
---|
| 256 |
|
---|
| 257 | #endif
|
---|