Bitcoin ABC 0.30.7
P2P Digital Currency
options_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2022 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <common/args.h>
6#include <seeder/options.h>
7#include <util/string.h>
8
9#include <boost/test/unit_test.hpp>
10
11static const char *TEST_HOST = "-host=seeder.bitcoinabc.org";
12static const char *TEST_NAMESERVER = "-ns=localhost";
13static const char *TEST_EMAIL = "[email protected]";
14
16public:
19
21};
22
23BOOST_AUTO_TEST_SUITE(options_tests)
24
26 const char *argv[] = {"ignored"};
27 BOOST_CHECK(opts.ParseCommandLine(1, argv) == seeder::CONTINUE_EXECUTION);
28 BOOST_CHECK(opts.dumpInterval ==
29 std::chrono::seconds(seeder::DEFAULT_DUMP_INTERVAL_SECONDS));
30 BOOST_CHECK(opts.nPort == seeder::DEFAULT_PORT);
33 BOOST_CHECK(opts.fWipeBan == seeder::DEFAULT_WIPE_BAN);
34 BOOST_CHECK(opts.fWipeIgnore == seeder::DEFAULT_WIPE_IGNORE);
35}
36
38 const char *argv[] = {"ignored", TEST_HOST, TEST_NAMESERVER, TEST_EMAIL,
39 "-port=5555"};
40 BOOST_CHECK(opts.ParseCommandLine(5, argv) == seeder::CONTINUE_EXECUTION);
41 BOOST_CHECK(opts.host == "seeder.bitcoinabc.org");
42 BOOST_CHECK(opts.ns == "localhost");
43 BOOST_CHECK(opts.mbox == "[email protected]");
44 BOOST_CHECK(opts.nPort == 5555);
45}
46
47BOOST_FIXTURE_TEST_CASE(options_dumpinterval_test, ArgsTestingSetup) {
48 const std::map<int, int> expectedResults = {
49 {-9999, EXIT_FAILURE},
50 {-1, EXIT_FAILURE},
51 {0, EXIT_FAILURE},
55
56 for (const auto entry : expectedResults) {
57 const std::string testArg = "-dumpinterval=" + ToString(entry.first);
58 const char *argv[] = {"ignored", TEST_HOST, TEST_NAMESERVER, TEST_EMAIL,
59 testArg.c_str()};
60 BOOST_CHECK(opts.ParseCommandLine(5, argv) == entry.second);
61 if (entry.second == seeder::CONTINUE_EXECUTION) {
62 BOOST_CHECK(opts.dumpInterval == std::chrono::seconds(entry.first));
63 }
64 }
65}
66
68 const std::map<int, int> expectedResults = {
69 {-9999, EXIT_FAILURE},
70 {-1, EXIT_FAILURE},
71 {0, EXIT_FAILURE},
75
76 for (const auto entry : expectedResults) {
77 const std::string testArg = "-threads=" + ToString(entry.first);
78 const char *argv[] = {"ignored", TEST_HOST, TEST_NAMESERVER, TEST_EMAIL,
79 testArg.c_str()};
80 BOOST_CHECK(opts.ParseCommandLine(5, argv) == entry.second);
81 if (entry.second == seeder::CONTINUE_EXECUTION) {
82 BOOST_CHECK(opts.nThreads == entry.first);
83 }
84 }
85}
86
87BOOST_FIXTURE_TEST_CASE(options_dns_threads_test, ArgsTestingSetup) {
88 const std::map<int, int> expectedResults = {
89 {-9999, EXIT_FAILURE},
90 {-1, EXIT_FAILURE},
91 {0, EXIT_FAILURE},
95
96 for (const auto entry : expectedResults) {
97 const std::string testArg = "-dnsthreads=" + ToString(entry.first);
98 const char *argv[] = {"ignored", TEST_HOST, TEST_NAMESERVER, TEST_EMAIL,
99 testArg.c_str()};
100 BOOST_CHECK(opts.ParseCommandLine(5, argv) == entry.second);
101 if (entry.second == seeder::CONTINUE_EXECUTION) {
102 BOOST_CHECK(opts.nDnsThreads == entry.first);
103 }
104 }
105}
106
108 const std::map<int, int> expectedResults = {
109 {-9999, EXIT_FAILURE},
110 {-1, EXIT_FAILURE},
111 // Note: port 0 indicates to the kernel that a random unused port should
112 // be assigned
119 {65536, EXIT_FAILURE},
120 {999999, EXIT_FAILURE}};
121
122 for (const auto entry : expectedResults) {
123 const std::string testArg = "-port=" + ToString(entry.first);
124 const char *argv[] = {"ignored", TEST_HOST, TEST_NAMESERVER, TEST_EMAIL,
125 testArg.c_str()};
126 BOOST_CHECK(opts.ParseCommandLine(5, argv) == entry.second);
127 if (entry.second == seeder::CONTINUE_EXECUTION) {
128 BOOST_CHECK(opts.nPort == entry.first);
129 }
130 }
131}
132
133BOOST_AUTO_TEST_SUITE_END()
ArgsManager argsManager
seeder::CDnsSeedOpts opts
static const bool DEFAULT_WIPE_BAN
Definition: options.h:22
static const int CONTINUE_EXECUTION
Definition: options.h:16
static const int DEFAULT_NUM_DNS_THREADS
Definition: options.h:21
static const int DEFAULT_DUMP_INTERVAL_SECONDS
Definition: options.h:18
static const bool DEFAULT_WIPE_IGNORE
Definition: options.h:23
static const int DEFAULT_NUM_THREADS
Definition: options.h:19
static const int DEFAULT_PORT
Definition: options.h:20
#define BOOST_CHECK(expr)
Definition: object.cpp:17
BOOST_FIXTURE_TEST_CASE(options_defaults_test, ArgsTestingSetup)
static const char * TEST_HOST
static const char * TEST_EMAIL
static const char * TEST_NAMESERVER
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:100