summaryrefslogtreecommitdiff
path: root/test/stringcomp.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/stringcomp.c
parent059c1842ef35aa6e2eb33230a228edb12ecd8852 (diff)
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/stringcomp.c')
-rw-r--r--test/stringcomp.c45
1 files changed, 12 insertions, 33 deletions
diff --git a/test/stringcomp.c b/test/stringcomp.c
index 8db7836..c965162 100644
--- a/test/stringcomp.c
+++ b/test/stringcomp.c
@@ -1,5 +1,4 @@
-/*
-Copyright 2009 Dan Nicholson
+/* Copyright 2009 Dan Nicholson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -34,48 +33,28 @@ authorization from the authors.
#include <sys/types.h>
#include "xkbcommon/xkbcommon.h"
+#include "test.h"
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- struct xkb_context *ctx = xkb_context_new(0);
+ struct xkb_context *ctx = test_get_context();
struct xkb_keymap *keymap;
- struct stat info;
- char *as_string, *buf;
- char *path;
- const char *srcdir;
- int fd, count, remaining;
+ char *as_string;
assert(ctx);
- srcdir = getenv("srcdir");
- assert(srcdir);
- assert(asprintf(&path, "%s/test/data/keymaps/stringcomp.data", srcdir) > 0);
- assert(path);
-
- fd = open(path, O_RDONLY);
- assert(fd >= 0);
- assert(fstat(fd, &info) == 0);
- as_string = malloc(info.st_size + 1);
+ as_string = test_read_file("keymaps/stringcomp.data");
assert(as_string);
- remaining = info.st_size;
- buf = as_string;
- while ((count = read(fd, buf, remaining))) {
- remaining -= count;
- buf += count;
- }
-
- assert(remaining == 0);
- as_string[info.st_size] = '\0';
-
- keymap = xkb_map_new_from_string(ctx, as_string,
- XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+ keymap = test_compile_string(ctx, as_string);
assert(keymap);
-
- free(path);
- close(fd);
free(as_string);
xkb_map_unref(keymap);
+
+ keymap = test_compile_string(ctx, "");
+ assert(!keymap);
+
xkb_context_unref(ctx);
return 0;