]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: Reformat test-smtp-params.c.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 8 Oct 2019 22:43:52 +0000 (00:43 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 7 Nov 2019 07:34:34 +0000 (07:34 +0000)
src/lib-smtp/test-smtp-params.c

index ac05e1cad03471265676d72e665b47ba71a4d946..1e03afc47aa0d04f3fc21717ec8e4e0700d95859 100644 (file)
@@ -55,20 +55,23 @@ valid_mail_params_parse_tests[] = {
                .params = {
                        .auth = &test_address1
                }
-       },{
+       },
+       {
                .input = "AUTH=user+2Bdetail",
                .caps = SMTP_CAPABILITY_AUTH,
                .params = {
                        .auth = &test_address2
                }
-       },{
+       },
+       {
                .input = "AUTH=e+3Dmc2@example.com",
                .caps = SMTP_CAPABILITY_AUTH,
                .params = {
                        .auth = &test_address3
                }
+       },
        /* BODY */
-       },{
+       {
                .input = "",
                .caps = SMTP_CAPABILITY_8BITMIME,
                .params = {
@@ -76,7 +79,8 @@ valid_mail_params_parse_tests[] = {
                                .type = SMTP_PARAM_MAIL_BODY_TYPE_UNSPECIFIED,
                        }
                }
-       },{
+       },
+       {
                .input = "BODY=7BIT",
                .caps = SMTP_CAPABILITY_8BITMIME,
                .params = {
@@ -84,7 +88,8 @@ valid_mail_params_parse_tests[] = {
                                .type = SMTP_PARAM_MAIL_BODY_TYPE_7BIT,
                        }
                }
-       },{
+       },
+       {
                .input = "BODY=8BITMIME",
                .caps = SMTP_CAPABILITY_8BITMIME,
                .params = {
@@ -92,7 +97,8 @@ valid_mail_params_parse_tests[] = {
                                .type = SMTP_PARAM_MAIL_BODY_TYPE_8BITMIME,
                        }
                }
-       },{
+       },
+       {
                .input = "BODY=BINARYMIME",
                .caps = SMTP_CAPABILITY_8BITMIME |
                        SMTP_CAPABILITY_BINARYMIME |
@@ -102,7 +108,8 @@ valid_mail_params_parse_tests[] = {
                                .type = SMTP_PARAM_MAIL_BODY_TYPE_BINARYMIME,
                        }
                }
-       },{
+       },
+       {
                .input = "BODY=FROP",
                .caps = SMTP_CAPABILITY_8BITMIME |
                        SMTP_CAPABILITY_BINARYMIME |
@@ -114,65 +121,75 @@ valid_mail_params_parse_tests[] = {
                                .ext = "FROP"
                        }
                }
+       },
        /* ENVID */
-       },{
+       {
                .input = "",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .envid = NULL,
                }
-       },{
+       },
+       {
                .input = "ENVID=",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .envid = "",
                }
-       },{
+       },
+       {
                .input = "ENVID=AABBCCDD",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .envid = "AABBCCDD",
                }
-       },{
+       },
+       {
                .input = "ENVID=AA+2BBB+3DCC+2BDD",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .envid = "AA+BB=CC+DD",
                }
+       },
        /* RET */
-       },{
+       {
                .input = "",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .ret = SMTP_PARAM_MAIL_RET_UNSPECIFIED,
                }
-       },{
+       },
+       {
                .input = "RET=HDRS",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .ret = SMTP_PARAM_MAIL_RET_HDRS,
                }
-       },{
+       },
+       {
                .input = "RET=FULL",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .ret = SMTP_PARAM_MAIL_RET_FULL,
                }
+       },
        /* SIZE */
