Skip to content

Commit c3898e2

Browse files
committed
fixed #5 added test for validator string list
1 parent 92e3320 commit c3898e2

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

unit-tests.wsjcpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_validator_email.
3333
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_validator_email.cpp")
3434
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_validator_uuid.h")
3535
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_validator_uuid.cpp")
36+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_validator_string_list.h")
37+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_validator_string_list.cpp")
3638

3739
# required-libraries
3840
list (APPEND WSJCPP_LIBRARIES "-lpthread")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "unit_test_validator_string_list.h"
2+
#include <vector>
3+
#include <wsjcpp_core.h>
4+
#include <wsjcpp_validators.h>
5+
6+
REGISTRY_UNIT_TEST(UnitTestValidatorStringList)
7+
8+
UnitTestValidatorStringList::UnitTestValidatorStringList()
9+
: WSJCppUnitTestBase("UnitTestStringList") {
10+
}
11+
12+
// ---------------------------------------------------------------------
13+
14+
void UnitTestValidatorStringList::init() {
15+
// nothing
16+
}
17+
18+
// ---------------------------------------------------------------------
19+
20+
bool UnitTestValidatorStringList::run() {
21+
bool bTestSuccess = true;
22+
23+
struct LTestVld {
24+
LTestVld(std::string sValue, bool bExpectedResult) {
25+
m_sValue = sValue;
26+
m_bExpectedResult = bExpectedResult;
27+
}
28+
std::string m_sValue;
29+
int m_bExpectedResult;
30+
};
31+
std::vector<LTestVld *> tests;
32+
33+
WJSCppValidatorStringListBase *pValidator = new WJSCppValidatorStringListBase("test", {"some1", "some2", "some3", "hello"});
34+
tests.push_back(new LTestVld("some", false));
35+
tests.push_back(new LTestVld("dkljsfld", false));
36+
tests.push_back(new LTestVld("hello", true));
37+
tests.push_back(new LTestVld("some1", true));
38+
tests.push_back(new LTestVld("some2", true));
39+
tests.push_back(new LTestVld("some3", true));
40+
41+
for (unsigned int i = 0; i < tests.size(); i++) {
42+
std::string sValue = tests[i]->m_sValue;
43+
bool bExpectedResult = tests[i]->m_bExpectedResult;
44+
std::string sError = "";
45+
bool bGotResult = pValidator->isValid(sValue, sError);
46+
compareB(bTestSuccess, "Test '" + sValue + "' error: " + sError, bGotResult, bExpectedResult);
47+
}
48+
49+
return bTestSuccess;
50+
}
51+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef UNIT_TEST_STRING_LIST_H
2+
#define UNIT_TEST_STRING_LIST_H
3+
4+
#include <wsjcpp_unit_tests.h>
5+
6+
// Description: TODO
7+
class UnitTestValidatorStringList : public WSJCppUnitTestBase {
8+
public:
9+
UnitTestValidatorStringList();
10+
virtual void init();
11+
virtual bool run();
12+
};
13+
14+
#endif // UNIT_TEST_STRING_LIST_H
15+

wsjcpp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ unit-tests:
4646
description: "Test email validator"
4747
- name: "ValidatorUuid"
4848
description: "Test uuid validator"
49+
- name: "ValidatorStringList"
50+
description: "Test validator from a string list"

0 commit comments

Comments
 (0)