Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit test for dynamic view hiding #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 67 additions & 62 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,88 @@ test the installation process. Defaults to off.

]]

cmake_minimum_required (VERSION 3.15 FATAL_ERROR)
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

project (FoleysGUIMagicTests
VERSION ${FGM_VERSION}
DESCRIPTION "Unit tests for the foleys_gui_magic JUCE module"
HOMEPAGE_URL "https://foleysfinest.com/developer/pluginguimagic/"
LANGUAGES CXX)
project(FoleysGUIMagicTests
VERSION ${FGM_VERSION}
DESCRIPTION "Unit tests for the foleys_gui_magic JUCE module"
HOMEPAGE_URL "https://foleysfinest.com/developer/pluginguimagic/"
LANGUAGES CXX)

enable_testing()

# cmake-format: off
# building command-line tools for iOS isn't supported by Apple's SDKs
if (IOS
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL iOS)
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL tvOS)
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL watchOS))
if(PROJECT_IS_TOP_LEVEL)
message (FATAL_ERROR "Building command-line tools for iOS isn't supported by Apple's SDKs;
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL iOS)
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL tvOS)
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL watchOS))

if (PROJECT_IS_TOP_LEVEL)
message(FATAL_ERROR "Building command-line tools for iOS isn't supported by Apple's SDKs;
the foleys_gui_magic unit test executable cannot be crosscompiled for iOS")
endif()
endif ()

return ()
return()
endif ()
# cmake-format: on

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

if (FGM_TEST_INSTALL OR PROJECT_IS_TOP_LEVEL)
set (CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)

find_package(foleys_gui_magic "${PROJECT_VERSION}" EXACT REQUIRED CONFIG)
endif ()

include(FetchContent)

FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG origin/devel)

FetchContent_MakeAvailable(Catch2)

