diff --git a/hyprtester/src/tests/main/smart_split.cpp b/hyprtester/src/tests/main/smartSplit.cpp similarity index 53% rename from hyprtester/src/tests/main/smart_split.cpp rename to hyprtester/src/tests/main/smartSplit.cpp index d48679f5f..ebe6b8255 100644 --- a/hyprtester/src/tests/main/smart_split.cpp +++ b/hyprtester/src/tests/main/smartSplit.cpp @@ -1,41 +1,21 @@ -#include -#include - +#include "tests.hpp" #include "../../shared.hpp" #include "../../hyprctlCompat.hpp" +#include +#include #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); -} +using namespace Hyprutils::OS; +using namespace Hyprutils::Memory; static void testConfigRegistration() { - NLog::log("{}Testing config option registration", Colors::GREEN); + NLog::log("{}Testing config: dwindle:smart_split_on_drop", 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"); @@ -47,135 +27,97 @@ static void testConfigRegistration() { } static void testSmartSplitBehavior() { - NLog::log("{}Testing smart split behavior", Colors::GREEN); + NLog::log("{}Testing smart split behavior with smart_split_on_drop enabled", Colors::YELLOW); - // 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")) + if (!Tests::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")) + if (!Tests::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); + NLog::log("{}Testing smart split with drop simulation", Colors::YELLOW); - // 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")) + if (!Tests::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")) + if (!Tests::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); + NLog::log("{}Testing default behavior with smart_split_on_drop disabled", Colors::YELLOW); - // 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")) + if (!Tests::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")) + if (!Tests::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); + NLog::log("{}Testing config: dwindle:smart_split_on_drop", 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;