Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00029 #ifndef CPPTEST_SUITE_H
00030 #define CPPTEST_SUITE_H
00031
00032 #include <list>
00033 #include <memory>
00034 #include <string>
00035
00036 #include "cpptest-time.h"
00037
00038 namespace Test
00039 {
00040 class Output;
00041
00051 class Suite
00052 {
00053 public:
00054 Suite();
00055 virtual ~Suite();
00056
00057 void add(std::auto_ptr<Suite> suite);
00058
00059 bool run(Output& output, bool cont_after_fail = true);
00060
00061 protected:
00064 typedef void (Suite::*Func)();
00065
00066 bool continue_after_failure() const { return _continue; }
00067
00068 virtual void setup() {}
00069 virtual void tear_down() {}
00070
00071 void register_test(Func func, const std::string& name);
00072 void assertment(Source s);
00073
00074 private:
00075 struct DoRun;
00076 struct ExecTests;
00077 struct SubSuiteTests;
00078 struct SuiteTime;
00079 struct SubSuiteTime;
00080
00081 friend struct DoRun;
00082 friend struct ExecTests;
00083 friend struct SubSuiteTests;
00084 friend struct SubSuiteTime;
00085
00086 struct Data
00087 {
00088 Func _func;
00089 std::string _name;
00090 Time _time;
00091
00092 Data(Func func, const std::string& name)
00093 : _func(func), _name(name) {}
00094 };
00095
00096 typedef std::list<Data> Tests;
00097 typedef std::list<Suite*> Suites;
00098
00099 std::string _name;
00100 const std::string* _cur_test;
00101 Suites _suites;
00102 Tests _tests;
00103 Output* _output;
00104 bool _result : 1;
00105 bool _success : 1;
00106 bool _continue : 1;
00107
00108 void do_run(Output* os, bool cont_after_fail);
00109 int total_tests() const;
00110 Time total_time(bool recursive) const;
00111
00112
00113
00114 Suite(const Suite&);
00115 Suite& operator=(const Suite&);
00116 };
00117
00133 #define TEST_ADD(func)\
00134 register_test(static_cast<Func>(&func), #func);
00135
00136 }
00137
00138 #endif // #ifndef CPPTEST_SUITE_H
00139