# HG changeset patch # User Timo Sirainen # Date 1453121807 -7200 # Node ID 796996d66955ed9e3cbcb8785a3baf36a412c004 # Parent 5795761cec2b7bc20eb3a16cf77f078318009cf1 lib-mail: message-parser unit test now verifies that parsed block parts match input. diff -r 5795761cec2b -r 796996d66955 src/lib-mail/test-message-parser.c --- a/src/lib-mail/test-message-parser.c Mon Jan 18 14:56:24 2016 +0200 +++ b/src/lib-mail/test-message-parser.c Mon Jan 18 14:56:47 2016 +0200 @@ -1,6 +1,7 @@ /* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "str.h" #include "istream.h" #include "message-parser.h" #include "test-common.h" @@ -74,18 +75,29 @@ struct message_part *parts, *parts2; struct message_block block; unsigned int i, end_of_headers_idx; + string_t *output; pool_t pool; int ret; test_begin("message parser in small blocks"); pool = pool_alloconly_create("message parser", 10240); input = test_istream_create(test_msg); + output = t_str_new(128); /* full parsing */ - parser = message_parser_init(pool, input, 0, 0); - while ((ret = message_parser_parse_next_block(parser, &block)) > 0) ; + parser = message_parser_init(pool, input, 0, + MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS | + MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES); + while ((ret = message_parser_parse_next_block(parser, &block)) > 0) { + if (block.hdr != NULL) + message_header_line_write(output, block.hdr); + else + str_append_n(output, block.data, block.size); + } + test_assert(ret < 0); test_assert(message_parser_deinit(&parser, &parts) == 0); + test_assert(strcmp(test_msg, str_c(output)) == 0); /* parsing in small blocks */ i_stream_seek(input, 0);