2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2012-2021 The Bitcoin Core developers
|
2014-12-13 12:09:33 +08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-03-18 10:11:00 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2013-04-13 00:13:08 -05:00
|
|
|
|
2020-04-16 13:11:54 -04:00
|
|
|
#include <test/util/setup_common.h>
|
2018-12-06 12:12:15 +01:00
|
|
|
#include <util/strencodings.h>
|
2018-10-22 15:51:11 -07:00
|
|
|
#include <util/system.h>
|
2013-04-13 00:13:08 -05:00
|
|
|
|
2021-12-22 12:11:13 -05:00
|
|
|
#include <limits>
|
2013-04-13 00:13:08 -05:00
|
|
|
#include <string>
|
2019-07-27 20:27:08 +03:00
|
|
|
#include <utility>
|
2013-04-13 00:13:08 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2012-02-06 12:37:49 -05:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup)
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
void ResetArgs(ArgsManager& local_args, const std::string& strArg)
|
2012-02-06 12:37:49 -05:00
|
|
|
{
|
|
|
|
std::vector<std::string> vecArg;
|
2014-09-23 16:53:34 -04:00
|
|
|
if (strArg.size())
|
2022-02-12 17:32:47 +01:00
|
|
|
boost::split(vecArg, strArg, IsSpace, boost::token_compress_on);
|
2012-02-06 12:37:49 -05:00
|
|
|
|
|
|
|
// Insert dummy executable name:
|
|
|
|
vecArg.insert(vecArg.begin(), "testbitcoin");
|
|
|
|
|
|
|
|
// Convert to char*:
|
|
|
|
std::vector<const char*> vecChar;
|
2018-06-18 07:58:28 +02:00
|
|
|
for (const std::string& s : vecArg)
|
2012-02-06 12:37:49 -05:00
|
|
|
vecChar.push_back(s.c_str());
|
|
|
|
|
2018-04-28 19:40:51 -04:00
|
|
|
std::string error;
|
2022-02-12 17:32:47 +01:00
|
|
|
BOOST_CHECK(local_args.ParseParameters(vecChar.size(), vecChar.data(), error));
|
2018-04-28 19:40:51 -04:00
|
|
|
}
|
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
void SetupArgs(ArgsManager& local_args, const std::vector<std::pair<std::string, unsigned int>>& args)
|
2018-04-28 19:40:51 -04:00
|
|
|
{
|
2019-07-27 20:27:08 +03:00
|
|
|
for (const auto& arg : args) {
|
2022-02-12 17:32:47 +01:00
|
|
|
local_args.AddArg(arg.first, "", arg.second, OptionsCategory::OPTIONS);
|
2018-04-28 19:40:51 -04:00
|
|
|
}
|
2012-02-06 12:37:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(boolarg)
|
|
|
|
{
|
2022-02-12 17:32:47 +01:00
|
|
|
ArgsManager local_args;
|
|
|
|
|
2019-11-12 17:01:00 -05:00
|
|
|
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
|
2022-02-12 17:32:47 +01:00
|
|
|
SetupArgs(local_args, {foo});
|
|
|
|
ResetArgs(local_args, "-foo");
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", true));
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-fo", false));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-fo", true));
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-fooo", false));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-fooo", true));
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo=0");
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo=1");
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", true));
|
2012-02-06 13:55:11 -05:00
|
|
|
|
|
|
|
// New 0.6 feature: auto-map -nosomething to !-something:
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-nofoo");
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
2012-02-06 13:55:11 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-nofoo=1");
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
2012-02-06 13:55:11 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo -nofoo"); // -nofoo should win
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
2012-02-06 13:55:11 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo=1 -nofoo=1"); // -nofoo should win
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
2012-02-06 13:55:11 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo=0 -nofoo=0"); // -nofoo=0 should win
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", true));
|
2015-06-15 17:17:23 +02:00
|
|
|
|
2012-02-06 13:55:11 -05:00
|
|
|
// New 0.6 feature: treat -- same as -:
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "--foo=1");
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", true));
|
2012-02-06 13:55:11 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "--nofoo=1");
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
2012-02-06 12:37:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(stringarg)
|
|
|
|
{
|
2022-02-12 17:32:47 +01:00
|
|
|
ArgsManager local_args;
|
|
|
|
|
2019-11-12 17:01:00 -05:00
|
|
|
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
|
|
|
|
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
|
2022-02-12 17:32:47 +01:00
|
|
|
SetupArgs(local_args, {foo, bar});
|
|
|
|
ResetArgs(local_args, "");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "eleven");
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-foo -bar");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "");
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-foo=");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "");
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-foo=11");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "11");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "11");
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-foo=eleven");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "eleven");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "eleven");
|
2012-02-06 12:37:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(intarg)
|
|
|
|
{
|
2022-02-12 17:32:47 +01:00
|
|
|
ArgsManager local_args;
|
|
|
|
|
2019-11-12 17:01:00 -05:00
|
|
|
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
|
|
|
|
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
|
2022-02-12 17:32:47 +01:00
|
|
|
SetupArgs(local_args, {foo, bar});
|
|
|
|
ResetArgs(local_args, "");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 11);
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 0);
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo -bar");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 0);
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2021-12-22 12:11:13 -05:00
|
|
|
// Check under-/overflow behavior.
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo=-9223372036854775809 -bar=9223372036854775808");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), std::numeric_limits<int64_t>::min());
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), std::numeric_limits<int64_t>::max());
|
2021-12-22 12:11:13 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo=11 -bar=12");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 11);
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 12);
|
2012-02-06 12:37:49 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-foo=NaN -bar=NotANumber");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 1), 0);
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
|
2012-02-06 12:37:49 -05:00
|
|
|
}
|
|
|
|
|
2022-02-04 17:57:51 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(patharg)
|
|
|
|
{
|
2022-02-12 17:32:47 +01:00
|
|
|
ArgsManager local_args;
|
|
|
|
|
2022-02-04 17:57:51 +02:00
|
|
|
const auto dir = std::make_pair("-dir", ArgsManager::ALLOW_ANY);
|
2022-02-12 17:32:47 +01:00
|
|
|
SetupArgs(local_args, {dir});
|
|
|
|
ResetArgs(local_args, "");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), fs::path{});
|
2022-02-04 17:57:51 +02:00
|
|
|
|
|
|
|
const fs::path root_path{"/"};
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/.");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/./");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/.//");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
const fs::path win_root_path{"C:\\"};
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=C:\\");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=C:/");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=C:\\\\");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=C:\\.");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=C:\\.\\");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=C:\\.\\\\");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const fs::path absolute_path{"/home/user/.bitcoin"};
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/home/user/.bitcoin");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/root/../home/user/.bitcoin");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/home/./user/.bitcoin");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/home/user/.bitcoin/");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/home/user/.bitcoin//");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/home/user/.bitcoin/.");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/home/user/.bitcoin/./");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=/home/user/.bitcoin/.//");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
|
|
|
const fs::path relative_path{"user/.bitcoin"};
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=user/.bitcoin");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=somewhere/../user/.bitcoin");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=user/./.bitcoin");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=user/.bitcoin/");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=user/.bitcoin//");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=user/.bitcoin/.");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=user/.bitcoin/./");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "-dir=user/.bitcoin/.//");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
|
2022-02-04 17:57:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 13:55:11 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(doubledash)
|
|
|
|
{
|
2022-02-12 17:32:47 +01:00
|
|
|
ArgsManager local_args;
|
|
|
|
|
2019-07-27 20:27:08 +03:00
|
|
|
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
|
|
|
|
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
|
2022-02-12 17:32:47 +01:00
|
|
|
SetupArgs(local_args, {foo, bar});
|
|
|
|
ResetArgs(local_args, "--foo");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetBoolArg("-foo", false), true);
|
2012-02-06 13:55:11 -05:00
|
|
|
|
2022-02-12 17:32:47 +01:00
|
|
|
ResetArgs(local_args, "--foo=verbose --bar=1");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "verbose");
|
|
|
|
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), 1);
|
2012-02-06 13:55:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(boolargno)
|
|
|
|
{
|
2022-02-12 17:32:47 +01:00
|
|
|
ArgsManager local_args;
|
|
|
|
|
2019-11-12 17:01:00 -05:00
|
|
|
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
|
|
|
|
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
|
2022-02-12 17:32:47 +01:00
|
|
|
SetupArgs(local_args, {foo, bar});
|
|
|
|
ResetArgs(local_args, "-nofoo");
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-nofoo=1");
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-nofoo=0");
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", true));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", false));
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-foo --nofoo"); // --nofoo should win
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
|
|
|
|
BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
|
|
|
|
|
|
|
|
ResetArgs(local_args, "-nofoo -foo"); // foo always wins:
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", true));
|
|
|
|
BOOST_CHECK(local_args.GetBoolArg("-foo", false));
|
2012-02-06 13:55:11 -05:00
|
|
|
}
|
|
|
|
|
2020-01-20 08:32:42 -07:00
|
|
|
BOOST_AUTO_TEST_CASE(logargs)
|
|
|
|
{
|
2022-02-12 17:32:47 +01:00
|
|
|
ArgsManager local_args;
|
|
|
|
|
2021-08-18 21:08:08 -04:00
|
|
|
const auto okaylog_bool = std::make_pair("-okaylog-bool", ArgsManager::ALLOW_ANY);
|
|
|
|
const auto okaylog_negbool = std::make_pair("-okaylog-negbool", ArgsManager::ALLOW_ANY);
|
2020-01-20 08:32:42 -07:00
|
|
|
const auto okaylog = std::make_pair("-okaylog", ArgsManager::ALLOW_ANY);
|
|
|
|
const auto dontlog = std::make_pair("-dontlog", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE);
|
2022-02-12 17:32:47 +01:00
|
|
|
SetupArgs(local_args, {okaylog_bool, okaylog_negbool, okaylog, dontlog});
|
|
|
|
ResetArgs(local_args, "-okaylog-bool -nookaylog-negbool -okaylog=public -dontlog=private");
|
2020-01-20 08:32:42 -07:00
|
|
|
|
|
|
|
// Everything logged to debug.log will also append to str
|
|
|
|
std::string str;
|
|
|
|
auto print_connection = LogInstance().PushBackCallback(
|
|
|
|
[&str](const std::string& s) {
|
|
|
|
str += s;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Log the arguments
|
2022-02-12 17:32:47 +01:00
|
|
|
local_args.LogArgs();
|
2020-01-20 08:32:42 -07:00
|
|
|
|
|
|
|
LogInstance().DeleteCallback(print_connection);
|
|
|
|
// Check that what should appear does, and what shouldn't doesn't.
|
|
|
|
BOOST_CHECK(str.find("Command-line arg: okaylog-bool=\"\"") != std::string::npos);
|
|
|
|
BOOST_CHECK(str.find("Command-line arg: okaylog-negbool=false") != std::string::npos);
|
|
|
|
BOOST_CHECK(str.find("Command-line arg: okaylog=\"public\"") != std::string::npos);
|
|
|
|
BOOST_CHECK(str.find("dontlog=****") != std::string::npos);
|
|
|
|
BOOST_CHECK(str.find("private") == std::string::npos);
|
|
|
|
}
|
|
|
|
|
2012-02-06 12:37:49 -05:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|