-       },{
+       {
                .input = "",
                .caps = SMTP_CAPABILITY_SIZE,
                .params = {
                        .size = 0
                }
-       },{
+       },
+       {
                .input = "SIZE=267914296",
                .caps = SMTP_CAPABILITY_SIZE,
                .params = {
                        .size = 267914296
                }
+       },
        /* <extensions> */
-       },{
+       {
                .input = "FROP=friep",
                .caps = SMTP_CAPABILITY_SIZE,
                .extensions = test_extensions,
@@ -184,7 +201,8 @@ valid_mail_params_parse_tests[] = {
                                }
                        }
                }
-       },{
+       },
+       {
                .input = "FROP=friep FRUP=frml",
                .extensions = test_extensions,
                .params = {
@@ -203,10 +221,10 @@ unsigned int valid_mail_params_parse_test_count =
 
 static void
 test_smtp_mail_params_auth(const struct smtp_params_mail *test,
-       const struct smtp_params_mail *parsed)
+                          const struct smtp_params_mail *parsed)
 {
        if (parsed->auth->localpart == NULL ||
-               test->auth->localpart == NULL) {
+           test->auth->localpart == NULL) {
                test_out(t_strdup_printf("params.auth->localpart = %s",
                                         parsed->auth->localpart),
                         (parsed->auth->localpart == test->auth->localpart));
@@ -217,7 +235,7 @@ test_smtp_mail_params_auth(const struct smtp_params_mail *test,
                                test->auth->localpart) == 0);
        }
        if (parsed->auth->domain == NULL ||
-               test->auth->domain == NULL) {
+           test->auth->domain == NULL) {
                test_out(t_strdup_printf("params.auth->domain = %s",
                                         parsed->auth->domain),
                         (parsed->auth->domain == test->auth->domain));
@@ -231,7 +249,7 @@ test_smtp_mail_params_auth(const struct smtp_params_mail *test,
 
 static void
 test_smtp_mail_params_body(const struct smtp_params_mail *test,
-       const struct smtp_params_mail *parsed)
+                          const struct smtp_params_mail *parsed)
 {
        const char *type_name = NULL;
 
@@ -256,18 +274,17 @@ test_smtp_mail_params_body(const struct smtp_params_mail *test,
        }
 
        test_out(t_strdup_printf("params.body.type = %s", type_name),
-               (parsed->body.type == test->body.type &&
-                       (parsed->body.type != SMTP_PARAM_MAIL_BODY_TYPE_EXTENSION ||
-                               (parsed->body.ext != NULL &&
-                                       strcmp(parsed->body.ext, test->body.ext) == 0))));
+                (parsed->body.type == test->body.type &&
+                 (parsed->body.type != SMTP_PARAM_MAIL_BODY_TYPE_EXTENSION ||
+                  (parsed->body.ext != NULL &&
+                   strcmp(parsed->body.ext, test->body.ext) == 0))));
 }
 
 static void
 test_smtp_mail_params_envid(const struct smtp_params_mail *test,
-       const struct smtp_params_mail *parsed)
+                           const struct smtp_params_mail *parsed)
 {
-       if (parsed->envid == NULL ||
-               test->envid == NULL) {
+       if (parsed->envid == NULL || test->envid == NULL) {
                test_out(t_strdup_printf("params.auth->localpart = %s",
                                         parsed->envid),
                         (parsed->envid == test->envid));
@@ -280,7 +297,7 @@ test_smtp_mail_params_envid(const struct smtp_params_mail *test,
 
 static void
 test_smtp_mail_params_ret(const struct smtp_params_mail *test,
-       const struct smtp_params_mail *parsed)
+                         const struct smtp_params_mail *parsed)
 {
        const char *ret_name = NULL;
 
@@ -304,7 +321,7 @@ test_smtp_mail_params_ret(const struct smtp_params_mail *test,
 
 static void
 test_smtp_mail_params_size(const struct smtp_params_mail *test,
-       const struct smtp_params_mail *parsed)
+                          const struct smtp_params_mail *parsed)
 {
        test_out(t_strdup_printf("params.size = %"PRIuUOFF_T, parsed->size),
                 parsed->size == test->size);
@@ -312,32 +329,32 @@ test_smtp_mail_params_size(const struct smtp_params_mail *test,
 
 static void
 test_smtp_mail_params_extensions(const struct smtp_params_mail *test,
-       const struct smtp_params_mail *parsed)
+                                const struct smtp_params_mail *parsed)
 {
        const struct smtp_param *tparam, *pparam;
        unsigned int i;
 
        if (!array_is_created(&test->extra_params) ||
-               array_count(&test->extra_params) == 0) {
+           array_count(&test->extra_params) == 0) {
                test_out(t_strdup_printf("params.extra_params.count = %u",
-                        (!array_is_created(&parsed->extra_params) ? 0 :
-                               array_count(&parsed->extra_params))),
+                        (!array_is_created(&parsed->extra_params) ?
+                         0 : array_count(&parsed->extra_params))),
                         (!array_is_created(&parsed->extra_params) ||
-                               array_count(&parsed->extra_params) == 0));
+                         array_count(&parsed->extra_params) == 0));
                return;
        }
 
        if (!array_is_created(&parsed->extra_params) ||
-               array_count(&parsed->extra_params) == 0) {
+           array_count(&parsed->extra_params) == 0) {
                test_out("params.extra_params.count = 0", FALSE);
                return;
        }
 
        if (array_count(&test->extra_params) !=
-               array_count(&parsed->extra_params)) {
+           array_count(&parsed->extra_params)) {
                test_out(t_strdup_printf("params.extra_params.count = %u",
-                        (!array_is_created(&parsed->extra_params) ? 0 :
-                               array_count(&parsed->extra_params))), FALSE);
+                        (!array_is_created(&parsed->extra_params) ?
+                         0 : array_count(&parsed->extra_params))), FALSE);
                return;
        }
 
@@ -345,13 +362,12 @@ test_smtp_mail_params_extensions(const struct smtp_params_mail *test,
                tparam = array_idx(&test->extra_params, i);
                pparam = array_idx(&parsed->extra_params, i);           
        
-               test_out(t_strdup_printf(
-                       "params.extra_params[%u] = [\"%s\"=\"%s\"]", i,
-                               pparam->keyword, pparam->value),
-                       strcmp(pparam->keyword, tparam->keyword) == 0 &&
+               test_out(t_strdup_printf("params.extra_params[%u] = [\"%s\"=\"%s\"]",
+                                        i, pparam->keyword, pparam->value),
+                        strcmp(pparam->keyword, tparam->keyword) == 0 &&
                                ((pparam->value == NULL && tparam->value == NULL) ||
                                 (pparam->value != NULL && tparam->value != NULL &&
-                                       strcmp(pparam->value, tparam->value) == 0)));
+                                 strcmp(pparam->value, tparam->value) == 0)));
        }
 }
 
