Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / API_CppTest / INC / cpptest-suite.h
1 // ---
2 //
3 // $Id: cpptest-suite.h,v 1.4 2010/03/26 04:45:14 hartwork Exp $
4 //
5 // CppTest - A C++ Unit Testing Framework
6 // Copyright (c) 2003 Niklas Lundell
7 //
8 // ---
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
24 //
25 // ---
26
27 /** \file */
28
29 #ifndef CPPTEST_SUITE_H
30 #define CPPTEST_SUITE_H
31
32 #include <list>
33 #include <memory>
34 #include <string>
35
36 #include "cpptest-time.h"
37 #include "cpptest-source.h"
38
39 namespace Test
40 {
41 class Output;
42
43 /// \brief Unit testing suite.
44 ///
45 /// Base class for all suites. Derive from this class to create own
46 /// test suites.
47 ///
48 /// %Test functions in derived classes are registered as tests using the
49 /// TEST_ADD(func). Testing is started by run(). Note that suites may be
50 /// embedded in other suites using add().
51 ///
52 class Suite
53 {
54 public:
55 Suite();
56 virtual ~Suite();
57
58 void add(std::auto_ptr<Suite> suite);
59
60 bool run(Output& output, bool cont_after_fail = true);
61
62 protected:
63 /// Pointer to a test function.
64 ///
65 typedef void (Suite::*Func)();
66
67 bool continue_after_failure() const { return _continue; }
68
69 virtual void setup() {}
70 virtual void tear_down() {}
71
72 void register_test(Func func, const std::string& name);
73 void assertment(Source s);
74
75 private:
76 struct DoRun;
77 struct ExecTests;
78 struct SubSuiteTests;
79 struct SuiteTime;
80 struct SubSuiteTime;
81
82 friend struct DoRun;
83 friend struct ExecTests;
84 friend struct SubSuiteTests;
85 friend struct SubSuiteTime;
86
87 struct Data
88 {
89 Func _func;
90 std::string _name;
91 Time _time;
92
93 Data(Func func, const std::string& name)
94 : _func(func), _name(name) {}
95 };
96
97 typedef std::list<Data> Tests;
98 typedef std::list<Suite*> Suites;
99
100 std::string _name; // Suite name
101 const std::string* _cur_test; // Current test func name
102 Suites _suites; // External test suites
103 Tests _tests; // All tests
104 Output* _output; // Output handler
105 bool _result : 1; // Test result
106 bool _success : 1; // Set if no test failed
107 bool _continue : 1; // Continue func after failures
108
109 void do_run(Output* os, bool cont_after_fail);
110 int total_tests() const;
111 Time total_time(bool recursive) const;
112
113 // Disable
114 //
115 Suite(const Suite&);
116 Suite& operator=(const Suite&);
117 };
118
119 /// Adds a test function to the enclosing suite. Note that test functions
120 /// should be added in the suites constructor.
121 ///
122 /// \param func Function to add, must be of type Suite::Func.
123 ///
124 /// \par Example:
125 /// \code
126 /// MySuite::MySuite()
127 /// {
128 /// TEST_ADD(&MySuite::test_1)
129 /// TEST_ADD(&MySuite::test_2)
130 /// ...
131 /// }
132 /// \endcode
133 ///
134 #define TEST_ADD(func)\
135 register_test(static_cast<Func>(&func), #func);
136
137 } // namespace Test
138
139 #endif // #ifndef CPPTEST_SUITE_H
140