Bitcoin Core 22.99.0
P2P Digital Currency
init_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2018-2020 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
14
15BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_default)
16{
17 SetWalletDir(m_walletdir_path_cases["default"]);
18 bool result = m_wallet_client->verify();
19 BOOST_CHECK(result == true);
20 fs::path walletdir = fs::PathFromString(gArgs.GetArg("-walletdir", ""));
21 fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
22 BOOST_CHECK_EQUAL(walletdir, expected_path);
23}
24
25BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_custom)
26{
27 SetWalletDir(m_walletdir_path_cases["custom"]);
28 bool result = m_wallet_client->verify();
29 BOOST_CHECK(result == true);
30 fs::path walletdir = fs::PathFromString(gArgs.GetArg("-walletdir", ""));
31 fs::path expected_path = fs::canonical(m_walletdir_path_cases["custom"]);
32 BOOST_CHECK_EQUAL(walletdir, expected_path);
33}
34
35BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_does_not_exist)
36{
37 SetWalletDir(m_walletdir_path_cases["nonexistent"]);
38 {
39 ASSERT_DEBUG_LOG("does not exist");
40 bool result = m_wallet_client->verify();
41 BOOST_CHECK(result == false);
42 }
43}
44
45BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_directory)
46{
47 SetWalletDir(m_walletdir_path_cases["file"]);
48 {
49 ASSERT_DEBUG_LOG("is not a directory");
50 bool result = m_wallet_client->verify();
51 BOOST_CHECK(result == false);
52 }
53}
54
55BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative)
56{
57 SetWalletDir(m_walletdir_path_cases["relative"]);
58 {
59 ASSERT_DEBUG_LOG("is a relative path");
60 bool result = m_wallet_client->verify();
61 BOOST_CHECK(result == false);
62 }
63}
64
65BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing)
66{
67 SetWalletDir(m_walletdir_path_cases["trailing"]);
68 bool result = m_wallet_client->verify();
69 BOOST_CHECK(result == true);
70 fs::path walletdir = fs::PathFromString(gArgs.GetArg("-walletdir", ""));
71 fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
72 BOOST_CHECK_EQUAL(walletdir, expected_path);
73}
74
75BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_no_trailing2)
76{
77 SetWalletDir(m_walletdir_path_cases["trailing2"]);
78 bool result = m_wallet_client->verify();
79 BOOST_CHECK(result == true);
80 fs::path walletdir = fs::PathFromString(gArgs.GetArg("-walletdir", ""));
81 fs::path expected_path = fs::canonical(m_walletdir_path_cases["default"]);
82 BOOST_CHECK_EQUAL(walletdir, expected_path);
83}
84
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:590
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
Definition: fs.h:34
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_default)
Definition: init_tests.cpp:15
static path PathFromString(const std::string &string)
Convert byte string to path object.
Definition: fs.h:133
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
#define ASSERT_DEBUG_LOG(message)
Definition: logging.h:39
ArgsManager gArgs
Definition: system.cpp:85