]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: Add unit test for message detail address parser
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 3 Jul 2017 16:00:14 +0000 (19:00 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 7 Aug 2017 10:27:04 +0000 (13:27 +0300)
src/lib-mail/test-message-address.c

index ebc84a0379115a43368fd2ad43838c4913bc3e7a..ac9551074810ec40152488d286e4856c654e330f 100644 (file)
@@ -295,10 +295,49 @@ static void test_message_address(void)
        test_end();
 }
 
+static void test_message_delim(void) {
+       test_begin("message address detail parsing");
+
+       struct {
+               const char *delimiters;
+               const char *address;
+               const char *username;
+               const char *detail;
+       } tests[] = {
+               { "", "", "", "" },
+               { "", "test", "test", "" },
+               { "", "test+address", "test+address", "" },
+               { "", "test:address", "test:address", "" },
+               { "", "test-address:another+delim", "test-address:another+delim", "" },
+               { "", "test@domain", "test@domain", "" },
+               { "", "test+address@domain", "test+address@domain", "" },
+               { "", "test:address@domain", "test:address@domain", "" },
+               { "", "test-address:another+delim@domain", "test-address:another+delim@domain", "" },
+
+               { "+-:", "", "", "" },
+               { "+-:", "test", "test", "" },
+               { "+-:", "test+address", "test+address", "" },
+               { "+-:", "test+-:address", "test", "address" },
+               { "+-:", "test+-:address@domain", "test@domain", "address" },
+       };
+
+       for(size_t i = 0; i < N_ELEMENTS(tests); i++) {
+               const char *username, *detail;
+
+               message_detail_address_parse(tests[i].delimiters, tests[i].address,
+                                            &username, &detail);
+               test_assert_idx(strcmp(username, tests[i].username) == 0, i);
+               test_assert_idx(strcmp(detail, tests[i].detail) == 0, i);
+       }
+
+       test_end();
+}
+
 int main(void)
 {
        static void (*test_functions[])(void) = {
                test_message_address,
+               test_message_delim,
                NULL
        };
        return test_run(test_functions);