Skip to content

Commit

Permalink
Add unit tests for debugger plugin shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Jun 8, 2022
1 parent a07bee2 commit 35b1132
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ file(GLOB UnitTests_HDR_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Source/UnitTests/*.h )
file(GLOB UnitTests_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Source/UnitTests/*.cpp )

add_executable(UnitTests ${UnitTests_HDR_FILES} ${UnitTests_SRC_FILES})
target_link_libraries(UnitTests RmlCore doctest::doctest trompeloeil::trompeloeil ${sample_LIBRARIES})
target_link_libraries(UnitTests RmlCore RmlDebugger doctest::doctest trompeloeil::trompeloeil ${sample_LIBRARIES})
add_common_target_options(UnitTests)

if(MSVC)
Expand Down
22 changes: 15 additions & 7 deletions Tests/Source/Common/TestsShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace {
const Rml::Vector2i window_size(1500, 800);

bool shell_initialized = false;
bool debugger_allowed = true;
int num_documents_begin = 0;
Rml::Context* shell_context = nullptr;

Expand All @@ -70,12 +71,13 @@ namespace {
#endif
} // namespace

static void InitializeShell()
static void InitializeShell(bool allow_debugger)
{
// Initialize shell and create context.
if (!shell_initialized)
{
shell_initialized = true;
debugger_allowed = allow_debugger;
REQUIRE(Shell::Initialize());

#ifdef RMLUI_TESTS_USE_SHELL
Expand All @@ -91,8 +93,11 @@ namespace {
shell_context = Rml::CreateContext("main", window_size);
Shell::LoadFonts();

Rml::Debugger::Initialise(shell_context);
num_documents_begin = shell_context->GetNumDocuments();
if (allow_debugger)
{
Rml::Debugger::Initialise(shell_context);
num_documents_begin = shell_context->GetNumDocuments();
}

shell_context->GetRootElement()->AddEventListener(Rml::EventId::Keydown, &shell_event_listener, true);

Expand All @@ -109,9 +114,9 @@ namespace {
}


Rml::Context* TestsShell::GetContext()
Rml::Context* TestsShell::GetContext(bool allow_debugger)
{
InitializeShell();
InitializeShell(allow_debugger);
return shell_context;
}

Expand Down Expand Up @@ -153,8 +158,11 @@ void TestsShell::ShutdownShell()
{
if (shell_initialized)
{
RMLUI_ASSERTMSG(shell_context->GetNumDocuments() == num_documents_begin, "Make sure all previously opened documents have been closed.");
(void)num_documents_begin;
if (debugger_allowed)
{
RMLUI_ASSERTMSG(shell_context->GetNumDocuments() == num_documents_begin, "Make sure all previously opened documents have been closed.");
(void)num_documents_begin;
}

tests_system_interface.SetNumExpectedWarnings(0);

Expand Down
2 changes: 1 addition & 1 deletion Tests/Source/Common/TestsShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Rml { class RenderInterface; }
namespace TestsShell {

// Will initialize the shell and create a context on first use.
Rml::Context* GetContext();
Rml::Context* GetContext(bool allow_debugger = true);

void BeginFrame();
void PresentFrame();
Expand Down
84 changes: 84 additions & 0 deletions Tests/Source/UnitTests/Debugger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* This source file is part of RmlUi, the HTML/CSS Interface Middleware
*
* For the latest information, see http://github.com/mikke89/RmlUi
*
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
* Copyright (c) 2019 The RmlUi Team, and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#include "../Common/TestsShell.h"
#include <RmlUi/Core/Context.h>
#include <RmlUi/Core/Core.h>
#include <RmlUi/Core/ElementDocument.h>
#include <RmlUi/Debugger.h>
#include <algorithm>
#include <doctest.h>

using namespace Rml;

TEST_CASE("debugger")
{
Context* context = TestsShell::GetContext(false);

SUBCASE("no_shutdown")
{
Rml::Debugger::Initialise(context);

ElementDocument* document = context->LoadDocument("assets/demo.rml");
TestsShell::RenderLoop();

document->Close();
TestsShell::RenderLoop();
}

SUBCASE("shutdown")
{
Rml::Debugger::Initialise(context);

ElementDocument* document = context->LoadDocument("assets/demo.rml");
TestsShell::RenderLoop();

document->Close();
TestsShell::RenderLoop();

Rml::Debugger::Shutdown();
TestsShell::RenderLoop();
}

SUBCASE("shutdown_early")
{
ElementDocument* document = context->LoadDocument("assets/demo.rml");
TestsShell::RenderLoop();

Rml::Debugger::Initialise(context);
TestsShell::RenderLoop();

Rml::Debugger::Shutdown();
TestsShell::RenderLoop();

document->Close();
TestsShell::RenderLoop();
}

TestsShell::ShutdownShell();
}

0 comments on commit 35b1132

Please sign in to comment.