/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "istream.h"
#include "istream-dot.h"
#include "test-common.h"
struct dot_test {
const char *input;
const char *output;
const char *parent_input;
};
bool send_last_lf, bool test_bufsize)
{
const unsigned char *data;
unsigned int i;
int ret;
if (!send_last_lf &&
if (output_len > 0 &&
output_len--;
if (output_len > 0 &&
output_len--;
}
}
if (!test_bufsize) {
outsize = 1; i = 0;
switch (ret) {
case -2:
/* seek one byte backwards so stream gets
reset */
/* go back to original position */
/* and finally allow reading one more byte */
break;
case 0:
test_istream_set_size(test_input, ++i);
break;
default:
test_assert(ret > 0);
}
}
(void)i_stream_read(test_input);
} else {
size = 0;
for (i = 1; i < output_len; i++) {
}
if (size < output_len)
if (size > 0)
}
/* read the data after the '.' line and verify it's still there */
(void)i_stream_read(test_input);
if (size > 0)
}
{
unsigned int i;
int ret;
if (!test_bufsize) {
outsize = 1; i = 0;
switch (ret) {
case -2:
/* seek one byte backwards so stream gets
reset */
/* go back to original position */
/* and finally allow reading one more byte */
break;
case 0:
test_istream_set_size(test_input, ++i);
break;
default:
test_assert(ret > 0);
}
}
(void)i_stream_read(test_input);
} else {
for (i = 1; i <= input_len; i++) {
(void)i_stream_read(input);
(void)i_stream_read(input);
}
(void)i_stream_read(input);
}
}
static void test_istream_dot(void)
{
{ "..foo\n..\n.foo\n.\nfoo", ".foo\n.\nfoo\n", "foo" },
{ "..foo\r\n..\r\n.foo\r\n.\r\nfoo", ".foo\r\n.\r\nfoo\r\n", "foo" },
{ "\r.\r\n.\r\n", "\r.\r\n", "" },
{ "\n\r.\r\r\n.\r\n", "\n\r.\r\r\n", "" },
{ "\r\n.\rfoo\n.\n", "\r\n\rfoo\n", "" },
{ "\r\n.\r\n", "\r\n", "" },
{ "\n.\r\n", "\n", "" },
{ "\n.\n", "\n", "" },
{ ".\r\n", "", "" },
{ ".\n", "", "" }
};
static const char *error_tests[] = {
"",
".",
"..",
".\r",
".\rx",
"..\r\n",
"\r.",
"\r.\r",
"\r.\rx",
"\r.\r\n",
"\r.\n",
"\r..\n",
"\r\n",
"\r\n.",
"\r\n.\r",
"\r\n.\rx",
"\r\n.\rx\n",
"\r\n..\r\n",
"\n",
"\n.",
"\n.\r",
"\n.\rx",
"\n..\r\n"
};
unsigned int i;
test_begin("dot istream");
for (i = 0; i < N_ELEMENTS(tests); i++) {
}
for (i = 0; i < N_ELEMENTS(error_tests); i++) {
}
test_end();
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}