From e29ad2003245455c095d6e2113260e06e714bbc6 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 24 Jul 2024 14:55:49 -0400 Subject: [PATCH] add Controller::CreateTestContext --- src/app/core/controller.cc | 24 ++++++++++++++++++++++++ src/app/core/controller.h | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index cca8b618..e4d1d116 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -238,6 +239,7 @@ absl::Status Controller::OnEntry(std::string filename) { RETURN_IF_ERROR(CreateSDL_Window()) RETURN_IF_ERROR(CreateRenderer()) RETURN_IF_ERROR(CreateGuiContext()) + RETURN_IF_ERROR(CreateTestContext()) if (flags()->kLoadAudioDevice) { RETURN_IF_ERROR(LoadAudioDevice()) master_editor_.emulator().set_audio_buffer(audio_buffer_); @@ -304,6 +306,8 @@ void Controller::DoRender() const { } void Controller::OnExit() { + ImGuiTestEngine_Stop(engine); + ImGui::DestroyContext(); if (flags()->kLoadAudioDevice) { SDL_PauseAudioDevice(audio_device_, 1); SDL_CloseAudioDevice(audio_device_); @@ -312,6 +316,7 @@ void Controller::OnExit() { ImGui_ImplSDLRenderer2_Shutdown(); ImGui_ImplSDL2_Shutdown(); ImGui::DestroyContext(); + ImGuiTestEngine_DestroyContext(engine); SDL_Quit(); } @@ -396,6 +401,25 @@ absl::Status Controller::CreateGuiContext() { return absl::OkStatus(); } +absl::Status Controller::CreateTestContext() { + // Initialize Test Engine + engine = ImGuiTestEngine_CreateContext(); + ImGuiTestEngineIO &test_io = ImGuiTestEngine_GetIO(engine); + test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info; + test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug; + + // Register your Tests + master_editor_.RegisterTests(engine); + + // Start test engine + ImGuiTestEngine_Start(engine, ImGui::GetCurrentContext()); + + // TODO: Setup with absl signal handler + ImGuiTestEngine_InstallDefaultCrashHandler(); + + return absl::OkStatus(); +} + absl::Status Controller::LoadFontFamilies() const { ImGuiIO &io = ImGui::GetIO(); diff --git a/src/app/core/controller.h b/src/app/core/controller.h index c9c665fe..6ddb2f98 100644 --- a/src/app/core/controller.h +++ b/src/app/core/controller.h @@ -4,9 +4,9 @@ #include #include #include +#include #include #include -#include #include @@ -56,6 +56,7 @@ class Controller : public ExperimentFlags { absl::Status CreateSDL_Window(); absl::Status CreateRenderer(); absl::Status CreateGuiContext(); + absl::Status CreateTestContext(); absl::Status LoadFontFamilies() const; absl::Status LoadAudioDevice(); void CloseWindow() { active_ = false; } @@ -65,6 +66,7 @@ class Controller : public ExperimentFlags { bool active_; int audio_frequency_ = 48000; int16_t *audio_buffer_; + ImGuiTestEngine *engine; editor::MasterEditor master_editor_; SDL_AudioDeviceID audio_device_; std::shared_ptr window_;