Modules/GraphicApplication/tests/WindowFrameTests.cpp
agent 711793ffd7 GraphicApplication: GPU device, window surfaces, window and platform backends
gpu/ replaces the OpenGL path and is split by lifetime:
- GpuDevice is the instance, device, graphics queue, command pool, one-shot
  uploads and render-target registry, shared by every window.
- WindowSurface is one window's surface, swapchain, render pass,
  depth-stencil and frames in flight. beginFrame() returns a GpuFrame
  (command buffer, frame slot, extent), the narrow view renderers record
  into. Render-finished semaphores are per swapchain image, Vulkan results
  are checked and failures throw GpuError.

backends/contract/ is the only thing a backend and the window share.
PlatformWindow is what a backend implements; it knows no coalescer or GPU
object. PlatformWindowHost is all a backend may call back: rawInput(),
onContentResized(), onSurfaceAvailable() and onSurfaceLost(), so the window
drives the GPU surface. Desktop-only manipulation is the optional
DesktopWindowControls interface. A backend also defines its surface
extensions, its resource directory and createPlatformWindow(), which
receives a typed PlatformContext.

- backends/wayland/ keeps xdg configure handling to itself and acknowledges
  it when the frame loop applies it. The seat is split per device
  (keyboard, pointer, tablet, text input, clipboard); clipboard contents are
  read asynchronously on the event loop. evdev key codes and the touchpad
  pinch converter live here. Resources resolve next to the executable.
- backends/android/ runs on native_app_glue and finishes the activity when
  the application returns or fails.

window/ owns the platform window, its WindowSurface, the coalescer and the
input queue, and exposes roles: WindowEventLoop, WindowInput (state,
injection, raw tap, delivery policies, the one place input is muted),
WindowControls (with desktop() for the optional controls) and
WindowServices. Window's public header names no backend.
2026-10-29 05:24:06 +03:00

106 lines
3.7 KiB
C++

#include "UnitTest++/UnitTest++.h"
#include "WindowFrame.hpp"
using namespace tp;
namespace {
WindowFrame floatingFrame() {
WindowFrame frame;
frame.setContentSize({ 800, 600 });
return frame;
}
}
SUITE(WindowFrameGeometry) {
TEST(FloatingTranslucentFrameReservesShadowMargin) {
const WindowFrame frame = floatingFrame();
const halnf margin = WindowFrame::kShadowMargin;
CHECK(frame.hasShadow());
CHECK_CLOSE(800 + margin * 2, frame.surfaceSize().x, 0.001f);
CHECK_CLOSE(600 + margin * 2, frame.surfaceSize().y, 0.001f);
CHECK_CLOSE(margin, frame.contentRect().x, 0.001f);
CHECK_CLOSE(WindowFrame::kCornerRadius, frame.cornerRadius(), 0.001f);
}
TEST(TiledFrameDropsShadowAndCorners) {
WindowFrame frame = floatingFrame();
frame.setTiled(true);
CHECK(!frame.hasShadow());
CHECK_CLOSE(0, frame.margin(), 0.001f);
CHECK_CLOSE(0, frame.cornerRadius(), 0.001f);
CHECK_CLOSE(800, frame.surfaceSize().x, 0.001f);
}
TEST(OpaqueSurfaceDropsShadowButKeepsResizeEdges) {
WindowFrame frame = floatingFrame();
frame.setTranslucent(false);
CHECK(!frame.hasShadow());
CHECK(frame.edgeAt({ 1, 300 }) == WindowEdge::Left);
CHECK(frame.edgeAt({ 400, 300 }) == WindowEdge::None);
}
TEST(InputRegionCoversContentPlusOuterResizeBorder) {
const WindowFrame frame = floatingFrame();
const RectF input = frame.inputRect();
CHECK_CLOSE(WindowFrame::kShadowMargin - WindowFrame::kResizeBorder, input.x, 0.001f);
CHECK_CLOSE(800 + WindowFrame::kResizeBorder * 2, input.z, 0.001f);
}
}
SUITE(WindowFrameEdges) {
TEST(ShadowOutsideResizeBorderIsNotInteractive) {
const WindowFrame frame = floatingFrame();
CHECK(frame.edgeAt({ 1, 1 }) == WindowEdge::None);
}
TEST(SidesResolveToSingleEdges) {
const WindowFrame frame = floatingFrame();
const RectF content = frame.contentRect();
const Vec2F middle = { content.x + content.z / 2, content.y + content.w / 2 };
CHECK(frame.edgeAt({ content.x - 2, middle.y }) == WindowEdge::Left);
CHECK(frame.edgeAt({ content.x + content.z + 2, middle.y }) == WindowEdge::Right);
CHECK(frame.edgeAt({ middle.x, content.y - 2 }) == WindowEdge::Top);
CHECK(frame.edgeAt({ middle.x, content.y + content.w + 2 }) == WindowEdge::Bottom);
}
TEST(InnerResizeStripStaysThin) {
const WindowFrame frame = floatingFrame();
const RectF content = frame.contentRect();
CHECK(frame.edgeAt({ content.x + 1, content.y + 200 }) == WindowEdge::Left);
CHECK(frame.edgeAt({ content.x + 6, content.y + 200 }) == WindowEdge::None);
}
TEST(CornersWinOverSides) {
const WindowFrame frame = floatingFrame();
const RectF content = frame.contentRect();
CHECK(frame.edgeAt({ content.x - 2, content.y + 4 }) == WindowEdge::TopLeft);
CHECK(frame.edgeAt({ content.x + 4, content.y - 2 }) == WindowEdge::TopLeft);
CHECK(frame.edgeAt({ content.x + content.z + 2, content.y + content.w - 4 }) == WindowEdge::BottomRight);
CHECK(frame.edgeAt({ content.x + content.z - 4, content.y - 2 }) == WindowEdge::TopRight);
CHECK(frame.edgeAt({ content.x - 2, content.y + content.w - 4 }) == WindowEdge::BottomLeft);
}
TEST(TiledFrameHasNoResizeEdges) {
WindowFrame frame = floatingFrame();
frame.setTiled(true);
CHECK(frame.edgeAt({ 0, 0 }) == WindowEdge::None);
CHECK(frame.edgeAt({ 1, 300 }) == WindowEdge::None);
}
TEST(EdgeCursorsMatchAxes) {
CHECK(cursorForEdge(WindowEdge::Left) == CursorShape::ResizeHorizontal);
CHECK(cursorForEdge(WindowEdge::Bottom) == CursorShape::ResizeVertical);
CHECK(cursorForEdge(WindowEdge::TopLeft) == CursorShape::ResizeNorthWestSouthEast);
CHECK(cursorForEdge(WindowEdge::BottomLeft) == CursorShape::ResizeNorthEastSouthWest);
CHECK(cursorForEdge(WindowEdge::None) == CursorShape::Default);
}
}