diff options
author | David Robillard <d@drobilla.net> | 2022-12-18 20:59:42 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:07 -0500 |
commit | 7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4 (patch) | |
tree | 60d75826d2a0c5af712f5cb50919d631e3f6b3c7 /test/test_reader.c | |
parent | 93133610d2454108ace24948358c4f0be47049a2 (diff) | |
download | serd-7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4.tar.gz serd-7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4.tar.bz2 serd-7fb4c5264b91d5a5ce9f13a9fb4308088b31fcd4.zip |
Use portable zix filesystem API in tests
Diffstat (limited to 'test/test_reader.c')
-rw-r--r-- | test/test_reader.c | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/test/test_reader.c b/test/test_reader.c index f931b258..a5595804 100644 --- a/test/test_reader.c +++ b/test/test_reader.c @@ -10,6 +10,9 @@ #include "serd/stream.h" #include "serd/syntax.h" #include "serd/world.h" +#include "zix/allocator.h" +#include "zix/filesystem.h" +#include "zix/path.h" #ifdef _WIN32 # include <windows.h> @@ -17,7 +20,6 @@ #include <assert.h> #include <stdio.h> -#include <stdlib.h> #include <string.h> typedef struct { @@ -151,6 +153,7 @@ test_read_eof_by_page(const char* const path) serd_sink_free(sink); serd_world_free(world); fclose(f); + assert(!zix_remove(path)); } // A byte-wise reader hits EOF once then continues (like a socket) @@ -264,7 +267,7 @@ test_read_nquads_chunks(const char* const path) serd_sink_free(sink); serd_world_free(world); fclose(f); - remove(path); + assert(!zix_remove(path)); } static void @@ -359,42 +362,30 @@ test_read_turtle_chunks(const char* const path) serd_sink_free(sink); serd_world_free(world); fclose(f); - remove(path); + assert(!zix_remove(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.ttl"; - const char* const nq_name = "serd_test_reader.nq"; - const size_t ttl_name_len = strlen(ttl_name); - const size_t nq_name_len = strlen(nq_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, nq_name, nq_name_len + 1); - test_read_nquads_chunks(path); - - memcpy(path + tmp_len + 1, ttl_name, ttl_name_len + 1); - test_read_turtle_chunks(path); - + 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 ttl_path = zix_path_join(NULL, dir, "serd_test_reader.ttl"); + char* const nq_path = zix_path_join(NULL, dir, "serd_test_reader.nq"); + + test_read_nquads_chunks(nq_path); + test_read_turtle_chunks(ttl_path); test_read_string(); - test_read_eof_by_page(path); + test_read_eof_by_page(ttl_path); test_read_eof_by_byte(); - assert(!remove(path)); - free(path); + assert(!zix_remove(dir)); + + zix_free(NULL, nq_path); + zix_free(NULL, ttl_path); + zix_free(NULL, dir); + zix_free(NULL, path_pattern); + zix_free(NULL, temp); return 0; } |