Bitcoin Core  24.99.0
P2P Digital Currency
getarg_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 #include <univalue.h>
7 #include <util/settings.h>
8 #include <util/strencodings.h>
9 #include <util/system.h>
10 
11 #include <limits>
12 #include <string>
13 #include <utility>
14 #include <vector>
15 
16 #include <boost/test/unit_test.hpp>
17 
18 BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup)
19 
20 void ResetArgs(ArgsManager& local_args, const std::string& strArg)
21 {
22  std::vector<std::string> vecArg;
23  if (strArg.size()) {
24  vecArg = SplitString(strArg, ' ');
25  }
26 
27  // Insert dummy executable name:
28  vecArg.insert(vecArg.begin(), "testbitcoin");
29 
30  // Convert to char*:
31  std::vector<const char*> vecChar;
32  for (const std::string& s : vecArg)
33  vecChar.push_back(s.c_str());
34 
35  std::string error;
36  BOOST_CHECK(local_args.ParseParameters(vecChar.size(), vecChar.data(), error));
37 }
38 
39 void SetupArgs(ArgsManager& local_args, const std::vector<std::pair<std::string, unsigned int>>& args)
40 {
41  for (const auto& arg : args) {
42  local_args.AddArg(arg.first, "", arg.second, OptionsCategory::OPTIONS);
43  }
44 }
45 
46 // Test behavior of GetArg functions when string, integer, and boolean types
47 // are specified in the settings.json file. GetArg functions are convenience
48 // functions. The GetSetting method can always be used instead of GetArg
49 // methods to retrieve original values, and there's not always an objective
50 // answer to what GetArg behavior is best in every case. This test makes sure
51 // there's test coverage for whatever the current behavior is, so it's not
52 // broken or changed unintentionally.
53 BOOST_AUTO_TEST_CASE(setting_args)
54 {
57 
58  auto set_foo = [&](const util::SettingsValue& value) {
59  args.LockSettings([&](util::Settings& settings) {
60  settings.rw_settings["foo"] = value;
61  });
62  };
63 
64  set_foo("str");
65  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "\"str\"");
66  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "str");
67  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
68  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), false);
69  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), false);
70 
71  set_foo("99");
72  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "\"99\"");
73  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "99");
74  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 99);
75  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), true);
76  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), true);
77 
78  set_foo("3.25");
79  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "\"3.25\"");
80  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "3.25");
81  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 3);
82  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), true);
83  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), true);
84 
85  set_foo("0");
86  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "\"0\"");
87  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "0");
88  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
89  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), false);
90  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), false);
91 
92  set_foo("");
93  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "\"\"");
94  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "");
95  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
96  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), true);
97  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), true);
98 
99  set_foo(99);
100  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "99");
101  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "99");
102  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 99);
103  BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
104  BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
105 
106  set_foo(3.25);
107  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "3.25");
108  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "3.25");
109  BOOST_CHECK_THROW(args.GetIntArg("foo", 100), std::runtime_error);
110  BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
111  BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
112 
113  set_foo(0);
114  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "0");
115  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "0");
116  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
117  BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
118  BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
119 
120  set_foo(true);
121  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "true");
122  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "1");
123  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 1);
124  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), true);
125  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), true);
126 
127  set_foo(false);
128  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "false");
129  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "0");
130  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
131  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), false);
132  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), false);
133 
134  set_foo(UniValue::VOBJ);
135  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "{}");
136  BOOST_CHECK_THROW(args.GetArg("foo", "default"), std::runtime_error);
137  BOOST_CHECK_THROW(args.GetIntArg("foo", 100), std::runtime_error);
138  BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
139  BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
140 
141  set_foo(UniValue::VARR);
142  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "[]");
143  BOOST_CHECK_THROW(args.GetArg("foo", "default"), std::runtime_error);
144  BOOST_CHECK_THROW(args.GetIntArg("foo", 100), std::runtime_error);
145  BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
146  BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
147 
148  set_foo(UniValue::VNULL);
149  BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "null");
150  BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "default");
151  BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 100);
152  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", true), true);
153  BOOST_CHECK_EQUAL(args.GetBoolArg("foo", false), false);
154 }
155 
157 {
158  ArgsManager local_args;
159 
160  const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
161  SetupArgs(local_args, {foo});
162  ResetArgs(local_args, "-foo");
163  BOOST_CHECK(local_args.GetBoolArg("-foo", false));
164  BOOST_CHECK(local_args.GetBoolArg("-foo", true));
165 
166  BOOST_CHECK(!local_args.GetBoolArg("-fo", false));
167  BOOST_CHECK(local_args.GetBoolArg("-fo", true));
168 
169  BOOST_CHECK(!local_args.GetBoolArg("-fooo", false));
170  BOOST_CHECK(local_args.GetBoolArg("-fooo", true));
171 
172  ResetArgs(local_args, "-foo=0");
173  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
174  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
175 
176  ResetArgs(local_args, "-foo=1");
177  BOOST_CHECK(local_args.GetBoolArg("-foo", false));
178  BOOST_CHECK(local_args.GetBoolArg("-foo", true));
179 
180  // New 0.6 feature: auto-map -nosomething to !-something:
181  ResetArgs(local_args, "-nofoo");
182  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
183  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
184 
185  ResetArgs(local_args, "-nofoo=1");
186  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
187  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
188 
189  ResetArgs(local_args, "-foo -nofoo"); // -nofoo should win
190  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
191  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
192 
193  ResetArgs(local_args, "-foo=1 -nofoo=1"); // -nofoo should win
194  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
195  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
196 
197  ResetArgs(local_args, "-foo=0 -nofoo=0"); // -nofoo=0 should win
198  BOOST_CHECK(local_args.GetBoolArg("-foo", false));
199  BOOST_CHECK(local_args.GetBoolArg("-foo", true));
200 
201  // New 0.6 feature: treat -- same as -:
202  ResetArgs(local_args, "--foo=1");
203  BOOST_CHECK(local_args.GetBoolArg("-foo", false));
204  BOOST_CHECK(local_args.GetBoolArg("-foo", true));
205 
206  ResetArgs(local_args, "--nofoo=1");
207  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
208  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
209 }
210 
212 {
213  ArgsManager local_args;
214 
215  const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
216  const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
217  SetupArgs(local_args, {foo, bar});
218  ResetArgs(local_args, "");
219  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "");
220  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "eleven");
221 
222  ResetArgs(local_args, "-foo -bar");
223  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "");
224  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "");
225 
226  ResetArgs(local_args, "-foo=");
227  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "");
228  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "");
229 
230  ResetArgs(local_args, "-foo=11");
231  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "11");
232  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "11");
233 
234  ResetArgs(local_args, "-foo=eleven");
235  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "eleven");
236  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", "eleven"), "eleven");
237 }
238 
240 {
241  ArgsManager local_args;
242 
243  const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
244  const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
245  SetupArgs(local_args, {foo, bar});
246  ResetArgs(local_args, "");
247  BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 11);
248  BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 0);
249 
250  ResetArgs(local_args, "-foo -bar");
251  BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 0);
252  BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
253 
254  // Check under-/overflow behavior.
255  ResetArgs(local_args, "-foo=-9223372036854775809 -bar=9223372036854775808");
256  BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), std::numeric_limits<int64_t>::min());
257  BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), std::numeric_limits<int64_t>::max());
258 
259  ResetArgs(local_args, "-foo=11 -bar=12");
260  BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 11);
261  BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 12);
262 
263  ResetArgs(local_args, "-foo=NaN -bar=NotANumber");
264  BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 1), 0);
265  BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
266 }
267 
269 {
270  ArgsManager local_args;
271 
272  const auto dir = std::make_pair("-dir", ArgsManager::ALLOW_ANY);
273  SetupArgs(local_args, {dir});
274  ResetArgs(local_args, "");
275  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), fs::path{});
276 
277  const fs::path root_path{"/"};
278  ResetArgs(local_args, "-dir=/");
279  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
280 
281  ResetArgs(local_args, "-dir=/.");
282  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
283 
284  ResetArgs(local_args, "-dir=/./");
285  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
286 
287  ResetArgs(local_args, "-dir=/.//");
288  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path);
289 
290 #ifdef WIN32
291  const fs::path win_root_path{"C:\\"};
292  ResetArgs(local_args, "-dir=C:\\");
293  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
294 
295  ResetArgs(local_args, "-dir=C:/");
296  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
297 
298  ResetArgs(local_args, "-dir=C:\\\\");
299  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
300 
301  ResetArgs(local_args, "-dir=C:\\.");
302  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
303 
304  ResetArgs(local_args, "-dir=C:\\.\\");
305  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
306 
307  ResetArgs(local_args, "-dir=C:\\.\\\\");
308  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path);
309 #endif
310 
311  const fs::path absolute_path{"/home/user/.bitcoin"};
312  ResetArgs(local_args, "-dir=/home/user/.bitcoin");
313  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
314 
315  ResetArgs(local_args, "-dir=/root/../home/user/.bitcoin");
316  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
317 
318  ResetArgs(local_args, "-dir=/home/./user/.bitcoin");
319  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
320 
321  ResetArgs(local_args, "-dir=/home/user/.bitcoin/");
322  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
323 
324  ResetArgs(local_args, "-dir=/home/user/.bitcoin//");
325  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
326 
327  ResetArgs(local_args, "-dir=/home/user/.bitcoin/.");
328  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
329 
330  ResetArgs(local_args, "-dir=/home/user/.bitcoin/./");
331  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
332 
333  ResetArgs(local_args, "-dir=/home/user/.bitcoin/.//");
334  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path);
335 
336  const fs::path relative_path{"user/.bitcoin"};
337  ResetArgs(local_args, "-dir=user/.bitcoin");
338  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
339 
340  ResetArgs(local_args, "-dir=somewhere/../user/.bitcoin");
341  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
342 
343  ResetArgs(local_args, "-dir=user/./.bitcoin");
344  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
345 
346  ResetArgs(local_args, "-dir=user/.bitcoin/");
347  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
348 
349  ResetArgs(local_args, "-dir=user/.bitcoin//");
350  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
351 
352  ResetArgs(local_args, "-dir=user/.bitcoin/.");
353  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
354 
355  ResetArgs(local_args, "-dir=user/.bitcoin/./");
356  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
357 
358  ResetArgs(local_args, "-dir=user/.bitcoin/.//");
359  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
360 
361  // Check negated and default argument handling. Specifying an empty argument
362  // is the same as not specifying the argument. This is convenient for
363  // scripting so later command line arguments can override earlier command
364  // line arguments or bitcoin.conf values. Currently the -dir= case cannot be
365  // distinguished from -dir case with no assignment, but #16545 would add the
366  // ability to distinguish these in the future (and treat the no-assign case
367  // like an imperative command or an error).
368  ResetArgs(local_args, "");
369  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
370  ResetArgs(local_args, "-dir=override");
371  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"override"});
372  ResetArgs(local_args, "-dir=");
373  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
374  ResetArgs(local_args, "-dir");
375  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
376  ResetArgs(local_args, "-nodir");
377  BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{""});
378 }
379 
381 {
382  ArgsManager local_args;
383 
384  const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
385  const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
386  SetupArgs(local_args, {foo, bar});
387  ResetArgs(local_args, "--foo");
388  BOOST_CHECK_EQUAL(local_args.GetBoolArg("-foo", false), true);
389 
390  ResetArgs(local_args, "--foo=verbose --bar=1");
391  BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "verbose");
392  BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), 1);
393 }
394 
396 {
397  ArgsManager local_args;
398 
399  const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
400  const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
401  SetupArgs(local_args, {foo, bar});
402  ResetArgs(local_args, "-nofoo");
403  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
404  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
405 
406  ResetArgs(local_args, "-nofoo=1");
407  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
408  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
409 
410  ResetArgs(local_args, "-nofoo=0");
411  BOOST_CHECK(local_args.GetBoolArg("-foo", true));
412  BOOST_CHECK(local_args.GetBoolArg("-foo", false));
413 
414  ResetArgs(local_args, "-foo --nofoo"); // --nofoo should win
415  BOOST_CHECK(!local_args.GetBoolArg("-foo", true));
416  BOOST_CHECK(!local_args.GetBoolArg("-foo", false));
417 
418  ResetArgs(local_args, "-nofoo -foo"); // foo always wins:
419  BOOST_CHECK(local_args.GetBoolArg("-foo", true));
420  BOOST_CHECK(local_args.GetBoolArg("-foo", false));
421 }
422 
424 {
425  ArgsManager local_args;
426 
427  const auto okaylog_bool = std::make_pair("-okaylog-bool", ArgsManager::ALLOW_ANY);
428  const auto okaylog_negbool = std::make_pair("-okaylog-negbool", ArgsManager::ALLOW_ANY);
429  const auto okaylog = std::make_pair("-okaylog", ArgsManager::ALLOW_ANY);
430  const auto dontlog = std::make_pair("-dontlog", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE);
431  SetupArgs(local_args, {okaylog_bool, okaylog_negbool, okaylog, dontlog});
432  ResetArgs(local_args, "-okaylog-bool -nookaylog-negbool -okaylog=public -dontlog=private42");
433 
434  // Everything logged to debug.log will also append to str
435  std::string str;
436  auto print_connection = LogInstance().PushBackCallback(
437  [&str](const std::string& s) {
438  str += s;
439  });
440 
441  // Log the arguments
442  local_args.LogArgs();
443 
444  LogInstance().DeleteCallback(print_connection);
445  // Check that what should appear does, and what shouldn't doesn't.
446  BOOST_CHECK(str.find("Command-line arg: okaylog-bool=\"\"") != std::string::npos);
447  BOOST_CHECK(str.find("Command-line arg: okaylog-negbool=false") != std::string::npos);
448  BOOST_CHECK(str.find("Command-line arg: okaylog=\"public\"") != std::string::npos);
449  BOOST_CHECK(str.find("dontlog=****") != std::string::npos);
450  BOOST_CHECK(str.find("private42") == std::string::npos);
451 }
452 
@ ALLOW_ANY
disable validation
Definition: system.h:172
@ SENSITIVE
Definition: system.h:188
void LockSettings(Fn &&fn)
Access settings with lock held.
Definition: system.h:466
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: system.cpp:616
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
Definition: system.cpp:1126
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:591
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
Definition: system.cpp:1095
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:641
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:698
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
Definition: system.cpp:380
std::list< std::function< void(const std::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun)
Connect a slot to the print signal and return the connection.
Definition: logging.h:137
void DeleteCallback(std::list< std::function< void(const std::string &)>>::iterator it)
Delete a connection.
Definition: logging.h:145
@ VNULL
Definition: univalue.h:20
@ VOBJ
Definition: univalue.h:20
@ VARR
Definition: univalue.h:20
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
BOOST_AUTO_TEST_SUITE_END()
void ResetArgs(ArgsManager &local_args, const std::string &strArg)
BOOST_AUTO_TEST_CASE(setting_args)
void SetupArgs(ArgsManager &local_args, const std::vector< std::pair< std::string, unsigned int >> &args)
BCLog::Logger & LogInstance()
Definition: logging.cpp:20
ArgsManager args
#define BOOST_CHECK_THROW(stmt, excMatch)
Definition: object.cpp:19
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:21
Basic testing setup.
Definition: setup_common.h:85
Stored settings.
Definition: settings.h:31
std::map< std::string, SettingsValue > rw_settings
Map of setting name to read-write file setting value.
Definition: settings.h:37
bool error(const char *fmt, const Args &... args)
Definition: system.h:48