chore: Refactor test_editor and yaze_test for better code organization and readability

This commit is contained in:
scawful
2024-08-24 23:36:47 -04:00
parent b2b3056ddd
commit b1f231612d
3 changed files with 61 additions and 64 deletions

View File

@@ -1,8 +1,14 @@
#include "test/integration/test_editor.h"
#include "app/core/controller.h"
#include "app/core/platform/renderer.h"
#include "app/gui/style.h"
#include "imgui/backends/imgui_impl_sdl2.h"
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
#include "imgui/imgui.h"
#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"
namespace yaze {
@@ -35,6 +41,58 @@ void TestEditor::RegisterTests(ImGuiTestEngine* engine) {
};
}
int RunIntegrationTest() {
yaze::test::integration::TestEditor test_editor;
yaze::app::core::Controller controller;
controller.init_test_editor(&test_editor);
if (!controller.CreateSDL_Window().ok()) {
return EXIT_FAILURE;
}
if (!controller.CreateRenderer().ok()) {
return EXIT_FAILURE;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
// Initialize Test Engine
ImGuiTestEngine* engine = ImGuiTestEngine_CreateContext();
ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine);
test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info;
test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug;
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
// Initialize ImGui for SDL
ImGui_ImplSDL2_InitForSDLRenderer(
controller.window(), yaze::app::core::Renderer::GetInstance().renderer());
ImGui_ImplSDLRenderer2_Init(
yaze::app::core::Renderer::GetInstance().renderer());
test_editor.RegisterTests(engine);
ImGuiTestEngine_Start(engine, ImGui::GetCurrentContext());
controller.set_active(true);
// Set the default style
yaze::app::gui::ColorsYaze();
// Build a new ImGui frame
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
while (controller.IsActive()) {
controller.OnInput();
if (const auto status = controller.OnTestLoad(); !status.ok()) {
return EXIT_FAILURE;
}
controller.DoRender();
}
ImGuiTestEngine_Stop(engine);
controller.OnExit();
}
} // namespace integration
} // namespace test
} // namespace yaze

View File

@@ -44,6 +44,8 @@ class TestEditor : public yaze::app::editor::Editor {
ImGuiTestEngine* engine_;
};
int RunIntegrationTest();
} // namespace integration
} // namespace test
} // namespace yaze

View File

@@ -7,15 +7,6 @@
#include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/symbolize.h"
#include "app/core/controller.h"
#include "app/core/platform/renderer.h"
#include "app/gui/style.h"
#include "imgui/backends/imgui_impl_sdl2.h"
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
#include "imgui/imgui.h"
#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 "test/integration/test_editor.h"
namespace yaze {
@@ -36,62 +27,8 @@ int main(int argc, char* argv[]) {
absl::FailureSignalHandlerOptions options;
absl::InstallFailureSignalHandler(options);
// Check if the argument says `integration`
if (argc > 1 && std::string(argv[1]) == "integration") {
// Support the ability to launch an integration test window.
// SDL_SetMainReady();
yaze::test::integration::TestEditor test_editor;
yaze::app::core::Controller controller;
controller.init_test_editor(&test_editor);
if (!controller.CreateSDL_Window().ok()) {
return EXIT_FAILURE;
}
if (!controller.CreateRenderer().ok()) {
return EXIT_FAILURE;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
// Initialize Test Engine
ImGuiTestEngine* engine = ImGuiTestEngine_CreateContext();
ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine);
test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info;
test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug;
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
// Initialize ImGui for SDL
ImGui_ImplSDL2_InitForSDLRenderer(
controller.window(),
yaze::app::core::Renderer::GetInstance().renderer());
ImGui_ImplSDLRenderer2_Init(
yaze::app::core::Renderer::GetInstance().renderer());
test_editor.RegisterTests(engine);
ImGuiTestEngine_Start(engine, ImGui::GetCurrentContext());
controller.set_active(true);
// Set the default style
yaze::app::gui::ColorsYaze();
// Build a new ImGui frame
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
while (controller.IsActive()) {
controller.OnInput();
if (const auto status = controller.OnTestLoad(); !status.ok()) {
return EXIT_FAILURE;
}
controller.DoRender();
}
ImGuiTestEngine_Stop(engine);
controller.OnExit();
return EXIT_SUCCESS;
return yaze::test::integration::RunIntegrationTest();
}
::testing::InitGoogleTest(&argc, argv);