]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test-base64 - Test MAX_BASE64_{EN,DE}CODED_SIZE() with existing tests
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Fri, 29 Mar 2019 07:59:09 +0000 (09:59 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Sun, 25 Aug 2019 12:45:26 +0000 (14:45 +0200)
src/lib/test-base64.c

index ef10632498f81b767f35c7d1c198b2e01dd0909b..974be149cc36855ff845a0f778d540a19ca5fa48 100644 (file)
@@ -26,6 +26,9 @@ static void test_base64_encode(void)
                str_truncate(str, 0);
                base64_encode(input[i], strlen(input[i]), str);
                test_assert(strcmp(output[i], str_c(str)) == 0);
+               test_assert(
+                       str_len(str) == MAX_BASE64_ENCODED_SIZE(
+                               strlen(input[i])));
        }
        test_end();
 }
@@ -72,6 +75,12 @@ static void test_base64_decode(void)
                            (src_pos == output[i].src_pos ||
                             (output[i].src_pos == UINT_MAX &&
                              src_pos == strlen(input[i]))));
+
+               if (ret >= 0) {
+                       test_assert(
+                               str_len(str) <= MAX_BASE64_DECODED_SIZE(
+                                       strlen(input[i])));
+               }
        }
        test_end();
 }