diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/.clang-tidy | 1 | ||||
-rw-r--r-- | test/meson.build | 4 | ||||
-rw-r--r-- | test/test_reader.c | 53 | ||||
-rw-r--r-- | test/test_reader_writer.c | 38 |
4 files changed, 39 insertions, 57 deletions
diff --git a/test/.clang-tidy b/test/.clang-tidy index 811dfa30..ea251c3a 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -13,5 +13,6 @@ Checks: > -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -concurrency-mt-unsafe, -hicpp-signed-bitwise, + -llvm-header-guard, -readability-function-cognitive-complexity, InheritParentConfig: true diff --git a/test/meson.build b/test/meson.build index 427d39dd..e0aea675 100644 --- a/test/meson.build +++ b/test/meson.build @@ -152,8 +152,8 @@ foreach unit : unit_tests executable( 'test_@0@'.format(unit), files('test_@0@.c'.format(unit)), - c_args: c_suppressions, - dependencies: serd_dep, + c_args: c_suppressions + platform_c_args, + dependencies: [serd_dep, zix_dep], ), env: test_env, suite: 'unit', 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; } 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; |