@@ -372,8 +388,8 @@ static void test_smtp_mail_params_parse_valid(void)
                        test->body_extensions, &params, &error_code, &error);
 
                test_begin(t_strdup_printf("smtp mail params valid [%d]", i));
-               test_out_reason(t_strdup_printf("parse(\"%s\")",
-                       test->input), ret >= 0, error);
+               test_out_reason(t_strdup_printf("parse(\"%s\")", test->input),
+                               ret >= 0, error);
 
                if (ret >= 0) {
                        string_t *encoded;
@@ -402,9 +418,9 @@ static void test_smtp_mail_params_parse_valid(void)
                        smtp_params_mail_write(encoded, test->caps, &params);
 
                        output = (test->output == NULL ? test->input : test->output);
-                       test_out(t_strdup_printf
-                               ("encode() = \"%s\"", str_c(encoded)),
-                               strcmp(str_c(encoded), output) == 0);
+                       test_out(t_strdup_printf("encode() = \"%s\"",
+                                                str_c(encoded)),
+                                strcmp(str_c(encoded), output) == 0);
                }
                test_end();
        } T_END;
@@ -424,38 +440,50 @@ invalid_mail_params_parse_tests[] = {
        /* AUTH */
        {
                .input = "AUTH=<>",
-       },{
+       },
+       {
                .input = "AUTH=++",
                .caps = SMTP_CAPABILITY_AUTH
+       },
        /* BODY */
-       },{
+       {
                .input = "BODY=8BITMIME",
-       },{
+       },
+       {
                .input = "BODY=BINARYMIME",
-       },{
+       },
+       {
                .input = "BODY=BINARYMIME",
                .caps = SMTP_CAPABILITY_BINARYMIME
-       },{
+       },
+       {
                .input = "BODY=FROP",
                .caps = SMTP_CAPABILITY_8BITMIME
+       },
        /* ENVID */
-       },{
+       {
                .input = "ENVID=AABBCC",
-       },{
+       },
+       {
                .input = "ENVID=++",
                .caps = SMTP_CAPABILITY_DSN
+       },
        /* RET */
-       },{
+       {
                .input = "RET=FULL",
-       },{
+       },
+       {
                .input = "RET=HDR",
-       },{
+       },
+       {
                .input = "RET=FROP",
                .caps = SMTP_CAPABILITY_DSN
+       },
        /* SIZE */
-       },{
+       {
                .input = "SIZE=13",
-       },{
+       },
+       {
                .input = "SIZE=ABC",
                .caps = SMTP_CAPABILITY_SIZE
        }
@@ -477,12 +505,13 @@ static void test_smtp_mail_params_parse_invalid(void)
 
                test = &invalid_mail_params_parse_tests[i];
                ret = smtp_params_mail_parse(pool_datastack_create(),
-                       test->input, test->caps, test->extensions, NULL,
-                       &params, &error_code, &error);
+                                            test->input, test->caps,
+                                            test->extensions, NULL,
+                                            &params, &error_code, &error);
 
                test_begin(t_strdup_printf("smtp mail params invalid [%d]", i));
