-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsjcpp_unit_tests.cpp
More file actions
87 lines (69 loc) · 3.02 KB
/
Copy pathwsjcpp_unit_tests.cpp
File metadata and controls
87 lines (69 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "wsjcpp_unit_tests.h"
WsjcppUnitTestBase::WsjcppUnitTestBase(const std::string &sTestName) {
m_sTestName = sTestName;
TAG = m_sTestName;
WsjcppUnitTests::addUnitTest(sTestName, this);
}
// ---------------------------------------------------------------------
std::string WsjcppUnitTestBase::name() {
return m_sTestName;
}
// ---------------------------------------------------------------------
void WsjcppUnitTestBase::compareS(bool &bTestSuccess, const std::string &sPoint,
const std::string &sValue, const std::string &sExpected) {
if (sValue != sExpected) {
WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + sExpected + "', but got '" + sValue + "'");
bTestSuccess = false;
}
}
// ---------------------------------------------------------------------
bool WsjcppUnitTestBase::compareN(bool &bTestSuccess, const std::string &sPoint, int nValue, int nExpected) {
if (nValue != nExpected) {
WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
bTestSuccess = false;
return false;
}
return true;
}
// ---------------------------------------------------------------------
bool WsjcppUnitTestBase::compareD(bool &bTestSuccess, const std::string &sPoint, double nValue, double nExpected) {
if (nValue != nExpected) {
WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
bTestSuccess = false;
return false;
}
return true;
}
// ---------------------------------------------------------------------
void WsjcppUnitTestBase::compareB(bool &bTestSuccess, const std::string &sPoint, bool bValue, bool bExpected) {
if (bValue != bExpected) {
WsjcppLog::err(TAG, " {" + sPoint + "} Expected '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'");
bTestSuccess = false;
}
}
// ---------------------------------------------------------------------
std::vector<WsjcppUnitTestBase*> *g_pWsjcppUnitTests = nullptr;
void WsjcppUnitTests::initGlobalVariables() {
if (g_pWsjcppUnitTests == nullptr) {
// WsjcppLog::info(std::string(), "Create handlers map");
g_pWsjcppUnitTests = new std::vector<WsjcppUnitTestBase*>();
}
}
// ---------------------------------------------------------------------
void WsjcppUnitTests::addUnitTest(const std::string &sTestName, WsjcppUnitTestBase* pUnitTest) {
WsjcppUnitTests::initGlobalVariables();
bool bFound = false;
for (int i = 0; i < g_pWsjcppUnitTests->size(); i++) {
WsjcppUnitTestBase* p = g_pWsjcppUnitTests->at(i);
if (p->name() == sTestName) {
bFound = true;
}
}
if (bFound) {
WsjcppLog::err(sTestName, "Already registered");
} else {
g_pWsjcppUnitTests->push_back(pUnitTest);
// Log::info(sCmd, "Registered");
}
}
// ---------------------------------------------------------------------