sandbox_tstengine.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifdef HELLOIMGUI_WITH_TEST_ENGINE
  2. #include "imgui.h"
  3. #include "hello_imgui/hello_imgui.h"
  4. #include "imgui_test_engine/imgui_te_ui.h"
  5. #include "imgui_test_engine/imgui_te_engine.h"
  6. #include "imgui_test_engine/imgui_te_context.h"
  7. ImGuiTest *test_open_metric, *test_capture_screenshot;
  8. void MyRegisterTests()
  9. {
  10. auto engine = HelloImGui::GetImGuiTestEngine();
  11. //-----------------------------------------------------------------
  12. // ## Open Metrics window
  13. //-----------------------------------------------------------------
  14. test_open_metric = IM_REGISTER_TEST(engine, "demo_tests", "open_metrics");
  15. test_open_metric->TestFunc = [](ImGuiTestContext* ctx)
  16. {
  17. ctx->SetRef("Dear ImGui Demo");
  18. ctx->MenuCheck("Tools/Metrics\\/Debugger");
  19. };
  20. //-----------------------------------------------------------------
  21. // ## Capture entire Dear ImGui Demo window.
  22. //-----------------------------------------------------------------
  23. test_capture_screenshot = IM_REGISTER_TEST(engine, "demo_tests", "capture_screenshot");
  24. test_capture_screenshot->TestFunc = [](ImGuiTestContext* ctx)
  25. {
  26. ctx->SetRef("Dear ImGui Demo");
  27. ctx->ItemOpen("Widgets"); // Open collapsing header
  28. ctx->ItemOpenAll("Basic"); // Open tree node and all its descendant
  29. ctx->CaptureScreenshotWindow("Dear ImGui Demo", ImGuiCaptureFlags_StitchAll | ImGuiCaptureFlags_HideMouseCursor);
  30. };
  31. }
  32. void AppGui()
  33. {
  34. auto engine = HelloImGui::GetImGuiTestEngine();
  35. ImGui::ShowDemoWindow();
  36. ImGuiTestEngine_ShowTestEngineWindows(engine, NULL);
  37. if (ImGui::Button("Run open metric automation"))
  38. ImGuiTestEngine_QueueTest(engine, test_open_metric);
  39. if (ImGui::Button("Run capture screenshot automation"))
  40. ImGuiTestEngine_QueueTest(engine, test_capture_screenshot);
  41. }
  42. int main(int, char**)
  43. {
  44. HelloImGui::RunnerParams runnerParams;
  45. runnerParams.useImGuiTestEngine = true;
  46. runnerParams.callbacks.ShowGui = AppGui;
  47. runnerParams.callbacks.RegisterTests = MyRegisterTests;
  48. HelloImGui::Run(runnerParams);
  49. }
  50. #else // #ifdef HELLOIMGUI_WITH_TEST_ENGINE
  51. int main(int, char**) {}
  52. #endif