2026-04-05 16:26:29 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
|
|
#include "XCUIBackend/LegacyImGuiHostInterop.h"
|
|
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-05 17:03:02 +08:00
|
|
|
TEST(LegacyImGuiHostInteropTest, CreatesLegacyHostAdaptersWithExpectedDebugNames) {
|
2026-04-05 16:26:29 +08:00
|
|
|
auto compositor = CreateLegacyImGuiWindowUICompositor();
|
|
|
|
|
auto presenter = CreateLegacyImGuiHostedPreviewPresenter();
|
|
|
|
|
auto canvasHost = CreateLegacyImGuiPanelCanvasHost();
|
|
|
|
|
|
|
|
|
|
ASSERT_NE(compositor, nullptr);
|
|
|
|
|
ASSERT_NE(presenter, nullptr);
|
|
|
|
|
ASSERT_NE(canvasHost, nullptr);
|
2026-04-05 17:03:02 +08:00
|
|
|
EXPECT_STREQ(canvasHost->GetDebugName(), "ImGuiXCUIPanelCanvasHost");
|
2026-04-05 16:26:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|