aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/DoS_tests.cpp4
-rw-r--r--src/test/accounting_tests.cpp4
-rw-r--r--src/test/alert_tests.cpp4
-rw-r--r--src/test/miner_tests.cpp4
-rw-r--r--src/test/rpc_tests.cpp4
-rw-r--r--src/test/rpc_wallet_tests.cpp4
-rw-r--r--src/test/test_bitcoin.cpp28
-rw-r--r--src/test/test_bitcoin.h18
8 files changed, 50 insertions, 20 deletions
diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp
index 9407511ecb..bf25548755 100644
--- a/src/test/DoS_tests.cpp
+++ b/src/test/DoS_tests.cpp
@@ -16,6 +16,8 @@
#include "serialize.h"
#include "util.h"
+#include "test/test_bitcoin.h"
+
#include <stdint.h>
#include <boost/assign/list_of.hpp> // for 'map_list_of()'
@@ -41,7 +43,7 @@ CService ip(uint32_t i)
return CService(CNetAddr(s), Params().GetDefaultPort());
}
-BOOST_AUTO_TEST_SUITE(DoS_tests)
+BOOST_FIXTURE_TEST_SUITE(DoS_tests, TestingSetup)
BOOST_AUTO_TEST_CASE(DoS_banning)
{
diff --git a/src/test/accounting_tests.cpp b/src/test/accounting_tests.cpp
index da07b8c7a6..36499f01a7 100644
--- a/src/test/accounting_tests.cpp
+++ b/src/test/accounting_tests.cpp
@@ -5,6 +5,8 @@
#include "wallet.h"
#include "walletdb.h"
+#include "test/test_bitcoin.h"
+
#include <stdint.h>
#include <boost/foreach.hpp>
@@ -12,7 +14,7 @@
extern CWallet* pwalletMain;
-BOOST_AUTO_TEST_SUITE(accounting_tests)
+BOOST_FIXTURE_TEST_SUITE(accounting_tests, TestingSetup)
static void
GetResults(CWalletDB& walletdb, std::map<CAmount, CAccountingEntry>& results)
diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp
index efc9211717..5e1f5f0294 100644
--- a/src/test/alert_tests.cpp
+++ b/src/test/alert_tests.cpp
@@ -15,6 +15,8 @@
#include "util.h"
#include "utilstrencodings.h"
+#include "test/test_bitcoin.h"
+
#include <fstream>
#include <boost/filesystem/operations.hpp>
@@ -78,7 +80,7 @@
}
#endif
-struct ReadAlerts
+struct ReadAlerts : public TestingSetup
{
ReadAlerts()
{
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index 44c57a8eaf..6ab9cb8a44 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -8,9 +8,11 @@
#include "uint256.h"
#include "util.h"
+#include "test/test_bitcoin.h"
+
#include <boost/test/unit_test.hpp>
-BOOST_AUTO_TEST_SUITE(miner_tests)
+BOOST_FIXTURE_TEST_SUITE(miner_tests, TestingSetup)
static
struct {
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 1c6963001f..45cb551d04 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -8,6 +8,8 @@
#include "base58.h"
#include "netbase.h"
+#include "test/test_bitcoin.h"
+
#include <boost/algorithm/string.hpp>
#include <boost/test/unit_test.hpp>
@@ -45,7 +47,7 @@ Value CallRPC(string args)
}
-BOOST_AUTO_TEST_SUITE(rpc_tests)
+BOOST_FIXTURE_TEST_SUITE(rpc_tests, TestingSetup)
BOOST_AUTO_TEST_CASE(rpc_rawparams)
{
diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp
index 57c49c2dfc..44475076b3 100644
--- a/src/test/rpc_wallet_tests.cpp
+++ b/src/test/rpc_wallet_tests.cpp
@@ -8,6 +8,8 @@
#include "base58.h"
#include "wallet.h"
+#include "test/test_bitcoin.h"
+
#include <boost/algorithm/string.hpp>
#include <boost/test/unit_test.hpp>
@@ -19,7 +21,7 @@ extern Value CallRPC(string args);
extern CWallet* pwalletMain;
-BOOST_AUTO_TEST_SUITE(rpc_wallet_tests)
+BOOST_FIXTURE_TEST_SUITE(rpc_wallet_tests, TestingSetup)
BOOST_AUTO_TEST_CASE(rpc_addmultisig)
{
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)
{
diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h
new file mode 100644
index 0000000000..c1448dcdeb
--- /dev/null
+++ b/src/test/test_bitcoin.h
@@ -0,0 +1,18 @@
+#ifndef BITCOIN_TEST_TEST_BITCOIN_H
+#define BITCOIN_TEST_TEST_BITCOIN_H
+
+#include "txdb.h"
+
+#include <boost/filesystem.hpp>
+#include <boost/thread.hpp>
+
+struct TestingSetup {
+ CCoinsViewDB *pcoinsdbview;
+ boost::filesystem::path pathTemp;
+ boost::thread_group threadGroup;
+
+ TestingSetup();
+ ~TestingSetup();
+};
+
+#endif