test-iostream-temp.c revision 431c0aba57fba2fd6eb398acd6ef4e73b5dc1b86
2e37d45867d081db150ab78dad303b9077aea24fTimo Sirainen/* Copyright (c) 2016 Dovecot authors, see the included COPYING file */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void test_iostream_temp_create_sized_memory(void)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_begin("iostream_temp_create_sized() memory");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/", 0, "test", 4);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_assert(o_stream_send(output, "123", 3) == 3);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_assert(o_stream_send(output, "4", 1) == 1);
2b9e49e4e65e3e2dca38f56971029a3051ccdb99Timo Sirainen /* now we'll try to switch to writing to a file, but it'll fail */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_assert(o_stream_send(output, "5", 1) == 1);
c0a87e5f3316a57e6f915882fa1951d0fbb74a61Timo Sirainenstatic void test_iostream_temp_create_sized_disk(void)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_begin("iostream_temp_create_sized() disk");
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen output = iostream_temp_create_sized(".", 0, "test", 4);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_assert(o_stream_send(output, "123", 3) == 3);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_assert(o_stream_send(output, "4", 1) == 1);
d22301419109ed4a38351715e6760011421dadecTimo Sirainen test_assert(o_stream_send(output, "5", 1) == 1);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen fd = open(".temp.istream", O_RDWR | O_CREAT | O_TRUNC, 0600);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen input = i_stream_create_fd_autoclose(&fd, 1024);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* a working fd-dup */
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen output = iostream_temp_create_sized(".nonexistent/",
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen temp_input = iostream_temp_finish(&output, 128);
4b2a4c8c762e3eaddf7fd2abfe7d4cca6e5e3fd8Timo Sirainen /* non-working fd-dup: write data before sending istream */
2b9e49e4e65e3e2dca38f56971029a3051ccdb99Timo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/",
4b2a4c8c762e3eaddf7fd2abfe7d4cca6e5e3fd8Timo Sirainen test_assert(o_stream_send(output, "1234", 4) == 4);
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);
e5fb952c6d49d3b6bff1746551566202e92947daTimo Sirainen /* non-working fd-dup: write data after sending istream */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/",
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen test_assert(o_stream_send(output, "1", 1) == 1);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* non-working fd-dup: send two istreams */
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen input2 = i_stream_create_limit(input, (uoff_t)-1);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen output = iostream_temp_create_sized(".intentional-nonexistent-error/",
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen test_assert(o_stream_send_istream(output, input) == OSTREAM_SEND_ISTREAM_RESULT_FINISHED);