mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-05 03:50:07 +00:00
Restructure OpenGLDemo and UnitTestsDemo and remove unused macro from DemoRunner
This commit is contained in:
parent
aa498afce2
commit
d6fb474c39
5 changed files with 809 additions and 821 deletions
|
|
@ -80,50 +80,50 @@
|
|||
|
||||
void registerDemos_One() noexcept
|
||||
{
|
||||
REGISTER_DEMO (AudioAppDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioLatencyDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioPlaybackDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioRecordingDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioSettingsDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioSynthesiserDemo, Audio, false)
|
||||
REGISTER_DEMO (MidiDemo, Audio, false)
|
||||
REGISTER_DEMO (MPEDemo, Audio, false)
|
||||
REGISTER_DEMO (PluckedStringsDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioAppDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioLatencyDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioPlaybackDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioRecordingDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioSettingsDemo, Audio, false)
|
||||
REGISTER_DEMO (AudioSynthesiserDemo, Audio, false)
|
||||
REGISTER_DEMO (MidiDemo, Audio, false)
|
||||
REGISTER_DEMO (MPEDemo, Audio, false)
|
||||
REGISTER_DEMO (PluckedStringsDemo, Audio, false)
|
||||
|
||||
#if JUCE_HAS_CONSTEXPR
|
||||
REGISTER_DEMO (SimpleFFTDemo, Audio, false)
|
||||
REGISTER_DEMO (BlocksDrawingDemo, BLOCKS, false)
|
||||
REGISTER_DEMO (BlocksMonitorDemo, BLOCKS, false)
|
||||
REGISTER_DEMO (BlocksSynthDemo, BLOCKS, false)
|
||||
REGISTER_DEMO (SimpleFFTDemo, Audio, false)
|
||||
REGISTER_DEMO (BlocksDrawingDemo, BLOCKS, false)
|
||||
REGISTER_DEMO (BlocksMonitorDemo, BLOCKS, false)
|
||||
REGISTER_DEMO (BlocksSynthDemo, BLOCKS, false)
|
||||
|
||||
REGISTER_DEMO (ConvolutionDemo, DSP, false)
|
||||
REGISTER_DEMO (FIRFilterDemo, DSP, false)
|
||||
REGISTER_DEMO (GainDemo, DSP, false)
|
||||
REGISTER_DEMO (IIRFilterDemo, DSP, false)
|
||||
REGISTER_DEMO (OscillatorDemo, DSP, false)
|
||||
REGISTER_DEMO (OverdriveDemo, DSP, false)
|
||||
REGISTER_DEMO (ConvolutionDemo, DSP, false)
|
||||
REGISTER_DEMO (FIRFilterDemo, DSP, false)
|
||||
REGISTER_DEMO (GainDemo, DSP, false)
|
||||
REGISTER_DEMO (IIRFilterDemo, DSP, false)
|
||||
REGISTER_DEMO (OscillatorDemo, DSP, false)
|
||||
REGISTER_DEMO (OverdriveDemo, DSP, false)
|
||||
#if JUCE_USE_SIMD
|
||||
REGISTER_DEMO (SIMDRegisterDemo, DSP, false)
|
||||
REGISTER_DEMO (SIMDRegisterDemo, DSP, false)
|
||||
#endif
|
||||
REGISTER_DEMO (StateVariableFilterDemo, DSP, false)
|
||||
REGISTER_DEMO (WaveShaperTanhDemo, DSP, false)
|
||||
REGISTER_DEMO (StateVariableFilterDemo, DSP, false)
|
||||
REGISTER_DEMO (WaveShaperTanhDemo, DSP, false)
|
||||
#endif
|
||||
|
||||
REGISTER_DEMO (Box2DDemo, Utilities, false)
|
||||
REGISTER_DEMO (Box2DDemo, Utilities, false)
|
||||
#if JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX
|
||||
REGISTER_DEMO (ChildProcessDemo, Utilities, false)
|
||||
REGISTER_DEMO (ChildProcessDemo, Utilities, false)
|
||||
#endif
|
||||
REGISTER_DEMO (CryptographyDemo, Utilities, false)
|
||||
REGISTER_DEMO (JavaScriptDemo, Utilities, false)
|
||||
REGISTER_DEMO (LiveConstantDemo, Utilities, false)
|
||||
REGISTER_DEMO (MultithreadingDemo, Utilities, false)
|
||||
REGISTER_DEMO (NetworkingDemo, Utilities, false)
|
||||
REGISTER_DEMO (OSCDemo, Utilities, false)
|
||||
REGISTER_DEMO (SystemInfoDemo, Utilities, false)
|
||||
REGISTER_DEMO (TimersAndEventsDemo, Utilities, false)
|
||||
REGISTER_DEMO_WITH_FILENAME (UnitTestClasses::UnitTestsDemo, Utilities, UnitTestsDemo, false)
|
||||
REGISTER_DEMO (ValueTreesDemo, Utilities, false)
|
||||
REGISTER_DEMO (XMLandJSONDemo, Utilities, false)
|
||||
REGISTER_DEMO (CryptographyDemo, Utilities, false)
|
||||
REGISTER_DEMO (JavaScriptDemo, Utilities, false)
|
||||
REGISTER_DEMO (LiveConstantDemo, Utilities, false)
|
||||
REGISTER_DEMO (MultithreadingDemo, Utilities, false)
|
||||
REGISTER_DEMO (NetworkingDemo, Utilities, false)
|
||||
REGISTER_DEMO (OSCDemo, Utilities, false)
|
||||
REGISTER_DEMO (SystemInfoDemo, Utilities, false)
|
||||
REGISTER_DEMO (TimersAndEventsDemo, Utilities, false)
|
||||
REGISTER_DEMO (UnitTestsDemo, Utilities, false)
|
||||
REGISTER_DEMO (ValueTreesDemo, Utilities, false)
|
||||
REGISTER_DEMO (XMLandJSONDemo, Utilities, false)
|
||||
}
|
||||
|
||||
Component* createIntroDemo()
|
||||
|
|
|
|||
|
|
@ -70,42 +70,42 @@
|
|||
|
||||
void registerDemos_Two() noexcept
|
||||
{
|
||||
REGISTER_DEMO (AnimationAppDemo, GUI, false)
|
||||
REGISTER_DEMO (AnimationDemo, GUI, false)
|
||||
REGISTER_DEMO (BouncingBallWavetableDemo, GUI, false)
|
||||
REGISTER_DEMO (AnimationAppDemo, GUI, false)
|
||||
REGISTER_DEMO (AnimationDemo, GUI, false)
|
||||
REGISTER_DEMO (BouncingBallWavetableDemo, GUI, false)
|
||||
#if JUCE_USE_CAMERA && ! JUCE_LINUX
|
||||
REGISTER_DEMO (CameraDemo, GUI, true)
|
||||
REGISTER_DEMO (CameraDemo, GUI, true)
|
||||
#endif
|
||||
#if ! JUCE_ANDROID
|
||||
REGISTER_DEMO (CodeEditorDemo, GUI, false)
|
||||
REGISTER_DEMO (CodeEditorDemo, GUI, false)
|
||||
#endif
|
||||
REGISTER_DEMO (ComponentDemo, GUI, false)
|
||||
REGISTER_DEMO (ComponentTransformsDemo, GUI, false)
|
||||
REGISTER_DEMO (DialogsDemo, GUI, false)
|
||||
REGISTER_DEMO (FlexBoxDemo, GUI, false)
|
||||
REGISTER_DEMO (FontsDemo, GUI, false)
|
||||
REGISTER_DEMO (GraphicsDemo, GUI, false)
|
||||
REGISTER_DEMO (ComponentDemo, GUI, false)
|
||||
REGISTER_DEMO (ComponentTransformsDemo, GUI, false)
|
||||
REGISTER_DEMO (DialogsDemo, GUI, false)
|
||||
REGISTER_DEMO (FlexBoxDemo, GUI, false)
|
||||
REGISTER_DEMO (FontsDemo, GUI, false)
|
||||
REGISTER_DEMO (GraphicsDemo, GUI, false)
|
||||
#if JUCE_HAS_CONSTEXPR
|
||||
REGISTER_DEMO (GridDemo, GUI, false)
|
||||
REGISTER_DEMO (GridDemo, GUI, false)
|
||||
#endif
|
||||
REGISTER_DEMO (ImagesDemo, GUI, false)
|
||||
REGISTER_DEMO (KeyMappingsDemo, GUI, false)
|
||||
REGISTER_DEMO (LookAndFeelDemo, GUI, false)
|
||||
REGISTER_DEMO (MDIDemo, GUI, false)
|
||||
REGISTER_DEMO (MenusDemo, GUI, false)
|
||||
REGISTER_DEMO (MultiTouchDemo, GUI, false)
|
||||
REGISTER_DEMO (ImagesDemo, GUI, false)
|
||||
REGISTER_DEMO (KeyMappingsDemo, GUI, false)
|
||||
REGISTER_DEMO (LookAndFeelDemo, GUI, false)
|
||||
REGISTER_DEMO (MDIDemo, GUI, false)
|
||||
REGISTER_DEMO (MenusDemo, GUI, false)
|
||||
REGISTER_DEMO (MultiTouchDemo, GUI, false)
|
||||
#if JUCE_OPENGL
|
||||
REGISTER_DEMO (OpenGLAppDemo, GUI, true)
|
||||
REGISTER_DEMO (OpenGLDemo2D, GUI, true)
|
||||
REGISTER_DEMO_WITH_FILENAME (OpenGLDemoClasses::OpenGLDemo, GUI, OpenGLDemo, true)
|
||||
REGISTER_DEMO (OpenGLAppDemo, GUI, true)
|
||||
REGISTER_DEMO (OpenGLDemo2D, GUI, true)
|
||||
REGISTER_DEMO (OpenGLDemo, GUI, true)
|
||||
#endif
|
||||
REGISTER_DEMO (PropertiesDemo, GUI, false)
|
||||
REGISTER_DEMO (PropertiesDemo, GUI, false)
|
||||
#if ! JUCE_LINUX
|
||||
REGISTER_DEMO (VideoDemo, GUI, true)
|
||||
REGISTER_DEMO (VideoDemo, GUI, true)
|
||||
#endif
|
||||
REGISTER_DEMO (WebBrowserDemo, GUI, true)
|
||||
REGISTER_DEMO (WidgetsDemo, GUI, false)
|
||||
REGISTER_DEMO (WindowsDemo, GUI, false)
|
||||
REGISTER_DEMO (WebBrowserDemo, GUI, true)
|
||||
REGISTER_DEMO (WidgetsDemo, GUI, false)
|
||||
REGISTER_DEMO (WindowsDemo, GUI, false)
|
||||
}
|
||||
|
||||
CodeEditorComponent::ColourScheme getDarkColourScheme()
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
#define CREATE_FILEPATH(DemoName, category) JUCE_STRINGIFY(EXPAND(category)/EXPAND(DemoName)EXPAND(FILE_EXT))
|
||||
|
||||
#define REGISTER_DEMO(DemoName, category, heavyweight) JUCEDemos::registerDemo ([] { return new DemoName(); }, CREATE_FILEPATH(DemoName, category), JUCE_STRINGIFY (category), heavyweight);
|
||||
#define REGISTER_DEMO_WITH_FILENAME(DemoName, category, fileName, heavyweight) JUCEDemos::registerDemo ([] { return new DemoName(); }, CREATE_FILEPATH(fileName, category), JUCE_STRINGIFY (category), heavyweight);
|
||||
|
||||
//==============================================================================
|
||||
struct JUCEDemos
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -40,7 +40,7 @@
|
|||
defines: JUCE_UNIT_TESTS=1
|
||||
|
||||
type: Component
|
||||
mainClass: UnitTestClasses::UnitTestsDemo
|
||||
mainClass: UnitTestsDemo
|
||||
|
||||
useLocalCopy: 1
|
||||
|
||||
|
|
@ -53,35 +53,98 @@
|
|||
#include "../Assets/DemoUtilities.h"
|
||||
|
||||
//==============================================================================
|
||||
struct UnitTestClasses
|
||||
class UnitTestsDemo : public Component
|
||||
{
|
||||
class UnitTestsDemo;
|
||||
class TestRunnerThread;
|
||||
public:
|
||||
UnitTestsDemo()
|
||||
{
|
||||
setOpaque (true);
|
||||
|
||||
addAndMakeVisible (startTestButton);
|
||||
startTestButton.onClick = [this] { start(); };
|
||||
|
||||
addAndMakeVisible (testResultsBox);
|
||||
testResultsBox.setMultiLine (true);
|
||||
testResultsBox.setFont (Font (Font::getDefaultMonospacedFontName(), 12.0f, Font::plain));
|
||||
|
||||
addAndMakeVisible (categoriesBox);
|
||||
categoriesBox.addItem ("All Tests", 1);
|
||||
|
||||
auto categories = UnitTest::getAllCategories();
|
||||
categories.sort (true);
|
||||
|
||||
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.");
|
||||
|
||||
setSize (500, 500);
|
||||
}
|
||||
|
||||
~UnitTestsDemo()
|
||||
{
|
||||
stopTest();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// This subclass of UnitTestRunner is used to redirect the test output to our
|
||||
// TextBox, and to interrupt the running tests when our thread is asked to stop..
|
||||
class CustomTestRunner : public UnitTestRunner
|
||||
void paint (Graphics& g) override
|
||||
{
|
||||
public:
|
||||
CustomTestRunner (TestRunnerThread& trt) : owner (trt) {}
|
||||
g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
|
||||
Colours::grey));
|
||||
}
|
||||
|
||||
void logMessage (const String& message) override
|
||||
void resized() override
|
||||
{
|
||||
auto bounds = getLocalBounds().reduced (6);
|
||||
|
||||
auto topSlice = bounds.removeFromTop (25);
|
||||
startTestButton.setBounds (topSlice.removeFromLeft (200));
|
||||
topSlice.removeFromLeft (10);
|
||||
categoriesBox .setBounds (topSlice.removeFromLeft (250));
|
||||
|
||||
bounds.removeFromTop (5);
|
||||
testResultsBox.setBounds (bounds);
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
startTest (categoriesBox.getText());
|
||||
}
|
||||
|
||||
void startTest (const String& category)
|
||||
{
|
||||
testResultsBox.clear();
|
||||
startTestButton.setEnabled (false);
|
||||
|
||||
currentTestThread.reset (new TestRunnerThread (*this, category));
|
||||
currentTestThread->startThread();
|
||||
}
|
||||
|
||||
void stopTest()
|
||||
{
|
||||
if (currentTestThread.get() != nullptr)
|
||||
{
|
||||
owner.logMessage (message);
|
||||
currentTestThread->stopThread (15000);
|
||||
currentTestThread.reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool shouldAbortTests() override
|
||||
{
|
||||
return owner.threadShouldExit();
|
||||
}
|
||||
void logMessage (const String& message)
|
||||
{
|
||||
testResultsBox.moveCaretToEnd();
|
||||
testResultsBox.insertTextAtCaret (message + newLine);
|
||||
testResultsBox.moveCaretToEnd();
|
||||
}
|
||||
|
||||
private:
|
||||
TestRunnerThread& owner;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomTestRunner)
|
||||
};
|
||||
void testFinished()
|
||||
{
|
||||
stopTest();
|
||||
startTestButton.setEnabled (true);
|
||||
logMessage (newLine + "*** Tests finished ***");
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
class TestRunnerThread : public Thread,
|
||||
private Timer
|
||||
|
|
@ -121,117 +184,45 @@ struct UnitTestClasses
|
|||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
// This subclass of UnitTestRunner is used to redirect the test output to our
|
||||
// TextBox, and to interrupt the running tests when our thread is asked to stop..
|
||||
class CustomTestRunner : public UnitTestRunner
|
||||
{
|
||||
public:
|
||||
CustomTestRunner (TestRunnerThread& trt) : owner (trt) {}
|
||||
|
||||
void logMessage (const String& message) override
|
||||
{
|
||||
owner.logMessage (message);
|
||||
}
|
||||
|
||||
bool shouldAbortTests() override
|
||||
{
|
||||
return owner.threadShouldExit();
|
||||
}
|
||||
|
||||
private:
|
||||
TestRunnerThread& owner;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomTestRunner)
|
||||
};
|
||||
|
||||
UnitTestsDemo& owner;
|
||||
const String category;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TestRunnerThread)
|
||||
};
|
||||
std::unique_ptr<TestRunnerThread> currentTestThread;
|
||||
|
||||
TextButton startTestButton { "Run Unit Tests..." };
|
||||
ComboBox categoriesBox;
|
||||
TextEditor testResultsBox;
|
||||
|
||||
//==============================================================================
|
||||
class UnitTestsDemo : public Component
|
||||
void lookAndFeelChanged() override
|
||||
{
|
||||
public:
|
||||
UnitTestsDemo()
|
||||
{
|
||||
setOpaque (true);
|
||||
testResultsBox.applyFontToAllText (testResultsBox.getFont());
|
||||
}
|
||||
|
||||
addAndMakeVisible (startTestButton);
|
||||
startTestButton.onClick = [this] { start(); };
|
||||
|
||||
addAndMakeVisible (testResultsBox);
|
||||
testResultsBox.setMultiLine (true);
|
||||
testResultsBox.setFont (Font (Font::getDefaultMonospacedFontName(), 12.0f, Font::plain));
|
||||
|
||||
addAndMakeVisible (categoriesBox);
|
||||
categoriesBox.addItem ("All Tests", 1);
|
||||
|
||||
auto categories = UnitTest::getAllCategories();
|
||||
categories.sort (true);
|
||||
|
||||
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.");
|
||||
|
||||
setSize (500, 500);
|
||||
}
|
||||
|
||||
~UnitTestsDemo()
|
||||
{
|
||||
stopTest();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void paint (Graphics& g) override
|
||||
{
|
||||
g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground,
|
||||
Colours::grey));
|
||||
}
|
||||
|
||||
void resized() override
|
||||
{
|
||||
auto bounds = getLocalBounds().reduced (6);
|
||||
|
||||
auto topSlice = bounds.removeFromTop (25);
|
||||
startTestButton.setBounds (topSlice.removeFromLeft (200));
|
||||
topSlice.removeFromLeft (10);
|
||||
categoriesBox .setBounds (topSlice.removeFromLeft (250));
|
||||
|
||||
bounds.removeFromTop (5);
|
||||
testResultsBox.setBounds (bounds);
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
startTest (categoriesBox.getText());
|
||||
}
|
||||
|
||||
void startTest (const String& category)
|
||||
{
|
||||
testResultsBox.clear();
|
||||
startTestButton.setEnabled (false);
|
||||
|
||||
currentTestThread.reset (new TestRunnerThread (*this, category));
|
||||
currentTestThread->startThread();
|
||||
}
|
||||
|
||||
void stopTest()
|
||||
{
|
||||
if (currentTestThread.get() != nullptr)
|
||||
{
|
||||
currentTestThread->stopThread (15000);
|
||||
currentTestThread.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void logMessage (const String& message)
|
||||
{
|
||||
testResultsBox.moveCaretToEnd();
|
||||
testResultsBox.insertTextAtCaret (message + newLine);
|
||||
testResultsBox.moveCaretToEnd();
|
||||
}
|
||||
|
||||
void testFinished()
|
||||
{
|
||||
stopTest();
|
||||
startTestButton.setEnabled (true);
|
||||
logMessage (newLine + "*** Tests finished ***");
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<TestRunnerThread> currentTestThread;
|
||||
|
||||
TextButton startTestButton { "Run Unit Tests..." };
|
||||
ComboBox categoriesBox;
|
||||
TextEditor testResultsBox;
|
||||
|
||||
void lookAndFeelChanged() override
|
||||
{
|
||||
testResultsBox.applyFontToAllText (testResultsBox.getFont());
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UnitTestsDemo)
|
||||
};
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UnitTestsDemo)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue