]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: test-imap-url - Split off test_imap_url_valid_check() to reduce indent.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sat, 20 Nov 2021 14:18:56 +0000 (15:18 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:09 +0000 (13:52 +0200)
src/lib-imap/test-imap-url.c

index 208b2d40804af9ad00140a3dc287e8c9499190de..0d627ba1dc2e33f0511b32f6bfd8194a28d9f16e 100644 (file)
@@ -800,6 +800,175 @@ static const struct valid_imap_url_test valid_url_tests[] = {
 
 static const unsigned int valid_url_test_count = N_ELEMENTS(valid_url_tests);
 
+static void
+test_imap_url_valid_check(const struct imap_url *urlt,
+                         const struct imap_url *urlp)
+{
+       if (urlp->host.name == NULL || urlt->host.name == NULL) {
+               test_out_quiet(t_strdup_printf("url->host.name = %s",
+                                              urlp->host.name),
+                              urlp->host.name == urlt->host.name);
+       } else {
+               test_out_quiet(t_strdup_printf("url->host.name = %s",
+                                              urlp->host.name),
+                              strcmp(urlp->host.name, urlt->host.name) == 0);
+       }
+       if (urlp->userid == NULL || urlt->userid == NULL) {
+               test_out_quiet(t_strdup_printf("url->userid = %s",
+                                              urlp->userid),
+                              urlp->userid == urlt->userid);
+       } else {
+               test_out_quiet(t_strdup_printf("url->userid = %s",
+                                              urlp->userid),
+                              strcmp(urlp->userid, urlt->userid) == 0);
+       }
+       if (urlp->auth_type == NULL || urlt->auth_type == NULL) {
+               test_out_quiet(t_strdup_printf("url->auth_type = %s",
+                                              urlp->auth_type),
+                              urlp->auth_type == urlt->auth_type);
+       } else {
+               test_out_quiet(t_strdup_printf("url->auth_type = %s",
+                                              urlp->auth_type),
+                              strcmp(urlp->auth_type, urlt->auth_type) == 0);
+       }
+       if (urlp->port == 0) {
+               test_out_quiet("url->port = (unspecified)",
+                              urlp->port == urlt->port);
+       } else {
+               test_out_quiet(t_strdup_printf("url->port = %u", urlp->port),
+                              urlp->port == urlt->port);
+       }
+       if (urlp->host.ip.family == 0) {
+               test_out_quiet("url->host.ip = (unspecified)",
+                              urlp->host.ip.family == urlt->host.ip.family);
+       } else {
+               test_out_quiet("url->host.ip = (valid)",
+                              urlp->host.ip.family == urlt->host.ip.family);
+       }
+       if (urlp->mailbox == NULL || urlt->mailbox == NULL) {
+               test_out_quiet(t_strdup_printf("url->mailbox = %s",
+                                              urlp->mailbox),
+                              urlp->mailbox == urlt->mailbox);
+       } else {
+               test_out_quiet(t_strdup_printf("url->mailbox = %s",
+                                              urlp->mailbox),
+                              strcmp(urlp->mailbox, urlt->mailbox) == 0);
+       }
+       test_out_quiet(t_strdup_printf("url->uidvalidity = %u",
+                                      urlp->uidvalidity),
+                      urlp->uidvalidity == urlt->uidvalidity);
+       test_out_quiet(t_strdup_printf("url->uid = %u", urlp->uid),
+                      urlp->uid == urlt->uid);
+       if (urlp->section == NULL || urlt->section == NULL) {
+               test_out_quiet(t_strdup_printf("url->section = %s",
+                                              urlp->section),
+                              urlp->section == urlt->section);
+       } else {
+               test_out_quiet(t_strdup_printf("url->section = %s",
+                                              urlp->section),
+                              strcmp(urlp->section, urlt->section) == 0);
+       }
+       test_out_quiet(t_strdup_printf(
+                               "url->partial = %"PRIuUOFF_T".%"PRIuUOFF_T,
+                               urlp->partial_offset, urlp->partial_size),
+                      urlp->partial_offset == urlt->partial_offset &&
+                      urlp->partial_size == urlt->partial_size);
+       if (urlp->search_program == NULL || urlt->search_program == NULL) {
+               test_out_quiet(t_strdup_printf(
+                                       "url->search_program = %s",
+                                       urlp->search_program),
+                              urlp->search_program == urlt->search_program);
+       } else {
+               test_out_quiet(t_strdup_printf(
+                                       "url->search_program = %s",
+                                       urlp->search_program),
+                              strcmp(urlp->search_program,
+                                     urlt->search_program) == 0);
+       }
+       if (urlt->uauth_rumpurl != NULL) {
+               if (urlp->uauth_rumpurl == NULL) {
+                       test_out_quiet("url->uauth_rumpurl = NULL", FALSE);
+               } else {
+                       test_out_quiet(t_strdup_printf(
+                                               "url->uauth_rumpurl = %s",
+                                               urlp->uauth_rumpurl),
+                                      strcmp(urlp->uauth_rumpurl,
+                                             urlt->uauth_rumpurl) == 0);
+               }
+               if (urlp->uauth_access_application == NULL ||
+                   urlt->uauth_access_application == NULL) {
+                       test_out_quiet(
+                               t_strdup_printf(
+                                       "url->uauth_access_application = %s",
+                                       urlp->uauth_access_application),
+                               (urlp->uauth_access_application ==
+                                urlt->uauth_access_application));
+               } else {
+                       test_out_quiet(
+                               t_strdup_printf(
+                                       "url->uauth_access_application = %s",
+                                       urlp->uauth_access_application),
+                               strcmp(urlp->uauth_access_application,
+                                      urlt->uauth_access_application) == 0);
+               }
+               if (urlp->uauth_access_user == NULL ||
+                   urlt->uauth_access_user == NULL) {
+                       test_out_quiet(
+                               t_strdup_printf(
+                                       "url->uauth_access_user = %s",
+                                       urlp->uauth_access_user),
+                               (urlp->uauth_access_user ==
+                                urlt->uauth_access_user));
+               } else {
+                       test_out_quiet(t_strdup_printf(
+                                               "url->uauth_access_user = %s",
+                                               urlp->uauth_access_user),
+                                      strcmp(urlp->uauth_access_user,
+                                             urlt->uauth_access_user) == 0);
+               }
+               if (urlp->uauth_mechanism == NULL ||
+                   urlt->uauth_mechanism == NULL) {
+                       test_out_quiet(t_strdup_printf(
+                                               "url->uauth_mechanism = %s",
+                                               urlp->uauth_mechanism),
+                                      (urlp->uauth_mechanism ==
+                                       urlt->uauth_mechanism));
+               } else {
+                       test_out_quiet(t_strdup_printf(
+                                               "url->uauth_mechanism = %s",
+                                               urlp->uauth_mechanism),
+                                      strcmp(urlp->uauth_mechanism,
+                                             urlt->uauth_mechanism) == 0);
+               }
+               if (urlp->uauth_token == NULL || urlt->uauth_token == NULL) {
+                       test_out_quiet(t_strdup_printf(
+                                              "url->uauth_token = %s",
+                                               urlp->uauth_token),
+                                      urlp->uauth_token == urlt->uauth_token);
+               } else {
+                       bool equal = (urlp->uauth_token_size ==
+                                     urlt->uauth_token_size);
+                       size_t i;
+                       test_out_quiet(t_strdup_printf(
+                                               "url->uauth_token_size = %zu",
+                                               urlp->uauth_token_size), equal);
+
+                       if (equal) {
+                               for (i = 0; i < urlp->uauth_token_size; i++) {
+                                       if (urlp->uauth_token[i] !=
+                                           urlt->uauth_token[i]) {
+                                               equal = FALSE;
+                                               break;
+                                       }
+                               }
+                               test_out_quiet(t_strdup_printf(
+                                       "url->uauth_token [index=%d]", (int)i),
+                                       equal);
+                       }
+               }
+       }
+}
+
 static void test_imap_url_valid(void)
 {
        unsigned int i;
@@ -820,164 +989,8 @@ static void test_imap_url_valid(void)
 
                test_out_reason(t_strdup_printf("imap_url_parse(%s)",
                        valid_url_tests[i].url), urlp != NULL, error);
-               if (urlp != NULL) {
-                       if (urlp->host.name == NULL || urlt->host.name == NULL) {
-                               test_out_quiet(t_strdup_printf("url->host.name = %s",
-                                                              urlp->host.name),
-                                              urlp->host.name == urlt->host.name);
-                       } else {
-                               test_out_quiet(t_strdup_printf("url->host.name = %s",
-                                                              urlp->host.name),
-                                              strcmp(urlp->host.name,
-                                                     urlt->host.name) == 0);
-                       }
-                       if (urlp->userid == NULL || urlt->userid == NULL) {
-                               test_out_quiet(t_strdup_printf("url->userid = %s",
-                                                              urlp->userid),
-                                              urlp->userid == urlt->userid);
-                       } else {
-                               test_out_quiet(t_strdup_printf("url->userid = %s",
-                                                              urlp->userid),
-                                              strcmp(urlp->userid,
-                                                     urlt->userid) == 0);
-                       }
-                       if (urlp->auth_type == NULL || urlt->auth_type == NULL) {
-                               test_out_quiet(t_strdup_printf("url->auth_type = %s",
-                                                              urlp->auth_type),
-                                              urlp->auth_type == urlt->auth_type);
-                       } else {
-                               test_out_quiet(t_strdup_printf("url->auth_type = %s",
-                                                              urlp->auth_type),
-                                              strcmp(urlp->auth_type,
-                                                     urlt->auth_type) == 0);
-                       }
-                       if (urlp->port == 0) {
-                               test_out_quiet("url->port = (unspecified)",
-                                              urlp->port == urlt->port);
-                       } else {
-                               test_out_quiet(t_strdup_printf("url->port = %u",
-                                                              urlp->port),
-                                              urlp->port == urlt->port);
-                       }
-                       if (urlp->host.ip.family == 0) {
-                               test_out_quiet("url->host.ip = (unspecified)",
-                                              urlp->host.ip.family == urlt->host.ip.family);
-                       } else {
-                               test_out_quiet("url->host.ip = (valid)",
-                                              urlp->host.ip.family == urlt->host.ip.family);
-                       }
-                       if (urlp->mailbox == NULL || urlt->mailbox == NULL) {
-                               test_out_quiet(t_strdup_printf("url->mailbox = %s",
-                                                              urlp->mailbox),
-                                              urlp->mailbox == urlt->mailbox);
-                       } else {
-                               test_out_quiet(t_strdup_printf("url->mailbox = %s",
-                                                              urlp->mailbox),
-                                              strcmp(urlp->mailbox, urlt->mailbox) == 0);
-                       }
-                       test_out_quiet(t_strdup_printf("url->uidvalidity = %u",
-                                                      urlp->uidvalidity),
-                                      urlp->uidvalidity == urlt->uidvalidity);
-                       test_out_quiet(t_strdup_printf("url->uid = %u", urlp->uid),
-                                      urlp->uid == urlt->uid);
-                       if (urlp->section == NULL || urlt->section == NULL) {
-                               test_out_quiet(t_strdup_printf("url->section = %s",
-                                                              urlp->section),
-                                              urlp->section == urlt->section);
-                       } else {
-                               test_out_quiet(t_strdup_printf("url->section = %s",
-                                                              urlp->section),
-                                              strcmp(urlp->section, urlt->section) == 0);
-                       }
-                       test_out_quiet(t_strdup_printf("url->partial = %"PRIuUOFF_T".%"PRIuUOFF_T,
-                                                      urlp->partial_offset, urlp->partial_size),
-                                      urlp->partial_offset == urlt->partial_offset &&
-                                      urlp->partial_size == urlt->partial_size);
-                       if (urlp->search_program == NULL || urlt->search_program == NULL) {
-                               test_out_quiet(t_strdup_printf(
-                                                       "url->search_program = %s",
-                                                       urlp->search_program),
-                                              urlp->search_program == urlt->search_program);
-                       } else {
-                               test_out_quiet(t_strdup_printf(
-                                                       "url->search_program = %s",
-                                                       urlp->search_program),
-                                              strcmp(urlp->search_program, urlt->search_program) == 0);
-                       }
-                       if (urlt->uauth_rumpurl != NULL) {
-                               if (urlp->uauth_rumpurl == NULL) {
-                                       test_out_quiet("url->uauth_rumpurl = NULL", FALSE);
-                               } else {
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_rumpurl = %s",
-                                                               urlp->uauth_rumpurl),
-                                                      strcmp(urlp->uauth_rumpurl, urlt->uauth_rumpurl) == 0);
-                               }
-                               if (urlp->uauth_access_application == NULL ||
-                                   urlt->uauth_access_application == NULL) {
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_access_application = %s",
-                                                               urlp->uauth_access_application),
-                                                      urlp->uauth_access_application == urlt->uauth_access_application);
-                               } else {
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_access_application = %s",
-                                                               urlp->uauth_access_application),
-                                                      strcmp(urlp->uauth_access_application,
-                                                             urlt->uauth_access_application) == 0);
-                               }
-                               if (urlp->uauth_access_user == NULL ||
-                                   urlt->uauth_access_user == NULL) {
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_access_user = %s",
-                                                               urlp->uauth_access_user),
-                                                      urlp->uauth_access_user == urlt->uauth_access_user);
-                               } else {
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_access_user = %s",
-                                                               urlp->uauth_access_user),
-                                                      strcmp(urlp->uauth_access_user,
-                                                             urlt->uauth_access_user) == 0);
-                               }
-                               if (urlp->uauth_mechanism == NULL || urlt->uauth_mechanism == NULL) {
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_mechanism = %s",
-                                                               urlp->uauth_mechanism),
-                                                      urlp->uauth_mechanism == urlt->uauth_mechanism);
-                               } else {
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_mechanism = %s",
-                                                               urlp->uauth_mechanism),
-                                                      strcmp(urlp->uauth_mechanism,
-                                                             urlt->uauth_mechanism) == 0);
-                               }
-                               if (urlp->uauth_token == NULL || urlt->uauth_token == NULL) {
-                                       test_out_quiet(t_strdup_printf(
-                                                              "url->uauth_token = %s",
-                                                               urlp->uauth_token),
-                                                      urlp->uauth_token == urlt->uauth_token);
-                               } else {
-                                       bool equal = urlp->uauth_token_size == urlt->uauth_token_size;
-                                       size_t i;
-                                       test_out_quiet(t_strdup_printf(
-                                                               "url->uauth_token_size = %zu",
-                                                               urlp->uauth_token_size),
-                                                      equal);
-
-                                       if (equal) {
-                                               for (i = 0; i < urlp->uauth_token_size; i++) {
-                                                       if (urlp->uauth_token[i] != urlt->uauth_token[i]) {
-                                                               equal = FALSE;
-                                                               break;
-                                                       }
-                                               }
-                                               test_out_quiet(t_strdup_printf(
-                                                       "url->uauth_token [index=%d]", (int)i),
-                                                       equal);
-                                       }
-                               }
-                       }
-               }
+               if (urlp != NULL)
+                       test_imap_url_valid_check(urlt, urlp);
 
                test_end();
        } T_END;