2011-08-02 15:34:23 +00:00
|
|
|
#define BOOST_TEST_MODULE Bitcoin Test Suite
|
2013-04-13 05:13:08 +00:00
|
|
|
|
|
|
|
|
2011-06-27 18:05:02 +00:00
|
|
|
|
2012-05-22 19:51:13 +00:00
|
|
|
#include "db.h"
|
2011-10-11 23:50:06 +00:00
|
|
|
#include "main.h"
|
2013-04-13 05:13:08 +00:00
|
|
|
#include "txdb.h"
|
|
|
|
#include "ui_interface.h"
|
2012-11-28 20:58:41 +00:00
|
|
|
#include "util.h"
|
2013-11-29 15:04:29 +00:00
|
|
|
#ifdef ENABLE_WALLET
|
2013-04-13 05:13:08 +00:00
|
|
|
#include "wallet.h"
|
2013-11-29 15:04:29 +00:00
|
|
|
#endif
|
2013-04-13 05:13:08 +00:00
|
|
|
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2011-07-31 18:00:38 +00:00
|
|
|
|
2012-01-05 02:40:52 +00:00
|
|
|
CWallet* pwalletMain;
|
|
|
|
|
2011-10-03 20:14:13 +00:00
|
|
|
extern bool fPrintToConsole;
|
2012-05-19 07:35:26 +00:00
|
|
|
extern void noui_connect();
|
|
|
|
|
2011-10-03 20:14:13 +00:00
|
|
|
struct TestingSetup {
|
2012-09-03 13:26:57 +00:00
|
|
|
CCoinsViewDB *pcoinsdbview;
|
2012-11-28 20:58:41 +00:00
|
|
|
boost::filesystem::path pathTemp;
|
2013-03-07 03:31:26 +00:00
|
|
|
boost::thread_group threadGroup;
|
2012-09-03 13:26:57 +00:00
|
|
|
|
2011-10-03 20:14:13 +00:00
|
|
|
TestingSetup() {
|
2012-08-20 15:33:20 +00:00
|
|
|
fPrintToDebugger = true; // don't want to write to debug.log file
|
2012-05-19 07:35:26 +00:00
|
|
|
noui_connect();
|
2013-11-29 15:04:29 +00:00
|
|
|
#ifdef ENABLE_WALLET
|
2012-05-22 19:51:13 +00:00
|
|
|
bitdb.MakeMock();
|
2013-11-29 15:04:29 +00:00
|
|
|
#endif
|
2012-11-28 20:58:41 +00:00
|
|
|
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
|
|
|
|
boost::filesystem::create_directories(pathTemp);
|
|
|
|
mapArgs["-datadir"] = pathTemp.string();
|
2012-11-09 23:09:57 +00:00
|
|
|
pblocktree = new CBlockTreeDB(1 << 20, true);
|
|
|
|
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
2012-09-03 13:26:57 +00:00
|
|
|
pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
|
2013-01-30 20:43:36 +00:00
|
|
|
InitBlockIndex();
|
2013-11-29 15:04:29 +00:00
|
|
|
#ifdef ENABLE_WALLET
|
2012-05-22 19:51:13 +00:00
|
|
|
bool fFirstRun;
|
|
|
|
pwalletMain = new CWallet("wallet.dat");
|
|
|
|
pwalletMain->LoadWallet(fFirstRun);
|
2012-01-05 02:40:52 +00:00
|
|
|
RegisterWallet(pwalletMain);
|
2013-11-29 15:04:29 +00:00
|
|
|
#endif
|
2012-12-01 22:04:14 +00:00
|
|
|
nScriptCheckThreads = 3;
|
|
|
|
for (int i=0; i < nScriptCheckThreads-1; i++)
|
2013-03-07 03:31:26 +00:00
|
|
|
threadGroup.create_thread(&ThreadScriptCheck);
|
2013-11-18 00:25:17 +00:00
|
|
|
RegisterNodeSignals(GetNodeSignals());
|
2012-01-05 02:40:52 +00:00
|
|
|
}
|
|
|
|
~TestingSetup()
|
|
|
|
{
|
2013-03-07 03:31:26 +00:00
|
|
|
threadGroup.interrupt_all();
|
|
|
|
threadGroup.join_all();
|
2013-11-18 00:25:17 +00:00
|
|
|
UnregisterNodeSignals(GetNodeSignals());
|
2013-11-29 15:04:29 +00:00
|
|
|
#ifdef ENABLE_WALLET
|
2012-01-05 02:40:52 +00:00
|
|
|
delete pwalletMain;
|
|
|
|
pwalletMain = NULL;
|
2013-11-29 15:04:29 +00:00
|
|
|
#endif
|
2012-09-03 13:26:57 +00:00
|
|
|
delete pcoinsTip;
|
|
|
|
delete pcoinsdbview;
|
|
|
|
delete pblocktree;
|
2013-11-29 15:04:29 +00:00
|
|
|
#ifdef ENABLE_WALLET
|
2012-05-22 19:51:13 +00:00
|
|
|
bitdb.Flush(true);
|
2013-11-29 15:04:29 +00:00
|
|
|
#endif
|
2012-11-28 20:58:41 +00:00
|
|
|
boost::filesystem::remove_all(pathTemp);
|
2011-10-03 20:14:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
BOOST_GLOBAL_FIXTURE(TestingSetup);
|
|
|
|
|
2011-07-31 18:00:38 +00:00
|
|
|
void Shutdown(void* parg)
|
|
|
|
{
|
2011-09-27 18:16:07 +00:00
|
|
|
exit(0);
|
2011-07-31 18:00:38 +00:00
|
|
|
}
|
2012-06-14 07:41:11 +00:00
|
|
|
|
|
|
|
void StartShutdown()
|
|
|
|
{
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|