Add TestEditor class and integration test setup for ImGui; implement basic UI elements and test registration functionality.
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
#include "test/integration/test_editor.h"
|
||||
|
||||
#include <SDL.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 {
|
||||
namespace test {
|
||||
|
||||
absl::Status TestEditor::Update() {
|
||||
ImGui::NewFrame();
|
||||
if (ImGui::Begin("My Window")) {
|
||||
ImGui::Text("Hello, world!");
|
||||
ImGui::Button("My Button");
|
||||
}
|
||||
|
||||
static bool show_demo_window = true;
|
||||
|
||||
ImGuiTestEngine_ShowTestEngineWindows(engine_, &show_demo_window);
|
||||
|
||||
ImGui::End();
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void TestEditor::RegisterTests(ImGuiTestEngine* engine) {
|
||||
engine_ = engine;
|
||||
ImGuiTest* test = IM_REGISTER_TEST(engine, "demo_test", "test1");
|
||||
test->TestFunc = [](ImGuiTestContext* ctx) {
|
||||
ctx->SetRef("My Window");
|
||||
ctx->ItemClick("My Button");
|
||||
ctx->ItemCheck("Node/Checkbox");
|
||||
};
|
||||
}
|
||||
|
||||
int RunIntegrationTest() {
|
||||
yaze::core::Controller controller;
|
||||
if (!controller.CreateWindow().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::core::Renderer::GetInstance().renderer());
|
||||
ImGui_ImplSDLRenderer2_Init(yaze::core::Renderer::GetInstance().renderer());
|
||||
|
||||
yaze::test::TestEditor test_editor;
|
||||
test_editor.RegisterTests(engine);
|
||||
ImGuiTestEngine_Start(engine, ImGui::GetCurrentContext());
|
||||
controller.set_active(true);
|
||||
|
||||
// Set the default style
|
||||
yaze::gui::ColorsYaze();
|
||||
|
||||
// Build a new ImGui frame
|
||||
ImGui_ImplSDLRenderer2_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
|
||||
while (controller.IsActive()) {
|
||||
controller.OnInput();
|
||||
test_editor.Update();
|
||||
controller.DoRender();
|
||||
}
|
||||
|
||||
ImGuiTestEngine_Stop(engine);
|
||||
controller.OnExit();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace yaze
|
||||
@@ -1,61 +0,0 @@
|
||||
#ifndef YAZE_TEST_INTEGRATION_TEST_EDITOR_H
|
||||
#define YAZE_TEST_INTEGRATION_TEST_EDITOR_H
|
||||
|
||||
#include "app/editor/editor.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui_test_engine/imgui_te_context.h"
|
||||
#include "imgui_test_engine/imgui_te_engine.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace test {
|
||||
|
||||
class TestEditor : public yaze::editor::Editor {
|
||||
public:
|
||||
TestEditor() = default;
|
||||
~TestEditor() = default;
|
||||
void Initialize() override {
|
||||
|
||||
}
|
||||
|
||||
absl::Status Cut() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
absl::Status Copy() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
absl::Status Paste() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
|
||||
absl::Status Undo() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
absl::Status Redo() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
|
||||
absl::Status Find() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
|
||||
absl::Status Update() override;
|
||||
|
||||
absl::Status Save() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
absl::Status Load() override {
|
||||
return absl::UnimplementedError("Not implemented");
|
||||
}
|
||||
|
||||
void RegisterTests(ImGuiTestEngine* engine);
|
||||
|
||||
private:
|
||||
ImGuiTestEngine* engine_;
|
||||
};
|
||||
|
||||
int RunIntegrationTest();
|
||||
|
||||
} // namespace test
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_TEST_INTEGRATION_TEST_EDITOR_H
|
||||
Reference in New Issue
Block a user