|
| 1 | +#include "unit_test_get_env.h" |
| 2 | +#include <vector> |
| 3 | +#include <wsjcpp_core.h> |
| 4 | + |
| 5 | +REGISTRY_UNIT_TEST(UnitTestGetEnv) |
| 6 | + |
| 7 | +UnitTestGetEnv::UnitTestGetEnv() |
| 8 | + : WSJCppUnitTestBase("UnitTestGetEnv") { |
| 9 | +} |
| 10 | + |
| 11 | +// --------------------------------------------------------------------- |
| 12 | + |
| 13 | +void UnitTestGetEnv::init() { |
| 14 | + // nothing |
| 15 | +} |
| 16 | + |
| 17 | +// --------------------------------------------------------------------- |
| 18 | + |
| 19 | +bool UnitTestGetEnv::run() { |
| 20 | + bool bTestSuccess = true; |
| 21 | + |
| 22 | + struct LTest { |
| 23 | + LTest(const std::string &sName, bool bExpectedResult, const std::string &sExpectedValue) { |
| 24 | + this->sName = sName; |
| 25 | + this->sExpectedValue = sExpectedValue; |
| 26 | + this->bExpectedResult = bExpectedResult; |
| 27 | + }; |
| 28 | + std::string sName; |
| 29 | + bool bExpectedResult; |
| 30 | + std::string sExpectedValue; |
| 31 | + }; |
| 32 | + |
| 33 | + std::vector<LTest> tests; |
| 34 | + tests.push_back(LTest("TESTENVVALUE1", true, "testvalue1")); |
| 35 | + tests.push_back(LTest("TESTENVVALUE1_", false, "")); |
| 36 | + tests.push_back(LTest("TEST_ENV_VALUE2", true, "test some value2")); |
| 37 | + tests.push_back(LTest("TEST_ENV_VALUE3", true, "932749387")); |
| 38 | + |
| 39 | + for (int i = 0; i < tests.size(); i++) { |
| 40 | + LTest test = tests[i]; |
| 41 | + std::string sValue; |
| 42 | + bool bResult = WSJCppCore::getEnv(test.sName, sValue); |
| 43 | + std::string testBaseName = "test#" + std::to_string(i) + " (" + test.sName + ")"; |
| 44 | + compareB(bTestSuccess, testBaseName + "-result", bResult, test.bExpectedResult); |
| 45 | + compareS(bTestSuccess, testBaseName + "-value", sValue, test.sExpectedValue); |
| 46 | + } |
| 47 | + return bTestSuccess; |
| 48 | +} |
| 49 | + |
0 commit comments