|
| 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 | + |
0 commit comments