bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainenstatic void test_iostream_temp_create_sized_memory(void)
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_begin("iostream_temp_create_sized() memory");
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/", 0, "test", 4);
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_assert(o_stream_send(output, "123", 3) == 3);
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_assert(o_stream_send(output, "4", 1) == 1);
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen /* now we'll try to switch to writing to a file, but it'll fail */
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_assert(o_stream_send(output, "5", 1) == 1);
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainenstatic void test_iostream_temp_create_sized_disk(void)
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_begin("iostream_temp_create_sized() disk");
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen output = iostream_temp_create_sized(".", 0, "test", 4);
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_assert(o_stream_send(output, "123", 3) == 3);
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_assert(o_stream_send(output, "4", 1) == 1);
2686ef87921233609d1d8ec8dee2883facc2c5ebTimo Sirainen test_assert(o_stream_send(output, "5", 1) == 1);
d97f081a3de44852197ced772e21560c108895a6Timo Sirainenstatic void test_iostream_temp_create_write_error(void)
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen test_begin("iostream_temp_create_sized() write error");
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen output = iostream_temp_create_sized(".", 0, "test", 1);
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen test_assert(o_stream_send(output, "123", 3) == 3);
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen test_assert(o_stream_temp_move_to_memory(output) == 0);
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen test_assert(o_stream_send(output, "45", 2) == 2);
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen struct istream *input = iostream_temp_finish(&output, 128);
d97f081a3de44852197ced772e21560c108895a6Timo Sirainen test_assert(i_stream_read_bytes(input, &data, &size, 5) == 1 &&
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen fd = open(".temp.istream", O_RDWR | O_CREAT | O_TRUNC, 0600);
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi input = i_stream_create_fd_autoclose(&fd, 1024);
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen /* a working fd-dup */
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen output = iostream_temp_create_sized(".nonexistent/",
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen temp_input = iostream_temp_finish(&output, 128);
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen /* non-working fd-dup: write data before sending istream */
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/",
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen test_assert(o_stream_send(output, "1234", 4) == 4);
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);
25ec868bd8b5375e1c1c4c3331d761667ddfe26cTimo Sirainen /* non-working fd-dup: write data after sending istream */
25ec868bd8b5375e1c1c4c3331d761667ddfe26cTimo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/",
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);
25ec868bd8b5375e1c1c4c3331d761667ddfe26cTimo Sirainen test_assert(o_stream_send(output, "1", 1) == 1);
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen /* non-working fd-dup: send two istreams */
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen input2 = i_stream_create_limit(input, (uoff_t)-1);
c076ad69e28e7d41af83ada84e12019793ffcfa2Timo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/",
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);