void testMutate () { String s; DynamicArray <T> v; s = "push_back (" + String::fromNumber <int> (numberToMutate) + ")"; beginTestCase (s); for (std::size_t i = 0; i < numberToMutate; ++i) v.push_back (T (String::fromNumber (i))); pass (); s = "read [] (" + String::fromNumber <int> (numberToMutate) + ")"; beginTestCase (s); for (std::size_t i = 0; i < numberToMutate; ++i) expect (v [i].msg == String::fromNumber (i)); s = "write [] (" + String::fromNumber <int> (numberToMutate) + ")"; beginTestCase (s); for (std::size_t i = 0; i < numberToMutate; ++i) v [i].msg = "+" + String::fromNumber (i); pass (); s = "verify [] (" + String::fromNumber <int> (numberToMutate) + ")"; beginTestCase (s); for (std::size_t i = 0; i < numberToMutate; ++i) expect (v [i].msg == String ("+") + String::fromNumber (i)); }
void testIterate () { typedef DynamicArray <T> V; V v; for (std::size_t i = 0; i < numberToMutate; ++i) v.push_back (T (String::fromNumber (i))); { int step = 1; beginTestCase ("iterator"); V::iterator iter; for (iter = v.begin (); iter + step < v.end (); iter += step) { step ++; V::difference_type d = iter - v.begin (); expect (iter->msg == String::fromNumber (d)); } } { int step = 1; beginTestCase ("const_iterator"); V::const_iterator iter; for (iter = v.begin (); iter + step < v.end (); iter += step) { step ++; V::difference_type d = iter - v.begin (); expect (iter->msg == String::fromNumber (d)); } } { int step = 1; beginTestCase ("reverse_iterator"); V::reverse_iterator iter; for (iter = v.rbegin (); iter + step < v.rend (); iter += step) { step ++; iter - v.rend (); } pass (); } { int step = 1; beginTestCase ("const_reverse_iterator"); V::const_reverse_iterator iter; for (iter = v.crbegin (); iter + step < v.crend (); iter += step) { step ++; iter - v.crend (); } pass (); } }
void runTest() { beginTestCase("Calls"); for(int i=0; i<100; i++) performCalls (); }
// Check logic for comparing a source's fetch results void testCompare () { beginTestCase ("compare"); { Array <Validator::Info> results = TestSource (1, 32).fetch (); expect (results.size () == 32); } { Array <Validator::Info> oldInfo = TestSource (1, 4).fetch (); expect (oldInfo.size () == 4); Array <Validator::Info> newInfo = TestSource (3, 6).fetch (); expect (newInfo.size () == 4); ValidatorsImp::Logic logic; Validator::List::Ptr oldList = logic.createListFromInfo (oldInfo); expect (oldList->size () == 4); Validator::List::Ptr newList = logic.createListFromInfo (newInfo); expect (newList->size () == 4); TestCompareCallback cb; ValidatorsImp::compareLists (*oldList, *newList, cb); expect (cb.numAdded == 2); expect (cb.numRemoved == 2); expect (cb.numUnchanged == 2); } }
void testThreads (int const threadCount) { String s; s << "threadCount = " << String (threadCount); beginTestCase (s); TestCallback cb (threadCount); Workers w (cb, "Test", 0); expect (w.getNumberOfThreads () == 0); w.setNumberOfThreads (threadCount); expect (w.getNumberOfThreads () == threadCount); for (int i = 0; i < threadCount; ++i) w.addTask (); // 10 seconds should be enough to finish on any system // bool signaled = cb.finished.wait (10 * 1000); expect (signaled, "timed out"); w.pauseAllThreadsAndWait (); int const count (cb.count.get ()); expectEquals (count, 0); }
void runTest () { beginTestCase ("List available unit tests"); TestList const& list (UnitTest::getAllTests ()); for (int i = 0; i < list.size (); ++i) { UnitTest const& test (*list [i]); String s; switch (test.getWhen ()) { default: case UnitTest::runNormal: s << " "; break; case UnitTest::runManual: s << "[manual] "; break; case UnitTest::runStartup: s << "[FORCED] "; break; }; s << test.getTestName (); logMessage (s); } pass (); }
void runTest () { beginTestCase ("Seed"); RippleAddress seed; expect (seed.setSeedGeneric ("masterpassphrase")); expect (seed.humanSeed () == "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", seed.humanSeed ()); beginTestCase ("RipplePublicKey"); RippleAddress deprecatedPublicKey (RippleAddress::createNodePublic (seed)); expect (deprecatedPublicKey.humanNodePublic () == "n94a1u4jAz288pZLtw6yFWVbi89YamiC6JBXPVUj5zmExe5fTVg9", deprecatedPublicKey.humanNodePublic ()); RipplePublicKey publicKey (deprecatedPublicKey); expect (publicKey.to_string() == deprecatedPublicKey.humanNodePublic(), publicKey.to_string()); beginTestCase ("RipplePrivateKey"); RippleAddress deprecatedPrivateKey (RippleAddress::createNodePrivate (seed)); expect (deprecatedPrivateKey.humanNodePrivate () == "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe", deprecatedPrivateKey.humanNodePrivate ()); RipplePrivateKey privateKey (deprecatedPrivateKey); expect (privateKey.to_string() == deprecatedPrivateKey.humanNodePrivate(), privateKey.to_string()); beginTestCase ("Generator"); RippleAddress generator (RippleAddress::createGeneratorPublic (seed)); expect (generator.humanGenerator () == "fhuJKrhSDzV2SkjLn9qbwm5AaRmrxDPfFsHDCP6yfDZWcxDFz4mt", generator.humanGenerator ()); beginTestCase ("RippleAccountID"); RippleAddress deprecatedAccountPublicKey ( RippleAddress::createAccountPublic (generator, 0)); expect (deprecatedAccountPublicKey.humanAccountID () == "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", deprecatedAccountPublicKey.humanAccountID ()); RippleAccountID accountID (deprecatedAccountPublicKey); expect (accountID.to_string() == deprecatedAccountPublicKey.humanAccountID(), accountID.to_string()); beginTestCase ("RippleAccountPublicKey"); expect (deprecatedAccountPublicKey.humanAccountPublic () == "aBQG8RQAzjs1eTKFEAQXr2gS4utcDiEC9wmi7pfUPTi27VCahwgw", deprecatedAccountPublicKey.humanAccountPublic ()); beginTestCase ("RippleAccountPrivateKey"); RippleAddress deprecatedAccountPrivateKey ( RippleAddress::createAccountPrivate (generator, seed, 0)); expect (deprecatedAccountPrivateKey.humanAccountPrivate () == "p9JfM6HHi64m6mvB6v5k7G2b1cXzGmYiCNJf6GHPKvFTWdeRVjh", deprecatedAccountPrivateKey.humanAccountPrivate ()); RippleAccountPrivateKey accountPrivateKey (deprecatedAccountPrivateKey); expect (accountPrivateKey.to_string() == deprecatedAccountPrivateKey.humanAccountPrivate(), privateKey.to_string()); }
void runTest () { beginTestCase ("report"); FatalErrorReporter reporter; // We don't really expect the program to run after this // but the unit test is here so you can manually test it. FatalError ("The unit test intentionally failed", __FILE__, __LINE__); }
void testAssign () { String s; s << "assign (" << String::fromNumber <int> (numberToAssign) << ")"; beginTestCase (s); DynamicArray <T> v; v.assign (numberToAssign); pass (); }
void testReserve () { String s; s << "reserve (" << String::fromNumber <int> (numberToReserve) << ")"; beginTestCase (s); DynamicArray <T> v; v.reserve (numberToReserve); v.assign (numberToReserve); pass (); }
void runTest () { beginTestCase ("diagnostics"); logMessage ("operatingSystemName = '" + SystemStats::getOperatingSystemName () + "'"); logMessage ("_DEBUG = " + String::fromNumber (envDebug ())); logMessage ("BEAST_DEBUG = " + String::fromNumber (beastDebug ())); logMessage ("BEAST_FORCE_DEBUG = " + String::fromNumber (beastForceDebug ())); logMessage ("sizeof(std::size_t) = " + String::fromNumber (sizeof(std::size_t))); bassertfalse; fail (); }
void testBackend (String type, int64 const seedValue, int numObjectsToTest = 2000) { DummyScheduler scheduler; beginTestCase (String ("Backend type=") + type); StringPairArray params; File const path (File::createTempFile ("node_db")); params.set ("type", type); params.set ("path", path.getFullPathName ()); // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); { // Open the backend ScopedPointer <Backend> backend (DatabaseImp::createBackend (params, scheduler)); // Write the batch storeBatch (*backend, batch); { // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } { // Reorder and read the copy again Batch copy; UnitTestUtilities::repeatableShuffle (batch.size (), batch, seedValue); fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } } { // Re-open the backend ScopedPointer <Backend> backend (DatabaseImp::createBackend (params, scheduler)); // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } }
void testImport (String destBackendType, String srcBackendType, int64 seedValue) { DummyScheduler scheduler; File const node_db (File::createTempFile ("node_db")); StringPairArray srcParams; srcParams.set ("type", srcBackendType); srcParams.set ("path", node_db.getFullPathName ()); // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); // Write to source db { ScopedPointer <Database> src (Database::New ("test", scheduler, srcParams)); storeBatch (*src, batch); } Batch copy; { // Re-open the db ScopedPointer <Database> src (Database::New ("test", scheduler, srcParams)); // Set up the destination database File const dest_db (File::createTempFile ("dest_db")); StringPairArray destParams; destParams.set ("type", destBackendType); destParams.set ("path", dest_db.getFullPathName ()); ScopedPointer <Database> dest (Database::New ("test", scheduler, destParams)); beginTestCase (String ("import into '") + destBackendType + "' from '" + srcBackendType + "'"); // Do the import dest->import (*src); // Get the results of the import fetchCopyOfBatch (*dest, ©, batch); } // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); }
void testPrevMissing () { beginTestCase ("prevMissing"); RangeSet const set = createPredefinedSet (); for (int i = 0; i < 100; ++i) { int const oneBelowRange = (10*(i/10))-1; int const expectedPrevMissing = ((i % 10) > 6) ? (i-1) : oneBelowRange; expect (set.prevMissing (i) == expectedPrevMissing); } }
// Make sure predictable object generation works! void testBatches (int64 const seedValue) { beginTestCase ("batch"); Batch batch1; createPredictableBatch (batch1, 0, numObjectsToTest, seedValue); Batch batch2; createPredictableBatch (batch2, 0, numObjectsToTest, seedValue); expect (areBatchesEqual (batch1, batch2), "Should be equal"); Batch batch3; createPredictableBatch (batch3, 1, numObjectsToTest, seedValue); expect (! areBatchesEqual (batch1, batch3), "Should not be equal"); }
void runTest() { beginTestCase ("Child Processes"); #if BEAST_WINDOWS || BEAST_MAC || BEAST_LINUX ChildProcess p; #if BEAST_WINDOWS expect (p.start ("tasklist")); #else expect (p.start ("ls /")); #endif //String output (p.readAllProcessOutput()); //expect (output.isNotEmpty()); #endif }
void runTest() { beginTestCase ("AbstractFifo"); int buffer [5000]; AbstractFifo fifo (numElementsInArray (buffer)); WriteThread writer (fifo, buffer); int n = 0; Random r; bool failed = false; for (int count = 100000; --count >= 0;) { int num = r.nextInt (6000) + 1; int start1, size1, start2, size2; fifo.prepareToRead (num, start1, size1, start2, size2); if (! (size1 >= 0 && size2 >= 0) && (size1 == 0 || (start1 >= 0 && start1 < fifo.getTotalSize())) && (size2 == 0 || (start2 >= 0 && start2 < fifo.getTotalSize()))) { expect (false, "prepareToRead returned negative values"); break; } for (int i = 0; i < size1; ++i) failed = (buffer [start1 + i] != n++) || failed; for (int i = 0; i < size2; ++i) failed = (buffer [start2 + i] != n++) || failed; if (failed) { break; } fifo.finishedRead (size1 + size2); } expect (! failed, "read values were incorrect"); }
void testMembership () { beginTestCase ("membership"); RangeSet r1, r2; r1.setRange (1, 10); r1.clearValue (5); r1.setRange (11, 20); r2.setRange (1, 4); r2.setRange (6, 10); r2.setRange (10, 20); expect (!r1.hasValue (5)); expect (r2.hasValue (9)); }
void runTest () { beginTestCase ("version"); BoostVersion version (BOOST_VERSION); logMessage (String ("BOOST_VERSION = " + version.toString ())); logMessage (String ("BOOST_LIB_VERSION = '") + BOOST_LIB_VERSION + "'"); if (BOOST_VERSION >= getMinimumVersion ()) { pass (); } else { fail (String ("Boost version is below ") + BoostVersion (minimumVersion).toString ()); } }
void runTest () { Config d; // get a default configuration object LoadFeeTrack l; beginTestCase ("fee scaling"); expect (l.scaleFeeBase (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 10000); expect (l.scaleFeeLoad (10000, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false) == 10000); expect (l.scaleFeeBase (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 1); expect (l.scaleFeeLoad (1, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE, false) == 1); // Check new default fee values give same fees as old defaults expect (l.scaleFeeBase (d.FEE_DEFAULT, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 10); expect (l.scaleFeeBase (d.FEE_ACCOUNT_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 200 * SYSTEM_CURRENCY_PARTS); expect (l.scaleFeeBase (d.FEE_OWNER_RESERVE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 50 * SYSTEM_CURRENCY_PARTS); expect (l.scaleFeeBase (d.FEE_NICKNAME_CREATE, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 1000); expect (l.scaleFeeBase (d.FEE_OFFER, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 10); expect (l.scaleFeeBase (d.FEE_CONTRACT_OPERATION, d.FEE_DEFAULT, d.TRANSACTION_FEE_BASE) == 1); }
void runTest () { beginTestCase ("Syntax"); logMessage ("steady_clock"); test (get_abstract_clock <std::chrono::steady_clock, std::chrono::seconds> ()); logMessage ("system_clock"); test (get_abstract_clock <std::chrono::system_clock, std::chrono::seconds> ()); logMessage ("high_resolution_clock"); test (get_abstract_clock <std::chrono::high_resolution_clock, std::chrono::seconds> ()); logMessage ("manual_clock"); test_manual (); pass (); }
void testFetch () { beginTestCase ("fetch"); Livecache <> c (m_clock, Journal()); add (1, 1, c); add (2, 1, c); add (3, 1, c); add (4, 1, c); add (4, 2, c); add (4, 3, c); add (5, 1, c); add (6, 1, c); add (6, 2, c); add (7, 1, c); // VFALCO TODO!!! pass(); }
void runTest () { beginTestCase ("create"); Factory <Object> factory; Callback1 callback1 (factory); Callback2 callback2 (factory); Object object (*this); factory.create_interfaces (object); // find existing interfaces expect (object.find_interface <Interface1> () != nullptr); expect (object.find_interface <Interface2> () != nullptr); // add duplicate interface try { object.add_interface (new Interface1); fail ("uncaught exeption"); } catch (std::invalid_argument const&) { pass (); } // request missing interface try { struct MissingInterface { }; object.get_interface <MissingInterface> (); fail ("uncaught exeption"); } catch (std::bad_cast const&) { pass (); } }
void UnitTest::failException () { Item item (false, "An exception was thrown"); if (m_case != nullptr) { m_case->failures++; } else { // This hack gives us a test case, to handle the condition where an // exception was thrown before beginTestCase() was called. // beginTestCase ("Exception outside test case"); } int const caseNumber = m_case->items.add (item); String s; s << "#" << String (caseNumber) << " threw an exception "; logMessage (s); m_runner->onFailure (); }
// Checks encoding/decoding blobs void testBlobs (int64 const seedValue) { beginTestCase ("encoding"); Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); EncodedBlob encoded; for (int i = 0; i < batch.size (); ++i) { encoded.prepare (batch [i]); DecodedBlob decoded (encoded.getKey (), encoded.getData (), encoded.getSize ()); expect (decoded.wasOk (), "Should be ok"); if (decoded.wasOk ()) { NodeObject::Ptr const object (decoded.createObject ()); expect (batch [i]->isCloneOf (object), "Should be clones"); } } }
void runTest() { beginTestCase ("call"); // Code from // http://llvm.org/svn/llvm-project/libcxx/trunk/test/utilities/intseq/intseq.general/integer_seq.pass.cpp // Make a couple of sequences using int3 = std::make_integer_sequence<int, 3>; // generates int: 0,1,2 using size7 = std::make_integer_sequence<size_t, 7>; // generates size_t: 0,1,2,3,4,5,6 using size4 = std::make_index_sequence<4>; // generates size_t: 0,1,2,3 using size2 = std::index_sequence_for<int, size_t>; // generates size_t: 0,1 using intmix = std::integer_sequence<int, 9, 8, 7, 2>; // generates int: 9,8,7,2 using sizemix = std::index_sequence<1, 1, 2, 3, 5>; // generates size_t: 1,1,2,3,5 // Make sure they're what we expect static_assert ( std::is_same <int3::value_type, int>::value, "int3 type wrong" ); static_assert ( int3::static_size == 3, "int3 size wrong" ); static_assert ( std::is_same <size7::value_type, size_t>::value, "size7 type wrong" ); static_assert ( size7::static_size == 7, "size7 size wrong" ); static_assert ( std::is_same <size4::value_type, size_t>::value, "size4 type wrong" ); static_assert ( size4::static_size == 4, "size4 size wrong" ); static_assert ( std::is_same <size2::value_type, size_t>::value, "size2 type wrong" ); static_assert ( size2::static_size == 2, "size2 size wrong" ); static_assert ( std::is_same <intmix::value_type, int>::value, "intmix type wrong" ); static_assert ( intmix::static_size == 4, "intmix size wrong" ); static_assert ( std::is_same <sizemix::value_type, size_t>::value, "sizemix type wrong" ); static_assert ( sizemix::static_size == 5, "sizemix size wrong" ); auto tup = std::make_tuple ( 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ); // Use them auto t3 = extract ( tup, int3() ); static_assert ( std::tuple_size<decltype(t3)>::value == int3::static_size, "t3 size wrong"); expect ( t3 == std::make_tuple ( 10, 11, 12 )); auto t7 = extract ( tup, size7 ()); static_assert ( std::tuple_size<decltype(t7)>::value == size7::static_size, "t7 size wrong"); expect ( t7 == std::make_tuple ( 10, 11, 12, 13, 14, 15, 16 )); auto t4 = extract ( tup, size4 ()); static_assert ( std::tuple_size<decltype(t4)>::value == size4::static_size, "t4 size wrong"); expect ( t4 == std::make_tuple ( 10, 11, 12, 13 )); auto t2 = extract ( tup, size2 ()); static_assert ( std::tuple_size<decltype(t2)>::value == size2::static_size, "t2 size wrong"); expect ( t2 == std::make_tuple ( 10, 11 )); auto tintmix = extract ( tup, intmix ()); static_assert ( std::tuple_size<decltype(tintmix)>::value == intmix::static_size, "tintmix size wrong"); expect ( tintmix == std::make_tuple ( 19, 18, 17, 12 )); auto tsizemix = extract ( tup, sizemix ()); static_assert ( std::tuple_size<decltype(tsizemix)>::value == sizemix::static_size, "tsizemix size wrong"); expect ( tsizemix == std::make_tuple ( 11, 11, 12, 13, 15 )); pass(); }
void testNodeStore (String type, bool const useEphemeralDatabase, bool const testPersistence, int64 const seedValue, int numObjectsToTest = 2000) { DummyScheduler scheduler; String s; s << String ("NodeStore backend '") + type + "'"; if (useEphemeralDatabase) s << " (with ephemeral database)"; beginTestCase (s); File const node_db (File::createTempFile ("node_db")); StringPairArray nodeParams; nodeParams.set ("type", type); nodeParams.set ("path", node_db.getFullPathName ()); File const temp_db (File::createTempFile ("temp_db")); StringPairArray tempParams; if (useEphemeralDatabase) { tempParams.set ("type", type); tempParams.set ("path", temp_db.getFullPathName ()); } // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); { // Open the database ScopedPointer <Database> db (Database::New ("test", scheduler, nodeParams, tempParams)); // Write the batch storeBatch (*db, batch); { // Read it back in Batch copy; fetchCopyOfBatch (*db, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } { // Reorder and read the copy again Batch copy; UnitTestUtilities::repeatableShuffle (batch.size (), batch, seedValue); fetchCopyOfBatch (*db, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } } if (testPersistence) { { // Re-open the database without the ephemeral DB ScopedPointer <Database> db (Database::New ("test", scheduler, nodeParams)); // Read it back in Batch copy; fetchCopyOfBatch (*db, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } if (useEphemeralDatabase) { // Verify the ephemeral db ScopedPointer <Database> db (Database::New ("test", scheduler, tempParams, StringPairArray ())); // Read it back in Batch copy; fetchCopyOfBatch (*db, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } } }
void runTest () { unsigned int seed; // VFALCO TODO Replace this with beast::Random RAND_pseudo_bytes (reinterpret_cast<unsigned char*> (&seed), sizeof (seed)); srand (seed); SHAMap source (smtFREE), destination (smtFREE); int items = 10000; for (int i = 0; i < items; ++i) source.addItem (*makeRandomAS (), false, false); beginTestCase ("add/remove"); unexpected (!confuseMap (source, 500), "ConfuseMap"); source.setImmutable (); std::vector<SHAMapNode> nodeIDs, gotNodeIDs; std::list< Blob > gotNodes; std::vector<uint256> hashes; std::vector<SHAMapNode>::iterator nodeIDIterator; std::list< Blob >::iterator rawNodeIterator; int passes = 0; int nodes = 0; destination.setSynching (); unexpected (!source.getNodeFat (SHAMapNode (), nodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0), "GetNodeFat"); unexpected (gotNodes.size () < 1, "NodeSize"); unexpected (!destination.addRootNode (*gotNodes.begin (), snfWIRE, NULL), "AddRootNode"); nodeIDs.clear (); gotNodes.clear (); #ifdef SMS_DEBUG int bytes = 0; #endif do { ++passes; hashes.clear (); // get the list of nodes we know we need destination.getMissingNodes (nodeIDs, hashes, 2048, NULL); if (nodeIDs.empty ()) break; // get as many nodes as possible based on this information for (nodeIDIterator = nodeIDs.begin (); nodeIDIterator != nodeIDs.end (); ++nodeIDIterator) { if (!source.getNodeFat (*nodeIDIterator, gotNodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0)) { WriteLog (lsFATAL, SHAMap) << "GetNodeFat fails"; fail ("GetNodeFat"); } else { pass (); } } assert (gotNodeIDs.size () == gotNodes.size ()); nodeIDs.clear (); hashes.clear (); if (gotNodeIDs.empty ()) { fail ("Got Node ID"); } else { pass (); } for (nodeIDIterator = gotNodeIDs.begin (), rawNodeIterator = gotNodes.begin (); nodeIDIterator != gotNodeIDs.end (); ++nodeIDIterator, ++rawNodeIterator) { ++nodes; #ifdef SMS_DEBUG bytes += rawNodeIterator->size (); #endif if (!destination.addKnownNode (*nodeIDIterator, *rawNodeIterator, NULL)) { WriteLog (lsTRACE, SHAMap) << "AddKnownNode fails"; fail ("AddKnownNode"); } else { pass (); } } gotNodeIDs.clear (); gotNodes.clear (); } while (true); destination.clearSynching (); #ifdef SMS_DEBUG WriteLog (lsINFO, SHAMap) << "SYNCHING COMPLETE " << items << " items, " << nodes << " nodes, " << bytes / 1024 << " KB"; #endif if (!source.deepCompare (destination)) { fail ("Deep Compare"); } else { pass (); } #ifdef SMS_DEBUG WriteLog (lsINFO, SHAMap) << "SHAMapSync test passed: " << items << " items, " << passes << " passes, " << nodes << " nodes"; #endif }
void runTest() { beginTestCase ("hooks"); #if ! BEAST_NO_STD_FUNCTION_CONSTRUCTIBLE static_assert (! std::is_constructible < std::function <void(void)>, int&&>::value, "Cannot construct std::function from int&&"); static_assert (! std::is_constructible < std::function <void(void)>, int>::value, "Cannot construct std::function from int"); static_assert (! std::is_constructible < asio::shared_handler <void(void)>, int>::value, "Cannot construct shared_handler from int"); #endif static_assert (std::is_constructible < asio::shared_handler <void(int)>, asio::shared_handler <void(int)>>::value, "Should construct <void(int)> from <void(int)>"); static_assert (! std::is_constructible < asio::shared_handler <void(int)>, asio::shared_handler <void(void)>>::value, "Can't construct <void(int)> from <void(void)>"); // Hooks called when using the raw handler { test_results r; test_handler h (r); async_op (h); expect (r.call); expect (r.alloc); expect (r.dealloc); expect (r.cont); test_invokable f; boost_asio_handler_invoke_helpers::invoke (std::ref (f), h); expect (r.invoke); expect (f.call); } // Use of std::function shows the hooks not getting called { test_results r; std::function <void(void)> fh ((test_handler) (r)); async_op (fh); expect (r.call); unexpected (r.alloc); unexpected (r.dealloc); unexpected (r.cont); test_invokable f; boost_asio_handler_invoke_helpers::invoke (std::ref (f), fh); unexpected (r.invoke); expect (f.call); } // Make sure shared_handler calls the hooks { test_results r; asio::shared_handler <void(void)> sh ((test_handler)(r)); async_op (sh); expect (r.call); expect (r.alloc); expect (r.dealloc); expect (r.cont); test_invokable f; boost_asio_handler_invoke_helpers::invoke (std::ref (f), sh); expect (r.invoke); expect (f.call); } // Make sure shared_handler via implicit conversion calls hooks { test_results r; test_handler h (r); virtual_async_op ((test_handler) (r)); expect (r.call); expect (r.alloc); expect (r.dealloc); expect (r.cont); } }
void runTest () { beginTestCase ("bassert"); bassert (false); }