From eaffa36f00cdb340a84c0847c22aab6248814903 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 16 Jan 2022 14:58:57 -0600 Subject: [PATCH] Update: Add parameter checking to unit tests, fix ordering, and other minor changes. --- level_0/f_account/tests/c/test-account-by_id.c | 91 +++++++++++--------- level_0/f_account/tests/c/test-account-by_id.h | 17 +++- level_0/f_account/tests/c/test-account-by_name.c | 97 ++++++++++++---------- level_0/f_account/tests/c/test-account-by_name.h | 17 +++- .../tests/c/test-account-id_group_by_name.c | 93 ++++++++++++--------- .../tests/c/test-account-id_group_by_name.h | 17 +++- .../tests/c/test-account-id_user_by_name.c | 91 +++++++++++--------- .../tests/c/test-account-id_user_by_name.h | 17 +++- .../tests/c/test-account-name_group_by_id.c | 91 +++++++++++--------- .../tests/c/test-account-name_group_by_id.h | 17 +++- .../tests/c/test-account-name_user_by_id.c | 91 +++++++++++--------- .../tests/c/test-account-name_user_by_id.h | 17 +++- level_0/f_account/tests/c/test-account.c | 31 ++++--- 13 files changed, 411 insertions(+), 276 deletions(-) diff --git a/level_0/f_account/tests/c/test-account-by_id.c b/level_0/f_account/tests/c/test-account-by_id.c index 3c43894..c4d7395 100644 --- a/level_0/f_account/tests/c/test-account-by_id.c +++ b/level_0/f_account/tests/c/test-account-by_id.c @@ -5,6 +5,46 @@ extern "C" { #endif +void test__f_account_by_id__fails(void **state) { + + const long size = 20; + uid_t uid = 0; + f_account_t account = f_account_t_initialize; + + int errnos[] = { + EINTR, + EIO, + EMFILE, + ENFILE, + ENOMEM, + ERANGE, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_interrupt, + F_input_output, + F_file_descriptor_max, + F_file_open_max, + F_memory_not, + F_buffer_too_small, + F_failure, + }; + + for (int i = 0; i < 7; ++i) { + + will_return(__wrap_sysconf, size); + will_return(__wrap_getpwuid_r, true); + will_return(__wrap_getpwuid_r, errnos[i]); + + const f_status_t status = f_account_by_id(uid, &account); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + + macro_f_account_t_delete_simple(account); +} + void test__f_account_by_id__not_found(void **state) { const long size = 20; @@ -26,6 +66,17 @@ void test__f_account_by_id__not_found(void **state) { macro_f_account_t_delete_simple(account); } +#ifndef _di_level_0_parameter_checking_ + void test__f_account_by_id__parameter_checking(void **state) { + + { + const f_status_t status = f_account_by_id(0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_account_by_id__works(void **state) { const long size = 20; @@ -63,46 +114,6 @@ void test__f_account_by_id__works(void **state) { macro_f_account_t_delete_simple(account); } -void test__f_account_by_id__fails(void **state) { - - const long size = 20; - uid_t uid = 0; - f_account_t account = f_account_t_initialize; - - int errnos[] = { - EINTR, - EIO, - EMFILE, - ENFILE, - ENOMEM, - ERANGE, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_interrupt, - F_input_output, - F_file_descriptor_max, - F_file_open_max, - F_memory_not, - F_buffer_too_small, - F_failure, - }; - - for (int i = 0; i < 7; ++i) { - - will_return(__wrap_sysconf, size); - will_return(__wrap_getpwuid_r, true); - will_return(__wrap_getpwuid_r, errnos[i]); - - const f_status_t status = f_account_by_id(uid, &account); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for - - macro_f_account_t_delete_simple(account); -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/tests/c/test-account-by_id.h b/level_0/f_account/tests/c/test-account-by_id.h index 00c9d31..111eb12 100644 --- a/level_0/f_account/tests/c/test-account-by_id.h +++ b/level_0/f_account/tests/c/test-account-by_id.h @@ -11,6 +11,13 @@ #define _TEST__F_account_by_id_ /** + * Test that function fails. + * + * @see f_account_by_id() + */ +extern void test__f_account_by_id__fails(void **state); + +/** * Test that function works but the account does not exist. * * @see f_account_by_id() @@ -18,17 +25,19 @@ extern void test__f_account_by_id__not_found(void **state); /** - * Test that function works. + * Test that parameter checking works as expected. * * @see f_account_by_id() */ -extern void test__f_account_by_id__works(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_account_by_id__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ /** - * Test that function fails. + * Test that function works. * * @see f_account_by_id() */ -extern void test__f_account_by_id__fails(void **state); +extern void test__f_account_by_id__works(void **state); #endif // _TEST__F_account_by_id_ diff --git a/level_0/f_account/tests/c/test-account-by_name.c b/level_0/f_account/tests/c/test-account-by_name.c index d3a9075..e1faebf 100644 --- a/level_0/f_account/tests/c/test-account-by_name.c +++ b/level_0/f_account/tests/c/test-account-by_name.c @@ -5,11 +5,51 @@ extern "C" { #endif +void test__f_account_by_name__fails(void **state) { + + const long size = 20; + char *name = "name"; + f_account_t account = f_account_t_initialize; + + int errnos[] = { + EINTR, + EIO, + EMFILE, + ENFILE, + ENOMEM, + ERANGE, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_interrupt, + F_input_output, + F_file_descriptor_max, + F_file_open_max, + F_memory_not, + F_buffer_too_small, + F_failure, + }; + + for (int i = 0; i < 7; ++i) { + + will_return(__wrap_sysconf, size); + will_return(__wrap_getpwnam_r, true); + will_return(__wrap_getpwnam_r, errnos[i]); + + const f_status_t status = f_account_by_name(name, &account); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + + macro_f_account_t_delete_simple(account); +} + void test__f_account_by_name__not_found(void **state) { const long size = 20; struct passwd password; - char *name = "the_name"; + char *name = "name"; f_account_t account = f_account_t_initialize; { @@ -26,12 +66,25 @@ void test__f_account_by_name__not_found(void **state) { macro_f_account_t_delete_simple(account); } +#ifndef _di_level_0_parameter_checking_ + void test__f_account_by_name__parameter_checking(void **state) { + + const f_string_t name = f_string_t_initialize; + + { + const f_status_t status = f_account_by_name(name, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_account_by_name__works(void **state) { const long size = 20; struct passwd password; struct passwd pointer; - char *name = "the_name"; + char *name = "name"; f_account_t account = f_account_t_initialize; password.pw_uid = 1; @@ -63,46 +116,6 @@ void test__f_account_by_name__works(void **state) { macro_f_account_t_delete_simple(account); } -void test__f_account_by_name__fails(void **state) { - - const long size = 20; - char *name = "the_name"; - f_account_t account = f_account_t_initialize; - - int errnos[] = { - EINTR, - EIO, - EMFILE, - ENFILE, - ENOMEM, - ERANGE, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_interrupt, - F_input_output, - F_file_descriptor_max, - F_file_open_max, - F_memory_not, - F_buffer_too_small, - F_failure, - }; - - for (int i = 0; i < 7; ++i) { - - will_return(__wrap_sysconf, size); - will_return(__wrap_getpwnam_r, true); - will_return(__wrap_getpwnam_r, errnos[i]); - - const f_status_t status = f_account_by_name(name, &account); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for - - macro_f_account_t_delete_simple(account); -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/tests/c/test-account-by_name.h b/level_0/f_account/tests/c/test-account-by_name.h index 4653293..0c7812c 100644 --- a/level_0/f_account/tests/c/test-account-by_name.h +++ b/level_0/f_account/tests/c/test-account-by_name.h @@ -11,6 +11,13 @@ #define _TEST__F_account_by_name_ /** + * Test that function fails. + * + * @see f_account_by_name() + */ +extern void test__f_account_by_name__fails(void **state); + +/** * Test that function works but the account does not exist. * * @see f_account_by_name() @@ -18,17 +25,19 @@ extern void test__f_account_by_name__not_found(void **state); /** - * Test that function works. + * Test that parameter checking works as expected. * * @see f_account_by_name() */ -extern void test__f_account_by_name__works(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_account_by_name__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ /** - * Test that function fails. + * Test that function works. * * @see f_account_by_name() */ -extern void test__f_account_by_name__fails(void **state); +extern void test__f_account_by_name__works(void **state); #endif // _TEST__F_account_by_name_ diff --git a/level_0/f_account/tests/c/test-account-id_group_by_name.c b/level_0/f_account/tests/c/test-account-id_group_by_name.c index b547d98..0d89003 100644 --- a/level_0/f_account/tests/c/test-account-id_group_by_name.c +++ b/level_0/f_account/tests/c/test-account-id_group_by_name.c @@ -5,11 +5,49 @@ extern "C" { #endif +void test__f_account_id_group_by_name__fails(void **state) { + + const long size = 20; + char *name = "name"; + gid_t gid = 0; + + int errnos[] = { + EINTR, + EIO, + EMFILE, + ENFILE, + ENOMEM, + ERANGE, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_interrupt, + F_input_output, + F_file_descriptor_max, + F_file_open_max, + F_memory_not, + F_buffer_too_small, + F_failure, + }; + + for (int i = 0; i < 7; ++i) { + + will_return(__wrap_sysconf, size); + will_return(__wrap_getgrnam_r, true); + will_return(__wrap_getgrnam_r, errnos[i]); + + const f_status_t status = f_account_id_group_by_name(name, &gid); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + void test__f_account_id_group_by_name__not_found(void **state) { const long size = 20; struct group group_data; - char *name = "the_name"; + char *name = "name"; gid_t gid = 0; { @@ -24,6 +62,19 @@ void test__f_account_id_group_by_name__not_found(void **state) { } } +#ifndef _di_level_0_parameter_checking_ + void test__f_account_id_group_by_name__parameter_checking(void **state) { + + const f_string_t name = f_string_t_initialize; + + { + const f_status_t status = f_account_id_group_by_name(name, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_account_id_group_by_name__works(void **state) { const long size = 20; @@ -33,7 +84,7 @@ void test__f_account_id_group_by_name__works(void **state) { gid_t gid = 0; group_data.gr_gid = 1; - group_data.gr_name = "the_name"; + group_data.gr_name = "gr_name"; group_data.gr_passwd = "gr_passwd"; group_data.gr_mem = pointers; @@ -50,44 +101,6 @@ void test__f_account_id_group_by_name__works(void **state) { } } -void test__f_account_id_group_by_name__fails(void **state) { - - const long size = 20; - char *name = "the_name"; - gid_t gid = 0; - - int errnos[] = { - EINTR, - EIO, - EMFILE, - ENFILE, - ENOMEM, - ERANGE, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_interrupt, - F_input_output, - F_file_descriptor_max, - F_file_open_max, - F_memory_not, - F_buffer_too_small, - F_failure, - }; - - for (int i = 0; i < 7; ++i) { - - will_return(__wrap_sysconf, size); - will_return(__wrap_getgrnam_r, true); - will_return(__wrap_getgrnam_r, errnos[i]); - - const f_status_t status = f_account_id_group_by_name(name, &gid); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/tests/c/test-account-id_group_by_name.h b/level_0/f_account/tests/c/test-account-id_group_by_name.h index 81f0c77..e1fe41d 100644 --- a/level_0/f_account/tests/c/test-account-id_group_by_name.h +++ b/level_0/f_account/tests/c/test-account-id_group_by_name.h @@ -11,6 +11,13 @@ #define _TEST__F_account_id_group_by_name_ /** + * Test that function fails. + * + * @see f_account_id_group_by_name() + */ +extern void test__f_account_id_group_by_name__fails(void **state); + +/** * Test that function works but the group does not exist. * * @see f_account_id_group_by_name() @@ -18,17 +25,19 @@ extern void test__f_account_id_group_by_name__not_found(void **state); /** - * Test that function works. + * Test that parameter checking works as expected. * * @see f_account_id_group_by_name() */ -extern void test__f_account_id_group_by_name__works(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_account_id_group_by_name__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ /** - * Test that function fails. + * Test that function works. * * @see f_account_id_group_by_name() */ -extern void test__f_account_id_group_by_name__fails(void **state); +extern void test__f_account_id_group_by_name__works(void **state); #endif // _TEST__F_account_id_group_by_name_ diff --git a/level_0/f_account/tests/c/test-account-id_user_by_name.c b/level_0/f_account/tests/c/test-account-id_user_by_name.c index 17811ed..4549f82 100644 --- a/level_0/f_account/tests/c/test-account-id_user_by_name.c +++ b/level_0/f_account/tests/c/test-account-id_user_by_name.c @@ -5,11 +5,49 @@ extern "C" { #endif +void test__f_account_id_user_by_name__fails(void **state) { + + const long size = 20; + char *name = "name"; + uid_t uid = 0; + + int errnos[] = { + EINTR, + EIO, + EMFILE, + ENFILE, + ENOMEM, + ERANGE, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_interrupt, + F_input_output, + F_file_descriptor_max, + F_file_open_max, + F_memory_not, + F_buffer_too_small, + F_failure, + }; + + for (int i = 0; i < 7; ++i) { + + will_return(__wrap_sysconf, size); + will_return(__wrap_getpwnam_r, true); + will_return(__wrap_getpwnam_r, errnos[i]); + + const f_status_t status = f_account_id_user_by_name(name, &uid); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for +} + void test__f_account_id_user_by_name__not_found(void **state) { const long size = 20; struct passwd password; - char *name = "the_name"; + char *name = "name"; uid_t uid = 0; { @@ -24,6 +62,19 @@ void test__f_account_id_user_by_name__not_found(void **state) { } } +#ifndef _di_level_0_parameter_checking_ + void test__f_account_id_user_by_name__parameter_checking(void **state) { + + const f_string_t name = f_string_t_initialize; + + { + const f_status_t status = f_account_id_user_by_name(name, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_account_id_user_by_name__works(void **state) { const long size = 20; @@ -52,44 +103,6 @@ void test__f_account_id_user_by_name__works(void **state) { } } -void test__f_account_id_user_by_name__fails(void **state) { - - const long size = 20; - char *name = "the_name"; - uid_t uid = 0; - - int errnos[] = { - EINTR, - EIO, - EMFILE, - ENFILE, - ENOMEM, - ERANGE, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_interrupt, - F_input_output, - F_file_descriptor_max, - F_file_open_max, - F_memory_not, - F_buffer_too_small, - F_failure, - }; - - for (int i = 0; i < 7; ++i) { - - will_return(__wrap_sysconf, size); - will_return(__wrap_getpwnam_r, true); - will_return(__wrap_getpwnam_r, errnos[i]); - - const f_status_t status = f_account_id_user_by_name(name, &uid); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/tests/c/test-account-id_user_by_name.h b/level_0/f_account/tests/c/test-account-id_user_by_name.h index d60904a..7786662 100644 --- a/level_0/f_account/tests/c/test-account-id_user_by_name.h +++ b/level_0/f_account/tests/c/test-account-id_user_by_name.h @@ -11,6 +11,13 @@ #define _TEST__F_account_id_user_by_name_ /** + * Test that function fails. + * + * @see f_account_id_user_by_name() + */ +extern void test__f_account_id_user_by_name__fails(void **state); + +/** * Test that function works but the group does not exist. * * @see f_account_id_user_by_name() @@ -18,17 +25,19 @@ extern void test__f_account_id_user_by_name__not_found(void **state); /** - * Test that function works. + * Test that parameter checking works as expected. * * @see f_account_id_user_by_name() */ -extern void test__f_account_id_user_by_name__works(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_account_id_user_by_name__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ /** - * Test that function fails. + * Test that function works. * * @see f_account_id_user_by_name() */ -extern void test__f_account_id_user_by_name__fails(void **state); +extern void test__f_account_id_user_by_name__works(void **state); #endif // _TEST__F_account_id_user_by_name_ diff --git a/level_0/f_account/tests/c/test-account-name_group_by_id.c b/level_0/f_account/tests/c/test-account-name_group_by_id.c index d1ff343..6103838 100644 --- a/level_0/f_account/tests/c/test-account-name_group_by_id.c +++ b/level_0/f_account/tests/c/test-account-name_group_by_id.c @@ -5,6 +5,46 @@ extern "C" { #endif +void test__f_account_name_group_by_id__fails(void **state) { + + const long size = 20; + gid_t gid = 0; + f_string_dynamic_t name = f_string_dynamic_t_initialize; + + int errnos[] = { + EINTR, + EIO, + EMFILE, + ENFILE, + ENOMEM, + ERANGE, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_interrupt, + F_input_output, + F_file_descriptor_max, + F_file_open_max, + F_memory_not, + F_buffer_too_small, + F_failure, + }; + + for (int i = 0; i < 7; ++i) { + + will_return(__wrap_sysconf, size); + will_return(__wrap_getgrgid_r, true); + will_return(__wrap_getgrgid_r, errnos[i]); + + const f_status_t status = f_account_name_group_by_id(gid, &name); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + + f_string_dynamic_resize(0, &name); +} + void test__f_account_name_group_by_id__not_found(void **state) { const long size = 20; @@ -26,6 +66,17 @@ void test__f_account_name_group_by_id__not_found(void **state) { f_string_dynamic_resize(0, &name); } +#ifndef _di_level_0_parameter_checking_ + void test__f_account_name_group_by_id__parameter_checking(void **state) { + + { + const f_status_t status = f_account_name_group_by_id(0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_account_name_group_by_id__works(void **state) { const long size = 20; @@ -55,46 +106,6 @@ void test__f_account_name_group_by_id__works(void **state) { f_string_dynamic_resize(0, &name); } -void test__f_account_name_group_by_id__fails(void **state) { - - const long size = 20; - gid_t gid = 0; - f_string_dynamic_t name = f_string_dynamic_t_initialize; - - int errnos[] = { - EINTR, - EIO, - EMFILE, - ENFILE, - ENOMEM, - ERANGE, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_interrupt, - F_input_output, - F_file_descriptor_max, - F_file_open_max, - F_memory_not, - F_buffer_too_small, - F_failure, - }; - - for (int i = 0; i < 7; ++i) { - - will_return(__wrap_sysconf, size); - will_return(__wrap_getgrgid_r, true); - will_return(__wrap_getgrgid_r, errnos[i]); - - const f_status_t status = f_account_name_group_by_id(gid, &name); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for - - f_string_dynamic_resize(0, &name); -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/tests/c/test-account-name_group_by_id.h b/level_0/f_account/tests/c/test-account-name_group_by_id.h index 6d44b98..d4ff4a1 100644 --- a/level_0/f_account/tests/c/test-account-name_group_by_id.h +++ b/level_0/f_account/tests/c/test-account-name_group_by_id.h @@ -11,6 +11,13 @@ #define _TEST__F_account_name_group_by_id_ /** + * Test that function fails. + * + * @see f_account_name_group_by_id() + */ +extern void test__f_account_name_group_by_id__fails(void **state); + +/** * Test that function works but the group does not exist. * * @see f_account_name_group_by_id() @@ -18,17 +25,19 @@ extern void test__f_account_name_group_by_id__not_found(void **state); /** - * Test that function works. + * Test that parameter checking works as expected. * * @see f_account_name_group_by_id() */ -extern void test__f_account_name_group_by_id__works(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_account_name_group_by_id__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ /** - * Test that function fails. + * Test that function works. * * @see f_account_name_group_by_id() */ -extern void test__f_account_name_group_by_id__fails(void **state); +extern void test__f_account_name_group_by_id__works(void **state); #endif // _TEST__F_account_name_group_by_id_ diff --git a/level_0/f_account/tests/c/test-account-name_user_by_id.c b/level_0/f_account/tests/c/test-account-name_user_by_id.c index bf14520..80dcc6b 100644 --- a/level_0/f_account/tests/c/test-account-name_user_by_id.c +++ b/level_0/f_account/tests/c/test-account-name_user_by_id.c @@ -5,6 +5,46 @@ extern "C" { #endif +void test__f_account_name_user_by_id__fails(void **state) { + + const long size = 20; + uid_t uid = 0; + f_string_dynamic_t name = f_string_dynamic_t_initialize; + + int errnos[] = { + EINTR, + EIO, + EMFILE, + ENFILE, + ENOMEM, + ERANGE, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_interrupt, + F_input_output, + F_file_descriptor_max, + F_file_open_max, + F_memory_not, + F_buffer_too_small, + F_failure, + }; + + for (int i = 0; i < 7; ++i) { + + will_return(__wrap_sysconf, size); + will_return(__wrap_getpwuid_r, true); + will_return(__wrap_getpwuid_r, errnos[i]); + + const f_status_t status = f_account_name_user_by_id(uid, &name); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + + f_string_dynamic_resize(0, &name); +} + void test__f_account_name_user_by_id__not_found(void **state) { const long size = 20; @@ -26,6 +66,17 @@ void test__f_account_name_user_by_id__not_found(void **state) { f_string_dynamic_resize(0, &name); } +#ifndef _di_level_0_parameter_checking_ + void test__f_account_name_user_by_id__parameter_checking(void **state) { + + { + const f_status_t status = f_account_name_user_by_id(0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_account_name_user_by_id__works(void **state) { const long size = 20; @@ -57,46 +108,6 @@ void test__f_account_name_user_by_id__works(void **state) { f_string_dynamic_resize(0, &name); } -void test__f_account_name_user_by_id__fails(void **state) { - - const long size = 20; - uid_t uid = 0; - f_string_dynamic_t name = f_string_dynamic_t_initialize; - - int errnos[] = { - EINTR, - EIO, - EMFILE, - ENFILE, - ENOMEM, - ERANGE, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_interrupt, - F_input_output, - F_file_descriptor_max, - F_file_open_max, - F_memory_not, - F_buffer_too_small, - F_failure, - }; - - for (int i = 0; i < 7; ++i) { - - will_return(__wrap_sysconf, size); - will_return(__wrap_getpwuid_r, true); - will_return(__wrap_getpwuid_r, errnos[i]); - - const f_status_t status = f_account_name_user_by_id(uid, &name); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for - - f_string_dynamic_resize(0, &name); -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_account/tests/c/test-account-name_user_by_id.h b/level_0/f_account/tests/c/test-account-name_user_by_id.h index 5954e64..e80814a 100644 --- a/level_0/f_account/tests/c/test-account-name_user_by_id.h +++ b/level_0/f_account/tests/c/test-account-name_user_by_id.h @@ -11,6 +11,13 @@ #define _TEST__F_account_name_user_by_id_ /** + * Test that function fails. + * + * @see f_account_name_user_by_id() + */ +extern void test__f_account_name_user_by_id__fails(void **state); + +/** * Test that function works but the group does not exist. * * @see f_account_name_user_by_id() @@ -18,17 +25,19 @@ extern void test__f_account_name_user_by_id__not_found(void **state); /** - * Test that function works. + * Test that parameter checking works as expected. * * @see f_account_name_user_by_id() */ -extern void test__f_account_name_user_by_id__works(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_account_name_user_by_id__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ /** - * Test that function fails. + * Test that function works. * * @see f_account_name_user_by_id() */ -extern void test__f_account_name_user_by_id__fails(void **state); +extern void test__f_account_name_user_by_id__works(void **state); #endif // _TEST__F_account_name_user_by_id_ diff --git a/level_0/f_account/tests/c/test-account.c b/level_0/f_account/tests/c/test-account.c index 534c6cf..74bbc83 100644 --- a/level_0/f_account/tests/c/test-account.c +++ b/level_0/f_account/tests/c/test-account.c @@ -19,29 +19,38 @@ int setdown(void **state) { int main(void) { const struct CMUnitTest tests[] = { + cmocka_unit_test(test__f_account_by_id__fails), cmocka_unit_test(test__f_account_by_id__not_found), cmocka_unit_test(test__f_account_by_id__works), - cmocka_unit_test(test__f_account_by_id__fails), + cmocka_unit_test(test__f_account_by_name__fails), cmocka_unit_test(test__f_account_by_name__not_found), cmocka_unit_test(test__f_account_by_name__works), - cmocka_unit_test(test__f_account_by_name__fails), - cmocka_unit_test(test__f_account_id_group_by_name__not_found), - cmocka_unit_test(test__f_account_id_group_by_name__works), cmocka_unit_test(test__f_account_id_group_by_name__fails), - - cmocka_unit_test(test__f_account_id_user_by_name__not_found), - cmocka_unit_test(test__f_account_id_user_by_name__works), - cmocka_unit_test(test__f_account_id_user_by_name__fails), - cmocka_unit_test(test__f_account_id_group_by_name__not_found), cmocka_unit_test(test__f_account_id_group_by_name__works), - cmocka_unit_test(test__f_account_id_group_by_name__fails), + cmocka_unit_test(test__f_account_id_user_by_name__fails), cmocka_unit_test(test__f_account_id_user_by_name__not_found), cmocka_unit_test(test__f_account_id_user_by_name__works), - cmocka_unit_test(test__f_account_id_user_by_name__fails), + + cmocka_unit_test(test__f_account_name_group_by_id__fails), + cmocka_unit_test(test__f_account_name_group_by_id__not_found), + cmocka_unit_test(test__f_account_name_group_by_id__works), + + cmocka_unit_test(test__f_account_name_user_by_id__fails), + cmocka_unit_test(test__f_account_name_user_by_id__not_found), + cmocka_unit_test(test__f_account_name_user_by_id__works), + + #ifndef _di_level_0_parameter_checking_ + cmocka_unit_test(test__f_account_by_id__parameter_checking), + cmocka_unit_test(test__f_account_by_name__parameter_checking), + cmocka_unit_test(test__f_account_id_group_by_name__parameter_checking), + cmocka_unit_test(test__f_account_id_user_by_name__parameter_checking), + cmocka_unit_test(test__f_account_name_group_by_id__parameter_checking), + cmocka_unit_test(test__f_account_name_user_by_id__parameter_checking), + #endif // _di_level_0_parameter_checking_ }; return cmocka_run_group_tests(tests, setup, setdown); -- 1.8.3.1