From ff9f776a48cdca700468f9d5a93625979d77e745 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Nov 2022 17:54:12 -0500 Subject: Use zix_path_join() --- test/lilv_test_utils.c | 32 ++++++++------- test/test_filesystem.c | 106 ++++++++----------------------------------------- test/test_state.c | 84 +++++++++++++++++++++------------------ test/test_util.c | 5 ++- 4 files changed, 83 insertions(+), 144 deletions(-) (limited to 'test') diff --git a/test/lilv_test_utils.c b/test/lilv_test_utils.c index 5fd2d6e..520b91a 100644 --- a/test/lilv_test_utils.c +++ b/test/lilv_test_utils.c @@ -4,10 +4,11 @@ #include "lilv_test_utils.h" #include "../src/filesystem.h" -#include "../src/lilv_internal.h" #include "lilv/lilv.h" #include "serd/serd.h" +#include "zix/allocator.h" +#include "zix/path.h" #include #include @@ -32,10 +33,10 @@ lilv_test_env_new(void) // Set custom LV2_PATH in build directory to only use test data char* test_path = lilv_path_canonical(LILV_TEST_DIR); - char* lv2_path = lilv_strjoin(test_path, "/lv2", NULL); + char* lv2_path = zix_path_join(NULL, test_path, "lv2"); LilvNode* path = lilv_new_string(world, lv2_path); lilv_world_set_option(world, LILV_OPTION_LV2_PATH, path); - free(lv2_path); + zix_free(NULL, lv2_path); free(test_path); lilv_node_free(path); @@ -45,10 +46,10 @@ lilv_test_env_new(void) void lilv_test_env_free(LilvTestEnv* env) { - free(env->test_content_path); - free(env->test_manifest_path); + zix_free(NULL, env->test_content_path); + zix_free(NULL, env->test_manifest_path); lilv_node_free(env->test_bundle_uri); - free(env->test_bundle_path); + zix_free(NULL, env->test_bundle_path); lilv_node_free(env->plugin2_uri); lilv_node_free(env->plugin1_uri); lilv_world_free(env->world); @@ -63,11 +64,11 @@ create_bundle(LilvTestEnv* env, { { char* const test_dir = lilv_path_canonical(LILV_TEST_DIR); - char* const bundle_dir = lilv_path_join(test_dir, name); + char* const bundle_dir = zix_path_join(NULL, test_dir, name); - env->test_bundle_path = lilv_path_join(bundle_dir, ""); + env->test_bundle_path = zix_path_join(NULL, bundle_dir, ""); - lilv_free(bundle_dir); + zix_free(NULL, bundle_dir); lilv_free(test_dir); } @@ -83,9 +84,12 @@ create_bundle(LilvTestEnv* env, (const uint8_t*)env->test_bundle_path, NULL, NULL, true); env->test_bundle_uri = lilv_new_uri(env->world, (const char*)s.buf); + env->test_manifest_path = - lilv_path_join(env->test_bundle_path, "manifest.ttl"); - env->test_content_path = lilv_path_join(env->test_bundle_path, "plugin.ttl"); + zix_path_join(NULL, env->test_bundle_path, "manifest.ttl"); + + env->test_content_path = + zix_path_join(NULL, env->test_bundle_path, "plugin.ttl"); serd_node_free(&s); @@ -148,10 +152,10 @@ delete_bundle(LilvTestEnv* env) remove(env->test_bundle_path); } - free(env->test_content_path); - free(env->test_manifest_path); + zix_free(NULL, env->test_content_path); + zix_free(NULL, env->test_manifest_path); lilv_node_free(env->test_bundle_uri); - free(env->test_bundle_path); + zix_free(NULL, env->test_bundle_path); env->test_content_path = NULL; env->test_manifest_path = NULL; diff --git a/test/test_filesystem.c b/test/test_filesystem.c index a0e3bc8..dc4fd27 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -8,6 +8,7 @@ #include "../src/filesystem.h" #include "zix/filesystem.h" +#include "zix/path.h" #include #include @@ -89,8 +90,8 @@ test_path_absolute(void) const char* const long_path = "a/b/c"; char* const cwd = lilv_path_current(); - char* const expected_short = lilv_path_join(cwd, short_path); - char* const expected_long = lilv_path_join(cwd, long_path); + char* const expected_short = zix_path_join(NULL, cwd, short_path); + char* const expected_long = zix_path_join(NULL, cwd, long_path); assert(equals(lilv_path_absolute(short_path), expected_short)); assert(equals(lilv_path_absolute(long_path), expected_long)); @@ -100,24 +101,6 @@ test_path_absolute(void) free(cwd); } -static void -test_path_absolute_child(void) -{ - const char* const parent = "/parent"; - const char* const short_path = "a"; - const char* const long_path = "a/b/c"; - - char* const expected_short = lilv_path_join(parent, short_path); - char* const expected_long = lilv_path_join(parent, long_path); - - assert(equals(lilv_path_absolute_child(short_path, parent), expected_short)); - - assert(equals(lilv_path_absolute_child(long_path, parent), expected_long)); - - free(expected_long); - free(expected_short); -} - static void test_path_relative_to(void) { @@ -179,64 +162,11 @@ test_path_filename(void) #endif } -static void -test_path_join(void) -{ - assert(lilv_path_join(NULL, NULL) == NULL); - assert(lilv_path_join(NULL, "") == NULL); - -#ifdef _WIN32 - assert(equals(lilv_path_join("", NULL), "\\")); - assert(equals(lilv_path_join("", ""), "\\")); - assert(equals(lilv_path_join("a", ""), "a\\")); - assert(equals(lilv_path_join("a", NULL), "a\\")); - assert(equals(lilv_path_join("a", "b"), "a\\b")); -#else - assert(equals(lilv_path_join("", NULL), "/")); - assert(equals(lilv_path_join("", ""), "/")); - assert(equals(lilv_path_join("a", ""), "a/")); - assert(equals(lilv_path_join("a", NULL), "a/")); - assert(equals(lilv_path_join("a", "b"), "a/b")); -#endif - - assert(equals(lilv_path_join("/a", ""), "/a/")); - assert(equals(lilv_path_join("/a/b", ""), "/a/b/")); - assert(equals(lilv_path_join("/a/", ""), "/a/")); - assert(equals(lilv_path_join("/a/b/", ""), "/a/b/")); - assert(equals(lilv_path_join("a/b", ""), "a/b/")); - assert(equals(lilv_path_join("a/", ""), "a/")); - assert(equals(lilv_path_join("a/b/", ""), "a/b/")); - - assert(equals(lilv_path_join("/a", NULL), "/a/")); - assert(equals(lilv_path_join("/a/b", NULL), "/a/b/")); - assert(equals(lilv_path_join("/a/", NULL), "/a/")); - assert(equals(lilv_path_join("/a/b/", NULL), "/a/b/")); - assert(equals(lilv_path_join("a/b", NULL), "a/b/")); - assert(equals(lilv_path_join("a/", NULL), "a/")); - assert(equals(lilv_path_join("a/b/", NULL), "a/b/")); - - assert(equals(lilv_path_join("/a", "b"), "/a/b")); - assert(equals(lilv_path_join("/a/", "b"), "/a/b")); - assert(equals(lilv_path_join("a/", "b"), "a/b")); - - assert(equals(lilv_path_join("/a", "b/"), "/a/b/")); - assert(equals(lilv_path_join("/a/", "b/"), "/a/b/")); - assert(equals(lilv_path_join("a", "b/"), "a/b/")); - assert(equals(lilv_path_join("a/", "b/"), "a/b/")); - -#ifdef _WIN32 - assert(equals(lilv_path_join("C:/a", "b"), "C:/a/b")); - assert(equals(lilv_path_join("C:\\a", "b"), "C:\\a\\b")); - assert(equals(lilv_path_join("C:/a", "b/"), "C:/a/b/")); - assert(equals(lilv_path_join("C:\\a", "b\\"), "C:\\a\\b\\")); -#endif -} - static void test_path_canonical(void) { char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - char* const file_path = lilv_path_join(temp_dir, "lilv_test_file"); + char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file"); FILE* f = fopen(file_path, "w"); fprintf(f, "test\n"); @@ -245,7 +175,7 @@ test_path_canonical(void) #ifndef _WIN32 // Test symlink resolution - char* const link_path = lilv_path_join(temp_dir, "lilv_test_link"); + char* const link_path = zix_path_join(NULL, temp_dir, "lilv_test_link"); assert(!lilv_symlink(file_path, link_path)); @@ -262,7 +192,7 @@ test_path_canonical(void) // Test dot segment resolution - char* const parent_dir_1 = lilv_path_join(temp_dir, ".."); + char* const parent_dir_1 = zix_path_join(NULL, temp_dir, ".."); char* const parent_dir_2 = lilv_path_parent(temp_dir); char* const real_parent_dir_1 = lilv_path_canonical(parent_dir_1); char* const real_parent_dir_2 = lilv_path_canonical(parent_dir_2); @@ -286,7 +216,7 @@ static void test_is_directory(void) { char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - char* const file_path = lilv_path_join(temp_dir, "lilv_test_file"); + char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file"); assert(lilv_is_directory(temp_dir)); assert(!lilv_is_directory(file_path)); // Nonexistent @@ -308,8 +238,8 @@ static void test_copy_file(void) { char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - char* const file_path = lilv_path_join(temp_dir, "lilv_test_file"); - char* const copy_path = lilv_path_join(temp_dir, "lilv_test_copy"); + char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file"); + char* const copy_path = zix_path_join(NULL, temp_dir, "lilv_test_copy"); FILE* f = fopen(file_path, "w"); fprintf(f, "test\n"); @@ -344,7 +274,7 @@ static void test_flock(void) { char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - char* const file_path = lilv_path_join(temp_dir, "lilv_test_file"); + char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file"); FILE* const f1 = fopen(file_path, "w"); FILE* const f2 = fopen(file_path, "w"); @@ -383,8 +313,8 @@ static void test_dir_for_each(void) { char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - char* const path1 = lilv_path_join(temp_dir, "lilv_test_1"); - char* const path2 = lilv_path_join(temp_dir, "lilv_test_2"); + char* const path1 = zix_path_join(NULL, temp_dir, "lilv_test_1"); + char* const path2 = zix_path_join(NULL, temp_dir, "lilv_test_2"); FILE* const f1 = fopen(path1, "w"); FILE* const f2 = fopen(path2, "w"); @@ -438,14 +368,14 @@ test_create_directories(void) assert(lilv_is_directory(temp_dir)); - char* const child_dir = lilv_path_join(temp_dir, "child"); - char* const grandchild_dir = lilv_path_join(child_dir, "grandchild"); + char* const child_dir = zix_path_join(NULL, temp_dir, "child"); + char* const grandchild_dir = zix_path_join(NULL, child_dir, "grandchild"); assert(!lilv_create_directories(grandchild_dir)); assert(lilv_is_directory(grandchild_dir)); assert(lilv_is_directory(child_dir)); - char* const file_path = lilv_path_join(temp_dir, "lilv_test_file"); + char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file"); FILE* const f = fopen(file_path, "w"); fprintf(f, "test\n"); @@ -467,8 +397,8 @@ static void test_file_equals(void) { char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - char* const path1 = lilv_path_join(temp_dir, "lilv_test_1"); - char* const path2 = lilv_path_join(temp_dir, "lilv_test_2"); + char* const path1 = zix_path_join(NULL, temp_dir, "lilv_test_1"); + char* const path2 = zix_path_join(NULL, temp_dir, "lilv_test_2"); FILE* const f1 = fopen(path1, "w"); FILE* const f2 = fopen(path2, "w"); @@ -502,11 +432,9 @@ main(void) test_path_is_child(); test_path_current(); test_path_absolute(); - test_path_absolute_child(); test_path_relative_to(); test_path_parent(); test_path_filename(); - test_path_join(); test_path_canonical(); test_is_directory(); test_copy_file(); diff --git a/test/test_state.c b/test/test_state.c index 524a495..97567a2 100644 --- a/test/test_state.c +++ b/test/test_state.c @@ -13,7 +13,9 @@ #include "lv2/state/state.h" #include "lv2/urid/urid.h" #include "serd/serd.h" +#include "zix/allocator.h" #include "zix/filesystem.h" +#include "zix/path.h" #ifdef _WIN32 # include @@ -117,10 +119,10 @@ create_test_directories(void) resolve it here so that path comparisons in tests work. */ dirs.top = lilv_path_canonical(top); - dirs.shared = lilv_path_join(dirs.top, "shared"); - dirs.scratch = lilv_path_join(dirs.shared, "scratch"); - dirs.copy = lilv_path_join(dirs.shared, "copy"); - dirs.link = lilv_path_join(dirs.shared, "link"); + dirs.shared = zix_path_join(NULL, dirs.top, "shared"); + dirs.scratch = zix_path_join(NULL, dirs.shared, "scratch"); + dirs.copy = zix_path_join(NULL, dirs.shared, "copy"); + dirs.link = zix_path_join(NULL, dirs.shared, "link"); assert(!mkdir(dirs.shared, 0700)); assert(!mkdir(dirs.scratch, 0700)); @@ -145,7 +147,7 @@ remove_file(const char* path, const char* name, void* data) { (void)data; - char* const full_path = lilv_path_join(path, name); + char* const full_path = zix_path_join(NULL, path, name); assert(!lilv_remove(full_path)); free(full_path); } @@ -163,10 +165,10 @@ cleanup_test_directories(const TestDirectories dirs) assert(!lilv_remove(dirs.shared)); assert(!lilv_remove(dirs.top)); - free(dirs.link); - free(dirs.copy); - free(dirs.scratch); - free(dirs.shared); + zix_free(NULL, dirs.link); + zix_free(NULL, dirs.copy); + zix_free(NULL, dirs.scratch); + zix_free(NULL, dirs.shared); free(dirs.top); } @@ -227,7 +229,7 @@ make_scratch_path(LV2_State_Make_Path_Handle handle, const char* path) { TestDirectories* dirs = (TestDirectories*)handle; - return lilv_path_join(dirs->scratch, path); + return zix_path_join(NULL, dirs->scratch, path); } static const LilvPlugin* @@ -585,11 +587,11 @@ test_to_files(void) assert(ctx->out == 1.0); // Check that the test plugin has made its recording scratch file - char* const recfile_path = lilv_path_join(dirs.scratch, "recfile"); + char* const recfile_path = zix_path_join(NULL, dirs.scratch, "recfile"); assert(zix_file_type(recfile_path) == ZIX_FILE_TYPE_REGULAR); // Get state - char* const bundle_1_path = lilv_path_join(dirs.top, "state1.lv2"); + char* const bundle_1_path = zix_path_join(NULL, dirs.top, "state1.lv2"); LilvState* const state_1 = state_from_instance(plugin, instance, ctx, &dirs, bundle_1_path); @@ -597,7 +599,7 @@ test_to_files(void) assert(lilv_state_get_num_properties(state_1) == 10); // Check that a snapshop of the recfile was created - char* const recfile_copy_1 = lilv_path_join(dirs.copy, "recfile"); + char* const recfile_copy_1 = zix_path_join(NULL, dirs.copy, "recfile"); assert(zix_file_type(recfile_copy_1) == ZIX_FILE_TYPE_REGULAR); // Save state to a bundle @@ -610,14 +612,15 @@ test_to_files(void) "state.ttl")); // Check that a manifest exists - char* const manifest_path = lilv_path_join(bundle_1_path, "manifest.ttl"); + char* const manifest_path = + zix_path_join(NULL, bundle_1_path, "manifest.ttl"); assert(zix_file_type(manifest_path) == ZIX_FILE_TYPE_REGULAR); // Check that the expected statements are in the manifest file assert(count_statements(manifest_path) == 3); // Check that a link to the recfile exists in the saved bundle - char* const recfile_link_1 = lilv_path_join(bundle_1_path, "recfile"); + char* const recfile_link_1 = zix_path_join(NULL, bundle_1_path, "recfile"); assert(zix_file_type(recfile_link_1) == ZIX_FILE_TYPE_REGULAR); #ifndef _WIN32 assert(zix_symlink_type(recfile_link_1) == ZIX_FILE_TYPE_SYMLINK); @@ -630,7 +633,7 @@ test_to_files(void) lilv_instance_run(instance, 2); // Get updated state - char* const bundle_2_path = lilv_path_join(dirs.top, "state2.lv2"); + char* const bundle_2_path = zix_path_join(NULL, dirs.top, "state2.lv2"); LilvState* const state_2 = state_from_instance(plugin, instance, ctx, &dirs, bundle_2_path); @@ -644,11 +647,11 @@ test_to_files(void) "state.ttl")); // Check that a new snapshop of the recfile was created - char* const recfile_copy_2 = lilv_path_join(dirs.copy, "recfile.2"); + char* const recfile_copy_2 = zix_path_join(NULL, dirs.copy, "recfile.2"); assert(zix_file_type(recfile_copy_2) == ZIX_FILE_TYPE_REGULAR); // Check that a link to the recfile exists in the updated bundle - char* const recfile_link_2 = lilv_path_join(bundle_2_path, "recfile"); + char* const recfile_link_2 = zix_path_join(NULL, bundle_2_path, "recfile"); assert(zix_file_type(recfile_link_2) == ZIX_FILE_TYPE_REGULAR); #ifndef _WIN32 assert(zix_symlink_type(recfile_link_2) == ZIX_FILE_TYPE_SYMLINK); @@ -664,16 +667,16 @@ test_to_files(void) assert(!lilv_remove(bundle_1_path)); cleanup_test_directories(dirs); - free(recfile_link_2); - free(recfile_copy_2); + zix_free(NULL, recfile_link_2); + zix_free(NULL, recfile_copy_2); lilv_state_free(state_2); - free(bundle_2_path); - free(recfile_link_1); - free(manifest_path); - free(recfile_copy_1); + zix_free(NULL, bundle_2_path); + zix_free(NULL, recfile_link_1); + zix_free(NULL, manifest_path); + zix_free(NULL, recfile_copy_1); lilv_state_free(state_1); - free(bundle_1_path); - free(recfile_path); + zix_free(NULL, bundle_1_path); + zix_free(NULL, recfile_path); test_context_free(ctx); } @@ -696,7 +699,7 @@ test_multi_save(void) assert(instance); // Get state - char* const bundle_1_path = lilv_path_join(dirs.top, "state1.lv2"); + char* const bundle_1_path = zix_path_join(NULL, dirs.top, "state1.lv2"); LilvState* const state_1 = state_from_instance(plugin, instance, ctx, &dirs, bundle_1_path); @@ -710,11 +713,12 @@ test_multi_save(void) "state.ttl")); // Check that a manifest exists - char* const manifest_path = lilv_path_join(bundle_1_path, "manifest.ttl"); + char* const manifest_path = + zix_path_join(NULL, bundle_1_path, "manifest.ttl"); assert(zix_file_type(manifest_path) == ZIX_FILE_TYPE_REGULAR); // Check that the state file exists - char* const state_path = lilv_path_join(bundle_1_path, "state.ttl"); + char* const state_path = zix_path_join(NULL, bundle_1_path, "state.ttl"); assert(zix_file_type(state_path) == ZIX_FILE_TYPE_REGULAR); // Check that the expected statements are in the files @@ -776,7 +780,7 @@ test_files_round_trip(void) assert(ctx->out == 1.0); // Save first state to a bundle - char* const bundle_1_1_path = lilv_path_join(dirs.top, "state1_1.lv2"); + char* const bundle_1_1_path = zix_path_join(NULL, dirs.top, "state1_1.lv2"); LilvState* const state_1_1 = state_from_instance(plugin, instance, ctx, &dirs, bundle_1_1_path); @@ -789,7 +793,7 @@ test_files_round_trip(void) "state.ttl")); // Save first state to another bundle - char* const bundle_1_2_path = lilv_path_join(dirs.top, "state1_2.lv2"); + char* const bundle_1_2_path = zix_path_join(NULL, dirs.top, "state1_2.lv2"); LilvState* const state_1_2 = state_from_instance(plugin, instance, ctx, &dirs, bundle_1_2_path); @@ -802,8 +806,10 @@ test_files_round_trip(void) "state.ttl")); // Load both first state bundles and check that the results are equal - char* const state_1_1_path = lilv_path_join(bundle_1_1_path, "state.ttl"); - char* const state_1_2_path = lilv_path_join(bundle_1_2_path, "state.ttl"); + char* const state_1_1_path = + zix_path_join(NULL, bundle_1_1_path, "state.ttl"); + char* const state_1_2_path = + zix_path_join(NULL, bundle_1_2_path, "state.ttl"); LilvState* state_1_1_loaded = lilv_state_new_from_file(ctx->env->world, &ctx->map, NULL, state_1_1_path); @@ -819,7 +825,7 @@ test_files_round_trip(void) lilv_instance_run(instance, 2); // Save updated state to a bundle - char* const bundle_2_path = lilv_path_join(dirs.top, "state2.lv2"); + char* const bundle_2_path = zix_path_join(NULL, dirs.top, "state2.lv2"); LilvState* const state_2 = state_from_instance(plugin, instance, ctx, &dirs, bundle_2_path); @@ -832,7 +838,7 @@ test_files_round_trip(void) "state.ttl")); // Load updated state bundle and check that it differs from the others - char* const state_2_path = lilv_path_join(bundle_2_path, "state.ttl"); + char* const state_2_path = zix_path_join(NULL, bundle_2_path, "state.ttl"); LilvState* state_2_loaded = lilv_state_new_from_file(ctx->env->world, &ctx->map, NULL, state_2_path); @@ -894,7 +900,7 @@ test_world_round_trip(void) assert(ctx->out == 1.0); // Save state to a bundle - char* const bundle_path = lilv_path_join(dirs.top, "state.lv2/"); + char* const bundle_path = zix_path_join(NULL, dirs.top, "state.lv2/"); LilvState* const start_state = state_from_instance(plugin, instance, ctx, &dirs, bundle_path); @@ -959,7 +965,7 @@ test_label_round_trip(void) lilv_state_set_label(state, "Monopoly on violence"); // Save to a bundle - char* const bundle_path = lilv_path_join(dirs.top, "state.lv2/"); + char* const bundle_path = zix_path_join(NULL, dirs.top, "state.lv2/"); assert(!lilv_state_save(ctx->env->world, &ctx->map, &ctx->unmap, @@ -969,7 +975,7 @@ test_label_round_trip(void) "state.ttl")); // Load bundle and check the label and that the states are equal - char* const state_path = lilv_path_join(bundle_path, "state.ttl"); + char* const state_path = zix_path_join(NULL, bundle_path, "state.ttl"); LilvState* const loaded = lilv_state_new_from_file(ctx->env->world, &ctx->map, NULL, state_path); @@ -1046,7 +1052,7 @@ test_delete(void) assert(ctx->out == 1.0); // Save state to a bundle - char* const bundle_path = lilv_path_join(dirs.top, "state.lv2/"); + char* const bundle_path = zix_path_join(NULL, dirs.top, "state.lv2/"); LilvState* const state = state_from_instance(plugin, instance, ctx, &dirs, bundle_path); diff --git a/test/test_util.c b/test/test_util.c index 6eaf3e5..f8fcd7f 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -6,6 +6,7 @@ #include "../src/filesystem.h" #include "lilv/lilv.h" +#include "zix/path.h" #include #include @@ -16,8 +17,8 @@ main(void) assert(!lilv_path_canonical(NULL)); char* const dir = lilv_create_temporary_directory("lilv_test_util_XXXXXX"); - char* const a_path = lilv_path_join(dir, "copy_a_XXXXXX"); - char* const b_path = lilv_path_join(dir, "copy_b_XXXXXX"); + char* const a_path = zix_path_join(NULL, dir, "copy_a_XXXXXX"); + char* const b_path = zix_path_join(NULL, dir, "copy_b_XXXXXX"); FILE* const fa = fopen(a_path, "w"); FILE* const fb = fopen(b_path, "w"); -- cgit v1.2.1