#include #include "XCUIBackend/LegacyImGuiHostInterop.h" #include namespace { using XCEngine::Editor::XCUIBackend::ApplyLegacyImGuiHostInputCapture; using XCEngine::Editor::XCUIBackend::ConfigureLegacyImGuiHostFonts; using XCEngine::Editor::XCUIBackend::CreateLegacyImGuiHostedPreviewPresenter; using XCEngine::Editor::XCUIBackend::CreateLegacyImGuiPanelCanvasHost; using XCEngine::Editor::XCUIBackend::CreateLegacyImGuiWindowUICompositor; using XCEngine::Editor::XCUIBackend::RenderLegacyImGuiDemoWindow; using XCEngine::Editor::XCUIBackend::XCUIInputBridgeFrameSnapshot; class ScopedImGuiContext final { public: ScopedImGuiContext() { IMGUI_CHECKVERSION(); ImGui::CreateContext(); } ~ScopedImGuiContext() { ImGui::DestroyContext(); } ScopedImGuiContext(const ScopedImGuiContext&) = delete; ScopedImGuiContext& operator=(const ScopedImGuiContext&) = delete; }; TEST(LegacyImGuiHostInteropTest, CreatesLegacyHostAdaptersWithExpectedDebugNames) { auto compositor = CreateLegacyImGuiWindowUICompositor(); auto presenter = CreateLegacyImGuiHostedPreviewPresenter(); auto canvasHost = CreateLegacyImGuiPanelCanvasHost(); ASSERT_NE(compositor, nullptr); ASSERT_NE(presenter, nullptr); ASSERT_NE(canvasHost, nullptr); EXPECT_STREQ(canvasHost->GetDebugName(), "ImGuiXCUIPanelCanvasHost"); } TEST(LegacyImGuiHostInteropTest, ApplyInputCaptureCopiesImGuiIoFlagsIntoSnapshot) { ScopedImGuiContext context = {}; ImGuiIO& io = ImGui::GetIO(); io.WantCaptureKeyboard = true; io.WantTextInput = true; XCUIInputBridgeFrameSnapshot snapshot = {}; ApplyLegacyImGuiHostInputCapture(snapshot); EXPECT_TRUE(snapshot.wantCaptureKeyboard); EXPECT_TRUE(snapshot.wantTextInput); } TEST(LegacyImGuiHostInteropTest, ConfigureFontsPopulatesDefaultFont) { ScopedImGuiContext context = {}; ASSERT_TRUE(ConfigureLegacyImGuiHostFonts()); EXPECT_NE(ImGui::GetIO().FontDefault, nullptr); EXPECT_GT(ImGui::GetIO().Fonts->Fonts.Size, 0); } TEST(LegacyImGuiHostInteropTest, RenderDemoWindowSkipsWorkWhenVisibilityIsDisabled) { ScopedImGuiContext context = {}; bool visible = false; EXPECT_FALSE(RenderLegacyImGuiDemoWindow(visible)); EXPECT_FALSE(visible); } } // namespace