Skip to content

Commit

Permalink
lib: Added unit test to iostream-temp.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Feb 24, 2016
1 parent e245fb1 commit 2686ef8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/Makefile.am
Expand Up @@ -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 \
Expand Down
46 changes: 46 additions & 0 deletions 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();
}
1 change: 1 addition & 0 deletions src/lib/test-lib.c
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/lib/test-lib.h
Expand Up @@ -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);
Expand Down

0 comments on commit 2686ef8

Please sign in to comment.