From be312286c9fc531a323cfeb1b393b63388efa5de Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 14 Jul 2013 11:09:46 -0700 Subject: [PATCH] Fix gcc compile --- .../beast/modules/beast_core/beast_core.h | 2 +- .../containers/beast_AbstractFifo.cpp | 6 +- .../beast_core/diagnostic/beast_UnitTest.h | 94 +++++------- .../modules/beast_core/files/beast_File.cpp | 6 +- .../modules/beast_core/json/beast_JSON.cpp | 6 +- .../modules/beast_core/maths/beast_Random.cpp | 6 +- .../streams/beast_MemoryInputStream.cpp | 7 +- .../modules/beast_core/text/beast_String.cpp | 6 +- .../beast_core/text/beast_TextDiff.cpp | 6 +- .../beast_core/threads/beast_ChildProcess.cpp | 6 +- .../beast_core/threads/beast_Thread.cpp | 6 +- .../zip/beast_GZIPCompressorOutputStream.cpp | 6 +- .../math/beast_UnsignedInteger.cpp | 7 +- .../beast_crypto/math/beast_UnsignedInteger.h | 2 +- .../validator/ripple_ValidatorListImp.h | 2 +- .../validator/ripple_Validators.cpp | 135 +++++++++++++----- 16 files changed, 176 insertions(+), 127 deletions(-) diff --git a/Subtrees/beast/modules/beast_core/beast_core.h b/Subtrees/beast/modules/beast_core/beast_core.h index 5235d8a5fe..a0d9a3042f 100644 --- a/Subtrees/beast/modules/beast_core/beast_core.h +++ b/Subtrees/beast/modules/beast_core/beast_core.h @@ -207,6 +207,7 @@ namespace beast #include "containers/beast_LockFreeStack.h" #include "threads/beast_SpinDelay.h" #include "memory/beast_StaticObject.h" +#include "memory/beast_Memory.h" #include "text/beast_String.h" #include "text/beast_CharacterFunctions.h" @@ -217,7 +218,6 @@ namespace beast #include "time/beast_PerformedAtExit.h" #include "diagnostic/beast_LeakChecked.h" -#include "memory/beast_Memory.h" #include "memory/beast_ByteOrder.h" #include "logging/beast_Logger.h" #include "threads/beast_Thread.h" diff --git a/Subtrees/beast/modules/beast_core/containers/beast_AbstractFifo.cpp b/Subtrees/beast/modules/beast_core/containers/beast_AbstractFifo.cpp index 2e38d18021..0e3dd1236d 100644 --- a/Subtrees/beast/modules/beast_core/containers/beast_AbstractFifo.cpp +++ b/Subtrees/beast/modules/beast_core/containers/beast_AbstractFifo.cpp @@ -126,10 +126,10 @@ void AbstractFifo::finishedRead (int numRead) noexcept //============================================================================== -class AbstractFifoTests : public UnitTestType +class AbstractFifoTests : public UnitTest { public: - AbstractFifoTests() : UnitTestType ("Abstract Fifo") + AbstractFifoTests() : UnitTest ("Abstract Fifo") { } @@ -225,5 +225,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static AbstractFifoTests abstractFifoTests; #endif diff --git a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h index da20626542..237f1ba89e 100644 --- a/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h +++ b/Subtrees/beast/modules/beast_core/diagnostic/beast_UnitTest.h @@ -28,14 +28,50 @@ #include "../containers/beast_OwnedArray.h" class UnitTests; -/** Factored base class for unit test template. + +/** This is a base class for classes that perform a unit test. + + To write a test using this class, your code should look something like this: + + @code + + class MyTest : public UnitTest + { + public: + MyTest() : UnitTest ("Foobar testing") { } + + void runTest() + { + beginTest ("Part 1"); + + expect (myFoobar.doesSomething()); + expect (myFoobar.doesSomethingElse()); + + beginTest ("Part 2"); + + expect (myOtherFoobar.doesSomething()); + expect (myOtherFoobar.doesSomethingElse()); + + //... + } + }; + + // Explicit template instantiation is required to make the unit + // test get automatically added to the set of unit tests. + template class UnitTestType ; + + @endcode + + To run one or more unit tests, use the UnitTests class. + + @see UnitTests */ class BEAST_API UnitTest : Uncopyable { public: //============================================================================== /** Creates a test with the given name. */ - explicit UnitTest (const String& name); + explicit UnitTest (String const& name); /** Destructor. */ virtual ~UnitTest(); @@ -241,58 +277,4 @@ private: bool logPasses; }; -//------------------------------------------------------------------------------ - -/** This is a base class for classes that perform a unit test. - - To write a test using this class, your code should look something like this: - - @code - - class MyTest : public UnitTestType - { - public: - MyTest() : UnitTestType ("Foobar testing") { } - - void runTest() - { - beginTest ("Part 1"); - - expect (myFoobar.doesSomething()); - expect (myFoobar.doesSomethingElse()); - - beginTest ("Part 2"); - - expect (myOtherFoobar.doesSomething()); - expect (myOtherFoobar.doesSomethingElse()); - - //... - } - }; - - // Explicit template instantiation is required to make the unit - // test get automatically added to the set of unit tests. - template class UnitTestType ; - - @endcode - - To run one or more unit tests, use the UnitTests class. - - @see UnitTests -*/ -template -class UnitTestType : public UnitTest -{ -public: - explicit UnitTestType (String const& name) - : UnitTest (name) - { - } - - static Type s_test; -}; - -template -Type UnitTestType ::s_test; - #endif diff --git a/Subtrees/beast/modules/beast_core/files/beast_File.cpp b/Subtrees/beast/modules/beast_core/files/beast_File.cpp index ab594bb9f3..7ef709e324 100644 --- a/Subtrees/beast/modules/beast_core/files/beast_File.cpp +++ b/Subtrees/beast/modules/beast_core/files/beast_File.cpp @@ -923,10 +923,10 @@ MemoryMappedFile::MemoryMappedFile (const File& file, const Range& fileRa //============================================================================== -class FileTests : public UnitTestType +class FileTests : public UnitTest { public: - FileTests() : UnitTestType ("File") {} + FileTests() : UnitTest ("File") {} void runTest() { @@ -1107,6 +1107,6 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static FileTests fileTests; #endif diff --git a/Subtrees/beast/modules/beast_core/json/beast_JSON.cpp b/Subtrees/beast/modules/beast_core/json/beast_JSON.cpp index 1b4b98e903..d712896a1f 100644 --- a/Subtrees/beast/modules/beast_core/json/beast_JSON.cpp +++ b/Subtrees/beast/modules/beast_core/json/beast_JSON.cpp @@ -532,10 +532,10 @@ void JSON::writeToStream (OutputStream& output, const var& data, const bool allO //============================================================================== //============================================================================== -class JSONTests : public UnitTestType +class JSONTests : public UnitTest { public: - JSONTests() : UnitTestType ("JSON") {} + JSONTests() : UnitTest ("JSON") { } static String createRandomWideCharString (Random& r) { @@ -640,5 +640,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static JSONTests jsonTests; #endif diff --git a/Subtrees/beast/modules/beast_core/maths/beast_Random.cpp b/Subtrees/beast/modules/beast_core/maths/beast_Random.cpp index 115b4ae752..ce3199699c 100644 --- a/Subtrees/beast/modules/beast_core/maths/beast_Random.cpp +++ b/Subtrees/beast/modules/beast_core/maths/beast_Random.cpp @@ -134,10 +134,10 @@ void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numB //============================================================================== -class RandomTests : public UnitTestType +class RandomTests : public UnitTest { public: - RandomTests() : UnitTestType ("Random") {} + RandomTests() : UnitTest ("Random") {} void runTest() { @@ -166,5 +166,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static RandomTests randomTests; #endif diff --git a/Subtrees/beast/modules/beast_core/streams/beast_MemoryInputStream.cpp b/Subtrees/beast/modules/beast_core/streams/beast_MemoryInputStream.cpp index a3ea331885..59c6078562 100644 --- a/Subtrees/beast/modules/beast_core/streams/beast_MemoryInputStream.cpp +++ b/Subtrees/beast/modules/beast_core/streams/beast_MemoryInputStream.cpp @@ -89,10 +89,10 @@ int64 MemoryInputStream::getPosition() //============================================================================== -class MemoryStreamTests : public UnitTestType +class MemoryStreamTests : public UnitTest { public: - MemoryStreamTests() : UnitTestType ("MemoryStream") {} + MemoryStreamTests() : UnitTest ("MemoryStream") { } void runTest() { @@ -149,6 +149,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static MemoryStreamTests memoryStreamTests; #endif - diff --git a/Subtrees/beast/modules/beast_core/text/beast_String.cpp b/Subtrees/beast/modules/beast_core/text/beast_String.cpp index 6e15b67ac4..d8771bb31f 100644 --- a/Subtrees/beast/modules/beast_core/text/beast_String.cpp +++ b/Subtrees/beast/modules/beast_core/text/beast_String.cpp @@ -2075,10 +2075,10 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes) //============================================================================== //============================================================================== -class StringTests : public UnitTestType +class StringTests : public UnitTest { public: - StringTests() : UnitTestType ("String") {} + StringTests() : UnitTest ("String") { } template struct TestUTFConversion @@ -2403,5 +2403,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static StringTests stringTests; #endif diff --git a/Subtrees/beast/modules/beast_core/text/beast_TextDiff.cpp b/Subtrees/beast/modules/beast_core/text/beast_TextDiff.cpp index 8453e1cac9..7a1f2a894c 100644 --- a/Subtrees/beast/modules/beast_core/text/beast_TextDiff.cpp +++ b/Subtrees/beast/modules/beast_core/text/beast_TextDiff.cpp @@ -174,10 +174,10 @@ String TextDiff::Change::appliedTo (const String& text) const noexcept //============================================================================== -class DiffTests : public UnitTestType +class DiffTests : public UnitTest { public: - DiffTests() : UnitTestType ("TextDiff") {} + DiffTests() : UnitTest ("TextDiff") {} static String createString() { @@ -230,5 +230,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static DiffTests diffTests; #endif diff --git a/Subtrees/beast/modules/beast_core/threads/beast_ChildProcess.cpp b/Subtrees/beast/modules/beast_core/threads/beast_ChildProcess.cpp index ede53e226c..4e809a7197 100644 --- a/Subtrees/beast/modules/beast_core/threads/beast_ChildProcess.cpp +++ b/Subtrees/beast/modules/beast_core/threads/beast_ChildProcess.cpp @@ -58,10 +58,10 @@ String ChildProcess::readAllProcessOutput() //============================================================================== -class ChildProcessTests : public UnitTestType +class ChildProcessTests : public UnitTest { public: - ChildProcessTests() : UnitTestType ("ChildProcess") {} + ChildProcessTests() : UnitTest ("ChildProcess") {} void runTest() { @@ -83,5 +83,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static ChildProcessTests childProcessTests; #endif diff --git a/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp b/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp index f0ce078a49..999f35d444 100644 --- a/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp +++ b/Subtrees/beast/modules/beast_core/threads/beast_Thread.cpp @@ -252,10 +252,10 @@ void SpinLock::enter() const noexcept //============================================================================== -class AtomicTests : public UnitTestType +class AtomicTests : public UnitTest { public: - AtomicTests() : UnitTestType ("Atomic") {} + AtomicTests() : UnitTest ("Atomic") {} void runTest() { @@ -351,5 +351,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static AtomicTests atomicTests; #endif diff --git a/Subtrees/beast/modules/beast_core/zip/beast_GZIPCompressorOutputStream.cpp b/Subtrees/beast/modules/beast_core/zip/beast_GZIPCompressorOutputStream.cpp index 489e94baf6..d8febfa5ad 100644 --- a/Subtrees/beast/modules/beast_core/zip/beast_GZIPCompressorOutputStream.cpp +++ b/Subtrees/beast/modules/beast_core/zip/beast_GZIPCompressorOutputStream.cpp @@ -158,10 +158,10 @@ bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/) //============================================================================== -class GZIPTests : public UnitTestType +class GZIPTests : public UnitTest { public: - GZIPTests() : UnitTestType ("GZIP") {} + GZIPTests() : UnitTest ("GZIP") {} void runTest() { @@ -206,5 +206,5 @@ public: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static GZIPTests gzipTests; #endif diff --git a/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.cpp b/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.cpp index cb46c38795..916e6bad0d 100644 --- a/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.cpp +++ b/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.cpp @@ -17,11 +17,10 @@ */ //============================================================================== -class UnsignedIntegerTests : public UnitTestType +class UnsignedIntegerTests : public UnitTest { public: - UnsignedIntegerTests () - : UnitTestType ("UnsignedInteger") + UnsignedIntegerTests () : UnitTest ("UnsignedInteger") { } @@ -84,5 +83,5 @@ private: }; #if BEAST_UNIT_TESTS -template class UnitTestType ; +static UnsignedIntegerTests unsignedIntegerTests; #endif diff --git a/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.h b/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.h index 17558bfda6..9d4f950ea3 100644 --- a/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.h +++ b/Subtrees/beast/modules/beast_crypto/math/beast_UnsignedInteger.h @@ -146,7 +146,7 @@ public: */ bool asBoolean () const noexcept { - return isNonZero (); + return isNotZero (); } /** Access a particular byte. diff --git a/modules/ripple_core/validator/ripple_ValidatorListImp.h b/modules/ripple_core/validator/ripple_ValidatorListImp.h index f14dfefaae..1667d02018 100644 --- a/modules/ripple_core/validator/ripple_ValidatorListImp.h +++ b/modules/ripple_core/validator/ripple_ValidatorListImp.h @@ -22,7 +22,7 @@ public: { } - int size () const + int size () const noexcept { return m_list.size (); } diff --git a/modules/ripple_core/validator/ripple_Validators.cpp b/modules/ripple_core/validator/ripple_Validators.cpp index 04ac4c29c7..e722d0b624 100644 --- a/modules/ripple_core/validator/ripple_Validators.cpp +++ b/modules/ripple_core/validator/ripple_Validators.cpp @@ -6,6 +6,23 @@ /* +Goal: + + Provide the listener with a ValidatorList. + - This forms the UNL + +Task: + + fetch ValidatorInfo array from a source + + - We have the old one and the new one, compute the following: + + * unchanged validators list + * new validators list + * removed validators list + + - From the unchanged / new / removed, figure out what to do. + Two important questions: - Are there any validators in my ChosenValidators that I dont want @@ -25,7 +42,7 @@ public: enum { // We will fetch a source at this interval - hoursBetweenFetches = 24 + hoursBetweenFetches = 24 ,secondsBetweenFetches = hoursBetweenFetches * 60 * 60 @@ -75,8 +92,7 @@ public: Status status; Time whenToFetch; - /** The number of times a fetch has failed. - */ + // The number of times a fetch has failed. int numberOfFailures; }; @@ -159,7 +175,10 @@ public: sorted.ensureStorageAllocated (arrayToSort.size ()); for (int i = 0; i < arrayToSort.size (); ++i) - sorted.addSorted (ValidatorInfoCompare(), arrayToSort [i]); + { + ValidatorInfoCompare compare; + sorted.addSorted (compare, arrayToSort [i]); + } arrayToSort.swapWithArray (sorted); } @@ -169,6 +188,59 @@ public: } + // Given the old list and the new list for a source, this + // computes which validators were added or removed, and + // updates some statistics. It also produces the new list. + // + void processFetch (FetchResult* pFetchResult, + ValidatorInfoArray& oldList, + ValidatorInfoArray& newList) + { + ValidatorsImp::FetchResult& fetchResult (*pFetchResult); + + // First sort both arrays. + // + ValidatorInfoCompare compare; + oldList.sort (compare, true); + newList.sort (compare, true); + + // Now walk both arrays and do an element-wise + // comparison to determine the set intersection. + // + for (int i = 0; i < bmax (oldList.size (), newList.size ()); ++i) + { + if (i >= oldList.size ()) + { + // newList [i] not present in oldList + // newList [i] was added + } + else if (i >= newList.size ()) + { + // oldList [i] not present in newList + // oldList [i] no longer present + } + else + { + int const result = ValidatorInfoCompare::compareElements (oldList [i], newList [i]); + + if (result < 0) + { + // oldList [i] not present in newList + // oldList [i] was removed + } + else if (result > 0) + { + // newList [i] not present in oldList + // newList [i] was added + } + else + { + // no change in validator + } + } + } + } + private: OwnedArray m_sources; SourceInfoArray m_sourceInfo; @@ -327,13 +399,14 @@ private: //------------------------------------------------------------------------------ -class ValidatorListTests : public UnitTestType +class ValidatorListTests : public UnitTest { public: - ValidatorListTests () : UnitTestType ("ValidatorList") + ValidatorListTests () : UnitTest ("ValidatorList") { } + // Check public key routines void publicKeyTest () { beginTest ("compare"); @@ -345,49 +418,45 @@ public: expect (two > one, "should be greater"); } + // Verify the test fetching void fetchTest () { beginTest ("fetch"); - TestValidatorSource source (0, 32); - ValidatorsImp::ValidatorInfoArray results; - source.fetch (results); + TestValidatorSource (0, 32).fetch (results); expect (results.size () == 32, "size should be 32"); } + // Check logic for comparing a source's fetch results + void processFetchTest () + { + beginTest ("process fetch"); + + ValidatorsImp::ValidatorInfoArray oldList; + TestValidatorSource (1, 2).fetch (oldList); + expect (oldList.size () == 2, "size should be 2"); + + ValidatorsImp::ValidatorInfoArray newList; + TestValidatorSource (2, 2).fetch (newList); + expect (newList.size () == 2, "size should be 2"); + + ValidatorsImp::FetchResult fetchResult; + + ValidatorsImp::Logic ().processFetch (&fetchResult, oldList, newList); + } + void runTest () { publicKeyTest (); fetchTest (); + + processFetchTest (); } }; -template class UnitTestType ; - -/* - -Goal: - - Provide the listener with a ValidatorList. - - This forms the UNL - -Task: - - fetch ValidatorInfo array from a source - - - We have the old one and the new one, compute the following: - - * unchanged validators list - * new validators list - * removed validators list - - - From the unchanged / new / removed, figure out what to do. - -*/ - - +static ValidatorListTests validatorListTests;