GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GTestCase.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GTestCase.cpp - 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.cpp
23  * @brief Test Case class implementation
24  * @author Jean-Baptiste Cayrou
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GTestCase.hpp"
32 
33 /* __ Method name definitions ____________________________________________ */
34 
35 /* __ Macros _____________________________________________________________ */
36 
37 /* __ Coding definitions _________________________________________________ */
38 
39 /* __ Debug definitions __________________________________________________ */
40 
41 
42 /*==========================================================================
43  = =
44  = Constructors/destructors =
45  = =
46  ==========================================================================*/
47 
48 /***********************************************************************//**
49  * @brief Void constructor
50  ***************************************************************************/
52 {
53  // Initialise members
54  init_members();
55 
56  // Return
57  return;
58 }
59 
60 
61 /***********************************************************************//**
62  * @brief Type and name constructor
63  *
64  * @param[in] kind Test kind (FAIL_TEST or ERROR_TEST)
65  * @param[in] name Test case name (default: "")
66  ***************************************************************************/
67 GTestCase::GTestCase(const ErrorKind& kind, const std::string& name)
68 {
69  // Initialise members
70  init_members();
71 
72  // Set kind
73  m_kind = kind;
74 
75  // Set name
76  m_name = name;
77 
78  // Return
79  return;
80 }
81 
82 
83 /***********************************************************************//**
84  * @brief Copy constructor
85  *
86  * @param[in] test Test case.
87  ***************************************************************************/
89 {
90  // Initialise members
91  init_members();
92 
93  // Copy members
94  copy_members(test);
95 
96  // Return
97  return;
98 }
99 
100 
101 /***********************************************************************//**
102  * @brief Destructor
103  ***************************************************************************/
105 {
106  // Free members
107  free_members();
108 
109  // Return
110  return;
111 }
112 
113 
114 /*==========================================================================
115  = =
116  = Operators =
117  = =
118  ==========================================================================*/
119 
120 /***********************************************************************//**
121  * @brief Assignment operator
122  *
123  * @param[in] test Test case.
124  * @return Test case.
125  ***************************************************************************/
127 {
128  // Execute only if object is not identical
129  if (this != &test) {
130 
131  // Free members
132  free_members();
133 
134  // Initialise members
135  init_members();
136 
137  // Copy members
138  copy_members(test);
139 
140  } // endif: object was not identical
141 
142  // Return
143  return *this;
144 }
145 
146 
147 /*==========================================================================
148  = =
149  = Public methods =
150  = =
151  ==========================================================================*/
152 
153 /***********************************************************************//**
154  * @brief Clear test case
155  ***************************************************************************/
157 {
158  // Free members
159  free_members();
160 
161  // Initialise private members
162  init_members();
163 
164  // Return
165  return;
166 }
167 
168 
169 /***********************************************************************//**
170  * @brief Clone test case
171  *
172  * @return Pointer to deep copy of test case.
173  ***************************************************************************/
175 {
176  // Clone this image
177  return new GTestCase(*this);
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Print test case result
183  *
184  * @param[in] chatter Chattiness (defaults to NORMAL).
185  * @return String containing test case information.
186  *
187  * Returns either ".", "F" or "E", dependent on the test result.
188  ***************************************************************************/
189 std::string GTestCase::print(const GChatter& chatter) const
190 {
191  // Initialize string
192  std::string result;
193 
194  // Continue only if chatter is not silent
195  if (chatter != SILENT) {
196 
197  // Set string dependent on test result
198  if (m_has_passed) {
199  result.append(".");
200  }
201  else if (m_kind == ERROR_TEST) {
202  result.append("E");
203  }
204  else {
205  result.append("F");
206  }
207 
208  } // endif: chatter was not silent
209 
210  // Return result
211  return result;
212 }
213 
214 
215 /*==========================================================================
216  = =
217  = Private methods =
218  = =
219  ==========================================================================*/
220 
221 /***********************************************************************//**
222  * @brief Initialise class members
223  ***************************************************************************/
225 {
226  // Initialise members
227  m_name = "Unnamed Error Test Case";
228  m_message = "";
229  m_type = "";
230  m_has_passed = true;
231  m_kind = ERROR_TEST;
232  m_duration = 0.0;
233 
234  // Return
235  return;
236 }
237 
238 
239 /***********************************************************************//**
240  * @brief Copy class members
241  *
242  * @param[in] test Test case.
243  *
244  * Copies all members from the test case class.
245  ***************************************************************************/
247 {
248  // Copy members
249  m_name = test.m_name;
250  m_message = test.m_message;
251  m_type = test.m_type;
252  m_has_passed = test.m_has_passed;
253  m_kind = test.m_kind;
254  m_duration = test.m_duration;
255 
256  // Return
257  return;
258 }
259 
260 /***********************************************************************//**
261  * @brief Delete class members
262  ***************************************************************************/
264 {
265  // Return
266  return;
267 }
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
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
void clear(void)
Clear test case.
Definition: GTestCase.cpp:156
const ErrorKind & kind(void) const
Return kind of test case.
Definition: GTestCase.hpp:195
double m_duration
Test duration.
Definition: GTestCase.hpp:95
Test case class interface definition.
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 & 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