Skip to content

Commit 8562374

Browse files
committed
Added unit test for dynamic view hiding
1 parent 795f879 commit 8562374

4 files changed

Lines changed: 201 additions & 69 deletions

File tree

Tests/CMakeLists.txt

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,88 @@ test the installation process. Defaults to off.
1111
1212
]]
1313

14-
cmake_minimum_required (VERSION 3.15 FATAL_ERROR)
14+
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
1515

16-
project (FoleysGUIMagicTests
17-
VERSION ${FGM_VERSION}
18-
DESCRIPTION "Unit tests for the foleys_gui_magic JUCE module"
19-
HOMEPAGE_URL "https://foleysfinest.com/developer/pluginguimagic/"
20-
LANGUAGES CXX)
16+
project(FoleysGUIMagicTests
17+
VERSION ${FGM_VERSION}
18+
DESCRIPTION "Unit tests for the foleys_gui_magic JUCE module"
19+
HOMEPAGE_URL "https://foleysfinest.com/developer/pluginguimagic/"
20+
LANGUAGES CXX)
2121

2222
enable_testing()
2323

2424
# cmake-format: off
2525
# building command-line tools for iOS isn't supported by Apple's SDKs
2626
if (IOS
27-
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL iOS)
28-
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL tvOS)
29-
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL watchOS))
30-
31-
if(PROJECT_IS_TOP_LEVEL)
32-
message (FATAL_ERROR "Building command-line tools for iOS isn't supported by Apple's SDKs;
27+
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL iOS)
28+
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL tvOS)
29+
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL watchOS))
30+
31+
if (PROJECT_IS_TOP_LEVEL)
32+
message(FATAL_ERROR "Building command-line tools for iOS isn't supported by Apple's SDKs;
3333
the foleys_gui_magic unit test executable cannot be crosscompiled for iOS")
34-
endif()
34+
endif ()
3535

36-
return ()
36+
return()
3737
endif ()
3838
# cmake-format: on
3939

40-
option (FGM_TEST_INSTALL
41-
"Build the tests against a system install of foleys_gui_magic, instead of the copy in this repo"
42-
"${PROJECT_IS_TOP_LEVEL}")
40+
option(FGM_TEST_INSTALL
41+
"Build the tests against a system install of foleys_gui_magic, instead of the copy in this repo"
42+
"${PROJECT_IS_TOP_LEVEL}")
4343

4444
if (FGM_TEST_INSTALL OR PROJECT_IS_TOP_LEVEL)
45-
set (CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
45+
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
46+
47+
find_package(foleys_gui_magic "${PROJECT_VERSION}" EXACT REQUIRED CONFIG)
48+
endif ()
49+
50+
include(FetchContent)
51+
52+
FetchContent_Declare(Catch2
53+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
54+
GIT_TAG origin/devel)
55+
56+
FetchContent_MakeAvailable(Catch2)
4657

47-
find_package (foleys_gui_magic "${PROJECT_VERSION}" EXACT REQUIRED CONFIG)
58+
if (catch2_SOURCE_DIR)
59+
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras")
4860
endif ()
4961

50-
include (FetchContent)
51-
52-
FetchContent_Declare (Catch2
53-
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
54-
GIT_TAG origin/devel)
55-
56-
FetchContent_MakeAvailable (Catch2)
57-
58-
if(catch2_SOURCE_DIR)
59-
list (APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras")
60-
endif()
61-
62-
include (Catch)
63-
64-
juce_add_console_app (FoleysGUIMagicTests VERSION ${FOLEYS_VERSION}
65-
BUNDLE_ID "com.foleysfinest.foleys_gui_magic.tests")
66-
67-
target_sources (FoleysGUIMagicTests PRIVATE
68-
foleys_MagicProcessorTests.cpp
69-
foleys_GuiTreeTests.cpp
70-
foleys_TestProcessors.h)
71-
72-
set_target_properties (
73-
FoleysGUIMagicTests
74-
PROPERTIES LABELS "foleys_gui_magic;Tests"
75-
FOLDER foleys_gui_magic
76-
EchoString "Building the foleys_gui_magic unit test runner..."
77-
MACOSX_BUNDLE OFF)
78-
79-
target_link_libraries (FoleysGUIMagicTests PRIVATE
80-
Catch2::Catch2WithMain
81-
foleys::foleys_gui_magic)
82-
83-
catch_discover_tests (
84-
FoleysGUIMagicTests
85-
TEST_PREFIX foleys_gui_magic.
86-
EXTRA_ARGS
87-
--warn NoAssertions
88-
--order rand
89-
--verbosity high
90-
PROPERTIES
91-
SKIP_REGULAR_EXPRESSION "SKIPPED:"
92-
FAIL_REGULAR_EXPRESSION "FAILED:"
62+
include(Catch)
63+
64+
juce_add_console_app(FoleysGUIMagicTests VERSION ${FOLEYS_VERSION}
65+
BUNDLE_ID "com.foleysfinest.foleys_gui_magic.tests")
66+
67+
target_sources(FoleysGUIMagicTests PRIVATE
68+
foleys_MagicBuilderTests.cpp
69+
foleys_MagicProcessorTests.cpp
70+
foleys_GuiTreeTests.cpp
71+
foleys_TestProcessors.h)
72+
73+
set_target_properties(
74+
FoleysGUIMagicTests
75+
PROPERTIES LABELS "foleys_gui_magic;Tests"
76+
FOLDER foleys_gui_magic
77+
EchoString "Building the foleys_gui_magic unit test runner..."
78+
MACOSX_BUNDLE OFF)
79+
80+
target_link_libraries(FoleysGUIMagicTests PRIVATE
81+
Catch2::Catch2WithMain
82+
foleys::foleys_gui_magic)
83+
84+
target_compile_definitions(FoleysGUIMagicTests
85+
PUBLIC
86+
JUCE_MODAL_LOOPS_PERMITTED=1)
87+
88+
catch_discover_tests(
89+
FoleysGUIMagicTests
90+
TEST_PREFIX foleys_gui_magic.
91+
EXTRA_ARGS
92+
--warn NoAssertions
93+
--order rand
94+
--verbosity high
95+
PROPERTIES
96+
SKIP_REGULAR_EXPRESSION "SKIPPED:"
97+
FAIL_REGULAR_EXPRESSION "FAILED:"
9398
)

Tests/foleys_GuiTreeTests.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@
3434
==============================================================================
3535
*/
3636

37-
#include <foleys_gui_magic/foleys_gui_magic.h>
38-
#include <catch2/catch_test_macros.hpp>
39-
40-
4137
#include "foleys_TestProcessors.h"
4238

39+
#include <catch2/catch_test_macros.hpp>
40+
#include <foleys_gui_magic/foleys_gui_magic.h>
41+
4342
TEST_CASE ("GUI tree test", "[gui]")
4443
{
45-
std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
46-
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
47-
REQUIRE (editor.get() != nullptr);
44+
const juce::ScopedJuceInitialiser_GUI init;
45+
46+
std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
47+
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
48+
REQUIRE (editor.get() != nullptr);
4849
}

Tests/foleys_MagicBuilderTests.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
==============================================================================
3+
Copyright (c) 2022 Foleys Finest Audio - Daniel Walz
4+
All rights reserved.
5+
6+
License for non-commercial projects:
7+
8+
Redistribution and use in source and binary forms, with or without modification,
9+
are permitted provided that the following conditions are met:
10+
1. Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
3. Neither the name of the copyright holder nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
License for commercial products:
20+
21+
To sell commercial products containing this module, you are required to buy a
22+
License from https://foleysfinest.com/developer/pluginguimagic/
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33+
OF THE POSSIBILITY OF SUCH DAMAGE.
34+
==============================================================================
35+
*/
36+
37+
#include <catch2/catch_test_macros.hpp>
38+
#include <foleys_gui_magic/foleys_gui_magic.h>
39+
40+
41+
TEST_CASE ("GUI builder test", "[gui]")
42+
{
43+
const juce::ScopedJuceInitialiser_GUI init;
44+
45+
class TestComponent : public juce::Component
46+
{
47+
public:
48+
TestComponent()
49+
{
50+
auto tree = juce::ValueTree::fromXml ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
51+
"\n"
52+
"<magic>\n"
53+
" <Styles>\n"
54+
" <Style name=\"default\">\n"
55+
" <Nodes/>\n"
56+
" <Classes>\n"
57+
" <hidden flex-grow=\"0\" active=\"HideEditor\">\n"
58+
" <media max-height=\"100000\" max-width=\"100000\"/>\n"
59+
" </hidden>\n"
60+
" </Classes>\n"
61+
" <Palettes>\n"
62+
" <default/>\n"
63+
" </Palettes>\n"
64+
" </Style>\n"
65+
" </Styles>\n"
66+
" <View>\n"
67+
" <View flex-direction=\"column\" caption=\"Hide Test\">\n"
68+
" <View>\n"
69+
" <View/>\n"
70+
" <ToggleButton id=\"hideEditor\" text=\"Hide Editor View\" property=\"HideEditor\"/>\n"
71+
" <View/>\n"
72+
" </View>\n"
73+
" <View>\n"
74+
" <View id=\"editor\" caption=\"Editor View\" class=\"hidden\"/>\n"
75+
" <View caption=\"Performance View\"/>\n"
76+
" </View>\n"
77+
" </View>\n"
78+
" </View>\n"
79+
"</magic>");
80+
81+
state.setGuiValueTree (tree);
82+
83+
builder.registerJUCEFactories();
84+
builder.createGUI (*this);
85+
}
86+
87+
void resized() override { builder.updateLayout(); }
88+
89+
foleys::MagicGUIState state;
90+
foleys::MagicGUIBuilder builder { state };
91+
};
92+
93+
auto testComponent = std::make_unique<TestComponent>();
94+
95+
auto value = testComponent->state.getPropertyAsValue ("HideEditor");
96+
value.setValue (false);
97+
98+
auto flags = juce::ComponentPeer::windowAppearsOnTaskbar | juce::ComponentPeer::windowHasTitleBar;
99+
testComponent->addToDesktop (flags);
100+
testComponent->setVisible (true);
101+
102+
testComponent->setSize (800, 600);
103+
104+
auto* editorItem = testComponent->builder.findGuiItemWithId ("editor");
105+
REQUIRE (editorItem);
106+
REQUIRE (editorItem->getWidth() > 200);
107+
REQUIRE (editorItem->getHeight() > 200);
108+
109+
auto* buttonItem = testComponent->builder.findGuiItemWithId ("hideEditor");
110+
REQUIRE (buttonItem);
111+
112+
auto* button = dynamic_cast<juce::ToggleButton*> (buttonItem->getWrappedComponent());
113+
REQUIRE (button);
114+
REQUIRE (button->getToggleState() == false);
115+
116+
button->triggerClick();
117+
118+
juce::MessageManager::getInstance()->runDispatchLoopUntil (100);
119+
120+
REQUIRE (bool (value.getValue()) == true);
121+
122+
// Horizontal layout with grow=0 from class hidden should make it zero wide
123+
REQUIRE (editorItem->getWidth() == 0);
124+
}

Tests/foleys_MagicProcessorTests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
TEST_CASE ("MagicProcessor test", "[processor]")
4343
{
44+
const juce::ScopedJuceInitialiser_GUI init;
45+
4446
std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
4547
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
4648
REQUIRE (editor.get() != nullptr);

0 commit comments

Comments
 (0)