Skip to content

Commit 7341b8b

Browse files
committed
TestSuite: amend "widgets_inputtext_callback_misc" and "widgets_inputtext_callback_replace" with undo tests aimed to excercise reconcile code.
for ocornut/imgui#7925
1 parent 604957e commit 7341b8b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

imgui_test_suite/imgui_tests_widgets_inputtext.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,10 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
11151115
ctx->KeyPress(ImGuiKey_Tab);
11161116
IM_CHECK_STR_EQ(vars.CompletionBuffer.c_str(), "Hello World.......................................");
11171117

1118+
// Test undo after callback changes
1119+
ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Z);
1120+
IM_CHECK_STR_EQ(vars.CompletionBuffer.c_str(), "Hello World");
1121+
11181122
// FIXME: Not testing History callback :)
11191123
ctx->ItemClick("History");
11201124
ctx->KeyCharsAppend("ABCDEF");
@@ -1130,6 +1134,12 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
11301134
ctx->KeyPress(ImGuiKey_DownArrow);
11311135
IM_CHECK_STR_EQ(vars.HistoryBuffer.c_str(), "Pressed Down!");
11321136

1137+
// Test undo after callback changes
1138+
ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Z);
1139+
IM_CHECK_STR_EQ(vars.HistoryBuffer.c_str(), "Pressed Up!");
1140+
ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Z);
1141+
IM_CHECK_STR_EQ(vars.HistoryBuffer.c_str(), "ABCD");
1142+
11331143
ctx->ItemClick("Edit");
11341144
IM_CHECK_STR_EQ(vars.EditBuffer.c_str(), "");
11351145
IM_CHECK_EQ(vars.EditCount, 0);
@@ -1162,28 +1172,34 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
11621172
}
11631173
return 0;
11641174
};
1165-
ImGui::InputText("Hello", vars.Str1, IM_ARRAYSIZE(vars.Str1), ImGuiInputTextFlags_CallbackAlways, callback);
1175+
ImGui::InputText("Hello", vars.Str1, IM_ARRAYSIZE(vars.Str1), vars.Bool1 ? ImGuiInputTextFlags_None : ImGuiInputTextFlags_CallbackAlways, callback);
11661176
ImGui::End();
11671177
};
11681178
t->TestFunc = [](ImGuiTestContext* ctx)
11691179
{
1180+
ImGuiTestGenericVars& vars = ctx->GenericVars;
11701181
ctx->SetRef("Test Window");
11711182
ctx->ItemInput("Hello");
11721183
ImGuiInputTextState* state = &ctx->UiContext->InputTextState;
11731184
IM_CHECK(state && state->ID == ctx->GetID("Hello"));
11741185
ctx->KeyCharsAppend("ab");
11751186
IM_CHECK(state->CurLenA == 2);
11761187
IM_CHECK(state->CurLenW == 2);
1177-
IM_CHECK(strcmp(state->TextA.Data, "ab") == 0);
1188+
IM_CHECK_STR_EQ(state->TextA.Data, "ab");
11781189
IM_CHECK(state->Stb->cursor == 2);
11791190
ctx->KeyCharsAppend("c");
11801191
IM_CHECK(state->CurLenA == 3);
11811192
IM_CHECK(state->CurLenW == 1);
1182-
IM_CHECK(strcmp(state->TextA.Data, "\xE5\xA5\xBD") == 0);
1193+
IM_CHECK_STR_EQ(state->TextA.Data, "\xE5\xA5\xBD");
11831194
IM_CHECK(state->TextW.Data[0] == 0x597D);
11841195
IM_CHECK(state->TextW.Data[1] == 0);
11851196
IM_CHECK(state->Stb->cursor == 1);
11861197
IM_CHECK(state->Stb->select_start == 0 && state->Stb->select_end == 1);
1198+
1199+
// Test undo after callback changes
1200+
vars.Bool1 = true; // Disable callback otherwise "abc" after undo will immediately we rewritten
1201+
ctx->KeyPress(ImGuiMod_Ctrl | ImGuiKey_Z);
1202+
IM_CHECK_STR_EQ(state->TextA.Data, "abc");
11871203
};
11881204

11891205
// ## Test resize callback (#3009, #2006, #1443, #1008)

0 commit comments

Comments
 (0)