testsuite.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2008 by Dr. Marc Boris Duerner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 #ifndef CXXTOOLS_UNIT_TESTSUITE_H
29 #define CXXTOOLS_UNIT_TESTSUITE_H
30 
31 #include <cxxtools/unit/test.h>
35 #include <vector>
36 #include <utility>
37 
38 namespace cxxtools {
39 
40  class SerializationInfo;
41 
42 namespace unit {
43 
75  class TestSuite : public Test
76  , public TestFixture
77  {
78  private:
79  class Context : public TestContext
80  {
81  public:
82  Context(TestFixture& fixture, TestMethod& test, const SerializationInfo* args, unsigned argCount)
83  : TestContext(fixture, test)
84  , _test(test)
85  , _args(args)
86  , _argCount(argCount)
87  {}
88 
89  virtual ~Context()
90  {}
91 
92  protected:
93  virtual void exec()
94  {
95  _test.exec(_args, _argCount);
96  }
97 
98  private:
99  TestMethod& _test;
100  const SerializationInfo* _args;
101  unsigned _argCount;
102  };
103 
104  public:
114  explicit TestSuite(const std::string& name, TestProtocol& protocol = TestSuite::defaultProtocol);
115 
116  ~TestSuite();
117 
119  virtual void setParameter(const std::string& name, const cxxtools::SerializationInfo& value);
120 
124  void setProtocol(TestProtocol* protocol);
125 
131  virtual void setUp();
132 
139  virtual void tearDown();
140 
146  virtual void run();
147 
159  void runTest( const std::string& name, const SerializationInfo* args = 0, size_t argCount = 0);
160 
161  void runAll();
162 
163  protected:
164  template <class ParentT>
165  void registerMethod(const std::string& name, ParentT& parent, void (ParentT::*method)() )
166  {
167  cxxtools::unit::TestMethod* test = new BasicTestMethod<ParentT>(this->name() + "::" + name, parent, method);
168  this->registerTest(test);
169  }
170 
171  template <class ParentT, typename A1>
172  void registerMethod(const std::string& name, ParentT& parent, void (ParentT::*method)(A1) )
173  {
174  cxxtools::unit::TestMethod* test = new BasicTestMethod<ParentT, A1>(this->name() + "::" + name, parent, method);
175  this->registerTest(test);
176  }
177 
178  template <class ParentT, typename A1, typename A2>
179  void registerMethod(const std::string& name, ParentT& parent, void (ParentT::*method)(A1, A2) )
180  {
181  cxxtools::unit::TestMethod* test = new BasicTestMethod<ParentT, A1, A2>(this->name() + "::" + name, parent, method);
182  this->registerTest(test);
183  }
184 
185  template <class ParentT, typename A1, typename A2, typename A3>
186  void registerMethod(const std::string& name, ParentT& parent, void (ParentT::*method)(A1, A2, A3) )
187  {
188  cxxtools::unit::TestMethod* test = new BasicTestMethod<ParentT, A1, A2, A3>(this->name() + "::" + name, parent, method);
189  this->registerTest(test);
190  }
191 
192  template <class ParentT, typename A1, typename A2, typename A3, typename A4>
193  void registerMethod(const std::string& name, ParentT& parent, void (ParentT::*method)(A1, A2, A3, A4) )
194  {
196  this->registerTest(test);
197  }
198 
199  template <class ParentT, typename A1, typename A2, typename A3, typename A4, typename A5>
200  void registerMethod(const std::string& name, ParentT& parent, void (ParentT::*method)(A1, A2, A3, A4, A5) )
201  {
203  this->registerTest(test);
204  }
205 
206  private:
207  void registerTest(TestMethod* test);
208 
209  TestMethod* findTest(const std::string& name);
210 
213  TestProtocol* _protocol;
214 
215  typedef std::vector<std::pair<std::string, TestMethod*> > Tests;
216  Tests _tests;
217 
218  public:
220  };
221 
222 } // namespace unit
223 
224 } // namespace cxxtools
225 
226 #endif // for header
227