Mercurial > dovecot > core-2.2
changeset 21860:f7cfff192280
lib: Add tests for extensions
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Sun, 25 Dec 2016 10:36:59 +0200 |
parents | 954374379116 |
children | e57b7745e081 |
files | src/lib/test-var-expand.c |
diffstat | 1 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/test-var-expand.c Fri Nov 18 09:39:46 2016 +0200 +++ b/src/lib/test-var-expand.c Sun Dec 25 10:36:59 2016 +0200 @@ -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 @@ 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 @@ 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 @@ test_var_expand_with_funcs(); test_var_get_key(); test_var_has_key(); - test_var_expand_hashing(); + test_var_expand_extensions(); }