dovecot-2.0: imap-parser unit testing started.
dovecot at dovecot.org
dovecot at dovecot.org
Tue May 26 04:23:01 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/9297ae2ee45f
changeset: 9366:9297ae2ee45f
user: Timo Sirainen <tss at iki.fi>
date: Mon May 25 21:22:47 2009 -0400
description:
imap-parser unit testing started.
diffstat:
2 files changed, 67 insertions(+), 5 deletions(-)
src/lib-imap/Makefile.am | 18 +++++++++----
src/lib-imap/test-imap-parser.c | 54 +++++++++++++++++++++++++++++++++++++++
diffs (95 lines):
diff -r 07b601734cc8 -r 9297ae2ee45f src/lib-imap/Makefile.am
--- a/src/lib-imap/Makefile.am Mon May 25 21:03:42 2009 -0400
+++ b/src/lib-imap/Makefile.am Mon May 25 21:22:47 2009 -0400
@@ -40,20 +40,28 @@ else
noinst_HEADERS = $(headers)
endif
-test_programs = test-imap-utf7 test-imap-match
+test_programs = \
+ test-imap-match \
+ test-imap-parser \
+ test-imap-utf7
+
noinst_PROGRAMS = $(test_programs)
test_libs = \
../lib-test/libtest.la \
../lib/liblib.la
+test_imap_match_SOURCES = test-imap-match.c
+test_imap_match_LDADD = imap-match.o $(test_libs)
+test_imap_match_DEPENDENCIES = imap-match.o $(test_libs)
+
+test_imap_parser_SOURCES = test-imap-parser.c
+test_imap_parser_LDADD = imap-parser.o $(test_libs)
+test_imap_parser_DEPENDENCIES = imap-parser.o $(test_libs)
+
test_imap_utf7_SOURCES = test-imap-utf7.c
test_imap_utf7_LDADD = imap-utf7.o $(test_libs)
test_imap_utf7_DEPENDENCIES = imap-utf7.o $(test_libs)
-
-test_imap_match_SOURCES = test-imap-match.c
-test_imap_match_LDADD = imap-match.o $(test_libs)
-test_imap_match_DEPENDENCIES = imap-match.o $(test_libs)
check: check-am check-test
check-test: $(test_programs)
diff -r 07b601734cc8 -r 9297ae2ee45f src/lib-imap/test-imap-parser.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-imap/test-imap-parser.c Mon May 25 21:22:47 2009 -0400
@@ -0,0 +1,54 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "istream.h"
+#include "imap-parser.h"
+#include "test-common.h"
+
+static void test_imap_parser_crlf(void)
+{
+ static const char *test_input = "foo\r\nx\ry\n";
+ struct istream *input;
+ struct imap_parser *parser;
+ const struct imap_arg *args;
+ unsigned int i;
+ bool fatal;
+
+ test_begin("imap parser crlf handling");
+ input = test_istream_create(test_input);
+ parser = imap_parser_create(input, NULL, 1024);
+
+ /* must return -2 until LF is read */
+ for (i = 0; test_input[i] != '\n'; i++) {
+ test_istream_set_size(input, i+1);
+ test_assert(imap_parser_read_args(parser, 0, 0, &args) == -2);
+ }
+ test_istream_set_size(input, i+1);
+ test_assert(imap_parser_read_args(parser, 0, 0, &args) == 2);
+ test_assert(args[0].type == IMAP_ARG_ATOM);
+ test_assert(args[1].type == IMAP_ARG_EOL);
+
+ /* CR without LF should fail with error */
+ imap_parser_reset(parser);
+ i_stream_seek(input, ++i);
+ test_istream_set_size(input, ++i);
+ test_assert(imap_parser_read_args(parser, 0, 0, &args) == -2);
+ test_istream_set_size(input, ++i);
+ test_assert(imap_parser_read_args(parser, 0, 0, &args) == -2);
+ test_istream_set_size(input, ++i);
+ test_assert(imap_parser_read_args(parser, 0, 0, &args) == -1);
+ test_assert(strcmp(imap_parser_get_error(parser, &fatal), "CR sent without LF") == 0 && !fatal);
+
+ imap_parser_destroy(&parser);
+ i_stream_destroy(&input);
+ test_end();
+}
+
+int main(void)
+{
+ static void (*test_functions[])(void) = {
+ test_imap_parser_crlf,
+ NULL
+ };
+ return test_run(test_functions);
+}
More information about the dovecot-cvs
mailing list