source: mainline/uspace/lib/cpp/include/internal/test/tests.hpp@ edbad13a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since edbad13a was 471e313, checked in by Dzejrou <dzejrou@…>, 7 years ago

cpp: added a test set that allows us to run tests and gather summary statistics about their results and then report those

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[b9f897c]1/*
2 * Copyright (c) 2017 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
[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
36namespace 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
49 bool run()
50 {
51 bool res{true};
52 unsigned int succeeded{};
53 unsigned int failed{};
54
55 for (auto test: tests_)
56 {
57 res &= test->run();
58 succeeded += test->get_succeeded();
59 failed += test->get_failed();
60 }
61
62 std::printf("\n");
63 if (res)
64 std::printf("[TESTS SUCCEEDED!]");
65 else
66 std::printf("[TESTS FAILED]");
67 std::printf("[%u OK][%u FAIL][%u TOTAL]\n",
68 succeeded, failed, (succeeded + failed));
69
70 return res;
71 }
72
73 ~test_set()
74 {
75 // TODO: Gimme unique_ptr!
76 for (auto ptr: tests_)
77 delete ptr;
78 }
79 private:
80 std::vector<test_suite*> tests_{};
81 };
82
[ad09a52]83 class array_test: public test_suite
84 {
85 public:
86 bool run() override;
87 const char* name() override;
88
89 array_test() = default;
90 ~array_test() = default;
91 };
92
[b9f897c]93 class vector_test: public test_suite
94 {
95 public:
96 bool run() override;
97 const char* name() override;
98
99 vector_test() = default;
100 ~vector_test() = default;
101
102 private:
103 void test_construction_and_assignment();
104 void test_insert();
105 void test_erase();
106 };
[ad09a52]107
108 class string_test: public test_suite
109 {
110 public:
111 bool run() override;
112 const char* name() override;
113
114 private:
115 void test_construction_and_assignment();
[9315761]116 void test_append();
[d7f0b3f7]117 void test_insert();
[e502572b]118 void test_erase();
[d466d284]119 void test_replace();
[173a246]120 void test_copy();
[923b0c8f]121 void test_find();
[d49bae9]122 void test_substr();
[035a35c]123 void test_compare();
[ad09a52]124 };
[b9f897c]125}
126
127#endif
Note: See TracBrowser for help on using the repository browser.