From fb4d3aefc366dfdd866b45a867cf5c717d957b6f Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 3 Aug 2012 04:01:21 +0200 Subject: [PATCH] test/stringcomp: Perform full round-trip test We now pass! \o/ Signed-off-by: Daniel Stone --- test/stringcomp.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) 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); -- 2.7.4