1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <windows.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "../config.c"
int main(void) {
const char *path = "config-test.tmp";
FILE *file = fopen(path, "w");
assert(file);
fputs("# comment\nalt + shift + return\n echo first +1\n echo obsolete\n"
"ctrl + f12\n echo second\n"
"alt + shift + return\n echo replacement\n :vd pin-app\n :vd app-pin-status\n"
"win + =65\n echo numeric\n"
"alt + 1\n :vd goto-desktop 1\n"
"alt + shift + 0\n :vd move-to-desktop 0\n"
"ctrl + alt + f11\n :quit\n", file);
fclose(file);
assert(load_config(path));
assert(binding_count == 8);
assert(bindings[0].key == VK_F12 && bindings[0].mod == MOD_CONTROL);
assert(bindings[1].key == VK_RETURN && bindings[1].mod == (MOD_ALT | MOD_SHIFT));
assert(strcmp(bindings[1].command, "echo replacement") == 0);
assert(bindings[2].action == PLUGIN && strcmp(bindings[2].plugin_action, "pin-app") == 0);
assert(bindings[3].action == PLUGIN && strcmp(bindings[3].plugin_action, "app-pin-status") == 0);
assert(bindings[4].key == 'A' && bindings[4].mod == MOD_WIN);
assert(bindings[5].action == PLUGIN && strcmp(bindings[5].plugin_name, "vd") == 0);
assert(strcmp(bindings[5].plugin_action, "goto-desktop") == 0);
assert(strcmp(bindings[5].plugin_args, "1") == 0);
assert(bindings[6].action == PLUGIN && strcmp(bindings[6].plugin_action, "move-to-desktop") == 0);
assert(strcmp(bindings[6].plugin_args, "0") == 0);
assert(bindings[7].action == QUIT);
free_bindings();
file = fopen(path, "w");
assert(file);
fputs("alt + release + a\n echo unsupported\n", file);
fclose(file);
assert(!load_config(path));
assert(binding_count == 0);
file = fopen(path, "w");
assert(file);
fputs("alt + a\nalt + b\n echo b\n", file);
fclose(file);
assert(!load_config(path));
assert(binding_count == 0);
file = fopen(path, "w");
assert(file);
fputs("alt + 1\n :../evil run now\n", file);
fclose(file);
assert(!load_config(path));
assert(binding_count == 0);
file = fopen(path, "w");
assert(file);
fputs("alt + 1\n :vd.move-to-desktop 2\n", file);
fclose(file);
assert(!load_config(path));
assert(binding_count == 0);
remove(path);
return 0;
}