From 53b9bc3f244005ae11764c57dfcf0bd7819ba078 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 29 Jan 2025 20:05:42 +0100 Subject: [PATCH] TestEngine: fix for menu-bar identifier in 1.91.8 wip. --- docs/CHANGELOG.txt | 1 + imgui_test_engine/imgui_te_context.cpp | 9 +++++++- imgui_test_suite/imgui_tests_core.cpp | 18 ++++++++-------- imgui_test_suite/imgui_tests_nav.cpp | 6 +++--- imgui_test_suite/imgui_tests_widgets.cpp | 27 ++++++++++++------------ 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9216525..23db8f5 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -8,6 +8,7 @@ CHANGELOG 2025/01/29: - TestEngine: fixed issue using MenuXXX() functions with a relative path when current SetRef() value is empty. +- TestEngine: fix for menu-bar changes in 1.91.8 wip. 2025/01/20: - TestEngine: added ItemReadAsString() function helpers to facilitate diff --git a/imgui_test_engine/imgui_te_context.cpp b/imgui_test_engine/imgui_te_context.cpp index 4d20aff..6bafed0 100644 --- a/imgui_test_engine/imgui_te_context.cpp +++ b/imgui_test_engine/imgui_te_context.cpp @@ -3380,7 +3380,9 @@ bool ImGuiTestContext::TabBarCompareOrder(ImGuiTabBar* tab_bar, const char** return true; } - +// Automatically insert "##MenuBar" between window and menus. +// Automatically open and navigate sub-menus +// FIXME: Currently assume that any path after the window are sub-menus. void ImGuiTestContext::MenuAction(ImGuiTestAction action, ImGuiTestRef ref) { if (IsError()) @@ -3445,8 +3447,13 @@ void ImGuiTestContext::MenuAction(ImGuiTestAction action, ImGuiTestRef ref) p = path_end; const bool is_target_item = (p == path_end); +#if IMGUI_VERSION_NUM >= 19174 + if (current_window->Flags & ImGuiWindowFlags_MenuBar) + buf.setf("//%s/##MenuBar/%.*s", current_window->Name, (int)(p - path), path); // Click menu in menu bar +#else if (current_window->Flags & ImGuiWindowFlags_MenuBar) buf.setf("//%s/##menubar/%.*s", current_window->Name, (int)(p - path), path); // Click menu in menu bar +#endif else buf.setf("//%s/%.*s", current_window->Name, (int)(p - path), path); // Click sub menu in its own window diff --git a/imgui_test_suite/imgui_tests_core.cpp b/imgui_test_suite/imgui_tests_core.cpp index 196c298..480f4d2 100644 --- a/imgui_test_suite/imgui_tests_core.cpp +++ b/imgui_test_suite/imgui_tests_core.cpp @@ -1050,24 +1050,24 @@ void RegisterTests_Window(ImGuiTestEngine* e) IM_CHECK_EQ(vars.SecondOpen, false); // Test menu opening by hovering a menu item while a menu is already open. - ctx->ItemClick("##menubar/First"); // Click and open first menu. + ctx->ItemClick("##MenuBar/First"); // Click and open first menu. IM_CHECK_EQ(vars.FirstOpen, true); IM_CHECK_EQ(vars.SecondOpen, false); - ctx->MouseMove("##menubar/Second", ImGuiTestOpFlags_NoFocusWindow); // Hover and open second menu. + ctx->MouseMove("##MenuBar/Second", ImGuiTestOpFlags_NoFocusWindow); // Hover and open second menu. IM_CHECK_EQ(vars.FirstOpen, false); IM_CHECK_EQ(vars.SecondOpen, true); - ctx->MouseMove("##menubar/First", ImGuiTestOpFlags_NoFocusWindow); // Hover and open first menu again. + ctx->MouseMove("##MenuBar/First", ImGuiTestOpFlags_NoFocusWindow); // Hover and open first menu again. IM_CHECK_EQ(vars.FirstOpen, true); IM_CHECK_EQ(vars.SecondOpen, false); // Test closing a menu by clicking menu item that opens this menu (#3496). //IM_SUSPEND_TESTFUNC(); - ctx->ItemClick("##menubar/First", 0, ImGuiTestOpFlags_NoFocusWindow); // Click it again to close. + ctx->ItemClick("##MenuBar/First", 0, ImGuiTestOpFlags_NoFocusWindow); // Click it again to close. IM_CHECK_EQ(vars.FirstOpen, false); IM_CHECK_EQ(vars.SecondOpen, false); // Test closing open menu by clicking popup window body. - ctx->ItemClick("##menubar/First"); // Click and open first menu. + ctx->ItemClick("##MenuBar/First"); // Click and open first menu. ctx->MouseSetViewport(popup); ctx->MouseMoveToPos(popup->Rect().GetBR() - ImVec2(20.0f, 20.0f)); // Clicking window outside of menu closes it. ctx->MouseClick(); @@ -1085,7 +1085,7 @@ void RegisterTests_Window(ImGuiTestEngine* e) ctx->WindowMove(popup->ID, window->Rect().GetTR()); // Test closing a menu by clicking popup's parent window body. - ctx->ItemClick("##menubar/First"); // Click and open first menu. + ctx->ItemClick("##MenuBar/First"); // Click and open first menu. ctx->MouseSetViewport(window); ctx->MouseMoveToPos(window->Rect().GetBL() + ImVec2(20.0f, -20.0f)); // Clicking parent window of menu popup closes it. ctx->MouseClick(); @@ -1105,7 +1105,7 @@ void RegisterTests_Window(ImGuiTestEngine* e) ctx->ItemClick("//Test Window/Open Menu Popup"); // Reopen popup if it was closed. // Test closing a menu by clicking on empty space. - ctx->ItemClick("##menubar/First"); // Click and reopen first menu. + ctx->ItemClick("##MenuBar/First"); // Click and reopen first menu. ctx->MouseClickOnVoid(); // Clicking outside of menu closes it. #if IMGUI_BROKEN_TESTS IM_CHECK_EQ(vars.FirstOpen, false); @@ -1422,7 +1422,7 @@ void RegisterTests_Window(ImGuiTestEngine* e) IM_CHECK(window3 != NULL && popup2 != NULL); IM_CHECK_EQ(g.NavWindow, window3); IM_CHECK_EQ(popup2->Active, true); - ctx->ItemClick(Str30f("//%s/##menubar/File", popup2->Name).c_str());// FIXME: MenuClick() does not work well with menus inside of a popup. + ctx->ItemClick(Str30f("//%s/##MenuBar/File", popup2->Name).c_str());// FIXME: MenuClick() does not work well with menus inside of a popup. #ifdef IMGUI_HAS_DOCK ctx->DockInto("Window3", "Interrupts", ImGuiDir_None, false, ImGuiTestOpFlags_NoFocusWindow | ImGuiTestOpFlags_NoError); IM_CHECK(ctx->WindowIsUndockedOrStandalone(window3)); // Can not dock into windows that belong to same begin stack, but are below parent popup @@ -6551,7 +6551,7 @@ void RegisterTests_TestEngine(ImGuiTestEngine* e) { ctx->SetRef("Test Window"); ctx->WindowResize("", ImVec2(50, 200)); - ctx->ItemClick("##menubar/Button"); + ctx->MenuClick("Button"); ctx->WindowResize("", ImVec2(50, 200)); ctx->MenuClick("SECOND_MENU/Item"); }; diff --git a/imgui_test_suite/imgui_tests_nav.cpp b/imgui_test_suite/imgui_tests_nav.cpp index 990142d..4923a72 100644 --- a/imgui_test_suite/imgui_tests_nav.cpp +++ b/imgui_test_suite/imgui_tests_nav.cpp @@ -296,8 +296,8 @@ void RegisterTests_Nav(ImGuiTestEngine* e) IM_CHECK(g.NavLayer == ImGuiNavLayer_Main); ctx->KeyPress(ImGuiMod_Alt); IM_CHECK(g.NavLayer == ImGuiNavLayer_Menu); - const char* menu_item_1 = step == 3 ? "#COLLAPSE" : "##menubar/File"; - const char* menu_item_2 = step == 3 ? "#CLOSE" : "##menubar/Edit"; + const char* menu_item_1 = step == 3 ? "#COLLAPSE" : "##MenuBar/File"; + const char* menu_item_2 = step == 3 ? "#CLOSE" : "##MenuBar/Edit"; IM_CHECK_EQ(g.NavId, ctx->GetID(menu_item_1)); ctx->KeyPress(ImGuiKey_RightArrow); IM_CHECK_EQ(g.NavId, ctx->GetID(menu_item_2)); @@ -1417,7 +1417,7 @@ void RegisterTests_Nav(ImGuiTestEngine* e) ctx->LogDebug("Test variant: in menu"); vars.ShowWindows = vars.SetFocus = vars.MenuLayer = true; ctx->Yield(2); - IM_CHECK_EQ(g.NavId, ctx->GetID("Window/##menubar/Item 2")); + IM_CHECK_EQ(g.NavId, ctx->GetID("Window/##MenuBar/Item 2")); IM_CHECK(g.NavLayer == ImGuiNavLayer_Menu); #endif }; diff --git a/imgui_test_suite/imgui_tests_widgets.cpp b/imgui_test_suite/imgui_tests_widgets.cpp index 3e44dec..3f5fb5d 100644 --- a/imgui_test_suite/imgui_tests_widgets.cpp +++ b/imgui_test_suite/imgui_tests_widgets.cpp @@ -3628,15 +3628,16 @@ void RegisterTests_Widgets(ImGuiTestEngine* e) }; t->TestFunc = [](ImGuiTestContext* ctx) { + // This would likely work with MenuClick("Menu") but going lower-level to ensure we don't mess with focus. auto& vars = ctx->GetVars(); ctx->SetRef("Test Window"); - ctx->ItemClick("##menubar/Menu", 0, ImGuiTestOpFlags_NoFocusWindow); + ctx->ItemClick("##MenuBar/Menu", 0, ImGuiTestOpFlags_NoFocusWindow); IM_CHECK(vars.MenuIsVisible); vars.MenuWasOnceNotVisible = false; - ctx->ItemClick("##menubar/Menu", 0, ImGuiTestOpFlags_NoFocusWindow); + ctx->ItemClick("##MenuBar/Menu", 0, ImGuiTestOpFlags_NoFocusWindow); IM_CHECK(vars.MenuIsVisible == false); IM_CHECK(vars.MenuWasOnceNotVisible); - ctx->ItemClick("##menubar/Menu", 0, ImGuiTestOpFlags_NoFocusWindow); + ctx->ItemClick("##MenuBar/Menu", 0, ImGuiTestOpFlags_NoFocusWindow); IM_CHECK(vars.MenuIsVisible); ctx->SetRef("//$FOCUSED"); @@ -3828,9 +3829,9 @@ void RegisterTests_Widgets(ImGuiTestEngine* e) ctx->SetRef("Test Window"); struct { const char* OpenButton; const char* MenuBase; } test_data[] = { - { NULL, "##menubar" }, // Test from a window menu bar. - { "Open Popup", "##menubar" }, // Test from popup menu bar. - { "Open Modal", "##menubar" }, // Test from modal menu bar. + { NULL, "##MenuBar" }, // Test from a window menu bar. + { "Open Popup", "##MenuBar" }, // Test from popup menu bar. + { "Open Modal", "##MenuBar" }, // Test from modal menu bar. { "Open Menu" , "" }, // Test from popup menu. }; @@ -3892,7 +3893,7 @@ void RegisterTests_Widgets(ImGuiTestEngine* e) IM_CHECK_NE(g.OpenPopupStack.back().OpenParentId, popup_parent_id); // 3. Now do same as 1. except in reverse order. - ctx->MouseMove("##menubar/Examples", ImGuiTestOpFlags_NoFocusWindow | ImGuiTestOpFlags_NoCheckHoveredId); + ctx->MouseMove("##MenuBar/Examples", ImGuiTestOpFlags_NoFocusWindow | ImGuiTestOpFlags_NoCheckHoveredId); IM_CHECK(g.OpenPopupStack.Size == 0); // 4. Clicking another menuset should finally open it. @@ -4135,7 +4136,7 @@ void RegisterTests_Widgets(ImGuiTestEngine* e) { ImGuiContext& g = *ImGui::GetCurrentContext(); - ctx->ItemClick("##MainMenuBar##menubar/Menu 1"); + ctx->MenuClick("##MainMenuBar/Menu 1"); // Click doesn't affect g.NavId which is null at this point @@ -4147,18 +4148,18 @@ void RegisterTests_Widgets(ImGuiTestEngine* e) ctx->KeyPress(ImGuiKey_LeftArrow); IM_CHECK_EQ(g.NavId, ctx->GetID("##Menu_00/Sub Menu 1")); ctx->KeyPress(ImGuiKey_LeftArrow); - IM_CHECK_EQ(g.NavId, ctx->GetID("##MainMenuBar##menubar/Menu 1")); + IM_CHECK_EQ(g.NavId, ctx->GetID("##MainMenuBar##MenuBar/Menu 1")); - ctx->MouseMove("##MainMenuBar##menubar/Menu 2"); // FIXME-TESTS: Workaround so TestEngine can find again Menu 1 + ctx->MouseMove("##MainMenuBar##MenuBar/Menu 2"); // FIXME-TESTS: Workaround so TestEngine can find again Menu 1 // Test forwarding of nav event to parent when there's no match in the current menu // Going from "Menu 1/Sub Menu 1/Item 1" to "Menu 2" - ctx->ItemClick("##MainMenuBar##menubar/Menu 1"); + ctx->ItemClick("##MainMenuBar##MenuBar/Menu 1"); ctx->KeyPress(ImGuiKey_DownArrow); ctx->KeyPress(ImGuiKey_RightArrow); IM_CHECK_EQ(g.NavId, ctx->GetID("##Menu_01/Item 1")); ctx->KeyPress(ImGuiKey_RightArrow); - IM_CHECK_EQ(g.NavId, ctx->GetID("##MainMenuBar##menubar/Menu 2")); + IM_CHECK_EQ(g.NavId, ctx->GetID("##MainMenuBar##MenuBar/Menu 2")); ctx->KeyPress(ImGuiKey_DownArrow); IM_CHECK_EQ(g.NavId, ctx->GetID("##Menu_00/Sub Menu 2-1")); @@ -4228,7 +4229,7 @@ void RegisterTests_Widgets(ImGuiTestEngine* e) #if IMGUI_BROKEN_TESTS ctx->MenuClick("Table/InputText2"); // FIXME-TESTS: This doesn't work because "../Table" in MenuAction doesn't resolve to an item, and even if it did it would try to click it. #else - ctx->ItemClick("##menubar/Table/InputText2"); + ctx->ItemClick("##MenuBar/Table/InputText2"); #endif IM_CHECK_EQ(g.NavLayer, ImGuiNavLayer_Menu); ctx->KeyPress(ImGuiKey_Escape); // Deactivate InputText