-               test_out_reason(t_strdup_printf("parse(\"%s\")",
-                       test->input), ret < 0, error);
+               test_out_reason(t_strdup_printf("parse(\"%s\")", test->input),
+                               ret < 0, error);
                test_end();
        } T_END;
 }
@@ -500,10 +529,11 @@ struct valid_rcpt_params_parse_test {
 
 static const struct valid_rcpt_params_parse_test
 valid_rcpt_params_parse_tests[] = {
-       /* AUTH */
-       {
+       /* ORCPT */
 #if 0 // FIXME: message_address_parser() does not allow bare localpart
       //         addresses.
+       {
+
                .input = "ORCPT=rfc822;user+2Bdetail",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
@@ -511,8 +541,9 @@ valid_rcpt_params_parse_tests[] = {
                                .addr = &test_address2
                        }
                }
-       },{
+       },
 #endif
+       {
                .input = "ORCPT=rfc822;e+3Dmc2@example.com",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
@@ -520,38 +551,44 @@ valid_rcpt_params_parse_tests[] = {
                                .addr = &test_address3
                        }
                }
+       },
        /* NOTIFY */
-       },{
+       {
                .input = "",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .notify = SMTP_PARAM_RCPT_NOTIFY_UNSPECIFIED,
                }
-       },{
+       },
+       {
                .input = "NOTIFY=SUCCESS",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .notify = SMTP_PARAM_RCPT_NOTIFY_SUCCESS,
                }
-       },{
+       },
+       {
                .input = "NOTIFY=FAILURE",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .notify = SMTP_PARAM_RCPT_NOTIFY_FAILURE,
                }
-       },{
+       },
+       {
                .input = "NOTIFY=DELAY",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .notify = SMTP_PARAM_RCPT_NOTIFY_DELAY,
                }
-       },{
+       },
+       {
                .input = "NOTIFY=NEVER",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
                        .notify = SMTP_PARAM_RCPT_NOTIFY_NEVER,
                }
