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 #include "cpptest-source.h"
00038
00039 namespace Test
00040 {
00041 class Output;
00042
00052 class Suite
00053 {
00054 public:
00055 Suite();
00056 virtual ~Suite();
00057
00058 void add(std::auto_ptr<Suite> suite);
00059
00060 bool run(Output& output, bool cont_after_fail = true);
00061
00062 protected:
00065 typedef void (Suite::*Func)();
00066
00067 bool continue_after_failure() const { return _continue; }
00068
00069 virtual void setup() {}
00070 virtual void tear_down() {}
00071
00072 void register_test(Func func, const std::string& name);
00073 void assertment(Source s);
00074
00075 private:
00076 struct DoRun;
00077 struct ExecTests;
00078 struct SubSuiteTests;
00079 struct SuiteTime;
00080 struct SubSuiteTime;
00081
00082 friend struct DoRun;
00083 friend struct ExecTests;
00084 friend struct SubSuiteTests;
00085 friend struct SubSuiteTime;
00086
00087 struct Data
00088 {
00089 Func _func;
00090 std::string _name;
00091 Time _time;
00092
00093 Data(Func func, const std::string& name)
00094 : _func(func), _name(name) {}
00095 };
00096
00097 typedef std::list<Data> Tests;
00098 typedef std::list<Suite*> Suites;
00099
00100 std::string _name;
00101 const std::string* _cur_test;
00102 Suites _suites;
00103 Tests _tests;
00104 Output* _output;
00105 bool _result : 1;
00106 bool _success : 1;
00107 bool _continue : 1;
00108
00109 void do_run(Output* os, bool cont_after_fail);
00110 int total_tests() const;
00111 Time total_time(bool recursive) const;
00112
00113
00114
00115 Suite(const Suite&);
00116 Suite& operator=(const Suite&);
00117 };
00118
00134 #define TEST_ADD(func)\
00135 register_test(static_cast<Func>(&func), #func);
00136
00137 }
00138
00139 #endif // #ifndef CPPTEST_SUITE_H
00140