From: Aki Tuomi Date: Sun, 25 Dec 2016 08:36:59 +0000 (+0200) Subject: lib: Add tests for extensions X-Git-Tag: 2.2.29.rc1~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec4485c4b04e470f75edf9eb86ac8693c0dbcc24;p=thirdparty%2Fdovecot%2Fcore.git lib: Add tests for extensions --- diff --git a/src/lib/test-var-expand.c b/src/lib/test-var-expand.c index 83c4710e43..386b1c6a15 100644 --- a/src/lib/test-var-expand.c +++ b/src/lib/test-var-expand.c @@ -5,6 +5,7 @@ #include "env-util.h" #include "hostpid.h" #include "var-expand.h" +#include "var-expand-private.h" struct var_expand_test { const char *in; @@ -202,9 +203,28 @@ static const char *test_var_expand_hashing_func1(const char *data, return data; } -static void test_var_expand_hashing(void) +static int test_var_expand_bad_func(struct var_expand_context *ctx ATTR_UNUSED, + const char *key, + const char *field ATTR_UNUSED, + const char **result_r ATTR_UNUSED, + const char **error_r) { - test_begin("var_expand_hashing"); + if (strcmp(key, "notfound") == 0) return 0; + *error_r = "Bad parameters"; + return -1; +} + +static const struct var_expand_extension_func_table test_extension_funcs[] = { + { "notfound", test_var_expand_bad_func }, + { "badparam", test_var_expand_bad_func }, + { NULL, NULL } +}; + +static void test_var_expand_extensions(void) +{ + test_begin("var_expand_extensions"); + + var_expand_register_func_array(test_extension_funcs); static struct var_expand_table table[] = { {'\0', "example", "value" }, @@ -241,6 +261,13 @@ static void test_var_expand_hashing(void) test_assert_idx(strcmp(str_c(str), tests[i].out) == 0, i); } + var_expand_with_funcs(str, "notfound: %{notfound:field}", + table, func_table, NULL); + var_expand_with_funcs(str, "notfound: %{badparam:field}", + table, func_table, NULL); + + var_expand_unregister_func_array(test_extension_funcs); + test_end(); } @@ -252,5 +279,5 @@ void test_var_expand(void) test_var_expand_with_funcs(); test_var_get_key(); test_var_has_key(); - test_var_expand_hashing(); + test_var_expand_extensions(); }