Imported Upstream version 2.0.90
[platform/upstream/kbd.git] / tests / libkeymap-test11.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <error.h>
5 #include <errno.h>
6
7 #include <keymap.h>
8
9 int
10 main(void)
11 {
12         FILE *f = NULL;
13         struct kbdfile *fp = NULL;
14         struct kbdfile_ctx *kbdfile_ctx;
15         struct kbsentry kbs;
16         struct lk_ctx *ctx;
17
18         kbdfile_ctx = kbdfile_context_new();
19         if (!kbdfile_ctx)
20                 error(EXIT_FAILURE, 0, "Unable to create kbdfile context");
21
22         fp = kbdfile_new(kbdfile_ctx);
23         if (!fp)
24                 error(EXIT_FAILURE, 0, "Unable to create kbdfile");
25
26         ctx = lk_init();
27         lk_set_log_fn(ctx, NULL, NULL);
28
29         kbdfile_set_pathname(fp, "keymap6.map");
30
31         f = fopen(DATADIR "/data/libkeymap/keymap6.map", "r");
32         if (!f)
33                 error(EXIT_FAILURE, 0, "Unable to open: " DATADIR "/data/libkeymap/keymap6.map: %s", strerror(errno));
34
35         kbdfile_set_file(fp, f);
36
37         if (lk_parse_keymap(ctx, fp) != 0)
38                 error(EXIT_FAILURE, 0, "Unable to parse keymap");
39
40         kbs.kb_func      = 0;
41         kbs.kb_string[0] = 0;
42         if (lk_get_func(ctx, &kbs) != 0)
43                 error(EXIT_FAILURE, 0, "Unable to get func 0");
44
45         kbs.kb_func      = 1;
46         kbs.kb_string[0] = 0;
47         if (lk_get_func(ctx, &kbs) != 0)
48                 error(EXIT_FAILURE, 0, "Unable to get func 1");
49
50         kbs.kb_func      = 2;
51         kbs.kb_string[0] = 0;
52         if (lk_get_func(ctx, &kbs) != -1)
53                 error(EXIT_FAILURE, 0, "Possible to get not alloced func");
54
55         kbdfile_free(fp);
56         kbdfile_context_free(kbdfile_ctx);
57         lk_free(ctx);
58
59         return EXIT_SUCCESS;
60 }