Skip to content

Commit 4bd21b0

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

4 files changed

Lines changed: 204 additions & 81 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: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
==============================================================================
3-
Copyright (c) 2022 Foleys Finest Audio - Daniel Walz
3+
Copyright (c) 2023 Foleys Finest Audio - Daniel Walz
44
All rights reserved.
55
6-
License for non-commercial projects:
6+
**BSD 3-Clause License**
77
88
Redistribution and use in source and binary forms, with or without modification,
99
are permitted provided that the following conditions are met:
@@ -16,10 +16,7 @@
1616
may be used to endorse or promote products derived from this software without
1717
specific prior written permission.
1818
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/
19+
==============================================================================
2320
2421
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2522
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -34,15 +31,16 @@
3431
==============================================================================
3532
*/
3633

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

36+
#include <catch2/catch_test_macros.hpp>
37+
#include <foleys_gui_magic/foleys_gui_magic.h>
38+
4339
TEST_CASE ("GUI tree test", "[gui]")
4440
{
45-
std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
46-
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
47-
REQUIRE (editor.get() != nullptr);
41+
const juce::ScopedJuceInitialiser_GUI init;
42+
43+
std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
44+
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
45+
REQUIRE (editor.get() != nullptr);
4846
}

Tests/foleys_MagicBuilderTests.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
==============================================================================
3+
Copyright (c) 2023 Foleys Finest Audio - Daniel Walz
4+
All rights reserved.
5+
6+
**BSD 3-Clause License**
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+
==============================================================================
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30+
OF THE POSSIBILITY OF SUCH DAMAGE.
31+
==============================================================================
32+
*/
33+
34+
#include <catch2/catch_test_macros.hpp>
35+
#include <foleys_gui_magic/foleys_gui_magic.h>
36+
37+
38+
TEST_CASE ("GUI builder test", "[gui]")
39+
{
40+
const juce::ScopedJuceInitialiser_GUI init;
41+
42+
class TestComponent : public juce::Component
43+
{
44+
public:
45+
TestComponent()
46+
{
47+
auto tree = juce::ValueTree::fromXml ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
48+
"\n"
49+
"<magic>\n"
50+
" <Styles>\n"
51+
" <Style name=\"default\">\n"
52+
" <Nodes/>\n"
53+
" <Classes>\n"
54+
" <hidden flex-grow=\"0\" active=\"HideEditor\">\n"
55+
" <media max-height=\"100000\" max-width=\"100000\"/>\n"
56+
" </hidden>\n"
57+
" </Classes>\n"
58+
" <Palettes>\n"
59+
" <default/>\n"
60+
" </Palettes>\n"
61+
" </Style>\n"
62+
" </Styles>\n"
63+
" <View>\n"
64+
" <View flex-direction=\"column\" caption=\"Hide Test\">\n"
65+
" <View>\n"
66+
" <View/>\n"
67+
" <ToggleButton id=\"hideEditor\" text=\"Hide Editor View\" property=\"HideEditor\"/>\n"
68+
" <View/>\n"
69+
" </View>\n"
70+
" <View>\n"
71+
" <View id=\"editor\" caption=\"Editor View\" class=\"hidden\"/>\n"
72+
" <View caption=\"Performance View\"/>\n"
73+
" </View>\n"
74+
" </View>\n"
75+
" </View>\n"
76+
"</magic>");
77+
78+
state.setGuiValueTree (tree);
79+
80+
builder.registerJUCEFactories();
81+
builder.createGUI (*this);
82+
}
83+
84+
void resized() override { builder.updateLayout(); }
85+
86+
foleys::MagicGUIState state;
87+
foleys::MagicGUIBuilder builder { state };
88+
};
89+
90+
auto testComponent = std::make_unique<TestComponent>();
91+
92+
auto value = testComponent->state.getPropertyAsValue ("HideEditor");
93+
value.setValue (false);
94+
95+
auto flags = juce::ComponentPeer::windowAppearsOnTaskbar | juce::ComponentPeer::windowHasTitleBar;
96+
testComponent->addToDesktop (flags);
97+
testComponent->setVisible (true);
98+
99+
testComponent->setSize (800, 600);
100+
101+
auto* editorItem = testComponent->builder.findGuiItemWithId ("editor");
102+
REQUIRE (editorItem);
103+
REQUIRE (editorItem->getWidth() > 200);
104+
REQUIRE (editorItem->getHeight() > 200);
105+
106+
auto* buttonItem = testComponent->builder.findGuiItemWithId ("hideEditor");
107+
REQUIRE (buttonItem);
108+
109+
auto* button = dynamic_cast<juce::ToggleButton*> (buttonItem->getWrappedComponent());
110+
REQUIRE (button);
111+
REQUIRE (button->getToggleState() == false);
112+
113+
button->triggerClick();
114+
115+
juce::MessageManager::getInstance()->runDispatchLoopUntil (100);
116+
117+
REQUIRE (button->getToggleState() == true);
118+
119+
// Horizontal layout with grow=0 from class hidden should make it zero wide
120+
REQUIRE (editorItem->getWidth() == 0);
121+
}

Tests/foleys_MagicProcessorTests.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
==============================================================================
3-
Copyright (c) 2022 Foleys Finest Audio - Daniel Walz
3+
Copyright (c) 2023 Foleys Finest Audio - Daniel Walz
44
All rights reserved.
55
6-
License for non-commercial projects:
6+
**BSD 3-Clause License**
77
88
Redistribution and use in source and binary forms, with or without modification,
99
are permitted provided that the following conditions are met:
@@ -16,10 +16,7 @@
1616
may be used to endorse or promote products derived from this software without
1717
specific prior written permission.
1818
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/
19+
==============================================================================
2320
2421
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2522
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@@ -41,6 +38,8 @@
4138

4239
TEST_CASE ("MagicProcessor test", "[processor]")
4340
{
41+
const juce::ScopedJuceInitialiser_GUI init;
42+
4443
std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
4544
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
4645
REQUIRE (editor.get() != nullptr);

0 commit comments

Comments
 (0)