NRE_TestSuite.hpp
Go to the documentation of this file.
1 
10  #pragma once
11 
12  #include <vector>
13  #include <string>
14  #include <sstream>
15  #include <iostream>
16 
17  #include "../InternalTest/NRE_InternalTest.hpp"
18 
23  namespace NRE {
28  namespace Tester {
29 
34  class TestSuite {
35  private : // Fields
36  std::vector<InternalTest*> suite;
37  std::vector<std::string> failLogs;
39  public : // Methods
44  void addTest(InternalTest* test);
49  void addLog(std::string const& log);
53  void runAll();
57  bool hasFailed() const;
58 
59  public : // Static
65  static void runAllTests();
69  static bool suiteHasFailed();
70  };
71 
76  void fail(std::string const& message = "Fail");
82  void fail(const InternalTest* test, std::string const& message = "Fail");
88  void assertTrue(bool assert, std::string const& message = "True Assertion Failed");
95  void assertTrue(const InternalTest* test, bool assert, std::string const& message = "True Assertion Failed");
101  void assertFalse(bool assert, std::string const& message = "False Assertion Failed");
108  void assertFalse(const InternalTest* test, bool assert, std::string const& message = "False Assertion Failed");
115  template <class T>
116  void assertEquals(T const& lhs, T const& rhs, std::string const& message = "Equals Assertion Failed") {
117  if (!(lhs == rhs)) {
118  std::stringstream lhsStr;
119  std::stringstream rhsStr;
120  lhsStr << lhs;
121  rhsStr << rhs;
122  TestSuite::suiteInstance.addLog(message + "\n\tExcepted : " + lhsStr.str() + "\n\tGet : " + rhsStr.str());
123  }
124  }
132  template <class T>
133  void assertEquals(const InternalTest* test, T const& lhs, T const& rhs, std::string const& message = "Equals Assertion Failed") {
134  if (!(lhs == rhs)) {
135  std::stringstream lhsStr;
136  std::stringstream rhsStr;
137  lhsStr << lhs;
138  rhsStr << rhs;
139  TestSuite::suiteInstance.addLog(message + test->getDetails() + "\n\tExcepted : " + lhsStr.str() + "\n\tGet : " + rhsStr.str());
140  }
141  }
148  template <class T>
149  void assertNotEquals(T const& lhs, T const& rhs, std::string const& message = "NotEquals Assertion Failed") {
150  if (!(lhs != rhs)) {
151  std::stringstream lhsStr;
152  lhsStr << lhs;
153  TestSuite::suiteInstance.addLog(message + "\n\tExcepted : not " + lhsStr.str() + "\n\tGet : " + lhsStr.str());
154  }
155  }
163  template <class T>
164  void assertNotEquals(const InternalTest* test, T const& lhs, T const& rhs, std::string const& message = "NotEquals Assertion Failed") {
165  if (!(lhs != rhs)) {
166  std::stringstream lhsStr;
167  lhsStr << lhs;
168  TestSuite::suiteInstance.addLog(message + test->getDetails() + "\n\tExcepted : not " + lhsStr.str() + "\n\tGet : " + lhsStr.str());
169  }
170  }
177  template <class T>
178  void assertLesser(T const& lhs, T const& rhs, std::string const& message = "Lesser Assertion Failed") {
179  if (!(lhs < rhs)) {
180  std::stringstream lhsStr;
181  std::stringstream rhsStr;
182  lhsStr << lhs;
183  rhsStr << rhs;
184  TestSuite::suiteInstance.addLog(message + "\n\tExcepted : < " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
185  }
186  }
194  template <class T>
195  void assertLesser(const InternalTest* test, T const& lhs, T const& rhs, std::string const& message = "Lesser Assertion Failed") {
196  if (!(lhs < rhs)) {
197  std::stringstream lhsStr;
198  std::stringstream rhsStr;
199  lhsStr << lhs;
200  rhsStr << rhs;
201  TestSuite::suiteInstance.addLog(message + test->getDetails() + "\n\tExcepted : < " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
202  }
203  }
210  template <class T>
211  void assertGreater(T const& lhs, T const& rhs, std::string const& message = "Greater Assertion Failed") {
212  if (!(lhs > rhs)) {
213  std::stringstream lhsStr;
214  std::stringstream rhsStr;
215  lhsStr << lhs;
216  rhsStr << rhs;
217  TestSuite::suiteInstance.addLog(message + "\n\tExcepted : > " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
218  }
219  }
227  template <class T>
228  void assertGreater(const InternalTest* test, T const& lhs, T const& rhs, std::string const& message = "Greater Assertion Failed") {
229  if (!(lhs > rhs)) {
230  std::stringstream lhsStr;
231  std::stringstream rhsStr;
232  lhsStr << lhs;
233  rhsStr << rhs;
234  TestSuite::suiteInstance.addLog(message + test->getDetails() + "\n\tExcepted : > " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
235  }
236  }
243  template <class T>
244  void assertLesserOrEquals(T const& lhs, T const& rhs, std::string const& message = "Lesser or Equals Assertion Failed") {
245  if (!(lhs <= rhs)) {
246  std::stringstream lhsStr;
247  std::stringstream rhsStr;
248  lhsStr << lhs;
249  rhsStr << rhs;
250  TestSuite::suiteInstance.addLog(message + "\n\tExcepted : <= " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
251  }
252  }
260  template <class T>
261  void assertLesserOrEquals(const InternalTest* test, T const& lhs, T const& rhs, std::string const& message = "Lesser or Equals Assertion Failed") {
262  if (!(lhs <= rhs)) {
263  std::stringstream lhsStr;
264  std::stringstream rhsStr;
265  lhsStr << lhs;
266  rhsStr << rhs;
267  TestSuite::suiteInstance.addLog(message + test->getDetails() + "\n\tExcepted : <= " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
268  }
269  }
276  template <class T>
277  void assertGreaterOrEquals(T const& lhs, T const& rhs, std::string const& message = "Greater or Equals Assertion Failed") {
278  if (!(lhs >= rhs)) {
279  std::stringstream lhsStr;
280  std::stringstream rhsStr;
281  lhsStr << lhs;
282  rhsStr << rhs;
283  TestSuite::suiteInstance.addLog(message + "\n\tExcepted : >= " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
284  }
285  }
293  template <class T>
294  void assertGreaterOrEquals(const InternalTest* test, T const& lhs, T const& rhs, std::string const& message = "Greater or Equals Assertion Failed") {
295  if (!(lhs >= rhs)) {
296  std::stringstream lhsStr;
297  std::stringstream rhsStr;
298  lhsStr << lhs;
299  rhsStr << rhs;
300  TestSuite::suiteInstance.addLog(message + test->getDetails() + "\n\tExcepted : >= " + rhsStr.str() + "\n\tGet : " + lhsStr.str());
301  }
302  }
308  void assertNull(const void* ptr, std::string const& message = "Null Assertion Failed");
315  void assertNull(const InternalTest* test, const void* ptr, std::string const& message = "Null Assertion Failed");
321  void assertNotNull(const void* ptr, std::string const& message = "NotNull Assertion Failed");
328  void assertNotNull(const InternalTest* test, const void* ptr, std::string const& message = "NotNull Assertion Failed");
329  }
330  }
void assertGreaterOrEquals(T const &lhs, T const &rhs, std::string const &message="Greater or Equals Assertion Failed")
Definition: NRE_TestSuite.hpp:277
void assertTrue(bool assert, std::string const &message)
Definition: NRE_TestSuite.cpp:67
void addTest(InternalTest *test)
Definition: NRE_TestSuite.cpp:18
Tester&#39;s API.
void runAll()
Definition: NRE_TestSuite.cpp:26
void addLog(std::string const &log)
Definition: NRE_TestSuite.cpp:22
static void runAllTests()
Definition: NRE_TestSuite.cpp:51
void assertLesserOrEquals(T const &lhs, T const &rhs, std::string const &message="Lesser or Equals Assertion Failed")
Definition: NRE_TestSuite.hpp:244
static TestSuite suiteInstance
Definition: NRE_TestSuite.hpp:60
void assertLesser(T const &lhs, T const &rhs, std::string const &message="Lesser Assertion Failed")
Definition: NRE_TestSuite.hpp:178
bool hasFailed() const
Definition: NRE_TestSuite.cpp:47
void assertGreater(T const &lhs, T const &rhs, std::string const &message="Greater Assertion Failed")
Definition: NRE_TestSuite.hpp:211
void fail(std::string const &message)
Definition: NRE_TestSuite.cpp:59
Describe an internal test used to register a user test inside the suite.
Definition: NRE_InternalTest.hpp:28
Describe the test suite used to store all used-defined test and run them.
Definition: NRE_TestSuite.hpp:34
void assertNotNull(const void *ptr, std::string const &message)
Definition: NRE_TestSuite.cpp:103
void assertFalse(bool assert, std::string const &message)
Definition: NRE_TestSuite.cpp:79
void assertNull(const void *ptr, std::string const &message)
Definition: NRE_TestSuite.cpp:91
std::string getDetails() const
Definition: NRE_InternalTest.cpp:28
void assertEquals(T const &lhs, T const &rhs, std::string const &message="Equals Assertion Failed")
Definition: NRE_TestSuite.hpp:116
The NearlyRealEngine&#39;s global namespace.
Definition: NRE_InternalTest.cpp:13
void assertNotEquals(T const &lhs, T const &rhs, std::string const &message="NotEquals Assertion Failed")
Definition: NRE_TestSuite.hpp:149
static bool suiteHasFailed()
Definition: NRE_TestSuite.cpp:55