Cross Reference: test-ostream-failure-at.c
xref
: /
dovecot
/
src
/
lib
/
test-ostream-failure-at.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
278
N/A
/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
278
N/A
278
N/A
#
include
"
test-lib.h
"
278
N/A
#
include
"
buffer.h
"
278
N/A
#
include
"
ostream.h
"
278
N/A
#
include
"
ostream-failure-at.h
"
278
N/A
278
N/A
#
define
TEST_DATA_LENGTH
128
278
N/A
#
define
TEST_ERRMSG
"test-ostream-failure-at error triggered"
278
N/A
278
N/A
void
test_ostream_failure_at
(
void
)
278
N/A
{
278
N/A
unsigned
char
test_data
[
TEST_DATA_LENGTH
];
278
N/A
struct
ostream
*
output
, *
buf_output
;
278
N/A
buffer_t
*
buf
=
t_buffer_create
(
256
);
278
N/A
unsigned
int
i;
278
N/A
278
N/A
test_begin
(
"ostream failure at"
);
278
N/A
for
(i = 0; i <
sizeof
(
test_data
); i++)
278
N/A
test_data
[i] = i;
844
N/A
for
(i = 0; i <
TEST_DATA_LENGTH
; i++) {
278
N/A
buf_output
=
o_stream_create_buffer
(
buf
);
278
N/A
output
=
o_stream_create_failure_at
(
buf_output
, i,
TEST_ERRMSG
);
278
N/A
if
(i > 0)
278
N/A
test_assert
(
o_stream_send
(
output
,
test_data
,
sizeof
(
test_data
)) == (
int
)i);
278
N/A
test_assert_idx
(
o_stream_send
(
output
,
test_data
,
sizeof
(
test_data
)) == -
1
&&
618
N/A
output
->
offset
== i &&
278
N/A
output
->
stream_errno
==
EIO
&&
278
N/A
strcmp
(
o_stream_get_error
(
output
),
TEST_ERRMSG
) == 0, i);
844
N/A
o_stream_destroy
(&
output
);
844
N/A
o_stream_destroy
(&
buf_output
);
278
N/A
}
278
N/A
/* shouldn't fail */
618
N/A
buf_output
=
o_stream_create_buffer
(
buf
);
278
N/A
output
=
o_stream_create_failure_at
(
buf_output
,
TEST_DATA_LENGTH
,
TEST_ERRMSG
);
1273
N/A
test_assert
(
o_stream_send
(
output
,
test_data
,
sizeof
(
test_data
)) ==
TEST_DATA_LENGTH
);
1273
N/A
test_assert
(
o_stream_flush
(
output
) > 0 &&
278
N/A
output
->
offset
==
TEST_DATA_LENGTH
&&
278
N/A
output
->
stream_errno
== 0);
278
N/A
o_stream_destroy
(&
output
);
278
N/A
o_stream_destroy
(&
buf_output
);
278
N/A
278
N/A
/* fail at flush */
278
N/A
buf_output
=
o_stream_create_buffer
(
buf
);
278
N/A
output
=
o_stream_create_failure_at_flush
(
buf_output
,
TEST_ERRMSG
);
278
N/A
test_assert
(
o_stream_send
(
output
,
test_data
,
sizeof
(
test_data
)) ==
TEST_DATA_LENGTH
);
278
N/A
test_assert
(
o_stream_flush
(
output
) < 0 &&
output
->
stream_errno
==
EIO
&&
278
N/A
strcmp
(
o_stream_get_error
(
output
),
TEST_ERRMSG
) == 0);
278
N/A
o_stream_destroy
(&
output
);
278
N/A
o_stream_destroy
(&
buf_output
);
278
N/A
test_end
();
278
N/A
}
278
N/A