aboutsummaryrefslogtreecommitdiff
path: root/src/test/util_tests.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2018-04-04 18:08:00 +1000
committerAnthony Towns <aj@erisian.com.au>2018-04-11 23:15:28 +1000
commit608415d4e6c6518aed248f33a58e07ba1e3df4c0 (patch)
tree32d9ce0f3395e73fb8b53944829e66f56b9e7177 /src/test/util_tests.cpp
parent68797e20f478d835b7ff691a656242c14283446a (diff)
[tests] Unit tests for network-specific config entries
Diffstat (limited to 'src/test/util_tests.cpp')
-rw-r--r--src/test/util_tests.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 1eb0d654f4..98ded7bc8c 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -187,6 +187,7 @@ BOOST_AUTO_TEST_CASE(util_FormatISO8601Time)
struct TestArgsManager : public ArgsManager
{
+ TestArgsManager() { m_network_only_args.clear(); }
std::map<std::string, std::vector<std::string> >& GetOverrideArgs() { return m_override_args; }
std::map<std::string, std::vector<std::string> >& GetConfigArgs() { return m_config_args; }
void ReadConfigString(const std::string str_config)
@@ -198,6 +199,11 @@ struct TestArgsManager : public ArgsManager
}
ReadConfigStream(streamConfig);
}
+ void SetNetworkOnlyArg(const std::string arg)
+ {
+ LOCK(cs_args);
+ m_network_only_args.insert(arg);
+ }
};
BOOST_AUTO_TEST_CASE(util_ParseParameters)
@@ -327,6 +333,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
"\n"
"[sec1]\n"
"ccc=extend2\n"
+ "d=eee\n"
"h=1\n"
"[sec2]\n"
"ccc=extend3\n"
@@ -336,10 +343,10 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
test_args.ReadConfigString(str_config);
// expectation: a, b, ccc, d, fff, ggg, h, i end up in map
- // so do sec1.ccc, sec1.h, sec2.ccc, sec2.iii
+ // so do sec1.ccc, sec1.d, sec1.h, sec2.ccc, sec2.iii
BOOST_CHECK(test_args.GetOverrideArgs().empty());
- BOOST_CHECK(test_args.GetConfigArgs().size() == 12);
+ BOOST_CHECK(test_args.GetConfigArgs().size() == 13);
BOOST_CHECK(test_args.GetConfigArgs().count("-a")
&& test_args.GetConfigArgs().count("-b")
@@ -429,12 +436,13 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
// 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"
);
+ // d is overridden
+ BOOST_CHECK(test_args.GetArg("-d", "xxx") == "eee");
// section-specific setting
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "1");
// section takes priority for multiple values
@@ -463,6 +471,29 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
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());
+
+ // Test section only options
+
+ test_args.SetNetworkOnlyArg("-d");
+ test_args.SetNetworkOnlyArg("-ccc");
+ test_args.SetNetworkOnlyArg("-h");
+
+ test_args.SelectConfigNetwork(CBaseChainParams::MAIN);
+ BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e");
+ BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2);
+ BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0");
+
+ test_args.SelectConfigNetwork("sec1");
+ BOOST_CHECK(test_args.GetArg("-d", "xxx") == "eee");
+ BOOST_CHECK(test_args.GetArgs("-d").size() == 1);
+ BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2);
+ BOOST_CHECK(test_args.GetArg("-h", "xxx") == "1");
+
+ test_args.SelectConfigNetwork("sec2");
+ BOOST_CHECK(test_args.GetArg("-d", "xxx") == "xxx");
+ BOOST_CHECK(test_args.GetArgs("-d").size() == 0);
+ BOOST_CHECK(test_args.GetArgs("-ccc").size() == 1);
+ BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0");
}
BOOST_AUTO_TEST_CASE(util_GetArg)