summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2013-03-18 20:55:18 +0000
committerDaniel Stone <daniel@fooishbar.org>2013-03-19 10:25:52 +0000
commita1f203c031777d654d6a1b1377ad6be986db402f (patch)
treeca547434b0294cdb85af985d840768333c0df9ae /test
parent0513686b5d1ea14b3b8340371b2174ce152732c8 (diff)
downloadlibxkbcommon-a1f203c031777d654d6a1b1377ad6be986db402f.tar.gz
libxkbcommon-a1f203c031777d654d6a1b1377ad6be986db402f.tar.bz2
libxkbcommon-a1f203c031777d654d6a1b1377ad6be986db402f.zip
test: Move test_key_seq to common.c
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'test')
-rw-r--r--test/common.c92
-rw-r--r--test/keyseq.c103
-rw-r--r--test/test.h18
3 files changed, 109 insertions, 104 deletions
diff --git a/test/common.c b/test/common.c
index f960501..400d872 100644
--- a/test/common.c
+++ b/test/common.c
@@ -38,6 +38,98 @@
#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)
{
diff --git a/test/keyseq.c b/test/keyseq.c
index 7f148f7..461a439 100644
--- a/test/keyseq.c
+++ b/test/keyseq.c
@@ -25,109 +25,6 @@
#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)
{
diff --git a/test/test.h b/test/test.h
index 046b64e..a72d6aa 100644
--- a/test/test.h
+++ b/test/test.h
@@ -25,11 +25,27 @@
#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);