Hide ImGui compat factories behind legacy XCUI interop
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Platform/D3D12WindowRenderer.h"
|
||||
#include "XCUIBackend/IEditorHostCompositor.h"
|
||||
#include "XCUIBackend/ImGuiWindowUICompositor.h"
|
||||
#include "XCUIBackend/UITextureRegistration.h"
|
||||
|
||||
78
tests/NewEditor/test_legacy_imgui_host_interop.cpp
Normal file
78
tests/NewEditor/test_legacy_imgui_host_interop.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#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::XCUIPanelCanvasHostBackend;
|
||||
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, CreatesLegacyHostAdaptersWithImGuiBackends) {
|
||||
auto compositor = CreateLegacyImGuiWindowUICompositor();
|
||||
auto presenter = CreateLegacyImGuiHostedPreviewPresenter();
|
||||
auto canvasHost = CreateLegacyImGuiPanelCanvasHost();
|
||||
|
||||
ASSERT_NE(compositor, nullptr);
|
||||
ASSERT_NE(presenter, nullptr);
|
||||
ASSERT_NE(canvasHost, nullptr);
|
||||
EXPECT_EQ(canvasHost->GetBackend(), XCUIPanelCanvasHostBackend::ImGui);
|
||||
|
||||
const auto capabilities = canvasHost->GetCapabilities();
|
||||
EXPECT_TRUE(capabilities.supportsPointerHitTesting);
|
||||
EXPECT_TRUE(capabilities.supportsHostedSurfaceImages);
|
||||
EXPECT_TRUE(capabilities.supportsPrimitiveOverlays);
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user