Testing harness for keysym functions A test program and script have been added for checking the XkbCommon keysym functions. This has already highlighted an error in handling of keysyms from XF86keysym.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
diff --git a/Makefile.am b/Makefile.am
index e418f40..5460eea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = include src
+SUBDIRS = include src test
EXTRA_DIST = ChangeLog
diff --git a/configure.ac b/configure.ac
index fed23c9..093038f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,4 +77,5 @@ AC_OUTPUT([
Makefile
include/Makefile
src/Makefile
+test/Makefile
])
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..ddf7b39
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+xkey
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..49362d1
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = -I$(top_srcdir)/include
+AM_CFLAGS = $(X11_CFLAGS)
+
+check_PROGRAMS = xkey
+xkey_SOURCES = xkey.c
+xkey_LDADD = $(top_builddir)/src/libxkbcommon.la
+
+TESTS = xkey.sh
+TESTS_ENVIRONMENT = $(SHELL)
diff --git a/test/xkey.c b/test/xkey.c
new file mode 100644
index 0000000..4f775f2
--- /dev/null
+++ b/test/xkey.c
@@ -0,0 +1,48 @@
+#include <X11/XkbCommon.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static void print_keysym(const char *s)
+{
+ KeySym ks = XkbcStringToKeysym(s);
+ if (ks == NoSymbol)
+ printf("NoSymbol\n");
+ else
+ printf("0x%lx\n", ks);
+}
+
+static void print_string(KeySym ks)
+{
+ char *s = XkbcKeysymToString(ks);
+ printf("%s\n", s ? s : "NULL");
+}
+
+int main(int argc, char *argv[])
+{
+ int mode;
+ KeySym sym;
+
+ if (argc < 3) {
+ fprintf(stderr, "error: not enough arguments\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (strcmp(argv[1], "-k") == 0) {
+ mode = 0;
+ sym = strtoul(argv[2], NULL, 16);
+ }
+ else if (strcmp(argv[1], "-s") == 0)
+ mode = 1;
+ else {
+ fprintf(stderr, "error: unrecognized argument \"%s\"\n", argv[1]);
+ exit(EXIT_FAILURE);
+ }
+
+ if (mode == 0)
+ print_string(sym);
+ else
+ print_keysym(argv[2]);
+
+ return 0;
+}
diff --git a/test/xkey.sh b/test/xkey.sh
new file mode 100755
index 0000000..b201822
--- /dev/null
+++ b/test/xkey.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+srcdir=${srcdir-.}
+builddir=${builddir-.}
+
+check_error()
+{
+ if [ "$2" != "$3" ]; then
+ echo "error checking $1" >&2
+ echo " expected: $2" >&2
+ echo " received: $3" >&2
+ return 1
+ fi
+}
+
+val=`${builddir}/xkey -s Undo` && \
+ check_error Undo 0xff65 $val || \
+ exit $?
+
+val=`${builddir}/xkey -k 0x1008ff56` && \
+ check_error 0x1008FF56 XF86Close $val || \
+ exit $?
+
+val=`${builddir}/xkey -s ThisKeyShouldNotExist` && \
+ check_error ThisKeyShouldNotExist NoSymbol $val || \
+ exit $?
+
+val=`${builddir}/xkey -k 0x0` && \
+ check_error 0x0 NULL $val || \
+ exit $?