|
Packit Service |
50ad14 |
#include <stdio.h>
|
|
Packit Service |
50ad14 |
#include <stdlib.h>
|
|
Packit Service |
50ad14 |
#include <check.h>
|
|
Packit Service |
50ad14 |
#include <keymap.h>
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
#include "modifiers.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
struct modifier {
|
|
Packit Service |
50ad14 |
const char *name;
|
|
Packit Service |
50ad14 |
const int bit;
|
|
Packit Service |
50ad14 |
const char ch;
|
|
Packit Service |
50ad14 |
};
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
START_TEST(test_parse_0)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int c;
|
|
Packit Service |
50ad14 |
lkfile_t f;
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
lk_set_log_fn(ctx, NULL, NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
f.pipe = 0;
|
|
Packit Service |
50ad14 |
strcpy(f.pathname, "keymap0.map");
|
|
Packit Service |
50ad14 |
f.fd = fopen(DATADIR "/keymap0.map", "r");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 16);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'q', "Unable to get keycode 16");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 17);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'w', "Unable to get keycode 17");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 18);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'e', "Unable to get keycode 18");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 19);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'r', "Unable to get keycode 19");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 20);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 't', "Unable to get keycode 20");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 21);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'y', "Unable to get keycode 21");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
END_TEST
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
START_TEST(test_parse_1)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int c;
|
|
Packit Service |
50ad14 |
lkfile_t f;
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
lk_set_log_fn(ctx, NULL, NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
f.pipe = 0;
|
|
Packit Service |
50ad14 |
strcpy(f.pathname, "keymap1.map");
|
|
Packit Service |
50ad14 |
f.fd = fopen(DATADIR "/keymap1.map", "r");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 16);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'q', "Unable to get keycode");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 1, 16);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'Q', "Unable to get keycode");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
END_TEST
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
START_TEST(test_parse_2)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int i = 0;
|
|
Packit Service |
50ad14 |
lkfile_t f;
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
lk_set_log_fn(ctx, NULL, NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
f.pipe = 0;
|
|
Packit Service |
50ad14 |
strcpy(f.pathname, "keymap2.map");
|
|
Packit Service |
50ad14 |
f.fd = fopen(DATADIR "/keymap2.map", "r");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
while (i < MAX_NR_KEYMAPS) {
|
|
Packit Service |
50ad14 |
int c = lk_get_key(ctx, i, 17);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'x', "Unable to get keycode");
|
|
Packit Service |
50ad14 |
i++;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
END_TEST
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
START_TEST(test_parse_3)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int i;
|
|
Packit Service |
50ad14 |
char str[] = "qwertyuiopasdfghjklzxcvbnm";
|
|
Packit Service |
50ad14 |
lkfile_t f;
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
lk_set_log_fn(ctx, NULL, NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
f.pipe = 0;
|
|
Packit Service |
50ad14 |
strcpy(f.pathname, "keymap3.map");
|
|
Packit Service |
50ad14 |
f.fd = fopen(DATADIR "/keymap3.map", "r");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
for (i = 0; i < 26; i++) {
|
|
Packit Service |
50ad14 |
int c = lk_get_key(ctx, i, 17);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != str[i], "Unable to get keycode");
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
END_TEST
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
START_TEST(test_parse_4)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int c;
|
|
Packit Service |
50ad14 |
lkfile_t f;
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
lk_set_log_fn(ctx, NULL, NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
f.pipe = 0;
|
|
Packit Service |
50ad14 |
strcpy(f.pathname, "keymap4.map");
|
|
Packit Service |
50ad14 |
f.fd = fopen(DATADIR "/keymap4.map", "r");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 16);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'q', "Unable to get keycode");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 17);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'w', "Include40.map failed");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
c = lk_get_key(ctx, 0, 18);
|
|
Packit Service |
50ad14 |
fail_if(KVAL(c) != 'e', "Include41.map failed");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
END_TEST
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
START_TEST(test_parse_5)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int i;
|
|
Packit Service |
50ad14 |
lkfile_t f;
|
|
Packit Service |
50ad14 |
struct kbsentry kbs;
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
lk_set_log_fn(ctx, NULL, NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
f.pipe = 0;
|
|
Packit Service |
50ad14 |
strcpy(f.pathname, "keymap5.map");
|
|
Packit Service |
50ad14 |
f.fd = fopen(DATADIR "/keymap5.map", "r");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
for (i = 0; i < MAX_NR_FUNC; i++) {
|
|
Packit Service |
50ad14 |
kbs.kb_func = i;
|
|
Packit Service |
50ad14 |
kbs.kb_string[0] = 0;
|
|
Packit Service |
50ad14 |
fail_if(lk_get_func(ctx, &kbs) != 0,
|
|
Packit Service |
50ad14 |
"Unable to get func %d", i);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
END_TEST
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
START_TEST(test_parse_6)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
lkfile_t f;
|
|
Packit Service |
50ad14 |
struct kbsentry kbs;
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
lk_set_log_fn(ctx, NULL, NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
f.pipe = 0;
|
|
Packit Service |
50ad14 |
strcpy(f.pathname, "keymap6.map");
|
|
Packit Service |
50ad14 |
f.fd = fopen(DATADIR "/keymap6.map", "r");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
kbs.kb_func = 0;
|
|
Packit Service |
50ad14 |
kbs.kb_string[0] = 0;
|
|
Packit Service |
50ad14 |
fail_if(lk_get_func(ctx, &kbs) != 0, "Unable to get func 0");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
kbs.kb_func = 1;
|
|
Packit Service |
50ad14 |
kbs.kb_string[0] = 0;
|
|
Packit Service |
50ad14 |
fail_if(lk_get_func(ctx, &kbs) != 0, "Unable to get func 1");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
kbs.kb_func = 2;
|
|
Packit Service |
50ad14 |
kbs.kb_string[0] = 0;
|
|
Packit Service |
50ad14 |
fail_if(lk_get_func(ctx, &kbs) != -1, "Possible to get not alloced func");
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
END_TEST
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
static Suite *
|
|
Packit Service |
50ad14 |
libkeymap_suite(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
Suite *s = suite_create("libkeymap");
|
|
Packit Service |
50ad14 |
TCase *tc_core = tcase_create(NULL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
setenv("LOADKEYS_INCLUDE_PATH", DATADIR, 1);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
tcase_add_test(tc_core, test_parse_0);
|
|
Packit Service |
50ad14 |
tcase_add_test(tc_core, test_parse_1);
|
|
Packit Service |
50ad14 |
tcase_add_test(tc_core, test_parse_2);
|
|
Packit Service |
50ad14 |
tcase_add_test(tc_core, test_parse_3);
|
|
Packit Service |
50ad14 |
tcase_add_test(tc_core, test_parse_4);
|
|
Packit Service |
50ad14 |
tcase_add_test(tc_core, test_parse_5);
|
|
Packit Service |
50ad14 |
tcase_add_test(tc_core, test_parse_6);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
suite_add_tcase(s, tc_core);
|
|
Packit Service |
50ad14 |
return s;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
int main(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int number_failed;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
Suite *s = libkeymap_suite();
|
|
Packit Service |
50ad14 |
SRunner *sr = srunner_create(s);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
srunner_run_all(sr, CK_NORMAL);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
number_failed = srunner_ntests_failed(sr);
|
|
Packit Service |
50ad14 |
srunner_free(sr);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
Packit Service |
50ad14 |
}
|