testmethod.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2006 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_TESTMETHOD_H
29 #define CXXTOOLS_UNIT_TESTMETHOD_H
30 
31 #include <cxxtools/unit/test.h>
32 #include <stdexcept>
33 #include <cstddef>
34 
35 namespace cxxtools {
36 
37  class SerializationInfo;
38 
39 namespace unit {
40 
42  {
43  public:
44  TestMethod(const std::string& name)
45  : cxxtools::unit::Test(name)
46  {}
47 
48  virtual ~TestMethod()
49  {}
50 
51  virtual void run()
52  {}
53 
54  virtual void exec(const SerializationInfo* si, unsigned argCount) = 0;
55  };
56 
57 
58  template < class C,
59  typename A1 = cxxtools::Void,
60  typename A2 = cxxtools::Void,
61  typename A3 = cxxtools::Void,
62  typename A4 = cxxtools::Void,
63  typename A5 = cxxtools::Void,
64  typename A6 = cxxtools::Void,
65  typename A7 = cxxtools::Void,
66  typename A8 = cxxtools::Void >
67  class BasicTestMethod : public cxxtools::Method<void, C, A1, A2, A3, A4, A5, A6, A7, A8>
68  , public TestMethod
69  {
70  public:
71  typedef C ClassT;
72  typedef void (C::*MemFuncT)(A1, A2, A3, A4, A5, A6, A7, A8);
73 
74  public:
75  BasicTestMethod(const std::string& name, C& object, MemFuncT ptr)
76  : cxxtools::Method<void, C, A1, A2, A3, A4, A5, A6, A7, A8>(object, ptr)
77  , TestMethod(name)
78  {}
79 
80  void exec(const SerializationInfo* args, unsigned argCount)
81  {
82  throw std::logic_error("SerializationInfo not implemented");
83  }
84 
85  virtual void run()
86  {}
87  };
88 
89 
90  template < class C >
91  class BasicTestMethod<C,
92  cxxtools::Void,
99  cxxtools::Void> : public cxxtools::Method<void, C>
100  , public TestMethod
101  {
102  public:
103  typedef C ClassT;
104  typedef void (C::*MemFuncT)();
105 
106  public:
107  BasicTestMethod(const std::string& name, C& object, MemFuncT ptr)
108  : cxxtools::Method<void, C>(object, ptr)
109  , TestMethod(name)
110  {}
111 
112  void exec(const SerializationInfo* si, unsigned argCount)
113  {
114  cxxtools::Method<void, C>::call();
115  }
116 
117  virtual void run()
118  {}
119  };
120 
121 } // namespace unit
122 
123 } // namespace cxxtools
124 
125 #endif // for header
126