1
/* Copyright (c) 2013-2015 Dovecot authors, see the included COPYING file */
8
#include "ostream-dot.h"
9
#include "test-common.h"
16
static void test_ostream_dot_one(const struct dot_test *test)
18
struct istream *test_input;
19
struct ostream *output, *test_output;
20
buffer_t *output_data;
21
const unsigned char *data;
25
test_input = test_istream_create(test->input);
26
output_data = buffer_create_dynamic(pool_datastack_create(), 1024);
27
test_output = o_stream_create_buffer(output_data);
29
output = o_stream_create_dot(test_output, FALSE);
31
while ((ret = i_stream_read(test_input)) > 0 || ret == -2) {
32
data = i_stream_get_data(test_input, &size);
33
ret = o_stream_send(output, data, size);
34
test_assert(ret >= 0);
37
i_stream_skip(test_input, ret);
40
test_assert(test_input->eof);
42
test_assert(o_stream_flush(output) > 0);
43
o_stream_unref(&output);
44
o_stream_unref(&test_output);
46
test_assert(strcmp(str_c(output_data), test->output) == 0);
48
i_stream_unref(&test_input);
51
static void test_ostream_dot(void)
53
static struct dot_test tests[] = {
54
{ "foo\r\n.\r\n", "foo\r\n..\r\n.\r\n" },
55
{ "foo\n.\n", "foo\r\n..\r\n.\r\n" },
56
{ ".foo\r\n.\r\nfoo\r\n", "..foo\r\n..\r\nfoo\r\n.\r\n" },
57
{ ".foo\n.\nfoo\n", "..foo\r\n..\r\nfoo\r\n.\r\n" },
58
{ "\r\n", "\r\n.\r\n" },
59
{ "\n", "\r\n.\r\n" },
64
for (i = 0; i < N_ELEMENTS(tests); i++) {
65
test_begin(t_strdup_printf("dot ostream[%d]:", i));
66
test_ostream_dot_one(&tests[i]);
73
static void (*test_functions[])(void) = {
77
return test_run(test_functions);