From: Timo Sirainen Date: Wed, 24 Feb 2016 14:39:59 +0000 (+0200) Subject: lib: Added unit test to iostream-temp. X-Git-Tag: 2.2.22.rc1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2686ef87921233609d1d8ec8dee2883facc2c5eb;p=thirdparty%2Fdovecot%2Fcore.git lib: Added unit test to iostream-temp. --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index a8bc8368ee..712ec856e7 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -311,6 +311,7 @@ test_lib_SOURCES = \ test-hex-binary.c \ test-ioloop.c \ test-iso8601-date.c \ + test-iostream-temp.c \ test-istream.c \ test-istream-base64-decoder.c \ test-istream-base64-encoder.c \ diff --git a/src/lib/test-iostream-temp.c b/src/lib/test-iostream-temp.c new file mode 100644 index 0000000000..7cfae398c3 --- /dev/null +++ b/src/lib/test-iostream-temp.c @@ -0,0 +1,46 @@ +/* Copyright (c) 2016 Dovecot authors, see the included COPYING file */ + +#include "test-lib.h" +#include "ostream.h" +#include "iostream-temp.h" + +static void test_iostream_temp_create_sized_memory(void) +{ + struct ostream *output; + + test_begin("iostream_temp_create_sized() memory"); + output = iostream_temp_create_sized(".intentional-nonexistent-error/", 0, "test", 4); + test_assert(o_stream_send(output, "123", 3) == 3); + test_assert(o_stream_send(output, "4", 1) == 1); + test_assert(o_stream_get_fd(output) == -1); + + /* now we'll try to switch to writing to a file, but it'll fail */ + test_expect_errors(1); + test_assert(o_stream_send(output, "5", 1) == 1); + test_expect_no_more_errors(); + + test_assert(o_stream_get_fd(output) == -1); + o_stream_destroy(&output); + test_end(); +} + +static void test_iostream_temp_create_sized_disk(void) +{ + struct ostream *output; + + test_begin("iostream_temp_create_sized() disk"); + output = iostream_temp_create_sized(".", 0, "test", 4); + test_assert(o_stream_send(output, "123", 3) == 3); + test_assert(o_stream_send(output, "4", 1) == 1); + test_assert(o_stream_get_fd(output) == -1); + test_assert(o_stream_send(output, "5", 1) == 1); + test_assert(o_stream_get_fd(output) != -1); + o_stream_destroy(&output); + test_end(); +} + +void test_iostream_temp(void) +{ + test_iostream_temp_create_sized_memory(); + test_iostream_temp_create_sized_disk(); +} diff --git a/src/lib/test-lib.c b/src/lib/test-lib.c index 3430a85653..325a37372c 100644 --- a/src/lib/test-lib.c +++ b/src/lib/test-lib.c @@ -22,6 +22,7 @@ int main(void) test_hex_binary, test_ioloop, test_iso8601_date, + test_iostream_temp, test_istream, test_istream_base64_decoder, test_istream_base64_encoder, diff --git a/src/lib/test-lib.h b/src/lib/test-lib.h index 8e32c241ab..e9cfe45ce0 100644 --- a/src/lib/test-lib.h +++ b/src/lib/test-lib.h @@ -23,6 +23,7 @@ void test_hash_method(void); void test_hex_binary(void); void test_ioloop(void); void test_iso8601_date(void); +void test_iostream_temp(void); void test_istream(void); void test_istream_base64_decoder(void); void test_istream_base64_encoder(void);