Skip to content

Commit

Permalink
TestSuite: added "misc_recover_1_nested", "misc_recover_2, "misc_reco…
Browse files Browse the repository at this point in the history
…ver_4_midway".
  • Loading branch information
ocornut committed Sep 27, 2024
1 parent c8014ae commit 696513a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion imgui_test_suite/imgui_test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static void TestSuite_PrintCommandLineHelp()
printf(" -nopause : don't pause application on exit.\n");
printf(" -nocapture : don't capture any images or video.\n");
printf(" -stressamount <int> : set performance test duration multiplier (default: 5)\n");
printf(" -fileopener <file> : provide a bat/cmd/shell script to open source file (default to opne with shell).\n");
printf(" -fileopener <file> : provide a bat/cmd/shell script to open source file (default to open with shell).\n");
printf(" -export-file <file> : save test run results in specified file.\n");
printf(" -export-format <format> : save test run results in specified format. (default: junit)\n");
printf(" -list : list queued tests (one per line) and exit.\n");
Expand Down
82 changes: 80 additions & 2 deletions imgui_test_suite/imgui_tests_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,7 @@ void RegisterTests_Layout(ImGuiTestEngine* e)
float y2 = window->DC.CursorPos.y;
ImGui::Text("Another line 5");
IM_CHECK_EQ(y2, y1 + 100.0f + ImGui::GetStyle().ItemSpacing.y);
ImGui::End();
}
#endif
};
Expand Down Expand Up @@ -3863,8 +3864,51 @@ void RegisterTests_Misc(ImGuiTestEngine* e)
};
#endif

// ## Test ErrorCheckEndFrameRecover(), ErrorCheckEndWindowRecover()
t = IM_REGISTER_TEST(e, "misc", "misc_recover");
// ## Test error handling and state recovery logic e.g. ErrorRecoveryTryToRecoverState()
#if IMGUI_VERSION_NUM >= 19123
t = IM_REGISTER_TEST(e, "misc", "misc_recover_1");
t->Flags |= ImGuiTestFlags_NoRecoveryWarnings;
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGui::Begin("Test window", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::PopID();
//ImGui::PopClipRect();
ImGui::PopFocusScope();
ImGui::PopFont();
ImGui::PopItemFlag();
ImGui::PopItemWidth();
ImGui::PopStyleColor();
ImGui::PopStyleVar();
ImGui::PopTextWrapPos();
};

t = IM_REGISTER_TEST(e, "misc", "misc_recover_1_nested");
t->Flags |= ImGuiTestFlags_NoRecoveryWarnings;
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGui::Begin("Parent Window", NULL, ImGuiWindowFlags_NoSavedSettings);

ImGui::Begin("Test window", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::PopID();
//ImGui::PopClipRect();
ImGui::PopFocusScope();
ImGui::PopFont();
ImGui::PopItemFlag();
ImGui::PopItemWidth();
ImGui::PopStyleColor();
ImGui::PopStyleVar();
ImGui::PopTextWrapPos();
};

t = IM_REGISTER_TEST(e, "misc", "misc_recover_2");
t->Flags |= ImGuiTestFlags_NoRecoveryWarnings;
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGui::End();
};
#endif

t = IM_REGISTER_TEST(e, "misc", "misc_recover_3");
t->Flags |= ImGuiTestFlags_NoRecoveryWarnings;
t->GuiFunc = [](ImGuiTestContext* ctx)
{
Expand Down Expand Up @@ -3893,10 +3937,44 @@ void RegisterTests_Misc(ImGuiTestEngine* e)
ImGui::SetNextItemOpen(true);
ImGui::TreeNode("node");
ImGui::BeginTabBar("tabbar");

#if IMGUI_VERSION_NUM >= 19123
ImGui::BeginChild("child", ImVec2(200, 200));
#endif
ImGui::BeginTable("table", 4);
// Ensure we run two frames.
};

// ## Basic way for manual state record/recover
#if IMGUI_VERSION_NUM >= 19123
t = IM_REGISTER_TEST(e, "misc", "misc_recover_4_midway");
t->Flags |= ImGuiTestFlags_NoRecoveryWarnings;
t->GuiFunc = [](ImGuiTestContext* ctx)
{
ImGuiContext& g = *GImGui;
ImGui::Begin("Test window", NULL, ImGuiWindowFlags_NoSavedSettings);
ImGui::PushID("Hello");
ImGui::BeginChild("Child");
ImGui::PushID("Hello2");
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4());

ImGuiErrorRecoveryState state;
ImGui::ErrorRecoveryStoreState(&state);
IM_CHECK_EQ(g.CurrentWindowStack.Size, 3);
IM_CHECK_EQ(g.CurrentWindow->IDStack.Size, 2);
int style_stack_size = g.ColorStack.Size;

ImGui::PushID("World2");
ImGui::BeginChild("Child2");
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 0, 1, 1));
ImGui::ErrorRecoveryTryToRecoverState(&state);

IM_CHECK_EQ(g.CurrentWindowStack.Size, 3);
IM_CHECK_EQ(g.CurrentWindow->IDStack.Size, 2);
IM_CHECK_EQ(g.ColorStack.Size, style_stack_size);
};
#endif

// ## Test window data garbage collection
t = IM_REGISTER_TEST(e, "misc", "misc_gc");
t->GuiFunc = [](ImGuiTestContext* ctx)
Expand Down

0 comments on commit 696513a

Please sign in to comment.