diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2015-03-03 07:49:12 -0800 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2015-03-03 09:01:46 -0800 |
commit | 51598b26319bf1ee98b399dee8152b902c62891a (patch) | |
tree | 21805efdbe19e67f3ed953695cb5f27c9d4ff4fe /src/test/test_bitcoin.cpp | |
parent | 86eb461c5bbe8200ab066f75b5acdf79fbae1086 (diff) |
Reinitialize state in between individual unit tests.
This changes the TestingSetup fixture to be per-unit-test rather than global.
Most tests don't need it, so it's only invoked in a few.
Diffstat (limited to 'src/test/test_bitcoin.cpp')
-rw-r--r-- | src/test/test_bitcoin.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index f2dae99d69..5df417b8e5 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -4,6 +4,8 @@ #define BOOST_TEST_MODULE Bitcoin Test Suite +#include "test_bitcoin.h" + #include "main.h" #include "random.h" #include "txdb.h" @@ -24,18 +26,15 @@ CWallet* pwalletMain; extern bool fPrintToConsole; extern void noui_connect(); -struct TestingSetup { - CCoinsViewDB *pcoinsdbview; - boost::filesystem::path pathTemp; - boost::thread_group threadGroup; - - TestingSetup() { +TestingSetup::TestingSetup() +{ fPrintToDebugLog = false; // don't want to write to debug.log file SelectParams(CBaseChainParams::UNITTEST); noui_connect(); #ifdef ENABLE_WALLET bitdb.MakeMock(); #endif + ClearDatadirCache(); pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); boost::filesystem::create_directories(pathTemp); mapArgs["-datadir"] = pathTemp.string(); @@ -53,27 +52,28 @@ struct TestingSetup { for (int i=0; i < nScriptCheckThreads-1; i++) threadGroup.create_thread(&ThreadScriptCheck); RegisterNodeSignals(GetNodeSignals()); - } - ~TestingSetup() - { +} + +TestingSetup::~TestingSetup() +{ + UnregisterNodeSignals(GetNodeSignals()); threadGroup.interrupt_all(); threadGroup.join_all(); - UnregisterNodeSignals(GetNodeSignals()); #ifdef ENABLE_WALLET + UnregisterValidationInterface(pwalletMain); delete pwalletMain; pwalletMain = NULL; #endif + UnloadBlockIndex(); delete pcoinsTip; delete pcoinsdbview; delete pblocktree; #ifdef ENABLE_WALLET bitdb.Flush(true); + bitdb.Reset(); #endif boost::filesystem::remove_all(pathTemp); - } -}; - -BOOST_GLOBAL_FIXTURE(TestingSetup); +} void Shutdown(void* parg) { |