summaryrefslogtreecommitdiff
path: root/test/filecomp.c
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2012-07-12 14:15:08 +0100
committerDaniel Stone <daniel@fooishbar.org>2012-07-12 14:48:22 +0100
commit3e86ebca0684d90899f34c2add6b1474c464613f (patch)
tree99fb64a1832fbe82915f0655ad53218217085635 /test/filecomp.c
parent059c1842ef35aa6e2eb33230a228edb12ecd8852 (diff)
downloadlibxkbcommon-3e86ebca0684d90899f34c2add6b1474c464613f.tar.gz
libxkbcommon-3e86ebca0684d90899f34c2add6b1474c464613f.tar.bz2
libxkbcommon-3e86ebca0684d90899f34c2add6b1474c464613f.zip
Add a library of common test functions
Including creating a context (will come in useful soon), opening and reading files, and compiling keymaps. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'test/filecomp.c')
-rw-r--r--test/filecomp.c69
1 files changed, 10 insertions, 59 deletions
diff --git a/test/filecomp.c b/test/filecomp.c
index a91d24a..b9b7ccd 100644
--- a/test/filecomp.c
+++ b/test/filecomp.c
@@ -31,82 +31,33 @@ authorization from the authors.
#include <limits.h>
#include "xkbcommon/xkbcommon.h"
+#include "test.h"
static int
-test_file(const char *path)
+test_file(struct xkb_context *ctx, const char *path_rel)
{
- FILE *file;
- struct xkb_context *context;
- struct xkb_keymap *keymap;
+ struct xkb_keymap *keymap = test_compile_file(ctx, path_rel);
- file = fopen(path, "r");
- assert(file != NULL);
-
- context = xkb_context_new(0);
- assert(context);
-
- fprintf(stderr, "\nCompiling path: %s\n", path);
-
- keymap = xkb_map_new_from_file(context, file,
- XKB_KEYMAP_FORMAT_TEXT_V1, 0);
- fclose(file);
-
- if (!keymap) {
- fprintf(stderr, "Failed to compile keymap\n");
- xkb_context_unref(context);
- return 0;
- }
-
- xkb_map_unref(keymap);
- 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/keymaps/%s", srcdir ? srcdir : ".", file_name);
- return test_file(path);
-}
-
-static int
-test_string(const char *string)
-{
- struct xkb_context *context;
- struct xkb_keymap *keymap;
-
- context = xkb_context_new(0);
- assert(context);
-
- fprintf(stderr, "\nCompiling string\n");
-
- keymap = xkb_map_new_from_string(context, string, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
- if (!keymap) {
- xkb_context_unref(context);
+ if (!keymap)
return 0;
- }
xkb_map_unref(keymap);
- xkb_context_unref(context);
return 1;
}
int
main(void)
{
+ struct xkb_context *ctx = test_get_context();
- assert(test_file_name("keymaps/basic.xkb"));
+ assert(test_file(ctx, "keymaps/basic.xkb"));
/* XXX check we actually get qwertz here ... */
- assert(test_file_name("keymaps/default.xkb"));
- assert(test_file_name("keymaps/comprehensive-plus-geom.xkb"));
+ assert(test_file(ctx, "keymaps/default.xkb"));
+ assert(test_file(ctx, "keymaps/comprehensive-plus-geom.xkb"));
- assert(!test_file_name("bad.xkb"));
+ assert(!test_file(ctx, "bad.xkb"));
- assert(!test_string(""));
+ xkb_context_unref(ctx);
return 0;
}