Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / testframework / easyunit / testregistry.h
1 /*
2 EasyUnit : Simple C++ Unit testing framework
3 Copyright (C) 2004 Barthelemy Dagenais
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Barthelemy Dagenais
20 barthelemy@prologique.com
21 */
22
23 #ifndef TESTREGISTRY_H
24 #define TESTREGISTRY_H
25
26 #include "test.h"
27 #include "testcase.h"
28 #include "testprinter.h"
29 #include "simplestring.h"
30 #include "testrunner.h"
31 #include "testresult.h"
32
33
34 /**
35 * The TestRegistry is the main class used to register all tests,
36 * and create appropriate TestCase. It can then be used to run
37 * tests and print results. All methods that should be used by
38 * the user are static.
39 */
40 class TestRegistry
41 {
42 public:
43 TestRegistry();
44 ~TestRegistry();
45
46 /**
47 * Add a test in the registry. If the previous TestCase was not the same
48 * as the one of the current test, a new TestCase is created.
49 *
50 * @param test Test to be added
51 */
52 static void addTest (Test *test);
53
54 /**
55 * Run all tests in the registry (default test runner) and return
56 * the test results.
57 *
58 * @return The test results
59 */
60 static const TestResult* run();
61
62 /**
63 * Pass all tests in the registry to the TestRunner runner and
64 * return the results of all tests ran.
65 *
66 * @param runner The custom runner used to decided which test to run
67 * @return The test results of all tests ran
68 */
69 static const TestResult* run(TestRunner *runner);
70
71 /**
72 * Run all tests in the registry (default test runner) and return
73 * the test results. This will also print the results using the
74 * default test printer (normal level of details and to the standard
75 * output).
76 *
77 * @return The test results
78 */
79 static const TestResult* runAndPrint();
80
81 /**
82 * Pass all tests in the registry to the TestRunner runner and
83 * return the results of all tests ran. This will also print the results
84 * using the default test printer (normal level of details and to the
85 * standard output).
86 *
87 * @param runner The custom runner used to decided which test to run
88 * @return The test results
89 */
90 static const TestResult* runAndPrint(TestRunner *runner);
91
92 /**
93 * Run all tests in the registry (default test runner) and return
94 * the test results. Results will also be given to
95 * to the TestPrinter printer.
96 *
97 * @param printer The custom printer used to print the test results
98 * @return The test results
99 */
100 static const TestResult* runAndPrint(TestPrinter *printer);
101
102 /**
103 * Pass all tests in the registry to the TestRunner runner and
104 * return the results of all tests ran. Results will also be given to
105 * to the TestPrinter printer.
106 *
107 * @param printer The custom printer used to print the test results
108 * @param runner The custom runner used to decided which test to run
109 * @return The test results
110 */
111 static const TestResult* runAndPrint(TestPrinter *printer, TestRunner *runner);
112
113 private:
114 static TestRegistry& instance();
115 static int nextName;
116 void add(Test *test);
117 void addTestCase(TestCase *testCase);
118 const TestResult* runTests(TestRunner *runner);
119 TestCase *currentTC_;
120 TestPrinter *defaultPrinter_;
121 int testCaseCount_;
122 TestRunner *defaultRunner_;
123 TestResult testResult_;
124 };
125
126 #endif // TESTREGISTRY_H
127
128