From 9458aa2fb0a21ae91a38c1de8887a022e27e57eb Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 28 Jul 2013 02:38:46 -0700 Subject: [PATCH] Update unit tests for beast, add JUnit XML output option --- TODO.txt | 11 +- modules/ripple_app/ledger/Ledger.cpp | 2 +- modules/ripple_app/main/ripple_Main.cpp | 68 +++- .../misc/ripple_ProofOfWorkFactory.cpp | 2 +- .../misc/ripple_SerializedTransaction.cpp | 12 +- modules/ripple_app/node/ripple_NodeStore.cpp | 12 +- modules/ripple_app/shamap/ripple_SHAMap.cpp | 32 +- .../ripple_app/shamap/ripple_SHAMapSync.cpp | 37 +- .../containers/ripple_RangeSet.cpp | 4 +- .../utility/ripple_StringUtilities.cpp | 50 +-- .../functional/ripple_LoadFeeTrack.cpp | 2 + .../validator/ripple_Validators.cpp | 2 +- modules/ripple_data/crypto/ripple_CKey.cpp | 18 +- .../protocol/ripple_RippleAddress.cpp | 2 +- .../ripple_data/protocol/ripple_STAmount.cpp | 365 +++++++++--------- .../protocol/ripple_SerializedObject.cpp | 37 +- .../protocol/ripple_Serializer.cpp | 2 +- 17 files changed, 369 insertions(+), 289 deletions(-) diff --git a/TODO.txt b/TODO.txt index 0a6875b49f..adfe160b8b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -5,18 +5,23 @@ RIPPLE TODO Vinnie's List: Changes day to day, descending priority (Items marked '*' can be handled by others.) +- Remove unnecessary beast .mm files * Make everyone check GitHub Issues every day - Finish unit tests and code for Validators - Do something about the throw() reporting weaknesses: * Make sure all Sconstruct and .pro builds have debug symbols in release * Replace all throw with beast::Throw() (Only in ripple sources, not in Subtrees/, protobuf, or websocket) + - Improved Beast exception object, provides __FILE__ and __LINE__ - Add file and line capabilities to beast::Throw() - Allow beast::Throw to be hooked for logging - Add stack trace capability to beast::Throw() diagnostics via the hook (use the existing beast::SystemStats::getStackBacktrace()) - Implement getStackBacktrace for BEAST_BSD targets -- Use the result of the beast UnitTests as the return code for main() + - Add UnhandledExceptionCatcher to beast + - Return EXIT_FAILURE on unhandled exception +- Add "FailingTests" and "PassingTests" to beast, run manually, to + help test CI scripts. * Document the command line options for the beast unit test framework - Tidy up all the loose files at the root of the repository - What the heck is up with site_scons/site_tools/protoc.py? @@ -27,6 +32,10 @@ Vinnie's List: Changes day to day, descending priority -------------------------------------------------------------------------------- +- Get rid of the WriteLog() stuff in the ripple tests and make it report the + message directly to the UnitTest object. Then update the JUnit XML output + routines to also write the auxiliary messages. + * Take away the "I" prefix from abstract interface classes, in both the class name and the file name. It is messing up sorting in the IDE. Use "Imp" or suffix for implementations. diff --git a/modules/ripple_app/ledger/Ledger.cpp b/modules/ripple_app/ledger/Ledger.cpp index 21281b6547..72825cf452 100644 --- a/modules/ripple_app/ledger/Ledger.cpp +++ b/modules/ripple_app/ledger/Ledger.cpp @@ -1926,7 +1926,7 @@ public: void runTest () { - beginTest ("uint256"); + beginTestCase ("uint256"); uint256 uBig ("D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000"); diff --git a/modules/ripple_app/main/ripple_Main.cpp b/modules/ripple_app/main/ripple_Main.cpp index 6602a0fafc..ce996ade4d 100644 --- a/modules/ripple_app/main/ripple_Main.cpp +++ b/modules/ripple_app/main/ripple_Main.cpp @@ -125,12 +125,13 @@ void printHelp (const po::options_description& desc) class RippleUnitTests : public UnitTests { public: - RippleUnitTests () + explicit RippleUnitTests (bool shouldLog) + : m_shouldLog (shouldLog) { // VFALCO NOTE It sucks that we have to do this but some // code demands the Application object exists. // - // To find out who, just change the 1 to 0 + // TODO To find out who, just change the #if 1 to #if 0 #if 1 setupConfigForUnitTests (&getConfig ()); @@ -138,12 +139,12 @@ public: #endif setAssertOnFailure (false); - setPassesAreLogged (false); } void logMessage (String const& message) { - Log::out () << message.toStdString (); + if (m_shouldLog) + Log::out () << message.toStdString (); } private: @@ -153,8 +154,48 @@ private: config->ephemeralNodeDatabase = StringPairArray (); config->importNodeDatabase = StringPairArray (); } + +private: + bool const m_shouldLog; }; +static int runUnitTests (String const& whichTests, String const& format) +{ + bool const shouldLog = format != "junit"; + + if (format != "junit" && format != "text" && format != "") + { + String s; + s << "Warning, unknown unittest-format='" << format << "'"; + Log::out () << s.toStdString (); + } + + RippleUnitTests tr (shouldLog); + + if (whichTests == "") + { + tr.runAllTests (); + } + else + { + tr.runTestsByName (whichTests); + } + + if (format == "junit") + { + UnitTestUtilities::JUnitXMLFormatter f (tr); + + String const s = f.createDocumentString (); + + Log::out () << s.toStdString (); + } + else + { + } + + return tr.anyTestsFailed () ? EXIT_FAILURE : EXIT_SUCCESS; +} + //------------------------------------------------------------------------------ int rippleMain (int argc, char** argv) @@ -219,6 +260,7 @@ int rippleMain (int argc, char** argv) ("standalone,a", "Run with no peers.") ("testnet,t", "Run in test net mode.") ("unittest,u", po::value ()->implicit_value (""), "Perform unit tests.") + ("unittest-format", po::value ()->implicit_value ("text"), "Format unit test output. Choices are 'text', 'junit'") ("parameters", po::value< vector > (), "Specify comma separated parameters.") ("quiet,q", "Reduce diagnotics.") ("verbose,v", "Verbose logging.") @@ -318,22 +360,12 @@ int rippleMain (int argc, char** argv) // if (vm.count ("unittest")) { - String const arg = vm ["unittest"].as (); + String format; - RippleUnitTests tr; + if (vm.count ("unittest-format")) + format = vm ["unittest-format"].as (); - if (arg == "") - { - tr.runAllTests (); - } - else - { - tr.runTest (arg); - } - - iResult = tr.anyTestsFailed () ? EXIT_FAILURE : EXIT_SUCCESS; - - return iResult; + return runUnitTests (vm ["unittest"].as (), format); } if (!iResult) diff --git a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp index 2896d23da4..3c6c6e3ede 100644 --- a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp +++ b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp @@ -250,7 +250,7 @@ public: String s; s << "solve difficulty " << String (pow.getDifficulty ()); - beginTest ("solve"); + beginTestCase ("solve"); uint256 solution = pow.solve (16777216); diff --git a/modules/ripple_app/misc/ripple_SerializedTransaction.cpp b/modules/ripple_app/misc/ripple_SerializedTransaction.cpp index 74d2cfab23..a842106a00 100644 --- a/modules/ripple_app/misc/ripple_SerializedTransaction.cpp +++ b/modules/ripple_app/misc/ripple_SerializedTransaction.cpp @@ -299,7 +299,7 @@ public: void runTest () { - beginTest ("tx"); + beginTestCase ("tx"); RippleAddress seed; seed.setSeedRandom (); @@ -313,7 +313,7 @@ public: j.setFieldVL (sfMessageKey, publicAcct.getAccountPublic ()); j.sign (privateAcct); - if (!j.checkSign ()) fail ("Transaction fails signature test"); + unexpected (!j.checkSign (), "Transaction fails signature test"); Serializer rawTxn; j.add (rawTxn); @@ -326,6 +326,10 @@ public: Log (lsFATAL) << copy.getJson (0); fail ("Transaction fails serialize/deserialize test"); } + else + { + pass (); + } UPTR_T new_obj = STObject::parseJson (j.getJson (0), sfGeneric); @@ -337,6 +341,10 @@ public: Log (lsINFO) << "BUILT " << new_obj->getJson (0); fail ("Built a different transaction"); } + else + { + pass (); + } } }; diff --git a/modules/ripple_app/node/ripple_NodeStore.cpp b/modules/ripple_app/node/ripple_NodeStore.cpp index 397524b2ac..1b123387ef 100644 --- a/modules/ripple_app/node/ripple_NodeStore.cpp +++ b/modules/ripple_app/node/ripple_NodeStore.cpp @@ -729,7 +729,7 @@ public: // Make sure predictable object generation works! void testBatches (int64 const seedValue) { - beginTest ("batch"); + beginTestCase ("batch"); Batch batch1; createPredictableBatch (batch1, 0, numObjectsToTest, seedValue); @@ -748,7 +748,7 @@ public: // Checks encoding/decoding blobs void testBlobs (int64 const seedValue) { - beginTest ("encoding"); + beginTestCase ("encoding"); Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); @@ -798,7 +798,7 @@ public: void testBackend (String type, int64 const seedValue) { - beginTest (String ("NodeStore::Backend type=") + type); + beginTestCase (String ("NodeStore::Backend type=") + type); StringPairArray params; File const path (File::createTempFile ("node_db")); @@ -914,7 +914,7 @@ public: { String s; s << "Testing backend '" << type << "' performance"; - beginTest (s); + beginTestCase (s); StringPairArray params; File const path (File::createTempFile ("node_db")); @@ -1021,7 +1021,7 @@ public: ScopedPointer dest (NodeStore::New (destParams)); - beginTest (String ("import into '") + destBackendType + "' from '" + srcBackendType + "'"); + beginTestCase (String ("import into '") + destBackendType + "' from '" + srcBackendType + "'"); // Do the import dest->import (*src); @@ -1049,7 +1049,7 @@ public: if (useEphemeralDatabase) s << " (with ephemeral database)"; - beginTest (s); + beginTestCase (s); File const node_db (File::createTempFile ("node_db")); StringPairArray nodeParams; diff --git a/modules/ripple_app/shamap/ripple_SHAMap.cpp b/modules/ripple_app/shamap/ripple_SHAMap.cpp index 25da604a29..aac9b46216 100644 --- a/modules/ripple_app/shamap/ripple_SHAMap.cpp +++ b/modules/ripple_app/shamap/ripple_SHAMap.cpp @@ -1074,7 +1074,7 @@ public: void runTest () { - beginTest ("add/traverse"); + beginTestCase ("add/traverse"); // h3 and h4 differ only in the leaf, same terminal node (level 19) uint256 h1, h2, h3, h4, h5; @@ -1087,23 +1087,23 @@ public: SHAMap sMap (smtFREE); SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5)); - if (!sMap.addItem (i2, true, false)) fail ("no add"); + unexpected (!sMap.addItem (i2, true, false), "no add"); - if (!sMap.addItem (i1, true, false)) fail ("no add"); + unexpected (!sMap.addItem (i1, true, false), "no add"); SHAMapItem::pointer i; i = sMap.peekFirstItem (); - if (!i || (*i != i1)) fail ("bad traverse"); + unexpected (!i || (*i != i1), "bad traverse"); i = sMap.peekNextItem (i->getTag ()); - if (!i || (*i != i2)) fail ("bad traverse"); + unexpected (!i || (*i != i2), "bad traverse"); i = sMap.peekNextItem (i->getTag ()); - if (i) fail ("bad traverse"); + unexpected (i, "bad traverse"); sMap.addItem (i4, true, false); sMap.delItem (i2.getTag ()); @@ -1111,36 +1111,36 @@ public: i = sMap.peekFirstItem (); - if (!i || (*i != i1)) fail ("bad traverse"); + unexpected (!i || (*i != i1), "bad traverse"); i = sMap.peekNextItem (i->getTag ()); - if (!i || (*i != i3)) fail ("bad traverse"); + unexpected (!i || (*i != i3), "bad traverse"); i = sMap.peekNextItem (i->getTag ()); - if (!i || (*i != i4)) fail ("bad traverse"); + unexpected (!i || (*i != i4), "bad traverse"); i = sMap.peekNextItem (i->getTag ()); - if (i) fail ("bad traverse"); + unexpected (i, "bad traverse"); - beginTest ("snapshot"); + beginTestCase ("snapshot"); uint256 mapHash = sMap.getHash (); SHAMap::pointer map2 = sMap.snapShot (false); - if (sMap.getHash () != mapHash) fail ("bad snapshot"); + unexpected (sMap.getHash () != mapHash, "bad snapshot"); - if (map2->getHash () != mapHash) fail ("bad snapshot"); + unexpected (map2->getHash () != mapHash, "bad snapshot"); - if (!sMap.delItem (sMap.peekFirstItem ()->getTag ())) fail ("bad mod"); + unexpected (!sMap.delItem (sMap.peekFirstItem ()->getTag ()), "bad mod"); - if (sMap.getHash () == mapHash) fail ("bad snapshot"); + unexpected (sMap.getHash () == mapHash, "bad snapshot"); - if (map2->getHash () != mapHash) fail ("bad snapshot"); + unexpected (map2->getHash () != mapHash, "bad snapshot"); } }; diff --git a/modules/ripple_app/shamap/ripple_SHAMapSync.cpp b/modules/ripple_app/shamap/ripple_SHAMapSync.cpp index e3376d241b..f30420b59e 100644 --- a/modules/ripple_app/shamap/ripple_SHAMapSync.cpp +++ b/modules/ripple_app/shamap/ripple_SHAMapSync.cpp @@ -653,7 +653,6 @@ public: void runTest () { - beginTest ("sync"); unsigned int seed; // VFALCO TODO Replace this with beast::Random @@ -668,9 +667,9 @@ public: - beginTest ("add/remove"); + beginTestCase ("add/remove"); - if (!confuseMap (source, 500)) fail ("ConfuseMap"); + unexpected (!confuseMap (source, 500), "ConfuseMap"); source.setImmutable (); @@ -686,20 +685,12 @@ public: destination.setSynching (); - if (!source.getNodeFat (SHAMapNode (), nodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0)) - { - fail ("GetNodeFat"); - } + unexpected (!source.getNodeFat (SHAMapNode (), nodeIDs, gotNodes, (rand () % 2) == 0, (rand () % 2) == 0), + "GetNodeFat"); - if (gotNodes.size () < 1) - { - fail ("NodeSize"); - } + unexpected (gotNodes.size () < 1, "NodeSize"); - if (!destination.addRootNode (*gotNodes.begin (), snfWIRE, NULL)) - { - fail ("AddRootNode"); - } + unexpected (!destination.addRootNode (*gotNodes.begin (), snfWIRE, NULL), "AddRootNode"); nodeIDs.clear (); gotNodes.clear (); @@ -726,6 +717,10 @@ public: WriteLog (lsFATAL, SHAMap) << "GetNodeFat fails"; fail ("GetNodeFat"); } + else + { + pass (); + } } assert (gotNodeIDs.size () == gotNodes.size ()); @@ -736,6 +731,10 @@ public: { fail ("Got Node ID"); } + else + { + pass (); + } for (nodeIDIterator = gotNodeIDs.begin (), rawNodeIterator = gotNodes.begin (); nodeIDIterator != gotNodeIDs.end (); ++nodeIDIterator, ++rawNodeIterator) @@ -750,6 +749,10 @@ public: WriteLog (lsTRACE, SHAMap) << "AddKnownNode fails"; fail ("AddKnownNode"); } + else + { + pass (); + } } gotNodeIDs.clear (); @@ -768,6 +771,10 @@ public: { fail ("Deep Compare"); } + else + { + pass (); + } #ifdef SMS_DEBUG WriteLog (lsINFO, SHAMap) << "SHAMapSync test passed: " << items << " items, " << diff --git a/modules/ripple_basics/containers/ripple_RangeSet.cpp b/modules/ripple_basics/containers/ripple_RangeSet.cpp index edd9314f3d..5d3476043b 100644 --- a/modules/ripple_basics/containers/ripple_RangeSet.cpp +++ b/modules/ripple_basics/containers/ripple_RangeSet.cpp @@ -269,7 +269,7 @@ public: void testMembership () { - beginTest ("membership"); + beginTestCase ("membership"); RangeSet r1, r2; @@ -288,7 +288,7 @@ public: void testPrevMissing () { - beginTest ("prevMissing"); + beginTestCase ("prevMissing"); RangeSet const set = createPredefinedSet (); diff --git a/modules/ripple_basics/utility/ripple_StringUtilities.cpp b/modules/ripple_basics/utility/ripple_StringUtilities.cpp index 79b1ef5597..4c720eb164 100644 --- a/modules/ripple_basics/utility/ripple_StringUtilities.cpp +++ b/modules/ripple_basics/utility/ripple_StringUtilities.cpp @@ -321,48 +321,48 @@ public: void runTest () { - beginTest ("parseUrl"); + beginTestCase ("parseUrl"); std::string strScheme; std::string strDomain; int iPort; std::string strPath; - if (!parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath)) - fail ("parseUrl: lower://domain failed"); + unexpected (!parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath), + "parseUrl: lower://domain failed"); - if (strScheme != "lower") - fail ("parseUrl: lower://domain : scheme failed"); + unexpected (strScheme != "lower", + "parseUrl: lower://domain : scheme failed"); - if (strDomain != "domain") - fail ("parseUrl: lower://domain : domain failed"); + unexpected (strDomain != "domain", + "parseUrl: lower://domain : domain failed"); - if (iPort != -1) - fail ("parseUrl: lower://domain : port failed"); + unexpected (iPort != -1, + "parseUrl: lower://domain : port failed"); - if (strPath != "") - fail ("parseUrl: lower://domain : path failed"); + unexpected (strPath != "", + "parseUrl: lower://domain : path failed"); - if (!parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath)) - fail ("parseUrl: UPPER://domain:234/ failed"); + unexpected (!parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath), + "parseUrl: UPPER://domain:234/ failed"); - if (strScheme != "upper") - fail ("parseUrl: UPPER://domain:234/ : scheme failed"); + unexpected (strScheme != "upper", + "parseUrl: UPPER://domain:234/ : scheme failed"); - if (iPort != 234) - fail (boost::str (boost::format ("parseUrl: UPPER://domain:234/ : port failed: %d") % iPort)); + unexpected (iPort != 234, + boost::str (boost::format ("parseUrl: UPPER://domain:234/ : port failed: %d") % iPort)); - if (strPath != "/") - fail ("parseUrl: UPPER://domain:234/ : path failed"); + unexpected (strPath != "/", + "parseUrl: UPPER://domain:234/ : path failed"); - if (!parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath)) - fail ("parseUrl: Mixed://domain/path failed"); + unexpected (!parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath), + "parseUrl: Mixed://domain/path failed"); - if (strScheme != "mixed") - fail ("parseUrl: Mixed://domain/path tolower failed"); + unexpected (strScheme != "mixed", + "parseUrl: Mixed://domain/path tolower failed"); - if (strPath != "/path") - fail ("parseUrl: Mixed://domain/path path failed"); + unexpected (strPath != "/path", + "parseUrl: Mixed://domain/path path failed"); } }; diff --git a/modules/ripple_core/functional/ripple_LoadFeeTrack.cpp b/modules/ripple_core/functional/ripple_LoadFeeTrack.cpp index 4c176a9dc2..efbb20a4bf 100644 --- a/modules/ripple_core/functional/ripple_LoadFeeTrack.cpp +++ b/modules/ripple_core/functional/ripple_LoadFeeTrack.cpp @@ -23,6 +23,8 @@ public: 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); diff --git a/modules/ripple_core/validator/ripple_Validators.cpp b/modules/ripple_core/validator/ripple_Validators.cpp index d2c2b43b53..35545f4a21 100644 --- a/modules/ripple_core/validator/ripple_Validators.cpp +++ b/modules/ripple_core/validator/ripple_Validators.cpp @@ -411,7 +411,7 @@ public: // Check logic for comparing a source's fetch results void processTest () { - beginTest ("process"); + beginTestCase ("process"); { Array results = TestSource (1, 32).fetch (); diff --git a/modules/ripple_data/crypto/ripple_CKey.cpp b/modules/ripple_data/crypto/ripple_CKey.cpp index 0870c66767..12729f1135 100644 --- a/modules/ripple_data/crypto/ripple_CKey.cpp +++ b/modules/ripple_data/crypto/ripple_CKey.cpp @@ -21,7 +21,7 @@ public: void runTest () { - beginTest ("determinism"); + beginTestCase ("determinism"); uint128 seed1, seed2; seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26"); @@ -32,20 +32,20 @@ public: root1.GetPrivateKeyU (priv1); root2.GetPrivateKeyU (priv2); - if (priv1.GetHex () != "7CFBA64F771E93E817E15039215430B53F7401C34931D111EAB3510B22DBB0D8") - fail ("Incorrect private key for generator"); + unexpected (priv1.GetHex () != "7CFBA64F771E93E817E15039215430B53F7401C34931D111EAB3510B22DBB0D8", + "Incorrect private key for generator"); - if (priv2.GetHex () != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B") - fail ("Incorrect private key for generator"); + unexpected (priv2.GetHex () != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B", + "Incorrect private key for generator"); RippleAddress nSeed; nSeed.setSeed (seed1); - if (nSeed.humanSeed () != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn") - fail ("Incorrect human seed"); + unexpected (nSeed.humanSeed () != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn", + "Incorrect human seed"); - if (nSeed.humanSeed1751 () != "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH") - fail ("Incorrect 1751 seed"); + unexpected (nSeed.humanSeed1751 () != "MAD BODY ACE MINT OKAY HUB WHAT DATA SACK FLAT DANA MATH", + "Incorrect 1751 seed"); } }; diff --git a/modules/ripple_data/protocol/ripple_RippleAddress.cpp b/modules/ripple_data/protocol/ripple_RippleAddress.cpp index a006162f14..12595eb3de 100644 --- a/modules/ripple_data/protocol/ripple_RippleAddress.cpp +++ b/modules/ripple_data/protocol/ripple_RippleAddress.cpp @@ -877,7 +877,7 @@ public: void runTest () { - beginTest ("public/private"); + beginTestCase ("public/private"); // Construct a seed. RippleAddress naSeed; diff --git a/modules/ripple_data/protocol/ripple_STAmount.cpp b/modules/ripple_data/protocol/ripple_STAmount.cpp index 159d395ba2..464cc4f61e 100644 --- a/modules/ripple_data/protocol/ripple_STAmount.cpp +++ b/modules/ripple_data/protocol/ripple_STAmount.cpp @@ -1351,6 +1351,10 @@ public: return false; } + else + { + pass (); + } return true; } @@ -1372,6 +1376,10 @@ public: fail ("Multiplication result is not exact"); } + else + { + pass (); + } aa = a; prod1 = STAmount::multiply (aa, bb, CURRENCY_ONE, ACCOUNT_ONE); @@ -1382,14 +1390,17 @@ public: << " not " << prod2.getFullText (); fail ("Multiplication result is not exact"); } - + else + { + pass (); + } } //-------------------------------------------------------------------------- void testSetValue () { - beginTest ("set value"); + beginTestCase ("set value"); STAmount saTmp; @@ -1414,296 +1425,296 @@ public: void testNativeCurrency () { - beginTest ("native currency"); + beginTestCase ("native currency"); STAmount zero, one (1), hundred (100); - if (serializeAndDeserialize (zero) != zero) fail ("STAmount fail"); + unexpected (serializeAndDeserialize (zero) != zero, "STAmount fail"); - if (serializeAndDeserialize (one) != one) fail ("STAmount fail"); + unexpected (serializeAndDeserialize (one) != one, "STAmount fail"); - if (serializeAndDeserialize (hundred) != hundred) fail ("STAmount fail"); + unexpected (serializeAndDeserialize (hundred) != hundred, "STAmount fail"); - if (!zero.isNative ()) fail ("STAmount fail"); + unexpected (!zero.isNative (), "STAmount fail"); - if (!hundred.isNative ()) fail ("STAmount fail"); + unexpected (!hundred.isNative (), "STAmount fail"); - if (!zero.isZero ()) fail ("STAmount fail"); + unexpected (!zero.isZero (), "STAmount fail"); - if (one.isZero ()) fail ("STAmount fail"); + unexpected (one.isZero (), "STAmount fail"); - if (hundred.isZero ()) fail ("STAmount fail"); + unexpected (hundred.isZero (), "STAmount fail"); - if ((zero < zero)) fail ("STAmount fail"); + unexpected ((zero < zero), "STAmount fail"); - if (! (zero < one)) fail ("STAmount fail"); + unexpected (! (zero < one), "STAmount fail"); - if (! (zero < hundred)) fail ("STAmount fail"); + unexpected (! (zero < hundred), "STAmount fail"); - if ((one < zero)) fail ("STAmount fail"); + unexpected ((one < zero), "STAmount fail"); - if ((one < one)) fail ("STAmount fail"); + unexpected ((one < one), "STAmount fail"); - if (! (one < hundred)) fail ("STAmount fail"); + unexpected (! (one < hundred), "STAmount fail"); - if ((hundred < zero)) fail ("STAmount fail"); + unexpected ((hundred < zero), "STAmount fail"); - if ((hundred < one)) fail ("STAmount fail"); + unexpected ((hundred < one), "STAmount fail"); - if ((hundred < hundred)) fail ("STAmount fail"); + unexpected ((hundred < hundred), "STAmount fail"); - if ((zero > zero)) fail ("STAmount fail"); + unexpected ((zero > zero), "STAmount fail"); - if ((zero > one)) fail ("STAmount fail"); + unexpected ((zero > one), "STAmount fail"); - if ((zero > hundred)) fail ("STAmount fail"); + unexpected ((zero > hundred), "STAmount fail"); - if (! (one > zero)) fail ("STAmount fail"); + unexpected (! (one > zero), "STAmount fail"); - if ((one > one)) fail ("STAmount fail"); + unexpected ((one > one), "STAmount fail"); - if ((one > hundred)) fail ("STAmount fail"); + unexpected ((one > hundred), "STAmount fail"); - if (! (hundred > zero)) fail ("STAmount fail"); + unexpected (! (hundred > zero), "STAmount fail"); - if (! (hundred > one)) fail ("STAmount fail"); + unexpected (! (hundred > one), "STAmount fail"); - if ((hundred > hundred)) fail ("STAmount fail"); + unexpected ((hundred > hundred), "STAmount fail"); - if (! (zero <= zero)) fail ("STAmount fail"); + unexpected (! (zero <= zero), "STAmount fail"); - if (! (zero <= one)) fail ("STAmount fail"); + unexpected (! (zero <= one), "STAmount fail"); - if (! (zero <= hundred)) fail ("STAmount fail"); + unexpected (! (zero <= hundred), "STAmount fail"); - if ((one <= zero)) fail ("STAmount fail"); + unexpected ((one <= zero), "STAmount fail"); - if (! (one <= one)) fail ("STAmount fail"); + unexpected (! (one <= one), "STAmount fail"); - if (! (one <= hundred)) fail ("STAmount fail"); + unexpected (! (one <= hundred), "STAmount fail"); - if ((hundred <= zero)) fail ("STAmount fail"); + unexpected ((hundred <= zero), "STAmount fail"); - if ((hundred <= one)) fail ("STAmount fail"); + unexpected ((hundred <= one), "STAmount fail"); - if (! (hundred <= hundred)) fail ("STAmount fail"); + unexpected (! (hundred <= hundred), "STAmount fail"); - if (! (zero >= zero)) fail ("STAmount fail"); + unexpected (! (zero >= zero), "STAmount fail"); - if ((zero >= one)) fail ("STAmount fail"); + unexpected ((zero >= one), "STAmount fail"); - if ((zero >= hundred)) fail ("STAmount fail"); + unexpected ((zero >= hundred), "STAmount fail"); - if (! (one >= zero)) fail ("STAmount fail"); + unexpected (! (one >= zero), "STAmount fail"); - if (! (one >= one)) fail ("STAmount fail"); + unexpected (! (one >= one), "STAmount fail"); - if ((one >= hundred)) fail ("STAmount fail"); + unexpected ((one >= hundred), "STAmount fail"); - if (! (hundred >= zero)) fail ("STAmount fail"); + unexpected (! (hundred >= zero), "STAmount fail"); - if (! (hundred >= one)) fail ("STAmount fail"); + unexpected (! (hundred >= one), "STAmount fail"); - if (! (hundred >= hundred)) fail ("STAmount fail"); + unexpected (! (hundred >= hundred), "STAmount fail"); - if (! (zero == zero)) fail ("STAmount fail"); + unexpected (! (zero == zero), "STAmount fail"); - if ((zero == one)) fail ("STAmount fail"); + unexpected ((zero == one), "STAmount fail"); - if ((zero == hundred)) fail ("STAmount fail"); + unexpected ((zero == hundred), "STAmount fail"); - if ((one == zero)) fail ("STAmount fail"); + unexpected ((one == zero), "STAmount fail"); - if (! (one == one)) fail ("STAmount fail"); + unexpected (! (one == one), "STAmount fail"); - if ((one == hundred)) fail ("STAmount fail"); + unexpected ((one == hundred), "STAmount fail"); - if ((hundred == zero)) fail ("STAmount fail"); + unexpected ((hundred == zero), "STAmount fail"); - if ((hundred == one)) fail ("STAmount fail"); + unexpected ((hundred == one), "STAmount fail"); - if (! (hundred == hundred)) fail ("STAmount fail"); + unexpected (! (hundred == hundred), "STAmount fail"); - if ((zero != zero)) fail ("STAmount fail"); + unexpected ((zero != zero), "STAmount fail"); - if (! (zero != one)) fail ("STAmount fail"); + unexpected (! (zero != one), "STAmount fail"); - if (! (zero != hundred)) fail ("STAmount fail"); + unexpected (! (zero != hundred), "STAmount fail"); - if (! (one != zero)) fail ("STAmount fail"); + unexpected (! (one != zero), "STAmount fail"); - if ((one != one)) fail ("STAmount fail"); + unexpected ((one != one), "STAmount fail"); - if (! (one != hundred)) fail ("STAmount fail"); + unexpected (! (one != hundred), "STAmount fail"); - if (! (hundred != zero)) fail ("STAmount fail"); + unexpected (! (hundred != zero), "STAmount fail"); - if (! (hundred != one)) fail ("STAmount fail"); + unexpected (! (hundred != one), "STAmount fail"); - if ((hundred != hundred)) fail ("STAmount fail"); + unexpected ((hundred != hundred), "STAmount fail"); - if (STAmount ().getText () != "0") fail ("STAmount fail"); + unexpected (STAmount ().getText () != "0", "STAmount fail"); - if (STAmount (31).getText () != "31") fail ("STAmount fail"); + unexpected (STAmount (31).getText () != "31", "STAmount fail"); - if (STAmount (310).getText () != "310") fail ("STAmount fail"); + unexpected (STAmount (310).getText () != "310", "STAmount fail"); } //-------------------------------------------------------------------------- void testCustomCurrency () { - beginTest ("custom currency"); + beginTestCase ("custom currency"); STAmount zero (CURRENCY_ONE, ACCOUNT_ONE), one (CURRENCY_ONE, ACCOUNT_ONE, 1), hundred (CURRENCY_ONE, ACCOUNT_ONE, 100); serializeAndDeserialize (one).getRaw (); - if (serializeAndDeserialize (zero) != zero) fail ("STAmount fail"); + unexpected (serializeAndDeserialize (zero) != zero, "STAmount fail"); - if (serializeAndDeserialize (one) != one) fail ("STAmount fail"); + unexpected (serializeAndDeserialize (one) != one, "STAmount fail"); - if (serializeAndDeserialize (hundred) != hundred) fail ("STAmount fail"); + unexpected (serializeAndDeserialize (hundred) != hundred, "STAmount fail"); - if (zero.isNative ()) fail ("STAmount fail"); + unexpected (zero.isNative (), "STAmount fail"); - if (hundred.isNative ()) fail ("STAmount fail"); + unexpected (hundred.isNative (), "STAmount fail"); - if (!zero.isZero ()) fail ("STAmount fail"); + unexpected (!zero.isZero (), "STAmount fail"); - if (one.isZero ()) fail ("STAmount fail"); + unexpected (one.isZero (), "STAmount fail"); - if (hundred.isZero ()) fail ("STAmount fail"); + unexpected (hundred.isZero (), "STAmount fail"); - if ((zero < zero)) fail ("STAmount fail"); + unexpected ((zero < zero), "STAmount fail"); - if (! (zero < one)) fail ("STAmount fail"); + unexpected (! (zero < one), "STAmount fail"); - if (! (zero < hundred)) fail ("STAmount fail"); + unexpected (! (zero < hundred), "STAmount fail"); - if ((one < zero)) fail ("STAmount fail"); + unexpected ((one < zero), "STAmount fail"); - if ((one < one)) fail ("STAmount fail"); + unexpected ((one < one), "STAmount fail"); - if (! (one < hundred)) fail ("STAmount fail"); + unexpected (! (one < hundred), "STAmount fail"); - if ((hundred < zero)) fail ("STAmount fail"); + unexpected ((hundred < zero), "STAmount fail"); - if ((hundred < one)) fail ("STAmount fail"); + unexpected ((hundred < one), "STAmount fail"); - if ((hundred < hundred)) fail ("STAmount fail"); + unexpected ((hundred < hundred), "STAmount fail"); - if ((zero > zero)) fail ("STAmount fail"); + unexpected ((zero > zero), "STAmount fail"); - if ((zero > one)) fail ("STAmount fail"); + unexpected ((zero > one), "STAmount fail"); - if ((zero > hundred)) fail ("STAmount fail"); + unexpected ((zero > hundred), "STAmount fail"); - if (! (one > zero)) fail ("STAmount fail"); + unexpected (! (one > zero), "STAmount fail"); - if ((one > one)) fail ("STAmount fail"); + unexpected ((one > one), "STAmount fail"); - if ((one > hundred)) fail ("STAmount fail"); + unexpected ((one > hundred), "STAmount fail"); - if (! (hundred > zero)) fail ("STAmount fail"); + unexpected (! (hundred > zero), "STAmount fail"); - if (! (hundred > one)) fail ("STAmount fail"); + unexpected (! (hundred > one), "STAmount fail"); - if ((hundred > hundred)) fail ("STAmount fail"); + unexpected ((hundred > hundred), "STAmount fail"); - if (! (zero <= zero)) fail ("STAmount fail"); + unexpected (! (zero <= zero), "STAmount fail"); - if (! (zero <= one)) fail ("STAmount fail"); + unexpected (! (zero <= one), "STAmount fail"); - if (! (zero <= hundred)) fail ("STAmount fail"); + unexpected (! (zero <= hundred), "STAmount fail"); - if ((one <= zero)) fail ("STAmount fail"); + unexpected ((one <= zero), "STAmount fail"); - if (! (one <= one)) fail ("STAmount fail"); + unexpected (! (one <= one), "STAmount fail"); - if (! (one <= hundred)) fail ("STAmount fail"); + unexpected (! (one <= hundred), "STAmount fail"); - if ((hundred <= zero)) fail ("STAmount fail"); + unexpected ((hundred <= zero), "STAmount fail"); - if ((hundred <= one)) fail ("STAmount fail"); + unexpected ((hundred <= one), "STAmount fail"); - if (! (hundred <= hundred)) fail ("STAmount fail"); + unexpected (! (hundred <= hundred), "STAmount fail"); - if (! (zero >= zero)) fail ("STAmount fail"); + unexpected (! (zero >= zero), "STAmount fail"); - if ((zero >= one)) fail ("STAmount fail"); + unexpected ((zero >= one), "STAmount fail"); - if ((zero >= hundred)) fail ("STAmount fail"); + unexpected ((zero >= hundred), "STAmount fail"); - if (! (one >= zero)) fail ("STAmount fail"); + unexpected (! (one >= zero), "STAmount fail"); - if (! (one >= one)) fail ("STAmount fail"); + unexpected (! (one >= one), "STAmount fail"); - if ((one >= hundred)) fail ("STAmount fail"); + unexpected ((one >= hundred), "STAmount fail"); - if (! (hundred >= zero)) fail ("STAmount fail"); + unexpected (! (hundred >= zero), "STAmount fail"); - if (! (hundred >= one)) fail ("STAmount fail"); + unexpected (! (hundred >= one), "STAmount fail"); - if (! (hundred >= hundred)) fail ("STAmount fail"); + unexpected (! (hundred >= hundred), "STAmount fail"); - if (! (zero == zero)) fail ("STAmount fail"); + unexpected (! (zero == zero), "STAmount fail"); - if ((zero == one)) fail ("STAmount fail"); + unexpected ((zero == one), "STAmount fail"); - if ((zero == hundred)) fail ("STAmount fail"); + unexpected ((zero == hundred), "STAmount fail"); - if ((one == zero)) fail ("STAmount fail"); + unexpected ((one == zero), "STAmount fail"); - if (! (one == one)) fail ("STAmount fail"); + unexpected (! (one == one), "STAmount fail"); - if ((one == hundred)) fail ("STAmount fail"); + unexpected ((one == hundred), "STAmount fail"); - if ((hundred == zero)) fail ("STAmount fail"); + unexpected ((hundred == zero), "STAmount fail"); - if ((hundred == one)) fail ("STAmount fail"); + unexpected ((hundred == one), "STAmount fail"); - if (! (hundred == hundred)) fail ("STAmount fail"); + unexpected (! (hundred == hundred), "STAmount fail"); - if ((zero != zero)) fail ("STAmount fail"); + unexpected ((zero != zero), "STAmount fail"); - if (! (zero != one)) fail ("STAmount fail"); + unexpected (! (zero != one), "STAmount fail"); - if (! (zero != hundred)) fail ("STAmount fail"); + unexpected (! (zero != hundred), "STAmount fail"); - if (! (one != zero)) fail ("STAmount fail"); + unexpected (! (one != zero), "STAmount fail"); - if ((one != one)) fail ("STAmount fail"); + unexpected ((one != one), "STAmount fail"); - if (! (one != hundred)) fail ("STAmount fail"); + unexpected (! (one != hundred), "STAmount fail"); - if (! (hundred != zero)) fail ("STAmount fail"); + unexpected (! (hundred != zero), "STAmount fail"); - if (! (hundred != one)) fail ("STAmount fail"); + unexpected (! (hundred != one), "STAmount fail"); - if ((hundred != hundred)) fail ("STAmount fail"); + unexpected ((hundred != hundred), "STAmount fail"); - if (STAmount (CURRENCY_ONE, ACCOUNT_ONE).getText () != "0") fail ("STAmount fail"); + unexpected (STAmount (CURRENCY_ONE, ACCOUNT_ONE).getText () != "0", "STAmount fail"); - if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31).getText () != "31") fail ("STAmount fail"); + unexpected (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31).getText () != "31", "STAmount fail"); - if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, 1).getText () != "310") fail ("STAmount fail"); + unexpected (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, 1).getText () != "310", "STAmount fail"); - if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -1).getText () != "3.1") fail ("STAmount fail"); + unexpected (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -1).getText () != "3.1", "STAmount fail"); - if (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -2).getText () != "0.31") fail ("STAmount fail"); + unexpected (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 31, -2).getText () != "0.31", "STAmount fail"); - if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60") - fail ("STAmount multiply fail 1"); + unexpected (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60", + "STAmount multiply fail 1"); - if (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60") - fail ("STAmount multiply fail 2"); + unexpected (STAmount::multiply (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60", + "STAmount multiply fail 2"); - if (STAmount::multiply (STAmount (20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60") - fail ("STAmount multiply fail 3"); + unexpected (STAmount::multiply (STAmount (20), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "60", + "STAmount multiply fail 3"); - if (STAmount::multiply (STAmount (20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60") - fail ("STAmount multiply fail 4"); + unexpected (STAmount::multiply (STAmount (20), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "60", + "STAmount multiply fail 4"); if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "20") { @@ -1712,30 +1723,34 @@ public: STAmount (3), CURRENCY_ONE, ACCOUNT_ONE).getText (); fail ("STAmount divide fail"); } + else + { + pass (); + } - if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "20") - fail ("STAmount divide fail"); + unexpected (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (3), uint160 (), ACCOUNT_XRP).getText () != "20", + "STAmount divide fail"); - if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "20") - fail ("STAmount divide fail"); + unexpected (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), CURRENCY_ONE, ACCOUNT_ONE).getText () != "20", + "STAmount divide fail"); - if (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), uint160 (), ACCOUNT_XRP).getText () != "20") - fail ("STAmount divide fail"); + unexpected (STAmount::divide (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 3), uint160 (), ACCOUNT_XRP).getText () != "20", + "STAmount divide fail"); STAmount a1 (CURRENCY_ONE, ACCOUNT_ONE, 60), a2 (CURRENCY_ONE, ACCOUNT_ONE, 10, -1); - if (STAmount::divide (a2, a1, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a1, a2))) - fail ("STAmount setRate(getRate) fail"); + unexpected (STAmount::divide (a2, a1, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a1, a2)), + "STAmount setRate(getRate) fail"); - if (STAmount::divide (a1, a2, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a2, a1))) - fail ("STAmount setRate(getRate) fail"); + unexpected (STAmount::divide (a1, a2, CURRENCY_ONE, ACCOUNT_ONE) != STAmount::setRate (STAmount::getRate (a2, a1)), + "STAmount setRate(getRate) fail"); } //-------------------------------------------------------------------------- void testArithmetic () { - beginTest ("arithmetic"); + beginTestCase ("arithmetic"); CBigNum b; @@ -1751,34 +1766,38 @@ public: WriteLog (lsFATAL, STAmount) << r << " != " << b.getuint64 () << " " << b.ToString (16); fail ("setull64/getull64 failure"); } + else + { + pass (); + } } // Test currency multiplication and division operations such as // convertToDisplayAmount, convertToInternalAmount, getRate, getClaimed, and getNeeded - if (STAmount::getRate (STAmount (1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 1"); + unexpected (STAmount::getRate (STAmount (1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 1"); - if (STAmount::getRate (STAmount (10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 2"); + unexpected (STAmount::getRate (STAmount (10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 2"); - if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 3"); + unexpected (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 3"); - if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 4"); + unexpected (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 4"); - if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 5"); + unexpected (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1), STAmount (10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 5"); - if (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 6"); + unexpected (STAmount::getRate (STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10), STAmount (1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 6"); - if (STAmount::getRate (STAmount (1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 7"); + unexpected (STAmount::getRate (STAmount (1), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 10)) != (((100ull - 14) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 7"); - if (STAmount::getRate (STAmount (10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull)) - fail ("STAmount getRate fail 8"); + unexpected (STAmount::getRate (STAmount (10), STAmount (CURRENCY_ONE, ACCOUNT_ONE, 1)) != (((100ull - 16) << (64 - 8)) | 1000000000000000ull), + "STAmount getRate fail 8"); roundTest (1, 3, 3); roundTest (2, 3, 9); @@ -1795,7 +1814,7 @@ public: void testUnderflow () { - beginTest ("underflow"); + beginTestCase ("underflow"); STAmount bigNative (STAmount::cMaxNative / 2); STAmount bigValue (CURRENCY_ONE, ACCOUNT_ONE, @@ -1843,7 +1862,7 @@ public: // Change this to actually do something. #if 0 - beginTest ("rounding "); + beginTestCase ("rounding "); uint64 value = 25000000000000000ull; int offset = -14; diff --git a/modules/ripple_data/protocol/ripple_SerializedObject.cpp b/modules/ripple_data/protocol/ripple_SerializedObject.cpp index 4dd89e9c12..91466e7fdc 100644 --- a/modules/ripple_data/protocol/ripple_SerializedObject.cpp +++ b/modules/ripple_data/protocol/ripple_SerializedObject.cpp @@ -1572,10 +1572,9 @@ public: void runTest () { - beginTest ("serialization"); + beginTestCase ("serialization"); - if (sfGeneric.isUseful ()) - fail ("sfGeneric must not be useful"); + unexpected (sfGeneric.isUseful (), "sfGeneric must not be useful"); SField sfTestVL (STI_VL, 255, "TestVL"); SField sfTestH256 (STI_HASH256, 255, "TestH256"); @@ -1591,16 +1590,16 @@ public: STObject object1 (elements, sfTestObject); STObject object2 (object1); - if (object1.getSerializer () != object2.getSerializer ()) fail ("STObject error 1"); + unexpected (object1.getSerializer () != object2.getSerializer (), "STObject error 1"); - if (object1.isFieldPresent (sfTestH256) || !object1.isFieldPresent (sfTestVL)) - fail ("STObject error"); + unexpected (object1.isFieldPresent (sfTestH256) || !object1.isFieldPresent (sfTestVL), + "STObject error"); object1.makeFieldPresent (sfTestH256); - if (!object1.isFieldPresent (sfTestH256)) fail ("STObject Error 2"); + unexpected (!object1.isFieldPresent (sfTestH256), "STObject Error 2"); - if (object1.getFieldH256 (sfTestH256) != uint256 ()) fail ("STObject error 3"); + unexpected (object1.getFieldH256 (sfTestH256) != uint256 (), "STObject error 3"); if (object1.getSerializer () == object2.getSerializer ()) { @@ -1608,26 +1607,30 @@ public: WriteLog (lsINFO, STObject) << "O2: " << object2.getJson (0); fail ("STObject error 4"); } + else + { + pass (); + } object1.makeFieldAbsent (sfTestH256); - if (object1.isFieldPresent (sfTestH256)) fail ("STObject error 5"); + unexpected (object1.isFieldPresent (sfTestH256), "STObject error 5"); - if (object1.getFlags () != 0) fail ("STObject error 6"); + unexpected (object1.getFlags () != 0, "STObject error 6"); - if (object1.getSerializer () != object2.getSerializer ()) fail ("STObject error 7"); + unexpected (object1.getSerializer () != object2.getSerializer (), "STObject error 7"); STObject copy (object1); - if (object1.isFieldPresent (sfTestH256)) fail ("STObject error 8"); + unexpected (object1.isFieldPresent (sfTestH256), "STObject error 8"); - if (copy.isFieldPresent (sfTestH256)) fail ("STObject error 9"); + unexpected (copy.isFieldPresent (sfTestH256), "STObject error 9"); - if (object1.getSerializer () != copy.getSerializer ()) fail ("STObject error 10"); + unexpected (object1.getSerializer () != copy.getSerializer (), "STObject error 10"); copy.setFieldU32 (sfTestU32, 1); - if (object1.getSerializer () == copy.getSerializer ()) fail ("STObject error 11"); + unexpected (object1.getSerializer () == copy.getSerializer (), "STObject error 11"); for (int i = 0; i < 1000; i++) { @@ -1641,9 +1644,9 @@ public: STObject object3 (elements, it, sfTestObject); - if (object1.getFieldVL (sfTestVL) != j) fail ("STObject error"); + unexpected (object1.getFieldVL (sfTestVL) != j, "STObject error"); - if (object3.getFieldVL (sfTestVL) != j) fail ("STObject error"); + unexpected (object3.getFieldVL (sfTestVL) != j, "STObject error"); } } }; diff --git a/modules/ripple_data/protocol/ripple_Serializer.cpp b/modules/ripple_data/protocol/ripple_Serializer.cpp index 5180a77a0d..eb1cad13a3 100644 --- a/modules/ripple_data/protocol/ripple_Serializer.cpp +++ b/modules/ripple_data/protocol/ripple_Serializer.cpp @@ -716,7 +716,7 @@ public: void runTest () { - beginTest ("hash"); + beginTestCase ("hash"); Serializer s1; s1.add32 (3);