test-istream-header-filter.c revision 07bba7cf547c26c6f46f23bb84b6cab919b4ae0c
/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "istream.h"
#include "message-header-parser.h"
#include "istream-header-filter.h"
#include "test-common.h"
static void
{
const unsigned char *data;
for (i = 1; i < input_len; i++) {
}
/* run again to make sure it's still correct the second time */
i_stream_seek(filter, 0);
while (i_stream_read(filter) > 0) ;
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
/* drop 1) first header, 2) X-Drop header */
}
}
static void test_istream_filter(void)
{
const char *input = "From: foo\nFrom: abc\nTo: bar\nSubject: plop\nX-Drop: 1\n\nhello world\n";
const char *output = "From: abc\n\nhello world\n";
const unsigned char *data;
test_begin("i_stream_create_header_filter: exclude");
filter_callback, (void *)NULL);
(void *)NULL);
for (i = 1; i < input_len; i++) {
}
i_stream_seek(filter, 0);
while (i_stream_read(filter) > 0) ;
test_end();
}
{
unsigned int i;
for (i = 0; i < count; i++)
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
}
static void test_istream_filter_large_buffer(void)
{
const unsigned char *data;
const char *p;
unsigned int i;
test_begin("i_stream_create_header_filter: large buffer");
NULL, 0,
(void *)NULL);
for (i = 0; i < 2; i++) {
for (;;) {
if (ret == -1)
break;
if (ret == -2) {
}
}
p = strchr(p, '\n');
/* seek back and retry once with caching and different
buffer size */
i_stream_seek(filter, 0);
str_truncate(output, 0);
}
test_end();
}
static void test_istream_filter_large_buffer2(void)
{
static const char *wanted_headers[] = { "References" };
const unsigned char *data;
unsigned int i;
int ret;
test_begin("i_stream_create_header_filter: large buffer2");
*null_header_filter_callback, (void *)NULL);
for (i = 0; i < 2; i++) {
}
/* seek back and retry once with caching and different
buffer size */
i_stream_seek(filter, 0);
str_truncate(output, 0);
}
test_end();
}
static void
struct message_header_line *hdr,
{
}
static void test_istream_callbacks(void)
{
unsigned int i;
test_begin("i_stream_create_header_filter: callbacks");
NULL, 0,
output);
/* callback should be called exactly once for all the header input */
for (i = 0; i < 2; i++) {
}
test_end();
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
return;
/* add a new header */
const char *new_hdr = "Added: header\n\n";
/* modify To header */
const char *new_to = "To: 123\n";
}
}
static void test_istream_edit(void)
{
const char *input = "From: foo\nTo: bar\n\nhello world\n";
const char *output = "From: foo\nTo: 123\nAdded: header\n\nhello world\n";
test_begin("i_stream_create_header_filter: edit headers");
NULL, 0,
edit_callback, (void *)NULL);
test_end();
}
static void test_istream_end_body_with_lf(void)
{
const char *input = "From: foo\n\nhello world";
const char *output = "From: foo\n\nhello world\n";
const unsigned char *data;
test_begin("i_stream_create_header_filter: end_body_with_lf");
NULL, 0,
(void *)NULL);
for (i = 1; i < input_len; i++) {
}
i_stream_seek(filter, 0);
for (i = 1; i < input_len; i++) {
}
test_end();
}
static void test_istream_add_missing_eoh(void)
{
struct {
const char *input;
const char *output;
unsigned int extra;
} tests[] = {
{ "From: foo", "From: foo\n\n", 1 },
{ "From: foo\n", "From: foo\n\n", 1 },
{ "From: foo\n\n", "From: foo\n\n", 1 },
{ "From: foo\n\nbar", "From: foo\n\nbar", 0 },
{ "From: foo\r\n", "From: foo\r\n\r\n", 1 },
{ "From: foo\r\n\r\n", "From: foo\r\n\r\n", 0 },
{ "From: foo\r\n\r\nbar", "From: foo\r\n\r\nbar", 0 }
};
unsigned int i;
test_begin("i_stream_create_header_filter: add missing EOH");
for (i = 0; i < N_ELEMENTS(tests); i++) {
NULL, 0,
*null_header_filter_callback, (void *)NULL);
}
test_end();
}
static void test_istream_hide_body(void)
{
struct {
const char *input;
const char *output;
int extra;
} tests[] = {
{ "From: foo", "From: foo", 0 },
{ "From: foo\n", "From: foo\n", 0 },
{ "From: foo\n\n", "From: foo\n\n", 1 },
{ "From: foo\n\nbar", "From: foo\n\n", -2 },
{ "From: foo\r\n", "From: foo\r\n", 0 },
{ "From: foo\r\n\r\n", "From: foo\r\n\r\n", 0 },
{ "From: foo\r\n\r\nbar", "From: foo\r\n\r\n", -3 }
};
unsigned int i;
test_begin("i_stream_create_header_filter: hide body");
for (i = 0; i < N_ELEMENTS(tests); i++) {
NULL, 0,
*null_header_filter_callback, (void *)NULL);
}
test_end();
}
static void ATTR_NULL(3)
struct message_header_line *hdr,
{
}
static void test_istream_strip_eoh(void)
{
const char *input = "From: foo\nTo: bar\n\nhello world\n";
const char *output = "From: foo\nTo: bar\nhello world\n";
test_begin("i_stream_create_header_filter: strip_eoh");
strip_eoh_callback, (void *)NULL);
test_end();
}
int main(void)
{
static void (*test_functions[])(void) = {
};
return test_run(test_functions);
}