Skip to content

Commit 77a733a

Browse files
committed
[tests] Add additional unit tests for -nofoo edge cases
1 parent af173c2 commit 77a733a

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/test/util_tests.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,52 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases)
258258
{
259259
// Test some awful edge cases that hopefully no user will ever exercise.
260260
TestArgsManager testArgs;
261+
262+
// Params test
261263
const char *argv_test[] = {"ignored", "-nofoo", "-foo", "-nobar=0"};
262264
testArgs.ParseParameters(4, (char**)argv_test);
263265

264266
// This was passed twice, second one overrides the negative setting.
265267
BOOST_CHECK(!testArgs.IsArgNegated("-foo"));
266-
BOOST_CHECK(testArgs.GetBoolArg("-foo", false) == true);
268+
BOOST_CHECK(testArgs.GetArg("-foo", "xxx") == "");
267269

268270
// A double negative is a positive.
269271
BOOST_CHECK(testArgs.IsArgNegated("-bar"));
270-
BOOST_CHECK(testArgs.GetBoolArg("-bar", false) == true);
272+
BOOST_CHECK(testArgs.GetArg("-bar", "xxx") == "1");
273+
274+
// Config test
275+
const char *conf_test = "nofoo=1\nfoo=1\nnobar=0\n";
276+
testArgs.ParseParameters(1, (char**)argv_test);
277+
testArgs.ReadConfigString(conf_test);
278+
279+
// This was passed twice, second one overrides the negative setting,
280+
// but not the value.
281+
BOOST_CHECK(!testArgs.IsArgNegated("-foo"));
282+
BOOST_CHECK(testArgs.GetArg("-foo", "xxx") == "0");
283+
284+
// A double negative is a positive.
285+
BOOST_CHECK(testArgs.IsArgNegated("-bar"));
286+
BOOST_CHECK(testArgs.GetArg("-bar", "xxx") == "1");
287+
288+
// Combined test
289+
const char *combo_test_args[] = {"ignored", "-nofoo", "-bar"};
290+
const char *combo_test_conf = "foo=1\nnobar=1\n";
291+
testArgs.ParseParameters(3, (char**)combo_test_args);
292+
testArgs.ReadConfigString(combo_test_conf);
293+
294+
// Command line overrides, but doesn't erase old setting
295+
BOOST_CHECK(!testArgs.IsArgNegated("-foo"));
296+
BOOST_CHECK(testArgs.GetArg("-foo", "xxx") == "0");
297+
BOOST_CHECK(testArgs.GetArgs("-foo").size() == 2
298+
&& testArgs.GetArgs("-foo").front() == "0"
299+
&& testArgs.GetArgs("-foo").back() == "1");
300+
301+
// Command line overrides, but doesn't erase old setting
302+
BOOST_CHECK(testArgs.IsArgNegated("-bar"));
303+
BOOST_CHECK(testArgs.GetArg("-bar", "xxx") == "");
304+
BOOST_CHECK(testArgs.GetArgs("-bar").size() == 2
305+
&& testArgs.GetArgs("-bar").front() == ""
306+
&& testArgs.GetArgs("-bar").back() == "0");
271307
}
272308

273309
BOOST_AUTO_TEST_CASE(util_ReadConfigStream)

0 commit comments

Comments
 (0)