From 7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 18 Dec 2022 20:59:42 -0500 Subject: Use portable zix filesystem API in tests --- test/test_reader_writer.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'test/test_reader_writer.c') diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 67c0d7ba..3cf7cf5d 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -16,17 +16,15 @@ #include "serd/syntax.h" #include "serd/world.h" #include "serd/writer.h" - -#ifdef _WIN32 -# include -#endif +#include "zix/allocator.h" +#include "zix/filesystem.h" +#include "zix/path.h" #include #include #include #include #include -#include #include typedef struct { @@ -284,30 +282,22 @@ test_reader(const char* path) int main(void) { -#ifdef _WIN32 - char tmp[MAX_PATH] = {0}; - const size_t tmp_len = (size_t)GetTempPath(sizeof(tmp), tmp); -#else - const char* const env_tmp = getenv("TMPDIR"); - const char* const tmp = env_tmp ? env_tmp : "/tmp"; - const size_t tmp_len = strlen(tmp); -#endif - - const char* const ttl_name = "serd_test_reader_writer.ttl"; - const size_t ttl_name_len = strlen(ttl_name); - const size_t path_len = tmp_len + 1 + ttl_name_len; - char* const path = (char*)calloc(path_len + 1, 1); - - memcpy(path, tmp, tmp_len + 1); - path[tmp_len] = '/'; - memcpy(path + tmp_len + 1, ttl_name, ttl_name_len + 1); + char* const temp = zix_temp_directory_path(NULL); + char* const path_pattern = zix_path_join(NULL, temp, "serdXXXXXX"); + char* const dir = zix_create_temporary_directory(NULL, path_pattern); + char* const path = zix_path_join(NULL, dir, "serd_test_reader.ttl"); test_write_errors(); test_writer(path); test_reader(path); - assert(!remove(path)); - free(path); + assert(!zix_remove(path)); + assert(!zix_remove(dir)); + + zix_free(NULL, path); + zix_free(NULL, dir); + zix_free(NULL, path_pattern); + zix_free(NULL, temp); printf("Success\n"); return 0; -- cgit v1.2.1