13#include <boost/algorithm/string.hpp>
14#include <boost/test/unit_test.hpp>
19 void SetupArgs(
const std::vector<std::pair<std::string, unsigned int>>& args);
20 void ResetArgs(
const std::string& strArg);
29 std::vector<std::string> vecArg;
31 boost::split(vecArg, strArg,
IsSpace, boost::token_compress_on);
34 vecArg.insert(vecArg.begin(),
"testbitcoin");
37 std::vector<const char*> vecChar;
38 for (
const std::string& s : vecArg)
39 vecChar.push_back(s.c_str());
42 BOOST_CHECK(m_local_args.ParseParameters(vecChar.size(), vecChar.data(),
error));
45void LocalTestingSetup :: SetupArgs(
const std::vector<std::pair<std::string, unsigned int>>& args)
47 m_local_args.ClearArgs();
48 for (
const auto& arg : args) {
58 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
false));
61 BOOST_CHECK(!m_local_args.GetBoolArg(
"-fo",
false));
64 BOOST_CHECK(!m_local_args.GetBoolArg(
"-fooo",
false));
65 BOOST_CHECK(m_local_args.GetBoolArg(
"-fooo",
true));
68 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
69 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
72 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
false));
77 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
78 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
80 ResetArgs(
"-nofoo=1");
81 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
82 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
84 ResetArgs(
"-foo -nofoo");
85 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
86 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
88 ResetArgs(
"-foo=1 -nofoo=1");
89 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
90 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
92 ResetArgs(
"-foo=0 -nofoo=0");
93 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
false));
98 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
false));
101 ResetArgs(
"--nofoo=1");
102 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
103 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
111 SetupArgs({foo, bar});
116 ResetArgs(
"-foo -bar");
124 ResetArgs(
"-foo=11");
128 ResetArgs(
"-foo=eleven");
138 SetupArgs({foo, bar});
143 ResetArgs(
"-foo -bar");
147 ResetArgs(
"-foo=11 -bar=12");
151 ResetArgs(
"-foo=NaN -bar=NotANumber");
160 SetupArgs({foo, bar});
164 ResetArgs(
"--foo=verbose --bar=1");
173 SetupArgs({foo, bar});
175 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
176 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
178 ResetArgs(
"-nofoo=1");
179 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
180 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
182 ResetArgs(
"-nofoo=0");
183 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
true));
184 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
false));
186 ResetArgs(
"-foo --nofoo");
187 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
true));
188 BOOST_CHECK(!m_local_args.GetBoolArg(
"-foo",
false));
190 ResetArgs(
"-nofoo -foo");
191 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
true));
192 BOOST_CHECK(m_local_args.GetBoolArg(
"-foo",
false));
201 SetupArgs({okaylog_bool, okaylog_negbool, okaylog, dontlog});
202 ResetArgs(
"-okaylog-bool -nookaylog-negbool -okaylog=public -dontlog=private");
207 [&str](
const std::string& s) {
212 m_local_args.LogArgs();
216 BOOST_CHECK(str.find(
"Command-line arg: okaylog-bool=\"\"") != std::string::npos);
217 BOOST_CHECK(str.find(
"Command-line arg: okaylog-negbool=false") != std::string::npos);
218 BOOST_CHECK(str.find(
"Command-line arg: okaylog=\"public\"") != std::string::npos);
219 BOOST_CHECK(str.find(
"dontlog=****") != std::string::npos);
220 BOOST_CHECK(str.find(
"private") == std::string::npos);
@ ALLOW_ANY
disable validation
std::list< std::function< void(conststd::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun)
Connect a slot to the print signal and return the connection.
void DeleteCallback(std::list< std::function< void(const std::string &)> >::iterator it)
Delete a connection.
void ResetArgs(const std::string &strArg)
void SetupArgs(const std::vector< std::pair< std::string, unsigned int > > &args)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(boolarg)
BCLog::Logger & LogInstance()
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
bool error(const char *fmt, const Args &... args)