From 3d6476c9021519995239ec93bbb11f0dce6c60a0 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Thu, 26 Jun 2025 19:43:39 +0200 Subject: Core: Add a test suite (#9297) Adds a test suite for testing hyprland's features with a runtime tester --------- Co-authored-by: Mihai Fufezan --- hyprtester/src/tests/main/window.cpp | 96 ++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 hyprtester/src/tests/main/window.cpp (limited to 'hyprtester/src/tests/main/window.cpp') diff --git a/hyprtester/src/tests/main/window.cpp b/hyprtester/src/tests/main/window.cpp new file mode 100644 index 00000000..4eecd68d --- /dev/null +++ b/hyprtester/src/tests/main/window.cpp @@ -0,0 +1,96 @@ +#include "tests.hpp" +#include "../../shared.hpp" +#include "../../hyprctlCompat.hpp" +#include +#include +#include +#include +#include +#include +#include +#include "../shared.hpp" + +static int ret = 0; + +using namespace Hyprutils::OS; +using namespace Hyprutils::Memory; + +#define UP CUniquePointer +#define SP CSharedPointer + +bool testWindows() { + NLog::log("{}Testing windows", Colors::GREEN); + + // test on workspace "window" + NLog::log("{}Switching to workspace `window`", Colors::YELLOW); + getFromSocket("/dispatch workspace name:window"); + + NLog::log("{}Spawning kittyProcA", Colors::YELLOW); + auto kittyProcA = Tests::spawnKitty(); + + if (!kittyProcA) { + NLog::log("{}Error: kitty did not spawn", Colors::RED); + return false; + } + + NLog::log("{}Expecting 1 window", Colors::YELLOW); + EXPECT(Tests::windowCount(), 1); + + // check kitty properties. One kitty should take the entire screen, as this is smart gaps + NLog::log("{}Expecting kitty to take up the whole screen", Colors::YELLOW); + { + auto str = getFromSocket("/clients"); + EXPECT(str.contains("at: 0,0"), true); + EXPECT(str.contains("size: 1920,1080"), true); + EXPECT(str.contains("fullscreen: 0"), true); + } + + NLog::log("{}Spawning kittyProcB", Colors::YELLOW); + auto kittyProcB = Tests::spawnKitty(); + if (!kittyProcB) { + NLog::log("{}Error: kitty did not spawn", Colors::RED); + return false; + } + + NLog::log("{}Expecting 2 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 2); + + // open xeyes + NLog::log("{}Spawning xeyes", Colors::YELLOW); + getFromSocket("/dispatch exec xeyes"); + + NLog::log("{}Keep checking if xeyes spawned", Colors::YELLOW); + int counter = 0; + while (Tests::windowCount() != 3) { + counter++; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + if (counter > 50) { + EXPECT(Tests::windowCount(), 3); + return !ret; + } + } + + NLog::log("{}Expecting 3 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 3); + + NLog::log("{}Checking props of xeyes", Colors::YELLOW); + // check some window props of xeyes, try to tile them + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "floating: 1"); + getFromSocket("/dispatch settiled class:XEyes"); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + str = getFromSocket("/clients"); + EXPECT_NOT_CONTAINS(str, "floating: 1"); + } + + // kill all + NLog::log("{}Killing all windows", Colors::YELLOW); + Tests::killAllWindows(); + + NLog::log("{}Expecting 0 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 0); + + return !ret; +} -- cgit v1.2.3