]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add tests for extensions
authorAki Tuomi <aki.tuomi@dovecot.fi>
Sun, 25 Dec 2016 08:36:59 +0000 (10:36 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 31 Mar 2017 11:03:12 +0000 (14:03 +0300)
src/lib/test-var-expand.c

index 83c4710e43f7fb3e156a855a0eaf76265bd296b4..386b1c6a1596d5038db9fb8870dbf0738b560304 100644 (file)
@@ -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();
 }