3#if defined(YAZE_ENABLE_IMGUI_TEST_ENGINE) && YAZE_ENABLE_IMGUI_TEST_ENGINE
8#if __has_include("imgui_test_engine/imgui_te_context.h")
9#include "imgui_test_engine/imgui_te_context.h"
10#elif __has_include("imgui_te_context.h")
11#include "imgui_te_context.h"
13#error "ImGui Test Engine context header not found"
16#if __has_include("imgui_test_engine/imgui_te_engine.h")
17#include "imgui_test_engine/imgui_te_engine.h"
18#elif __has_include("imgui_te_engine.h")
19#include "imgui_te_engine.h"
21#error "ImGui Test Engine engine header not found"
28void EnsureTile16PanelOpenAndFocused(ImGuiTestContext* ctx) {
29 ctx->SetRef(
"Tile16 Editor");
30 if (ctx->GetWindowByRef(
"") ==
nullptr) {
31 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_T);
35 ctx->SetRef(
"Tile16 Editor");
36 IM_CHECK(ctx->GetWindowByRef(
"") !=
nullptr);
41void ExpectActiveQuadrant(ImGuiTestContext* ctx,
const char* label) {
42 const std::string pattern = std::string(
"**/Active ") + label +
":*";
43 IM_CHECK(ctx->ItemExists(pattern.c_str()));
46void ExpectBrushPalette(ImGuiTestContext* ctx,
int palette) {
47 const std::string pattern =
48 std::string(
"**/*Brush Palette: ") + std::to_string(palette) +
"*";
49 IM_CHECK(ctx->ItemExists(pattern.c_str()));
67static void RegisterKeyboardShortcutTests(ImGuiTestEngine* engine) {
71 IM_REGISTER_TEST(engine,
"overworld_keys",
"mouse_mode_key_1");
72 test->TestFunc = [](ImGuiTestContext* ctx) {
73 ctx->KeyPress(ImGuiKey_1);
81 IM_REGISTER_TEST(engine,
"overworld_keys",
"draw_mode_key_2");
82 test->TestFunc = [](ImGuiTestContext* ctx) {
83 ctx->KeyPress(ImGuiKey_2);
86 ctx->KeyPress(ImGuiKey_1);
94 IM_REGISTER_TEST(engine,
"overworld_keys",
"brush_toggle_key_b");
95 test->TestFunc = [](ImGuiTestContext* ctx) {
96 ctx->KeyPress(ImGuiKey_B);
99 ctx->KeyPress(ImGuiKey_B);
107 IM_REGISTER_TEST(engine,
"overworld_keys",
"fill_tool_key_f");
108 test->TestFunc = [](ImGuiTestContext* ctx) {
109 ctx->KeyPress(ImGuiKey_F);
112 ctx->KeyPress(ImGuiKey_F);
120 IM_REGISTER_TEST(engine,
"overworld_keys",
"eyedropper_key_i");
121 test->TestFunc = [](ImGuiTestContext* ctx) {
122 ctx->KeyPress(ImGuiKey_I);
130 IM_REGISTER_TEST(engine,
"overworld_keys",
"lock_toggle_ctrl_l");
131 test->TestFunc = [](ImGuiTestContext* ctx) {
132 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_L);
135 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_L);
143 IM_REGISTER_TEST(engine,
"overworld_keys",
"fullscreen_toggle_f11");
144 test->TestFunc = [](ImGuiTestContext* ctx) {
145 ctx->KeyPress(ImGuiKey_F11);
148 ctx->KeyPress(ImGuiKey_F11);
156 IM_REGISTER_TEST(engine,
"overworld_keys",
"undo_no_crash");
157 test->TestFunc = [](ImGuiTestContext* ctx) {
158 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Z);
166 IM_REGISTER_TEST(engine,
"overworld_keys",
"redo_no_crash");
167 test->TestFunc = [](ImGuiTestContext* ctx) {
168 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Y);
176 IM_REGISTER_TEST(engine,
"overworld_keys",
"tile16_editor_ctrl_t");
177 test->TestFunc = [](ImGuiTestContext* ctx) {
178 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_T);
181 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_T);
188 ImGuiTest* test = IM_REGISTER_TEST(engine,
"overworld_keys",
189 "tile16_quadrant_hotkeys_apply_focus");
190 test->TestFunc = [](ImGuiTestContext* ctx) {
191 EnsureTile16PanelOpenAndFocused(ctx);
193 struct QuadrantStep {
197 const QuadrantStep steps[] = {
204 for (
const auto& step : steps) {
205 ctx->KeyPress(step.key);
207 ExpectActiveQuadrant(ctx, step.label);
210 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_T);
217 ImGuiTest* test = IM_REGISTER_TEST(
218 engine,
"overworld_keys",
"tile16_ctrl_numeric_hotkeys_palette_rows");
219 test->TestFunc = [](ImGuiTestContext* ctx) {
220 EnsureTile16PanelOpenAndFocused(ctx);
222 ctx->KeyPress(ImGuiKey_4);
224 ExpectActiveQuadrant(ctx,
"BR");
226 for (
int palette = 0; palette < 8; ++palette) {
227 const ImGuiKey number_key =
static_cast<ImGuiKey
>(ImGuiKey_1 + palette);
228 ctx->KeyPress(ImGuiMod_Ctrl | number_key);
230 ExpectBrushPalette(ctx, palette);
231 ExpectActiveQuadrant(ctx,
"BR");
234 ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_T);
248static void RegisterEntityModeTests(ImGuiTestEngine* engine) {
252 IM_REGISTER_TEST(engine,
"overworld_entity",
"mode_keys_3_to_8");
253 test->TestFunc = [](ImGuiTestContext* ctx) {
255 ctx->KeyPress(ImGuiKey_3);
257 ctx->KeyPress(ImGuiKey_4);
259 ctx->KeyPress(ImGuiKey_5);
261 ctx->KeyPress(ImGuiKey_6);
263 ctx->KeyPress(ImGuiKey_7);
265 ctx->KeyPress(ImGuiKey_8);
268 ctx->KeyPress(ImGuiKey_1);
281static void RegisterModeRoundTripTests(ImGuiTestEngine* engine) {
285 IM_REGISTER_TEST(engine,
"overworld_modes",
"full_mode_cycle");
286 test->TestFunc = [](ImGuiTestContext* ctx) {
288 ctx->KeyPress(ImGuiKey_1);
292 ctx->KeyPress(ImGuiKey_2);
296 ctx->KeyPress(ImGuiKey_F);
300 ctx->KeyPress(ImGuiKey_B);
304 ctx->KeyPress(ImGuiKey_B);
308 ctx->KeyPress(ImGuiKey_1);
316 IM_REGISTER_TEST(engine,
"overworld_modes",
"rapid_mode_switch");
317 test->TestFunc = [](ImGuiTestContext* ctx) {
318 for (
int i = 0; i < 10; ++i) {
319 ctx->KeyPress(ImGuiKey_B);
323 ctx->KeyPress(ImGuiKey_1);
342static void RegisterCanvasNavigationTests(ImGuiTestEngine* engine) {
346 IM_REGISTER_TEST(engine,
"overworld_canvas",
"idle_frames_stable");
347 test->TestFunc = [](ImGuiTestContext* ctx) {
363static void RegisterWorldSelectorTests(ImGuiTestEngine* engine) {
367 IM_REGISTER_TEST(engine,
"overworld_toolbar",
"toolbar_renders_stable");
368 test->TestFunc = [](ImGuiTestContext* ctx) {
382 if (engine ==
nullptr)
384 RegisterKeyboardShortcutTests(engine);
385 RegisterEntityModeTests(engine);
386 RegisterModeRoundTripTests(engine);
387 RegisterCanvasNavigationTests(engine);
388 RegisterWorldSelectorTests(engine);
void RegisterOverworldUITests(ImGuiTestEngine *)