Overhaul test suite
authorRan Benita <ran234@gmail.com>
Fri, 30 Mar 2012 23:44:39 +0000 (02:44 +0300)
committerDaniel Stone <daniel@fooishbar.org>
Mon, 9 Apr 2012 13:21:47 +0000 (14:21 +0100)
Rewrite all of the current tests in the following ways:
- Instead of the current mix of C and shell, just use single-process
  pure C file per test. All of the .sh files are removed, but everything
  that was tested is ported.
- Instead of handling the test logs ourselves, use Automake's
  "parallel-test" mechanism. This will create a single log file for each
  test with it's stdout+stderr, and a top level "test-suite.log" file
  for all the failed tests.
- The "parallel-tests" directive also makes the test run in parallel,
  so "make check" runs faster.
- Also use the "color-tests" directive to have the "make check" output
  colorized. Who doesn't like to see PASS in green?
- All of the test data files are moved into the test/data subdirectory.
  That way we can just put the directory in EXTRA_DIST and forget about
  it.
- The test/Makefile.am file is consolidated into the main Makefile.am,
  for a completely non-recursive build.

Right now the tests are completely independent and just use simple
assert()'s. More sophistication can be added as needed.

It should also be noted that it's still possible to use shell, python,
etc. if a test wants more flexibility than C can provide, just do as
before.

Signed-off-by: Ran Benita <ran234@gmail.com>
[daniels: Updated for xkb_keymap changes.]

21 files changed:
.gitignore
Makefile.am
configure.ac
test/Makefile.am [deleted file]
test/canonicalise.c
test/canonicalise.sh [deleted file]
test/context.c
test/context.sh [deleted file]
test/data/bad.xkb [moved from test/bad.xkb with 100% similarity]
test/data/basic.xkb [moved from test/basic.xkb with 100% similarity]
test/data/comprehensive-plus-geom.xkb [moved from test/comprehensive-plus-geom.xkb with 100% similarity]
test/data/default.xkb [moved from test/default.xkb with 100% similarity]
test/filecomp.c
test/namescomp.c
test/namescomp.sh [deleted file]
test/rulescomp.c
test/rulescomp.sh [deleted file]
test/state.c
test/state.sh [deleted file]
test/xkey.c
test/xkey.sh [deleted file]

index 2aed1bf..3d36dc6 100644 (file)
@@ -79,3 +79,4 @@ core
 
 .dirstamp
 cscope.out
+test-suite.log
index 0564a7c..1d13e39 100644 (file)
@@ -1,7 +1,5 @@
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = . test
-
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = xkbcommon.pc
 
@@ -97,3 +95,29 @@ makekeys_makekeys_LDFLAGS = $(AM_LDFLAGS) $(LDFLAGS_FOR_BUILD)
 
 src/ks_tables.h: $(KEYSYMDEFS) $(top_builddir)/makekeys/makekeys$(EXEEXT)
        $(top_builddir)/makekeys/makekeys $(KEYSYMDEFS) > $@
+
+# Tests
+
+TESTS_ENVIRONMENT =
+
+TESTS = \
+       test/xkey \
+       test/filecomp \
+       test/namescomp \
+       test/rulescomp \
+       test/canonicalise \
+       test/state \
+       test/context
+TESTS_LDADD = libxkbcommon.la
+
+test_xkey_LDADD = $(TESTS_LDADD)
+test_filecomp_LDADD = $(TESTS_LDADD)
+test_namescomp_LDADD = $(TESTS_LDADD)
+test_rulescomp_LDADD = $(TESTS_LDADD)
+test_canonicalise_LDADD = $(TESTS_LDADD)
+test_state_LDADD = $(TESTS_LDADD)
+test_context_LDADD = $(TESTS_LDADD)
+
+check_PROGRAMS = $(TESTS)
+
+EXTRA_DIST = test/data
index 0cf7e50..3923026 100644 (file)
@@ -29,7 +29,7 @@ AC_CONFIG_HEADERS([src/config.h])
 AC_CONFIG_MACRO_DIR([m4])
 
 # Initialize Automake
