diff --git a/doc/developer-notes.md b/doc/developer-notes.md index f1fcbd8378ed..0e69126e038b 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -460,6 +460,11 @@ General C++ - *Rationale*: This avoids memory and resource leaks, and ensures exception safety +- Use `MakeUnique()` to construct objects owned by `unique_ptr`s + + - *Rationale*: `MakeUnique` is concise and ensures exception safety in complex expressions. + `MakeUnique` is a temporary project local implementation of `std::make_unique` (C++14). + C++ data structures -------------------- diff --git a/src/bench/bench_dash.cpp b/src/bench/bench_dash.cpp index 749085d3fd9f..001e7612ee44 100644 --- a/src/bench/bench_dash.cpp +++ b/src/bench/bench_dash.cpp @@ -16,6 +16,8 @@ #include +const std::function G_TRANSLATION_FUN = nullptr; + static const int64_t DEFAULT_BENCH_EVALUATIONS = 5; static const char* DEFAULT_BENCH_FILTER = ".*"; static const char* DEFAULT_BENCH_SCALING = "1.0"; @@ -95,7 +97,7 @@ int main(int argc, char** argv) return EXIT_FAILURE; } - std::unique_ptr printer(new benchmark::ConsolePrinter()); + std::unique_ptr printer = MakeUnique(); std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER); if ("plot" == printer_arg) { printer.reset(new benchmark::PlotlyPrinter( diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index 33cf3a35f3d9..a50917ca458a 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -26,7 +26,8 @@ static void DeserializeBlockTest(benchmark::State& state) while (state.KeepRunning()) { CBlock block; stream >> block; - assert(stream.Rewind(sizeof(raw_bench::block813851))); + bool rewound = stream.Rewind(sizeof(raw_bench::block813851)); + assert(rewound); } } @@ -43,10 +44,12 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state) while (state.KeepRunning()) { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here stream >> block; - assert(stream.Rewind(sizeof(raw_bench::block813851))); + bool rewound = stream.Rewind(sizeof(raw_bench::block813851)); + assert(rewound); CValidationState validationState; - assert(CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime())); + bool checked = CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime()); + assert(checked); } } diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index d68795bd0371..8730fadea33a 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -66,7 +66,7 @@ static void add_coin(const CAmount& nValue, int nInput, std::vector CMutableTransaction tx; tx.vout.resize(nInput + 1); tx.vout[nInput].nValue = nValue; - std::unique_ptr wtx(new CWalletTx(&testWallet, MakeTransactionRef(std::move(tx)))); + std::unique_ptr wtx = MakeUnique(&testWallet, MakeTransactionRef(std::move(tx))); set.emplace_back(COutput(wtx.get(), nInput, 0, true, true, true).GetInputCoin(), 0, true, 0, 0); wtxn.emplace_back(std::move(wtx)); } diff --git a/src/dash-cli.cpp b/src/dash-cli.cpp index cf97031aa0b4..8d6bc22f7323 100644 --- a/src/dash-cli.cpp +++ b/src/dash-cli.cpp @@ -26,6 +26,8 @@ #include +const std::function G_TRANSLATION_FUN = nullptr; + static const char DEFAULT_RPCCONNECT[] = "127.0.0.1"; static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900; static const bool DEFAULT_NAMED=false; diff --git a/src/dash-tx.cpp b/src/dash-tx.cpp index 5fe7e7d6f552..d2ff5807e385 100644 --- a/src/dash-tx.cpp +++ b/src/dash-tx.cpp @@ -32,6 +32,8 @@ static bool fCreateBlank; static std::map registers; static const int CONTINUE_EXECUTION=-1; +const std::function G_TRANSLATION_FUN = nullptr; + static void SetupBitcoinTxArgs() { gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS); diff --git a/src/dashd.cpp b/src/dashd.cpp index 3dd8012093c8..b8bf72d27d90 100644 --- a/src/dashd.cpp +++ b/src/dashd.cpp @@ -25,6 +25,8 @@ #include +const std::function G_TRANSLATION_FUN = nullptr; + /* Introduction text for doxygen: */ /*! \mainpage Developer documentation diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 4ad50ce8bbef..bc65581b2738 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -247,8 +247,9 @@ bool StartHTTPRPC() // ifdef can be removed once we switch to better endpoint support and API versioning RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC); #endif - assert(EventBase()); - httpRPCTimerInterface = MakeUnique(EventBase()); + struct event_base* eventBase = EventBase(); + assert(eventBase); + httpRPCTimerInterface = MakeUnique(eventBase); RPCSetTimerInterface(httpRPCTimerInterface.get()); return true; } diff --git a/src/init.cpp b/src/init.cpp index fb68e041c82b..54d35b8aafc2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -453,12 +453,12 @@ static void registerSignalHandler(int signal, void(*handler)(int)) static void OnRPCStarted() { - uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange); + uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange); } static void OnRPCStopped() { - uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange); + uiInterface.NotifyBlockTip_disconnect(&RPCNotifyBlockChange); RPCNotifyBlockChange(false, nullptr); g_best_block_cv.notify_all(); LogPrint(BCLog::RPC, "RPC stopped.\n"); @@ -1855,7 +1855,7 @@ bool AppInitMain() */ if (gArgs.GetBoolArg("-server", false)) { - uiInterface.InitMessage.connect(SetRPCWarmupStatus); + uiInterface.InitMessage_connect(SetRPCWarmupStatus); if (!AppInitServers()) return InitError(_("Unable to start HTTP server. See debug log for details.")); } @@ -2432,13 +2432,13 @@ bool AppInitMain() // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly. // No locking, as this happens before any background thread is started. if (chainActive.Tip() == nullptr) { - uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); + uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait); } else { fHaveGenesis = true; } if (gArgs.IsArgSet("-blocknotify")) - uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); + uiInterface.NotifyBlockTip_connect(BlockNotifyCallback); std::vector vImportFiles; for (const std::string& strFile : gArgs.GetArgs("-loadblock")) { @@ -2456,7 +2456,7 @@ bool AppInitMain() while (!fHaveGenesis && !ShutdownRequested()) { g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500)); } - uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); + uiInterface.NotifyBlockTip_disconnect(BlockNotifyGenesisWait); } // As importing blocks can take several minutes, it's possible the user diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 7279a9a7b02f..2a4e1f17b237 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -365,44 +365,44 @@ class NodeImpl : public Node std::unique_ptr handleInitMessage(InitMessageFn fn) override { - return MakeHandler(::uiInterface.InitMessage.connect(fn)); + return MakeHandler(::uiInterface.InitMessage_connect(fn)); } std::unique_ptr handleMessageBox(MessageBoxFn fn) override { - return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn)); + return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn)); } std::unique_ptr handleQuestion(QuestionFn fn) override { - return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn)); + return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn)); } std::unique_ptr handleShowProgress(ShowProgressFn fn) override { - return MakeHandler(::uiInterface.ShowProgress.connect(fn)); + return MakeHandler(::uiInterface.ShowProgress_connect(fn)); } std::unique_ptr handleLoadWallet(LoadWalletFn fn) override { CHECK_WALLET( - return MakeHandler(::uiInterface.LoadWallet.connect([fn](std::shared_ptr wallet) { fn(MakeWallet(wallet)); }))); + return MakeHandler(::uiInterface.LoadWallet_connect([fn](std::shared_ptr wallet) { fn(MakeWallet(wallet)); }))); } std::unique_ptr handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyNumConnectionsChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn)); } std::unique_ptr handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyNetworkActiveChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn)); } std::unique_ptr handleNotifyAlertChanged(NotifyAlertChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyAlertChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn)); } std::unique_ptr handleBannedListChanged(BannedListChangedFn fn) override { - return MakeHandler(::uiInterface.BannedListChanged.connect(fn)); + return MakeHandler(::uiInterface.BannedListChanged_connect(fn)); } std::unique_ptr handleNotifyBlockTip(NotifyBlockTipFn fn) override { - return MakeHandler(::uiInterface.NotifyBlockTip.connect([fn](bool initial_download, const CBlockIndex* block) { + return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](bool initial_download, const CBlockIndex* block) { fn(initial_download, block->nHeight, block->GetBlockTime(), block->GetBlockHash().ToString(), GuessVerificationProgress(Params().TxData(), block)); })); @@ -410,7 +410,7 @@ class NodeImpl : public Node std::unique_ptr handleNotifyHeaderTip(NotifyHeaderTipFn fn) override { return MakeHandler( - ::uiInterface.NotifyHeaderTip.connect([fn](bool initial_download, const CBlockIndex* block) { + ::uiInterface.NotifyHeaderTip_connect([fn](bool initial_download, const CBlockIndex* block) { fn(initial_download, block->nHeight, block->GetBlockTime(), block->GetBlockHash().ToString(), GuessVerificationProgress(Params().TxData(), block)); })); @@ -418,14 +418,14 @@ class NodeImpl : public Node std::unique_ptr handleNotifyMasternodeListChanged(NotifyMasternodeListChangedFn fn) override { return MakeHandler( - ::uiInterface.NotifyMasternodeListChanged.connect([fn](const CDeterministicMNList& newList) { + ::uiInterface.NotifyMasternodeListChanged_connect([fn](const CDeterministicMNList& newList) { fn(newList); })); } std::unique_ptr handleNotifyAdditionalDataSyncProgressChanged(NotifyAdditionalDataSyncProgressChangedFn fn) override { return MakeHandler( - ::uiInterface.NotifyAdditionalDataSyncProgressChanged.connect([fn](double nSyncProgress) { + ::uiInterface.NotifyAdditionalDataSyncProgressChanged_connect([fn](double nSyncProgress) { fn(nSyncProgress); })); } diff --git a/src/noui.cpp b/src/noui.cpp index 7591eb991cb9..1fad06c085f8 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -13,6 +13,8 @@ #include #include +#include + static bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style) { bool fSecure = style & CClientUIInterface::SECURE; @@ -53,7 +55,7 @@ static void noui_InitMessage(const std::string& message) void noui_connect() { // Connect dashd signal handlers - uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox); - uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion); - uiInterface.InitMessage.connect(noui_InitMessage); + uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox); + uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion); + uiInterface.InitMessage_connect(noui_InitMessage); } diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 1f87618c5f3a..3df992d45544 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -61,6 +61,8 @@ #include #include +#include + const std::string BitcoinGUI::DEFAULT_UIPLATFORM = #if defined(Q_OS_MAC) "macosx" diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index 41012a710cad..c9bd09e3880d 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -76,13 +76,10 @@ static void InitMessage(const std::string &message) LogPrintf("init message: %s\n", message); } -/* - Translate string to current locale using Qt. - */ -static std::string Translate(const char* psz) -{ +/** Translate string to current locale using Qt. */ +const std::function G_TRANSLATION_FUN = [](const char* psz) { return QCoreApplication::translate("dash-core", psz).toStdString(); -} +}; static QString GetLangTerritory() { @@ -628,7 +625,6 @@ int main(int argc, char *argv[]) // Now that QSettings are accessible, initialize translations QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator); - translationInterface.Translate.connect(Translate); if (gArgs.IsArgSet("-printcrashinfo")) { auto crashInfo = GetCrashInfoStrFromSerializedStr(gArgs.GetArg("-printcrashinfo", "")); diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index 67126ee2997b..20fffe7693f4 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -18,8 +18,8 @@ #include #include #include -#include #include +#include #include #include @@ -27,6 +27,8 @@ #include #include +#include + SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) : QWidget(0, f), curAlignment(0), m_node(node) { diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 2a443e70a1a7..505e1e0a6014 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -13,10 +13,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -24,6 +24,8 @@ #include #include +#include + // Amount column is right-aligned it contains numbers static int column_alignments[] = { Qt::AlignLeft|Qt::AlignVCenter, /* status */ diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 4231250bd0eb..77d9f6f10e46 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -361,7 +361,8 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script) SignatureData sigs; if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) { // VerifyScript check is just defensive, and should never fail. - assert(VerifyScript(sigs.scriptSig, script, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER)); + bool verified = VerifyScript(sigs.scriptSig, script, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER); + assert(verified); return true; } return false; diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp index 01489cd88bb1..1e795843c9c7 100644 --- a/src/test/allocator_tests.cpp +++ b/src/test/allocator_tests.cpp @@ -163,7 +163,7 @@ class TestLockedPageAllocator: public LockedPageAllocator BOOST_AUTO_TEST_CASE(lockedpool_tests_mock) { // Test over three virtual arenas, of which one will succeed being locked - std::unique_ptr x(new TestLockedPageAllocator(3, 1)); + std::unique_ptr x = MakeUnique(3, 1); LockedPool pool(std::move(x)); BOOST_CHECK(pool.stats().total == 0); BOOST_CHECK(pool.stats().locked == 0); diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index e709df4ce00c..40dd04303cec 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -13,8 +13,10 @@ BOOST_FIXTURE_TEST_SUITE(amount_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(MoneyRangeTest) { BOOST_CHECK_EQUAL(MoneyRange(CAmount(-1)), false); - BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY + CAmount(1)), false); + BOOST_CHECK_EQUAL(MoneyRange(CAmount(0)), true); BOOST_CHECK_EQUAL(MoneyRange(CAmount(1)), true); + BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY), true); + BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY + CAmount(1)), false); } BOOST_AUTO_TEST_CASE(GetFeeTest) @@ -23,43 +25,43 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) feeRate = CFeeRate(0); // Must always return 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e5), 0); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e5), CAmount(0)); feeRate = CFeeRate(1000); // Must always just return the arg - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(1), 1); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), 121); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), 999); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), 1e3); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), 9e3); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1), CAmount(1)); + BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(121)); + BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(999)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(1e3)); + BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(9e3)); feeRate = CFeeRate(-1000); // Must always just return -1 * arg - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(1), -1); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), -121); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), -999); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), -1e3); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), -9e3); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1), CAmount(-1)); + BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(-121)); + BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(-999)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(-1e3)); + BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(-9e3)); feeRate = CFeeRate(123); // Truncates the result, if not integer - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(8), 1); // Special case: returns 1 instead of 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(9), 1); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), 14); - BOOST_CHECK_EQUAL(feeRate.GetFee(122), 15); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), 122); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), 123); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), 1107); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(8), CAmount(1)); // Special case: returns 1 instead of 0 + BOOST_CHECK_EQUAL(feeRate.GetFee(9), CAmount(1)); + BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(14)); + BOOST_CHECK_EQUAL(feeRate.GetFee(122), CAmount(15)); + BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(122)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(123)); + BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(1107)); feeRate = CFeeRate(-123); // Truncates the result, if not integer - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(8), -1); // Special case: returns -1 instead of 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(9), -1); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(8), CAmount(-1)); // Special case: returns -1 instead of 0 + BOOST_CHECK_EQUAL(feeRate.GetFee(9), CAmount(-1)); // check alternate constructor feeRate = CFeeRate(1000); @@ -67,6 +69,9 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) BOOST_CHECK_EQUAL(feeRate.GetFee(100), altFeeRate.GetFee(100)); // Check full constructor + BOOST_CHECK(CFeeRate(CAmount(-1), 0) == CFeeRate(0)); + BOOST_CHECK(CFeeRate(CAmount(0), 0) == CFeeRate(0)); + BOOST_CHECK(CFeeRate(CAmount(1), 0) == CFeeRate(0)); // default value BOOST_CHECK(CFeeRate(CAmount(-1), 1000) == CFeeRate(-1)); BOOST_CHECK(CFeeRate(CAmount(0), 1000) == CFeeRate(0)); diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 830fa95783a2..cc08112dda11 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -147,7 +147,7 @@ typedef CCheckQueue FrozenCleanup_Queue; */ static void Correct_Queue_range(std::vector range) { - auto small_queue = std::unique_ptr(new Correct_Queue {QUEUE_BATCH_SIZE}); + auto small_queue = MakeUnique(QUEUE_BATCH_SIZE); small_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); // Make vChecks here to save on malloc (this test can be slow...) std::vector vChecks; @@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random) /** Test that failing checks are caught */ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) { - auto fail_queue = std::unique_ptr(new Failing_Queue {QUEUE_BATCH_SIZE}); + auto fail_queue = MakeUnique(QUEUE_BATCH_SIZE); fail_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); for (size_t i = 0; i < 1001; ++i) { @@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) // future blocks, ie, the bad state is cleared. BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) { - auto fail_queue = std::unique_ptr(new Failing_Queue {QUEUE_BATCH_SIZE}); + auto fail_queue = MakeUnique(QUEUE_BATCH_SIZE); fail_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); for (auto times = 0; times < 10; ++times) { @@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) // more than once as well BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) { - auto queue = std::unique_ptr(new Unique_Queue {QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); size_t COUNT = 100000; @@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) // time could leave the data hanging across a sequence of blocks. BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) { - auto queue = std::unique_ptr(new Memory_Queue {QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); for (size_t i = 0; i < 1000; ++i) { size_t total = i; @@ -322,7 +322,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) // have been destructed BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) { - auto queue = std::unique_ptr(new FrozenCleanup_Queue {QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); bool fails = false; queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); std::thread t0([&]() { @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) /** Test that CCheckQueueControl is threadsafe */ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) { - auto queue = std::unique_ptr(new Standard_Queue{QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); { boost::thread_group tg; std::atomic nThreads {0}; diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index b4904d07fc5c..957f2883c86c 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -183,12 +183,12 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test) bool fInboundIn = false; // Test that fFeeler is false by default. - std::unique_ptr pnode1(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, CAddress(), pszDest, fInboundIn)); + std::unique_ptr pnode1 = MakeUnique(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, CAddress(), pszDest, fInboundIn); BOOST_CHECK(pnode1->fInbound == false); BOOST_CHECK(pnode1->fFeeler == false); fInboundIn = true; - std::unique_ptr pnode2(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, fInboundIn)); + std::unique_ptr pnode2 = MakeUnique(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, fInboundIn); BOOST_CHECK(pnode2->fInbound == true); BOOST_CHECK(pnode2->fFeeler == false); } diff --git a/src/test/test_dash.cpp b/src/test/test_dash.cpp index 786dc00ca894..ba48ade7d67d 100644 --- a/src/test/test_dash.cpp +++ b/src/test/test_dash.cpp @@ -9,15 +9,16 @@ #include #include #include -#include #include #include #include -#include -#include -#include #include +#include #include