Changeset View
Changeset View
Standalone View
Standalone View
src/test/test_bitcoin_main.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#define BOOST_TEST_MODULE Bitcoin Test Suite | #define BOOST_TEST_MODULE Bitcoin Test Suite | ||||
#define BOOST_TEST_NO_MAIN | |||||
#include <banman.h> | #include <banman.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <memory> | #include <memory> | ||||
std::unique_ptr<CConnman> g_connman; | std::unique_ptr<CConnman> g_connman; | ||||
std::unique_ptr<BanMan> g_banman; | std::unique_ptr<BanMan> g_banman; | ||||
[[noreturn]] void Shutdown(void *parg) { | [[noreturn]] void Shutdown(void *parg) { | ||||
std::exit(EXIT_SUCCESS); | std::exit(EXIT_SUCCESS); | ||||
} | } | ||||
[[noreturn]] void StartShutdown() { | [[noreturn]] void StartShutdown() { | ||||
std::exit(EXIT_SUCCESS); | std::exit(EXIT_SUCCESS); | ||||
} | } | ||||
bool ShutdownRequested() { | bool ShutdownRequested() { | ||||
return false; | return false; | ||||
} | } | ||||
int main(int argc, char *argv[]) { | namespace utf = boost::unit_test::framework; | ||||
// Additional CLI params supported by test_bitcoin: | |||||
/* | |||||
* Global fixture for passing custom arguments, and clearing them all after each | |||||
* test case. | |||||
*/ | |||||
struct CustomArgumentsFixture { | |||||
std::string error; | |||||
CustomArgumentsFixture() { | |||||
std::set<std::string> testArgs = { | std::set<std::string> testArgs = { | ||||
"-phononactivationtime", | "-phononactivationtime", | ||||
}; | }; | ||||
// Note: gArgs.ParseParameters() cannot be called here or it will fail to | for (const auto &arg : testArgs) { | ||||
// parse BOOST runtime params. | gArgs.AddArg(arg, "", false, OptionsCategory::HIDDEN); | ||||
for (int i = 1; i < argc; i++) { | |||||
std::string key(argv[i]); | |||||
std::string value; | |||||
if (ParseKeyValue(key, value)) { | |||||
if (testArgs.count(key) > 0) { | |||||
gArgs.ForceSetArg(key, value); | |||||
} | |||||
} | } | ||||
if (!gArgs.ParseParameters(utf::master_test_suite().argc, | |||||
utf::master_test_suite().argv, error)) { | |||||
throw utf::setup_error(error); | |||||
} | } | ||||
return boost::unit_test::unit_test_main(&init_unit_test, argc, argv); | |||||
} | } | ||||
~CustomArgumentsFixture(){}; | |||||
}; | |||||
BOOST_GLOBAL_FIXTURE(CustomArgumentsFixture); |