Files

49 lines
1.4 KiB
C
Raw Permalink Normal View History

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xkbcommon/xkbcommon.h>
#include "config.h"
int main(void) {
uint32_t mods;
char *key = NULL;
assert(config_parse_mods("ctrl+q", &mods, &key) == 0);
assert(mods == MOD_CTRL);
assert(strcmp(key, "q") == 0);
free(key);
assert(config_parse_mods("space", &mods, &key) == 0);
assert(mods == 0);
assert(strcmp(key, "space") == 0);
free(key);
assert(config_parse_action("quit") == ACTION_QUIT);
assert(config_parse_action("select:glider") == ACTION_SELECT_GLIDER);
assert(config_parse_action("nope") == ACTION_NONE);
config_t cfg = config_defaults();
xkb_keysym_t one = xkb_keysym_from_name("1", XKB_KEYSYM_CASE_INSENSITIVE);
xkb_keysym_t space = xkb_keysym_from_name("space", XKB_KEYSYM_CASE_INSENSITIVE);
assert(config_lookup(&cfg, 0, one) == ACTION_SELECT_GLIDER);
assert(config_lookup(&cfg, 0, space) == ACTION_ROTATE);
const char *path = "/tmp/opencode/test_keys.conf";
FILE *fp = fopen(path, "w");
assert(fp);
fputs("[bindings]\n\"1\" = \"quit\"\n", fp);
fclose(fp);
config_t cfg2 = config_load(path);
assert(config_lookup(&cfg2, 0, one) == ACTION_QUIT);
assert(config_lookup(&cfg2, 0, space) == ACTION_ROTATE);
config_free(&cfg);
config_free(&cfg2);
remove(path);
printf("config tests passed\n");
return 0;
}