aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_reader_writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-12-18 20:59:42 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commit7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4 (patch)
tree60d75826d2a0c5af712f5cb50919d631e3f6b3c7 /test/test_reader_writer.c
parent93133610d2454108ace24948358c4f0be47049a2 (diff)
downloadserd-7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4.tar.gz
serd-7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4.tar.bz2
serd-7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4.zip
Use portable zix filesystem API in tests
Diffstat (limited to 'test/test_reader_writer.c')
-rw-r--r--test/test_reader_writer.c38
1 files changed, 14 insertions, 24 deletions
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 <windows.h>
-#endif
+#include "zix/allocator.h"
+#include "zix/filesystem.h"
+#include "zix/path.h"
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
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;