GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GTestCase.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GTestCase.hpp - Test case class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-2013 by Jean-Baptiste Cayrou *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GTestCase.hpp
23  * @brief Test case class interface definition
24  * @author Jean-Baptiste Cayrou
25  */
26 
27 #ifndef GTESTCASE_H
28 #define GTESTCASE_H
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GBase.hpp"
33 
34 
35 /***********************************************************************//**
36  * @class GTestCase
37  *
38  * @brief Test class
39  *
40  * This class implements a single test case result. It contains information
41  * about the test name, an optional message that is created in case of an
42  * error or a failure, a type information (containing usually the name of
43  * the class that is failing), and some information about the test duration.
44  * Furthermore, the test case knows whether the test succeeded or failed,
45  * and whether the test was an error or a failure test.
46  ***************************************************************************/
47 class GTestCase : public GBase {
48 
49 public:
50  // Public enumerators
51  enum ErrorKind {
54  };
55 
56  // Constructors and destructors
57  GTestCase(void);
58  GTestCase(const ErrorKind& kind, const std::string& name = "");
59  GTestCase(const GTestCase& test);
60  virtual ~GTestCase(void);
61 
62  // Operators
63  GTestCase& operator=(const GTestCase& test);
64 
65  // Methods
66  void clear(void);
67  GTestCase* clone(void) const;
68  std::string classname(void) const;
69  const std::string& name(void) const;
70  void name(const std::string& name);
71  const std::string& message(void) const;
72  void message( const std::string& message);
73  const std::string& type(void) const;
74  void type( const std::string& type);
75  const ErrorKind& kind(void) const;
76  void kind(const ErrorKind& kind);
77  const bool& has_passed(void) const;
78  void has_passed(const bool& has_passed);
79  const double& duration(void) const;
80  void duration(const double& duration);
81  std::string print(const GChatter& chatter = NORMAL) const;
82 
83 protected:
84  // Protected methods
85  void init_members(void);
86  void copy_members(const GTestCase& test);
87  void free_members(void);
88 
89  // Private members
90  std::string m_name; //!< Test name
91  std::string m_message; //!< Test message
92  std::string m_type; //!< Test type
93  bool m_has_passed; //!< Boolean to check test success
94  ErrorKind m_kind; //!< Kind of test case (failure or error test)
95  double m_duration; //!< Test duration
96 };
97 
98 
99 /***********************************************************************//**
100  * @brief Return class name
101  *
102  * @return String containing the class name ("GTestCase").
103  ***************************************************************************/
104 inline
105 std::string GTestCase::classname(void) const
106 {
107  return ("GTestCase");
108 }
109 
110 
111 /***********************************************************************//**
112  * @brief Return test case name
113  *
114  * @return Test case name.
115  ***************************************************************************/
116 inline
117 const std::string& GTestCase::name(void) const
118 {
119  return m_name;
120 }
121 
122 
123 /***********************************************************************//**
124  * @brief Set test case name
125  *
126  * @param[in] name Test case name.
127  ***************************************************************************/
128 inline
129 void GTestCase::name(const std::string& name)
130 {
131  m_name = name;
132  return;
133 }
134 
135 
136 /***********************************************************************//**
137  * @brief Return test case message
138  *
139  * @return Test case message.
140  ***************************************************************************/
141 inline
142 const std::string& GTestCase::message(void) const
143 {
144  return m_message;
145 }
146 
147 
148 /***********************************************************************//**
149  * @brief Set test case message
150  *
151  * @param[in] message Test case message.
152  ***************************************************************************/
153 inline
154 void GTestCase::message(const std::string& message)
155 {
156  m_message = message;
157  return;
158 }
159 
160 
161 /***********************************************************************//**
162  * @brief Return test case type
163  *
164  * @return Type of test case.
165  ***************************************************************************/
166 inline
167 const std::string& GTestCase::type(void) const
168 {
169  return m_type;
170 }
171 
172 
173 /***********************************************************************//**
174  * @brief Set type of test case
175  *
176  * @param[in] type Type of test case.
177  ***************************************************************************/
178 inline
179 void GTestCase::type(const std::string& type)
180 {
181  m_type = type;
182  return;
183 }
184 
185 
186 /***********************************************************************//**
187  * @brief Return kind of test case
188  *
189  * @return Test case kind (FAIL_TEST or ERROR_TEST).
190  *
191  * Returns whether this test case is for failure testing (FAIL_TEST) or
192  * error testing (ERROR_TEST).
193  ***************************************************************************/
194 inline
196 {
197  return m_kind;
198 }
199 
200 
201 /***********************************************************************//**
202  * @brief Set kind of test case
203  *
204  * @param[in] kind Kind of test case (FAIL_TEST or ERROR_TEST)
205  *
206  * Specifies whether this test case is for failure testing (FAIL_TEST) or
207  * error testing (ERROR_TEST).
208  ***************************************************************************/
209 inline
210 void GTestCase::kind(const ErrorKind& kind)
211 {
212  m_kind = kind;
213  return;
214 }
215 
216 
217 /***********************************************************************//**
218  * @brief Return whether the test passed
219  *
220  * @return True if test has passed, false otherwise.
221  *
222  * This method returns true if the test has passed, false otherwise.
223  ***************************************************************************/
224 inline
225 const bool& GTestCase::has_passed(void) const
226 {
227  return m_has_passed;
228 }
229 
230 
231 /***********************************************************************//**
232  * @brief Set if test passed
233  *
234  * @param[in] has_passed Test passed (true or false)
235  ***************************************************************************/
236 inline
237 void GTestCase::has_passed(const bool& has_passed)
238 {
240  return;
241 }
242 
243 
244 /***********************************************************************//**
245  * @brief Return test case duration
246  *
247  * @return Duration of test case.
248  ***************************************************************************/
249 inline
250 const double& GTestCase::duration(void) const
251 {
252  return m_duration;
253 }
254 
255 
256 /***********************************************************************//**
257  * @brief Set test duration
258  *
259  * @param[in] duration Test duration.
260  ***************************************************************************/
261 inline
262 void GTestCase::duration(const double& duration)
263 {
265  return;
266 }
267 
268 #endif /* GTESTCASE_H */
void init_members(void)
Initialise class members.
Definition: GTestCase.cpp:224
virtual ~GTestCase(void)
Destructor.
Definition: GTestCase.cpp:104
Test class.
Definition: GTestCase.hpp:47
Definition of interface for all GammaLib classes.
std::string m_message
Test message.
Definition: GTestCase.hpp:91
GTestCase * clone(void) const
Clone test case.
Definition: GTestCase.cpp:174
std::string m_type
Test type.
Definition: GTestCase.hpp:92
std::string m_name
Test name.
Definition: GTestCase.hpp:90
std::string classname(void) const
Return class name.
Definition: GTestCase.hpp:105
void clear(void)
Clear test case.
Definition: GTestCase.cpp:156
const ErrorKind & kind(void) const
Return kind of test case.
Definition: GTestCase.hpp:195
const double & duration(void) const
Return test case duration.
Definition: GTestCase.hpp:250
double m_duration
Test duration.
Definition: GTestCase.hpp:95
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
GChatter
Definition: GTypemaps.hpp:33
GTestCase(void)
Void constructor.
Definition: GTestCase.cpp:51
void copy_members(const GTestCase &test)
Copy class members.
Definition: GTestCase.cpp:246
GTestCase & operator=(const GTestCase &test)
Assignment operator.
Definition: GTestCase.cpp:126
const std::string & message(void) const
Return test case message.
Definition: GTestCase.hpp:142
const std::string & type(void) const
Return test case type.
Definition: GTestCase.hpp:167
const bool & has_passed(void) const
Return whether the test passed.
Definition: GTestCase.hpp:225
const std::string & name(void) const
Return test case name.
Definition: GTestCase.hpp:117
bool m_has_passed
Boolean to check test success.
Definition: GTestCase.hpp:93
void free_members(void)
Delete class members.
Definition: GTestCase.cpp:263
std::string print(const GChatter &chatter=NORMAL) const
Print test case result.
Definition: GTestCase.cpp:189
ErrorKind m_kind
Kind of test case (failure or error test)
Definition: GTestCase.hpp:94