]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Added unit test to iostream-temp.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 24 Feb 2016 14:39:59 +0000 (16:39 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 24 Feb 2016 14:39:59 +0000 (16:39 +0200)
src/lib/Makefile.am
src/lib/test-iostream-temp.c [new file with mode: 0644]
src/lib/test-lib.c
src/lib/test-lib.h

index a8bc8368ee6205acc5417d5419c906e16fc7cf32..712ec856e77fc19b2f5920fd448ec23cd46706f5 100644 (file)
@@ -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 (file)
index 0000000..7cfae39
--- /dev/null
@@ -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();
+}
index 3430a856534d4627f3a3790a6dd5887f197b437e..325a37372c8def964ca4a32c40ba21301408497a 100644 (file)
@@ -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,
index 8e32c241abc962229e5cdd791d1c65b39a77a821..e9cfe45ce089783c535dce8e6a60f7447b824518 100644 (file)
@@ -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);