dovecot-2.0: Added unit test for istream-base64-encoder.
dovecot at dovecot.org
dovecot at dovecot.org
Mon Nov 15 18:22:15 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/bb6fc4e13bc9
changeset: 12420:bb6fc4e13bc9
user: Timo Sirainen <tss at iki.fi>
date: Mon Nov 15 16:22:08 2010 +0000
description:
Added unit test for istream-base64-encoder.
diffstat:
src/lib/Makefile.am | 1 +
src/lib/test-istream-base64-encoder.c | 71 +++++++++++++++++++++++++++++++++++
src/lib/test-lib.c | 1 +
src/lib/test-lib.h | 1 +
4 files changed, 74 insertions(+), 0 deletions(-)
diffs (108 lines):
diff -r b1d946388d9b -r bb6fc4e13bc9 src/lib/Makefile.am
--- a/src/lib/Makefile.am Mon Nov 15 16:21:45 2010 +0000
+++ b/src/lib/Makefile.am Mon Nov 15 16:22:08 2010 +0000
@@ -237,6 +237,7 @@
test-crc32.c \
test-hash-format.c \
test-hex-binary.c \
+ test-istream-base64-encoder.c \
test-istream-concat.c \
test-istream-crlf.c \
test-istream-seekable.c \
diff -r b1d946388d9b -r bb6fc4e13bc9 src/lib/test-istream-base64-encoder.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/test-istream-base64-encoder.c Mon Nov 15 16:22:08 2010 +0000
@@ -0,0 +1,71 @@
+/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "str.h"
+#include "istream-internal.h"
+#include "istream-base64-encoder.h"
+
+static const char *hello = "hello world";
+
+static const char *
+encode(const char *text, unsigned int chars_per_line, bool crlf)
+{
+ struct istream *input, *input_data;
+ const char *reply;
+ const unsigned char *data;
+ size_t size;
+ ssize_t ret;
+
+ input_data = i_stream_create_from_data(text, strlen(text));
+ input = i_stream_create_base64_encoder(input_data, chars_per_line, crlf);
+ while ((ret = i_stream_read(input)) > 0) ;
+ test_assert(ret == -1);
+
+ data = i_stream_get_data(input, &size);
+ reply = t_strndup(data, size);
+
+ i_stream_unref(&input);
+ i_stream_unref(&input_data);
+ return reply;
+}
+
+static void
+test_istream_base64_encoder_seek(const char *textin, const char *textout)
+{
+ unsigned int offset, len = strlen(textout);
+ struct istream *input, *input_data;
+ const unsigned char *data;
+ size_t size;
+ ssize_t ret;
+
+ input_data = i_stream_create_from_data(textin, strlen(textin));
+ input = i_stream_create_base64_encoder(input_data, 4, TRUE);
+
+ while ((ret = i_stream_read(input)) > 0) ;
+ data = i_stream_get_data(input, &size);
+ i_stream_skip(input, size);
+
+ for (offset = 0; offset < len; offset++) {
+ i_stream_seek(input, offset);
+ while ((ret = i_stream_read(input)) > 0) ;
+ test_assert(ret == -1);
+
+ data = i_stream_get_data(input, &size);
+ test_assert(size == len-offset);
+ test_assert(memcmp(data, textout+offset, size) == 0);
+ i_stream_skip(input, size);
+ }
+
+ i_stream_unref(&input);
+ i_stream_unref(&input_data);
+}
+
+void test_istream_base64_encoder(void)
+{
+ test_begin("istream base64 encoder");
+ test_assert(strcmp(encode(hello, 80, FALSE), "aGVsbG8gd29ybGQ=") == 0);
+ test_assert(strcmp(encode(hello, 4, FALSE), "aGVs\nbG8g\nd29y\nbGQ=") == 0);
+ test_assert(strcmp(encode(hello, 4, TRUE), "aGVs\r\nbG8g\r\nd29y\r\nbGQ=") == 0);
+ test_istream_base64_encoder_seek(hello, "aGVs\r\nbG8g\r\nd29y\r\nbGQ=");
+ test_end();
+}
diff -r b1d946388d9b -r bb6fc4e13bc9 src/lib/test-lib.c
--- a/src/lib/test-lib.c Mon Nov 15 16:21:45 2010 +0000
+++ b/src/lib/test-lib.c Mon Nov 15 16:22:08 2010 +0000
@@ -13,6 +13,7 @@
test_crc32,
test_hash_format,
test_hex_binary,
+ test_istream_base64_encoder,
test_istream_concat,
test_istream_crlf,
test_istream_seekable,
diff -r b1d946388d9b -r bb6fc4e13bc9 src/lib/test-lib.h
--- a/src/lib/test-lib.h Mon Nov 15 16:21:45 2010 +0000
+++ b/src/lib/test-lib.h Mon Nov 15 16:22:08 2010 +0000
@@ -12,6 +12,7 @@
void test_crc32(void);
void test_hash_format(void);
void test_hex_binary(void);
+void test_istream_base64_encoder(void);
void test_istream_concat(void);
void test_istream_crlf(void);
void test_istream_seekable(void);
More information about the dovecot-cvs
mailing list