-       },{
+       },
+       {
                .input = "NOTIFY=SUCCESS,FAILURE,DELAY",
                .caps = SMTP_CAPABILITY_DSN,
                .params = {
@@ -559,8 +596,9 @@ valid_rcpt_params_parse_tests[] = {
                                SMTP_PARAM_RCPT_NOTIFY_FAILURE |
                                SMTP_PARAM_RCPT_NOTIFY_DELAY,
                }
+       },
        /* <extensions> */
-       },{
+       {
                .input = "FROP=friep",
                .caps = SMTP_CAPABILITY_SIZE,
                .extensions = test_extensions,
@@ -572,7 +610,8 @@ valid_rcpt_params_parse_tests[] = {
                                }
                        }
                }
-       },{
+       },
+       {
                .input = "FROP=friep FRUP=frml",
                .extensions = test_extensions,
                .params = {
@@ -591,7 +630,7 @@ unsigned int valid_rcpt_params_parse_test_count =
 
 static void
 test_smtp_rcpt_params_orcpt(const struct smtp_params_rcpt *test,
-       const struct smtp_params_rcpt *parsed)
+                           const struct smtp_params_rcpt *parsed)
 {
        if (parsed->orcpt.addr == NULL) {
                test_out("params.orcpt.addr = NULL",
@@ -600,11 +639,11 @@ test_smtp_rcpt_params_orcpt(const struct smtp_params_rcpt *test,
        }
                
        if (parsed->orcpt.addr->localpart == NULL ||
-               test->orcpt.addr->localpart == NULL) {
+           test->orcpt.addr->localpart == NULL) {
                test_out(t_strdup_printf("params.orcpt.addr->localpart = %s",
                                         parsed->orcpt.addr->localpart),
                         (parsed->orcpt.addr->localpart ==
-                               test->orcpt.addr->localpart));
+                         test->orcpt.addr->localpart));
        } else {
                test_out(t_strdup_printf("params.orcpt.addr->localpart = \"%s\"",
                                         parsed->orcpt.addr->localpart),
@@ -612,11 +651,11 @@ test_smtp_rcpt_params_orcpt(const struct smtp_params_rcpt *test,
                                test->orcpt.addr->localpart) == 0);
        }
        if (parsed->orcpt.addr->domain == NULL ||
-               test->orcpt.addr->domain == NULL) {
+           test->orcpt.addr->domain == NULL) {
                test_out(t_strdup_printf("params.orcpt.addr->domain = %s",
                                         parsed->orcpt.addr->domain),
                         (parsed->orcpt.addr->domain ==
-                               test->orcpt.addr->domain));
+                         test->orcpt.addr->domain));
        } else {
                test_out(t_strdup_printf("params.orcpt.addr->domain = \"%s\"",
                                         parsed->orcpt.addr->domain),
@@ -628,7 +667,7 @@ test_smtp_rcpt_params_orcpt(const struct smtp_params_rcpt *test,
 
 static void
 test_smtp_rcpt_params_notify(const struct smtp_params_rcpt *test,
-       const struct smtp_params_rcpt *parsed)
+                            const struct smtp_params_rcpt *parsed)
 {
        string_t *notify_name;
 
@@ -661,29 +700,29 @@ test_smtp_rcpt_params_notify(const struct smtp_params_rcpt *test,
 
 static void
 test_smtp_rcpt_params_extensions(const struct smtp_params_rcpt *test,
-       const struct smtp_params_rcpt *parsed)
+                                const struct smtp_params_rcpt *parsed)
 {
        const struct smtp_param *tparam, *pparam;
        unsigned int i;
 
        if (!array_is_created(&test->extra_params) ||
-               array_count(&test->extra_params) == 0) {
+           array_count(&test->extra_params) == 0) {
                test_out(t_strdup_printf("params.extra_params.count = %u",
-                        (!array_is_created(&parsed->extra_params) ? 0 :
-                               array_count(&parsed->extra_params))),
+                        (!array_is_created(&parsed->extra_params) ?
+                         0 : array_count(&parsed->extra_params))),
                         (!array_is_created(&parsed->extra_params) ||
-                               array_count(&parsed->extra_params) == 0));
+                         array_count(&parsed->extra_params) == 0));
                return;
        }
 
        if (!array_is_created(&parsed->extra_params) ||
-               array_count(&parsed->extra_params) == 0) {
+           array_count(&parsed->extra_params) == 0) {
                test_out("params.extra_params.count = 0", FALSE);
                return;
        }
 
        if (array_count(&test->extra_params) !=
-               array_count(&parsed->extra_params)) {
+           array_count(&parsed->extra_params)) {
                test_out(t_strdup_printf("params.extra_params.count = %u",
                         (!array_is_created(&parsed->extra_params) ? 0 :
                                array_count(&parsed->extra_params))), FALSE);
@@ -694,13 +733,12 @@ test_smtp_rcpt_params_extensions(const struct smtp_params_rcpt *test,
                tparam = array_idx(&test->extra_params, i);
                pparam = array_idx(&parsed->extra_params, i);           
        
-               test_out(t_strdup_printf(
-                               "params.extra_params[%u] = [\"%s\"=\"%s\"]", i,
-                               pparam->keyword, pparam->value),
+               test_out(t_strdup_printf("params.extra_params[%u] = [\"%s\"=\"%s\"]",
+                                        i, pparam->keyword, pparam->value),
                         strcmp(pparam->keyword, tparam->keyword) == 0 &&
                                ((pparam->value == NULL && tparam->value == NULL) ||
                                 (pparam->value != NULL && tparam->value != NULL &&
-                                       strcmp(pparam->value, tparam->value) == 0)));
+                                 strcmp(pparam->value, tparam->value) == 0)));
        }
 }
 