-AM_INIT_AUTOMAKE([foreign dist-bzip2 subdir-objects])
+AM_INIT_AUTOMAKE([foreign dist-bzip2 subdir-objects color-tests parallel-tests])
 AM_MAINTAINER_MODE
 
 # Get _GNU_SOURCE and friends
@@ -106,8 +106,5 @@ AC_ARG_WITH([xkb_config_root],
     [XKBCONFIGROOT="$xkb_base"])
 AC_SUBST([XKBCONFIGROOT])
 
-AC_CONFIG_FILES([
-        Makefile
-        test/Makefile
-        xkbcommon.pc])
+AC_CONFIG_FILES([Makefile xkbcommon.pc])
 AC_OUTPUT
diff --git a/test/Makefile.am b/test/Makefile.am
deleted file mode 100644 (file)
index 9a43e42..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
-AM_CFLAGS = $(X11_CFLAGS) $(XORG_COMPILER_FLAGS)
-LDADD = $(top_builddir)/libxkbcommon.la
-
-TESTS_ENVIRONMENT = $(SHELL)
-
-check_PROGRAMS = xkey filecomp namescomp rulescomp canonicalise state context
-TESTS = $(check_PROGRAMS:=.sh)
-
-EXTRA_DIST =           \
-       $(TESTS)        \
-       bad.xkb         \
-       basic.xkb       \
-       default.xkb     \
-       comprehensive-plus-geom.xkb
-
-clean-local:
-       rm -f *.log
index da672eb..f223363 100644 (file)
  * Author: Daniel Stone <daniel@fooishbar.org>
  */
 
