2 * Copyright 2009 Dan Nicholson
3 * Copyright © 2012 Daniel Stone
4 * Copyright © 2012 Ran Benita
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Except as contained in this notice, the names of the authors or their
24 * institutions shall not be used in advertising or otherwise to promote the
25 * sale, use or other dealings in this Software without prior written
26 * authorization from the authors.
36 #include <sys/types.h>
38 #include <sys/syslog.h>
40 #include "xkbcommon/xkbcommon.h"
44 test_get_path(const char *path_rel)
46 static char path[PATH_MAX];
47 const char *srcdir = getenv("srcdir");
49 snprintf(path, PATH_MAX - 1,
50 "%s/test/data/%s", srcdir ? srcdir : ".",
51 path_rel ? path_rel : "");
57 test_read_file(const char *path_rel)
61 int fd, count, remaining;
63 fd = open(test_get_path(path_rel), O_RDONLY);
67 if (fstat(fd, &info) != 0) {
72 ret = malloc(info.st_size + 1);
78 remaining = info.st_size;
80 while ((count = read(fd, tmp, remaining))) {
84 ret[info.st_size] = '\0';
96 test_get_context(void)
98 struct xkb_context *ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
103 xkb_context_include_path_append(ctx, test_get_path(""));
105 xkb_set_log_priority(ctx, LOG_DEBUG);
106 xkb_set_log_verbosity(ctx, 101);
112 test_compile_file(struct xkb_context *context, const char *path_rel)
114 struct xkb_keymap *keymap;
116 const char *path = test_get_path(path_rel);
118 file = fopen(path, "r");
120 fprintf(stderr, "Failed to open path: %s\n", path);
123 assert(file != NULL);
125 keymap = xkb_map_new_from_file(context, file,
126 XKB_KEYMAP_FORMAT_TEXT_V1, 0);
130 fprintf(stderr, "Failed to compile path: %s\n", path);
134 fprintf(stderr, "Successfully compiled path: %s\n", path);
140 test_compile_string(struct xkb_context *context, const char *string)
142 struct xkb_keymap *keymap;
144 keymap = xkb_map_new_from_string(context, string,
145 XKB_KEYMAP_FORMAT_TEXT_V1, 0);
147 fprintf(stderr, "Failed to compile string\n");
155 test_compile_rules(struct xkb_context *context, const char *rules,
156 const char *model, const char *layout,
157 const char *variant, const char *options)
159 struct xkb_keymap *keymap;
160 struct xkb_rule_names rmlvo = {
168 keymap = xkb_map_new_from_names(context, &rmlvo, 0);
171 "Failed to compile RMLVO: '%s', '%s', '%s', '%s', '%s'\n",
172 rules, model, layout, variant, options);