Skip to content

Commit 58d95ac

Browse files
committed
TestSuite: amend "widgets_status_inputtext", "widgets_inputtext_temp_buffer" to test buffer write-back on multilne during the IsItemDeactivatedAfterEdit() frame.
ocornut/imgui#9308
1 parent 81e103f commit 58d95ac

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎imgui_test_suite/imgui_tests_widgets.cpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,10 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
10341034
if (is_enter_keep_active)
10351035
continue;
10361036
#endif
1037+
#if IMGUI_VERSION_NUM < 19266
10371038
if (is_temp_apply_on_deactivate)
10381039
continue; // Unsupported yet (#9308)
1040+
#endif
10391041
if (is_enter_keep_active && is_multiline)
10401042
continue; // Unsupported yet
10411043

@@ -1083,7 +1085,10 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
10831085
IM_CHECK(status.RetValue != 0 && status.Activated && !status.Deactivated && !status.DeactivatedAfterEdit && status.Edited >= 1);
10841086
status.Clear();
10851087
ctx->KeyPress(ImGuiKey_Tab);
1086-
IM_CHECK(status.RetValue == 0 && !status.Activated && status.Deactivated && status.DeactivatedAfterEdit && status.Edited == 0);
1088+
if (!is_temp_apply_on_deactivate)
1089+
IM_CHECK(status.RetValue == 0 && !status.Activated && status.Deactivated && status.DeactivatedAfterEdit && status.Edited == 0);
1090+
else
1091+
IM_CHECK(status.RetValue >= 1 && !status.Activated && status.Deactivated && status.DeactivatedAfterEdit && status.Edited >= 1);
10871092
IM_CHECK_STR_EQ(vars.Str1, "Hello World");
10881093
status.Clear();
10891094

@@ -1093,7 +1098,10 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
10931098
IM_CHECK(status.RetValue != 0 && status.Activated && !status.Deactivated && !status.DeactivatedAfterEdit && status.Edited >= 1);
10941099
status.Clear();
10951100
ctx->ItemClick("Sibling");
1096-
IM_CHECK(status.RetValue == 0 && !status.Activated && status.Deactivated && status.DeactivatedAfterEdit && status.Edited == 0);
1101+
if (!is_temp_apply_on_deactivate)
1102+
IM_CHECK(status.RetValue == 0 && !status.Activated && status.Deactivated && status.DeactivatedAfterEdit && status.Edited == 0);
1103+
else
1104+
IM_CHECK(status.RetValue >= 1 && !status.Activated && status.Deactivated && status.DeactivatedAfterEdit && status.Edited >= 1);
10971105
IM_CHECK_STR_EQ(vars.Str1, "123");
10981106
status.Clear();
10991107
}

‎imgui_test_suite/imgui_tests_widgets_inputtext.cpp‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,9 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
15221522
int& i_stored = vars.Int1;
15231523
int& i_tmp = vars.Int2;
15241524
i_tmp = i_stored;
1525+
1526+
const bool is_multiline = (vars.Step % 4) == 2;
1527+
15251528
if (ImGui::InputInt("Field1", &i_tmp))
15261529
if (ImGui::IsItemDeactivatedAfterEdit())
15271530
i_stored = i_tmp;
@@ -1530,7 +1533,13 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
15301533
char* s_tmp = vars.Str2;
15311534
int s_bufsize = IM_COUNTOF(vars.Str1);
15321535
memcpy(s_tmp, s_stored, s_bufsize);
1533-
if (ImGui::InputText("Field2", s_tmp, s_bufsize, vars.InputTextFlags))
1536+
1537+
bool ret;
1538+
if (is_multiline)
1539+
ret = ImGui::InputTextMultiline("Field2", s_tmp, s_bufsize, { 0,0 }, vars.InputTextFlags);
1540+
else
1541+
ret = ImGui::InputText("Field2", s_tmp, s_bufsize, vars.InputTextFlags);
1542+
if (ret)
15341543
if (ImGui::IsItemDeactivatedAfterEdit())
15351544
memcpy(s_stored, s_tmp, s_bufsize);
15361545

@@ -1541,13 +1550,16 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
15411550
auto& vars = ctx->GenericVars;
15421551
ctx->SetRef("Test Window");
15431552

1544-
for (int step = 0; step < 2; step++)
1553+
for (int step = 0; step < 4; step++)
15451554
{
1555+
const bool is_enter_keep_active = (step % 2) == 1;
1556+
const bool is_multiline = (step % 4) == 2;
15461557
#if IMGUI_VERSION_NUM < 19264
1547-
if (step == 1)
1558+
if (is_enter_keep_active)
15481559
continue;
15491560
#endif
1550-
ImGui::GetIO().ConfigInputTextEnterKeepActive = (step == 1);
1561+
ImGui::GetIO().ConfigInputTextEnterKeepActive = is_enter_keep_active;
1562+
vars.Step = step;
15511563
ctx->Yield();
15521564

15531565
int& i_stored = vars.Int1;
@@ -1573,10 +1585,23 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
15731585
char* s_stored = vars.Str1;
15741586
char* s_tmp = vars.Str2;
15751587
ctx->ItemClick("Field2");
1576-
15771588
const char* s_step1 = (n == 0 || n == 1) ? "abc" : "";
1578-
ctx->KeyCharsReplaceEnter(s_step1);
1589+
ctx->KeyCharsReplace(s_step1);
1590+
ctx->KeyPress(is_multiline ? ImGuiMod_Ctrl | ImGuiKey_Enter : ImGuiKey_Enter);
15791591
IM_CHECK_STR_EQ(s_stored, s_step1);
1592+
1593+
// Testing with Tab as it takes the deactivation path (#9308, #8915)
1594+
#if IMGUI_VERSION_NUM >= 19266
1595+
ctx->ItemClick("Field2");
1596+
ctx->KeyCharsReplace("eee");
1597+
IM_CHECK_STR_EQ(s_stored, s_step1);
1598+
IM_CHECK_STR_EQ(s_tmp, "eee");
1599+
ctx->KeyPress(ImGuiKey_Tab);
1600+
IM_CHECK_STR_EQ(s_stored, "eee");
1601+
IM_CHECK_STR_EQ(s_tmp, "eee");
1602+
strcpy(s_stored, s_step1);
1603+
#endif
1604+
15801605
ctx->ItemClick("Field2");
15811606
ctx->KeyCharsReplace("fff");
15821607
IM_CHECK_STR_EQ(s_stored, s_step1);

0 commit comments

Comments
 (0)
⌂ 换网址