-#include "xkbcommon/xkbcommon.h"
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
-int main(int argc, char *argv[])
+#include "xkbcommon/xkbcommon.h"
+
+struct test_data {
+    struct xkb_component_names new;
+    struct xkb_component_names old;
+    int pass_old;
+    const char *exp_keycodes;
+    const char *exp_compat;
+    const char *exp_symbols;
+    const char *exp_types;
+};
+
+static struct test_data *
+new_data(void)
+{
+    return calloc(1, sizeof(struct test_data));
+}
+
+static void
+free_data(struct test_data *data)
 {
-    struct xkb_component_names *new, *old = NULL;
-
-    if (argc != 5 && argc != 9) {
-        fprintf(stderr, "usage: canonicalise (new kccgst) [old kccgst]\n");
-        return 1;
-    }
-
-
-    new = calloc(1, sizeof(*new));
-    if (!new) {
-        fprintf(stderr, "failed to calloc new\n");
-        return 1;
-    }
-    new->keycodes = strdup(argv[1]);
-    new->compat = strdup(argv[2]);
-    new->symbols = strdup(argv[3]);
-    new->types = strdup(argv[4]);
-
-    if (argc == 9) {
-        old = calloc(1, sizeof(*old));
-        if (!old) {
-            fprintf(stderr, "failed to calloc old\n");
-            return 1;
-        }
-        old->keycodes = strdup(argv[5]);
-        old->compat = strdup(argv[6]);
-        old->symbols = strdup(argv[7]);
-        old->types = strdup(argv[8]);
-    }
-
-    xkb_canonicalise_components(new, old);
-
-    printf("%s %s %s %s\n", new->keycodes, new->compat, new->symbols, new->types);
-
-    free(new->keycodes);
-    free(new->compat);
-    free(new->symbols);
-    free(new->types);
-    free(new);
-
-    if (old) {
-        free(old->keycodes);
-        free(old->compat);
-        free(old->symbols);
-        free(old->types);
-        free(old);
-    }
+    free(data->new.keycodes);
+    free(data->new.compat);
+    free(data->new.symbols);
+    free(data->new.types);
+    free(data->old.keycodes);
+    free(data->old.compat);
+    free(data->old.symbols);
+    free(data->old.types);
+    free(data);
+}
+
+static void
+set_new(struct test_data *data, const char *keycodes, const char *compat,
+        const char *symbols, const char *types)
+{
+    data->new.keycodes = strdup(keycodes);
+    data->new.compat = strdup(compat);
+    data->new.symbols = strdup(symbols);
+    data->new.types = strdup(types);
+}
+
+static void
+set_old(struct test_data *data, const char *keycodes, const char *compat,
+        const char *symbols, const char *types)
+{
+    data->old.keycodes = strdup(keycodes);
+    data->old.compat = strdup(compat);
+    data->old.symbols = strdup(symbols);
+    data->old.types = strdup(types);
+    data->pass_old = 1;
+}
+
+static void
+set_exp(struct test_data *data, const char *keycodes, const char *compat,
+        const char *symbols, const char *types)
+{
+    data->exp_keycodes = keycodes;
+    data->exp_compat = compat;
+    data->exp_symbols = symbols;
+    data->exp_types = types;
+}
+
+static int
+test_canonicalise(struct test_data *data)
+{
+    fprintf(stderr, "New: %s %s %s %s\n", data->new.keycodes,
+            data->new.compat, data->new.symbols, data->new.types);
+    if (data->pass_old)
+        fprintf(stderr, "Old: %s %s %s %s\n", data->old.keycodes,
+                data->old.compat, data->old.symbols, data->old.types);
+    fprintf(stderr, "Expected: %s %s %s %s\n", data->exp_keycodes,
+            data->exp_compat, data->exp_symbols, data->exp_types);
+
+    if (data->pass_old)
+        xkb_canonicalise_components(&data->new, &data->old);
+    else
+        xkb_canonicalise_components(&data->new, NULL);
+
+    fprintf(stderr, "Received: %s %s %s %s\n\n", data->new.keycodes,
+            data->new.compat, data->new.symbols, data->new.types);
+
+    return (strcmp(data->new.keycodes, data->exp_keycodes) == 0) &&
+           (strcmp(data->new.compat, data->exp_compat) == 0) &&
+           (strcmp(data->new.symbols, data->exp_symbols) == 0) &&
+           (strcmp(data->new.types, data->exp_types) == 0);
+}
+
+int
+main(void)
+{
+    struct test_data *twopart, *onepart;
+
+    twopart = new_data();
+    set_new(twopart, "+inet(pc104)",        "%+complete",     "pc(pc104)+%+ctrl(nocaps)",          "|complete");
+    set_old(twopart, "xfree86",             "basic",          "us(dvorak)",                        "xfree86");
+    set_exp(twopart, "xfree86+inet(pc104)", "basic+complete", "pc(pc104)+us(dvorak)+ctrl(nocaps)", "xfree86|complete");
+    assert(test_canonicalise(twopart));
+    free_data(twopart);
+
+    onepart = new_data();
+    set_new(onepart, "evdev", "complete", "pc(pc104)+us+compose(ralt)", "complete");
+    set_exp(onepart, "evdev", "complete", "pc(pc104)+us+compose(ralt)", "complete");
+    assert(test_canonicalise(onepart));
+    free_data(onepart);
 
     return 0;
 }
