| 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 |
|
|---|
| 142 | #endif
|
|---|