test-message-header-decode.c revision 2d310b66c9e541e4a3db7bac89b01534f486bb95
2e37d45867d081db150ab78dad303b9077aea24fTimo Sirainen/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenbool charset_is_utf8(const char *charset ATTR_UNUSED) { return TRUE; }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenint charset_to_utf8_begin(const char *charset ATTR_UNUSED,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen struct charset_translation **t_r ATTR_UNUSED) { return 0; }
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainenvoid charset_to_utf8_end(struct charset_translation **t ATTR_UNUSED) {}
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainencharset_to_utf8(struct charset_translation *t ATTR_UNUSED,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen const unsigned char *src, size_t *src_size, buffer_t *dest)
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen static const char *data[] = {
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen " \t=?utf-8?q?=c3=a4?= =?utf-8?q?=c3=a4?= b \t\r\n ", "ää b \t\r\n ",
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen "a =?utf-8?q?=c3=a4?=\t\t\r\n =?utf-8?q?=c3=a4?= b", "a ää b",
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen "a =?utf-8?q?=c3=a4?= x =?utf-8?q?=c3=a4?= b", "a ä x ä b",
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen unsigned int i;
132487b9a47c2eb6fc80cfa2b0aaf82c6dc3af56Timo Sirainen message_header_decode_utf8((const unsigned char *)data[i],
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen test_assert(strcmp(str_c(dest), data[i+1]) == 0);
11352dc3e4b29f3d2763c82f8ea4f99e8daf4fa3Timo Sirainenstatic void test_message_header_decode_encode_random(void)
942302b0247403645394d848b3c620ead262a2a5Timo Sirainen unsigned int i, j, buflen;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen test_begin("message header encode & decode randomly");
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen for (i = 0; i < 1000; i++) {
cd8507179823de33d6e8242e10dbc15d136245b5Timo Sirainen /* fill only with 7bit data so we don't have to worry about
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen the data being valid UTF-8 */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen for (j = 0; j < sizeof(buf); j++)
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen message_header_encode_q(buf, buflen, encoded, 0);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen message_header_decode_utf8(encoded->data, encoded->used,
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen message_header_encode_b(buf, buflen, encoded, 0);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen message_header_decode_utf8(encoded->data, encoded->used,
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen static void (*test_functions[])(void) = {