From: Stephan Bosch Date: Mon, 27 Oct 2025 21:02:55 +0000 (+0100) Subject: lib: test-buffer-istream - Use the new test-dir API X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1e98d0eb7106f0cd68ed1d43c84dd5caba7c0319;p=thirdparty%2Fdovecot%2Fcore.git lib: test-buffer-istream - Use the new test-dir API --- diff --git a/src/lib/test-buffer-istream.c b/src/lib/test-buffer-istream.c index 056c859580..6f95e1075b 100644 --- a/src/lib/test-buffer-istream.c +++ b/src/lib/test-buffer-istream.c @@ -8,32 +8,37 @@ #include #include -#define TEST_FILENAME ".test_buffer_append_full_file" +#define TEST_FILENAME "buffer_append_full_file" + static void test_buffer_append_full_file(void) { const char *test_string = "this is a test string\n"; test_begin("buffer_append_full_file"); buffer_t *result = t_buffer_create(32); - const char *error; - int fd = open(TEST_FILENAME, O_WRONLY|O_CREAT, 0600); + const char *error, *path; + int fd; + + path = test_dir_prepend(TEST_FILENAME); + fd = open(path, O_WRONLY|O_CREAT, 0600); + i_assert(fd > -1); test_assert(write_full(fd, test_string, strlen(test_string)) == 0); i_close_fd(&fd); - test_assert(buffer_append_full_file(result, TEST_FILENAME, SIZE_MAX, + test_assert(buffer_append_full_file(result, path, SIZE_MAX, &error) == BUFFER_APPEND_OK); test_assert_strcmp(str_c(result), test_string); /* test max_read_size */ for (size_t max = 0; max < strlen(test_string)-1; max++) { buffer_set_used_size(result, 0); - test_assert(buffer_append_full_file(result, TEST_FILENAME, + test_assert(buffer_append_full_file(result, path, max, &error) == BUFFER_APPEND_READ_MAX_SIZE); test_assert(result->used == max && memcmp(result->data, test_string, max) == 0); } - fd = open(TEST_FILENAME, O_WRONLY|O_TRUNC); + fd = open(path, O_WRONLY|O_TRUNC); i_assert(fd > -1); /* write it enough many times */ for (size_t i = 0; i < IO_BLOCK_SIZE; i += strlen(test_string)) { @@ -41,7 +46,7 @@ static void test_buffer_append_full_file(void) } i_close_fd(&fd); buffer_set_used_size(result, 0); - test_assert(buffer_append_full_file(result, TEST_FILENAME, + test_assert(buffer_append_full_file(result, path, SIZE_MAX, &error) == BUFFER_APPEND_OK); for (size_t i = 0; i < result->used; i += strlen(test_string)) { const char *data = result->data; @@ -49,16 +54,16 @@ static void test_buffer_append_full_file(void) test_assert(memcmp(data, test_string, strlen(test_string)) == 0); } buffer_set_used_size(result, 0); - test_assert(chmod(TEST_FILENAME, 0) == 0); + test_assert(chmod(path, 0) == 0); error = NULL; - test_assert(buffer_append_full_file(result, TEST_FILENAME, SIZE_MAX, + test_assert(buffer_append_full_file(result, path, SIZE_MAX, &error) == BUFFER_APPEND_READ_ERROR); test_assert(error != NULL && *error != '\0'); buffer_set_used_size(result, 0); - test_assert(chmod(TEST_FILENAME, 0700) == 0); + test_assert(chmod(path, 0700) == 0); /* test permission problems */ - i_unlink(TEST_FILENAME); - test_assert(buffer_append_full_file(result, TEST_FILENAME, SIZE_MAX, + i_unlink(path); + test_assert(buffer_append_full_file(result, path, SIZE_MAX, &error) == BUFFER_APPEND_READ_ERROR); test_assert_strcmp(str_c(result), ""); test_end(); diff --git a/src/lib/test-lib.c b/src/lib/test-lib.c index 62e6b0ddd5..6ca3367e96 100644 --- a/src/lib/test-lib.c +++ b/src/lib/test-lib.c @@ -24,5 +24,8 @@ int main(int argc, char **argv) #undef FATAL { NULL, NULL } }; + + test_dir_init("lib"); + return test_run_named_with_fatals(match, test_functions, fatal_functions); } diff --git a/src/lib/test-lib.h b/src/lib/test-lib.h index 7fdd105cb2..02867b8430 100644 --- a/src/lib/test-lib.h +++ b/src/lib/test-lib.h @@ -3,6 +3,7 @@ #include "lib.h" #include "test-common.h" +#include "test-dir.h" #define TEST(x) TEST_DECL(x) #define FATAL(x) FATAL_DECL(x)