summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2014-06-10 00:14:38 +0200
committerDaniel Carl <danielcarl@gmx.de>2014-06-10 00:27:43 +0200
commit386ac81a53b6b9914ac02963048291804bdcbd39 (patch)
treefffa3f65ebbc24530c1dd5e1baf93f32a5aa9d8c /tests
parent9ad8cd825dcdf028f50d06e5ce028944c7630f97 (diff)
Removed test macros by functions.
This lead to better readable output in case if a test case fails.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-map.c52
-rw-r--r--tests/test-util.c72
2 files changed, 64 insertions, 60 deletions
diff --git a/tests/test-map.c b/tests/test-map.c
index f34c680..93f51e7 100644
--- a/tests/test-map.c
+++ b/tests/test-map.c
@@ -31,11 +31,6 @@ static int qpos = 0; /* points to the queue entry for the next keypress */
queue[qpos] = '\0'; \
}
#define QUEUE_CLEAR() {queue[(qpos = 0)] = '\0';}
-#define TEST_HANDLE_STRING(in, expected) { \
- QUEUE_CLEAR(); \
- map_handle_string(in, true); \
- g_assert_cmpstr(queue, ==, expected); \
-}
typedef struct {
guint state;
@@ -50,62 +45,69 @@ 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 */
- TEST_HANDLE_STRING("a", "[a]");
- TEST_HANDLE_STRING("b", "[b]");
- TEST_HANDLE_STRING("<Tab>", "[tab]");
- TEST_HANDLE_STRING("<S-Tab>", "[shift-tab]");
- TEST_HANDLE_STRING("<C-F>", "[ctrl-f]");
- TEST_HANDLE_STRING("<C-f>", "[ctrl-f]");
- TEST_HANDLE_STRING("<CR>", "[cr]");
- TEST_HANDLE_STRING("foobar", "[baz]");
+ check_handle_string("a", "[a]");
+ check_handle_string("b", "[b]");
+ check_handle_string("<Tab>", "[tab]");
+ check_handle_string("<S-Tab>", "[shift-tab]");
+ check_handle_string("<C-F>", "[ctrl-f]");
+ check_handle_string("<C-f>", "[ctrl-f]");
+ check_handle_string("<CR>", "[cr]");
+ check_handle_string("foobar", "[baz]");
}
static void test_handle_string_alias(void)
{
/* CTRL-I is the same like <Tab> and CTRL-M like <CR> */
- TEST_HANDLE_STRING("<C-I>", "[tab]");
- TEST_HANDLE_STRING("<C-M>", "[cr]");
+ check_handle_string("<C-I>", "[tab]");
+ check_handle_string("<C-M>", "[cr]");
}
static void test_handle_string_multiple(void)
{
/* test multiple mappings together */
- TEST_HANDLE_STRING("ba", "[b][a]");
+ check_handle_string("ba", "[b][a]");
/* incomplete ambiguous sequences are not matched jet */
- TEST_HANDLE_STRING("foob", "");
- TEST_HANDLE_STRING("ar", "[baz]");
+ check_handle_string("foob", "");
+ check_handle_string("ar", "[baz]");
}
static void test_handle_string_remapped(void)
{
/* test multiple mappings together */
- TEST_HANDLE_STRING("ba", "[b][a]");
+ check_handle_string("ba", "[b][a]");
/* incomplete ambiguous sequences are not matched jet */
- TEST_HANDLE_STRING("foob", "");
- TEST_HANDLE_STRING("ar", "[baz]");
+ check_handle_string("foob", "");
+ check_handle_string("ar", "[baz]");
/* test remapping */
map_insert("c", "baza", 't', true);
- TEST_HANDLE_STRING("c", "[b][a]z[a]");
+ check_handle_string("c", "[b][a]z[a]");
map_insert("d", "cki", 't', true);
- TEST_HANDLE_STRING("d", "[b][a]z[a]ki");
+ check_handle_string("d", "[b][a]z[a]ki");
}
static void test_remove(void)
{
map_insert("x", "[x]", 't', false);
/* make sure that the mapping works */
- TEST_HANDLE_STRING("x", "[x]");
+ check_handle_string("x", "[x]");
map_delete("x", 't');
/* make sure the mapping removed */
- TEST_HANDLE_STRING("x", "x");
+ check_handle_string("x", "x");
}
static void test_keypress_single(void)
diff --git a/tests/test-util.c b/tests/test-util.c
index e4c9337..6dc26b4 100644
--- a/tests/test-util.c
+++ b/tests/test-util.c
@@ -22,10 +22,11 @@
extern VbCore vb;
-#define EXPAND(in, out) { \
- char *value = util_expand(in, UTIL_EXP_DOLLAR|UTIL_EXP_TILDE|UTIL_EXP_SPECIAL); \
- g_assert_cmpstr(value, ==, out); \
- g_free(value); \
+static void check_expand(const char *str, const char *expected)
+{
+ char *result = util_expand(str, UTIL_EXP_DOLLAR|UTIL_EXP_TILDE|UTIL_EXP_SPECIAL);
+ g_assert_cmpstr(result, ==, expected);
+ g_free(result);
}
static void test_expand_evn(void)
@@ -33,36 +34,36 @@ static void test_expand_evn(void)
/* set environment var for testing expansion */
g_setenv("VIMB_VAR", "value", true);
- EXPAND("$VIMB_VAR", "value");
- EXPAND("$VIMB_VAR", "value");
- EXPAND("$VIMB_VAR$VIMB_VAR", "valuevalue");
- EXPAND("${VIMB_VAR}", "value");
- EXPAND("my$VIMB_VAR", "myvalue");
- EXPAND("'$VIMB_VAR'", "'value'");
- EXPAND("${VIMB_VAR}s ", "values ");
+ check_expand("$VIMB_VAR", "value");
+ check_expand("$VIMB_VAR", "value");
+ check_expand("$VIMB_VAR$VIMB_VAR", "valuevalue");
+ check_expand("${VIMB_VAR}", "value");
+ check_expand("my$VIMB_VAR", "myvalue");
+ check_expand("'$VIMB_VAR'", "'value'");
+ check_expand("${VIMB_VAR}s ", "values ");
g_unsetenv("UNKNOWN");
- EXPAND("$UNKNOWN", "");
- EXPAND("${UNKNOWN}", "");
- EXPAND("'$UNKNOWN'", "''");
+ check_expand("$UNKNOWN", "");
+ check_expand("${UNKNOWN}", "");
+ check_expand("'$UNKNOWN'", "''");
}
static void test_expand_escaped(void)
{
g_setenv("VIMB_VAR", "value", true);
- EXPAND("\\$VIMB_VAR", "$VIMB_VAR");
- EXPAND("\\${VIMB_VAR}", "${VIMB_VAR}");
+ check_expand("\\$VIMB_VAR", "$VIMB_VAR");
+ check_expand("\\${VIMB_VAR}", "${VIMB_VAR}");
- EXPAND("\\~/", "~/");
- EXPAND("\\~/vimb", "~/vimb");
- EXPAND("\\~root", "~root");
+ check_expand("\\~/", "~/");
+ check_expand("\\~/vimb", "~/vimb");
+ check_expand("\\~root", "~root");
- EXPAND("\\%", "%");
+ check_expand("\\%", "%");
- EXPAND("\\\\$VIMB_VAR", "\\value"); /* \\$VAR becomes \ExpandedVar */
- EXPAND("\\\\\\$VIMB_VAR", "\\$VIMB_VAR"); /* \\\$VAR becomes \$VAR */
+ check_expand("\\\\$VIMB_VAR", "\\value"); /* \\$VAR becomes \ExpandedVar */
+ check_expand("\\\\\\$VIMB_VAR", "\\$VIMB_VAR"); /* \\\$VAR becomes \$VAR */
}
static void test_expand_tilde_home(void)
@@ -70,19 +71,19 @@ static void test_expand_tilde_home(void)
char *dir;
const char *home = util_get_home_dir();
- EXPAND("~", "~");
- EXPAND("~/", home);
- EXPAND("foo~/bar", "foo~/bar");
- EXPAND("~/foo", (dir = g_strdup_printf("%s/foo", home)));
+ check_expand("~", "~");
+ check_expand("~/", home);
+ check_expand("foo~/bar", "foo~/bar");
+ check_expand("~/foo", (dir = g_strdup_printf("%s/foo", home)));
g_free(dir);
- EXPAND("foo ~/bar", (dir = g_strdup_printf("foo %s/bar", home)));
+ check_expand("foo ~/bar", (dir = g_strdup_printf("foo %s/bar", home)));
g_free(dir);
- EXPAND("~/~", (dir = g_strdup_printf("%s/~", home)));
+ check_expand("~/~", (dir = g_strdup_printf("%s/~", home)));
g_free(dir);
- EXPAND("~/~/", (dir = g_strdup_printf("%s/~/", home)));
+ check_expand("~/~/", (dir = g_strdup_printf("%s/~/", home)));
g_free(dir);
}
@@ -93,17 +94,18 @@ static void test_expand_tilde_user(void)
char *in, *out;
/* don't expand within words */
- EXPAND((in = g_strdup_printf("foo~%s/bar", user)), in);
+ in = g_strdup_printf("foo~%s/bar", user);
+ check_expand(in, in);
g_free(in);
- EXPAND((in = g_strdup_printf("foo ~%s", user)), (out = g_strdup_printf("foo %s", home)));
+ check_expand((in = g_strdup_printf("foo ~%s", user)), (out = g_strdup_printf("foo %s", home)));
g_free(in);
g_free(out);
- EXPAND((in = g_strdup_printf("~%s", user)), home);
+ check_expand((in = g_strdup_printf("~%s", user)), home);
g_free(in);
- EXPAND((in = g_strdup_printf("~%s/bar", user)), (out = g_strdup_printf("%s/bar", home)));
+ check_expand((in = g_strdup_printf("~%s/bar", user)), (out = g_strdup_printf("%s/bar", home)));
g_free(in);
g_free(out);
}
@@ -112,8 +114,8 @@ static void test_expand_speacial(void)
{
vb.state.uri = "http://fanglingsu.github.io/vimb/";
- EXPAND("%", "http://fanglingsu.github.io/vimb/");
- EXPAND("'%'", "'http://fanglingsu.github.io/vimb/'");
+ check_expand("%", "http://fanglingsu.github.io/vimb/");
+ check_expand("'%'", "'http://fanglingsu.github.io/vimb/'");
}
static void test_strcasestr(void)