GammaLib 2.0.0
Loading...
Searching...
No Matches
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 ***************************************************************************/
47class GTestCase : public GBase {
48
49public:
50 // Public enumerators
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
83protected:
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 ***************************************************************************/
104inline
105std::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 ***************************************************************************/
116inline
117const 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 ***************************************************************************/
128inline
129void 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 ***************************************************************************/
141inline
142const 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 ***************************************************************************/
153inline
154void GTestCase::message(const std::string& message)
155{
157 return;
158}
159
160
161/***********************************************************************//**
162 * @brief Return test case type
163 *
164 * @return Type of test case.
165 ***************************************************************************/
166inline
167const 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 ***************************************************************************/
178inline
179void 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 ***************************************************************************/
194inline
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 ***************************************************************************/
209inline
210void 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 ***************************************************************************/
224inline
225const 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 ***************************************************************************/
236inline
237void 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 ***************************************************************************/
249inline
250const 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 ***************************************************************************/
261inline
262void GTestCase::duration(const double& duration)
263{
265 return;
266}
267
268#endif /* GTESTCASE_H */
Definition of interface for all GammaLib classes.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Test class.
Definition GTestCase.hpp:47
void clear(void)
Clear test case.
const double & duration(void) const
Return test case duration.
const bool & has_passed(void) const
Return whether the test passed.
std::string m_message
Test message.
Definition GTestCase.hpp:91
void free_members(void)
Delete class members.
const ErrorKind & kind(void) const
Return kind of test case.
void copy_members(const GTestCase &test)
Copy class members.
std::string print(const GChatter &chatter=NORMAL) const
Print test case result.
GTestCase(void)
Void constructor.
Definition GTestCase.cpp:51
bool m_has_passed
Boolean to check test success.
Definition GTestCase.hpp:93
GTestCase * clone(void) const
Clone test case.
const std::string & name(void) const
Return test case name.
GTestCase & operator=(const GTestCase &test)
Assignment operator.
const std::string & type(void) const
Return test case type.
std::string classname(void) const
Return class name.
const std::string & message(void) const
Return test case message.
void init_members(void)
Initialise class members.
std::string m_type
Test type.
Definition GTestCase.hpp:92
double m_duration
Test duration.
Definition GTestCase.hpp:95
std::string m_name
Test name.
Definition GTestCase.hpp:90
virtual ~GTestCase(void)
Destructor.
ErrorKind m_kind
Kind of test case (failure or error test)
Definition GTestCase.hpp:94