test: Move test_key_seq to common.c
authorDaniel Stone <daniel@fooishbar.org>
Mon, 18 Mar 2013 20:55:18 +0000 (20:55 +0000)
committerDaniel Stone <daniel@fooishbar.org>
Tue, 19 Mar 2013 10:25:52 +0000 (10:25 +0000)
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
test/common.c
test/keyseq.c
test/test.h

index f960501..400d872 100644 (file)
 
 #include "test.h"
 
+/*
+ * Test a sequence of keysyms, resulting from a sequence of key presses,
+ * against the keysyms they're supposed to generate.
+ *
+ * - Each test runs with a clean state.
+ * - Each line in the test is made up of:
+ *   + A keycode, given as a KEY_* from linux/input.h.
+ *   + A direction - DOWN for press, UP for release, BOTH for
+ *     immediate press + release, REPEAT to just get the syms.
+ *   + A sequence of keysyms that should result from this keypress.
+ *
+ * The vararg format is:
+ * <KEY_*>  <DOWN | UP | BOTH>  <XKB_KEY_* (zero or more)>  <NEXT | FINISH>
+ *
+ * See below for examples.
+ */
+int
+test_key_seq(struct xkb_keymap *keymap, ...)
+{
+    struct xkb_state *state;
+
+    va_list ap;
+    xkb_keycode_t kc;
+    int op;
+    xkb_keysym_t keysym;
+
+    const xkb_keysym_t *syms;
+    unsigned int nsyms, i;
+    char ksbuf[64];
+
+    fprintf(stderr, "----\n");
+
+    state = xkb_state_new(keymap);
+    assert(state);
+
+    va_start(ap, keymap);
+
+    for (;;) {
+        kc = va_arg(ap, int) + EVDEV_OFFSET;
+        op = va_arg(ap, int);
+
+        nsyms = xkb_state_key_get_syms(state, kc, &syms);
+        fprintf(stderr, "got %d syms for key 0x%x: [", nsyms, kc);
+
+        if (op == DOWN || op == BOTH)
+            xkb_state_update_key(state, kc, XKB_KEY_DOWN);
+        if (op == UP || op == BOTH)
+            xkb_state_update_key(state, kc, XKB_KEY_UP);
+
+        for (i = 0; i < nsyms; i++) {
+            keysym = va_arg(ap, int);
+            xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
+            fprintf(stderr, "%s%s", (i != 0) ? ", " : "", ksbuf);
+
+            if (keysym == FINISH || keysym == NEXT) {
+                xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
+                fprintf(stderr, "Did not expect keysym: %s.\n", ksbuf);
+                goto fail;
+            }
+
+            if (keysym != syms[i]) {
+                xkb_keysym_get_name(keysym, ksbuf, sizeof(ksbuf));
+                fprintf(stderr, "Expected keysym: %s. ", ksbuf);;
+                xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
+                fprintf(stderr, "Got keysym: %s.\n", ksbuf);;
+                goto fail;
+            }
+        }
+
+        fprintf(stderr, "]\n");
+
+        keysym = va_arg(ap, int);
+        if (keysym == NEXT)
+            continue;
+        if (keysym == FINISH)
+            break;
+
+        xkb_keysym_get_name(keysym, ksbuf, sizeof(ksbuf));
+        fprintf(stderr, "Expected keysym: %s. Didn't get it.\n", ksbuf);
+        goto fail;
+    }
+
+    va_end(ap);
+    xkb_state_unref(state);
+    return 1;
+
+fail:
+    va_end(ap);
+    xkb_state_unref(state);
+    return 0;
+}
+
 const char *
 test_get_path(const char *path_rel)
 {
index 7f148f7..461a439 100644 (file)
 
 #include "test.h"
 
-enum {
-    DOWN,
-    REPEAT,
-    UP,
-    BOTH,
-    NEXT,
-    FINISH,
-};
-
-#define EVDEV_OFFSET 8
-
-/*
- * Test a sequence of keysyms, resulting from a sequence of key presses,
- * against the keysyms they're supposed to generate.
- *
- * - Each test runs with a clean state.
- * - Each line in the test is made up of:
- *   + A keycode, given as a KEY_* from linux/input.h.
- *   + A direction - DOWN for press, UP for release, BOTH for
- *     immediate press + release, REPEAT to just get the syms.
- *   + A sequence of keysyms that should result from this keypress.
- *
- * The vararg format is:
- * <KEY_*>  <DOWN | UP | BOTH>  <XKB_KEY_* (zero or more)>  <NEXT | FINISH>
- *
- * See below for examples.
- */
-static int
-test_key_seq(struct xkb_keymap *keymap, ...)
-{
-    struct xkb_state *state;
-
-    va_list ap;
-    xkb_keycode_t kc;
-    int op;
-    xkb_keysym_t keysym;
-
-    const xkb_keysym_t *syms;
-    unsigned int nsyms, i;
-    char ksbuf[64];
-
-    fprintf(stderr, "----\n");
-
-    state = xkb_state_new(keymap);
-    assert(state);
-
-    va_start(ap, keymap);
-
-    for (;;) {
-        kc = va_arg(ap, int) + EVDEV_OFFSET;
-        op = va_arg(ap, int);
-
-        nsyms = xkb_state_key_get_syms(state, kc, &syms);
-        fprintf(stderr, "got %d syms for key 0x%x: [", nsyms, kc);
-
-        if (op == DOWN || op == BOTH)
-            xkb_state_update_key(state, kc, XKB_KEY_DOWN);
-        if (op == UP || op == BOTH)
-            xkb_state_update_key(state, kc, XKB_KEY_UP);
-
-        for (i = 0; i < nsyms; i++) {
-            keysym = va_arg(ap, int);
-            xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
-            fprintf(stderr, "%s%s", (i != 0) ? ", " : "", ksbuf);
-
-            if (keysym == FINISH || keysym == NEXT) {
-                xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
-                fprintf(stderr, "Did not expect keysym: %s.\n", ksbuf);
-                goto fail;
-            }
-
-            if (keysym != syms[i]) {
-                xkb_keysym_get_name(keysym, ksbuf, sizeof(ksbuf));
-                fprintf(stderr, "Expected keysym: %s. ", ksbuf);;
-                xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
-                fprintf(stderr, "Got keysym: %s.\n", ksbuf);;
-                goto fail;
-            }
-        }
-
-        fprintf(stderr, "]\n");
-
-        keysym = va_arg(ap, int);
-        if (keysym == NEXT)
-            continue;
-        if (keysym == FINISH)
-            break;
-
-        xkb_keysym_get_name(keysym, ksbuf, sizeof(ksbuf));
-        fprintf(stderr, "Expected keysym: %s. Didn't get it.\n", ksbuf);
-        goto fail;
-    }
-
-    va_end(ap);
-    xkb_state_unref(state);
-    return 1;
-
-fail:
-    va_end(ap);
-    xkb_state_unref(state);
-    return 0;
-}
-
 int
 main(void)
 {
index 046b64e..a72d6aa 100644 (file)
 
 #include <assert.h>
 
- /* Don't use compat names in internal code. */
+/* Don't use compat names in internal code. */
 #define _XKBCOMMON_COMPAT_H
 #include "xkbcommon/xkbcommon.h"
 #include "utils.h"
 
+/* The offset between KEY_* numbering, and keycodes in the XKB evdev
+ * dataset. */
+#define EVDEV_OFFSET 8
+
+enum key_seq_state {
+    DOWN,
+    REPEAT,
+    UP,
+    BOTH,
+    NEXT,
+    FINISH,
+};
+
+int
+test_key_seq(struct xkb_keymap *keymap, ...);
+
 const char *
 test_get_path(const char *path_rel);