protocols/
test/
.gitignore
21 B
clients.py
54.8 KiB
ctl_unit.c
2.5 KiB
run.py
33.7 KiB
unit.c
47.6 KiB
.clang-format
571 B
.clangd
365 B
.gitignore
82 B
.gitsigners
182 B
LICENSE
32.3 KiB
LICENSE.dwl
34.9 KiB
LICENSE.dwm
2.0 KiB
LICENSE.spectrwm
1.3 KiB
LICENSE.sway
1.0 KiB
LICENSE.tinywl
7.0 KiB
Makefile
9.4 KiB
PKGBUILD
952 B
README
6.2 KiB
config.def.h
15.3 KiB
config.mk
269 B
swm.1.adoc
4.1 KiB
swm.c
270.4 KiB
swm.desktop
81 B
swm.h
3.5 KiB
swmctl.1.adoc
3.3 KiB
swmctl.c
27.3 KiB
util.c
2.2 KiB
util.h
399 B
test/ctl_unit.c
raw
| 1 | #define _POSIX_C_SOURCE 200809L |
| 2 | #include <assert.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <sys/wait.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #define main swmctl_program_main |
| 8 | #include "swmctl.c" |
| 9 | #undef main |
| 10 | |
| 11 | static void expect_invalid_color(const char *value) { |
| 12 | pid_t child = fork(); |
| 13 | int status; |
| 14 | |
| 15 | assert(child >= 0); |
| 16 | if (!child) { |
| 17 | int nullfd = open("/dev/null", O_WRONLY); |
| 18 | |
| 19 | assert(nullfd >= 0); |
| 20 | assert(dup2(nullfd, STDERR_FILENO) >= 0); |
| 21 | close(nullfd); |
| 22 | parse_color(value); |
| 23 | _exit(EXIT_SUCCESS); |
| 24 | } |
| 25 | assert(waitpid(child, &status, 0) == child); |
| 26 | assert(WIFEXITED(status)); |
| 27 | assert(WEXITSTATUS(status) == EXIT_FAILURE); |
| 28 | } |
| 29 | |
| 30 | /* Verify active-window updates and single-line title output. */ |
| 31 | static void test_active_window_events(void) { |
| 32 | event_window_t first = { .title = "one", .active = true, .ready = true }; |
| 33 | event_window_t second = { .title = "two", .ready = true }; |
| 34 | char output[128] = { 0 }; |
| 35 | FILE *capture = tmpfile(); |
| 36 | int saved; |
| 37 | |
| 38 | assert(capture && fflush(stdout) == 0); |
| 39 | saved = dup(STDOUT_FILENO); |
| 40 | assert(saved >= 0 && dup2(fileno(capture), STDOUT_FILENO) >= 0); |
| 41 | wl_list_init(&event_windows); |
| 42 | wl_list_insert(event_windows.prev, &first.link); |
| 43 | wl_list_insert(event_windows.prev, &second.link); |
| 44 | |
| 45 | publish_active_window(); |
| 46 | publish_active_window(); |
| 47 | second.title = "renamed"; |
| 48 | publish_active_window(); |
| 49 | first.title = "one\nchanged"; |
| 50 | first.ready = false; |
| 51 | publish_active_window(); |
| 52 | first.ready = true; |
| 53 | publish_active_window(); |
| 54 | first.active = false; |
| 55 | second.active = true; |
| 56 | publish_active_window(); |
| 57 | second.active = false; |
| 58 | publish_active_window(); |
| 59 | |
| 60 | assert(dup2(saved, STDOUT_FILENO) >= 0); |
| 61 | close(saved); |
| 62 | rewind(capture); |
| 63 | assert(fread(output, 1, sizeof(output) - 1, capture) > 0); |
| 64 | assert(!strcmp(output, "one\none changed\nrenamed\n\n")); |
| 65 | fclose(capture); |
| 66 | } |
| 67 | |
| 68 | int main(void) { |
| 69 | char escaped[64] = {}; |
| 70 | FILE *stream = tmpfile(); |
| 71 | |
| 72 | assert(stream); |
| 73 | print_window_field(stream, "title\x1b[2J"); |
| 74 | rewind(stream); |
| 75 | assert(fread(escaped, 1, sizeof(escaped) - 1, stream) > 0); |
| 76 | assert(!strcmp(escaped, "title\\x1b[2J")); |
| 77 | assert(fclose(stream) == 0); |
| 78 | assert(parse_color("#012345") == 0x012345ff); |
| 79 | assert(parse_color("#01234567") == 0x01234567); |
| 80 | expect_invalid_color("# 12345"); |
| 81 | expect_invalid_color("#+12345"); |
| 82 | test_active_window_events(); |
| 83 | return EXIT_SUCCESS; |
| 84 | } |