From: Kevin Day Date: Fri, 15 Apr 2022 21:01:40 +0000 (-0500) Subject: Update: Directory tests following recent changes. X-Git-Tag: 0.5.10~208 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=f985269ef5033fac4cbb576dd2fa01c08b3a02b3;p=fll Update: Directory tests following recent changes. The change from a7d607fecf1fdd5eff36d53b6108b6cc316bdf1f didn't include test updates. The tests need to provide properly dynamically allocated structure for the mocks so that the deallocation internal to the called functions work as expected. --- diff --git a/level_0/f_directory/tests/unit/c/test-directory-list.c b/level_0/f_directory/tests/unit/c/test-directory-list.c index f4f127c..64a1639 100644 --- a/level_0/f_directory/tests/unit/c/test-directory-list.c +++ b/level_0/f_directory/tests/unit/c/test-directory-list.c @@ -69,9 +69,10 @@ void test__f_directory_list__returns_directory_empty(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - struct dirent *directories[0]; + struct dirent **directories; - memset(directories, 0, sizeof(struct dirent *)); + // The scandir() allocates each struct dirent. + directories = malloc(sizeof(struct dirent *)); will_return(__wrap_scandir, false); will_return(__wrap_scandir, directories); @@ -91,9 +92,10 @@ void test__f_directory_list__works(void **state) { const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4); { - struct dirent *directories[1]; + struct dirent **directories; // The scandir() allocates each struct dirent. + directories = malloc(sizeof(struct dirent *)); directories[0] = (struct dirent *) malloc(sizeof(struct dirent)); memset(directories[0], 0, sizeof(struct dirent));