From f985269ef5033fac4cbb576dd2fa01c08b3a02b3 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 15 Apr 2022 16:01:40 -0500 Subject: [PATCH] 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. --- level_0/f_directory/tests/unit/c/test-directory-list.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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)); -- 1.8.3.1