diff --git a/test/canonicalise.sh b/test/canonicalise.sh
deleted file mode 100755 (executable)
index 7e20622..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/sh -x
-
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-
-name=canonicalise
-prog="$builddir/$name$EXEEXT"
-log="$builddir/$name.log"
-
-log_kccgst()
-{
-    echo "  keycodes: $1" >>"$log"
-    echo "  compat: $2" >>"$log"
-    echo "  symbols: $3" >>"$log"
-    echo "  types: $4" >>"$log"
-}
-
-rm -f "$log"
-
-test() {
-    ret=`$prog $2 $3`
-    echo "Input (new):" >>"$log"
-    log_kccgst $2
-    echo >>"$log"
-    echo "Input (old):" >>"$log"
-    log_kccgst $3
-    echo >>"$log"
-    echo "Expecting:" >>"$log"
-    log_kccgst $1
-    echo >>"$log"
-    echo "Received:" >>"$log"
-    log_kccgst $ret
-    echo >>"$log"
-
-    ret=`echo "$ret" | sed -e 's/[  ]*/ /g;'`
-    exp=`echo "$1" | sed -e 's/[  ]*/ /g;'`
-
-    if ! [ "$ret" = "$exp" ]; then
-        echo "Error: Return and expectations different" >>"$log"
-        exit 1
-    fi
-}
-
-# This is a bit of a horror, but I can't really remember how to properly
-# handle arrays in shell, and I'm offline.
-twopart_new="+inet(pc104)        %+complete     pc(pc104)+%+ctrl(nocaps)          |complete"
-twopart_old="xfree86             basic          us(dvorak)                        xfree86"
-twopart_exp="xfree86+inet(pc104) basic+complete pc(pc104)+us(dvorak)+ctrl(nocaps) xfree86|complete"
-
-onepart_new="evdev               complete       pc(pc104)+us+compose(ralt)        complete"
-onepart_exp="evdev               complete       pc(pc104)+us+compose(ralt)        complete"
-
-test "$twopart_exp" "$twopart_new" "$twopart_old"
-echo >>"$log"
-echo >>"$log"
-test "$onepart_exp" "$onepart_new"
index 1ed965e..4009eff 100644 (file)
  */
 
 #include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <X11/keysym.h>
-#include <linux/input.h>
+
 #include "xkbcommon/xkbcommon.h"
-#include "utils.h"
-#include "XKBcommonint.h"
 
 int
