test-message-header-decode.c revision baf3e87e186453fda13bd21f7cbcb2efc8492e8b
2e37d45867d081db150ab78dad303b9077aea24fTimo Sirainen/* Copyright (c) 2009-2016 Dovecot authors, see the included COPYING file */
37847ec8eaec9ad55c9df10ae109efe7b37ac573Timo Sirainenbool charset_is_utf8(const char *charset ATTR_UNUSED) { return TRUE; }
37847ec8eaec9ad55c9df10ae109efe7b37ac573Timo Sirainenint charset_to_utf8_begin(const char *charset ATTR_UNUSED,
94d8e51119003d2bc5a100c663f90141f297385dTimo Sirainen struct charset_translation **t_r ATTR_UNUSED) { return 0; }
ef50336eefcb9ba99f73c6af37420eaf8857a39bTimo Sirainenvoid charset_to_utf8_end(struct charset_translation **t ATTR_UNUSED) {}
ef50336eefcb9ba99f73c6af37420eaf8857a39bTimo Sirainencharset_to_utf8(struct charset_translation *t ATTR_UNUSED,
91b203fd2132510a47a4b34252c0ae0efd688a19Timo Sirainen const unsigned char *src, size_t *src_size, buffer_t *dest)
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen static const char *data[] = {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen " \t=?utf-8?q?=c3=a4?= =?utf-8?q?=c3=a4?= b \t\r\n ", "\xC3\xA4\xC3\xA4 b \t\r\n ",
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "a =?utf-8?q?=c3=a4?=\t\t\r\n =?utf-8?q?=c3=a4?= b", "a \xC3\xA4\xC3\xA4 b",
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "a =?utf-8?q?=c3=a4?= x =?utf-8?q?=c3=a4?= b", "a \xC3\xA4 x \xC3\xA4 b",
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "a =?utf-8?b?w6TDpCDDpA==?= b", "a \xC3\xA4\xC3\xA4 \xC3\xA4 b",
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen unsigned int i;
de486b59018016977015ef42e6071155b60e82e1Timo Sirainen message_header_decode_utf8((const unsigned char *)data[i],
220e21750948941dc6e33b8f11b552fa21d7f81eTimo Sirainen test_assert(strcmp(str_c(dest), data[i+1]) == 0);
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainenstatic void test_message_header_decode_encode_random(void)
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen unsigned int i, j, buflen;
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen test_begin("message header encode & decode randomly");
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen for (i = 0; i < 1000; i++) {
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* fill only with 7bit data so we don't have to worry about
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen the data being valid UTF-8 */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen for (j = 0; j < sizeof(buf); j++)
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen message_header_encode_q(buf, buflen, encoded, 0);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen message_header_decode_utf8(encoded->data, encoded->used,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen message_header_encode_b(buf, buflen, encoded, 0);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen message_header_decode_utf8(encoded->data, encoded->used,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen static void (*const test_functions[])(void) = {