Codebergdnkl
foot
master
1#if !defined(_DEBUG)
2 #define _DEBUG
3#endif
4#undef NDEBUG
6#include "../log.h"
8#include "../config.c"
10#define ALEN(v) (sizeof(v) / sizeof((v)[0]))
12/*
13 * Stubs
14 */
16void
17user_notification_add_fmt(user_notifications_t *notifications,
18 enum user_notification_kind kind,
19 const char *fmt, ...)
20{
21}
23static void
24test_invalid_key(struct context *ctx, bool (*parse_fun)(struct context *ctx),
25 const char *key)
26{
27 ctx->key = key;
28 ctx->value = "value for invalid key";
30 if (parse_fun(ctx)) {
31 BUG("[%s].%s: did not fail to parse as expected"
32 "(key should be invalid)", ctx->section, ctx->key);
33 }
34}
36static void
37test_string(struct context *ctx, bool (*parse_fun)(struct context *ctx),
38 const char *key, char *const *ptr)
39{
40 ctx->key = key;
42 static const struct {
43 const char *option_string;
44 const char *value;
45 bool invalid;
46 } input[] = {
47 {"a string", "a string"},
48 };
50 for (size_t i = 0; i < ALEN(input); i++) {
51 ctx->value = input[i].option_string;
53 if (input[i].invalid) {
54 if (parse_fun(ctx)) {
55 BUG("[%s].%s=%s: did not fail to parse as expected",
56 ctx->section, ctx->key, ctx->value);
57 }
58 } else {
59 if (!parse_fun(ctx)) {
60 BUG("[%s].%s=%s: failed to parse",
61 ctx->section, ctx->key, ctx->value);
62 }
63 if (!streq(*ptr, input[i].value)) {
64 BUG("[%s].%s=%s: set value (%s) not the expected one (%s)",
65 ctx->section, ctx->key, ctx->value,
66 *ptr, input[i].value);
67 }
68 }
69 }
70}
72static void
73test_c32string(struct context *ctx, bool (*parse_fun)(struct context *ctx),
74 const char *key, char32_t *const *ptr)
75{
76 ctx->key = key;
78 static const struct {
79 const char *option_string;
80 const char32_t *value;
81 bool invalid;
82 } input[] = {
83 {"a string", U"a string"},
84 };
86 for (size_t i = 0; i < ALEN(input); i++) {
87 ctx->value = input[i].option_string;
89 if (input[i].invalid) {
90 if (parse_fun(ctx)) {
91 BUG("[%s].%s=%s: did not fail to parse as expected",
92 ctx->section, ctx->key, ctx->value);
93 }
94 } else {
95 if (!parse_fun(ctx)) {
96 BUG("[%s].%s=%s: failed to parse",
97 ctx->section, ctx->key, ctx->value);
98 }
99 if (c32cmp(*ptr, input[i].value) != 0) {
100 BUG("[%s].%s=%s: set value (%ls) not the expected one (%ls)",
101 ctx->section, ctx->key, ctx->value,
102 (const wchar_t *)*ptr,
103 (const wchar_t *)input[i].value);
104 }
105 }
106 }
107}
109static void
110test_boolean(struct context *ctx, bool (*parse_fun)(struct context *ctx),
111 const char *key, const bool *ptr)
112{
113 ctx->key = key;
115 static const struct {
116 const char *option_string;
117 bool value;
118 bool invalid;
119 } input[] = {
120 {"1", true}, {"0", false},
121 {"on", true}, {"off", false},
122 {"true", true}, {"false", false},
123 {"unittest-invalid-boolean-value", false, true},
124 };
126 for (size_t i = 0; i < ALEN(input); i++) {
127 ctx->value = input[i].option_string;
129 if (input[i].invalid) {
130 if (parse_fun(ctx)) {
131 BUG("[%s].%s=%s: did not fail to parse as expected",
132 ctx->section, ctx->key, ctx->value);
133 }
134 } else {
135 if (!parse_fun(ctx)) {
136 BUG("[%s].%s=%s: failed to parse",
137 ctx->section, ctx->key, ctx->value);
138 }
139 if (*ptr != input[i].value) {
140 BUG("[%s].%s=%s: set value (%s) not the expected one (%s)",
141 ctx->section, ctx->key, ctx->value,
142 *ptr ? "true" : "false",
143 input[i].value ? "true" : "false");
144 }
145 }
146 }
147}
149static void
150test_uint16(struct context *ctx, bool (*parse_fun)(struct context *ctx),
151 const char *key, const uint16_t *ptr)
152{
153 ctx->key = key;
155 static const struct {
156 const char *option_string;
157 uint16_t value;
158 bool invalid;
159 } input[] = {
160 {"0", 0}, {"65535", 65535}, {"65536", 0, true},
161 {"abc", 0, true}, {"true", 0, true},
162 };
164 for (size_t i = 0; i < ALEN(input); i++) {
165 ctx->value = input[i].option_string;
167 if (input[i].invalid) {
168 if (parse_fun(ctx)) {
169 BUG("[%s].%s=%s: did not fail to parse as expected",
170 ctx->section, ctx->key, ctx->value);
171 }
172 } else {
173 if (!parse_fun(ctx)) {
174 BUG("[%s].%s=%s: failed to parse",
175 ctx->section, ctx->key, ctx->value);
176 }
177 if (*ptr != input[i].value) {
178 BUG("[%s].%s=%s: set value (%hu) not the expected one (%hu)",
179 ctx->section, ctx->key, ctx->value,
180 *ptr, input[i].value);
181 }
182 }
183 }
184}
186static void
187test_uint32(struct context *ctx, bool (*parse_fun)(struct context *ctx),
188 const char *key, const uint32_t *ptr)
189{
190 ctx->key = key;
192 static const struct {
193 const char *option_string;
194 uint32_t value;
195 bool invalid;
196 } input[] = {
197 {"0", 0}, {"65536", 65536}, {"4294967295", 4294967295},
198 {"4294967296", 0, true}, {"abc", 0, true}, {"true", 0, true},
199 };
201 for (size_t i = 0; i < ALEN(input); i++) {
202 ctx->value = input[i].option_string;
204 if (input[i].invalid) {
205 if (parse_fun(ctx)) {
206 BUG("[%s].%s=%s: did not fail to parse as expected",
207 ctx->section, ctx->key, ctx->value);
208 }
209 } else {
210 if (!parse_fun(ctx)) {
211 BUG("[%s].%s=%s: failed to parse",
212 ctx->section, ctx->key, ctx->value);
213 }
214 if (*ptr != input[i].value) {
215 BUG("[%s].%s=%s: set value (%u) not the expected one (%u)",
216 ctx->section, ctx->key, ctx->value,
217 *ptr, input[i].value);
218 }
219 }
220 }
221}
223static void
224test_float(struct context *ctx, bool (*parse_fun)(struct context *ctx),
225 const char *key, const float *ptr)
226{
227 ctx->key = key;
229 static const struct {
230 const char *option_string;
231 float value;
232 bool invalid;
233 } input[] = {
234 {"0", 0}, {"0.1", 0.1}, {"1e10", 1e10}, {"-10.7", -10.7},
235 {"abc", 0, true}, {"true", 0, true},
236 };
238 for (size_t i = 0; i < ALEN(input); i++) {
239 ctx->value = input[i].option_string;
241 if (input[i].invalid) {
242 if (parse_fun(ctx)) {
243 BUG("[%s].%s=%s: did not fail to parse as expected",
244 ctx->section, ctx->key, ctx->value);
245 }
246 } else {
247 if (!parse_fun(ctx)) {
248 BUG("[%s].%s=%s: failed to parse",
249 ctx->section, ctx->key, ctx->value);
250 }
251 if (*ptr != input[i].value) {
252 BUG("[%s].%s=%s: set value (%f) not the expected one (%f)",
253 ctx->section, ctx->key, ctx->value,
254 *ptr, input[i].value);
255 }
256 }
257 }
258}
260static void
261test_pt_or_px(struct context *ctx, bool (*parse_fun)(struct context *ctx),
262 const char *key, const struct pt_or_px *ptr)
263{
264 ctx->key = key;
266 static const struct {
267 const char *option_string;
268 struct pt_or_px value;
269 bool invalid;
270 } input[] = {
271 {"12", {.pt = 12}}, {"12px", {.px = 12}},
272 {"unittest-invalid-pt-or-px-value", {0}, true},
273 };
275 for (size_t i = 0; i < ALEN(input); i++) {
276 ctx->value = input[i].option_string;
278 if (input[i].invalid) {
279 if (parse_fun(ctx)) {
280 BUG("[%s].%s=%s: did not fail to parse as expected",
281 ctx->section, ctx->key, ctx->value);
282 }
283 } else {
284 if (!parse_fun(ctx)) {
285 BUG("[%s].%s=%s: failed to parse",
286 ctx->section, ctx->key, ctx->value);
287 }
288 if (memcmp(ptr, &input[i].value, sizeof(*ptr)) != 0) {
289 BUG("[%s].%s=%s: "
290 "set value (pt=%f, px=%d) not the expected one (pt=%f, px=%d)",
291 ctx->section, ctx->key, ctx->value,
292 ptr->pt, ptr->px,
293 input[i].value.pt, input[i].value.px);
294 }
295 }
296 }
297}
299static void
300test_spawn_template(struct context *ctx, bool (*parse_fun)(struct context *ctx),
301 const char *key, const struct config_spawn_template *ptr)
302{
303 static const char *const args[] = {
304 "command", "arg1", "arg2", "arg3 has spaces"};
306 ctx->key = key;
307 ctx->value = "command arg1 arg2 \"arg3 has spaces\"";
309 if (!parse_fun(ctx))
310 BUG("[%s].%s=%s: failed to parse", ctx->section, ctx->key, ctx->value);
312 if (ptr->argv.args == NULL)
313 BUG("[%s].%s=%s: argv is NULL", ctx->section, ctx->key, ctx->value);
315 for (size_t i = 0; i < ALEN(args); i++) {
316 if (ptr->argv.args[i] == NULL || !streq(ptr->argv.args[i], args[i])) {
317 BUG("[%s].%s=%s: set value not the expected one: "
318 "mismatch of arg #%zu: expected=\"%s\", got=\"%s\"",
319 ctx->section, ctx->key, ctx->value, i,
320 args[i], ptr->argv.args[i]);
321 }
322 }
324 if (ptr->argv.args[ALEN(args)] != NULL) {
325 BUG("[%s].%s=%s: set value not the expected one: "
326 "expected NULL terminator at arg #%zu, got=\"%s\"",
327 ctx->section, ctx->key, ctx->value,
328 ALEN(args), ptr->argv.args[ALEN(args)]);
329 }
331 /* Trigger parse failure */
332 ctx->value = "command with \"unterminated quote";
333 if (parse_fun(ctx)) {
334 BUG("[%s].%s=%s: did not fail to parse as expected",
335 ctx->section, ctx->key, ctx->value);
336 }
337}
339static void
340test_enum(struct context *ctx, bool (*parse_fun)(struct context *ctx),
341 const char *key, size_t count, const char *enum_strings[static count],
342 int enum_values[static count], int *ptr)
343{
344 ctx->key = key;
346 for (size_t i = 0; i < count; i++) {
347 ctx->value = enum_strings[i];
348 if (!parse_fun(ctx)) {
349 BUG("[%s].%s=%s: failed to parse",
350 ctx->section, ctx->key, ctx->value);
351 }
353 if (*ptr != enum_values[i]) {
354 BUG("[%s].%s=%s: set value not the expected one: expected %d, got %d",
355 ctx->section, ctx->key, ctx->value, enum_values[i], *ptr);
356 }
357 }
359 ctx->value = "invalid-enum-value";
360 if (parse_fun(ctx)) {
361 BUG("[%s].%s=%s: did not fail to parse as expected",
362 ctx->section, ctx->key, ctx->value);
363 }
364}
367static void
368test_color(struct context *ctx, bool (*parse_fun)(struct context *ctx),
369 const char *key, bool alpha_allowed, uint32_t *ptr)
370{
371 ctx->key = key;
373 const struct {
374 const char *option_string;
375 uint32_t color;
376 bool invalid;
377 } input[] = {
378 {"000000", 0},
379 {"999999", 0x999999},
380 {"ffffff", 0xffffff},
381 {"ffffffff", 0xffffffff, !alpha_allowed},
382 {"aabbccdd", 0xaabbccdd, !alpha_allowed},
383 {"00", 0, true},
384 {"0000", 0, true},
385 {"00000", 0, true},
386 {"000000000", 0, true},
387 {"unittest-invalid-color", 0, true},
388 };
390 for (size_t i = 0; i < ALEN(input); i++) {
391 ctx->value = input[i].option_string;
392 if (input[i].invalid) {
393 if (parse_fun(ctx)) {
394 BUG("[%s].%s=%s: did not fail to parse as expected",
395 ctx->section, ctx->key, ctx->value);
396 }
397 } else {
398 if (!parse_fun(ctx)) {
399 BUG("[%s].%s=%s: failed to parse",
400 ctx->section, ctx->key, ctx->value);
401 }
403 uint32_t color = input[i].color;
404 if (alpha_allowed && strlen(input[i].option_string) == 6)
405 color |= 0xff000000;
407 if (*ptr != color) {
408 BUG("[%s].%s=%s: expected 0x%08x, got 0x%08x",
409 ctx->section, ctx->key, ctx->value,
410 color, *ptr);
411 }
412 }
413 }
414}
416static void
417test_two_colors(struct context *ctx, bool (*parse_fun)(struct context *ctx),
418 const char *key, bool alpha_allowed,
419 uint32_t *ptr1, uint32_t *ptr2)
420{
421 ctx->key = key;
423 const struct {
424 const char *option_string;
425 uint32_t color1;
426 uint32_t color2;
427 bool invalid;
428 } input[] = {
429 {"000000 000000", 0, 0},
431 /* No alpha */
432 {"999999 888888", 0x999999, 0x888888},
433 {"ffffff aaaaaa", 0xffffff, 0xaaaaaa},
435 /* Both colors have alpha component */
436 {"ffffffff 00000000", 0xffffffff, 0x00000000, !alpha_allowed},
437 {"aabbccdd, ee112233", 0xaabbccdd, 0xee112233, !alpha_allowed},
439 /* Only one color has alpha component */
440 {"ffffffff 112233", 0xffffffff, 0x112233, !alpha_allowed},
441 {"ffffff ff112233", 0x00ffffff, 0xff112233, !alpha_allowed},
443 {"unittest-invalid-color", 0, 0, true},
444 };
446 for (size_t i = 0; i < ALEN(input); i++) {
447 ctx->value = input[i].option_string;
448 if (input[i].invalid) {
449 if (parse_fun(ctx)) {
450 BUG("[%s].%s=%s: did not fail to parse as expected",
451 ctx->section, ctx->key, ctx->value);
452 }
453 } else {
454 if (!parse_fun(ctx)) {
455 BUG("[%s].%s=%s: failed to parse",
456 ctx->section, ctx->key, ctx->value);
457 }
459 if (*ptr1 != input[i].color1) {
460 BUG("[%s].%s=%s: expected 0x%08x, got 0x%08x",
461 ctx->section, ctx->key, ctx->value,
462 input[i].color1, *ptr1);
463 }
465 if (*ptr2 != input[i].color2) {
466 BUG("[%s].%s=%s: expected 0x%08x, got 0x%08x",
467 ctx->section, ctx->key, ctx->value,
468 input[i].color2, *ptr2);
469 }
470 }
471 }
472}
474static void
475test_section_main(void)
476{
477 struct config conf = {0};
478 struct context ctx = {.conf = &conf, .section = "main", .path = "unittest"};
480 test_invalid_key(&ctx, &parse_section_main, "invalid-key");
482 test_string(&ctx, &parse_section_main, "shell", &conf.shell);
483 test_string(&ctx, &parse_section_main, "term", &conf.term);
484 test_string(&ctx, &parse_section_main, "app-id", &conf.app_id);
485 test_string(&ctx, &parse_section_main, "toplevel-tag", &conf.toplevel_tag);
486 test_string(&ctx, &parse_section_main, "utmp-helper", &conf.utmp_helper_path);
488 test_c32string(&ctx, &parse_section_main, "word-delimiters", &conf.word_delimiters);
490 test_boolean(&ctx, &parse_section_main, "login-shell", &conf.login_shell);
491 test_boolean(&ctx, &parse_section_main, "box-drawings-uses-font-glyphs", &conf.box_drawings_uses_font_glyphs);
492 test_boolean(&ctx, &parse_section_main, "locked-title", &conf.locked_title);
493 test_boolean(&ctx, &parse_section_main, "dpi-aware", &conf.dpi_aware);
494 test_boolean(&ctx, &parse_section_main, "gamma-correct-blending", &conf.gamma_correct);
495 test_boolean(&ctx, &parse_section_main, "uppercase-regex-insert", &conf.uppercase_regex_insert);
497 test_pt_or_px(&ctx, &parse_section_main, "font-size-adjustment", &conf.font_size_adjustment.pt_or_px); /* TODO: test ‘N%’ values too */
498 test_pt_or_px(&ctx, &parse_section_main, "line-height", &conf.line_height);
499 test_pt_or_px(&ctx, &parse_section_main, "letter-spacing", &conf.letter_spacing);
500 test_pt_or_px(&ctx, &parse_section_main, "horizontal-letter-offset", &conf.horizontal_letter_offset);
501 test_pt_or_px(&ctx, &parse_section_main, "vertical-letter-offset", &conf.vertical_letter_offset);
502 test_pt_or_px(&ctx, &parse_section_main, "underline-thickness", &conf.underline_thickness);
503 test_pt_or_px(&ctx, &parse_section_main, "strikeout-thickness", &conf.strikeout_thickness);
505 test_uint16(&ctx, &parse_section_main, "resize-delay-ms", &conf.resize_delay_ms);
506 test_uint16(&ctx, &parse_section_main, "workers", &conf.render_worker_count);
508 test_enum(&ctx, &parse_section_main, "selection-target",
509 4,
510 (const char *[]){"none", "primary", "clipboard", "both"},
511 (int []){SELECTION_TARGET_NONE,
512 SELECTION_TARGET_PRIMARY,
513 SELECTION_TARGET_CLIPBOARD,
514 SELECTION_TARGET_BOTH},
515 (int *)&conf.selection_target);
517 test_enum(
518 &ctx, &parse_section_main, "initial-window-mode",
519 3,
520 (const char *[]){"windowed", "maximized", "fullscreen"},
521 (int []){STARTUP_WINDOWED, STARTUP_MAXIMIZED, STARTUP_FULLSCREEN},
522 (int *)&conf.startup_mode);
524 test_enum(
525 &ctx, &parse_section_main, "initial-color-theme",
526 2,
527 (const char *[]){"dark", "light", "1", "2"},
528 (int []){COLOR_THEME_DARK, COLOR_THEME_LIGHT,
529 COLOR_THEME_DARK, COLOR_THEME_LIGHT},
530 (int *)&conf.initial_color_theme);
532 /* TODO: font (custom) */
533 /* TODO: include (custom) */
534 /* TODO: bold-text-in-bright (enum/boolean) */
535 /* TODO: pad (geometry + optional string)*/
536 /* TODO: initial-window-size-pixels (geometry) */
537 /* TODO: initial-window-size-chars (geometry) */
539 config_free(&conf);
540}
542static void
543test_section_security(void)
544{
545 struct config conf = {0};
546 struct context ctx = {.conf = &conf, .section = "security", .path = "unittest"};
548 test_invalid_key(&ctx, &parse_section_security, "invalid-key");
549 test_enum(
550 &ctx, &parse_section_security, "osc52", 4,
551 (const char*[]){"disabled", "copy-enabled", "paste-enabled", "enabled"},
552 (int []){OSC52_DISABLED, OSC52_COPY_ENABLED, OSC52_PASTE_ENABLED, OSC52_ENABLED},
553 (int *)&conf.security.osc52);
555 config_free(&conf);
556}
558static void
559test_section_bell(void)
560{
561 struct config conf = {0};
562 struct context ctx = {.conf = &conf, .section = "bell", .path = "unittest"};
564 test_invalid_key(&ctx, &parse_section_bell, "invalid-key");
566 test_boolean(&ctx, &parse_section_bell, "urgent", &conf.bell.urgent);
567 test_boolean(&ctx, &parse_section_bell, "notify", &conf.bell.notify);
568 test_boolean(&ctx, &parse_section_bell, "system", &conf.bell.system_bell);
569 test_boolean(&ctx, &parse_section_bell, "command-focused",
570 &conf.bell.command_focused);
571 test_spawn_template(&ctx, &parse_section_bell, "command",
572 &conf.bell.command);
574 config_free(&conf);
575}
577static void
578test_section_desktop_notifications(void)
579{
580 struct config conf = {0};
581 struct context ctx = {.conf = &conf, .section = "desktop-notifications", .path = "unittest"};
583 test_invalid_key(&ctx, &parse_section_desktop_notifications, "invalid-key");
585 test_boolean(&ctx, &parse_section_desktop_notifications, "inhibit-when-focused", &conf.desktop_notifications.inhibit_when_focused);
586 test_spawn_template(&ctx, &parse_section_desktop_notifications, "command", &conf.desktop_notifications.command);
587 test_spawn_template(&ctx, &parse_section_desktop_notifications, "command-action-argument", &conf.desktop_notifications.command_action_arg);
588 test_spawn_template(&ctx, &parse_section_desktop_notifications, "close", &conf.desktop_notifications.close);
590 config_free(&conf);
591}
593static void
594test_section_scrollback(void)
595{
596 struct config conf = {0};
597 struct context ctx = {
598 .conf = &conf, .section = "scrollback", .path = "unittest"};
600 test_invalid_key(&ctx, &parse_section_scrollback, "invalid-key");
602 test_uint32(&ctx, &parse_section_scrollback, "lines",
603 &conf.scrollback.lines);
604 test_float(&ctx, parse_section_scrollback, "multiplier", &conf.scrollback.multiplier);
606 test_enum(
607 &ctx, &parse_section_scrollback, "indicator-position",
608 3,
609 (const char *[]){"none", "fixed", "relative"},
610 (int []){SCROLLBACK_INDICATOR_POSITION_NONE,
611 SCROLLBACK_INDICATOR_POSITION_FIXED,
612 SCROLLBACK_INDICATOR_POSITION_RELATIVE},
613 (int *)&conf.scrollback.indicator.position);
615 /* TODO: indicator-format (enum, sort-of) */
617 config_free(&conf);
618}
620static void
621test_section_url(void)
622{
623 struct config conf = {0};
624 struct context ctx = {
625 .conf = &conf, .section = "url", .path = "unittest"};
627 test_invalid_key(&ctx, &parse_section_url, "invalid-key");
629 test_spawn_template(&ctx, &parse_section_url, "launch", &conf.url.launch);
630 test_enum(&ctx, &parse_section_url, "osc8-underline",
631 2,
632 (const char *[]){"url-mode", "always"},
633 (int []){OSC8_UNDERLINE_URL_MODE, OSC8_UNDERLINE_ALWAYS},
634 (int *)&conf.url.osc8_underline);
635 test_enum(&ctx, &parse_section_url, "style",
636 6, (const char *[]){"none", "single", "double", "curly", "dotted", "dashed"},
637 (int []){UNDERLINE_NONE, UNDERLINE_SINGLE, UNDERLINE_DOUBLE, UNDERLINE_CURLY, UNDERLINE_DOTTED, UNDERLINE_DASHED},
638 (int *)&conf.url.style);
639 test_c32string(&ctx, &parse_section_url, "label-letters", &conf.url.label_letters);
641 config_free(&conf);
642}
644static void
645test_section_cursor(void)
646{
647 struct config conf = {0};
648 struct context ctx = {
649 .conf = &conf, .section = "cursor", .path = "unittest"};
651 test_invalid_key(&ctx, &parse_section_cursor, "invalid-key");
653 test_enum(
654 &ctx, &parse_section_cursor, "style",
655 3,
656 (const char *[]){"block", "beam", "underline"},
657 (int []){CURSOR_BLOCK, CURSOR_BEAM, CURSOR_UNDERLINE},
658 (int *)&conf.cursor.style);
659 test_enum(
660 &ctx, &parse_section_cursor, "unfocused-style",
661 3,
662 (const char *[]){"unchanged", "hollow", "none"},
663 (int []){CURSOR_UNFOCUSED_UNCHANGED, CURSOR_UNFOCUSED_HOLLOW, CURSOR_UNFOCUSED_NONE},
664 (int *)&conf.cursor.unfocused_style);
665 test_boolean(&ctx, &parse_section_cursor, "blink", &conf.cursor.blink.enabled);
666 test_uint32(&ctx, &parse_section_cursor, "blink-rate", &conf.cursor.blink.rate_ms);
667 test_pt_or_px(&ctx, &parse_section_cursor, "beam-thickness",
668 &conf.cursor.beam_thickness);
669 test_pt_or_px(&ctx, &parse_section_cursor, "underline-thickness",
670 &conf.cursor.underline_thickness);
672 /* TODO: color (two RRGGBB values) */
674 config_free(&conf);
675}
677static void
678test_section_mouse(void)
679{
680 struct config conf = {0};
681 struct context ctx = {
682 .conf = &conf, .section = "mouse", .path = "unittest"};
684 test_invalid_key(&ctx, &parse_section_mouse, "invalid-key");
686 test_boolean(&ctx, &parse_section_mouse, "hide-when-typing",
687 &conf.mouse.hide_when_typing);
688 test_boolean(&ctx, &parse_section_mouse, "alternate-scroll-mode",
689 &conf.mouse.alternate_scroll_mode);
691 config_free(&conf);
692}
694static void
695test_section_touch(void)
696{
697 struct config conf = {0};
698 struct context ctx = {
699 .conf = &conf, .section = "touch", .path = "unittest"};
701 test_invalid_key(&ctx, &parse_section_touch, "invalid-key");
703 test_uint32(&ctx, &parse_section_touch, "long-press-delay",
704 &conf.touch.long_press_delay);
706 config_free(&conf);
707}
709static void
710test_section_colors_dark(void)
711{
712 struct config conf = {0};
713 struct context ctx = {
714 .conf = &conf, .section = "colors-dark", .path = "unittest"};
716 test_invalid_key(&ctx, &parse_section_colors_dark, "invalid-key");
718 test_color(&ctx, &parse_section_colors_dark, "foreground", false, &conf.colors_dark.fg);
719 test_color(&ctx, &parse_section_colors_dark, "background", false, &conf.colors_dark.bg);
720 test_color(&ctx, &parse_section_colors_dark, "regular0", false, &conf.colors_dark.table[0]);
721 test_color(&ctx, &parse_section_colors_dark, "regular1", false, &conf.colors_dark.table[1]);
722 test_color(&ctx, &parse_section_colors_dark, "regular2", false, &conf.colors_dark.table[2]);
723 test_color(&ctx, &parse_section_colors_dark, "regular3", false, &conf.colors_dark.table[3]);
724 test_color(&ctx, &parse_section_colors_dark, "regular4", false, &conf.colors_dark.table[4]);
725 test_color(&ctx, &parse_section_colors_dark, "regular5", false, &conf.colors_dark.table[5]);
726 test_color(&ctx, &parse_section_colors_dark, "regular6", false, &conf.colors_dark.table[6]);
727 test_color(&ctx, &parse_section_colors_dark, "regular7", false, &conf.colors_dark.table[7]);
728 test_color(&ctx, &parse_section_colors_dark, "bright0", false, &conf.colors_dark.table[8]);
729 test_color(&ctx, &parse_section_colors_dark, "bright1", false, &conf.colors_dark.table[9]);
730 test_color(&ctx, &parse_section_colors_dark, "bright2", false, &conf.colors_dark.table[10]);
731 test_color(&ctx, &parse_section_colors_dark, "bright3", false, &conf.colors_dark.table[11]);
732 test_color(&ctx, &parse_section_colors_dark, "bright4", false, &conf.colors_dark.table[12]);
733 test_color(&ctx, &parse_section_colors_dark, "bright5", false, &conf.colors_dark.table[13]);
734 test_color(&ctx, &parse_section_colors_dark, "bright6", false, &conf.colors_dark.table[14]);
735 test_color(&ctx, &parse_section_colors_dark, "bright7", false, &conf.colors_dark.table[15]);
736 test_color(&ctx, &parse_section_colors_dark, "dim0", false, &conf.colors_dark.dim[0]);
737 test_color(&ctx, &parse_section_colors_dark, "dim1", false, &conf.colors_dark.dim[1]);
738 test_color(&ctx, &parse_section_colors_dark, "dim2", false, &conf.colors_dark.dim[2]);
739 test_color(&ctx, &parse_section_colors_dark, "dim3", false, &conf.colors_dark.dim[3]);
740 test_color(&ctx, &parse_section_colors_dark, "dim4", false, &conf.colors_dark.dim[4]);
741 test_color(&ctx, &parse_section_colors_dark, "dim5", false, &conf.colors_dark.dim[5]);
742 test_color(&ctx, &parse_section_colors_dark, "dim6", false, &conf.colors_dark.dim[6]);
743 test_color(&ctx, &parse_section_colors_dark, "dim7", false, &conf.colors_dark.dim[7]);
744 test_color(&ctx, &parse_section_colors_dark, "selection-foreground", false, &conf.colors_dark.selection_fg);
745 test_color(&ctx, &parse_section_colors_dark, "selection-background", false, &conf.colors_dark.selection_bg);
746 test_color(&ctx, &parse_section_colors_dark, "urls", false, &conf.colors_dark.url);
747 test_two_colors(&ctx, &parse_section_colors_dark, "jump-labels", false,
748 &conf.colors_dark.jump_label.fg,
749 &conf.colors_dark.jump_label.bg);
750 test_two_colors(&ctx, &parse_section_colors_dark, "scrollback-indicator", false,
751 &conf.colors_dark.scrollback_indicator.fg,
752 &conf.colors_dark.scrollback_indicator.bg);
753 test_two_colors(&ctx, &parse_section_colors_dark, "search-box-no-match", false,
754 &conf.colors_dark.search_box.no_match.fg,
755 &conf.colors_dark.search_box.no_match.bg);
756 test_two_colors(&ctx, &parse_section_colors_dark, "search-box-match", false,
757 &conf.colors_dark.search_box.match.fg,
758 &conf.colors_dark.search_box.match.bg);
760 test_two_colors(&ctx, &parse_section_colors_dark, "cursor", false,
761 &conf.colors_dark.cursor.text,
762 &conf.colors_dark.cursor.cursor);
764 test_enum(&ctx, &parse_section_colors_dark, "alpha-mode", 3,
765 (const char *[]){"default", "matching", "all"},
766 (int []){ALPHA_MODE_DEFAULT, ALPHA_MODE_MATCHING, ALPHA_MODE_ALL},
767 (int *)&conf.colors_dark.alpha_mode);
769 test_enum(&ctx, &parse_section_colors_dark, "dim-blend-towards", 2,
770 (const char *[]){"black", "white"},
771 (int []){DIM_BLEND_TOWARDS_BLACK, DIM_BLEND_TOWARDS_WHITE},
772 (int *)&conf.colors_dark.dim_blend_towards);
774 for (size_t i = 0; i < 255; i++) {
775 char key_name[4];
776 sprintf(key_name, "%zu", i);
777 test_color(&ctx, &parse_section_colors_dark, key_name, false,
778 &conf.colors_dark.table[i]);
779 }
781 test_boolean(&ctx, &parse_section_colors_dark, "blur", &conf.colors_dark.blur);
783 test_invalid_key(&ctx, &parse_section_colors_dark, "256");
785 /* TODO: alpha (float in range 0-1, converted to uint16_t) */
787 config_free(&conf);
788}
790static void
791test_section_colors_light(void)
792{
793 struct config conf = {0};
794 struct context ctx = {
795 .conf = &conf, .section = "colors-light", .path = "unittest"};
797 test_invalid_key(&ctx, &parse_section_colors_light, "invalid-key");
799 test_color(&ctx, &parse_section_colors_light, "foreground", false, &conf.colors_light.fg);
800 test_color(&ctx, &parse_section_colors_light, "background", false, &conf.colors_light.bg);
801 test_color(&ctx, &parse_section_colors_light, "regular0", false, &conf.colors_light.table[0]);
802 test_color(&ctx, &parse_section_colors_light, "regular1", false, &conf.colors_light.table[1]);
803 test_color(&ctx, &parse_section_colors_light, "regular2", false, &conf.colors_light.table[2]);
804 test_color(&ctx, &parse_section_colors_light, "regular3", false, &conf.colors_light.table[3]);
805 test_color(&ctx, &parse_section_colors_light, "regular4", false, &conf.colors_light.table[4]);
806 test_color(&ctx, &parse_section_colors_light, "regular5", false, &conf.colors_light.table[5]);
807 test_color(&ctx, &parse_section_colors_light, "regular6", false, &conf.colors_light.table[6]);
808 test_color(&ctx, &parse_section_colors_light, "regular7", false, &conf.colors_light.table[7]);
809 test_color(&ctx, &parse_section_colors_light, "bright0", false, &conf.colors_light.table[8]);
810 test_color(&ctx, &parse_section_colors_light, "bright1", false, &conf.colors_light.table[9]);
811 test_color(&ctx, &parse_section_colors_light, "bright2", false, &conf.colors_light.table[10]);
812 test_color(&ctx, &parse_section_colors_light, "bright3", false, &conf.colors_light.table[11]);
813 test_color(&ctx, &parse_section_colors_light, "bright4", false, &conf.colors_light.table[12]);
814 test_color(&ctx, &parse_section_colors_light, "bright5", false, &conf.colors_light.table[13]);
815 test_color(&ctx, &parse_section_colors_light, "bright6", false, &conf.colors_light.table[14]);
816 test_color(&ctx, &parse_section_colors_light, "bright7", false, &conf.colors_light.table[15]);
817 test_color(&ctx, &parse_section_colors_light, "dim0", false, &conf.colors_light.dim[0]);
818 test_color(&ctx, &parse_section_colors_light, "dim1", false, &conf.colors_light.dim[1]);
819 test_color(&ctx, &parse_section_colors_light, "dim2", false, &conf.colors_light.dim[2]);
820 test_color(&ctx, &parse_section_colors_light, "dim3", false, &conf.colors_light.dim[3]);
821 test_color(&ctx, &parse_section_colors_light, "dim4", false, &conf.colors_light.dim[4]);
822 test_color(&ctx, &parse_section_colors_light, "dim5", false, &conf.colors_light.dim[5]);
823 test_color(&ctx, &parse_section_colors_light, "dim6", false, &conf.colors_light.dim[6]);
824 test_color(&ctx, &parse_section_colors_light, "dim7", false, &conf.colors_light.dim[7]);
825 test_color(&ctx, &parse_section_colors_light, "selection-foreground", false, &conf.colors_light.selection_fg);
826 test_color(&ctx, &parse_section_colors_light, "selection-background", false, &conf.colors_light.selection_bg);
827 test_color(&ctx, &parse_section_colors_light, "urls", false, &conf.colors_light.url);
828 test_two_colors(&ctx, &parse_section_colors_light, "jump-labels", false,
829 &conf.colors_light.jump_label.fg,
830 &conf.colors_light.jump_label.bg);
831 test_two_colors(&ctx, &parse_section_colors_light, "scrollback-indicator", false,
832 &conf.colors_light.scrollback_indicator.fg,
833 &conf.colors_light.scrollback_indicator.bg);
834 test_two_colors(&ctx, &parse_section_colors_light, "search-box-no-match", false,
835 &conf.colors_light.search_box.no_match.fg,
836 &conf.colors_light.search_box.no_match.bg);
837 test_two_colors(&ctx, &parse_section_colors_light, "search-box-match", false,
838 &conf.colors_light.search_box.match.fg,
839 &conf.colors_light.search_box.match.bg);
841 test_two_colors(&ctx, &parse_section_colors_light, "cursor", false,
842 &conf.colors_light.cursor.text,
843 &conf.colors_light.cursor.cursor);
845 test_enum(&ctx, &parse_section_colors_light, "alpha-mode", 3,
846 (const char *[]){"default", "matching", "all"},
847 (int []){ALPHA_MODE_DEFAULT, ALPHA_MODE_MATCHING, ALPHA_MODE_ALL},
848 (int *)&conf.colors_light.alpha_mode);
850 test_enum(&ctx, &parse_section_colors_light, "dim-blend-towards", 2,
851 (const char *[]){"black", "white"},
852 (int []){DIM_BLEND_TOWARDS_BLACK, DIM_BLEND_TOWARDS_WHITE},
853 (int *)&conf.colors_light.dim_blend_towards);
855 for (size_t i = 0; i < 255; i++) {
856 char key_name[4];
857 sprintf(key_name, "%zu", i);
858 test_color(&ctx, &parse_section_colors_light, key_name, false,
859 &conf.colors_light.table[i]);
860 }
862 test_boolean(&ctx, &parse_section_colors_light, "blur", &conf.colors_light.blur);
864 test_invalid_key(&ctx, &parse_section_colors_light, "256");
866 /* TODO: alpha (float in range 0-1, converted to uint16_t) */
868 config_free(&conf);
869}
871static void
872test_section_csd(void)
873{
874 struct config conf = {0};
875 struct context ctx = {
876 .conf = &conf, .section = "csd", .path = "unittest"};
878 test_invalid_key(&ctx, &parse_section_csd, "invalid-key");
880 test_enum(
881 &ctx, &parse_section_csd, "preferred",
882 3,
883 (const char *[]){"none", "client", "server"},
884 (int []){CONF_CSD_PREFER_NONE,
885 CONF_CSD_PREFER_CLIENT,
886 CONF_CSD_PREFER_SERVER},
887 (int *)&conf.csd.preferred);
888 test_uint16(&ctx, &parse_section_csd, "size", &conf.csd.title_height);
889 test_color(&ctx, &parse_section_csd, "color", true, &conf.csd.color.title);
890 test_uint16(&ctx, &parse_section_csd, "border-width",
891 &conf.csd.border_width_visible);
892 test_color(&ctx, &parse_section_csd, "border-color", true,
893 &conf.csd.color.border);
894 test_uint16(&ctx, &parse_section_csd, "button-width",
895 &conf.csd.button_width);
896 test_color(&ctx, &parse_section_csd, "button-color", true,
897 &conf.csd.color.buttons);
898 test_color(&ctx, &parse_section_csd, "button-minimize-color", true,
899 &conf.csd.color.minimize);
900 test_color(&ctx, &parse_section_csd, "button-maximize-color", true,
901 &conf.csd.color.maximize);
902 test_color(&ctx, &parse_section_csd, "button-close-color", true,
903 &conf.csd.color.quit);
904 test_boolean(&ctx, &parse_section_csd, "hide-when-maximized",
905 &conf.csd.hide_when_maximized);
906 test_boolean(&ctx, &parse_section_csd, "double-click-to-maximize",
907 &conf.csd.double_click_to_maximize);
909 /* TODO: verify the ‘set’ bit is actually set for colors */
910 /* TODO: font */
912 config_free(&conf);
913}
915static bool
916have_modifier(const config_modifier_list_t *mods, const char *mod)
917{
918 tll_foreach(*mods, it) {
919 if (strcmp(it->item, mod) == 0)
920 return true;
921 }
923 return false;
924}
926static void
927test_key_binding(struct context *ctx, bool (*parse_fun)(struct context *ctx),
928 int action, int max_action, const char *const *map,
929 struct config_key_binding_list *bindings,
930 enum key_binding_type type, bool need_argv, bool need_section_id)
931{
932 xassert(map[action] != NULL);
933 xassert(bindings->count == 0);
935 const char *key = map[action];
937 /* “Randomize” which modifiers to enable */
938 const bool ctrl = action % 2;
939 const bool alt = action % 3;
940 const bool shift = action % 4;
941 const bool super = action % 5;
942 const bool argv = need_argv;
943 const bool section_id = need_section_id;
945 xassert(!(argv && section_id));
947 static const char *const args[] = {
948 "command", "arg1", "arg2", "arg3 has spaces"};
950 /* Generate the modifier part of the ‘value’ */
951 char modifier_string[32];
952 sprintf(modifier_string, "%s%s%s%s",
953 ctrl ? XKB_MOD_NAME_CTRL "+" : "",
954 alt ? XKB_MOD_NAME_ALT "+" : "",
955 shift ? XKB_MOD_NAME_SHIFT "+" : "",
956 super ? XKB_MOD_NAME_LOGO "+" : "");
958 /* Use a unique symbol for this action (key bindings) */
959 const xkb_keysym_t sym = XKB_KEY_a + action;
961 /* Mouse button (mouse bindings) */
962 const int button_idx = action % ALEN(button_map);
963 const int button = button_map[button_idx].code;
964 const int click_count = action % 3 + 1;
966 /* Finally, generate the ‘value’ (e.g. “Control+shift+x”) */
967 char value[128] = {0};
969 ctx->key = key;
970 ctx->value = value;
972 /* First, try setting the empty string */
973 if (parse_fun(ctx)) {
974 BUG("[%s].%s=<empty>: did not fail to parse as expected",
975 ctx->section, ctx->key);
976 }
978 switch (type) {
979 case KEY_BINDING: {
980 char sym_name[16];
981 xkb_keysym_get_name(sym, sym_name, sizeof(sym_name));
983 snprintf(value, sizeof(value), "%s%s%s",
984 argv ? "[command arg1 arg2 \"arg3 has spaces\"] " : section_id ? "[foobar]" : "",
985 modifier_string, sym_name);
986 break;
987 }
989 case MOUSE_BINDING: {
990 const char *const button_name = button_map[button_idx].name;
991 int chars = snprintf(
992 value, sizeof(value), "%s%s%s",
993 argv ? "[command arg1 arg2 \"arg3 has spaces\"] " : section_id ? "[foobar]" : "",
994 modifier_string, button_name);
996 xassert(click_count > 0);
997 if (click_count > 1)
998 snprintf(&value[chars], sizeof(value) - chars, "-%d", click_count);
999 break;
1000 }
1001 }
1003 if (!parse_fun(ctx)) {
1004 BUG("[%s].%s=%s failed to parse",
1005 ctx->section, ctx->key, ctx->value);
1006 }
1008 const struct config_key_binding *binding =
1009 &bindings->arr[bindings->count - 1];
1011 if (argv) {
1012 if (binding->aux.pipe.args == NULL) {
1013 BUG("[%s].%s=%s: pipe argv is NULL",
1014 ctx->section, ctx->key, ctx->value);
1015 }
1017 for (size_t i = 0; i < ALEN(args); i++) {
1018 if (binding->aux.pipe.args[i] == NULL ||
1019 !streq(binding->aux.pipe.args[i], args[i]))
1020 {
1021 BUG("[%s].%s=%s: pipe argv not the expected one: "
1022 "mismatch of arg #%zu: expected=\"%s\", got=\"%s\"",
1023 ctx->section, ctx->key, ctx->value, i,
1024 args[i], binding->aux.pipe.args[i]);
1025 }
1026 }
1028 if (binding->aux.pipe.args[ALEN(args)] != NULL) {
1029 BUG("[%s].%s=%s: pipe argv not the expected one: "
1030 "expected NULL terminator at arg #%zu, got=\"%s\"",
1031 ctx->section, ctx->key, ctx->value,
1032 ALEN(args), binding->aux.pipe.args[ALEN(args)]);
1033 }
1034 } else if (section_id) {
1035 if (binding->aux.regex_name == NULL) {
1036 BUG("[%s].%s=%s: regex name is NULL",
1037 ctx->section, ctx->key, ctx->value);
1038 }
1040 if (!streq(binding->aux.regex_name, "foobar")) {
1041 BUG("[%s].%s=%s: regex name not the expected one: "
1042 "expected=\"%s\", got=\"%s\"",
1043 ctx->section, ctx->key, ctx->value,
1044 "foobar", binding->aux.regex_name);
1045 }
1046 } else {
1047 if (binding->aux.pipe.args != NULL) {
1048 BUG("[%s].%s=%s: pipe argv not NULL",
1049 ctx->section, ctx->key, ctx->value);
1050 }
1051 }
1053 if (binding->action != action) {
1054 BUG("[%s].%s=%s: action mismatch: %d != %d",
1055 ctx->section, ctx->key, ctx->value, binding->action, action);
1056 }
1058 bool have_ctrl = have_modifier(&binding->modifiers, XKB_MOD_NAME_CTRL);
1059 bool have_alt = have_modifier(&binding->modifiers, XKB_MOD_NAME_ALT);
1060 bool have_shift = have_modifier(&binding->modifiers, XKB_MOD_NAME_SHIFT);
1061 bool have_super = have_modifier(&binding->modifiers, XKB_MOD_NAME_LOGO);
1063 if (have_ctrl != ctrl || have_alt != alt ||
1064 have_shift != shift || have_super != super)
1065 {
1066 BUG("[%s].%s=%s: modifier mismatch:\n"
1067 " have: ctrl=%d, alt=%d, shift=%d, super=%d\n"
1068 " expected: ctrl=%d, alt=%d, shift=%d, super=%d",
1069 ctx->section, ctx->key, ctx->value,
1070 have_ctrl, have_alt, have_shift, have_super,
1071 ctrl, alt, shift, super);
1072 }
1074 switch (type) {
1075 case KEY_BINDING:
1076 if (binding->k.sym != sym) {
1077 BUG("[%s].%s=%s: key symbol mismatch: %d != %d",
1078 ctx->section, ctx->key, ctx->value, binding->k.sym, sym);
1079 }
1080 break;
1082 case MOUSE_BINDING:;
1083 if (binding->m.button != button) {
1084 BUG("[%s].%s=%s: mouse button mismatch: %d != %d",
1085 ctx->section, ctx->key, ctx->value, binding->m.button, button);
1086 }
1088 if (binding->m.count != click_count) {
1089 BUG("[%s].%s=%s: mouse button click count mismatch: %d != %d",
1090 ctx->section, ctx->key, ctx->value,
1091 binding->m.count, click_count);
1092 }
1093 break;
1094 }
1097 free_key_binding_list(bindings);
1098}
1100enum collision_test_mode {
1101 FAIL_DIFFERENT_ACTION,
1102 FAIL_DIFFERENT_ARGV,
1103 FAIL_MOUSE_OVERRIDE,
1104 SUCCEED_SAME_ACTION_AND_ARGV,
1105};
1107static void
1108_test_binding_collisions(struct context *ctx,
1109 int max_action, const char *const *map,
1110 enum key_binding_type type,
1111 enum collision_test_mode test_mode)
1112{
1113 struct config_key_binding *bindings_array =
1114 xcalloc(2, sizeof(bindings_array[0]));
1116 struct config_key_binding_list bindings = {
1117 .count = 2,
1118 .arr = bindings_array,
1119 };
1121 /* First, verify we get a collision when trying to assign the same
1122 * key combo to multiple actions */
1123 bindings.arr[0] = (struct config_key_binding){
1124 .action = (test_mode == FAIL_DIFFERENT_ACTION
1125 ? max_action - 1 : max_action),
1126 .modifiers = tll_init(),
1127 .path = "unittest",
1128 };
1129 tll_push_back(bindings.arr[0].modifiers, xstrdup(XKB_MOD_NAME_CTRL));
1131 bindings.arr[1] = (struct config_key_binding){
1132 .action = max_action,
1133 .modifiers = tll_init(),
1134 .path = "unittest",
1135 };
1136 tll_push_back(bindings.arr[1].modifiers, xstrdup(XKB_MOD_NAME_CTRL));
1138 switch (type) {
1139 case KEY_BINDING:
1140 bindings.arr[0].k.sym = XKB_KEY_a;
1141 bindings.arr[1].k.sym = XKB_KEY_a;
1142 break;
1144 case MOUSE_BINDING:
1145 bindings.arr[0].m.button = BTN_LEFT;
1146 bindings.arr[0].m.count = 1;
1147 bindings.arr[1].m.button = BTN_LEFT;
1148 bindings.arr[1].m.count = 1;
1149 break;
1150 }
1152 switch (test_mode) {
1153 case FAIL_DIFFERENT_ACTION:
1154 break;
1156 case FAIL_MOUSE_OVERRIDE:
1157 tll_free_and_free(ctx->conf->mouse.selection_override_modifiers, free);
1158 tll_push_back(ctx->conf->mouse.selection_override_modifiers, xstrdup(XKB_MOD_NAME_CTRL));
1159 break;
1161 case FAIL_DIFFERENT_ARGV:
1162 case SUCCEED_SAME_ACTION_AND_ARGV:
1163 bindings.arr[0].aux.type = BINDING_AUX_PIPE;
1164 bindings.arr[0].aux.master_copy = true;
1165 bindings.arr[0].aux.pipe.args = xcalloc(
1166 4, sizeof(bindings.arr[0].aux.pipe.args[0]));
1167 bindings.arr[0].aux.pipe.args[0] = xstrdup("/usr/bin/foobar");
1168 bindings.arr[0].aux.pipe.args[1] = xstrdup("hello");
1169 bindings.arr[0].aux.pipe.args[2] = xstrdup("world");
1171 bindings.arr[1].aux.type = BINDING_AUX_PIPE;
1172 bindings.arr[1].aux.master_copy = true;
1173 bindings.arr[1].aux.pipe.args = xcalloc(
1174 4, sizeof(bindings.arr[1].aux.pipe.args[0]));
1175 bindings.arr[1].aux.pipe.args[0] = xstrdup("/usr/bin/foobar");
1176 bindings.arr[1].aux.pipe.args[1] = xstrdup("hello");
1178 if (test_mode == SUCCEED_SAME_ACTION_AND_ARGV)
1179 bindings.arr[1].aux.pipe.args[2] = xstrdup("world");
1180 break;
1181 }
1183 bool expected_result =
1184 test_mode == SUCCEED_SAME_ACTION_AND_ARGV ? true : false;
1186 if (resolve_key_binding_collisions(
1187 ctx->conf, ctx->section, map, &bindings, type) != expected_result)
1188 {
1189 BUG("[%s].%s vs. %s: %s",
1190 ctx->section, map[max_action - 1], map[max_action],
1191 (expected_result == true
1192 ? "invalid key combo collision detected"
1193 : "key combo collision not detected"));
1194 }
1196 if (expected_result == false) {
1197 if (bindings.count != 1)
1198 BUG("[%s]: colliding binding not removed", ctx->section);
1200 if (bindings.arr[0].action !=
1201 (test_mode == FAIL_DIFFERENT_ACTION ? max_action - 1 : max_action))
1202 {
1203 BUG("[%s]: wrong binding removed", ctx->section);
1204 }
1205 }
1207 free_key_binding_list(&bindings);
1208}
1210static void
1211test_binding_collisions(struct context *ctx,
1212 int max_action, const char *const *map,
1213 enum key_binding_type type)
1214{
1215 _test_binding_collisions(ctx, max_action, map, type, FAIL_DIFFERENT_ACTION);
1216 _test_binding_collisions(ctx, max_action, map, type, FAIL_DIFFERENT_ARGV);
1217 _test_binding_collisions(ctx, max_action, map, type, SUCCEED_SAME_ACTION_AND_ARGV);
1219 if (type == MOUSE_BINDING) {
1220 _test_binding_collisions(
1221 ctx, max_action, map, type, FAIL_MOUSE_OVERRIDE);
1222 }
1223}
1225static void
1226test_section_key_bindings(void)
1227{
1228 struct config conf = {0};
1229 struct context ctx = {
1230 .conf = &conf, .section = "key-bindings", .path = "unittest"};
1232 test_invalid_key(&ctx, &parse_section_key_bindings, "invalid-key");
1234 for (int action = 0; action < BIND_ACTION_KEY_COUNT; action++) {
1235 if (binding_action_map[action] == NULL)
1236 continue;
1238 test_key_binding(
1239 &ctx, &parse_section_key_bindings,
1240 action, BIND_ACTION_KEY_COUNT - 1,
1241 binding_action_map, &conf.bindings.key, KEY_BINDING,
1242 action >= BIND_ACTION_PIPE_SCROLLBACK && action <= BIND_ACTION_PIPE_COMMAND_OUTPUT,
1243 action >= BIND_ACTION_REGEX_LAUNCH && action <= BIND_ACTION_REGEX_COPY);
1244 }
1246 config_free(&conf);
1247}
1249static void
1250test_section_key_bindings_collisions(void)
1251{
1252 struct config conf = {0};
1253 struct context ctx = {
1254 .conf = &conf, .section = "key-bindings", .path = "unittest"};
1256 test_binding_collisions(
1257 &ctx, BIND_ACTION_KEY_COUNT - 1, binding_action_map, KEY_BINDING);
1259 config_free(&conf);
1260}
1262static void
1263test_section_search_bindings(void)
1264{
1265 struct config conf = {0};
1266 struct context ctx = {
1267 .conf = &conf, .section = "search-bindings", .path = "unittest"};
1269 test_invalid_key(&ctx, &parse_section_search_bindings, "invalid-key");
1271 for (int action = 0; action < BIND_ACTION_SEARCH_COUNT; action++) {
1272 if (search_binding_action_map[action] == NULL)
1273 continue;
1275 test_key_binding(
1276 &ctx, &parse_section_search_bindings,
1277 action, BIND_ACTION_SEARCH_COUNT - 1,
1278 search_binding_action_map, &conf.bindings.search, KEY_BINDING,
1279 false, false);
1280 }
1282 config_free(&conf);
1283}
1285static void
1286test_section_search_bindings_collisions(void)
1287{
1288 struct config conf = {0};
1289 struct context ctx = {
1290 .conf = &conf, .section = "search-bindings", .path = "unittest"};
1292 test_binding_collisions(
1293 &ctx,
1294 BIND_ACTION_SEARCH_COUNT - 1, search_binding_action_map, KEY_BINDING);
1296 config_free(&conf);
1297}
1299static void
1300test_section_url_bindings(void)
1301{
1302 struct config conf = {0};
1303 struct context ctx = {
1304 .conf = &conf, .section = "rul-bindings", .path = "unittest"};
1306 test_invalid_key(&ctx, &parse_section_url_bindings, "invalid-key");
1308 for (int action = 0; action < BIND_ACTION_URL_COUNT; action++) {
1309 if (url_binding_action_map[action] == NULL)
1310 continue;
1312 test_key_binding(
1313 &ctx, &parse_section_url_bindings,
1314 action, BIND_ACTION_URL_COUNT - 1,
1315 url_binding_action_map, &conf.bindings.url, KEY_BINDING,
1316 false, false);
1317 }
1319 config_free(&conf);
1320}
1322static void
1323test_section_url_bindings_collisions(void)
1324{
1325 struct config conf = {0};
1326 struct context ctx = {
1327 .conf = &conf, .section = "url-bindings", .path = "unittest"};
1329 test_binding_collisions(
1330 &ctx,
1331 BIND_ACTION_URL_COUNT - 1, url_binding_action_map, KEY_BINDING);
1333 config_free(&conf);
1334}
1336static void
1337test_section_mouse_bindings(void)
1338{
1339 struct config conf = {0};
1340 struct context ctx = {
1341 .conf = &conf, .section = "mouse-bindings", .path = "unittest"};
1343 test_invalid_key(&ctx, &parse_section_mouse_bindings, "invalid-key");
1345 for (int action = 0; action < BIND_ACTION_COUNT; action++) {
1346 if (binding_action_map[action] == NULL)
1347 continue;
1349 test_key_binding(
1350 &ctx, &parse_section_mouse_bindings,
1351 action, BIND_ACTION_COUNT - 1,
1352 binding_action_map, &conf.bindings.mouse, MOUSE_BINDING,
1353 false, false);
1354 }
1356 config_free(&conf);
1357}
1359static void
1360test_section_mouse_bindings_collisions(void)
1361{
1362 struct config conf = {0};
1363 struct context ctx = {
1364 .conf = &conf, .section = "mouse-bindings", .path = "unittest"};
1366 test_binding_collisions(
1367 &ctx,
1368 BIND_ACTION_COUNT - 1, binding_action_map, MOUSE_BINDING);
1370 config_free(&conf);
1371}
1373static void
1374test_section_text_bindings(void)
1375{
1376 struct config conf = {0};
1377 struct context ctx = {
1378 .conf = &conf, .section = "text-bindings", .path = "unittest"};
1380 ctx.key = "abcd";
1381 ctx.value = XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT "+x";
1382 xassert(parse_section_text_bindings(&ctx));
1384 ctx.key = "\\x07";
1385 xassert(parse_section_text_bindings(&ctx));
1387 ctx.key = "\\x1g";
1388 xassert(!parse_section_text_bindings(&ctx));
1390 ctx.key = "\\x1";
1391 xassert(!parse_section_text_bindings(&ctx));
1393 ctx.key = "\\x";
1394 xassert(!parse_section_text_bindings(&ctx));
1396 ctx.key = "\\";
1397 xassert(!parse_section_text_bindings(&ctx));
1399 ctx.key = "\\y";
1400 xassert(!parse_section_text_bindings(&ctx));
1402#if 0
1403 /* Invalid modifier and key names are detected later, when a
1404 * layout is applied */
1405 ctx.key = "abcd";
1406 ctx.value = "InvalidMod+y";
1407 xassert(!parse_section_text_bindings(&ctx));
1408#endif
1409 config_free(&conf);
1410}
1412static void
1413test_section_environment(void)
1414{
1415 struct config conf = {0};
1416 struct context ctx = {
1417 .conf = &conf, .section = "environment", .path = "unittest"};
1419 /* A single variable */
1420 ctx.key = "FOO";
1421 ctx.value = "bar";
1422 xassert(parse_section_environment(&ctx));
1423 xassert(tll_length(conf.env_vars) == 1);
1424 xassert(streq(tll_front(conf.env_vars).name, "FOO"));
1425 xassert(streq(tll_front(conf.env_vars).value, "bar"));
1427 /* Add a second variable */
1428 ctx.key = "BAR";
1429 ctx.value = "123";
1430 xassert(parse_section_environment(&ctx));
1431 xassert(tll_length(conf.env_vars) == 2);
1432 xassert(streq(tll_back(conf.env_vars).name, "BAR"));
1433 xassert(streq(tll_back(conf.env_vars).value, "123"));
1435 /* Replace the *value* of the first variable */
1436 ctx.key = "FOO";
1437 ctx.value = "456";
1438 xassert(parse_section_environment(&ctx));
1439 xassert(tll_length(conf.env_vars) == 2);
1440 xassert(streq(tll_front(conf.env_vars).name, "FOO"));
1441 xassert(streq(tll_front(conf.env_vars).value, "456"));
1442 xassert(streq(tll_back(conf.env_vars).name, "BAR"));
1443 xassert(streq(tll_back(conf.env_vars).value, "123"));
1445 config_free(&conf);
1446}
1448static void
1449test_section_tweak(void)
1450{
1451 struct config conf = {0};
1452 struct context ctx = {
1453 .conf = &conf, .section = "tweak", .path = "unittest"};
1455 test_invalid_key(&ctx, &parse_section_tweak, "invalid-key");
1457 test_enum(
1458 &ctx, &parse_section_tweak, "scaling-filter",
1459 5,
1460 (const char *[]){"none", "nearest", "bilinear", "cubic", "lanczos3"},
1461 (int []){FCFT_SCALING_FILTER_NONE,
1462 FCFT_SCALING_FILTER_NEAREST,
1463 FCFT_SCALING_FILTER_BILINEAR,
1464 FCFT_SCALING_FILTER_CUBIC,
1465 FCFT_SCALING_FILTER_LANCZOS3},
1466 (int *)&conf.tweak.fcft_filter);
1468 test_boolean(&ctx, &parse_section_tweak, "overflowing-glyphs",
1469 &conf.tweak.overflowing_glyphs);
1471 test_enum(
1472 &ctx, &parse_section_tweak, "render-timer",
1473 4,
1474 (const char *[]){"none", "osd", "log", "both"},
1475 (int []){RENDER_TIMER_NONE,
1476 RENDER_TIMER_OSD,
1477 RENDER_TIMER_LOG,
1478 RENDER_TIMER_BOTH},
1479 (int *)&conf.tweak.render_timer);
1481 test_float(&ctx, &parse_section_tweak, "box-drawing-base-thickness",
1482 &conf.tweak.box_drawing_base_thickness);
1483 test_boolean(&ctx, &parse_section_tweak, "box-drawing-solid-shades",
1484 &conf.tweak.box_drawing_solid_shades);
1486#if 0 /* Must be less than 16ms */
1487 test_uint32(&ctx, &parse_section_tweak, "delayed-render-lower",
1488 &conf.tweak.delayed_render_lower_ns);
1489 test_uint32(&ctx, &parse_section_tweak, "delayed-render-upper",
1490 &conf.tweak.delayed_render_upper_ns);
1491#endif
1492 test_boolean(&ctx, &parse_section_tweak, "damage-whole-window",
1493 &conf.tweak.damage_whole_window);
1495#if defined(FOOT_GRAPHEME_CLUSTERING)
1496 test_boolean(&ctx, &parse_section_tweak, "grapheme-shaping",
1497 &conf.tweak.grapheme_shaping);
1498#else
1499 /* TODO: the setting still exists, but is always forced to ‘false’. */
1500#endif
1502 test_enum(
1503 &ctx, &parse_section_tweak, "grapheme-width-method",
1504 3,
1505 (const char *[]){"wcswidth", "double-width", "max"},
1506 (int []){GRAPHEME_WIDTH_WCSWIDTH,
1507 GRAPHEME_WIDTH_DOUBLE,
1508 GRAPHEME_WIDTH_MAX},
1509 (int *)&conf.tweak.grapheme_width_method);
1511 test_boolean(&ctx, &parse_section_tweak, "font-monospace-warn",
1512 &conf.tweak.font_monospace_warn);
1514 test_float(&ctx, &parse_section_tweak, "bold-text-in-bright-amount",
1515 &conf.bold_in_bright.amount);
1517 test_uint32(&ctx, &parse_section_tweak, "min-stride-alignment",
1518 &conf.tweak.min_stride_alignment);
1520#if 0 /* Must be equal to, or less than INT32_MAX */
1521 test_uint32(&ctx, &parse_section_tweak, "max-shm-pool-size-mb",
1522 &conf.tweak.max_shm_pool_size);
1523#endif
1525 config_free(&conf);
1526}
1528int
1529main(int argc, const char *const *argv)
1530{
1531 FcInit();
1532 log_init(LOG_COLORIZE_AUTO, false, 0, LOG_CLASS_ERROR);
1533 test_section_main();
1534 test_section_security();
1535 test_section_bell();
1536 test_section_desktop_notifications();
1537 test_section_scrollback();
1538 test_section_url();
1539 test_section_cursor();
1540 test_section_mouse();
1541 test_section_touch();
1542 test_section_colors_dark();
1543 test_section_colors_light();
1544 test_section_csd();
1545 test_section_key_bindings();
1546 test_section_key_bindings_collisions();
1547 test_section_search_bindings();
1548 test_section_search_bindings_collisions();
1549 test_section_url_bindings();
1550 test_section_url_bindings_collisions();
1551 test_section_mouse_bindings();
1552 test_section_mouse_bindings_collisions();
1553 test_section_text_bindings();
1554 test_section_environment();
1555 test_section_tweak();
1556 log_deinit();
1557 FcFini();
1558 return 0;
1559}
Diagnostics5 git calls · 839 ms
CallStatusSizeTime0839 ms
discover200178 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=178 git.server.agent=git/2.56.1-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=178 git.pkt.payload.max=35
ls-refs20010 KiB2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=10322 git.response.cache=UPDATING git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=108 git.pkt.data=107 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=10322 git.pkt.payload.max=106 git.ls_refs.count=107 git.ls_refs.head=refs/heads/master
fetchcombine:blob:none+tree:2 · deepen 12008.6 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=8830 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=8830 git.pkt.payload.max=8730 git.sideband.band1.bytes=8730 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=14 git.pack.bytes=8730 git.fetch.wide.objects=14 git.fetch.wide.extra_bytes=9909 git.fetch.wide.blobs=0
fetchtree:0 · deepen 102009.3 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=834 git.response.bytes=9489 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=9489 git.pkt.payload.max=9389 git.sideband.band1.bytes=9389 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=9389 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=de930681b6073ba5b599a0f956bfbd114762ad5a git.pack.full=10Open pack map
fetch2008.7 KiB834 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=8947 git.response.cache=MISS git.response.duration_ms=834 git.fetch.wants=4fff7f0c4dd4eab6713411944f72c2323befe2f7 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=8947 git.pkt.payload.max=8920 git.sideband.band1.bytes=8920 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://codeberg.org/dnkl/foot
- Ref
- refs/heads/master
- Commit
- c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
- cf-ray
- a5e2bc778ce0cfc3
- Request
- 43288b41…
- Protocol
- v2 · sha1
- Agent
- git/2.56.1-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format