CppTest home page CppTest project page

cpptest-suite.h
Go to the documentation of this file.
1 // ---
2 //
3 // $Id: cpptest-suite.h,v 1.3 2005/06/08 08:08:06 nilu 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 
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 
38 namespace Test
39 {
40  class Output;
41 
51  class Suite
52  {
53  public:
54  Suite();
55  virtual ~Suite();
56 
57  void add(std::auto_ptr<Suite> suite);
58 
59  bool run(Output& output, bool cont_after_fail = true);
60 
61  protected:
64  typedef void (Suite::*Func)();
65 
66  bool continue_after_failure() const { return _continue; }
67 
68  virtual void setup() {}
69  virtual void tear_down() {}
70 
71  void register_test(Func func, const std::string& name);
72  void assertment(Source s);
73 
74  private:
75  struct DoRun;
76  struct ExecTests;
77  struct SubSuiteTests;
78  struct SuiteTime;
79  struct SubSuiteTime;
80 
81  friend struct DoRun;
82  friend struct ExecTests;
83  friend struct SubSuiteTests;
84  friend struct SubSuiteTime;
85 
86  struct Data
87  {
88  Func _func;
89  std::string _name;
90  Time _time;
91 
92  Data(Func func, const std::string& name)
93  : _func(func), _name(name) {}
94  };
95 
96  typedef std::list<Data> Tests;
97  typedef std::list<Suite*> Suites;
98 
99  std::string _name; // Suite name
100  const std::string* _cur_test; // Current test func name
101  Suites _suites; // External test suites
102  Tests _tests; // All tests
103  Output* _output; // Output handler
104  bool _result : 1; // Test result
105  bool _success : 1; // Set if no test failed
106  bool _continue : 1; // Continue func after failures
107 
108  void do_run(Output* os, bool cont_after_fail);
109  int total_tests() const;
110  Time total_time(bool recursive) const;
111 
112  // Disable
113  //
114  Suite(const Suite&);
115  Suite& operator=(const Suite&);
116  };
117 
133  #define TEST_ADD(func)\
134  register_test(static_cast<Func>(&func), #func);
135 
136 } // namespace Test
137 
138 #endif // #ifndef CPPTEST_SUITE_H
139 
virtual void tear_down()
Definition: cpptest-suite.h:69
void(Suite::* Func)()
Definition: cpptest-suite.h:64
Time representation.
Definition: cpptest-time.h:43
Assertment source information.
Definition: cpptest-source.h:42
void add(std::auto_ptr< Suite > suite)
Definition: suite.cpp:120
virtual void setup()
Definition: cpptest-suite.h:68
void register_test(Func func, const std::string &name)
Definition: suite.cpp:135
void assertment(Source s)
Definition: suite.cpp:152
virtual ~Suite()
Definition: suite.cpp:71
Definition: collectoroutput.cpp:37
Unit testing suite.
Definition: cpptest-suite.h:51
Test suite output handler.
Definition: cpptest-output.h:55
bool run(Output &output, bool cont_after_fail=true)
Definition: suite.cpp:85
Suite()
Definition: suite.cpp:63

Supported by:

SourceForge Logo