Skip to content

Commit 8291cd3

Browse files
committed
Removed methos compareS / compare N / compareB from unit-tests
1 parent 576a998 commit 8291cd3

16 files changed

+26
-62
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ project(wsjcpp-core)
55
include(${CMAKE_CURRENT_SOURCE_DIR}/src.wsjcpp/CMakeLists.txt)
66

77
#### BEGIN_WSJCPP_APPEND
8-
list (APPEND WSJCPP_SOURCES "./src/some.h")
9-
list (APPEND WSJCPP_SOURCES "./src/some.cpp")
108
#### END_WSJCPP_APPEND
119

1210
set(CMAKE_CXX_STANDARD 11)

src/wsjcpp_unit_tests.cpp

-31
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,6 @@ bool WsjcppUnitTestBase::runTest() {
6363

6464
// ---------------------------------------------------------------------
6565

66-
bool WsjcppUnitTestBase::compareS(const std::string &sMark,
67-
const std::string &sValue, const std::string &sExpected) {
68-
if (sValue != sExpected) {
69-
fail(" {" + sMark + "} Expected '" + sExpected + "', but got '" + sValue + "'");
70-
return false;
71-
}
72-
return true;
73-
}
74-
75-
// ---------------------------------------------------------------------
76-
77-
bool WsjcppUnitTestBase::compareN(const std::string &sMark, int nValue, int nExpected) {
78-
if (nValue != nExpected) {
79-
fail(" {" + sMark + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
80-
return false;
81-
}
82-
return true;
83-
}
84-
85-
// ---------------------------------------------------------------------
86-
8766
bool WsjcppUnitTestBase::compareD(const std::string &sMark, double nValue, double nExpected) {
8867
if (abs(nValue - nExpected) > std::numeric_limits<double>::epsilon()) {
8968
fail(" {" + sMark + "} Expected '" + std::to_string(nExpected) + "', but got '" + std::to_string(nValue) + "'");
@@ -94,16 +73,6 @@ bool WsjcppUnitTestBase::compareD(const std::string &sMark, double nValue, doubl
9473

9574
// ---------------------------------------------------------------------
9675

97-
bool WsjcppUnitTestBase::compareB(const std::string &sMark, bool bValue, bool bExpected) {
98-
if (bValue != bExpected) {
99-
fail(" {" + sMark + "} Expected '" + (bExpected ? "true" : "false") + "', but got '" + (bValue ? "true" : "false") + "'");
100-
return false;
101-
}
102-
return true;
103-
}
104-
105-
// ---------------------------------------------------------------------
106-
10776
std::vector<WsjcppUnitTestBase*> *g_pWsjcppUnitTests = nullptr;
10877

10978
void WsjcppUnitTests::initGlobalVariables() {

src/wsjcpp_unit_tests.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ class WsjcppUnitTestBase {
1717
virtual bool doAfterTest() = 0;
1818
protected:
1919
std::string TAG;
20-
21-
bool compareS(const std::string &sMark, const std::string &sValue, const std::string &sExpected);
22-
bool compareN(const std::string &sMark, int nValue, int nExpected);
20+
2321
bool compareD(const std::string &sMark, double nValue, double nExpected);
24-
bool compareB(const std::string &sMark, bool bValue, bool bExpected);
2522
template<typename T1, typename T2> bool compare(const std::string &sMark, T1 tGotValue, T2 tExpectedValue) {
2623
if (tGotValue != tExpectedValue) {
2724
std::stringstream ss;

unit-tests.wsjcpp/src/unit_test_create_empty_file.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ bool UnitTestCreateEmptyFile::doBeforeTest() {
1818
// ---------------------------------------------------------------------
1919

2020
void UnitTestCreateEmptyFile::executeTest() {
21-
compareB("./data/", WsjcppCore::dirExists("./data/"), true);
21+
compare("./data/", WsjcppCore::dirExists("./data/"), true);
2222
std::string sFilename = "./data/empty.txt";
2323
if (WsjcppCore::fileExists(sFilename)) {
2424
WsjcppCore::removeFile(sFilename);
2525
}
26-
compareB("fileExists 1: " + sFilename, WsjcppCore::fileExists(sFilename), false);
27-
compareB("createEmptyFile 1: " + sFilename, WsjcppCore::createEmptyFile(sFilename), true);
28-
compareB("createEmptyFile 2: " + sFilename, WsjcppCore::createEmptyFile(sFilename), false);
29-
compareB("fileExists 2: " + sFilename, WsjcppCore::fileExists(sFilename), true);
26+
compare("fileExists 1: " + sFilename, WsjcppCore::fileExists(sFilename), false);
27+
compare("createEmptyFile 1: " + sFilename, WsjcppCore::createEmptyFile(sFilename), true);
28+
compare("createEmptyFile 2: " + sFilename, WsjcppCore::createEmptyFile(sFilename), false);
29+
compare("fileExists 2: " + sFilename, WsjcppCore::fileExists(sFilename), true);
3030
}
3131

3232
// ---------------------------------------------------------------------

unit-tests.wsjcpp/src/unit_test_decode_uri_component.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void UnitTestDecodeUriComponent::executeTest() {
3737
for (int i = 0; i < tests.size(); i++) {
3838
LTest test = tests[i];
3939
std::string sStr = WsjcppCore::decodeUriComponent(test.sStr);
40-
compareS("test" + std::to_string(i), sStr, test.sExpectedStr);
40+
compare("test" + std::to_string(i), sStr, test.sExpectedStr);
4141
}
4242
}
4343

unit-tests.wsjcpp/src/unit_test_encode_uri_component.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void UnitTestEncodeUriComponent::executeTest() {
3737
for (int i = 0; i < tests.size(); i++) {
3838
LTest test = tests[i];
3939
std::string sStr = WsjcppCore::encodeUriComponent(test.sStr);
40-
compareS("test" + std::to_string(i), sStr, test.sExpectedStr);
40+
compare("test" + std::to_string(i), sStr, test.sExpectedStr);
4141
}
4242
}
4343

unit-tests.wsjcpp/src/unit_test_get_env.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void UnitTestGetEnv::executeTest() {
4040
std::string sValue;
4141
bool bResult = WsjcppCore::getEnv(test.sName, sValue);
4242
std::string testBaseName = "test#" + std::to_string(i) + " (" + test.sName + ")";
43-
compareB(testBaseName + "-result", bResult, test.bExpectedResult);
44-
compareS(testBaseName + "-value", sValue, test.sExpectedValue);
43+
compare(testBaseName + "-result", bResult, test.bExpectedResult);
44+
compare(testBaseName + "-value", sValue, test.sExpectedValue);
4545
}
4646
}
4747

unit-tests.wsjcpp/src/unit_test_get_human_size_bytes.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void UnitTestgetHumanSizeBytes::executeTest() {
5555
long nValue = tests[i].nValue;
5656
std::string sExpectedStr = tests[i].sExpectedStr;
5757
std::string sGotStr = WsjcppCore::getHumanSizeBytes(nValue);
58-
compareS("value=" + std::to_string(nValue), sGotStr, sExpectedStr);
58+
compare("value=" + std::to_string(nValue), sGotStr, sExpectedStr);
5959
}
6060
}
6161

unit-tests.wsjcpp/src/unit_test_join.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void UnitTestJoin::executeTest() {
2424
vTest.push_back("2");
2525
vTest.push_back("abc");
2626
std::string sRet = WsjcppCore::join(vTest, ", ");
27-
compareS("join", sRet, ", 1, 2, abc");
27+
compare("join", sRet, ", 1, 2, abc");
2828
}
2929

3030
// ---------------------------------------------------------------------

unit-tests.wsjcpp/src/unit_test_list_of_dirs.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ bool UnitTestListOfDirs::doBeforeTest() {
2121
void UnitTestListOfDirs::executeTest() {
2222
std::vector<std::string> vDirs = WsjcppCore::getListOfDirs("./data/list_of_dirs");
2323

24-
compareN("size", vDirs.size(), 4);
24+
compare("size", vDirs.size(), 4);
2525
if (vDirs.size() == 4) {
26-
compareS("name of dir1", vDirs[0], "a1");
27-
compareS("name of dir2", vDirs[1], "b2");
28-
compareS("name of dir3", vDirs[2], "c3");
29-
compareS("name of dir4", vDirs[3], "d4");
26+
compare("name of dir1", vDirs[0], "a1");
27+
compare("name of dir2", vDirs[1], "b2");
28+
compare("name of dir3", vDirs[2], "c3");
29+
compare("name of dir4", vDirs[3], "d4");
3030
}
3131
}
3232

unit-tests.wsjcpp/src/unit_test_read_file_to_buffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ void UnitTestReadFileToBuffer::executeTest() {
2323
char *pBuffer = nullptr;
2424
int nBufferSize = 0;
2525
WsjcppCore::readFileToBuffer("./data/readFileToBuffer.txt", &pBuffer, nBufferSize);
26-
compareN("Size of readed", nBufferSize, sExpected.length());
26+
compare("Size of readed", nBufferSize, sExpected.length());
2727
int nMin = std::min(nBufferSize, (int)sExpected.length());
2828
for (int i = 0; i < nMin; i++) {
2929
char c_got = pBuffer[i];
3030
char c_expected = sExpected[i];
31-
compareN("Check the " + std::to_string(i), c_got, c_expected);
31+
compare("Check the " + std::to_string(i), c_got, c_expected);
3232
}
3333
}
3434

unit-tests.wsjcpp/src/unit_test_replace_all.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void UnitTestReplaceAll::executeTest() {
4343
LTest test = tests[i];
4444
std::string sStr = test.sStr;
4545
WsjcppCore::replaceAll(sStr, test.sFrom, test.sTo);
46-
compareS("test" + std::to_string(i), sStr, test.sExpectedStr);
46+
compare("test" + std::to_string(i), sStr, test.sExpectedStr);
4747
}
4848
}
4949

unit-tests.wsjcpp/src/unit_test_split.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ void UnitTestSplit::executeTest() {
4545
LTest test = tests[i];
4646
std::string sPrefix = "test" + std::to_string(i) + "(\"" + test.sStr + "\")";
4747
std::vector<std::string> vSplitted = WsjcppCore::split(test.sStr, test.sDelim);
48-
compareN(sPrefix + ": size", vSplitted.size(), test.vExpectedVector.size());
48+
compare(sPrefix + ": size", vSplitted.size(), test.vExpectedVector.size());
4949
int nMin = std::min(vSplitted.size(), test.vExpectedVector.size());
5050
for (int n = 0; n < nMin; n++) {
51-
compareS(sPrefix + ", element: " + std::to_string(n), vSplitted[n], test.vExpectedVector[n]);
51+
compare(sPrefix + ", element: " + std::to_string(n), vSplitted[n], test.vExpectedVector[n]);
5252
}
5353
}
5454
}

unit-tests.wsjcpp/src/unit_test_test_resources.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ bool UnitTestTestResources::doBeforeTest() {
2020
void UnitTestTestResources::executeTest() {
2121
// std::vector<ResourceFile*> &list();
2222
WsjcppResourceFile* pFile = WsjcppResourcesManager::get("html/images/points.svg");
23-
compareN("getBufferSize", pFile->getBufferSize(), 2979);
24-
compareS("getFilename", pFile->getFilename(), "html/images/points.svg");
23+
compare("getBufferSize", pFile->getBufferSize(), 2979);
24+
compare("getFilename", pFile->getFilename(), "html/images/points.svg");
2525
}
2626

2727
// ---------------------------------------------------------------------

unit-tests.wsjcpp/src/unit_test_to_lower.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool UnitTestToLower::doBeforeTest() {
1818
// ---------------------------------------------------------------------
1919

2020
void UnitTestToLower::executeTest() {
21-
compareS("str1", "abc_def", WsjcppCore::toLower("ABC_DEF"));
21+
compare("str1", "abc_def", WsjcppCore::toLower("ABC_DEF"));
2222
}
2323

2424
// ---------------------------------------------------------------------

unit-tests.wsjcpp/src/unit_test_uint2_hex_string.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void UnitTestUint2HexString::executeTest() {
3737
for (int i = 0; i < tests.size(); i++) {
3838
LTest test = tests[i];
3939
std::string sStr = WsjcppCore::uint2hexString(test.nNumber);
40-
compareS("test" + std::to_string(i), sStr, test.sExpectedStr);
40+
compare("test" + std::to_string(i), sStr, test.sExpectedStr);
4141
}
4242
}
4343

0 commit comments

Comments
 (0)