fhq-server  v0.2.33
Documentation for fhq-server. FreeHackQuest is an open source platform for competitions of computer security.
wsjcpp_unit_tests.h
Go to the documentation of this file.
1 #ifndef WSJCPP_UNIT_TESTS_H
2 #define WSJCPP_UNIT_TESTS_H
3 
4 #include <wsjcpp_core.h>
5 #include <sstream>
6 
8  public:
9  WsjcppUnitTestBase(const std::string &sTestName);
10  std::string getName();
11  void ok(const std::string &sSuccessMessage);
12  void fail(const std::string &sFailedMessage);
13  bool runTest();
14 
15  virtual bool doBeforeTest() = 0;
16  virtual void executeTest() = 0;
17  virtual bool doAfterTest() = 0;
18  protected:
19  std::string TAG;
20 
21  bool compareD(const std::string &sMark, double nValue, double nExpected);
22  template<typename T1, typename T2> bool compare(const std::string &sMark, T1 tGotValue, T2 tExpectedValue) {
23  if (tGotValue != tExpectedValue) {
24  std::stringstream ss;
25  ss << " {mark: " << sMark << "} Expected '" << tExpectedValue << "', but got '" << tGotValue << "'";
26  fail(ss.str());
27  return false;
28  }
29  return true;
30  }
31  private:
33  std::string m_sTestName;
34 };
35 
36 extern std::vector<WsjcppUnitTestBase*> *g_pWsjcppUnitTests;
37 
39  public:
40  static void initGlobalVariables();
41  static void addUnitTest(const std::string &sTestName, WsjcppUnitTestBase* pUnitTest);
42 };
43 
44 // RegistryCmdHandler
45 #define REGISTRY_WSJCPP_UNIT_TEST( classname ) \
46  static classname * pRegistryWsjcppUnitTest ## classname = new classname(); \
47 
48 
49 #endif // WSJCPP_UNIT_TESTS_H
void fail(const std::string &sFailedMessage)
Definition: wsjcpp_unit_tests.cpp:29
std::string TAG
Definition: wsjcpp_unit_tests.h:19
virtual bool doBeforeTest()=0
std::string m_sTestName
Definition: wsjcpp_unit_tests.h:33
virtual bool doAfterTest()=0
WsjcppUnitTestBase(const std::string &sTestName)
Definition: wsjcpp_unit_tests.cpp:7
Definition: wsjcpp_unit_tests.h:38
bool runTest()
Definition: wsjcpp_unit_tests.cpp:36
std::string getName()
Definition: wsjcpp_unit_tests.cpp:16
Definition: wsjcpp_unit_tests.h:7
virtual void executeTest()=0
bool compareD(const std::string &sMark, double nValue, double nExpected)
Definition: wsjcpp_unit_tests.cpp:66
std::vector< WsjcppUnitTestBase * > * g_pWsjcppUnitTests
Definition: wsjcpp_unit_tests.cpp:76
void ok(const std::string &sSuccessMessage)
Definition: wsjcpp_unit_tests.cpp:22
bool compare(const std::string &sMark, T1 tGotValue, T2 tExpectedValue)
Definition: wsjcpp_unit_tests.h:22
bool m_bTestResult
Definition: wsjcpp_unit_tests.h:32