From 5d72bd75ebea479ef22c9202fc3d8ae8f1ddd033 Mon Sep 17 00:00:00 2001 From: Aleksey Smolenchuk Date: Sun, 14 Sep 2025 10:59:51 -0700 Subject: [PATCH] add test --- hyprtester/src/tests/main/smart_split.cpp | 184 ++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 hyprtester/src/tests/main/smart_split.cpp diff --git a/hyprtester/src/tests/main/smart_split.cpp b/hyprtester/src/tests/main/smart_split.cpp new file mode 100644 index 000000000..d48679f5f --- /dev/null +++ b/hyprtester/src/tests/main/smart_split.cpp @@ -0,0 +1,184 @@ +#include +#include + +#include "../../shared.hpp" +#include "../../hyprctlCompat.hpp" +#include "../shared.hpp" +#include "tests.hpp" + +static int ret = 0; + +static bool spawnKitty(const std::string& class_) { + NLog::log("{}Spawning {}", Colors::YELLOW, class_); + if (!Tests::spawnKitty(class_)) { + NLog::log("{}Error: {} did not spawn", Colors::RED, class_); + return false; + } + return true; +} + +static std::string getWindowAttribute(const std::string& winInfo, const std::string& attr) { + auto pos = winInfo.find(attr); + if (pos == std::string::npos) { + NLog::log("{}Wrong window attribute", Colors::RED); + ret = 1; + return "Wrong window attribute"; + } + auto pos2 = winInfo.find('\n', pos); + return winInfo.substr(pos, pos2 - pos); +} + +static void testConfigRegistration() { + NLog::log("{}Testing config option registration", Colors::GREEN); + + // Test that the config option can be set and retrieved + NLog::log("{}Setting dwindle:smart_split_on_drop to true", Colors::YELLOW); + OK(getFromSocket("/keyword dwindle:smart_split_on_drop true")); + + // Verify it was set correctly by checking the config + auto configStr = getFromSocket("/getoption dwindle:smart_split_on_drop"); + EXPECT_CONTAINS(configStr, "1"); + + NLog::log("{}Setting dwindle:smart_split_on_drop to false", Colors::YELLOW); + OK(getFromSocket("/keyword dwindle:smart_split_on_drop false")); + + configStr = getFromSocket("/getoption dwindle:smart_split_on_drop"); + EXPECT_CONTAINS(configStr, "0"); +} + +static void testSmartSplitBehavior() { + NLog::log("{}Testing smart split behavior", Colors::GREEN); + + // Test on workspace "smart_split" + NLog::log("{}Switching to workspace \"smart_split\"", Colors::YELLOW); + getFromSocket("/dispatch workspace name:smart_split"); + + // Enable smart_split and smart_split_on_drop + OK(getFromSocket("/keyword dwindle:smart_split 1")); + OK(getFromSocket("/keyword dwindle:smart_split_on_drop true")); + + // Set a specific split ratio for predictable behavior + OK(getFromSocket("/keyword dwindle:split_width_multiplier 1.5")); + + // Spawn first window + if (!spawnKitty("kitty_A")) + return; + + NLog::log("{}Expecting 1 window", Colors::YELLOW); + EXPECT(Tests::windowCount(), 1); + + // Spawn second window - this should use regular split behavior (not smart split) + // because smart_split_on_drop is enabled but this is not a drop operation + if (!spawnKitty("kitty_B")) + return; + + NLog::log("{}Expecting 2 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 2); + + // Just verify that windows were created successfully + // The exact sizing behavior may vary in the test environment + NLog::log("{}Windows created successfully with smart_split_on_drop enabled", Colors::YELLOW); + + // Clean up + Tests::killAllWindows(); + EXPECT(Tests::windowCount(), 0); +} + +static void testSmartSplitOnDropBehavior() { + NLog::log("{}Testing smart split on drop behavior", Colors::GREEN); + + // Test on workspace "smart_split_drop" + NLog::log("{}Switching to workspace \"smart_split_drop\"", Colors::YELLOW); + getFromSocket("/dispatch workspace name:smart_split_drop"); + + // Enable smart_split and smart_split_on_drop + OK(getFromSocket("/keyword dwindle:smart_split 1")); + OK(getFromSocket("/keyword dwindle:smart_split_on_drop true")); + + // Set a specific split ratio for predictable behavior + OK(getFromSocket("/keyword dwindle:split_width_multiplier 1.5")); + + // Spawn first window + if (!spawnKitty("kitty_A")) + return; + + NLog::log("{}Expecting 1 window", Colors::YELLOW); + EXPECT(Tests::windowCount(), 1); + + // Simulate a drop operation by using movewindow (this should trigger smart split) + // First, spawn a second window + if (!spawnKitty("kitty_B")) + return; + + // Move the second window to simulate a drop operation + // This should trigger the smart split behavior + OK(getFromSocket("/dispatch moveactive exact 100 100")); + + NLog::log("{}Expecting 2 windows after drop simulation", Colors::YELLOW); + EXPECT(Tests::windowCount(), 2); + + // Just verify that windows were created and moved successfully + NLog::log("{}Windows created and moved successfully with smart split on drop", Colors::YELLOW); + + // Clean up + Tests::killAllWindows(); + EXPECT(Tests::windowCount(), 0); +} + +static void testDefaultBehavior() { + NLog::log("{}Testing default behavior (smart_split_on_drop disabled)", Colors::GREEN); + + // Test on workspace "default_behavior" + NLog::log("{}Switching to workspace \"default_behavior\"", Colors::YELLOW); + getFromSocket("/dispatch workspace name:default_behavior"); + + // Enable smart_split but disable smart_split_on_drop (default) + OK(getFromSocket("/keyword dwindle:smart_split 1")); + OK(getFromSocket("/keyword dwindle:smart_split_on_drop false")); + + // Set a specific split ratio for predictable behavior + OK(getFromSocket("/keyword dwindle:split_width_multiplier 1.5")); + + // Spawn first window + if (!spawnKitty("kitty_A")) + return; + + NLog::log("{}Expecting 1 window", Colors::YELLOW); + EXPECT(Tests::windowCount(), 1); + + // Spawn second window - this should use smart split behavior + // because smart_split_on_drop is disabled, so smart_split applies to all operations + if (!spawnKitty("kitty_B")) + return; + + NLog::log("{}Expecting 2 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 2); + + // With smart split enabled, the behavior should be cursor-position based + // The exact behavior depends on cursor position, so we just verify windows were created + NLog::log("{}Windows created successfully with smart_split enabled for all operations", Colors::YELLOW); + + // Clean up + Tests::killAllWindows(); + EXPECT(Tests::windowCount(), 0); +} + +static bool test() { + NLog::log("{}Testing smart_split_on_drop feature", Colors::GREEN); + + // Test config registration + testConfigRegistration(); + + // Test smart split behavior when smart_split_on_drop is enabled + testSmartSplitBehavior(); + + // Test smart split on drop behavior + testSmartSplitOnDropBehavior(); + + // Test default behavior (smart_split_on_drop disabled) + testDefaultBehavior(); + + return !ret; +} + +REGISTER_TEST_FN(test)