Skip to content

Commit 7634b31

Browse files
committed
TestEngine: Added ItemExists() helper.
1 parent 60c9a2f commit 7634b31

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ CHANGELOG
55
Those changes are not all listed here.
66
** For a while this is going to ONLY INCLUDE BREAKING CHANGES.
77

8+
2023/03/28:
9+
- TestEngine: Added ItemExists() helper.
10+
811
2023/03/14:
912
- TestEngine: Fixed GatherItems() max-depth test being off-by-1 (regression in 2023/03/06 update).
1013

imgui_test_engine/imgui_te_context.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,15 +2890,23 @@ void ImGuiTestContext::ItemDragWithDelta(ImGuiTestRef ref_src, ImVec2 pos_del
28902890
MouseUp(0);
28912891
}
28922892

2893+
bool ImGuiTestContext::ItemExists(ImGuiTestRef ref)
2894+
{
2895+
ImGuiTestItemInfo* item = ItemInfo(ref, ImGuiTestOpFlags_NoError);
2896+
return item->ID != 0;
2897+
}
2898+
28932899
void ImGuiTestContext::ItemVerifyCheckedIfAlive(ImGuiTestRef ref, bool checked)
28942900
{
2901+
// This is designed to deal with disappearing items which will not update their state,
2902+
// e.g. a checkable menu item in a popup which closes when checked.
2903+
// Otherwise ItemInfo() data is preserved for an additional frame.
28952904
Yield();
28962905
ImGuiTestItemInfo* item = ItemInfo(ref, ImGuiTestOpFlags_NoError);
28972906
if (item->ID == 0)
28982907
return;
28992908
if (item->TimestampMain + 1 >= ImGuiTestEngine_GetFrameCount(Engine) && item->TimestampStatus == item->TimestampMain)
2900-
if (((item->StatusFlags & ImGuiItemStatusFlags_Checked) != 0) != checked)
2901-
IM_CHECK(((item->StatusFlags & ImGuiItemStatusFlags_Checked) != 0) == checked);
2909+
IM_CHECK_SILENT(((item->StatusFlags & ImGuiItemStatusFlags_Checked) != 0) == checked);
29022910
}
29032911

29042912
// FIXME-TESTS: Could this be handled by ItemClose()?

imgui_test_engine/imgui_te_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ struct IMGUI_API ImGuiTestContext
426426
void ItemDragWithDelta(ImGuiTestRef ref_src, ImVec2 pos_delta);
427427

428428
// Helpers for Item/Widget state query
429+
bool ItemExists(ImGuiTestRef ref);
429430
void ItemVerifyCheckedIfAlive(ImGuiTestRef ref, bool checked);
430431

431432
// Helpers for Tab Bars widgets

0 commit comments

Comments
 (0)