mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-24 22:09:20 +02:00
tests: Use MakeUnique to construct objects owned by unique_ptrs
This commit is contained in:
@@ -163,7 +163,7 @@ private:
|
||||
BOOST_AUTO_TEST_CASE(lockedpool_tests_mock)
|
||||
{
|
||||
// Test over three virtual arenas, of which one will succeed being locked
|
||||
std::unique_ptr<LockedPageAllocator> x(new TestLockedPageAllocator(3, 1));
|
||||
std::unique_ptr<LockedPageAllocator> x = MakeUnique<TestLockedPageAllocator>(3, 1);
|
||||
LockedPool pool(std::move(x));
|
||||
BOOST_CHECK(pool.stats().total == 0);
|
||||
BOOST_CHECK(pool.stats().locked == 0);
|
||||
|
||||
@@ -148,7 +148,7 @@ typedef CCheckQueue<FrozenCleanupCheck> FrozenCleanup_Queue;
|
||||
*/
|
||||
static void Correct_Queue_range(std::vector<size_t> range)
|
||||
{
|
||||
auto small_queue = std::unique_ptr<Correct_Queue>(new Correct_Queue {QUEUE_BATCH_SIZE});
|
||||
auto small_queue = MakeUnique<Correct_Queue>(QUEUE_BATCH_SIZE);
|
||||
boost::thread_group tg;
|
||||
for (auto x = 0; x < nScriptCheckThreads; ++x) {
|
||||
tg.create_thread([&]{small_queue->Thread();});
|
||||
@@ -213,7 +213,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<Failing_Queue>(new Failing_Queue {QUEUE_BATCH_SIZE});
|
||||
auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE);
|
||||
|
||||
boost::thread_group tg;
|
||||
for (auto x = 0; x < nScriptCheckThreads; ++x) {
|
||||
@@ -246,7 +246,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<Failing_Queue>(new Failing_Queue {QUEUE_BATCH_SIZE});
|
||||
auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE);
|
||||
boost::thread_group tg;
|
||||
for (auto x = 0; x < nScriptCheckThreads; ++x) {
|
||||
tg.create_thread([&]{fail_queue->Thread();});
|
||||
@@ -274,7 +274,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<Unique_Queue>(new Unique_Queue {QUEUE_BATCH_SIZE});
|
||||
auto queue = MakeUnique<Unique_Queue>(QUEUE_BATCH_SIZE);
|
||||
boost::thread_group tg;
|
||||
for (auto x = 0; x < nScriptCheckThreads; ++x) {
|
||||
tg.create_thread([&]{queue->Thread();});
|
||||
@@ -310,7 +310,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<Memory_Queue>(new Memory_Queue {QUEUE_BATCH_SIZE});
|
||||
auto queue = MakeUnique<Memory_Queue>(QUEUE_BATCH_SIZE);
|
||||
boost::thread_group tg;
|
||||
for (auto x = 0; x < nScriptCheckThreads; ++x) {
|
||||
tg.create_thread([&]{queue->Thread();});
|
||||
@@ -341,7 +341,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
|
||||
// have been destructed
|
||||
BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
|
||||
{
|
||||
auto queue = std::unique_ptr<FrozenCleanup_Queue>(new FrozenCleanup_Queue {QUEUE_BATCH_SIZE});
|
||||
auto queue = MakeUnique<FrozenCleanup_Queue>(QUEUE_BATCH_SIZE);
|
||||
boost::thread_group tg;
|
||||
bool fails = false;
|
||||
for (auto x = 0; x < nScriptCheckThreads; ++x) {
|
||||
@@ -384,7 +384,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<Standard_Queue>(new Standard_Queue{QUEUE_BATCH_SIZE});
|
||||
auto queue = MakeUnique<Standard_Queue>(QUEUE_BATCH_SIZE);
|
||||
{
|
||||
boost::thread_group tg;
|
||||
std::atomic<int> nThreads {0};
|
||||
|
||||
@@ -179,12 +179,12 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
|
||||
bool fInboundIn = false;
|
||||
|
||||
// Test that fFeeler is false by default.
|
||||
std::unique_ptr<CNode> pnode1(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, CAddress(), pszDest, fInboundIn));
|
||||
std::unique_ptr<CNode> pnode1 = MakeUnique<CNode>(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<CNode> pnode2(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, fInboundIn));
|
||||
std::unique_ptr<CNode> pnode2 = MakeUnique<CNode>(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, fInboundIn);
|
||||
BOOST_CHECK(pnode2->fInbound == true);
|
||||
BOOST_CHECK(pnode2->fFeeler == false);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||
nScriptCheckThreads = 3;
|
||||
for (int i=0; i < nScriptCheckThreads-1; i++)
|
||||
threadGroup.create_thread(&ThreadScriptCheck);
|
||||
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests.
|
||||
g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
|
||||
connman = g_connman.get();
|
||||
peerLogic.reset(new PeerLogicValidation(connman, scheduler, /*enable_bip61=*/true));
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ static int test_one_input(std::vector<uint8_t> buffer) {
|
||||
|
||||
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
|
||||
void initialize() {
|
||||
globalVerifyHandle = std::unique_ptr<ECCVerifyHandle>(new ECCVerifyHandle());
|
||||
globalVerifyHandle = MakeUnique<ECCVerifyHandle>();
|
||||
}
|
||||
|
||||
// This function is used by libFuzzer
|
||||
|
||||
Reference in New Issue
Block a user