Changeset View
Changeset View
Standalone View
Standalone View
src/test/util_tests.cpp
Show First 20 Lines • Show All 306 Lines • ▼ Show 20 Lines | const char *str_config = "a=\n" | ||||
"ccc=argument\n" | "ccc=argument\n" | ||||
"ccc=multiple\n" | "ccc=multiple\n" | ||||
"d=e\n" | "d=e\n" | ||||
"nofff=1\n" | "nofff=1\n" | ||||
"noggg=0\n" | "noggg=0\n" | ||||
"h=1\n" | "h=1\n" | ||||
"noh=1\n" | "noh=1\n" | ||||
"noi=1\n" | "noi=1\n" | ||||
"i=1\n"; | "i=1\n" | ||||
"sec1.ccc=extend1\n" | |||||
"\n" | |||||
"[sec1]\n" | |||||
"ccc=extend2\n" | |||||
"h=1\n" | |||||
"[sec2]\n" | |||||
"ccc=extend3\n" | |||||
"iii=2\n"; | |||||
TestArgsManager test_args; | TestArgsManager test_args; | ||||
test_args.ReadConfigString(str_config); | test_args.ReadConfigString(str_config); | ||||
// expectation: a, b, ccc, d, fff, ggg, h, i end up in map | // expectation: a, b, ccc, d, fff, ggg, h, i end up in map | ||||
// so do sec1.ccc, sec1.h, sec2.ccc, sec2.iii | |||||
BOOST_CHECK(test_args.GetOverrideArgs().empty()); | BOOST_CHECK(test_args.GetOverrideArgs().empty()); | ||||
BOOST_CHECK(test_args.GetConfigArgs().size() == 8); | BOOST_CHECK(test_args.GetConfigArgs().size() == 12); | ||||
BOOST_CHECK(test_args.GetConfigArgs().count("-a") && | BOOST_CHECK(test_args.GetConfigArgs().count("-a") && | ||||
test_args.GetConfigArgs().count("-b") && | test_args.GetConfigArgs().count("-b") && | ||||
test_args.GetConfigArgs().count("-ccc") && | test_args.GetConfigArgs().count("-ccc") && | ||||
test_args.GetConfigArgs().count("-d") && | test_args.GetConfigArgs().count("-d") && | ||||
test_args.GetConfigArgs().count("-fff") && | test_args.GetConfigArgs().count("-fff") && | ||||
test_args.GetConfigArgs().count("-ggg") && | test_args.GetConfigArgs().count("-ggg") && | ||||
test_args.GetConfigArgs().count("-h") && | test_args.GetConfigArgs().count("-h") && | ||||
test_args.GetConfigArgs().count("-i")); | test_args.GetConfigArgs().count("-i")); | ||||
BOOST_CHECK(test_args.GetConfigArgs().count("-sec1.ccc") && | |||||
test_args.GetConfigArgs().count("-sec1.h") && | |||||
test_args.GetConfigArgs().count("-sec2.ccc") && | |||||
test_args.GetConfigArgs().count("-sec2.iii")); | |||||
BOOST_CHECK(test_args.IsArgSet("-a") && test_args.IsArgSet("-b") && | BOOST_CHECK(test_args.IsArgSet("-a") && test_args.IsArgSet("-b") && | ||||
test_args.IsArgSet("-ccc") && test_args.IsArgSet("-d") && | test_args.IsArgSet("-ccc") && test_args.IsArgSet("-d") && | ||||
test_args.IsArgSet("-fff") && test_args.IsArgSet("-ggg") && | test_args.IsArgSet("-fff") && test_args.IsArgSet("-ggg") && | ||||
test_args.IsArgSet("-h") && test_args.IsArgSet("-i") && | test_args.IsArgSet("-h") && test_args.IsArgSet("-i") && | ||||
!test_args.IsArgSet("-zzz")); | !test_args.IsArgSet("-zzz") && !test_args.IsArgSet("-iii")); | ||||
BOOST_CHECK(test_args.GetArg("-a", "xxx") == "" && | BOOST_CHECK(test_args.GetArg("-a", "xxx") == "" && | ||||
test_args.GetArg("-b", "xxx") == "1" && | test_args.GetArg("-b", "xxx") == "1" && | ||||
test_args.GetArg("-ccc", "xxx") == "argument" && | test_args.GetArg("-ccc", "xxx") == "argument" && | ||||
test_args.GetArg("-d", "xxx") == "e" && | test_args.GetArg("-d", "xxx") == "e" && | ||||
test_args.GetArg("-fff", "xxx") == "0" && | test_args.GetArg("-fff", "xxx") == "0" && | ||||
test_args.GetArg("-ggg", "xxx") == "1" && | test_args.GetArg("-ggg", "xxx") == "1" && | ||||
test_args.GetArg("-h", "xxx") == "0" && | test_args.GetArg("-h", "xxx") == "0" && | ||||
test_args.GetArg("-i", "xxx") == "1" && | test_args.GetArg("-i", "xxx") == "1" && | ||||
test_args.GetArg("-zzz", "xxx") == "xxx"); | test_args.GetArg("-zzz", "xxx") == "xxx" && | ||||
test_args.GetArg("-iii", "xxx") == "xxx"); | |||||
for (bool def : {false, true}) { | for (bool def : {false, true}) { | ||||
BOOST_CHECK(test_args.GetBoolArg("-a", def) && | BOOST_CHECK(test_args.GetBoolArg("-a", def) && | ||||
test_args.GetBoolArg("-b", def) && | test_args.GetBoolArg("-b", def) && | ||||
!test_args.GetBoolArg("-ccc", def) && | !test_args.GetBoolArg("-ccc", def) && | ||||
!test_args.GetBoolArg("-d", def) && | !test_args.GetBoolArg("-d", def) && | ||||
!test_args.GetBoolArg("-fff", def) && | !test_args.GetBoolArg("-fff", def) && | ||||
test_args.GetBoolArg("-ggg", def) && | test_args.GetBoolArg("-ggg", def) && | ||||
!test_args.GetBoolArg("-h", def) && | !test_args.GetBoolArg("-h", def) && | ||||
test_args.GetBoolArg("-i", def) && | test_args.GetBoolArg("-i", def) && | ||||
test_args.GetBoolArg("-zzz", def) == def); | test_args.GetBoolArg("-zzz", def) == def && | ||||
test_args.GetBoolArg("-iii", def) == def); | |||||
} | } | ||||
BOOST_CHECK(test_args.GetArgs("-a").size() == 1 && | BOOST_CHECK(test_args.GetArgs("-a").size() == 1 && | ||||
test_args.GetArgs("-a").front() == ""); | test_args.GetArgs("-a").front() == ""); | ||||
BOOST_CHECK(test_args.GetArgs("-b").size() == 1 && | BOOST_CHECK(test_args.GetArgs("-b").size() == 1 && | ||||
test_args.GetArgs("-b").front() == "1"); | test_args.GetArgs("-b").front() == "1"); | ||||
BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2 && | BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2 && | ||||
test_args.GetArgs("-ccc").front() == "argument" && | test_args.GetArgs("-ccc").front() == "argument" && | ||||
Show All 16 Lines | BOOST_AUTO_TEST_CASE(util_ReadConfigStream) { | ||||
BOOST_CHECK(!test_args.IsArgNegated("-d")); | BOOST_CHECK(!test_args.IsArgNegated("-d")); | ||||
BOOST_CHECK(test_args.IsArgNegated("-fff")); | BOOST_CHECK(test_args.IsArgNegated("-fff")); | ||||
BOOST_CHECK(!test_args.IsArgNegated("-ggg")); | BOOST_CHECK(!test_args.IsArgNegated("-ggg")); | ||||
// last setting takes precedence | // last setting takes precedence | ||||
BOOST_CHECK(test_args.IsArgNegated("-h")); | BOOST_CHECK(test_args.IsArgNegated("-h")); | ||||
// last setting takes precedence | // last setting takes precedence | ||||
BOOST_CHECK(!test_args.IsArgNegated("-i")); | BOOST_CHECK(!test_args.IsArgNegated("-i")); | ||||
BOOST_CHECK(!test_args.IsArgNegated("-zzz")); | BOOST_CHECK(!test_args.IsArgNegated("-zzz")); | ||||
// Test sections work | |||||
test_args.SelectConfigNetwork("sec1"); | |||||
// same as original | |||||
BOOST_CHECK(test_args.GetArg("-a", "xxx") == "" && | |||||
test_args.GetArg("-b", "xxx") == "1" && | |||||
test_args.GetArg("-d", "xxx") == "e" && | |||||
test_args.GetArg("-fff", "xxx") == "0" && | |||||
test_args.GetArg("-ggg", "xxx") == "1" && | |||||
test_args.GetArg("-zzz", "xxx") == "xxx" && | |||||
test_args.GetArg("-iii", "xxx") == "xxx"); | |||||
// section-specific setting | |||||
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "1"); | |||||
// section takes priority for multiple values | |||||
BOOST_CHECK(test_args.GetArg("-ccc", "xxx") == "extend1"); | |||||
// check multiple values works | |||||
const std::vector<std::string> sec1_ccc_expected = {"extend1", "extend2", | |||||
"argument", "multiple"}; | |||||
const auto &sec1_ccc_res = test_args.GetArgs("-ccc"); | |||||
BOOST_CHECK_EQUAL_COLLECTIONS(sec1_ccc_res.begin(), sec1_ccc_res.end(), | |||||
sec1_ccc_expected.begin(), | |||||
sec1_ccc_expected.end()); | |||||
test_args.SelectConfigNetwork("sec2"); | |||||
// same as original | |||||
BOOST_CHECK(test_args.GetArg("-a", "xxx") == "" && | |||||
test_args.GetArg("-b", "xxx") == "1" && | |||||
test_args.GetArg("-d", "xxx") == "e" && | |||||
test_args.GetArg("-fff", "xxx") == "0" && | |||||
test_args.GetArg("-ggg", "xxx") == "1" && | |||||
test_args.GetArg("-zzz", "xxx") == "xxx" && | |||||
test_args.GetArg("-h", "xxx") == "0"); | |||||
// section-specific setting | |||||
BOOST_CHECK(test_args.GetArg("-iii", "xxx") == "2"); | |||||
// section takes priority for multiple values | |||||
BOOST_CHECK(test_args.GetArg("-ccc", "xxx") == "extend3"); | |||||
// check multiple values works | |||||
const std::vector<std::string> sec2_ccc_expected = {"extend3", "argument", | |||||
"multiple"}; | |||||
const auto &sec2_ccc_res = test_args.GetArgs("-ccc"); | |||||
BOOST_CHECK_EQUAL_COLLECTIONS(sec2_ccc_res.begin(), sec2_ccc_res.end(), | |||||
sec2_ccc_expected.begin(), | |||||
sec2_ccc_expected.end()); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(util_GetArg) { | BOOST_AUTO_TEST_CASE(util_GetArg) { | ||||
TestArgsManager testArgs; | TestArgsManager testArgs; | ||||
testArgs.GetOverrideArgs().clear(); | testArgs.GetOverrideArgs().clear(); | ||||
testArgs.GetOverrideArgs()["strtest1"] = {"string..."}; | testArgs.GetOverrideArgs()["strtest1"] = {"string..."}; | ||||
// strtest2 undefined on purpose | // strtest2 undefined on purpose | ||||
testArgs.GetOverrideArgs()["inttest1"] = {"12345"}; | testArgs.GetOverrideArgs()["inttest1"] = {"12345"}; | ||||
▲ Show 20 Lines • Show All 728 Lines • Show Last 20 Lines |