From 6bfcd820b40d2db7ca1136602f6caef1ab6bc46d Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 20 Jul 2017 17:24:05 +0100 Subject: [PATCH] Unit tests: Added an optional argument to the UnitTest constructor to specify a category and methods to get and run unit tests in a specified category. Updated the built-in JUCE unit tests and Demo project to use categories. --- examples/Demo/Source/Demos/UnitTestsDemo.cpp | 45 +++++++++++++------ .../buffers/juce_AudioDataConverters.cpp | 2 +- .../buffers/juce_FloatVectorOperations.cpp | 2 +- .../juce_audio_basics/midi/juce_MidiRPN.cpp | 4 +- .../mpe/juce_MPEInstrument.cpp | 2 +- .../mpe/juce_MPEMessages.cpp | 2 +- .../juce_audio_basics/mpe/juce_MPENote.cpp | 2 +- .../juce_audio_basics/mpe/juce_MPEValue.cpp | 2 +- .../juce_audio_basics/mpe/juce_MPEZone.cpp | 2 +- .../mpe/juce_MPEZoneLayout.cpp | 2 +- .../codecs/juce_WavAudioFormat.cpp | 2 +- .../containers/juce_AbstractFifo.cpp | 2 +- .../containers/juce_HashMap_test.cpp | 2 +- .../containers/juce_ListenerList.cpp | 2 +- modules/juce_core/files/juce_File.cpp | 2 +- modules/juce_core/javascript/juce_JSON.cpp | 2 +- modules/juce_core/maths/juce_BigInteger.cpp | 2 +- modules/juce_core/maths/juce_Random.cpp | 2 +- .../juce_core/misc/juce_StdFunctionCompat.cpp | 2 +- .../streams/juce_MemoryInputStream.cpp | 2 +- modules/juce_core/text/juce_Base64.cpp | 2 +- modules/juce_core/text/juce_String.cpp | 2 +- modules/juce_core/text/juce_TextDiff.cpp | 2 +- .../juce_core/threads/juce_ChildProcess.cpp | 2 +- modules/juce_core/threads/juce_Thread.cpp | 4 +- modules/juce_core/time/juce_Time.cpp | 2 +- .../juce_core/unit_tests/juce_UnitTest.cpp | 34 +++++++++++++- modules/juce_core/unit_tests/juce_UnitTest.h | 22 ++++++++- .../zip/juce_GZIPCompressorOutputStream.cpp | 2 +- .../encryption/juce_BlowFish.cpp | 2 +- .../juce_cryptography/hashing/juce_MD5.cpp | 2 +- .../juce_cryptography/hashing/juce_SHA256.cpp | 2 +- .../hashing/juce_Whirlpool.cpp | 2 +- .../values/juce_CachedValue.cpp | 2 +- .../values/juce_ValueTree.cpp | 2 +- modules/juce_osc/osc/juce_OSCAddress.cpp | 6 +-- modules/juce_osc/osc/juce_OSCArgument.cpp | 2 +- modules/juce_osc/osc/juce_OSCBundle.cpp | 4 +- modules/juce_osc/osc/juce_OSCMessage.cpp | 2 +- modules/juce_osc/osc/juce_OSCReceiver.cpp | 2 +- modules/juce_osc/osc/juce_OSCSender.cpp | 4 +- modules/juce_osc/osc/juce_OSCTimeTag.cpp | 2 +- 42 files changed, 129 insertions(+), 62 deletions(-) diff --git a/examples/Demo/Source/Demos/UnitTestsDemo.cpp b/examples/Demo/Source/Demos/UnitTestsDemo.cpp index 148662dcdc..6ea7290731 100644 --- a/examples/Demo/Source/Demos/UnitTestsDemo.cpp +++ b/examples/Demo/Source/Demos/UnitTestsDemo.cpp @@ -63,16 +63,21 @@ struct UnitTestClasses private Timer { public: - TestRunnerThread (UnitTestsDemo& utd) + TestRunnerThread (UnitTestsDemo& utd, const String& ctg) : Thread ("Unit Tests"), - owner (utd) + owner (utd), + category (ctg) { } void run() override { CustomTestRunner runner (*this); - runner.runAllTests(); + + if (category == "All Tests") + runner.runAllTests(); + else + runner.runTestsInCategory (category); startTimer (50); // when finished, start the timer which will // wait for the thread to end, then tell our component. @@ -94,6 +99,7 @@ struct UnitTestClasses private: UnitTestsDemo& owner; + const String category; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TestRunnerThread) }; @@ -110,13 +116,22 @@ struct UnitTestClasses setOpaque (true); addAndMakeVisible (startTestButton); + startTestButton.addListener (this); + addAndMakeVisible (testResultsBox); testResultsBox.setMultiLine (true); testResultsBox.setFont (Font (Font::getDefaultMonospacedFontName(), 12.0f, Font::plain)); - startTestButton.addListener (this); + addAndMakeVisible (categoriesBox); + categoriesBox.addItem ("All Tests", 1); + + auto categories = UnitTest::getAllCategories(); + categories.sort (true); - logMessage ("This panel runs all the built-in JUCE unit-tests.\n"); + categoriesBox.addItemList (categories, 2); + categoriesBox.setSelectedId (1); + + logMessage ("This panel runs the built-in JUCE unit-tests from the selected category.\n"); logMessage ("To add your own unit-tests, see the JUCE_UNIT_TESTS macro."); } @@ -134,26 +149,29 @@ struct UnitTestClasses void resized() override { - Rectangle r (getLocalBounds().reduced (6)); + auto bounds = getLocalBounds().reduced (6); + + auto topSlice = bounds.removeFromTop (25); + startTestButton.setBounds (topSlice.removeFromLeft (200)); + topSlice.removeFromLeft (10); + categoriesBox.setBounds (topSlice.removeFromLeft (250)); - startTestButton.setBounds (r.removeFromTop (25).removeFromLeft (200)); - testResultsBox.setBounds (r.withTrimmedTop (5)); + bounds.removeFromTop (5); + testResultsBox.setBounds (bounds); } void buttonClicked (Button* buttonThatWasClicked) override { if (buttonThatWasClicked == &startTestButton) - { - startTest(); - } + startTest (categoriesBox.getText()); } - void startTest() + void startTest (const String& category) { testResultsBox.clear(); startTestButton.setEnabled (false); - currentTestThread = new TestRunnerThread (*this); + currentTestThread = new TestRunnerThread (*this, category); currentTestThread->startThread(); } @@ -184,6 +202,7 @@ struct UnitTestClasses ScopedPointer currentTestThread; TextButton startTestButton; + ComboBox categoriesBox; TextEditor testResultsBox; void lookAndFeelChanged() override diff --git a/modules/juce_audio_basics/buffers/juce_AudioDataConverters.cpp b/modules/juce_audio_basics/buffers/juce_AudioDataConverters.cpp index c9e543ebbe..de705a8d36 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioDataConverters.cpp +++ b/modules/juce_audio_basics/buffers/juce_AudioDataConverters.cpp @@ -475,7 +475,7 @@ void AudioDataConverters::deinterleaveSamples (const float* const source, class AudioConversionTests : public UnitTest { public: - AudioConversionTests() : UnitTest ("Audio data conversion") {} + AudioConversionTests() : UnitTest ("Audio data conversion", "Audio") {} template struct Test5 diff --git a/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp b/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp index fe23ceea65..05f15f942e 100644 --- a/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp +++ b/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp @@ -1016,7 +1016,7 @@ void JUCE_CALLTYPE FloatVectorOperations::disableDenormalisedNumberSupport() noe class FloatVectorOperationsTests : public UnitTest { public: - FloatVectorOperationsTests() : UnitTest ("FloatVectorOperations") {} + FloatVectorOperationsTests() : UnitTest ("FloatVectorOperations", "Audio") {} template struct TestRunner diff --git a/modules/juce_audio_basics/midi/juce_MidiRPN.cpp b/modules/juce_audio_basics/midi/juce_MidiRPN.cpp index eb829fc2b2..fbe7cf50bd 100644 --- a/modules/juce_audio_basics/midi/juce_MidiRPN.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiRPN.cpp @@ -163,7 +163,7 @@ MidiBuffer MidiRPNGenerator::generate (int midiChannel, class MidiRPNDetectorTests : public UnitTest { public: - MidiRPNDetectorTests() : UnitTest ("MidiRPNDetector class") {} + MidiRPNDetectorTests() : UnitTest ("MidiRPNDetector class", "MIDI/MPE") {} void runTest() override { @@ -305,7 +305,7 @@ static MidiRPNDetectorTests MidiRPNDetectorUnitTests; class MidiRPNGeneratorTests : public UnitTest { public: - MidiRPNGeneratorTests() : UnitTest ("MidiRPNGenerator class") {} + MidiRPNGeneratorTests() : UnitTest ("MidiRPNGenerator class", "MIDI/MPE") {} void runTest() override { diff --git a/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp b/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp index be836cc6f2..70aee29fde 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp @@ -695,7 +695,7 @@ class MPEInstrumentTests : public UnitTest { public: MPEInstrumentTests() - : UnitTest ("MPEInstrument class") + : UnitTest ("MPEInstrument class", "MIDI/MPE") { // using two MPE zones with the following layout for testing // diff --git a/modules/juce_audio_basics/mpe/juce_MPEMessages.cpp b/modules/juce_audio_basics/mpe/juce_MPEMessages.cpp index b6e7dfff24..09939a1045 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEMessages.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPEMessages.cpp @@ -71,7 +71,7 @@ MidiBuffer MPEMessages::setZoneLayout (const MPEZoneLayout& layout) class MPEMessagesTests : public UnitTest { public: - MPEMessagesTests() : UnitTest ("MPEMessages class") {} + MPEMessagesTests() : UnitTest ("MPEMessages class", "MIDI/MPE") {} void runTest() override { diff --git a/modules/juce_audio_basics/mpe/juce_MPENote.cpp b/modules/juce_audio_basics/mpe/juce_MPENote.cpp index 33b9cde397..1f47cec021 100644 --- a/modules/juce_audio_basics/mpe/juce_MPENote.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPENote.cpp @@ -99,7 +99,7 @@ bool MPENote::operator!= (const MPENote& other) const noexcept class MPENoteTests : public UnitTest { public: - MPENoteTests() : UnitTest ("MPENote class") {} + MPENoteTests() : UnitTest ("MPENote class", "MIDI/MPE") {} //============================================================================== void runTest() override diff --git a/modules/juce_audio_basics/mpe/juce_MPEValue.cpp b/modules/juce_audio_basics/mpe/juce_MPEValue.cpp index 597140743e..9413057542 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEValue.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPEValue.cpp @@ -89,7 +89,7 @@ bool MPEValue::operator!= (const MPEValue& other) const noexcept class MPEValueTests : public UnitTest { public: - MPEValueTests() : UnitTest ("MPEValue class") {} + MPEValueTests() : UnitTest ("MPEValue class", "MIDI/MPE") {} void runTest() override { diff --git a/modules/juce_audio_basics/mpe/juce_MPEZone.cpp b/modules/juce_audio_basics/mpe/juce_MPEZone.cpp index 3ea8f14f7a..912a86c3c5 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEZone.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPEZone.cpp @@ -163,7 +163,7 @@ bool MPEZone::operator!= (const MPEZone& other) const noexcept class MPEZoneTests : public UnitTest { public: - MPEZoneTests() : UnitTest ("MPEZone class") {} + MPEZoneTests() : UnitTest ("MPEZone class", "MIDI/MPE") {} void runTest() override { diff --git a/modules/juce_audio_basics/mpe/juce_MPEZoneLayout.cpp b/modules/juce_audio_basics/mpe/juce_MPEZoneLayout.cpp index 944d6d3ea6..450dc09f6b 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEZoneLayout.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPEZoneLayout.cpp @@ -204,7 +204,7 @@ void MPEZoneLayout::removeListener (Listener* const listenerToRemove) noexcept class MPEZoneLayoutTests : public UnitTest { public: - MPEZoneLayoutTests() : UnitTest ("MPEZoneLayout class") {} + MPEZoneLayoutTests() : UnitTest ("MPEZoneLayout class", "MIDI/MPE") {} void runTest() override { diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index ee19345280..46167655fa 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -1691,7 +1691,7 @@ bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPai struct WaveAudioFormatTests : public UnitTest { - WaveAudioFormatTests() : UnitTest ("Wave audio format tests") {} + WaveAudioFormatTests() : UnitTest ("Wave audio format tests", "Audio") {} void runTest() override { diff --git a/modules/juce_core/containers/juce_AbstractFifo.cpp b/modules/juce_core/containers/juce_AbstractFifo.cpp index decb2b9b4e..03d61396b5 100644 --- a/modules/juce_core/containers/juce_AbstractFifo.cpp +++ b/modules/juce_core/containers/juce_AbstractFifo.cpp @@ -130,7 +130,7 @@ void AbstractFifo::finishedRead (int numRead) noexcept class AbstractFifoTests : public UnitTest { public: - AbstractFifoTests() : UnitTest ("Abstract Fifo") {} + AbstractFifoTests() : UnitTest ("Abstract Fifo", "Containers") {} class WriteThread : public Thread { diff --git a/modules/juce_core/containers/juce_HashMap_test.cpp b/modules/juce_core/containers/juce_HashMap_test.cpp index 9baa956a21..428bdc8071 100644 --- a/modules/juce_core/containers/juce_HashMap_test.cpp +++ b/modules/juce_core/containers/juce_HashMap_test.cpp @@ -22,7 +22,7 @@ struct HashMapTest : public UnitTest { - HashMapTest() : UnitTest ("HashMap") {} + HashMapTest() : UnitTest ("HashMap", "Containers") {} void runTest() override { diff --git a/modules/juce_core/containers/juce_ListenerList.cpp b/modules/juce_core/containers/juce_ListenerList.cpp index dfa0b9d184..f0885171b0 100644 --- a/modules/juce_core/containers/juce_ListenerList.cpp +++ b/modules/juce_core/containers/juce_ListenerList.cpp @@ -76,7 +76,7 @@ struct Listener2 : public ListenerBase class ListenerListTests : public UnitTest { public: - ListenerListTests() : UnitTest ("ListenerList") {} + ListenerListTests() : UnitTest ("ListenerList", "Containers") {} template void callHelper (std::vector& expectedCounterValues) diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index e6ed109022..c5bd5b8be6 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -1004,7 +1004,7 @@ MemoryMappedFile::MemoryMappedFile (const File& file, const Range& fileRa class FileTests : public UnitTest { public: - FileTests() : UnitTest ("Files") {} + FileTests() : UnitTest ("Files", "Files") {} void runTest() override { diff --git a/modules/juce_core/javascript/juce_JSON.cpp b/modules/juce_core/javascript/juce_JSON.cpp index 1f31c6a2e0..0623266b45 100644 --- a/modules/juce_core/javascript/juce_JSON.cpp +++ b/modules/juce_core/javascript/juce_JSON.cpp @@ -529,7 +529,7 @@ Result JSON::parseQuotedString (String::CharPointerType& t, var& result) class JSONTests : public UnitTest { public: - JSONTests() : UnitTest ("JSON") {} + JSONTests() : UnitTest ("JSON", "JSON") {} static String createRandomWideCharString (Random& r) { diff --git a/modules/juce_core/maths/juce_BigInteger.cpp b/modules/juce_core/maths/juce_BigInteger.cpp index a82d025f99..14a9354394 100644 --- a/modules/juce_core/maths/juce_BigInteger.cpp +++ b/modules/juce_core/maths/juce_BigInteger.cpp @@ -1291,7 +1291,7 @@ uint32 readLittleEndianBitsInBuffer (const void* buffer, uint32 startBit, uint32 class BigIntegerTests : public UnitTest { public: - BigIntegerTests() : UnitTest ("BigInteger") {} + BigIntegerTests() : UnitTest ("BigInteger", "Maths") {} static BigInteger getBigRandom (Random& r) { diff --git a/modules/juce_core/maths/juce_Random.cpp b/modules/juce_core/maths/juce_Random.cpp index 0c2d1ec72b..5d83f718aa 100644 --- a/modules/juce_core/maths/juce_Random.cpp +++ b/modules/juce_core/maths/juce_Random.cpp @@ -154,7 +154,7 @@ void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numB class RandomTests : public UnitTest { public: - RandomTests() : UnitTest ("Random") {} + RandomTests() : UnitTest ("Random", "Maths") {} void runTest() override { diff --git a/modules/juce_core/misc/juce_StdFunctionCompat.cpp b/modules/juce_core/misc/juce_StdFunctionCompat.cpp index f0012e9892..cf548ef609 100644 --- a/modules/juce_core/misc/juce_StdFunctionCompat.cpp +++ b/modules/juce_core/misc/juce_StdFunctionCompat.cpp @@ -75,7 +75,7 @@ namespace FunctionTestsHelpers class FunctionTests : public UnitTest { public: - FunctionTests() : UnitTest ("Function") {} + FunctionTests() : UnitTest ("Function", "Function") {} void runTest() override { diff --git a/modules/juce_core/streams/juce_MemoryInputStream.cpp b/modules/juce_core/streams/juce_MemoryInputStream.cpp index 6c57981761..3dfb1237c6 100644 --- a/modules/juce_core/streams/juce_MemoryInputStream.cpp +++ b/modules/juce_core/streams/juce_MemoryInputStream.cpp @@ -98,7 +98,7 @@ int64 MemoryInputStream::getPosition() class MemoryStreamTests : public UnitTest { public: - MemoryStreamTests() : UnitTest ("MemoryInputStream & MemoryOutputStream") {} + MemoryStreamTests() : UnitTest ("MemoryInputStream & MemoryOutputStream", "Memory Streams") {} void runTest() override { diff --git a/modules/juce_core/text/juce_Base64.cpp b/modules/juce_core/text/juce_Base64.cpp index b49f443e73..bda7c3b669 100644 --- a/modules/juce_core/text/juce_Base64.cpp +++ b/modules/juce_core/text/juce_Base64.cpp @@ -124,7 +124,7 @@ String Base64::toBase64 (const String& text) class Base64Tests : public UnitTest { public: - Base64Tests() : UnitTest ("Base64 class") {} + Base64Tests() : UnitTest ("Base64 class", "Text") {} static MemoryBlock createRandomData (Random& r) { diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index b67fcea45b..d835bfc26a 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -2223,7 +2223,7 @@ StringRef::StringRef (const String& string) noexcept : text (string.getCharPoin class StringTests : public UnitTest { public: - StringTests() : UnitTest ("String class") {} + StringTests() : UnitTest ("String class", "Text") {} template struct TestUTFConversion diff --git a/modules/juce_core/text/juce_TextDiff.cpp b/modules/juce_core/text/juce_TextDiff.cpp index 19ec187f30..35b13f7a48 100644 --- a/modules/juce_core/text/juce_TextDiff.cpp +++ b/modules/juce_core/text/juce_TextDiff.cpp @@ -220,7 +220,7 @@ String TextDiff::Change::appliedTo (const String& text) const noexcept class DiffTests : public UnitTest { public: - DiffTests() : UnitTest ("TextDiff class") {} + DiffTests() : UnitTest ("TextDiff class", "Text") {} static String createString (Random& r) { diff --git a/modules/juce_core/threads/juce_ChildProcess.cpp b/modules/juce_core/threads/juce_ChildProcess.cpp index 50a11244b7..5648c5d673 100644 --- a/modules/juce_core/threads/juce_ChildProcess.cpp +++ b/modules/juce_core/threads/juce_ChildProcess.cpp @@ -81,7 +81,7 @@ String ChildProcess::readAllProcessOutput() class ChildProcessTests : public UnitTest { public: - ChildProcessTests() : UnitTest ("ChildProcess") {} + ChildProcessTests() : UnitTest ("ChildProcess", "Threads") {} void runTest() override { diff --git a/modules/juce_core/threads/juce_Thread.cpp b/modules/juce_core/threads/juce_Thread.cpp index 7e0a94ac21..28b7cf40b9 100644 --- a/modules/juce_core/threads/juce_Thread.cpp +++ b/modules/juce_core/threads/juce_Thread.cpp @@ -299,7 +299,7 @@ bool JUCE_CALLTYPE Process::isRunningUnderDebugger() noexcept class AtomicTests : public UnitTest { public: - AtomicTests() : UnitTest ("Atomics") {} + AtomicTests() : UnitTest ("Atomics", "Threads") {} void runTest() override { @@ -422,7 +422,7 @@ class ThreadLocalValueUnitTest : public UnitTest, private Thread { public: ThreadLocalValueUnitTest() - : UnitTest ("ThreadLocalValue"), + : UnitTest ("ThreadLocalValue", "Threads"), Thread ("ThreadLocalValue Thread") {} diff --git a/modules/juce_core/time/juce_Time.cpp b/modules/juce_core/time/juce_Time.cpp index 72645d5ed4..2e78b58edb 100644 --- a/modules/juce_core/time/juce_Time.cpp +++ b/modules/juce_core/time/juce_Time.cpp @@ -628,7 +628,7 @@ Time Time::getCompilationDate() class TimeTests : public UnitTest { public: - TimeTests() : UnitTest ("Time") {} + TimeTests() : UnitTest ("Time", "Time") {} void runTest() override { diff --git a/modules/juce_core/unit_tests/juce_UnitTest.cpp b/modules/juce_core/unit_tests/juce_UnitTest.cpp index ea7d2f0096..2ed41b9813 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.cpp +++ b/modules/juce_core/unit_tests/juce_UnitTest.cpp @@ -20,8 +20,8 @@ ============================================================================== */ -UnitTest::UnitTest (const String& nm) - : name (nm), runner (nullptr) +UnitTest::UnitTest (const String& nm, const String& ctg) + : name (nm), category (ctg), runner (nullptr) { getAllTests().add (this); } @@ -37,6 +37,31 @@ Array& UnitTest::getAllTests() return tests; } +Array UnitTest::getTestsInCategory (const String& category) +{ + if (category.isEmpty()) + return getAllTests(); + + Array unitTests; + + for (auto* test : getAllTests()) + if (test->getCategory() == category) + unitTests.add (test); + + return unitTests; +} + +StringArray UnitTest::getAllCategories() +{ + StringArray categories; + + for (auto* test : getAllTests()) + if (test->getCategory().isNotEmpty()) + categories.addIfNotAlreadyThere (test->getCategory()); + + return categories; +} + void UnitTest::initialise() {} void UnitTest::shutdown() {} @@ -159,6 +184,11 @@ void UnitTestRunner::runAllTests (int64 randomSeed) runTests (UnitTest::getAllTests(), randomSeed); } +void UnitTestRunner::runTestsInCategory (const String& category, int64 randomSeed) +{ + runTests (UnitTest::getTestsInCategory (category), randomSeed); +} + void UnitTestRunner::logMessage (const String& message) { Logger::writeToLog (message); diff --git a/modules/juce_core/unit_tests/juce_UnitTest.h b/modules/juce_core/unit_tests/juce_UnitTest.h index b431943e29..68c4459818 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.h +++ b/modules/juce_core/unit_tests/juce_UnitTest.h @@ -67,8 +67,8 @@ class JUCE_API UnitTest { public: //============================================================================== - /** Creates a test with the given name. */ - explicit UnitTest (const String& name); + /** Creates a test with the given name and optionally places it in a category. */ + explicit UnitTest (const String& name, const String& category = String()); /** Destructor. */ virtual ~UnitTest(); @@ -76,6 +76,9 @@ public: /** Returns the name of the test. */ const String& getName() const noexcept { return name; } + /** Returns the category of the test. */ + const String& getCategory() const noexcept { return category; } + /** Runs the test, using the specified UnitTestRunner. You shouldn't need to call this method directly - use UnitTestRunner::runTests() instead. @@ -85,6 +88,12 @@ public: /** Returns the set of all UnitTest objects that currently exist. */ static Array& getAllTests(); + /** Returns the set of UnitTests in a specified category. */ + static Array getTestsInCategory (const String& category); + + /** Returns a StringArray containing all of the categories of UnitTests that have been registered. */ + static StringArray getAllCategories(); + //============================================================================== /** You can optionally implement this method to set up your test. This method will be called before runTest(). @@ -289,6 +298,7 @@ private: //============================================================================== const String name; + const String category; UnitTestRunner* runner; JUCE_DECLARE_NON_COPYABLE (UnitTest) @@ -335,6 +345,14 @@ public: */ void runAllTests (int64 randomSeed = 0); + /** Runs all the UnitTest objects within a specified category. + This calls runTests() for all the objects listed in UnitTest::getTestsInCategory(). + + If you want to run the tests with a predetermined seed, you can pass that into + the randomSeed argument, or pass 0 to have a randomly-generated seed chosen. + */ + void runTestsInCategory (const String& category, int64 randomSeed = 0); + /** Sets a flag to indicate whether an assertion should be triggered if a test fails. This is true by default. */ diff --git a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp index 19da1f08f5..d8c46bc009 100644 --- a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp +++ b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp @@ -158,7 +158,7 @@ bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/) class GZIPTests : public UnitTest { public: - GZIPTests() : UnitTest ("GZIP") {} + GZIPTests() : UnitTest ("GZIP", "Compression") {} void runTest() override { diff --git a/modules/juce_cryptography/encryption/juce_BlowFish.cpp b/modules/juce_cryptography/encryption/juce_BlowFish.cpp index 838ee089ce..cc16b5c9bc 100644 --- a/modules/juce_cryptography/encryption/juce_BlowFish.cpp +++ b/modules/juce_cryptography/encryption/juce_BlowFish.cpp @@ -368,7 +368,7 @@ int BlowFish::unpad (const void* data, size_t size) noexcept class BlowFishTests : public UnitTest { public: - BlowFishTests() : UnitTest ("BlowFish") {} + BlowFishTests() : UnitTest ("BlowFish", "Cryptography") {} static void fillMemoryBlockWithRandomData (MemoryBlock& block, Random& random) { diff --git a/modules/juce_cryptography/hashing/juce_MD5.cpp b/modules/juce_cryptography/hashing/juce_MD5.cpp index 648d799484..c4f7f86393 100644 --- a/modules/juce_cryptography/hashing/juce_MD5.cpp +++ b/modules/juce_cryptography/hashing/juce_MD5.cpp @@ -307,7 +307,7 @@ bool MD5::operator!= (const MD5& other) const noexcept { return ! operator== ( class MD5Tests : public UnitTest { public: - MD5Tests() : UnitTest ("MD5") {} + MD5Tests() : UnitTest ("MD5", "Cryptography") {} void test (const char* input, const char* expected) { diff --git a/modules/juce_cryptography/hashing/juce_SHA256.cpp b/modules/juce_cryptography/hashing/juce_SHA256.cpp index 8d90c9aeb6..4173e4c644 100644 --- a/modules/juce_cryptography/hashing/juce_SHA256.cpp +++ b/modules/juce_cryptography/hashing/juce_SHA256.cpp @@ -240,7 +240,7 @@ bool SHA256::operator!= (const SHA256& other) const noexcept { return ! operato class SHA256Tests : public UnitTest { public: - SHA256Tests() : UnitTest ("SHA-256") {} + SHA256Tests() : UnitTest ("SHA-256", "Cryptography") {} void test (const char* input, const char* expected) { diff --git a/modules/juce_cryptography/hashing/juce_Whirlpool.cpp b/modules/juce_cryptography/hashing/juce_Whirlpool.cpp index 6ece8d7cb0..de4474fbbd 100644 --- a/modules/juce_cryptography/hashing/juce_Whirlpool.cpp +++ b/modules/juce_cryptography/hashing/juce_Whirlpool.cpp @@ -626,7 +626,7 @@ bool Whirlpool::operator!= (const Whirlpool& other) const noexcept { return ! o class WhirlpoolTests : public UnitTest { public: - WhirlpoolTests() : UnitTest ("Whirlpool") {} + WhirlpoolTests() : UnitTest ("Whirlpool", "Cryptography") {} void test (const char* input, const char* expected) { diff --git a/modules/juce_data_structures/values/juce_CachedValue.cpp b/modules/juce_data_structures/values/juce_CachedValue.cpp index c96de9b8bd..b8ecbcc34d 100644 --- a/modules/juce_data_structures/values/juce_CachedValue.cpp +++ b/modules/juce_data_structures/values/juce_CachedValue.cpp @@ -29,7 +29,7 @@ class CachedValueTests : public UnitTest { public: - CachedValueTests() : UnitTest ("CachedValues") {} + CachedValueTests() : UnitTest ("CachedValues", "Values") {} void runTest() override { diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp index 525101871d..afe068d16d 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.cpp +++ b/modules/juce_data_structures/values/juce_ValueTree.cpp @@ -1057,7 +1057,7 @@ void ValueTree::Listener::valueTreeRedirected (ValueTree&) {} class ValueTreeTests : public UnitTest { public: - ValueTreeTests() : UnitTest ("ValueTrees") {} + ValueTreeTests() : UnitTest ("ValueTrees", "Values") {} static String createRandomIdentifier (Random& r) { diff --git a/modules/juce_osc/osc/juce_OSCAddress.cpp b/modules/juce_osc/osc/juce_OSCAddress.cpp index 44312fcd89..888a3f1010 100644 --- a/modules/juce_osc/osc/juce_OSCAddress.cpp +++ b/modules/juce_osc/osc/juce_OSCAddress.cpp @@ -397,7 +397,7 @@ String OSCAddressPattern::toString() const noexcept class OSCAddressTests : public UnitTest { public: - OSCAddressTests() : UnitTest ("OSCAddress class") {} + OSCAddressTests() : UnitTest ("OSCAddress class", "OSC") {} void runTest() { @@ -441,7 +441,7 @@ static OSCAddressTests OSCAddressUnitTests; class OSCAddressPatternTests : public UnitTest { public: - OSCAddressPatternTests() : UnitTest ("OSCAddressPattern class") {} + OSCAddressPatternTests() : UnitTest ("OSCAddressPattern class", "OSC") {} void runTest() { @@ -580,7 +580,7 @@ static OSCAddressPatternTests OSCAddressPatternUnitTests; class OSCPatternMatcherTests : public UnitTest { public: - OSCPatternMatcherTests() : UnitTest ("OSCAddress class / pattern matching") {} + OSCPatternMatcherTests() : UnitTest ("OSCAddress class / pattern matching", "OSC") {} void runTest() { diff --git a/modules/juce_osc/osc/juce_OSCArgument.cpp b/modules/juce_osc/osc/juce_OSCArgument.cpp index 56028aeb0c..1bde638129 100644 --- a/modules/juce_osc/osc/juce_OSCArgument.cpp +++ b/modules/juce_osc/osc/juce_OSCArgument.cpp @@ -88,7 +88,7 @@ const MemoryBlock& OSCArgument::getBlob() const noexcept class OSCArgumentTests : public UnitTest { public: - OSCArgumentTests() : UnitTest ("OSCArgument class") {} + OSCArgumentTests() : UnitTest ("OSCArgument class", "OSC") {} MemoryBlock getMemoryBlockWithRandomData (size_t numBytes) diff --git a/modules/juce_osc/osc/juce_OSCBundle.cpp b/modules/juce_osc/osc/juce_OSCBundle.cpp index ce1b139fd3..d2dcaf1ecf 100644 --- a/modules/juce_osc/osc/juce_OSCBundle.cpp +++ b/modules/juce_osc/osc/juce_OSCBundle.cpp @@ -111,7 +111,7 @@ const OSCBundle& OSCBundle::Element::getBundle() const class OSCBundleTests : public UnitTest { public: - OSCBundleTests() : UnitTest ("OSCBundle class") {} + OSCBundleTests() : UnitTest ("OSCBundle class", "OSC") {} void runTest() { @@ -214,7 +214,7 @@ static OSCBundleTests OSCBundleUnitTests; class OSCBundleElementTests : public UnitTest { public: - OSCBundleElementTests() : UnitTest ("OSCBundle::Element class") {} + OSCBundleElementTests() : UnitTest ("OSCBundle::Element class", "OSC") {} void runTest() { diff --git a/modules/juce_osc/osc/juce_OSCMessage.cpp b/modules/juce_osc/osc/juce_OSCMessage.cpp index 8204cdaf8a..b62b61e8bc 100644 --- a/modules/juce_osc/osc/juce_OSCMessage.cpp +++ b/modules/juce_osc/osc/juce_OSCMessage.cpp @@ -85,7 +85,7 @@ void OSCMessage::addArgument (OSCArgument arg) { arguments.add (arg); } class OSCMessageTests : public UnitTest { public: - OSCMessageTests() : UnitTest ("OSCMessage class") {} + OSCMessageTests() : UnitTest ("OSCMessage class", "OSC") {} void runTest() { diff --git a/modules/juce_osc/osc/juce_OSCReceiver.cpp b/modules/juce_osc/osc/juce_OSCReceiver.cpp index 29150b5570..35da262ef0 100644 --- a/modules/juce_osc/osc/juce_OSCReceiver.cpp +++ b/modules/juce_osc/osc/juce_OSCReceiver.cpp @@ -635,7 +635,7 @@ void OSCReceiver::registerFormatErrorHandler (FormatErrorHandler handler) class OSCInputStreamTests : public UnitTest { public: - OSCInputStreamTests() : UnitTest ("OSCInputStream class") {} + OSCInputStreamTests() : UnitTest ("OSCInputStream class", "OSC") {} void runTest() { diff --git a/modules/juce_osc/osc/juce_OSCSender.cpp b/modules/juce_osc/osc/juce_OSCSender.cpp index 80084c1c71..c0fe39854c 100644 --- a/modules/juce_osc/osc/juce_OSCSender.cpp +++ b/modules/juce_osc/osc/juce_OSCSender.cpp @@ -314,7 +314,7 @@ bool OSCSender::sendToIPAddress (const String& host, int port, const OSCBundle& class OSCBinaryWriterTests : public UnitTest { public: - OSCBinaryWriterTests() : UnitTest ("OSCBinaryWriter class") {} + OSCBinaryWriterTests() : UnitTest ("OSCBinaryWriter class", "OSC") {} void runTest() { @@ -641,7 +641,7 @@ static OSCBinaryWriterTests OSCBinaryWriterUnitTests; class OSCRoundTripTests : public UnitTest { public: - OSCRoundTripTests() : UnitTest ("OSCRoundTripTests class") {} + OSCRoundTripTests() : UnitTest ("OSCRoundTripTests class", "OSC") {} void runTest() { diff --git a/modules/juce_osc/osc/juce_OSCTimeTag.cpp b/modules/juce_osc/osc/juce_OSCTimeTag.cpp index 453b67be4b..35021a2ec8 100644 --- a/modules/juce_osc/osc/juce_OSCTimeTag.cpp +++ b/modules/juce_osc/osc/juce_OSCTimeTag.cpp @@ -80,7 +80,7 @@ bool OSCTimeTag::isImmediately() const noexcept class OSCTimeTagTests : public UnitTest { public: - OSCTimeTagTests() : UnitTest ("OSCTimeTag class") {} + OSCTimeTagTests() : UnitTest ("OSCTimeTag class", "OSC") {} void runTest() {