2 * Copyright © 2009 Dan Nicholson
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
32 #define DATA_PATH "keymaps/stringcomp.data"
35 main(int argc, char *argv[])
37 struct xkb_context *ctx = test_get_context(0);
38 struct xkb_keymap *keymap;
39 char *original, *dump;
43 /* Load in a prebuilt keymap, make sure we can compile it from memory,
44 * then compare it to make sure we get the same result when dumping it
46 original = test_read_file(DATA_PATH);
49 /* Load a prebuild keymap, once without, once with the trailing \0 */
50 for (int i = 0; i <= 1; i++) {
51 keymap = test_compile_buffer(ctx, original, strlen(original) + i);
54 dump = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_USE_ORIGINAL_FORMAT);
57 if (!streq(original, dump)) {
59 "round-trip test failed: dumped map differs from original\n");
60 fprintf(stderr, "path to original file: %s\n",
61 test_get_path(DATA_PATH));
62 fprintf(stderr, "length: dumped %lu, original %lu\n",
63 (unsigned long) strlen(dump),
64 (unsigned long) strlen(original));
65 fprintf(stderr, "dumped map:\n");
66 fprintf(stderr, "%s\n", dump);
72 xkb_keymap_unref(keymap);
77 /* Make sure we can't (falsely claim to) compile an empty string. */
78 keymap = test_compile_buffer(ctx, "", 0);
81 /* Make sure we can recompile our output for a normal keymap from rules. */
82 keymap = test_compile_rules(ctx, NULL, NULL,
83 "ru,ca,de,us", ",multix,neo,intl", NULL);
85 dump = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_USE_ORIGINAL_FORMAT);
87 xkb_keymap_unref(keymap);
88 keymap = test_compile_buffer(ctx, dump, strlen(dump));
90 xkb_keymap_unref(keymap);
93 xkb_context_unref(ctx);