Line data Source code
1 : /*
2 : * File: TestFBProblemRunner.cpp
3 : * Author: Pantelis Sopasakis
4 : *
5 : * Created on Apr 17, 2016, 12:25:58 PM
6 : *
7 : * ForBES is free software: you can redistribute it and/or modify
8 : * it under the terms of the GNU Lesser General Public License as published by
9 : * the Free Software Foundation, either version 3 of the License, or
10 : * (at your option) any later version.
11 : *
12 : * ForBES is distributed in the hope that it will be useful,
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : * GNU Lesser General Public License for more details.
16 : *
17 : * You should have received a copy of the GNU Lesser General Public License
18 : * along with ForBES. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : // CppUnit site http://sourceforge.net/projects/cppunit/files
22 :
23 : #include <cppunit/BriefTestProgressListener.h>
24 : #include <cppunit/CompilerOutputter.h>
25 : #include <cppunit/extensions/TestFactoryRegistry.h>
26 : #include <cppunit/TestResult.h>
27 : #include <cppunit/TestResultCollector.h>
28 : #include <cppunit/TestRunner.h>
29 :
30 : #include <cppunit/Test.h>
31 : #include <cppunit/TestFailure.h>
32 : #include <cppunit/portability/Stream.h>
33 :
34 : class ProgressListener : public CPPUNIT_NS::TestListener {
35 : public:
36 :
37 1 : ProgressListener()
38 1 : : m_lastTestFailed(false) {
39 1 : }
40 :
41 1 : ~ProgressListener() {
42 1 : }
43 :
44 1 : void startTest(CPPUNIT_NS::Test *test) {
45 1 : CPPUNIT_NS::stdCOut() << test->getName();
46 1 : CPPUNIT_NS::stdCOut() << "\n";
47 1 : CPPUNIT_NS::stdCOut().flush();
48 :
49 1 : m_lastTestFailed = false;
50 1 : }
51 :
52 0 : void addFailure(const CPPUNIT_NS::TestFailure &failure) {
53 0 : CPPUNIT_NS::stdCOut() << " : " << (failure.isError() ? "error" : "assertion");
54 0 : m_lastTestFailed = true;
55 0 : }
56 :
57 1 : void endTest(CPPUNIT_NS::Test *test) {
58 1 : if (!m_lastTestFailed)
59 1 : CPPUNIT_NS::stdCOut() << " : OK";
60 1 : CPPUNIT_NS::stdCOut() << "\n";
61 1 : }
62 :
63 : private:
64 : /// Prevents the use of the copy constructor.
65 : ProgressListener(const ProgressListener ©);
66 :
67 : /// Prevents the use of the copy operator.
68 : void operator=(const ProgressListener ©);
69 :
70 : private:
71 : bool m_lastTestFailed;
72 : };
73 :
74 1 : int main() {
75 : // Create the event manager and test controller
76 1 : CPPUNIT_NS::TestResult controller;
77 :
78 : // Add a listener that colllects test result
79 2 : CPPUNIT_NS::TestResultCollector result;
80 1 : controller.addListener(&result);
81 :
82 : // Add a listener that print dots as test run.
83 2 : ProgressListener progress;
84 1 : controller.addListener(&progress);
85 :
86 : // Add the top suite to the test runner
87 2 : CPPUNIT_NS::TestRunner runner;
88 1 : runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
89 1 : runner.run(controller);
90 :
91 : // Print test in a compiler compatible format.
92 2 : CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut());
93 1 : outputter.write();
94 :
95 2 : return result.wasSuccessful() ? 0 : 1;
96 3 : }
|