From edf5cb2c51d88543ac328de82bfe832f5786cb5d Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 28 Sep 2025 15:44:44 -0400 Subject: [PATCH] Enhance EditorIntegrationTest for ImGui Test Engine support - Added conditional compilation for the ImGui Test Engine in `EditorIntegrationTest`, allowing for test registration and engine initialization when enabled. - Updated the constructor and destructor to manage the test engine context appropriately. - Improved the `Initialize` method to include test engine setup and registration, enhancing the integration testing capabilities. - Ensured compatibility with scenarios where the ImGui Test Engine is disabled by providing default implementations for related methods. --- .../editor/editor_integration_test.cc | 18 +++++++++++++++++- .../editor/editor_integration_test.h | 12 +++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/integration/editor/editor_integration_test.cc b/test/integration/editor/editor_integration_test.cc index 20a8852f..6ef82339 100644 --- a/test/integration/editor/editor_integration_test.cc +++ b/test/integration/editor/editor_integration_test.cc @@ -9,22 +9,32 @@ #include "imgui/backends/imgui_impl_sdl2.h" #include "imgui/backends/imgui_impl_sdlrenderer2.h" #include "imgui/imgui.h" + +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE #include "imgui_test_engine/imgui_te_context.h" #include "imgui_test_engine/imgui_te_engine.h" #include "imgui_test_engine/imgui_te_imconfig.h" #include "imgui_test_engine/imgui_te_ui.h" +#endif namespace yaze { namespace test { EditorIntegrationTest::EditorIntegrationTest() - : engine_(nullptr), show_demo_window_(true) {} +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE + : engine_(nullptr), show_demo_window_(true) +#else + +#endif +{} EditorIntegrationTest::~EditorIntegrationTest() { +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE if (engine_) { ImGuiTestEngine_Stop(engine_); ImGuiTestEngine_DestroyContext(engine_); } +#endif } absl::Status EditorIntegrationTest::Initialize() { @@ -33,11 +43,13 @@ absl::Status EditorIntegrationTest::Initialize() { IMGUI_CHECKVERSION(); ImGui::CreateContext(); +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE // Initialize Test Engine engine_ = ImGuiTestEngine_CreateContext(); ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine_); test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info; test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug; +#endif ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; @@ -47,9 +59,11 @@ absl::Status EditorIntegrationTest::Initialize() { controller_.window(), yaze::core::Renderer::Get().renderer()); ImGui_ImplSDLRenderer2_Init(yaze::core::Renderer::Get().renderer()); +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE // Register tests RegisterTests(engine_); ImGuiTestEngine_Start(engine_, ImGui::GetCurrentContext()); +#endif controller_.set_active(true); // Set the default style @@ -83,8 +97,10 @@ int EditorIntegrationTest::RunTest() { absl::Status EditorIntegrationTest::Update() { ImGui::NewFrame(); +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE // Show test engine windows ImGuiTestEngine_ShowTestEngineWindows(engine_, &show_demo_window_); +#endif return absl::OkStatus(); } diff --git a/test/integration/editor/editor_integration_test.h b/test/integration/editor/editor_integration_test.h index 4aa78f31..b06aaa4e 100644 --- a/test/integration/editor/editor_integration_test.h +++ b/test/integration/editor/editor_integration_test.h @@ -7,8 +7,11 @@ #include "app/rom.h" #include "app/core/controller.h" #include "app/core/window.h" + +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE #include "imgui_test_engine/imgui_te_context.h" #include "imgui_test_engine/imgui_te_engine.h" +#endif namespace yaze { namespace test { @@ -39,8 +42,13 @@ class EditorIntegrationTest { // Run the test int RunTest(); +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE // Register tests for a specific editor virtual void RegisterTests(ImGuiTestEngine* engine) = 0; +#else + // Default implementation when ImGui Test Engine is disabled + virtual void RegisterTests(void* engine) {} +#endif // Update the test environment virtual absl::Status Update(); @@ -66,9 +74,11 @@ class EditorIntegrationTest { private: core::Controller controller_; +#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE ImGuiTestEngine* engine_; - std::unique_ptr test_rom_; bool show_demo_window_; +#endif + std::unique_ptr test_rom_; core::Window window_; };