Bitcoin Core  22.99.0
P2P Digital Currency
init_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 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 
5 #include <boost/test/unit_test.hpp>
6 
7 #include <noui.h>
8 #include <test/util/logging.h>
10 #include <util/system.h>
12 
13 namespace wallet {
14 BOOST_FIXTURE_TEST_SUITE(init_tests, InitWalletDirTestingSetup)
15 
16 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_default)
17 {
18  SetWalletDir(m_walletdir_path_cases["default"]);
19  bool result = m_wallet_loader->verify();
20  BOOST_CHECK(result == true);
21  fs::path walletdir = gArgs.GetPathArg("-walletdir");
22  fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
23  BOOST_CHECK_EQUAL(walletdir, expected_path);
24 }
25 
26 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_custom)
27 {
28  SetWalletDir(m_walletdir_path_cases["custom"]);
29  bool result = m_wallet_loader->verify();
30  BOOST_CHECK(result == true);
31  fs::path walletdir = gArgs.GetPathArg("-walletdir");
32  fs::path expected_path = fs::canonical(m_walletdir_path_cases["custom"]);
33  BOOST_CHECK_EQUAL(walletdir, expected_path);
34 }
35 
36 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_does_not_exist)
37 {
38  SetWalletDir(m_walletdir_path_cases["nonexistent"]);
39  {
40  ASSERT_DEBUG_LOG("does not exist");
41  bool result = m_wallet_loader->verify();
42  BOOST_CHECK(result == false);
43  }
44 }
45 
46 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_directory)
47 {
48  SetWalletDir(m_walletdir_path_cases["file"]);
49  {
50  ASSERT_DEBUG_LOG("is not a directory");
51  bool result = m_wallet_loader->verify();
52  BOOST_CHECK(result == false);
53  }
54 }
55 
56 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative)
57 {
58  SetWalletDir(m_walletdir_path_cases["relative"]);
59  {
60  ASSERT_DEBUG_LOG("is a relative path");
61  bool result = m_wallet_loader->verify();
62  BOOST_CHECK(result == false);
63  }
64 }
65 
66 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing)
67 {
68  SetWalletDir(m_walletdir_path_cases["trailing"]);
69  bool result = m_wallet_loader->verify();
70  BOOST_CHECK(result == true);
71  fs::path walletdir = gArgs.GetPathArg("-walletdir");
72  fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
73  BOOST_CHECK_EQUAL(walletdir, expected_path);
74 }
75 
76 BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2)
77 {
78  SetWalletDir(m_walletdir_path_cases["trailing2"]);
79  bool result = m_wallet_loader->verify();
80  BOOST_CHECK(result == true);
81  fs::path walletdir = gArgs.GetPathArg("-walletdir");
82  fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
83  BOOST_CHECK_EQUAL(walletdir, expected_path);
84 }
85 
87 } // namespace wallet
setup_common.h
ArgsManager::GetPathArg
fs::path GetPathArg(std::string pathlike_arg) const
Get a normalized path from a specified pathlike argument.
Definition: system.cpp:390
wallet
Definition: node.h:38
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
ASSERT_DEBUG_LOG
#define ASSERT_DEBUG_LOG(message)
Definition: logging.h:39
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:29
gArgs
ArgsManager gArgs
Definition: system.cpp:87
logging.h
wallet::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(bnb_search_test)
Definition: coinselector_tests.cpp:177
system.h
noui.h
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition: object.cpp:17
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
init_test_fixture.h