Skip to content

Commit

Permalink
TestSuite: amend "widgets_text_unformatted_fastpath" to test for fast…
Browse files Browse the repository at this point in the history
…-path with NULL case.

ocornut/imgui#7016
  • Loading branch information
ocornut committed Nov 22, 2023
1 parent b761410 commit 5d3fc1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 11 additions & 0 deletions imgui_test_suite/imgui_tests_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2902,6 +2902,7 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)

// ## Flex code paths that try to avoid formatting when "%s" is used as format.
// ## Also flex "%.*s" variant (#6846)
// ## Verify case of passing NULL as string (#7016)
t = IM_REGISTER_TEST(e, "widgets", "widgets_text_unformatted_fastpath");
t->GuiFunc = [](ImGuiTestContext* ctx)
{
Expand All @@ -2927,6 +2928,16 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
IM_CHECK_STR_EQ(g.TempBuffer.Data, "STRINGVIEW!");
#endif

#if IMGUI_VERSION_NUM >= 19001
ImGui::LogToClipboard();
ImGui::Text("%s", NULL);
ImGui::Text("%.*s", 3, NULL);
ImGui::Text("%.*s", 9999, NULL);
ImGui::LogFinish();
IM_CHECK_STR_EQ(g.TempBuffer.Data, "STRINGVIEW!");
IM_CHECK_STR_EQ(ImGui::GetClipboardText(), "(null)" IM_NEWLINE "(nu" IM_NEWLINE "(null)" IM_NEWLINE);
#endif

ImGui::End();
};

Expand Down
17 changes: 11 additions & 6 deletions imgui_test_suite/imgui_tests_widgets_inputtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,19 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
ctx->ItemClick("Other"); // This is to ensure stb_textedit_clear_state() gets called (clear the undo buffer, etc.)
ctx->ItemClick("InputText");

#if IMGUI_VERSION_NUM < 19001
int IMSTB_TEXTEDIT_UNDOSTATECOUNT = STB_TEXTEDIT_UNDOSTATECOUNT;
int IMSTB_TEXTEDIT_UNDOCHARCOUNT = STB_TEXTEDIT_UNDOCHARCOUNT;
#endif

ImGuiInputTextState& input_text_state = g.InputTextState;
ImStb::StbUndoState& undo_state = input_text_state.Stb.undostate;
IM_CHECK_EQ(input_text_state.ID, g.ActiveId);
IM_CHECK_EQ(undo_state.undo_point, 0);
IM_CHECK_EQ(undo_state.undo_char_point, 0);
IM_CHECK_EQ(undo_state.redo_point, STB_TEXTEDIT_UNDOSTATECOUNT);
IM_CHECK_EQ(undo_state.redo_char_point, STB_TEXTEDIT_UNDOCHARCOUNT);
IM_CHECK_EQ(STB_TEXTEDIT_UNDOCHARCOUNT, 999); // Test designed for this value
IM_CHECK_EQ(undo_state.redo_point, IMSTB_TEXTEDIT_UNDOSTATECOUNT);
IM_CHECK_EQ(undo_state.redo_char_point, IMSTB_TEXTEDIT_UNDOCHARCOUNT);
IM_CHECK_EQ(IMSTB_TEXTEDIT_UNDOCHARCOUNT, 999); // Test designed for this value

// Insert 350 characters via 10 paste operations
// We use paste operations instead of key-by-key insertion so we know our undo buffer will contains 10 undo points.
Expand All @@ -185,14 +190,14 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
IM_CHECK_EQ(undo_state.undo_char_point, 0);

// Undo x2
IM_CHECK(undo_state.redo_point == STB_TEXTEDIT_UNDOSTATECOUNT);
IM_CHECK(undo_state.redo_point == IMSTB_TEXTEDIT_UNDOSTATECOUNT);
ctx->KeyPress(ImGuiMod_Shortcut | ImGuiKey_Z);
ctx->KeyPress(ImGuiMod_Shortcut | ImGuiKey_Z);
len = (int)strlen(vars.StrLarge.Data);
IM_CHECK_EQ(len, 350 * 2);
IM_CHECK_EQ(undo_state.undo_point, 1);
IM_CHECK_EQ(undo_state.redo_point, STB_TEXTEDIT_UNDOSTATECOUNT - 2);
IM_CHECK_EQ(undo_state.redo_char_point, STB_TEXTEDIT_UNDOCHARCOUNT - 350 * 2);
IM_CHECK_EQ(undo_state.redo_point, IMSTB_TEXTEDIT_UNDOSTATECOUNT - 2);
IM_CHECK_EQ(undo_state.redo_char_point, IMSTB_TEXTEDIT_UNDOCHARCOUNT - 350 * 2);

// Undo x1 should call stb_textedit_discard_redo()
ctx->KeyPress(ImGuiMod_Shortcut | ImGuiKey_Z);
Expand Down

0 comments on commit 5d3fc1f

Please # to comment.