Line data Source code
1 : // Copyright (c) 2018-2019 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 <memory> 6 : 7 : #include <boost/test/unit_test.hpp> 8 : 9 : #include <fs.h> 10 : #include <test/util/setup_common.h> 11 : #include <wallet/bdb.h> 12 : 13 : 14 89 : BOOST_FIXTURE_TEST_SUITE(db_tests, BasicTestingSetup) 15 : 16 95 : BOOST_AUTO_TEST_CASE(getwalletenv_file) 17 : { 18 1 : std::string test_name = "test_name.dat"; 19 1 : const fs::path datadir = GetDataDir(); 20 1 : fs::path file_path = datadir / test_name; 21 1 : std::ofstream f(file_path.BOOST_FILESYSTEM_C_STR); 22 1 : f.close(); 23 : 24 1 : std::string filename; 25 1 : std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, filename); 26 1 : BOOST_CHECK(filename == test_name); 27 1 : BOOST_CHECK(env->Directory() == datadir); 28 1 : } 29 : 30 95 : BOOST_AUTO_TEST_CASE(getwalletenv_directory) 31 : { 32 1 : std::string expected_name = "wallet.dat"; 33 1 : const fs::path datadir = GetDataDir(); 34 : 35 1 : std::string filename; 36 1 : std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(datadir, filename); 37 1 : BOOST_CHECK(filename == expected_name); 38 1 : BOOST_CHECK(env->Directory() == datadir); 39 1 : } 40 : 41 95 : BOOST_AUTO_TEST_CASE(getwalletenv_g_dbenvs_multiple) 42 : { 43 1 : fs::path datadir = GetDataDir() / "1"; 44 1 : fs::path datadir_2 = GetDataDir() / "2"; 45 1 : std::string filename; 46 : 47 1 : std::shared_ptr<BerkeleyEnvironment> env_1 = GetWalletEnv(datadir, filename); 48 1 : std::shared_ptr<BerkeleyEnvironment> env_2 = GetWalletEnv(datadir, filename); 49 1 : std::shared_ptr<BerkeleyEnvironment> env_3 = GetWalletEnv(datadir_2, filename); 50 : 51 1 : BOOST_CHECK(env_1 == env_2); 52 1 : BOOST_CHECK(env_2 != env_3); 53 1 : } 54 : 55 95 : BOOST_AUTO_TEST_CASE(getwalletenv_g_dbenvs_free_instance) 56 : { 57 1 : fs::path datadir = GetDataDir() / "1"; 58 1 : fs::path datadir_2 = GetDataDir() / "2"; 59 1 : std::string filename; 60 : 61 1 : std::shared_ptr <BerkeleyEnvironment> env_1_a = GetWalletEnv(datadir, filename); 62 1 : std::shared_ptr <BerkeleyEnvironment> env_2_a = GetWalletEnv(datadir_2, filename); 63 1 : env_1_a.reset(); 64 : 65 1 : std::shared_ptr<BerkeleyEnvironment> env_1_b = GetWalletEnv(datadir, filename); 66 1 : std::shared_ptr<BerkeleyEnvironment> env_2_b = GetWalletEnv(datadir_2, filename); 67 : 68 1 : BOOST_CHECK(env_1_a != env_1_b); 69 1 : BOOST_CHECK(env_2_a == env_2_b); 70 1 : } 71 : 72 89 : BOOST_AUTO_TEST_SUITE_END()