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