@@ -717,8 +755,9 @@ static void test_smtp_rcpt_params_parse_valid(void)
 
                test = &valid_rcpt_params_parse_tests[i];
                ret = smtp_params_rcpt_parse(pool_datastack_create(),
-                       test->input, test->caps, test->extensions,
-                       &params, &error_code, &error);
+                                            test->input, test->caps,
+                                            test->extensions,
+                                            &params, &error_code, &error);
 
                test_begin(t_strdup_printf("smtp rcpt params valid [%d]", i));
                test_out_reason(t_strdup_printf("parse(\"%s\")",
@@ -763,18 +802,23 @@ invalid_rcpt_params_parse_tests[] = {
        /* DSN */
        {
                .input = "ORCPT=rfc822;frop@example.com",
-       },{
+       },
+       {
                .input = "ORCPT=++",
                .caps = SMTP_CAPABILITY_DSN
-       },{
+       },
+       {
                .input = "ORCPT=rfc822;++",
                .caps = SMTP_CAPABILITY_DSN
-       },{
+       },
+       {
                .input = "NOTIFY=SUCCESS",
-       },{
+       },
+       {
                .input = "NOTIFY=FROP",
                .caps = SMTP_CAPABILITY_DSN
-       },{
+       },
+       {
                .input = "NOTIFY=NEVER,SUCCESS",
                .caps = SMTP_CAPABILITY_DSN
        }
@@ -796,12 +840,13 @@ static void test_smtp_rcpt_params_parse_invalid(void)
 
                test = &invalid_rcpt_params_parse_tests[i];
                ret = smtp_params_rcpt_parse(pool_datastack_create(),
-                       test->input, test->caps, test->extensions,
-                       &params, &error_code, &error);
+                                            test->input, test->caps,
+                                            test->extensions,
+                                            &params, &error_code, &error);
 
                test_begin(t_strdup_printf("smtp rcpt params invalid [%d]", i));
-               test_out_reason(t_strdup_printf("parse(\"%s\")",
-                       test->input), ret < 0, error);
+               test_out_reason(t_strdup_printf("parse(\"%s\")", test->input),
+                               ret < 0, error);
                test_end();
        } T_END;
 }