From 07a05e6edbf20016836a7c47d8cb8102fbfed86b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Nov 2022 17:54:30 -0500 Subject: Use zix_dir_for_each() --- test/test_filesystem.c | 59 -------------------------------------------------- test/test_state.c | 22 +++++++++---------- 2 files changed, 11 insertions(+), 70 deletions(-) (limited to 'test') diff --git a/test/test_filesystem.c b/test/test_filesystem.c index f788e90..4ed1d5e 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -3,16 +3,10 @@ #undef NDEBUG -#include "lilv_internal.h" - #include "../src/filesystem.h" -#include "zix/filesystem.h" -#include "zix/path.h" - #include #include -#include #include #include @@ -104,58 +98,6 @@ test_path_filename(void) #endif } -typedef struct { - size_t n_names; - char** names; -} FileList; - -static void -visit(const char* const path, const char* const name, void* const data) -{ - (void)path; - - FileList* file_list = (FileList*)data; - - file_list->names = - (char**)realloc(file_list->names, sizeof(char*) * ++file_list->n_names); - - file_list->names[file_list->n_names - 1] = lilv_strdup(name); -} - -static void -test_dir_for_each(void) -{ - char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - 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"); - fprintf(f1, "test\n"); - fprintf(f2, "test\n"); - fclose(f2); - fclose(f1); - - FileList file_list = {0, NULL}; - lilv_dir_for_each(temp_dir, &file_list, visit); - - assert((!strcmp(file_list.names[0], "lilv_test_1") && - !strcmp(file_list.names[1], "lilv_test_2")) || - (!strcmp(file_list.names[0], "lilv_test_2") && - !strcmp(file_list.names[1], "lilv_test_1"))); - - assert(!zix_remove(path2)); - assert(!zix_remove(path1)); - assert(!zix_remove(temp_dir)); - - free(file_list.names[0]); - free(file_list.names[1]); - free(file_list.names); - free(path2); - free(path1); - free(temp_dir); -} - int main(void) { @@ -163,7 +105,6 @@ main(void) test_path_relative_to(); test_path_parent(); test_path_filename(); - test_dir_for_each(); return 0; } diff --git a/test/test_state.c b/test/test_state.c index 26d8d97..f29949e 100644 --- a/test/test_state.c +++ b/test/test_state.c @@ -155,9 +155,9 @@ remove_file(const char* path, const char* name, void* data) static void cleanup_test_directories(const TestDirectories dirs) { - lilv_dir_for_each(dirs.scratch, NULL, remove_file); - lilv_dir_for_each(dirs.copy, NULL, remove_file); - lilv_dir_for_each(dirs.link, NULL, remove_file); + zix_dir_for_each(dirs.scratch, NULL, remove_file); + zix_dir_for_each(dirs.copy, NULL, remove_file); + zix_dir_for_each(dirs.link, NULL, remove_file); assert(!zix_remove(dirs.link)); assert(!zix_remove(dirs.copy)); @@ -661,8 +661,8 @@ test_to_files(void) assert(zix_file_equals(NULL, recfile_link_2, recfile_copy_2)); lilv_instance_free(instance); - lilv_dir_for_each(bundle_2_path, NULL, remove_file); - lilv_dir_for_each(bundle_1_path, NULL, remove_file); + zix_dir_for_each(bundle_2_path, NULL, remove_file); + zix_dir_for_each(bundle_1_path, NULL, remove_file); assert(!zix_remove(bundle_2_path)); assert(!zix_remove(bundle_1_path)); cleanup_test_directories(dirs); @@ -741,7 +741,7 @@ test_multi_save(void) assert(count_statements(state_path) == 21); lilv_instance_free(instance); - lilv_dir_for_each(bundle_1_path, NULL, remove_file); + zix_dir_for_each(bundle_1_path, NULL, remove_file); zix_remove(bundle_1_path); cleanup_test_directories(dirs); @@ -847,9 +847,9 @@ test_files_round_trip(void) assert(!lilv_state_equals(state_1_1_loaded, state_2_loaded)); lilv_instance_free(instance); - lilv_dir_for_each(bundle_1_1_path, NULL, remove_file); - lilv_dir_for_each(bundle_1_2_path, NULL, remove_file); - lilv_dir_for_each(bundle_2_path, NULL, remove_file); + zix_dir_for_each(bundle_1_1_path, NULL, remove_file); + zix_dir_for_each(bundle_1_2_path, NULL, remove_file); + zix_dir_for_each(bundle_2_path, NULL, remove_file); zix_remove(bundle_1_1_path); zix_remove(bundle_1_2_path); zix_remove(bundle_2_path); @@ -1066,7 +1066,7 @@ test_delete(void) // Count the number of shared files before doing anything unsigned n_shared_files_before = 0; - lilv_dir_for_each(dirs.shared, &n_shared_files_before, count_file); + zix_dir_for_each(dirs.shared, &n_shared_files_before, count_file); lilv_instance_free(instance); @@ -1075,7 +1075,7 @@ test_delete(void) // Ensure the number of shared files is the same after deletion unsigned n_shared_files_after = 0; - lilv_dir_for_each(dirs.shared, &n_shared_files_after, count_file); + zix_dir_for_each(dirs.shared, &n_shared_files_after, count_file); assert(n_shared_files_before == n_shared_files_after); // Ensure the state directory has been deleted -- cgit v1.2.1