diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/lib/test-istream-failure-at.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/test-istream-failure-at.c')
-rw-r--r-- | src/lib/test-istream-failure-at.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/test-istream-failure-at.c b/src/lib/test-istream-failure-at.c new file mode 100644 index 0000000..d0313ba --- /dev/null +++ b/src/lib/test-istream-failure-at.c @@ -0,0 +1,49 @@ +/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */ + +#include "test-lib.h" +#include "istream.h" +#include "istream-failure-at.h" + +#define TEST_DATA_LENGTH 128 +#define TEST_ERRMSG "test-istream-failure-at error triggered" + +void test_istream_failure_at(void) +{ + struct istream *input, *data_input; + unsigned char test_data[TEST_DATA_LENGTH]; + unsigned int i; + ssize_t ret; + + test_begin("istream failure at"); + for (i = 0; i < sizeof(test_data); i++) + test_data[i] = i; + data_input = i_stream_create_from_data(test_data, sizeof(test_data)); + for (i = 0; i < TEST_DATA_LENGTH; i++) { + i_stream_seek(data_input, 0); + input = i_stream_create_failure_at(data_input, i, EIO, TEST_ERRMSG); + while ((ret = i_stream_read(input)) > 0) + i_stream_skip(input, ret); + test_assert_idx(ret == -1 && input->v_offset == i && + input->stream_errno == EIO && + strcmp(i_stream_get_error(input), TEST_ERRMSG) == 0, i); + i_stream_destroy(&input); + } + /* shouldn't fail */ + i_stream_seek(data_input, 0); + input = i_stream_create_failure_at(data_input, TEST_DATA_LENGTH, EIO, TEST_ERRMSG); + while ((ret = i_stream_read(input)) > 0) + i_stream_skip(input, ret); + test_assert(ret == -1 && input->stream_errno == 0); + i_stream_destroy(&input); + /* fail at EOF */ + i_stream_seek(data_input, 0); + input = i_stream_create_failure_at_eof(data_input, EIO, TEST_ERRMSG); + while ((ret = i_stream_read(input)) > 0) + i_stream_skip(input, ret); + test_assert_idx(ret == -1 && input->v_offset == TEST_DATA_LENGTH && + input->stream_errno == EIO && + strcmp(i_stream_get_error(input), TEST_ERRMSG) == 0, i); + i_stream_destroy(&input); + i_stream_destroy(&data_input); + test_end(); +} |