From d19158775a3fe08978cc0ab8d7fc44cbc8da92cf Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 3 Jan 2023 14:52:16 -0600 Subject: [PATCH] Update: Be more thorough in the f_file unit test. The "*_returns_false" test is doing a more complete check but the "*_returns_true" is not. Redesign the "*_returns_true" test to have the same structure as the "*_returns_false" test. --- level_0/f_file/tests/unit/c/test-file-is.c | 20 +++++++++++++------- level_0/f_file/tests/unit/c/test-file-is_at.c | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/level_0/f_file/tests/unit/c/test-file-is.c b/level_0/f_file/tests/unit/c/test-file-is.c index 7a846bd..ad4cd0e 100644 --- a/level_0/f_file/tests/unit/c/test-file-is.c +++ b/level_0/f_file/tests/unit/c/test-file-is.c @@ -136,21 +136,27 @@ void test__f_file_is__returns_true(void **state) { F_file_type_socket_d, }; - for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 8; ++j) { struct stat statistics; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = 1 | types[i]; + statistics.st_mode = 1 | types[j]; + + for (int i = 0; i < 8; ++i) { + + // Skip what would return false. + if (j != i) continue; - will_return(__wrap_lstat, false); - will_return(__wrap_lstat, &statistics); - will_return(__wrap_lstat, 0); + will_return(__wrap_lstat, false); + will_return(__wrap_lstat, &statistics); + will_return(__wrap_lstat, 0); - const f_status_t status = f_file_is(path, types[i], F_false); + const f_status_t status = f_file_is(path, types[i], F_false); - assert_int_equal(status, F_true); + assert_int_equal(status, F_true); + } // for } // for } diff --git a/level_0/f_file/tests/unit/c/test-file-is_at.c b/level_0/f_file/tests/unit/c/test-file-is_at.c index 41ed324..08684b1 100644 --- a/level_0/f_file/tests/unit/c/test-file-is_at.c +++ b/level_0/f_file/tests/unit/c/test-file-is_at.c @@ -123,21 +123,27 @@ void test__f_file_is_at__returns_true(void **state) { F_file_type_socket_d, }; - for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 8; ++j) { struct stat statistics; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = 1 | types[i]; + statistics.st_mode = 1 | types[j]; + + for (int i = 0; i < 8; ++i) { + + // Skip what would return false. + if (j != i) continue; - will_return(__wrap_fstatat, false); - will_return(__wrap_fstatat, &statistics); - will_return(__wrap_fstatat, 0); + will_return(__wrap_fstatat, false); + will_return(__wrap_fstatat, &statistics); + will_return(__wrap_fstatat, 0); - const f_status_t status = f_file_is_at(0, path, types[i], 0); + const f_status_t status = f_file_is_at(0, path, types[i], 0); - assert_int_equal(status, F_true); + assert_int_equal(status, F_true); + } // for } // for } -- 1.8.3.1