test/stringcomp: Perform full round-trip test We now pass! \o/ Signed-off-by: Daniel Stone <daniel@fooishbar.org>
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
diff --git a/test/stringcomp.c b/test/stringcomp.c
index e13a312..03a3cb0 100644
--- a/test/stringcomp.c
+++ b/test/stringcomp.c
@@ -1,4 +1,5 @@
-/* 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"),
@@ -30,23 +31,47 @@
#include "xkbcommon/xkbcommon.h"
#include "test.h"
+#define DATA_PATH "keymaps/stringcomp.data"
+
int
main(int argc, char *argv[])
{
struct xkb_context *ctx = test_get_context();
struct xkb_keymap *keymap;
- char *as_string;
+ char *original, *dump;
assert(ctx);
- as_string = test_read_file("keymaps/stringcomp.data");
- assert(as_string);
+ /* Load in a prebuilt keymap, make sure we can compile it from a string,
+ * then compare it to make sure we get the same result when dumping it
+ * to a string. */
+ original = test_read_file(DATA_PATH);
+ assert(original);
- keymap = test_compile_string(ctx, as_string);
+ keymap = test_compile_string(ctx, original);
assert(keymap);
- free(as_string);
+
+ dump = xkb_map_get_as_string(keymap);
+ assert(dump);
+
+ if (!streq(original, dump)) {
+ fprintf(stderr,
+ "round-trip test failed: dumped map differs from original\n");
+ fprintf(stderr, "path to original file: %s\n",
+ test_get_path(DATA_PATH));
+ fprintf(stderr, "length: dumped %zu, original %zu\n",
+ strlen(dump), strlen(original));
+ fprintf(stderr, "dumped map:\n");
+ fprintf(stderr, "%s\n", dump);
+ fflush(stderr);
+ assert(0);
+ }
+
+ free(original);
+ free(dump);
xkb_map_unref(keymap);
+ /* Make sure we can't (falsely claim to) compile an empty string. */
keymap = test_compile_string(ctx, "");
assert(!keymap);