-main(int argc, char *argv[])
+main(void)
 {
     struct xkb_context *context = xkb_context_new();
 
diff --git a/test/context.sh b/test/context.sh
deleted file mode 100755 (executable)
index 730e5a5..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-
-name=context
-prog="$builddir/$name$EXEEXT"
-log="$builddir/$name.log"
-
-rm -f "$log"
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-$builddir/$name$EXEEXT >> $log 2>&1
similarity index 100%
rename from test/bad.xkb
rename to test/data/bad.xkb
similarity index 100%
rename from test/basic.xkb
rename to test/data/basic.xkb
similarity index 100%
rename from test/default.xkb
rename to test/data/default.xkb
index 5a557a4..52f54ae 100644 (file)
@@ -24,73 +24,91 @@ sale, use or other dealings in this Software without prior written
 authorization from the authors.
 */
 
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <assert.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <errno.h>
 #include <fcntl.h>
-#include "xkbcommon/xkbcommon.h"
-#include "utils.h"
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
-static char buffer[8192];
+#include "xkbcommon/xkbcommon.h"
 
-int main(int argc, char *argv[])
+static int
+test_file(const char *path)
 {
+    int fd;
     struct xkb_context *context;
     struct xkb_keymap *xkb;
-    char *path;
-    int fd;
-    int i, len, from_string = 0;
-
-    /* Require xkb file */
-    if (argc < 2) {
-        fprintf(stderr, "Not enough arguments\n");
-        fprintf(stderr, "Usage: %s [-s] XKBFILE\n",
-                argv[0]);
-        exit(1);
-    }
-
-    i = 1;
-    if (strcmp(argv[1], "-s") == 0) {
-       from_string = 2;
-       i++;
-    }
-
-    path = argv[i];
 
     fd = open(path, O_RDONLY);
-    if (fd < 0) {
-        fprintf(stderr, "Failed to open file \"%s\": %s\n", path,
-                strerror(errno));
-        exit(1);
-    }
+    assert(fd >= 0);
 
     context = xkb_context_new();
     assert(context);
 
-    if (from_string) {
-       len = read(fd, buffer, sizeof(buffer));
-       buffer[len] = '\0';
-       xkb = xkb_map_new_from_string(context, buffer,
-                                      XKB_KEYMAP_FORMAT_TEXT_V1);
-    } else {
-       xkb = xkb_map_new_from_fd(context, fd,
-                                  XKB_KEYMAP_FORMAT_TEXT_V1);
-    }
+    fprintf(stderr, "\nCompiling path: %s\n", path);
+
+    xkb = xkb_map_new_from_fd(context, fd, XKB_KEYMAP_FORMAT_TEXT_V1);
     close(fd);
 
     if (!xkb) {
         fprintf(stderr, "Failed to compile keymap\n");
         xkb_context_unref(context);
-        exit(1);
+        return 0;
     }
 
     xkb_map_unref(xkb);
     xkb_context_unref(context);
+    return 1;
+}
+
+static int
+test_file_name(const char *file_name)
+{
+    static char path[PATH_MAX];
+    const char *srcdir = getenv("srcdir");
+
+    snprintf(path, PATH_MAX - 1, "%s/test/data/%s", srcdir ? srcdir : ".", file_name);
+    return test_file(path);
+}
+
+static int
+test_string(const char *string)
+{
+    struct xkb_context *context;
+    struct xkb_keymap *xkb;
+
+    context = xkb_context_new();
+    assert(context);
+
+    fprintf(stderr, "\nCompiling string\n");
+
+    xkb = xkb_map_new_from_string(context, string, XKB_KEYMAP_FORMAT_TEXT_V1);
+    if (!xkb) {
+        xkb_context_unref(context);
+        return 0;
+    }
+
+    xkb_map_unref(xkb);
+    xkb_context_unref(context);
+    return 1;
+}
+
+int
+main(void)
+{
+
+    assert(test_file_name("basic.xkb"));
+    /* XXX check we actually get qwertz here ... */
+    assert(test_file_name("default.xkb"));
+    assert(test_file_name("comprehensive-plus-geom.xkb"));
+
+    assert(!test_file_name("bad.xkb"));
+
+    assert(!test_string(""));
 
     return 0;
 }
index 6fb3448..0bd4d87 100644 (file)
@@ -27,42 +27,62 @@ authorization from the authors.
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
+
 #include "xkbcommon/xkbcommon.h"
-#include "utils.h"
 
-int main(int argc, char *argv[])
+static int
+test_names(const char *keycodes, const char *types,
+           const char *compat, const char *symbols)
 {
+    int ret = 1;
     struct xkb_context *context;
     struct xkb_keymap *xkb;
-    struct xkb_component_names kccgst;
-
-    /* Require Kc + T + C + S */
-    if (argc < 5) {
-        fprintf(stderr, "Not enough arguments\n");
-        fprintf(stderr, "Usage: %s KEYCODES TYPES COMPAT SYMBOLS\n",
-                argv[0]);
-        exit(1);
-    }
-
-    kccgst.keymap = NULL;
-    kccgst.keycodes = argv[1];
-    kccgst.types = argv[2];
-    kccgst.compat = argv[3];
-    kccgst.symbols = argv[4];
+    struct xkb_component_names kccgst = {
+        .keymap = NULL,
+        .keycodes = strdup(keycodes),
+        .types = strdup(types),
+        .compat = strdup(compat),
+        .symbols = strdup(symbols),
+    };
 
     context = xkb_context_new();
     assert(context);
 
-    xkb = xkb_map_new_from_kccgst(context, &kccgst);
+    fprintf(stderr, "\nCompiling %s %s %s %s\n", kccgst.keycodes, kccgst.types,
+            kccgst.compat, kccgst.symbols);
 
+    xkb = xkb_map_new_from_kccgst(context, &kccgst);
     if (!xkb) {
-        fprintf(stderr, "Failed to compile keymap\n");
-        xkb_context_unref(context);
-        exit(1);
+        ret = 0;
+        goto err_ctx;
     }
 
     xkb_map_unref(xkb);
+err_ctx:
     xkb_context_unref(context);
+    free(kccgst.keycodes);
+    free(kccgst.types);
+    free(kccgst.compat);
+    free(kccgst.symbols);
+    return ret;
+}
+
+int
+main(void)
+{
+    assert(test_names("xfree86+aliases(qwertz)", "complete", "complete", "pc+de"));
+    assert(test_names("xfree86+aliases(qwerty)", "complete", "complete", "pc+us"));
+    assert(test_names("xfree86+aliases(qwertz)", "complete", "complete",
+                      "pc+de+level3(ralt_switch_for_alts_toggle)+group(alts_toggle)"));
+
+    assert(!test_names("",                        "",         "",         ""));
+    assert(!test_names("xfree86+aliases(qwerty)", "",         "",         ""));
+    assert(!test_names("xfree86+aliases(qwertz)", "",         "",         "pc+de"));
+    assert(!test_names("xfree86+aliases(qwertz)", "complete", "",         "pc+de"));
+    assert(!test_names("xfree86+aliases(qwertz)", "",         "complete", "pc+de"));
+    assert(!test_names("xfree86+aliases(qwertz)", "complete", "complete", ""));
+    assert(!test_names("badnames",                "complete", "pc+us",    "pc(pc101)"));
 
     return 0;
 }
diff --git a/test/namescomp.sh b/test/namescomp.sh
deleted file mode 100755 (executable)
index 864e390..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-
-name=namescomp
-prog="$builddir/$name$EXEEXT"
-log="$builddir/$name.log"
-
-compile()
-{
-    echo "$prog '$1' '$2' '$3' '$4'" >>"$log"
-    $prog "$1" "$2" "$3" "$4" >>"$log" 2>&1 || exit $?
-}
-
-failcompile()
-{
-    echo "$prog '$1' '$2' '$3' '$4'" >>"$log"
-    if $prog "$1" "$2" "$3" "$4" >>"$log" 2>&1; then
-        exit 1
-    fi
-}
-
-rm -f "$log"
-
-compile "xfree86+aliases(qwertz)" "complete" "complete" "pc+de"
-compile "xfree86+aliases(qwerty)" "complete" "complete" "pc+us"
-compile "xfree86+aliases(qwertz)" "complete" "complete" \
-    "pc+de+level3(ralt_switch_for_alts_toggle)+group(alts_toggle)"
-
-failcompile "" "" "" ""
-failcompile "xfree86+aliases(qwerty)" "" "" ""
-failcompile "xfree86+aliases(qwertz)" "" "" "pc+de"
-failcompile "xfree86+aliases(qwertz)" "complete" "" "pc+de"
-failcompile "xfree86+aliases(qwertz)" "" "complete" "pc+de"
-failcompile "xfree86+aliases(qwertz)" "complete" "complete" ""
-failcompile "badnames" "complete" "pc+us" "pc(pc101)"
index 593d299..d6352f7 100644 (file)
@@ -25,45 +25,53 @@ authorization from the authors.
 */
 
 #include <assert.h>
-#include <stdlib.h>
 #include <stdio.h>
-#include <X11/Xdefs.h>
+
 #include "xkbcommon/xkbcommon.h"
-#include "utils.h"
 
-int main(int argc, char *argv[])
+static int
+test_rmlvo(const char *rules, const char *model, const char *layout,
+           const char *variant, const char *options)
 {
     struct xkb_context *context;
     struct xkb_keymap *xkb;
-    struct xkb_rule_names rmlvo;
-
-    /* Require rmlvo */
-    if (argc < 6) {
-        fprintf(stderr, "Not enough arguments\n");
-        fprintf(stderr, "Usage: %s RULES MODEL LAYOUT VARIANT OPTIONS\n",
-                argv[0]);
-        exit(1);
-    }
-
-    rmlvo.rules = argv[1];
-    rmlvo.model = argv[2];
-    rmlvo.layout = argv[3];
-    rmlvo.variant = argv[4];
-    rmlvo.options = argv[5];
+    struct xkb_rule_names rmlvo = {
+        .rules = rules,
+        .model = model,
+        .layout = layout,
+        .variant = variant,
+        .options = options
+    };
 
     context = xkb_context_new();
     assert(context);
 
-    xkb = xkb_map_new_from_names(context, &rmlvo);
+    fprintf(stderr, "\nCompiling %s %s %s %s %s\n", rmlvo.rules, rmlvo.model,
+           rmlvo.layout, rmlvo.variant, rmlvo.options);
 
+    xkb = xkb_map_new_from_names(context, &rmlvo);
     if (!xkb) {
-        fprintf(stderr, "Failed to compile keymap\n");
         xkb_context_unref(context);
-        exit(1);
+        return 0;
     }
 
     xkb_map_unref(xkb);
     xkb_context_unref(context);
+    return 1;
+}
+
+int
+main(void)
+{
+    assert(test_rmlvo("base",       "pc105",  "us",  "",      ""));
+    assert(test_rmlvo("base",       "",       "us",  "",      ""));
+    assert(test_rmlvo("evdev",      "pc105",  "us",  "intl",  ""));
+    assert(test_rmlvo("evdev",      "pc105",  "us",  "intl",  "grp:alts_toggle"));
+
+    assert(!test_rmlvo("",          "",       "",    "",      ""));
+    assert(!test_rmlvo("base",      "",       "",    "",      ""));
+    assert(!test_rmlvo("base",      "pc105",  "",    "",      ""));
+    assert(!test_rmlvo("badrules",  "",       "us",  "",      ""));
 
     return 0;
 }
diff --git a/test/rulescomp.sh b/test/rulescomp.sh
deleted file mode 100755 (executable)
index 9309d96..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh
-
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-
-name=rulescomp
-prog="$builddir/$name$EXEEXT"
-log="$builddir/$name.log"
-
-compile()
-{
-    echo "$prog '$1' '$2' '$3' '$4' '$5'" >>"$log"
-    $prog "$1" "$2" "$3" "$4" "$5" >>"$log" 2>&1 || exit $?
-}
-
-failcompile()
-{
-    echo "$prog '$1' '$2' '$3' '$4' '$5'" >>"$log"
-    if $prog "$1" "$2" "$3" "$4" "$5" >>"$log" 2>&1; then
-        exit 1
-    fi
-}
-
-rm -f "$log"
-
-compile base pc105 us "" ""
-compile base "" us "" ""
-compile evdev pc105 us intl ""
-compile evdev pc105 us intl grp:alts_toggle
-
-failcompile "" "" "" "" "" ""
-failcompile base "" "" "" "" ""
-failcompile base pc105 "" "" "" ""
-failcompile badrules "" us "" "" ""
index 2486f71..d698476 100644 (file)
@@ -28,8 +28,8 @@
 #include <stdlib.h>
 #include <X11/keysym.h>
 #include <linux/input.h>
+
 #include "xkbcommon/xkbcommon.h"
-#include "utils.h"
 #include "XKBcommonint.h"
 
 /* Offset between evdev keycodes (where KEY_ESCAPE is 1), and the evdev XKB
@@ -91,7 +91,7 @@ static void
 test_update_key(struct xkb_keymap *xkb)
 {
     struct xkb_state *state = xkb_state_new(xkb);
-    xkb_keysym_t *syms;
+    const xkb_keysym_t *syms;
     int num_syms;
 
     assert(state);
@@ -203,17 +203,17 @@ test_serialisation(struct xkb_keymap *xkb)
 }
 
 int
-main(int argc, char *argv[])
+main(void)
 {
     struct xkb_context *context;
     struct xkb_keymap *xkb;
-    struct xkb_rule_names rmlvo;
-
-    rmlvo.rules = "evdev";
-    rmlvo.model = "pc104";
-    rmlvo.layout = "us";
-    rmlvo.variant = NULL;
-    rmlvo.options = NULL;
+    struct xkb_rule_names rmlvo = {
+        .rules = "evdev",
+        .model = "pc104",
+        .layout = "us",
+        .variant = NULL,
+        .options = NULL,
+    };
 
     context = xkb_context_new();
     assert(context);
diff --git a/test/state.sh b/test/state.sh
deleted file mode 100755 (executable)
index 7753426..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-
-name=state
-prog="$builddir/$name$EXEEXT"
-log="$builddir/$name.log"
-
-rm -f "$log"
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-$builddir/$name$EXEEXT >> $log 2>&1
index 51909c2..3024a4d 100644 (file)
@@ -1,51 +1,50 @@
-#include "xkbmisc.h"
-#include "xkbcommon/xkbcommon.h"
+#include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-static void print_keysym(const char *s)
+#include "xkbcommon/xkbcommon.h"
+
+static int
+test_string(const char *string, xkb_keysym_t expected)
 {
-    xkb_keysym_t ks = xkb_string_to_keysym(s);
-    if (ks == XKB_KEYSYM_NO_SYMBOL)
-        printf("NoSymbol\n");
-    else
-        printf("0x%lX\n", ks);
+    xkb_keysym_t keysym;
+
+    keysym = xkb_string_to_keysym(string);
+
+    fprintf(stderr, "Expected string %s -> %x\n", string, expected);
+    fprintf(stderr, "Received string %s -> %x\n\n", string, keysym);
+
+    return keysym == expected;
 }
 
-static void print_string(xkb_keysym_t ks)
+static int
+test_keysym(xkb_keysym_t keysym, const char *expected)
 {
     char s[16];
 
-    xkb_keysym_to_string(ks, s, sizeof s);
-    printf("%s\n", s);
+    xkb_keysym_to_string(keysym, s, sizeof(s));
+
+    fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
+    fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
+
+    return strcmp(s, expected) == 0;
 }
 
-int main(int argc, char *argv[])
+int
+main(void)
 {
-    int mode;
-    xkb_keysym_t 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]);
+    assert(test_string("Undo", 0xFF65));
+    assert(test_string("ThisKeyShouldNotExist", XKB_KEYSYM_NO_SYMBOL));
+    assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
+    assert(test_string("VoidSymbol", 0xFFFFFF));
+    assert(test_string("U4567", 0x1004567));
+    assert(test_string("0x10203040", 0x10203040));
+
+    assert(test_keysym(0x1008FF56, "XF86Close"));
+    assert(test_keysym(0x0, "NoSymbol"));
+    assert(test_keysym(0x1008FE20, "XF86Ungrab"));
+    assert(test_keysym(0x01001234, "U1234"));
 
     return 0;
 }
diff --git a/test/xkey.sh b/test/xkey.sh
deleted file mode 100755 (executable)
index 1478a74..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/sh
-
-srcdir=${srcdir-.}
-builddir=${builddir-.}
-
-name=xkey
-prog="$builddir/$name$EXEEXT"
-log="$builddir/$name.log"
-
-check_error()
-{
-    if [ "$2" != "$3" ]; then
-        echo "error checking $1" >&2
-        echo "  expected: $2" >&2
-        echo "  received: $3" >&2
-        return 1
-    fi
-}
-
-check_string()
-{
-    echo "$prog -s '$1'" >>"$log"
-    val=`$prog -s "$1"` &&
-        echo "$val" >>"$log" &&
-        check_error "$1" "$2" "$val" >>"$log" 2>&1 ||
-        exit $?
-}
-
-check_key()
-{
-    echo "$prog -k '$1'" >>"$log"
-    val=`$prog -k "$1"` && \
-        echo "$val" >>"$log" &&
-        check_error "$1" "$2" "$val" >>"$log" 2>&1 || \
-        exit $?
-}
-
-rm -f "$log"
-
-check_string Undo 0xFF65
-check_key 0x1008FF56 XF86Close
-check_string ThisKeyShouldNotExist NoSymbol
-check_key 0x0 NoSymbol
-check_string XF86_Switch_VT_5 0x1008FE05
-check_key 0x1008FE20 XF86Ungrab
-check_string VoidSymbol 0xFFFFFF
-check_key 0x01001234 U1234
-check_string U4567 0x1004567
-check_string 0x10203040 0x10203040