GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GTestSuites.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GTestSuites.hpp - Test suite container class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-2016 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 GTestSuites.hpp
23  * @brief Test suite container class interface definition
24  * @author Jean-Baptiste Cayrou
25  */
26 
27 #ifndef GTESTSUITES_HPP
28 #define GTESTSUITES_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GContainer.hpp"
34 #include "GLog.hpp"
35 #include "GTestSuite.hpp"
36 
37 /* __ Forward declarations _______________________________________________ */
38 class GFilename;
39 class GXml;
40 
41 
42 /***********************************************************************//**
43  * @class GTestSuites
44  *
45  * @brief Test suite container class
46  *
47  * This is a container class for test suites. All test suites will be
48  * executed by invoking the run() method, and test results are saved in
49  * JUnit format to an XML file using the save() method.
50  *
51  * @todo Provide detailed description
52  ***************************************************************************/
53 class GTestSuites : public GContainer {
54 
55 public:
56  // Constructors and destructors
57  GTestSuites(void);
58  GTestSuites(const GTestSuites& suites);
59  explicit GTestSuites(const std::string& name);
60  virtual ~GTestSuites(void);
61 
62  // Operators
63  GTestSuites& operator=(const GTestSuites& suites);
64  GTestSuite* operator[](const int& index);
65  const GTestSuite* operator[](const int& index) const;
66 
67  // Methods
68  void clear(void);
69  GTestSuites* clone(void) const;
70  std::string classname(void) const;
71  GTestSuite* at(const int& index);
72  const GTestSuite* at(const int& index) const;
73  int size(void) const;
74  bool is_empty(void) const;
75  GTestSuite* set(const int& index, const GTestSuite& suite);
76  GTestSuite* append(const GTestSuite& suite);
77  GTestSuite* insert(const int& index, const GTestSuite& suite);
78  void remove(const int& index);
79  void reserve(const int& num);
80  void extend(const GTestSuites& suites);
81  const std::string& name(void) const;
82  void name(const std::string& name);
83  void cout(const bool& flag);
84  int errors(void) const;
85  int failures(void) const;
86  int tests(void) const;
87  const time_t& timestamp(void) const;
88  bool run(void);
89  void save(const GFilename& filename) const;
90  std::string print(const GChatter& chatter = NORMAL) const;
91 
92 protected:
93  // Protected methods
94  void init_members(void);
95  void copy_members(const GTestSuites& suites);
96  void free_members(void);
97  void write(GXml& xml) const;
98 
99  // Protected members
100  std::string m_name; //!< Name of container
101  std::vector<GTestSuite*> m_testsuites; //!< Vector of test suites
102  time_t m_timestamp; //!< Timestamp
103  GLog m_log; //!< Log
104 };
105 
106 
107 /***********************************************************************//**
108  * @brief Return class name
109  *
110  * @return String containing the class name ("GTestSuites").
111  ***************************************************************************/
112 inline
113 std::string GTestSuites::classname(void) const
114 {
115  return ("GTestSuites");
116 }
117 
118 
119 /***********************************************************************//**
120  * @brief Returns pointer to test suite
121  *
122  * @param[in] index Test suite index [0,...,size()-1].
123  * @return Pointer to test suite.
124  *
125  * Returns pointer to test suite with @p index. No range checking is done
126  * for the index.
127  ***************************************************************************/
128 inline
130 {
131  return (m_testsuites[index]);
132 }
133 
134 
135 /***********************************************************************//**
136  * @brief Returns pointer to test suite (const version)
137  *
138  * @param[in] index Test suite index [0,...,size()-1].
139  * @return Pointer to test suite.
140  *
141  * Returns pointer to test suite with @p index. No range checking is done
142  * for the index.
143  ***************************************************************************/
144 inline
145 const GTestSuite* GTestSuites::operator[](const int& index) const
146 {
147  return (m_testsuites[index]);
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Return number of test suites in container
153  *
154  * @return Number of test suites in container.
155  *
156  * Returns the number of test suites in the container.
157  ***************************************************************************/
158 inline
159 int GTestSuites::size(void) const
160 {
161  return (int)m_testsuites.size();
162 }
163 
164 
165 /***********************************************************************//**
166  * @brief Signals if there are no test suites in the container
167  *
168  * @return True if test suite container is empty, false otherwise.
169  *
170  * Signals if the container does not contain any test suite.
171  ***************************************************************************/
172 inline
173 bool GTestSuites::is_empty(void) const
174 {
175  return (m_testsuites.empty());
176 }
177 
178 
179 /***********************************************************************//**
180  * @brief Reserves space for test suites in container
181  *
182  * @param[in] num Number of test suites.
183  *
184  * Reserves space for @p num test suites in the container.
185  ***************************************************************************/
186 inline
187 void GTestSuites::reserve(const int& num)
188 {
189  m_testsuites.reserve(num);
190  return;
191 }
192 
193 
194 /***********************************************************************//**
195  * @brief Return test suite container name
196  *
197  * @return Test suite container name
198  ***************************************************************************/
199 inline
200 const std::string& GTestSuites::name(void) const
201 {
202  return m_name;
203 }
204 
205 
206 /***********************************************************************//**
207  * @brief Set test suite container name
208  *
209  * @param[in] name Test suite container name.
210  ***************************************************************************/
211 inline
212 void GTestSuites::name(const std::string& name)
213 {
214  m_name = name;
215  return;
216 }
217 
218 
219 /***********************************************************************//**
220  * @brief Enables/disables logging into standard output stream
221  *
222  * @param[in] flag Enable/disable logging (true/false).
223  *
224  * Enables or disables logging into the standard output stream.
225  ***************************************************************************/
226 inline
227 void GTestSuites::cout(const bool& flag)
228 {
229  m_log.cout(flag);
230  return;
231 }
232 
233 
234 /***********************************************************************//**
235  * @brief Return the timestamp
236  *
237  * The time step is set at the moment of construction of the test suites
238  * container.
239  ***************************************************************************/
240 inline
241 const time_t& GTestSuites::timestamp(void) const
242 {
243  return m_timestamp;
244 }
245 
246 #endif /* GTESTSUITES_HPP */
void write(GXml &xml) const
Write Test Suites into XML document.
GTestSuites & operator=(const GTestSuites &suites)
Assignment operator.
Test suite container class.
Definition: GTestSuites.hpp:53
std::vector< GTestSuite * > m_testsuites
Vector of test suites.
void clear(void)
Clear test suites.
void free_members(void)
Delete class members.
void copy_members(const GTestSuites &suites)
Copy class members.
int failures(void) const
Return the total number of failures in all test suites.
void reserve(const int &num)
Reserves space for test suites in container.
void cout(const bool &flag)
Set standard output stream (cout) flag.
Definition: GLog.hpp:275
void cout(const bool &flag)
Enables/disables logging into standard output stream.
time_t m_timestamp
Timestamp.
GTestSuites * clone(void) const
Clone test suites.
GTestSuite * operator[](const int &index)
Returns pointer to test suite.
Abstract test suite base class definition.
Information logger interface definition.
Definition: GLog.hpp:62
bool is_empty(void) const
Signals if there are no test suites in the container.
const time_t & timestamp(void) const
Return the timestamp.
GTestSuite * at(const int &index)
Returns pointer to test suite.
int size(void) const
Return number of test suites in container.
GTestSuite * set(const int &index, const GTestSuite &suite)
Set test suite in container.
XML class.
Definition: GXml.hpp:172
Filename class.
Definition: GFilename.hpp:62
void save(const GFilename &filename) const
Save test report into XML file.
virtual ~GTestSuites(void)
Destructor.
GTestSuite * append(const GTestSuite &suite)
Append test suite to container.
GChatter
Definition: GTypemaps.hpp:33
std::string print(const GChatter &chatter=NORMAL) const
Print test suites information.
Abstract test suite class for unit testing on GammaLib fixtures.
Definition: GTestSuite.hpp:53
GLog m_log
Log.
GTestSuite * insert(const int &index, const GTestSuite &suite)
Insert test suite into container.
std::string classname(void) const
Return class name.
const std::string & name(void) const
Return test suite container name.
Information logger class definition.
std::string m_name
Name of container.
void init_members(void)
Initialise class members.
GTestSuites(void)
Void constructor.
Definition: GTestSuites.cpp:59
Definition of interface for container classes.
bool run(void)
Run all tests.
int tests(void) const
Return the total number of tests they are in all test suites.
int errors(void) const
Return the total number of errors in all test suites.
void extend(const GTestSuites &suites)
Append test suite container.
Interface class for container classes.
Definition: GContainer.hpp:52