From ea713014d818c1efae13dde0083512b0c7c3f33f Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Tue, 3 Feb 2015 22:46:11 +0100 Subject: [PATCH] Better message if unit test fails. --- tests/test-map.c | 52 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/tests/test-map.c b/tests/test-map.c index 7b605aa..74baf8a 100644 --- a/tests/test-map.c +++ b/tests/test-map.c @@ -31,6 +31,11 @@ static int qpos = 0; /* points to the queue entry for the next keypress */ queue[qpos] = '\0'; \ } #define QUEUE_CLEAR() {queue[(qpos = 0)] = '\0';} +#define ASSERT_MAPPING(s, e) { \ + QUEUE_CLEAR(); \ + map_handle_string(s, true); \ + g_assert_cmpstr(queue, ==, e); \ +} typedef struct { guint state; @@ -45,69 +50,62 @@ VbResult keypress(int key) return RESULT_COMPLETE; } -static void check_handle_string(const char *str, const char *expected) -{ - QUEUE_CLEAR(); - map_handle_string(str, true); - g_assert_cmpstr(queue, ==, expected); -} - static void test_handle_string_simple(void) { /* test simple mappings */ - check_handle_string("a", "[a]"); - check_handle_string("b", "[b]"); - check_handle_string("", "[tab]"); - check_handle_string("", "[shift-tab]"); - check_handle_string("", "[ctrl-f]"); - check_handle_string("", "[ctrl-f]"); - check_handle_string("", "[cr]"); - check_handle_string("foobar", "[baz]"); + ASSERT_MAPPING("a", "[a]"); + ASSERT_MAPPING("b", "[b]"); + ASSERT_MAPPING("", "[tab]"); + ASSERT_MAPPING("", "[shift-tab]"); + ASSERT_MAPPING("", "[ctrl-f]"); + ASSERT_MAPPING("", "[ctrl-f]"); + ASSERT_MAPPING("", "[cr]"); + ASSERT_MAPPING("foobar", "[baz]"); } static void test_handle_string_alias(void) { /* CTRL-I is the same like and CTRL-M like */ - check_handle_string("", "[tab]"); - check_handle_string("", "[cr]"); + ASSERT_MAPPING("", "[tab]"); + ASSERT_MAPPING("", "[cr]"); } static void test_handle_string_multiple(void) { /* test multiple mappings together */ - check_handle_string("ba", "[b][a]"); + ASSERT_MAPPING("ba", "[b][a]"); /* incomplete ambiguous sequences are not matched jet */ - check_handle_string("foob", ""); - check_handle_string("ar", "[baz]"); + ASSERT_MAPPING("foob", ""); + ASSERT_MAPPING("ar", "[baz]"); } static void test_handle_string_remapped(void) { /* test multiple mappings together */ - check_handle_string("ba", "[b][a]"); + ASSERT_MAPPING("ba", "[b][a]"); /* incomplete ambiguous sequences are not matched jet */ - check_handle_string("foob", ""); - check_handle_string("ar", "[baz]"); + ASSERT_MAPPING("foob", ""); + ASSERT_MAPPING("ar", "[baz]"); /* test remapping */ map_insert("c", "baza", 't', true); - check_handle_string("c", "[b][a]z[a]"); + ASSERT_MAPPING("c", "[b][a]z[a]"); map_insert("d", "cki", 't', true); - check_handle_string("d", "[b][a]z[a]ki"); + ASSERT_MAPPING("d", "[b][a]z[a]ki"); } static void test_remove(void) { map_insert("x", "[x]", 't', false); /* make sure that the mapping works */ - check_handle_string("x", "[x]"); + ASSERT_MAPPING("x", "[x]"); map_delete("x", 't'); /* make sure the mapping removed */ - check_handle_string("x", "x"); + ASSERT_MAPPING("x", "x"); } static void test_keypress_single(void) -- 2.20.1