mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 15:39:05 +01:00
test: Make tests arg type specific
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <test/setup_common.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@@ -32,17 +33,18 @@ static void ResetArgs(const std::string& strArg)
|
||||
BOOST_CHECK(gArgs.ParseParameters(vecChar.size(), vecChar.data(), error));
|
||||
}
|
||||
|
||||
static void SetupArgs(const std::vector<std::string>& args)
|
||||
static void SetupArgs(const std::vector<std::pair<std::string, unsigned int>>& args)
|
||||
{
|
||||
gArgs.ClearArgs();
|
||||
for (const std::string& arg : args) {
|
||||
gArgs.AddArg(arg, "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
for (const auto& arg : args) {
|
||||
gArgs.AddArg(arg.first, "", arg.second, OptionsCategory::OPTIONS);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(boolarg)
|
||||
{
|
||||
SetupArgs({"-foo"});
|
||||
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_BOOL);
|
||||
SetupArgs({foo});
|
||||
ResetArgs("-foo");
|
||||
BOOST_CHECK(gArgs.GetBoolArg("-foo", false));
|
||||
BOOST_CHECK(gArgs.GetBoolArg("-foo", true));
|
||||
@@ -95,7 +97,9 @@ BOOST_AUTO_TEST_CASE(boolarg)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(stringarg)
|
||||
{
|
||||
SetupArgs({"-foo", "-bar"});
|
||||
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_STRING);
|
||||
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_STRING);
|
||||
SetupArgs({foo, bar});
|
||||
ResetArgs("");
|
||||
BOOST_CHECK_EQUAL(gArgs.GetArg("-foo", ""), "");
|
||||
BOOST_CHECK_EQUAL(gArgs.GetArg("-foo", "eleven"), "eleven");
|
||||
@@ -120,7 +124,9 @@ BOOST_AUTO_TEST_CASE(stringarg)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(intarg)
|
||||
{
|
||||
SetupArgs({"-foo", "-bar"});
|
||||
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_INT);
|
||||
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_INT);
|
||||
SetupArgs({foo, bar});
|
||||
ResetArgs("");
|
||||
BOOST_CHECK_EQUAL(gArgs.GetArg("-foo", 11), 11);
|
||||
BOOST_CHECK_EQUAL(gArgs.GetArg("-foo", 0), 0);
|
||||
@@ -140,7 +146,9 @@ BOOST_AUTO_TEST_CASE(intarg)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(doubledash)
|
||||
{
|
||||
SetupArgs({"-foo", "-bar"});
|
||||
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
|
||||
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
|
||||
SetupArgs({foo, bar});
|
||||
ResetArgs("--foo");
|
||||
BOOST_CHECK_EQUAL(gArgs.GetBoolArg("-foo", false), true);
|
||||
|
||||
@@ -151,7 +159,9 @@ BOOST_AUTO_TEST_CASE(doubledash)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(boolargno)
|
||||
{
|
||||
SetupArgs({"-foo", "-bar"});
|
||||
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_BOOL);
|
||||
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_BOOL);
|
||||
SetupArgs({foo, bar});
|
||||
ResetArgs("-nofoo");
|
||||
BOOST_CHECK(!gArgs.GetBoolArg("-foo", true));
|
||||
BOOST_CHECK(!gArgs.GetBoolArg("-foo", false));
|
||||
|
||||
Reference in New Issue
Block a user