#include "TestHarness.hpp"
#include "ui/WindowFit.hpp"
using namespace dp::ui;
DP_TEST(window_fit_caps_height_at_percent_and_centers) {
const WindowFitResult r = WindowFit::fit({430, 900}, 0, 0, 1920, 1080, 80);
CHECK_EQ(r.maxHeight, 864);
CHECK_EQ(r.height, 864);
CHECK_EQ(r.width, 430);
CHECK_EQ(r.x, (1920 - 430) / 2);
CHECK_EQ(r.y, (1080 - 864) / 2);
}
DP_TEST(window_fit_keeps_smaller_window_and_centers_it) {
const WindowFitResult r = WindowFit::fit({430, 600}, 0, 0, 1920, 1080, 80);
CHECK_EQ(r.height, 600);
CHECK_EQ(r.y, (1080 - 600) / 2);
}
DP_TEST(window_fit_follows_display_origin_and_small_screens) {
const WindowFitResult r = WindowFit::fit({430, 900}, 100, 50, 800, 600, 80);
CHECK_EQ(r.maxHeight, 480);
CHECK_EQ(r.height, 480);
CHECK_EQ(r.x, 100 + (800 - 430) / 2);
CHECK_EQ(r.y, 50 + (600 - 480) / 2);
const WindowFitResult narrow = WindowFit::fit({430, 900}, 0, 0, 360, 640, 80);
CHECK_EQ(narrow.width, 360);
CHECK_EQ(narrow.x, 0);
}
DP_TEST(window_fit_clamps_percent) {
CHECK_EQ(WindowFit::clampPercent(5), 20);
CHECK_EQ(WindowFit::clampPercent(500), 100);
CHECK_EQ(WindowFit::fit({430, 900}, 0, 0, 1920, 1080, 100).maxHeight, 1080);
}
DP_TEST(window_fit_subtracts_window_manager_frame) {
const WindowFitResult r = WindowFit::fit({430, 900}, 0, 0, 1920, 1080, 80, 5, 29, 5, 5);
CHECK_EQ(r.height + 29 + 5, 864); // outer height equals the cap
CHECK_EQ(r.maxHeight, 830);
CHECK_EQ(r.x - 5, (1920 - (430 + 10)) / 2);
CHECK_EQ(r.y - 29, (1080 - 864) / 2);
}