1 /* 2 * Copyright 2009 Dan Nicholson 3 * 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: 10 * 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 13 * Software. 14 * 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. 22 */ 23 24 #include "evdev-scancodes.h" 25 #include "test.h" 26 27 static int 28 test_rmlvo_va(struct xkb_context *context, const char *rules, 29 const char *model, const char *layout, 30 const char *variant, const char *options, va_list ap) 31 { 32 struct xkb_keymap *keymap; 33 int ret; 34 35 keymap = test_compile_rules(context, rules, model, layout, variant, 36 options); 37 if (!keymap) 38 return 0; 39 40 fprintf(stderr, "Compiled '%s' '%s' '%s' '%s' '%s'\n", 41 strnull(rules), strnull(model), strnull(layout), 42 strnull(variant), strnull(options)); 43 44 ret = test_key_seq_va(keymap, ap); 45 46 xkb_keymap_unref(keymap); 47 48 return ret; 49 } 50 51 static int 52 test_rmlvo(struct xkb_context *context, const char *rules, 53 const char *model, const char *layout, const char *variant, 54 const char *options, ...) 55 { 56 va_list ap; 57 int ret; 58 59 va_start(ap, options); 60 ret = test_rmlvo_va(context, rules, model, layout, variant, options, ap); 61 va_end(ap); 62 63 return ret; 64 } 65 66 static int 67 test_rmlvo_env(struct xkb_context *ctx, const char *rules, const char *model, 68 const char *layout, const char *variant, const char *options, 69 ...) 70 { 71 va_list ap; 72 int ret; 73 74 va_start (ap, options); 75 76 if (!isempty(rules)) 77 setenv("XKB_DEFAULT_RULES", rules, 1); 78 else 79 unsetenv("XKB_DEFAULT_RULES"); 80 81 if (!isempty(model)) 82 setenv("XKB_DEFAULT_MODEL", model, 1); 83 else 84 unsetenv("XKB_DEFAULT_MODEL"); 85 86 if (!isempty(layout)) 87 setenv("XKB_DEFAULT_LAYOUT", layout, 1); 88 else 89 unsetenv("XKB_DEFAULT_LAYOUT"); 90 91 if (!isempty(variant)) 92 setenv("XKB_DEFAULT_VARIANT", variant, 1); 93 else 94 unsetenv("XKB_DEFAULT_VARIANT"); 95 96 if (!isempty(options)) 97 setenv("XKB_DEFAULT_OPTIONS", options, 1); 98 else 99 unsetenv("XKB_DEFAULT_OPTIONS"); 100 101 ret = test_rmlvo_va(ctx, NULL, NULL, NULL, NULL, NULL, ap); 102 103 va_end(ap); 104 105 return ret; 106 } 107 108 int 109 main(int argc, char *argv[]) 110 { 111 struct xkb_context *ctx = test_get_context(CONTEXT_ALLOW_ENVIRONMENT_NAMES); 112 113 assert(ctx); 114 115 #define KS(name) xkb_keysym_from_name(name, 0) 116 117 assert(test_rmlvo(ctx, "evdev", "pc105", "us,il,ru,ca", ",,,multix", "grp:alts_toggle,ctrl:nocaps,compose:rwin", 118 KEY_Q, BOTH, XKB_KEY_q, NEXT, 119 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT, 120 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT, 121 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT, 122 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT, 123 KEY_Q, BOTH, XKB_KEY_slash, NEXT, 124 KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L, NEXT, 125 KEY_Q, BOTH, XKB_KEY_Q, NEXT, 126 KEY_RIGHTMETA, BOTH, XKB_KEY_Multi_key, FINISH)); 127 assert(test_rmlvo(ctx, "evdev", "pc105", "us,in", "", "grp:alts_toggle", 128 KEY_A, BOTH, XKB_KEY_a, NEXT, 129 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT, 130 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT, 131 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT, 132 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT, 133 KEY_A, BOTH, KS("U094b"), FINISH)); 134 assert(test_rmlvo(ctx, "evdev", "pc105", "us", "intl", "", 135 KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH)); 136 assert(test_rmlvo(ctx, "evdev", "evdev", "us", "intl", "grp:alts_toggle", 137 KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH)); 138 139 /* 20 is not a legal group; make sure this is handled gracefully. */ 140 assert(test_rmlvo(ctx, "evdev", "", "us:20", "", "", 141 KEY_A, BOTH, XKB_KEY_a, FINISH)); 142 143 /* Don't choke on missing values in RMLVO. Should just skip them. 144 Currently generates us,us,ca. */ 145 assert(test_rmlvo(ctx, "evdev", "", "us,,ca", "", "grp:alts_toggle", 146 KEY_A, BOTH, XKB_KEY_a, NEXT, 147 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT, 148 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT, 149 KEY_RIGHTALT, UP, XKB_KEY_ISO_Next_Group, NEXT, 150 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT, 151 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT, 152 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT, 153 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT, 154 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT, 155 KEY_APOSTROPHE, BOTH, XKB_KEY_dead_grave, FINISH)); 156 157 assert(test_rmlvo(ctx, "", "", "", "", "", 158 KEY_A, BOTH, XKB_KEY_a, FINISH)); 159 160 assert(!test_rmlvo(ctx, "does-not-exist", "", "", "", "", 161 KEY_A, BOTH, XKB_KEY_a, FINISH)); 162 163 assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "", 164 KEY_A, BOTH, XKB_KEY_a, FINISH)); 165 assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "ctrl:nocaps", 166 KEY_CAPSLOCK, BOTH, XKB_KEY_Control_L, FINISH)); 167 168 /* Ignores multix and generates us,ca. */ 169 assert(test_rmlvo_env(ctx, "evdev", "", "us,ca", ",,,multix", "grp:alts_toggle", 170 KEY_A, BOTH, XKB_KEY_a, NEXT, 171 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT, 172 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT, 173 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT, 174 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT, 175 KEY_GRAVE, UP, XKB_KEY_numbersign, FINISH)); 176 177 assert(!test_rmlvo_env(ctx, "broken", "what-on-earth", "invalid", "", "", 178 KEY_A, BOTH, XKB_KEY_a, FINISH)); 179 180 /* Ensure a keymap with an empty xkb_keycodes compiles fine. */ 181 assert(test_rmlvo_env(ctx, "base", "empty", "empty", "", "", 182 KEY_A, BOTH, XKB_KEY_NoSymbol, FINISH)); 183 184 /* Has an illegal escape sequence, but shouldn't fail. */ 185 assert(test_rmlvo_env(ctx, "evdev", "", "cz", "bksl", "", 186 KEY_A, BOTH, XKB_KEY_a, FINISH)); 187 188 xkb_context_unref(ctx); 189 190 ctx = test_get_context(0); 191 assert(test_rmlvo_env(ctx, "broken", "but", "ignored", "per", "ctx flags", 192 KEY_A, BOTH, XKB_KEY_a, FINISH)); 193 194 /* Test response to invalid flags. */ 195 { 196 struct xkb_rule_names rmlvo = { NULL }; 197 assert(!xkb_keymap_new_from_names(ctx, &rmlvo, -1)); 198 assert(!xkb_keymap_new_from_names(ctx, &rmlvo, 5453)); 199 } 200 201 xkb_context_unref(ctx); 202 return 0; 203 } 204