| 1 |
#include "tests.hpp" |
| 2 |
#include "../../shared.hpp" |
| 3 |
#include "../../hyprctlCompat.hpp" |
| 4 |
#include <hyprutils/os/Process.hpp> |
| 5 |
#include <hyprutils/memory/WeakPtr.hpp> |
| 6 |
#include "../shared.hpp" |
| 7 |
|
| 8 |
using namespace Hyprutils::OS; |
| 9 |
using namespace Hyprutils::Memory; |
| 10 |
|
| 11 |
#define UP CUniquePointer |
| 12 |
#define SP CSharedPointer |
| 13 |
|
| 14 |
// Uncomment once test vm can run hyprland-dialog |
| 15 |
// static void testAnrDialogs() { |
| 16 |
// NLog::log("{}Testing ANR dialogs", Colors::YELLOW); |
| 17 |
// |
| 18 |
// OK(getFromSocket("/eval hl.config({ misc = { enable_anr_dialog = true } })")); |
| 19 |
// OK(getFromSocket("/eval hl.config({ misc = { anr_missed_pings = 1 } })")); |
| 20 |
// |
| 21 |
// NLog::log("{}ANR dialog: regular workspaces", Colors::YELLOW); |
| 22 |
// { |
| 23 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '2' })")); |
| 24 |
// |
| 25 |
// auto kitty = Tests::spawnKitty("bad_kitty"); |
| 26 |
// |
| 27 |
// if (!kitty) { |
| 28 |
// ret = 1; |
| 29 |
// return; |
| 30 |
// } |
| 31 |
// |
| 32 |
// { |
| 33 |
// auto str = getFromSocket("/activewindow"); |
| 34 |
// ASSERT_CONTAINS(str, "workspace: 2"); |
| 35 |
// } |
| 36 |
// |
| 37 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })")); |
| 38 |
// |
| 39 |
// ::kill(kitty->pid(), SIGSTOP); |
| 40 |
// Tests::waitUntilWindowsN(2); |
| 41 |
// |
| 42 |
// { |
| 43 |
// auto str = getFromSocket("/activeworkspace"); |
| 44 |
// ASSERT_CONTAINS(str, "windows: 0"); |
| 45 |
// } |
| 46 |
// |
| 47 |
// { |
| 48 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:hyprland-dialog' })")) |
| 49 |
// auto str = getFromSocket("/activewindow"); |
| 50 |
// ASSERT_CONTAINS(str, "workspace: 2"); |
| 51 |
// } |
| 52 |
// } |
| 53 |
// |
| 54 |
// Tests::killAllWindows(); |
| 55 |
// |
| 56 |
// NLog::log("{}ANR dialog: named workspaces", Colors::YELLOW); |
| 57 |
// { |
| 58 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:yummy' })")); |
| 59 |
// |
| 60 |
// auto kitty = Tests::spawnKitty("bad_kitty"); |
| 61 |
// |
| 62 |
// if (!kitty) { |
| 63 |
// ret = 1; |
| 64 |
// return; |
| 65 |
// } |
| 66 |
// |
| 67 |
// { |
| 68 |
// auto str = getFromSocket("/activewindow"); |
| 69 |
// ASSERT_CONTAINS(str, "yummy"); |
| 70 |
// } |
| 71 |
// |
| 72 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })")); |
| 73 |
// |
| 74 |
// ::kill(kitty->pid(), SIGSTOP); |
| 75 |
// Tests::waitUntilWindowsN(2); |
| 76 |
// |
| 77 |
// { |
| 78 |
// auto str = getFromSocket("/activeworkspace"); |
| 79 |
// ASSERT_CONTAINS(str, "windows: 0"); |
| 80 |
// } |
| 81 |
// |
| 82 |
// { |
| 83 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:hyprland-dialog' })")) |
| 84 |
// auto str = getFromSocket("/activewindow"); |
| 85 |
// ASSERT_CONTAINS(str, "yummy"); |
| 86 |
// } |
| 87 |
// } |
| 88 |
// |
| 89 |
// Tests::killAllWindows(); |
| 90 |
// |
| 91 |
// NLog::log("{}ANR dialog: special workspaces", Colors::YELLOW); |
| 92 |
// { |
| 93 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'special:apple' })")); |
| 94 |
// |
| 95 |
// auto kitty = Tests::spawnKitty("bad_kitty"); |
| 96 |
// |
| 97 |
// if (!kitty) { |
| 98 |
// ret = 1; |
| 99 |
// return; |
| 100 |
// } |
| 101 |
// |
| 102 |
// { |
| 103 |
// auto str = getFromSocket("/activewindow"); |
| 104 |
// ASSERT_CONTAINS(str, "special:apple"); |
| 105 |
// } |
| 106 |
// |
| 107 |
// OK(getFromSocket("/dispatch hl.dsp.workspace.toggle_special('apple')")); |
| 108 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = '1' })")); |
| 109 |
// |
| 110 |
// ::kill(kitty->pid(), SIGSTOP); |
| 111 |
// Tests::waitUntilWindowsN(2); |
| 112 |
// |
| 113 |
// { |
| 114 |
// auto str = getFromSocket("/activeworkspace"); |
| 115 |
// ASSERT_CONTAINS(str, "windows: 0"); |
| 116 |
// } |
| 117 |
// |
| 118 |
// { |
| 119 |
// OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:hyprland-dialog' })")) |
| 120 |
// auto str = getFromSocket("/activewindow"); |
| 121 |
// ASSERT_CONTAINS(str, "special:apple"); |
| 122 |
// } |
| 123 |
// } |
| 124 |
// |
| 125 |
// OK(getFromSocket("/reload")); |
| 126 |
// Tests::killAllWindows(); |
| 127 |
// } |
| 128 |
|
| 129 |
// TODO: decompose this into multiple test cases |
| 130 |
TEST_CASE(misc) { |
| 131 |
NLog::log("{}Testing close_special_on_empty", Colors::YELLOW); |
| 132 |
|
| 133 |
OK(getFromSocket("/eval hl.config({ misc = { close_special_on_empty = false } })")); |
| 134 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'special:test' })")); |
| 135 |
|
| 136 |
Tests::spawnKitty(); |
| 137 |
|
| 138 |
{ |
| 139 |
auto str = getFromSocket("/monitors"); |
| 140 |
ASSERT_CONTAINS(str, "special workspace: -"); |
| 141 |
} |
| 142 |
|
| 143 |
Tests::killAllWindows(); |
| 144 |
|
| 145 |
{ |
| 146 |
auto str = getFromSocket("/monitors"); |
| 147 |
ASSERT_CONTAINS(str, "special workspace: -"); |
| 148 |
} |
| 149 |
|
| 150 |
Tests::spawnKitty(); |
| 151 |
|
| 152 |
OK(getFromSocket("/eval hl.config({ misc = { close_special_on_empty = true } })")); |
| 153 |
|
| 154 |
Tests::killAllWindows(); |
| 155 |
|
| 156 |
{ |
| 157 |
auto str = getFromSocket("/monitors"); |
| 158 |
ASSERT_NOT_CONTAINS(str, "special workspace: -"); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
TEST_CASE(processesThatDieEarlyAreReaped) { |
| 163 |
// Ensure that the process autostarted in the config does not |
| 164 |
// become a zombie even if it terminates very quickly. |
| 165 |
ASSERT(Tests::execAndGet("pgrep -f 'sleep 0'").empty(), true); |
| 166 |
} |