Browse Source

Add unit tests for debugger plugin shutdown

Michael Ragazzon 3 years ago
parent
commit
35b1132d7d

+ 1 - 1
Tests/CMakeLists.txt

@@ -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 )
 file(GLOB UnitTests_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Source/UnitTests/*.cpp )
 
 
 add_executable(UnitTests ${UnitTests_HDR_FILES} ${UnitTests_SRC_FILES})
 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)
 add_common_target_options(UnitTests)
 
 
 if(MSVC)
 if(MSVC)

+ 15 - 7
Tests/Source/Common/TestsShell.cpp

@@ -44,6 +44,7 @@ namespace {
 	const Rml::Vector2i window_size(1500, 800);
 	const Rml::Vector2i window_size(1500, 800);
 
 
 	bool shell_initialized = false;
 	bool shell_initialized = false;
+	bool debugger_allowed = true;
 	int num_documents_begin = 0;
 	int num_documents_begin = 0;
 	Rml::Context* shell_context = nullptr;
 	Rml::Context* shell_context = nullptr;
 
 
@@ -70,12 +71,13 @@ namespace {
 #endif
 #endif
 } // namespace
 } // namespace
 
 
-	static void InitializeShell()
+	static void InitializeShell(bool allow_debugger)
 	{
 	{
 		// Initialize shell and create context.
 		// Initialize shell and create context.
 		if (!shell_initialized)
 		if (!shell_initialized)
 		{
 		{
 			shell_initialized = true;
 			shell_initialized = true;
+			debugger_allowed = allow_debugger;
 			REQUIRE(Shell::Initialize());
 			REQUIRE(Shell::Initialize());
 
 
 #ifdef RMLUI_TESTS_USE_SHELL
 #ifdef RMLUI_TESTS_USE_SHELL
@@ -91,8 +93,11 @@ namespace {
 			shell_context = Rml::CreateContext("main", window_size);
 			shell_context = Rml::CreateContext("main", window_size);
 			Shell::LoadFonts();
 			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);
 			shell_context->GetRootElement()->AddEventListener(Rml::EventId::Keydown, &shell_event_listener, true);
 
 
@@ -109,9 +114,9 @@ namespace {
 	}
 	}
 
 
 
 
-Rml::Context* TestsShell::GetContext()
+Rml::Context* TestsShell::GetContext(bool allow_debugger)
 {
 {
-	InitializeShell();
+	InitializeShell(allow_debugger);
 	return shell_context;
 	return shell_context;
 }
 }
 
 
@@ -153,8 +158,11 @@ void TestsShell::ShutdownShell()
 {
 {
 	if (shell_initialized)
 	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);
 		tests_system_interface.SetNumExpectedWarnings(0);
 
 

+ 1 - 1
Tests/Source/Common/TestsShell.h

@@ -35,7 +35,7 @@ namespace Rml { class RenderInterface; }
 namespace TestsShell {
 namespace TestsShell {
 
 
 	// Will initialize the shell and create a context on first use.
 	// Will initialize the shell and create a context on first use.
-	Rml::Context* GetContext();
+	Rml::Context* GetContext(bool allow_debugger = true);
 
 
 	void BeginFrame();
 	void BeginFrame();
 	void PresentFrame();
 	void PresentFrame();

+ 84 - 0
Tests/Source/UnitTests/Debugger.cpp

@@ -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();
+}