test-istream-crlf.c revision 3d2d1ba0a14521c7320370d8cafb9a95b49d333d
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainenstatic void test_istream_crlf_input(const char *input)
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const unsigned char *data;
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int i, j, pos, input_len = strlen(input);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen for (j = 0; j < 4; j++) {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen istream = i_stream_create_from_data(input, input_len);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen if (j%2 == 0) {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* drop CRs */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen for (i = 0; i < input_len; i++) {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* add missing CRs */
a21f618de284dc22a480af1371d5f5cea50a39dfTimo Sirainen for (i = 0; i < input_len; i++) {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen if (j >= 2) {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen if (crlf_istream->real_stream->buffer_size != 0) {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen /* this is pretty evil */
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen data = i_stream_get_data(crlf_istream, &size);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen test_assert(pos + (unsigned int)ret1 == size);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen test_assert(memcmp(data, str_data(output), size) == 0);
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen const char *input[] = {
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen "foo\nbar\r\nbaz\r\r\n",
96f89d51e8315f644f46804a9f0fc4f685ac48bfTimo Sirainen unsigned int i;