diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h index 5235d8a5f..a0d9a3042 100644 --- a/modules/beast_core/beast_core.h +++ b/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/modules/beast_core/containers/beast_AbstractFifo.cpp b/modules/beast_core/containers/beast_AbstractFifo.cpp index 2e38d1802..0e3dd1236 100644 --- a/modules/beast_core/containers/beast_AbstractFifo.cpp +++ b/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/modules/beast_core/diagnostic/beast_UnitTest.h b/modules/beast_core/diagnostic/beast_UnitTest.h index da2062654..237f1ba89 100644 --- a/modules/beast_core/diagnostic/beast_UnitTest.h +++ b/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/modules/beast_core/files/beast_File.cpp b/modules/beast_core/files/beast_File.cpp index ab594bb9f..7ef709e32 100644 --- a/modules/beast_core/files/beast_File.cpp +++ b/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/modules/beast_core/json/beast_JSON.cpp b/modules/beast_core/json/beast_JSON.cpp index 1b4b98e90..d712896a1 100644 --- a/modules/beast_core/json/beast_JSON.cpp +++ b/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/modules/beast_core/maths/beast_Random.cpp b/modules/beast_core/maths/beast_Random.cpp index 115b4ae75..ce3199699 100644 --- a/modules/beast_core/maths/beast_Random.cpp +++ b/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/modules/beast_core/streams/beast_MemoryInputStream.cpp b/modules/beast_core/streams/beast_MemoryInputStream.cpp index a3ea33188..59c607856 100644 --- a/modules/beast_core/streams/beast_MemoryInputStream.cpp +++ b/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/modules/beast_core/text/beast_String.cpp b/modules/beast_core/text/beast_String.cpp index 6e15b67ac..d8771bb31 100644 --- a/modules/beast_core/text/beast_String.cpp +++ b/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/modules/beast_core/text/beast_TextDiff.cpp b/modules/beast_core/text/beast_TextDiff.cpp index 8453e1cac..7a1f2a894 100644 --- a/modules/beast_core/text/beast_TextDiff.cpp +++ b/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/modules/beast_core/threads/beast_ChildProcess.cpp b/modules/beast_core/threads/beast_ChildProcess.cpp index ede53e226..4e809a719 100644 --- a/modules/beast_core/threads/beast_ChildProcess.cpp +++ b/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/modules/beast_core/threads/beast_Thread.cpp b/modules/beast_core/threads/beast_Thread.cpp index f0ce078a4..999f35d44 100644 --- a/modules/beast_core/threads/beast_Thread.cpp +++ b/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/modules/beast_core/zip/beast_GZIPCompressorOutputStream.cpp b/modules/beast_core/zip/beast_GZIPCompressorOutputStream.cpp index 489e94baf..d8febfa5a 100644 --- a/modules/beast_core/zip/beast_GZIPCompressorOutputStream.cpp +++ b/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/modules/beast_crypto/math/beast_UnsignedInteger.cpp b/modules/beast_crypto/math/beast_UnsignedInteger.cpp index cb46c3879..916e6bad0 100644 --- a/modules/beast_crypto/math/beast_UnsignedInteger.cpp +++ b/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/modules/beast_crypto/math/beast_UnsignedInteger.h b/modules/beast_crypto/math/beast_UnsignedInteger.h index 17558bfda..9d4f950ea 100644 --- a/modules/beast_crypto/math/beast_UnsignedInteger.h +++ b/modules/beast_crypto/math/beast_UnsignedInteger.h @@ -146,7 +146,7 @@ public: */ bool asBoolean () const noexcept { - return isNonZero (); + return isNotZero (); } /** Access a particular byte.