find_package (foleys_gui_magic "${PROJECT_VERSION}" EXACT REQUIRED CONFIG)
if (catch2_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras")
endif ()

include (FetchContent)

FetchContent_Declare (Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG origin/devel)

FetchContent_MakeAvailable (Catch2)

if(catch2_SOURCE_DIR)
list (APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras")
endif()

include (Catch)

juce_add_console_app (FoleysGUIMagicTests VERSION ${FOLEYS_VERSION}
BUNDLE_ID "com.foleysfinest.foleys_gui_magic.tests")

target_sources (FoleysGUIMagicTests PRIVATE
foleys_MagicProcessorTests.cpp
foleys_GuiTreeTests.cpp
foleys_TestProcessors.h)

set_target_properties (
FoleysGUIMagicTests
PROPERTIES LABELS "foleys_gui_magic;Tests"
FOLDER foleys_gui_magic
EchoString "Building the foleys_gui_magic unit test runner..."
MACOSX_BUNDLE OFF)

target_link_libraries (FoleysGUIMagicTests PRIVATE
Catch2::Catch2WithMain
foleys::foleys_gui_magic)

catch_discover_tests (
FoleysGUIMagicTests
TEST_PREFIX foleys_gui_magic.
EXTRA_ARGS
--warn NoAssertions
--order rand
--verbosity high
PROPERTIES
SKIP_REGULAR_EXPRESSION "SKIPPED:"
FAIL_REGULAR_EXPRESSION "FAILED:"
include(Catch)

juce_add_console_app(FoleysGUIMagicTests VERSION ${FOLEYS_VERSION}
BUNDLE_ID "com.foleysfinest.foleys_gui_magic.tests")

target_sources(FoleysGUIMagicTests PRIVATE
foleys_MagicBuilderTests.cpp
foleys_MagicProcessorTests.cpp
foleys_GuiTreeTests.cpp
foleys_TestProcessors.h)

set_target_properties(
FoleysGUIMagicTests
PROPERTIES LABELS "foleys_gui_magic;Tests"
FOLDER foleys_gui_magic
EchoString "Building the foleys_gui_magic unit test runner..."
MACOSX_BUNDLE OFF)

target_link_libraries(FoleysGUIMagicTests PRIVATE
Catch2::Catch2WithMain
foleys::foleys_gui_magic)

target_compile_definitions(FoleysGUIMagicTests
PUBLIC
JUCE_MODAL_LOOPS_PERMITTED=1)

catch_discover_tests(
FoleysGUIMagicTests
TEST_PREFIX foleys_gui_magic.
EXTRA_ARGS
--warn NoAssertions
--order rand
--verbosity high
PROPERTIES
SKIP_REGULAR_EXPRESSION "SKIPPED:"
FAIL_REGULAR_EXPRESSION "FAILED:"
)
24 changes: 11 additions & 13 deletions Tests/foleys_GuiTreeTests.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
==============================================================================
Copyright (c) 2022 Foleys Finest Audio - Daniel Walz
Copyright (c) 2023 Foleys Finest Audio - Daniel Walz
All rights reserved.

License for non-commercial projects:
**BSD 3-Clause License**

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand All @@ -16,10 +16,7 @@
may be used to endorse or promote products derived from this software without
specific prior written permission.

License for commercial products:

To sell commercial products containing this module, you are required to buy a
License from https://foleysfinest.com/developer/pluginguimagic/
==============================================================================

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand All @@ -34,15 +31,16 @@
==============================================================================
*/

#include <foleys_gui_magic/foleys_gui_magic.h>
#include <catch2/catch_test_macros.hpp>


#include "foleys_TestProcessors.h"

#include <catch2/catch_test_macros.hpp>
#include <foleys_gui_magic/foleys_gui_magic.h>

TEST_CASE ("GUI tree test", "[gui]")
{
std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
REQUIRE (editor.get() != nullptr);
const juce::ScopedJuceInitialiser_GUI init;

std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
REQUIRE (editor.get() != nullptr);
}
121 changes: 121 additions & 0 deletions Tests/foleys_MagicBuilderTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
==============================================================================
Copyright (c) 2023 Foleys Finest Audio - Daniel Walz
All rights reserved.

**BSD 3-Clause License**

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

==============================================================================

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
==============================================================================
*/

#include <catch2/catch_test_macros.hpp>
#include <foleys_gui_magic/foleys_gui_magic.h>


TEST_CASE ("GUI builder test", "[gui]")
{
const juce::ScopedJuceInitialiser_GUI init;

class TestComponent : public juce::Component
{
public:
TestComponent()
{
auto tree = juce::ValueTree::fromXml ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"\n"
"<magic>\n"
" <Styles>\n"
" <Style name=\"default\">\n"
" <Nodes/>\n"
" <Classes>\n"
" <hidden flex-grow=\"0\" active=\"HideEditor\">\n"
" <media max-height=\"100000\" max-width=\"100000\"/>\n"
" </hidden>\n"
" </Classes>\n"
" <Palettes>\n"
" <default/>\n"
" </Palettes>\n"
" </Style>\n"
" </Styles>\n"
" <View>\n"
" <View flex-direction=\"column\" caption=\"Hide Test\">\n"
" <View>\n"
" <View/>\n"
" <ToggleButton id=\"hideEditor\" text=\"Hide Editor View\" property=\"HideEditor\"/>\n"
" <View/>\n"
" </View>\n"
" <View>\n"
" <View id=\"editor\" caption=\"Editor View\" class=\"hidden\"/>\n"
" <View caption=\"Performance View\"/>\n"
" </View>\n"
" </View>\n"
" </View>\n"
"</magic>");

state.setGuiValueTree (tree);

builder.registerJUCEFactories();
builder.createGUI (*this);
}

void resized() override { builder.updateLayout(); }

foleys::MagicGUIState state;
foleys::MagicGUIBuilder builder { state };
};

auto testComponent = std::make_unique<TestComponent>();

auto value = testComponent->state.getPropertyAsValue ("HideEditor");
value.setValue (false);

auto flags = juce::ComponentPeer::windowAppearsOnTaskbar | juce::ComponentPeer::windowHasTitleBar;
testComponent->addToDesktop (flags);
testComponent->setVisible (true);

testComponent->setSize (800, 600);

auto* editorItem = testComponent->builder.findGuiItemWithId ("editor");
REQUIRE (editorItem);
REQUIRE (editorItem->getWidth() > 200);
REQUIRE (editorItem->getHeight() > 200);

auto* buttonItem = testComponent->builder.findGuiItemWithId ("hideEditor");
REQUIRE (buttonItem);

auto* button = dynamic_cast<juce::ToggleButton*> (buttonItem->getWrappedComponent());
REQUIRE (button);
REQUIRE (button->getToggleState() == false);

button->triggerClick();

juce::MessageManager::getInstance()->runDispatchLoopUntil (100);

REQUIRE (button->getToggleState() == true);

// Horizontal layout with grow=0 from class hidden should make it zero wide
REQUIRE (editorItem->getWidth() == 0);
}
11 changes: 5 additions & 6 deletions Tests/foleys_MagicProcessorTests.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
==============================================================================
Copyright (c) 2022 Foleys Finest Audio - Daniel Walz
Copyright (c) 2023 Foleys Finest Audio - Daniel Walz
All rights reserved.

License for non-commercial projects:
**BSD 3-Clause License**

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand All @@ -16,10 +16,7 @@
may be used to endorse or promote products derived from this software without
specific prior written permission.

License for commercial products:

To sell commercial products containing this module, you are required to buy a
License from https://foleysfinest.com/developer/pluginguimagic/
==============================================================================

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand All @@ -41,6 +38,8 @@

TEST_CASE ("MagicProcessor test", "[processor]")
{
const juce::ScopedJuceInitialiser_GUI init;

std::unique_ptr<juce::AudioProcessor> processor (new UnitTestProcessor());
std::unique_ptr<juce::AudioProcessorEditor> editor (processor->createEditor());
REQUIRE (editor.get() != nullptr);
Expand Down