mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 08:25:51 +00:00
Fix gcc compile
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -126,10 +126,10 @@ void AbstractFifo::finishedRead (int numRead) noexcept
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class AbstractFifoTests : public UnitTestType <AbstractFifoTests>
|
||||
class AbstractFifoTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
AbstractFifoTests() : UnitTestType <AbstractFifoTests> ("Abstract Fifo")
|
||||
AbstractFifoTests() : UnitTest ("Abstract Fifo")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -225,5 +225,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <AbstractFifoTests>;
|
||||
static AbstractFifoTests abstractFifoTests;
|
||||
#endif
|
||||
|
||||
@@ -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 <MyTest>;
|
||||
|
||||
@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 <MyTest>
|
||||
{
|
||||
public:
|
||||
MyTest() : UnitTestType <MyTest> ("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 <MyTest>;
|
||||
|
||||
@endcode
|
||||
|
||||
To run one or more unit tests, use the UnitTests class.
|
||||
|
||||
@see UnitTests
|
||||
*/
|
||||
template <class Type>
|
||||
class UnitTestType : public UnitTest
|
||||
{
|
||||
public:
|
||||
explicit UnitTestType (String const& name)
|
||||
: UnitTest (name)
|
||||
{
|
||||
}
|
||||
|
||||
static Type s_test;
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
Type UnitTestType <Type>::s_test;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -923,10 +923,10 @@ MemoryMappedFile::MemoryMappedFile (const File& file, const Range<int64>& fileRa
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class FileTests : public UnitTestType <FileTests>
|
||||
class FileTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
FileTests() : UnitTestType <FileTests> ("File") {}
|
||||
FileTests() : UnitTest ("File") {}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
@@ -1107,6 +1107,6 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <FileTests>;
|
||||
static FileTests fileTests;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -532,10 +532,10 @@ void JSON::writeToStream (OutputStream& output, const var& data, const bool allO
|
||||
//==============================================================================
|
||||
//==============================================================================
|
||||
|
||||
class JSONTests : public UnitTestType <JSONTests>
|
||||
class JSONTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
JSONTests() : UnitTestType <JSONTests> ("JSON") {}
|
||||
JSONTests() : UnitTest ("JSON") { }
|
||||
|
||||
static String createRandomWideCharString (Random& r)
|
||||
{
|
||||
@@ -640,5 +640,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <JSONTests>;
|
||||
static JSONTests jsonTests;
|
||||
#endif
|
||||
|
||||
@@ -134,10 +134,10 @@ void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numB
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class RandomTests : public UnitTestType <RandomTests>
|
||||
class RandomTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
RandomTests() : UnitTestType <RandomTests> ("Random") {}
|
||||
RandomTests() : UnitTest ("Random") {}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
@@ -166,5 +166,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <RandomTests>;
|
||||
static RandomTests randomTests;
|
||||
#endif
|
||||
|
||||
@@ -89,10 +89,10 @@ int64 MemoryInputStream::getPosition()
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class MemoryStreamTests : public UnitTestType <MemoryStreamTests>
|
||||
class MemoryStreamTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
MemoryStreamTests() : UnitTestType <MemoryStreamTests> ("MemoryStream") {}
|
||||
MemoryStreamTests() : UnitTest ("MemoryStream") { }
|
||||
|
||||
void runTest()
|
||||
{
|
||||
@@ -149,6 +149,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <MemoryStreamTests>;
|
||||
static MemoryStreamTests memoryStreamTests;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2075,10 +2075,10 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
|
||||
//==============================================================================
|
||||
//==============================================================================
|
||||
|
||||
class StringTests : public UnitTestType <StringTests>
|
||||
class StringTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
StringTests() : UnitTestType <StringTests> ("String") {}
|
||||
StringTests() : UnitTest ("String") { }
|
||||
|
||||
template <class CharPointerType>
|
||||
struct TestUTFConversion
|
||||
@@ -2403,5 +2403,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <StringTests>;
|
||||
static StringTests stringTests;
|
||||
#endif
|
||||
|
||||
@@ -174,10 +174,10 @@ String TextDiff::Change::appliedTo (const String& text) const noexcept
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class DiffTests : public UnitTestType <DiffTests>
|
||||
class DiffTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
DiffTests() : UnitTestType <DiffTests> ("TextDiff") {}
|
||||
DiffTests() : UnitTest ("TextDiff") {}
|
||||
|
||||
static String createString()
|
||||
{
|
||||
@@ -230,5 +230,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <DiffTests>;
|
||||
static DiffTests diffTests;
|
||||
#endif
|
||||
|
||||
@@ -58,10 +58,10 @@ String ChildProcess::readAllProcessOutput()
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class ChildProcessTests : public UnitTestType <ChildProcessTests>
|
||||
class ChildProcessTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
ChildProcessTests() : UnitTestType <ChildProcessTests> ("ChildProcess") {}
|
||||
ChildProcessTests() : UnitTest ("ChildProcess") {}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
@@ -83,5 +83,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <ChildProcessTests>;
|
||||
static ChildProcessTests childProcessTests;
|
||||
#endif
|
||||
|
||||
@@ -252,10 +252,10 @@ void SpinLock::enter() const noexcept
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class AtomicTests : public UnitTestType <AtomicTests>
|
||||
class AtomicTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
AtomicTests() : UnitTestType <AtomicTests> ("Atomic") {}
|
||||
AtomicTests() : UnitTest ("Atomic") {}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
@@ -351,5 +351,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <AtomicTests>;
|
||||
static AtomicTests atomicTests;
|
||||
#endif
|
||||
|
||||
@@ -158,10 +158,10 @@ bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
|
||||
|
||||
//==============================================================================
|
||||
|
||||
class GZIPTests : public UnitTestType <GZIPTests>
|
||||
class GZIPTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
GZIPTests() : UnitTestType <GZIPTests> ("GZIP") {}
|
||||
GZIPTests() : UnitTest ("GZIP") {}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
@@ -206,5 +206,5 @@ public:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <GZIPTests>;
|
||||
static GZIPTests gzipTests;
|
||||
#endif
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class UnsignedIntegerTests : public UnitTestType <UnsignedIntegerTests>
|
||||
class UnsignedIntegerTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
UnsignedIntegerTests ()
|
||||
: UnitTestType <UnsignedIntegerTests> ("UnsignedInteger")
|
||||
UnsignedIntegerTests () : UnitTest ("UnsignedInteger")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -84,5 +83,5 @@ private:
|
||||
};
|
||||
|
||||
#if BEAST_UNIT_TESTS
|
||||
template class UnitTestType <UnsignedIntegerTests>;
|
||||
static UnsignedIntegerTests unsignedIntegerTests;
|
||||
#endif
|
||||
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
*/
|
||||
bool asBoolean () const noexcept
|
||||
{
|
||||
return isNonZero ();
|
||||
return isNotZero ();
|
||||
}
|
||||
|
||||
/** Access a particular byte.
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
int size () const
|
||||
int size () const noexcept
|
||||
{
|
||||
return m_list.size ();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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 <Source> m_sources;
|
||||
SourceInfoArray m_sourceInfo;
|
||||
@@ -327,13 +399,14 @@ private:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class ValidatorListTests : public UnitTestType <ValidatorListTests>
|
||||
class ValidatorListTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
ValidatorListTests () : UnitTestType <ValidatorListTests> ("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 <ValidatorListTests>;
|
||||
|
||||
/*
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user