From 901b4a1369f28bd8646d13ea7af333dc945e7df8 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 16 Jan 2022 16:39:40 -0600 Subject: [PATCH] Update: Add parameter checking to unit tests, fix ordering, and other minor changes. --- .../tests/c/test-capability-ambient_get.c | 49 +++++---- .../tests/c/test-capability-ambient_get.h | 17 ++- .../tests/c/test-capability-ambient_reset.c | 38 +++---- .../tests/c/test-capability-ambient_reset.h | 10 +- .../tests/c/test-capability-ambient_set.c | 46 ++++---- .../tests/c/test-capability-ambient_set.h | 10 +- .../f_capability/tests/c/test-capability-clear.c | 53 +++++---- .../f_capability/tests/c/test-capability-clear.h | 17 ++- .../tests/c/test-capability-clear_flag.c | 17 ++- .../tests/c/test-capability-clear_flag.h | 17 ++- .../f_capability/tests/c/test-capability-compare.c | 62 +++++------ .../f_capability/tests/c/test-capability-compare.h | 10 +- .../f_capability/tests/c/test-capability-copy.c | 61 ++++++----- .../f_capability/tests/c/test-capability-copy.h | 13 ++- .../tests/c/test-capability-copy_external.c | 67 +++++++----- .../tests/c/test-capability-copy_external.h | 17 ++- .../tests/c/test-capability-copy_internal.c | 69 +++++++----- .../tests/c/test-capability-copy_internal.h | 17 ++- .../f_capability/tests/c/test-capability-delete.c | 55 ++++++---- .../f_capability/tests/c/test-capability-delete.h | 17 ++- .../tests/c/test-capability-file_descriptor_get.c | 59 ++++++---- .../tests/c/test-capability-file_descriptor_get.h | 17 ++- .../tests/c/test-capability-file_descriptor_set.c | 46 ++++---- .../tests/c/test-capability-file_descriptor_set.h | 10 +- .../tests/c/test-capability-file_get.c | 59 ++++++---- .../tests/c/test-capability-file_get.h | 17 ++- .../tests/c/test-capability-file_set.c | 46 ++++---- .../tests/c/test-capability-file_set.h | 10 +- .../tests/c/test-capability-flag_get.c | 69 +++++++----- .../tests/c/test-capability-flag_get.h | 17 ++- .../tests/c/test-capability-flag_set.c | 69 +++++++----- .../tests/c/test-capability-flag_set.h | 17 ++- .../tests/c/test-capability-from_name.c | 59 ++++++---- .../tests/c/test-capability-from_name.h | 17 ++- .../tests/c/test-capability-from_text.c | 59 ++++++---- .../tests/c/test-capability-from_text.h | 17 ++- .../tests/c/test-capability-groups_set.c | 52 ++++----- .../tests/c/test-capability-groups_set.h | 10 +- .../tests/c/test-capability-initialize.c | 53 +++++---- .../tests/c/test-capability-initialize.h | 17 ++- .../tests/c/test-capability-mode_get.c | 11 ++ .../tests/c/test-capability-mode_get.h | 13 ++- .../tests/c/test-capability-mode_get_name.c | 15 ++- .../tests/c/test-capability-mode_get_name.h | 13 ++- .../tests/c/test-capability-mode_set.c | 44 ++++---- .../tests/c/test-capability-mode_set.h | 10 +- .../tests/c/test-capability-owner_get.c | 15 ++- .../tests/c/test-capability-owner_get.h | 13 ++- .../tests/c/test-capability-owner_set.c | 48 ++++----- .../tests/c/test-capability-owner_set.h | 10 +- .../tests/c/test-capability-process_bound_drop.c | 61 ++++++----- .../tests/c/test-capability-process_bound_drop.h | 17 ++- .../tests/c/test-capability-process_bound_get.c | 61 ++++++----- .../tests/c/test-capability-process_bound_get.h | 17 ++- .../tests/c/test-capability-process_get.c | 53 +++++---- .../tests/c/test-capability-process_get.h | 17 ++- .../tests/c/test-capability-process_get_by_id.c | 59 +++++----- .../tests/c/test-capability-process_get_by_id.h | 17 ++- .../tests/c/test-capability-process_set.c | 44 ++++---- .../tests/c/test-capability-process_set.h | 10 +- .../tests/c/test-capability-security_bits_get.c | 53 +++++---- .../tests/c/test-capability-security_bits_get.h | 17 ++- .../tests/c/test-capability-security_bits_set.c | 44 ++++---- .../tests/c/test-capability-security_bits_set.h | 10 +- .../f_capability/tests/c/test-capability-size.c | 61 ++++++----- .../f_capability/tests/c/test-capability-size.h | 17 ++- .../tests/c/test-capability-supported.h | 6 +- .../tests/c/test-capability-supported_ambient.h | 6 +- .../tests/c/test-capability-supported_code.c | 2 +- .../tests/c/test-capability-supported_code.h | 6 +- .../f_capability/tests/c/test-capability-to_name.c | 71 +++++++----- .../f_capability/tests/c/test-capability-to_name.h | 17 ++- .../f_capability/tests/c/test-capability-to_text.c | 73 +++++++------ .../f_capability/tests/c/test-capability-to_text.h | 17 ++- .../tests/c/test-capability-user_set.c | 4 +- .../tests/c/test-capability-user_set.h | 10 +- level_0/f_capability/tests/c/test-capability.c | 120 ++++++++++++++------- 77 files changed, 1541 insertions(+), 923 deletions(-) diff --git a/level_0/f_capability/tests/c/test-capability-ambient_get.c b/level_0/f_capability/tests/c/test-capability-ambient_get.c index 9125894..42a9baa 100644 --- a/level_0/f_capability/tests/c/test-capability-ambient_get.c +++ b/level_0/f_capability/tests/c/test-capability-ambient_get.c @@ -5,9 +5,39 @@ extern "C" { #endif +void test__f_capability_ambient_get__fails(void **state) { + + #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) + f_capability_value_t value = f_capability_value_t_initialize; + int ambient = 0; + + { + will_return(__wrap_cap_get_ambient, true); + + const f_status_t status = f_capability_ambient_get(value, &ambient); + + assert_int_equal(F_status_set_fine(status), F_supported_not); + assert_int_equal(ambient, -1); + } + #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) +} + +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_ambient_get__parameter_checking(void **state) { + + const f_capability_value_t value = f_capability_value_t_initialize; + + { + const f_status_t status = f_capability_ambient_get(value, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_capability_ambient_get__works(void **state) { - f_capability_value_t value = f_capability_value_t_initialize; + const f_capability_value_t value = f_capability_value_t_initialize; int ambient = 0; #if defined(_di_libcap_) || defined(_libcap_legacy_only_) @@ -28,23 +58,6 @@ void test__f_capability_ambient_get__works(void **state) { } } -void test__f_capability_ambient_get__fails(void **state) { - - #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) - f_capability_value_t value = f_capability_value_t_initialize; - int ambient = 0; - - { - will_return(__wrap_cap_get_ambient, true); - - const f_status_t status = f_capability_ambient_get(value, &ambient); - - assert_int_equal(F_status_set_fine(status), F_supported_not); - assert_int_equal(ambient, -1); - } - #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-ambient_get.h b/level_0/f_capability/tests/c/test-capability-ambient_get.h index 89bcafe..edaad3c 100644 --- a/level_0/f_capability/tests/c/test-capability-ambient_get.h +++ b/level_0/f_capability/tests/c/test-capability-ambient_get.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__ambient_get /** - * Test that function works. + * Test that function fails. * * @see f_capability_ambient_get() */ -extern void test__f_capability_ambient_get__works(void **state); +extern void test__f_capability_ambient_get__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_ambient_get() */ -extern void test__f_capability_ambient_get__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_ambient_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_ambient_get() + */ +extern void test__f_capability_ambient_get__works(void **state); #endif // _TEST__F_capability__ambient_get diff --git a/level_0/f_capability/tests/c/test-capability-ambient_reset.c b/level_0/f_capability/tests/c/test-capability-ambient_reset.c index c17e3ea..3459bb9 100644 --- a/level_0/f_capability/tests/c/test-capability-ambient_reset.c +++ b/level_0/f_capability/tests/c/test-capability-ambient_reset.c @@ -5,25 +5,6 @@ extern "C" { #endif -void test__f_capability_ambient_reset__works(void **state) { - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - printf("[ WARN ] f_capability_ambient_reset() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_ambient, false); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - - { - const f_status_t status = f_capability_ambient_reset(); - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - } -} - void test__f_capability_ambient_reset__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) @@ -60,6 +41,25 @@ void test__f_capability_ambient_reset__fails(void **state) { #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) } +void test__f_capability_ambient_reset__works(void **state) { + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + printf("[ WARN ] f_capability_ambient_reset() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_ambient, false); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + + { + const f_status_t status = f_capability_ambient_reset(); + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-ambient_reset.h b/level_0/f_capability/tests/c/test-capability-ambient_reset.h index 8391ff8..7e6c91a 100644 --- a/level_0/f_capability/tests/c/test-capability-ambient_reset.h +++ b/level_0/f_capability/tests/c/test-capability-ambient_reset.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__ambient_reset /** - * Test that function works. + * Test that function fails. * * @see f_capability_ambient_reset() */ -extern void test__f_capability_ambient_reset__works(void **state); +extern void test__f_capability_ambient_reset__fails(void **state); + +// f_capability_ambient_reset() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_ambient_reset() */ -extern void test__f_capability_ambient_reset__fails(void **state); +extern void test__f_capability_ambient_reset__works(void **state); #endif // _TEST__F_capability__ambient_reset diff --git a/level_0/f_capability/tests/c/test-capability-ambient_set.c b/level_0/f_capability/tests/c/test-capability-ambient_set.c index db69868..584592a 100644 --- a/level_0/f_capability/tests/c/test-capability-ambient_set.c +++ b/level_0/f_capability/tests/c/test-capability-ambient_set.c @@ -5,32 +5,10 @@ extern "C" { #endif -void test__f_capability_ambient_set__works(void **state) { - - f_capability_value_t value = f_capability_value_t_initialize; - f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - printf("[ WARN ] f_capability_ambient_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_ambient, false); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - - { - const f_status_t status = f_capability_ambient_set(value, flag_value); - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - } -} - void test__f_capability_ambient_set__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) - f_capability_value_t value = f_capability_value_t_initialize; + const f_capability_value_t value = f_capability_value_t_initialize; f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; int errnos[] = { @@ -57,6 +35,28 @@ void test__f_capability_ambient_set__fails(void **state) { #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) } +void test__f_capability_ambient_set__works(void **state) { + + const f_capability_value_t value = f_capability_value_t_initialize; + f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + printf("[ WARN ] f_capability_ambient_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_ambient, false); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + + { + const f_status_t status = f_capability_ambient_set(value, flag_value); + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-ambient_set.h b/level_0/f_capability/tests/c/test-capability-ambient_set.h index 633fc7d..d57dde1 100644 --- a/level_0/f_capability/tests/c/test-capability-ambient_set.h +++ b/level_0/f_capability/tests/c/test-capability-ambient_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__ambient_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_ambient_set() */ -extern void test__f_capability_ambient_set__works(void **state); +extern void test__f_capability_ambient_set__fails(void **state); + +// f_capability_ambient_reset() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_ambient_set() */ -extern void test__f_capability_ambient_set__fails(void **state); +extern void test__f_capability_ambient_set__works(void **state); #endif // _TEST__F_capability__ambient_set diff --git a/level_0/f_capability/tests/c/test-capability-clear.c b/level_0/f_capability/tests/c/test-capability-clear.c index bff320f..8d481db 100644 --- a/level_0/f_capability/tests/c/test-capability-clear.c +++ b/level_0/f_capability/tests/c/test-capability-clear.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_capability_clear__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_clear() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_clear, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_clear(&capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_clear__fails(void **state) { #if !defined(_di_libcap_) @@ -57,6 +36,38 @@ void test__f_capability_clear__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_clear__parameter_checking(void **state) { + + { + const f_status_t status = f_capability_clear(0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_clear__works(void **state) { + + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_clear() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_clear, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_clear(&capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-clear.h b/level_0/f_capability/tests/c/test-capability-clear.h index a09104b..61a4011 100644 --- a/level_0/f_capability/tests/c/test-capability-clear.h +++ b/level_0/f_capability/tests/c/test-capability-clear.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__clear /** - * Test that function works. + * Test that function fails. * * @see f_capability_clear() */ -extern void test__f_capability_clear__works(void **state); +extern void test__f_capability_clear__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_clear() */ -extern void test__f_capability_clear__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_clear__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_clear() + */ +extern void test__f_capability_clear__works(void **state); #endif // _TEST__F_capability__clear diff --git a/level_0/f_capability/tests/c/test-capability-clear_flag.c b/level_0/f_capability/tests/c/test-capability-clear_flag.c index 280024a..f2bf87e 100644 --- a/level_0/f_capability/tests/c/test-capability-clear_flag.c +++ b/level_0/f_capability/tests/c/test-capability-clear_flag.c @@ -5,10 +5,23 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_clear_flag__parameter_checking(void **state) { + + const f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; + + { + const f_status_t status = f_capability_clear_flag(flag_value, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_capability_clear_flag__works(void **state) { f_capability_t capability = f_capability_t_initialize; - f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; + const f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; #if defined(_di_libcap_) printf("[ WARN ] f_capability_clear_flag() is not implemented and cannot be fully tested.\n"); @@ -31,7 +44,7 @@ void test__f_capability_clear_flag__fails(void **state) { #if !defined(_di_libcap_) f_capability_t capability = f_capability_t_initialize; - f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; + const f_capability_flag_value_t flag_value = f_capability_flag_value_t_initialize; int errnos[] = { EINVAL, diff --git a/level_0/f_capability/tests/c/test-capability-clear_flag.h b/level_0/f_capability/tests/c/test-capability-clear_flag.h index 23a8492..4f9fe5f 100644 --- a/level_0/f_capability/tests/c/test-capability-clear_flag.h +++ b/level_0/f_capability/tests/c/test-capability-clear_flag.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__clear_flag /** - * Test that function works. + * Test that function fails. * * @see f_capability_clear_flag() */ -extern void test__f_capability_clear_flag__works(void **state); +extern void test__f_capability_clear_flag__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_clear_flag() */ -extern void test__f_capability_clear_flag__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_clear_flag__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_clear_flag() + */ +extern void test__f_capability_clear_flag__works(void **state); #endif // _TEST__F_capability__clear_flag diff --git a/level_0/f_capability/tests/c/test-capability-compare.c b/level_0/f_capability/tests/c/test-capability-compare.c index 3762786..15833b9 100644 --- a/level_0/f_capability/tests/c/test-capability-compare.c +++ b/level_0/f_capability/tests/c/test-capability-compare.c @@ -5,10 +5,39 @@ extern "C" { #endif +void test__f_capability_compare__fails(void **state) { + + #if !defined(_di_libcap_) + const f_capability_t capability_1 = f_capability_t_initialize; + const f_capability_t capability_2 = f_capability_t_initialize; + int flags = 0; + + int errnos[] = { + EINVAL, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_parameter, + F_failure, + }; + + for (int i = 0; i < 2; ++i) { + + will_return(__wrap_cap_compare, true); + will_return(__wrap_cap_compare, errnos[i]); + + const f_status_t status = f_capability_compare(capability_1, capability_2, &flags); + + assert_int_equal(F_status_set_fine(status), statuss[i]); + } // for + #endif // !defined(_di_libcap_) +} + void test__f_capability_compare__works(void **state) { - f_capability_t capability_1 = f_capability_t_initialize; - f_capability_t capability_2 = f_capability_t_initialize; + const f_capability_t capability_1 = f_capability_t_initialize; + const f_capability_t capability_2 = f_capability_t_initialize; int flags = 0; #if defined(_di_libcap_) @@ -41,35 +70,6 @@ void test__f_capability_compare__works(void **state) { #endif // defined(_di_libcap_) } -void test__f_capability_compare__fails(void **state) { - - #if !defined(_di_libcap_) - f_capability_t capability_1 = f_capability_t_initialize; - f_capability_t capability_2 = f_capability_t_initialize; - int flags = 0; - - int errnos[] = { - EINVAL, - mock_errno_generic, - }; - - f_status_t statuss[] = { - F_parameter, - F_failure, - }; - - for (int i = 0; i < 2; ++i) { - - will_return(__wrap_cap_compare, true); - will_return(__wrap_cap_compare, errnos[i]); - - const f_status_t status = f_capability_compare(capability_1, capability_2, &flags); - - assert_int_equal(F_status_set_fine(status), statuss[i]); - } // for - #endif // !defined(_di_libcap_) -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-compare.h b/level_0/f_capability/tests/c/test-capability-compare.h index fd04416..2c087c4 100644 --- a/level_0/f_capability/tests/c/test-capability-compare.h +++ b/level_0/f_capability/tests/c/test-capability-compare.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__compare /** - * Test that function works. + * Test that function fails. * * @see f_capability_compare() */ -extern void test__f_capability_compare__works(void **state); +extern void test__f_capability_compare__fails(void **state); + +// f_capability_compare() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_compare() */ -extern void test__f_capability_compare__fails(void **state); +extern void test__f_capability_compare__works(void **state); #endif // _TEST__F_capability__compare diff --git a/level_0/f_capability/tests/c/test-capability-copy.c b/level_0/f_capability/tests/c/test-capability-copy.c index 5c5e0c3..c9407f9 100644 --- a/level_0/f_capability/tests/c/test-capability-copy.c +++ b/level_0/f_capability/tests/c/test-capability-copy.c @@ -5,33 +5,10 @@ extern "C" { #endif -void test__f_capability_copy__works(void **state) { - - f_capability_t capability_1 = f_capability_t_initialize; - f_capability_t capability_2 = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_copy() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_dup, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_copy(capability_1, &capability_2); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(capability_2, 1); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_copy__fails(void **state) { #if !defined(_di_libcap_) - f_capability_t capability_1 = f_capability_t_initialize; + const f_capability_t capability_1 = f_capability_t_initialize; f_capability_t capability_2 = f_capability_t_initialize; int errnos[] = { @@ -58,6 +35,42 @@ void test__f_capability_copy__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_copy__parameter_checking(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + + { + const f_status_t status = f_capability_copy(capability, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_copy__works(void **state) { + + const f_capability_t capability_1 = f_capability_t_initialize; + f_capability_t capability_2 = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_copy() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_dup, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_copy(capability_1, &capability_2); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(capability_2, 1); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-copy.h b/level_0/f_capability/tests/c/test-capability-copy.h index e1bfea8..0b4f453 100644 --- a/level_0/f_capability/tests/c/test-capability-copy.h +++ b/level_0/f_capability/tests/c/test-capability-copy.h @@ -11,6 +11,13 @@ #define _TEST__F_capability__copy /** + * Test that function fails. + * + * @see f_capability_copy() + */ +extern void test__f_capability_copy__fails(void **state); + +/** * Test that function works. * * @see f_capability_copy() @@ -18,10 +25,12 @@ extern void test__f_capability_copy__works(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_copy() */ -extern void test__f_capability_copy__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_copy__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ #endif // _TEST__F_capability__copy diff --git a/level_0/f_capability/tests/c/test-capability-copy_external.c b/level_0/f_capability/tests/c/test-capability-copy_external.c index 66b487a..418ed4a 100644 --- a/level_0/f_capability/tests/c/test-capability-copy_external.c +++ b/level_0/f_capability/tests/c/test-capability-copy_external.c @@ -5,37 +5,11 @@ extern "C" { #endif -void test__f_capability_copy_external__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - ssize_t max = 0; - int stub = 0; - void *external = (void *) &stub; - ssize_t size = 0; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_copy_external() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_copy_ext, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_copy_external(capability, max, external, &size); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(size, 1); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_copy_external__fails(void **state) { #if !defined(_di_libcap_) f_capability_t capability = f_capability_t_initialize; - ssize_t max = 0; + const ssize_t max = 0; int stub = 0; void *external = (void *) &stub; ssize_t size = 0; @@ -64,6 +38,45 @@ void test__f_capability_copy_external__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_copy_external__parameter_checking(void **state) { + + f_capability_t capability = f_capability_t_initialize; + + { + const f_status_t status = f_capability_copy_external(capability, 0, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_copy_external__works(void **state) { + + f_capability_t capability = f_capability_t_initialize; + const ssize_t max = 0; + int stub = 0; + void *external = (void *) &stub; + ssize_t size = 0; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_copy_external() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_copy_ext, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_copy_external(capability, max, external, &size); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(size, 1); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-copy_external.h b/level_0/f_capability/tests/c/test-capability-copy_external.h index 32c23ee..358f3ac 100644 --- a/level_0/f_capability/tests/c/test-capability-copy_external.h +++ b/level_0/f_capability/tests/c/test-capability-copy_external.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__copy_external /** - * Test that function works. + * Test that function fails. * * @see f_capability_copy_external() */ -extern void test__f_capability_copy_external__works(void **state); +extern void test__f_capability_copy_external__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_copy_external() */ -extern void test__f_capability_copy_external__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_copy_external__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_copy_external() + */ +extern void test__f_capability_copy_external__works(void **state); #endif // _TEST__F_capability__copy_external diff --git a/level_0/f_capability/tests/c/test-capability-copy_internal.c b/level_0/f_capability/tests/c/test-capability-copy_internal.c index 8aad5f3..ccd3794 100644 --- a/level_0/f_capability/tests/c/test-capability-copy_internal.c +++ b/level_0/f_capability/tests/c/test-capability-copy_internal.c @@ -5,30 +5,6 @@ extern "C" { #endif -void test__f_capability_copy_internal__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - int stub = 0; - void *external = (void *) &stub; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_copy_internal() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_copy_int, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_copy_internal(external, &capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(capability, 1); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_copy_internal__fails(void **state) { #if !defined(_di_libcap_) @@ -60,6 +36,51 @@ void test__f_capability_copy_internal__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_copy_internal__parameter_checking(void **state) { + + f_capability_t capability = f_capability_t_initialize; + int stub = 0; + void *external = (void *) &stub; + + { + const f_status_t status = f_capability_copy_internal(0, &capability); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + + { + const f_status_t status = f_capability_copy_internal(external, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_copy_internal__works(void **state) { + + f_capability_t capability = f_capability_t_initialize; + int stub = 0; + void *external = (void *) &stub; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_copy_internal() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_copy_int, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_copy_internal(external, &capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(capability, 1); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-copy_internal.h b/level_0/f_capability/tests/c/test-capability-copy_internal.h index 078a939..6e2bac1 100644 --- a/level_0/f_capability/tests/c/test-capability-copy_internal.h +++ b/level_0/f_capability/tests/c/test-capability-copy_internal.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__copy_internal /** - * Test that function works. + * Test that function fails. * * @see f_capability_copy_internal() */ -extern void test__f_capability_copy_internal__works(void **state); +extern void test__f_capability_copy_internal__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_copy_internal() */ -extern void test__f_capability_copy_internal__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_copy_internal__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_copy_internal() + */ +extern void test__f_capability_copy_internal__works(void **state); #endif // _TEST__F_capability__copy_internal diff --git a/level_0/f_capability/tests/c/test-capability-delete.c b/level_0/f_capability/tests/c/test-capability-delete.c index 1b46878..3eadd39 100644 --- a/level_0/f_capability/tests/c/test-capability-delete.c +++ b/level_0/f_capability/tests/c/test-capability-delete.c @@ -5,28 +5,6 @@ extern "C" { #endif -void test__f_capability_delete__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_delete() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_free, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_delete(&capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(capability, 0); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_delete__fails(void **state) { #if !defined(_di_libcap_) @@ -56,6 +34,39 @@ void test__f_capability_delete__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_capability_delete(0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_delete__works(void **state) { + + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_delete() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_free, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_delete(&capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(capability, 0); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-delete.h b/level_0/f_capability/tests/c/test-capability-delete.h index 6018b2a..6d6e6bd 100644 --- a/level_0/f_capability/tests/c/test-capability-delete.h +++ b/level_0/f_capability/tests/c/test-capability-delete.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__delete /** - * Test that function works. + * Test that function fails. * * @see f_capability_delete() */ -extern void test__f_capability_delete__works(void **state); +extern void test__f_capability_delete__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_delete() */ -extern void test__f_capability_delete__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_delete__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_delete() + */ +extern void test__f_capability_delete__works(void **state); #endif // _TEST__F_capability__delete diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_get.c b/level_0/f_capability/tests/c/test-capability-file_descriptor_get.c index 0d1f3ff..461d476 100644 --- a/level_0/f_capability/tests/c/test-capability-file_descriptor_get.c +++ b/level_0/f_capability/tests/c/test-capability-file_descriptor_get.c @@ -5,32 +5,10 @@ extern "C" { #endif -void test__f_capability_file_descriptor_get__works(void **state) { - - int descriptor = 0; - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_file_descriptor_get() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_fd, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_file_descriptor_get(descriptor, &capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_file_descriptor_get__fails(void **state) { #if !defined(_di_libcap_) - int descriptor = 0; + const int descriptor = 0; f_capability_t capability = f_capability_t_initialize; int errnos[] = { @@ -69,6 +47,41 @@ void test__f_capability_file_descriptor_get__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_file_descriptor_get__parameter_checking(void **state) { + + const int descriptor = 0; + + { + const f_status_t status = f_capability_file_descriptor_get(descriptor, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_file_descriptor_get__works(void **state) { + + const int descriptor = 0; + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_file_descriptor_get() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_fd, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_file_descriptor_get(descriptor, &capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_get.h b/level_0/f_capability/tests/c/test-capability-file_descriptor_get.h index b436024..b4e0db3 100644 --- a/level_0/f_capability/tests/c/test-capability-file_descriptor_get.h +++ b/level_0/f_capability/tests/c/test-capability-file_descriptor_get.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__file_descriptor_get /** - * Test that function works. + * Test that function fails. * * @see f_capability_file_descriptor_get() */ -extern void test__f_capability_file_descriptor_get__works(void **state); +extern void test__f_capability_file_descriptor_get__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_file_descriptor_get() */ -extern void test__f_capability_file_descriptor_get__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_file_descriptor_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_file_descriptor_get() + */ +extern void test__f_capability_file_descriptor_get__works(void **state); #endif // _TEST__F_capability__file_descriptor_get diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_set.c b/level_0/f_capability/tests/c/test-capability-file_descriptor_set.c index 89dccfe..f8462ae 100644 --- a/level_0/f_capability/tests/c/test-capability-file_descriptor_set.c +++ b/level_0/f_capability/tests/c/test-capability-file_descriptor_set.c @@ -5,32 +5,10 @@ extern "C" { #endif -void test__f_capability_file_descriptor_set__works(void **state) { - - int descriptor = 0; - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_file_descriptor_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_set_fd, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_file_descriptor_set(descriptor, capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_file_descriptor_set__fails(void **state) { #if !defined(_di_libcap_) - int descriptor = 0; + const int descriptor = 0; f_capability_t capability = f_capability_t_initialize; int errnos[] = { @@ -69,6 +47,28 @@ void test__f_capability_file_descriptor_set__fails(void **state) { #endif // !defined(_di_libcap_) } +void test__f_capability_file_descriptor_set__works(void **state) { + + const int descriptor = 0; + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_file_descriptor_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_set_fd, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_file_descriptor_set(descriptor, capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-file_descriptor_set.h b/level_0/f_capability/tests/c/test-capability-file_descriptor_set.h index 13e7623..bbb7628 100644 --- a/level_0/f_capability/tests/c/test-capability-file_descriptor_set.h +++ b/level_0/f_capability/tests/c/test-capability-file_descriptor_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__file_descriptor_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_file_descriptor_set() */ -extern void test__f_capability_file_descriptor_set__works(void **state); +extern void test__f_capability_file_descriptor_set__fails(void **state); + +// f_capability_file_descriptor_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_file_descriptor_set() */ -extern void test__f_capability_file_descriptor_set__fails(void **state); +extern void test__f_capability_file_descriptor_set__works(void **state); #endif // _TEST__F_capability__file_descriptor_set diff --git a/level_0/f_capability/tests/c/test-capability-file_get.c b/level_0/f_capability/tests/c/test-capability-file_get.c index 31dbb46..e02a9a6 100644 --- a/level_0/f_capability/tests/c/test-capability-file_get.c +++ b/level_0/f_capability/tests/c/test-capability-file_get.c @@ -5,32 +5,10 @@ extern "C" { #endif -void test__f_capability_file_get__works(void **state) { - - f_string_t path = f_string_t_initialize; - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_file_get() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_file, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_file_get(path, &capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_file_get__fails(void **state) { #if !defined(_di_libcap_) - f_string_t path = f_string_t_initialize; + const f_string_t path = f_string_t_initialize; f_capability_t capability = f_capability_t_initialize; int errnos[] = { @@ -69,6 +47,41 @@ void test__f_capability_file_get__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_file_get__parameter_checking(void **state) { + + const f_string_t path = f_string_t_initialize; + + { + const f_status_t status = f_capability_file_get(path, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_file_get__works(void **state) { + + const f_string_t path = f_string_t_initialize; + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_file_get() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_file, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_file_get(path, &capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-file_get.h b/level_0/f_capability/tests/c/test-capability-file_get.h index 55afbce..bc77e5a 100644 --- a/level_0/f_capability/tests/c/test-capability-file_get.h +++ b/level_0/f_capability/tests/c/test-capability-file_get.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__file_get /** - * Test that function works. + * Test that function fails. * * @see f_capability_file_get() */ -extern void test__f_capability_file_get__works(void **state); +extern void test__f_capability_file_get__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_file_get() */ -extern void test__f_capability_file_get__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_file_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_file_get() + */ +extern void test__f_capability_file_get__works(void **state); #endif // _TEST__F_capability__file_get diff --git a/level_0/f_capability/tests/c/test-capability-file_set.c b/level_0/f_capability/tests/c/test-capability-file_set.c index 6ccf929..25ca069 100644 --- a/level_0/f_capability/tests/c/test-capability-file_set.c +++ b/level_0/f_capability/tests/c/test-capability-file_set.c @@ -5,32 +5,10 @@ extern "C" { #endif -void test__f_capability_file_set__works(void **state) { - - f_string_t path = f_string_t_initialize; - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_file_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_set_file, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_file_set(path, capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_file_set__fails(void **state) { #if !defined(_di_libcap_) - f_string_t path = f_string_t_initialize; + const f_string_t path = f_string_t_initialize; f_capability_t capability = f_capability_t_initialize; int errnos[] = { @@ -69,6 +47,28 @@ void test__f_capability_file_set__fails(void **state) { #endif // !defined(_di_libcap_) } +void test__f_capability_file_set__works(void **state) { + + const f_string_t path = f_string_t_initialize; + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_file_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_set_file, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_file_set(path, capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-file_set.h b/level_0/f_capability/tests/c/test-capability-file_set.h index dd54e2e..cf2ee1d 100644 --- a/level_0/f_capability/tests/c/test-capability-file_set.h +++ b/level_0/f_capability/tests/c/test-capability-file_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__file_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_file_set() */ -extern void test__f_capability_file_set__works(void **state); +extern void test__f_capability_file_set__fails(void **state); + +// f_capability_file_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_file_set() */ -extern void test__f_capability_file_set__fails(void **state); +extern void test__f_capability_file_set__works(void **state); #endif // _TEST__F_capability__file_set diff --git a/level_0/f_capability/tests/c/test-capability-flag_get.c b/level_0/f_capability/tests/c/test-capability-flag_get.c index 5910951..8de3529 100644 --- a/level_0/f_capability/tests/c/test-capability-flag_get.c +++ b/level_0/f_capability/tests/c/test-capability-flag_get.c @@ -5,37 +5,13 @@ extern "C" { #endif -void test__f_capability_flag_get__works(void **state) { - - f_capability_flag_t flag = f_capability_flag_t_initialize; - f_capability_flag_value_t value = f_capability_flag_value_t_initialize; - f_capability_t capability = f_capability_t_initialize; - f_capability_value_t capability_value = f_capability_value_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_flag_get() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_flag, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_flag_get(capability, capability_value, flag, &value); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_flag_get__fails(void **state) { #if !defined(_di_libcap_) - f_capability_flag_t flag = f_capability_flag_t_initialize; + const f_capability_flag_t flag = f_capability_flag_t_initialize; + const f_capability_t capability = f_capability_t_initialize; + const f_capability_value_t capability_value = f_capability_value_t_initialize; f_capability_flag_value_t value = f_capability_flag_value_t_initialize; - f_capability_t capability = f_capability_t_initialize; - f_capability_value_t capability_value = f_capability_value_t_initialize; int errnos[] = { EINVAL, @@ -59,6 +35,45 @@ void test__f_capability_flag_get__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_flag_get__parameter_checking(void **state) { + + const f_capability_flag_t flag = f_capability_flag_t_initialize; + const f_capability_t capability = f_capability_t_initialize; + const f_capability_value_t capability_value = f_capability_value_t_initialize; + + { + const f_status_t status = f_capability_flag_get(capability, capability_value, flag, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_flag_get__works(void **state) { + + const f_capability_flag_t flag = f_capability_flag_t_initialize; + const f_capability_t capability = f_capability_t_initialize; + const f_capability_value_t capability_value = f_capability_value_t_initialize; + f_capability_flag_value_t value = f_capability_flag_value_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_flag_get() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_flag, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_flag_get(capability, capability_value, flag, &value); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-flag_get.h b/level_0/f_capability/tests/c/test-capability-flag_get.h index eb1b5f9..dfbdea8 100644 --- a/level_0/f_capability/tests/c/test-capability-flag_get.h +++ b/level_0/f_capability/tests/c/test-capability-flag_get.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__flag_get /** - * Test that function works. + * Test that function fails. * * @see f_capability_flag_get() */ -extern void test__f_capability_flag_get__works(void **state); +extern void test__f_capability_flag_get__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_flag_get() */ -extern void test__f_capability_flag_get__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_flag_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_flag_get() + */ +extern void test__f_capability_flag_get__works(void **state); #endif // _TEST__F_capability__flag_get diff --git a/level_0/f_capability/tests/c/test-capability-flag_set.c b/level_0/f_capability/tests/c/test-capability-flag_set.c index fd0f430..afc0c70 100644 --- a/level_0/f_capability/tests/c/test-capability-flag_set.c +++ b/level_0/f_capability/tests/c/test-capability-flag_set.c @@ -5,36 +5,12 @@ extern "C" { #endif -void test__f_capability_flag_set__works(void **state) { - - f_capability_flag_t flag = f_capability_flag_t_initialize; - f_capability_flag_value_t value = f_capability_flag_value_t_initialize; - f_int32s_t codes = f_int32s_t_initialize; - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_flag_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_set_flag, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_flag_set(flag, value, codes, &capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_flag_set__fails(void **state) { #if !defined(_di_libcap_) - f_capability_flag_t flag = f_capability_flag_t_initialize; - f_capability_flag_value_t value = f_capability_flag_value_t_initialize; - f_int32s_t codes = f_int32s_t_initialize; + const f_capability_flag_t flag = f_capability_flag_t_initialize; + const f_capability_flag_value_t value = f_capability_flag_value_t_initialize; + const f_int32s_t codes = f_int32s_t_initialize; f_capability_t capability = f_capability_t_initialize; int errnos[] = { @@ -59,6 +35,45 @@ void test__f_capability_flag_set__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_flag_set__parameter_checking(void **state) { + + const f_capability_flag_t flag = f_capability_flag_t_initialize; + const f_capability_flag_value_t value = f_capability_flag_value_t_initialize; + const f_int32s_t codes = f_int32s_t_initialize; + + { + const f_status_t status = f_capability_flag_set(flag, value, codes, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_flag_set__works(void **state) { + + const f_capability_flag_t flag = f_capability_flag_t_initialize; + const f_capability_flag_value_t value = f_capability_flag_value_t_initialize; + const f_int32s_t codes = f_int32s_t_initialize; + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_flag_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_set_flag, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_flag_set(flag, value, codes, &capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-flag_set.h b/level_0/f_capability/tests/c/test-capability-flag_set.h index 623594b..6c2638c 100644 --- a/level_0/f_capability/tests/c/test-capability-flag_set.h +++ b/level_0/f_capability/tests/c/test-capability-flag_set.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__flag_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_flag_set() */ -extern void test__f_capability_flag_set__works(void **state); +extern void test__f_capability_flag_set__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_flag_set() */ -extern void test__f_capability_flag_set__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_flag_set__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_flag_set() + */ +extern void test__f_capability_flag_set__works(void **state); #endif // _TEST__F_capability__flag_set diff --git a/level_0/f_capability/tests/c/test-capability-from_name.c b/level_0/f_capability/tests/c/test-capability-from_name.c index e1327e8..73ba3df 100644 --- a/level_0/f_capability/tests/c/test-capability-from_name.c +++ b/level_0/f_capability/tests/c/test-capability-from_name.c @@ -5,32 +5,10 @@ extern "C" { #endif -void test__f_capability_from_name__works(void **state) { - - f_string_t name = f_string_t_initialize; - f_capability_value_t capability_value = f_capability_value_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_from_name() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_from_name, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_from_name(name, &capability_value); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_from_name__fails(void **state) { #if !defined(_di_libcap_) - f_string_t name = f_string_t_initialize; + const f_string_t name = f_string_t_initialize; f_capability_value_t capability_value = f_capability_value_t_initialize; int errnos[] = { @@ -57,6 +35,41 @@ void test__f_capability_from_name__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_from_name__parameter_checking(void **state) { + + const f_string_t name = f_string_t_initialize; + + { + const f_status_t status = f_capability_from_name(name, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_from_name__works(void **state) { + + const f_string_t name = f_string_t_initialize; + f_capability_value_t capability_value = f_capability_value_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_from_name() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_from_name, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_from_name(name, &capability_value); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-from_name.h b/level_0/f_capability/tests/c/test-capability-from_name.h index c33ea13..7eaea9c 100644 --- a/level_0/f_capability/tests/c/test-capability-from_name.h +++ b/level_0/f_capability/tests/c/test-capability-from_name.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__from_name /** - * Test that function works. + * Test that function fails. * * @see f_capability_from_name() */ -extern void test__f_capability_from_name__works(void **state); +extern void test__f_capability_from_name__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_from_name() */ -extern void test__f_capability_from_name__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_from_name__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_from_name() + */ +extern void test__f_capability_from_name__works(void **state); #endif // _TEST__F_capability__from_name diff --git a/level_0/f_capability/tests/c/test-capability-from_text.c b/level_0/f_capability/tests/c/test-capability-from_text.c index 2dd90c7..672dbc0 100644 --- a/level_0/f_capability/tests/c/test-capability-from_text.c +++ b/level_0/f_capability/tests/c/test-capability-from_text.c @@ -5,32 +5,10 @@ extern "C" { #endif -void test__f_capability_from_text__works(void **state) { - - f_string_t text = f_string_t_initialize; - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_from_text() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_from_text, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_from_text(text, &capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_from_text__fails(void **state) { #if !defined(_di_libcap_) - f_string_t text = f_string_t_initialize; + const f_string_t text = f_string_t_initialize; f_capability_t capability = f_capability_t_initialize; int errnos[] = { @@ -57,6 +35,41 @@ void test__f_capability_from_text__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_from_text__parameter_checking(void **state) { + + const f_string_t text = f_string_t_initialize; + + { + const f_status_t status = f_capability_from_text(text, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_from_text__works(void **state) { + + const f_string_t text = f_string_t_initialize; + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_from_text() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_from_text, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_from_text(text, &capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-from_text.h b/level_0/f_capability/tests/c/test-capability-from_text.h index 8c54a0c..751948b 100644 --- a/level_0/f_capability/tests/c/test-capability-from_text.h +++ b/level_0/f_capability/tests/c/test-capability-from_text.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__from_text /** - * Test that function works. + * Test that function fails. * * @see f_capability_from_text() */ -extern void test__f_capability_from_text__works(void **state); +extern void test__f_capability_from_text__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_from_text() */ -extern void test__f_capability_from_text__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_from_text__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_from_text() + */ +extern void test__f_capability_from_text__works(void **state); #endif // _TEST__F_capability__from_text diff --git a/level_0/f_capability/tests/c/test-capability-groups_set.c b/level_0/f_capability/tests/c/test-capability-groups_set.c index ac3f3a0..669b8b9 100644 --- a/level_0/f_capability/tests/c/test-capability-groups_set.c +++ b/level_0/f_capability/tests/c/test-capability-groups_set.c @@ -5,35 +5,12 @@ extern "C" { #endif -void test__f_capability_groups_set__works(void **state) { - - gid_t group; - size_t total = 2; - gid_t groups[total]; - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - printf("[ WARN ] f_capability_groups_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_setgroups, false); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - - { - const f_status_t status = f_capability_groups_set(group, total, groups); - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - } -} - void test__f_capability_groups_set__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) - gid_t group; - size_t total = 2; - gid_t groups[total]; + const gid_t group = 1; + const size_t total = 2; + const gid_t groups[] = { 3, 4 }; int errnos[] = { EINVAL, @@ -61,6 +38,29 @@ void test__f_capability_groups_set__fails(void **state) { #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) } +void test__f_capability_groups_set__works(void **state) { + + const gid_t group = 1; + const size_t total = 2; + const gid_t groups[] = { 3, 4 }; + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + printf("[ WARN ] f_capability_groups_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_setgroups, false); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + + { + const f_status_t status = f_capability_groups_set(group, total, groups); + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-groups_set.h b/level_0/f_capability/tests/c/test-capability-groups_set.h index afb8fdd..9374f0f 100644 --- a/level_0/f_capability/tests/c/test-capability-groups_set.h +++ b/level_0/f_capability/tests/c/test-capability-groups_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__groups_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_groups_set() */ -extern void test__f_capability_groups_set__works(void **state); +extern void test__f_capability_groups_set__fails(void **state); + +// f_capability_groups_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_groups_set() */ -extern void test__f_capability_groups_set__fails(void **state); +extern void test__f_capability_groups_set__works(void **state); #endif // _TEST__F_capability__groups_set diff --git a/level_0/f_capability/tests/c/test-capability-initialize.c b/level_0/f_capability/tests/c/test-capability-initialize.c index 665e41e..b445852 100644 --- a/level_0/f_capability/tests/c/test-capability-initialize.c +++ b/level_0/f_capability/tests/c/test-capability-initialize.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_capability_initialize__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_initialize() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_init, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_initialize(&capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_initialize__fails(void **state) { #if !defined(_di_libcap_) @@ -55,6 +34,38 @@ void test__f_capability_initialize__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_initialize__parameter_checking(void **state) { + + { + const f_status_t status = f_capability_initialize(0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_initialize__works(void **state) { + + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_initialize() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_init, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_initialize(&capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-initialize.h b/level_0/f_capability/tests/c/test-capability-initialize.h index 3f436b4..224763b 100644 --- a/level_0/f_capability/tests/c/test-capability-initialize.h +++ b/level_0/f_capability/tests/c/test-capability-initialize.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__initialize /** - * Test that function works. + * Test that function fails. * * @see f_capability_initialize() */ -extern void test__f_capability_initialize__works(void **state); +extern void test__f_capability_initialize__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_initialize() */ -extern void test__f_capability_initialize__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_initialize__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_initialize() + */ +extern void test__f_capability_initialize__works(void **state); #endif // _TEST__F_capability__initialize diff --git a/level_0/f_capability/tests/c/test-capability-mode_get.c b/level_0/f_capability/tests/c/test-capability-mode_get.c index 7733a60..78dcc8d 100644 --- a/level_0/f_capability/tests/c/test-capability-mode_get.c +++ b/level_0/f_capability/tests/c/test-capability-mode_get.c @@ -5,6 +5,17 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_mode_get__parameter_checking(void **state) { + + { + const f_status_t status = f_capability_mode_get(0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_capability_mode_get__works(void **state) { f_capability_mode_t mode = f_capability_mode_t_initialize; diff --git a/level_0/f_capability/tests/c/test-capability-mode_get.h b/level_0/f_capability/tests/c/test-capability-mode_get.h index d30dded..0350e90 100644 --- a/level_0/f_capability/tests/c/test-capability-mode_get.h +++ b/level_0/f_capability/tests/c/test-capability-mode_get.h @@ -10,6 +10,17 @@ #ifndef _TEST__F_capability__mode_get #define _TEST__F_capability__mode_get +// cap_get_mode() doesn't return failure. + +/** + * Test that parameter checking works as expected. + * + * @see f_capability_mode_get() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_mode_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + /** * Test that function works. * @@ -17,6 +28,4 @@ */ extern void test__f_capability_mode_get__works(void **state); -// cap_get_mode() doesn't return failure. - #endif // _TEST__F_capability__mode_get diff --git a/level_0/f_capability/tests/c/test-capability-mode_get_name.c b/level_0/f_capability/tests/c/test-capability-mode_get_name.c index 71b324b..78a0b3b 100644 --- a/level_0/f_capability/tests/c/test-capability-mode_get_name.c +++ b/level_0/f_capability/tests/c/test-capability-mode_get_name.c @@ -5,9 +5,22 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_mode_get_name__parameter_checking(void **state) { + + const f_capability_mode_t mode = f_capability_mode_t_initialize; + + { + const f_status_t status = f_capability_mode_get_name(mode, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_capability_mode_get_name__works(void **state) { - f_capability_mode_t mode = f_capability_mode_t_initialize; + const f_capability_mode_t mode = f_capability_mode_t_initialize; f_string_constant_t constant = f_string_constant_t_initialize; #if defined(_di_libcap_) || defined(_libcap_legacy_only_) diff --git a/level_0/f_capability/tests/c/test-capability-mode_get_name.h b/level_0/f_capability/tests/c/test-capability-mode_get_name.h index f36776a..d9f368f 100644 --- a/level_0/f_capability/tests/c/test-capability-mode_get_name.h +++ b/level_0/f_capability/tests/c/test-capability-mode_get_name.h @@ -10,6 +10,17 @@ #ifndef _TEST__F_capability__mode_get_name #define _TEST__F_capability__mode_get_name +// cap_mode_name() doesn't return failure. + +/** + * Test that parameter checking works as expected. + * + * @see f_capability_mode_get_name() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_mode_get_name__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + /** * Test that function works. * @@ -17,6 +28,4 @@ */ extern void test__f_capability_mode_get_name__works(void **state); -// cap_mode_name() doesn't return failure. - #endif // _TEST__F_capability__mode_get_name diff --git a/level_0/f_capability/tests/c/test-capability-mode_set.c b/level_0/f_capability/tests/c/test-capability-mode_set.c index 32f56ce..f1e0588 100644 --- a/level_0/f_capability/tests/c/test-capability-mode_set.c +++ b/level_0/f_capability/tests/c/test-capability-mode_set.c @@ -5,31 +5,10 @@ extern "C" { #endif -void test__f_capability_mode_set__works(void **state) { - - f_capability_mode_t mode = f_capability_mode_t_initialize; - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - printf("[ WARN ] f_capability_mode_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_mode_set, false); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - - { - const f_status_t status = f_capability_mode_set(mode); - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - } -} - void test__f_capability_mode_set__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) - f_capability_mode_t mode = f_capability_mode_t_initialize; + const f_capability_mode_t mode = f_capability_mode_t_initialize; int errnos[] = { EINVAL, @@ -57,6 +36,27 @@ void test__f_capability_mode_set__fails(void **state) { #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) } +void test__f_capability_mode_set__works(void **state) { + + const f_capability_mode_t mode = f_capability_mode_t_initialize; + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + printf("[ WARN ] f_capability_mode_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_mode_set, false); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + + { + const f_status_t status = f_capability_mode_set(mode); + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-mode_set.h b/level_0/f_capability/tests/c/test-capability-mode_set.h index d1c8753..621b6b6 100644 --- a/level_0/f_capability/tests/c/test-capability-mode_set.h +++ b/level_0/f_capability/tests/c/test-capability-mode_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__mode_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_mode_set() */ -extern void test__f_capability_mode_set__works(void **state); +extern void test__f_capability_mode_set__fails(void **state); + +// f_capability_mode_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_mode_set() */ -extern void test__f_capability_mode_set__fails(void **state); +extern void test__f_capability_mode_set__works(void **state); #endif // _TEST__F_capability__mode_set diff --git a/level_0/f_capability/tests/c/test-capability-owner_get.c b/level_0/f_capability/tests/c/test-capability-owner_get.c index 51f0081..be036d2 100644 --- a/level_0/f_capability/tests/c/test-capability-owner_get.c +++ b/level_0/f_capability/tests/c/test-capability-owner_get.c @@ -5,9 +5,22 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_owner_get__parameter_checking(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + + { + const f_status_t status = f_capability_owner_get(capability, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_capability_owner_get__works(void **state) { - f_capability_t capability = f_capability_t_initialize; + const f_capability_t capability = f_capability_t_initialize; uid_t id; #if defined(_di_libcap_) || defined(_libcap_legacy_only_) diff --git a/level_0/f_capability/tests/c/test-capability-owner_get.h b/level_0/f_capability/tests/c/test-capability-owner_get.h index 04991c9..08bcf63 100644 --- a/level_0/f_capability/tests/c/test-capability-owner_get.h +++ b/level_0/f_capability/tests/c/test-capability-owner_get.h @@ -10,6 +10,17 @@ #ifndef _TEST__F_capability__owner_get #define _TEST__F_capability__owner_get +// cap_mode_name() doesn't return failure. + +/** + * Test that parameter checking works as expected. + * + * @see f_capability_owner_get() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_owner_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + /** * Test that function works. * @@ -17,6 +28,4 @@ */ extern void test__f_capability_owner_get__works(void **state); -// cap_mode_name() doesn't return failure. - #endif // _TEST__F_capability__owner_get diff --git a/level_0/f_capability/tests/c/test-capability-owner_set.c b/level_0/f_capability/tests/c/test-capability-owner_set.c index 02da076..7e57945 100644 --- a/level_0/f_capability/tests/c/test-capability-owner_set.c +++ b/level_0/f_capability/tests/c/test-capability-owner_set.c @@ -5,33 +5,11 @@ extern "C" { #endif -void test__f_capability_owner_set__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - uid_t id; - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - printf("[ WARN ] f_capability_owner_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_set_nsowner, false); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - - { - const f_status_t status = f_capability_owner_set(capability, id); - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - } -} - void test__f_capability_owner_set__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) - f_capability_t capability = f_capability_t_initialize; - uid_t id; + const f_capability_t capability = f_capability_t_initialize; + const uid_t id; int errnos[] = { EACCES, @@ -69,6 +47,28 @@ void test__f_capability_owner_set__fails(void **state) { #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) } +void test__f_capability_owner_set__works(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + const uid_t id; + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + printf("[ WARN ] f_capability_owner_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_set_nsowner, false); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + + { + const f_status_t status = f_capability_owner_set(capability, id); + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-owner_set.h b/level_0/f_capability/tests/c/test-capability-owner_set.h index b2687fd..60c0c4a 100644 --- a/level_0/f_capability/tests/c/test-capability-owner_set.h +++ b/level_0/f_capability/tests/c/test-capability-owner_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__owner_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_owner_set() */ -extern void test__f_capability_owner_set__works(void **state); +extern void test__f_capability_owner_set__fails(void **state); + +// f_capability_owner_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_owner_set() */ -extern void test__f_capability_owner_set__fails(void **state); +extern void test__f_capability_owner_set__works(void **state); #endif // _TEST__F_capability__owner_set diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_drop.c b/level_0/f_capability/tests/c/test-capability-process_bound_drop.c index a6bb5ab..c3fa114 100644 --- a/level_0/f_capability/tests/c/test-capability-process_bound_drop.c +++ b/level_0/f_capability/tests/c/test-capability-process_bound_drop.c @@ -5,33 +5,10 @@ extern "C" { #endif -void test__f_capability_process_bound_drop__works(void **state) { - - f_capability_value_t value = f_capability_value_t_initialize; - int bound = 0; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_process_bound_drop() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_drop_bound, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_process_bound_drop(value, &bound); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(bound, 1); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_process_bound_drop__fails(void **state) { #if !defined(_di_libcap_) - f_capability_value_t value = f_capability_value_t_initialize; + const f_capability_value_t value = f_capability_value_t_initialize; int bound = 0; int errnos[] = { @@ -60,6 +37,42 @@ void test__f_capability_process_bound_drop__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_process_bound_drop__parameter_checking(void **state) { + + const f_capability_value_t value = f_capability_value_t_initialize; + + { + const f_status_t status = f_capability_process_bound_drop(value, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_process_bound_drop__works(void **state) { + + const f_capability_value_t value = f_capability_value_t_initialize; + int bound = 0; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_process_bound_drop() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_drop_bound, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_process_bound_drop(value, &bound); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(bound, 1); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_drop.h b/level_0/f_capability/tests/c/test-capability-process_bound_drop.h index 4143d90..4981054 100644 --- a/level_0/f_capability/tests/c/test-capability-process_bound_drop.h +++ b/level_0/f_capability/tests/c/test-capability-process_bound_drop.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__process_bound_drop /** - * Test that function works. + * Test that function fails. * * @see f_capability_process_bound_drop() */ -extern void test__f_capability_process_bound_drop__works(void **state); +extern void test__f_capability_process_bound_drop__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_process_bound_drop() */ -extern void test__f_capability_process_bound_drop__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_process_bound_drop__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_process_bound_drop() + */ +extern void test__f_capability_process_bound_drop__works(void **state); #endif // _TEST__F_capability__process_bound_drop diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_get.c b/level_0/f_capability/tests/c/test-capability-process_bound_get.c index 409d541..32c85d3 100644 --- a/level_0/f_capability/tests/c/test-capability-process_bound_get.c +++ b/level_0/f_capability/tests/c/test-capability-process_bound_get.c @@ -5,33 +5,10 @@ extern "C" { #endif -void test__f_capability_process_bound_get__works(void **state) { - - f_capability_value_t value = f_capability_value_t_initialize; - int bound = 0; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_process_bound_get() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_bound, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_process_bound_get(value, &bound); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(bound, 1); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_process_bound_get__fails(void **state) { #if !defined(_di_libcap_) - f_capability_value_t value = f_capability_value_t_initialize; + const f_capability_value_t value = f_capability_value_t_initialize; int bound = 0; int errnos[] = { @@ -54,6 +31,42 @@ void test__f_capability_process_bound_get__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_process_bound_get__parameter_checking(void **state) { + + const f_capability_value_t value = f_capability_value_t_initialize; + + { + const f_status_t status = f_capability_process_bound_get(value, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_process_bound_get__works(void **state) { + + const f_capability_value_t value = f_capability_value_t_initialize; + int bound = 0; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_process_bound_get() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_bound, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_process_bound_get(value, &bound); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(bound, 1); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-process_bound_get.h b/level_0/f_capability/tests/c/test-capability-process_bound_get.h index cfa3f9b..58bd2e8 100644 --- a/level_0/f_capability/tests/c/test-capability-process_bound_get.h +++ b/level_0/f_capability/tests/c/test-capability-process_bound_get.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__process_bound_get /** - * Test that function works. + * Test that function fails. * * @see f_capability_process_bound_get() */ -extern void test__f_capability_process_bound_get__works(void **state); +extern void test__f_capability_process_bound_get__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_process_bound_get() */ -extern void test__f_capability_process_bound_get__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_process_bound_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_process_bound_get() + */ +extern void test__f_capability_process_bound_get__works(void **state); #endif // _TEST__F_capability__process_bound_get diff --git a/level_0/f_capability/tests/c/test-capability-process_get.c b/level_0/f_capability/tests/c/test-capability-process_get.c index 60aded0..8d34dfc 100644 --- a/level_0/f_capability/tests/c/test-capability-process_get.c +++ b/level_0/f_capability/tests/c/test-capability-process_get.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_capability_process_get__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_process_get() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_proc, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_process_get(&capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_process_get__fails(void **state) { #if !defined(_di_libcap_) @@ -55,6 +34,38 @@ void test__f_capability_process_get__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_process_get__parameter_checking(void **state) { + + { + const f_status_t status = f_capability_process_get(0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_process_get__works(void **state) { + + f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_process_get() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_proc, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_process_get(&capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-process_get.h b/level_0/f_capability/tests/c/test-capability-process_get.h index 2397ab2..eb01f17 100644 --- a/level_0/f_capability/tests/c/test-capability-process_get.h +++ b/level_0/f_capability/tests/c/test-capability-process_get.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__process_get /** - * Test that function works. + * Test that function fails. * * @see f_capability_process_get() */ -extern void test__f_capability_process_get__works(void **state); +extern void test__f_capability_process_get__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_process_get() */ -extern void test__f_capability_process_get__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_process_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_process_get() + */ +extern void test__f_capability_process_get__works(void **state); #endif // _TEST__F_capability__process_get diff --git a/level_0/f_capability/tests/c/test-capability-process_get_by_id.c b/level_0/f_capability/tests/c/test-capability-process_get_by_id.c index 7087f20..723b998 100644 --- a/level_0/f_capability/tests/c/test-capability-process_get_by_id.c +++ b/level_0/f_capability/tests/c/test-capability-process_get_by_id.c @@ -5,34 +5,11 @@ extern "C" { #endif -void test__f_capability_process_get_by_id__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - pid_t pid; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_process_get_by_id() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_pid, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_process_get_by_id(pid, &capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(capability, 1); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_process_get_by_id__fails(void **state) { #if !defined(_di_libcap_) f_capability_t capability = f_capability_t_initialize; - pid_t pid; + const pid_t pid = 0; int errnos[] = { mock_errno_generic, @@ -54,6 +31,40 @@ void test__f_capability_process_get_by_id__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_process_get_by_id__parameter_checking(void **state) { + + { + const f_status_t status = f_capability_process_get_by_id(0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_process_get_by_id__works(void **state) { + + f_capability_t capability = f_capability_t_initialize; + const pid_t pid = 0; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_process_get_by_id() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_pid, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_process_get_by_id(pid, &capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(capability, 1); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-process_get_by_id.h b/level_0/f_capability/tests/c/test-capability-process_get_by_id.h index d5c9357..6688dd3 100644 --- a/level_0/f_capability/tests/c/test-capability-process_get_by_id.h +++ b/level_0/f_capability/tests/c/test-capability-process_get_by_id.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__process_get_by_id /** - * Test that function works. + * Test that function fails. * * @see f_capability_process_get_by_id() */ -extern void test__f_capability_process_get_by_id__works(void **state); +extern void test__f_capability_process_get_by_id__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_process_get_by_id() */ -extern void test__f_capability_process_get_by_id__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_process_get_by_id__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_process_get_by_id() + */ +extern void test__f_capability_process_get_by_id__works(void **state); #endif // _TEST__F_capability__process_get_by_id diff --git a/level_0/f_capability/tests/c/test-capability-process_set.c b/level_0/f_capability/tests/c/test-capability-process_set.c index 00b26cd..a16bd13 100644 --- a/level_0/f_capability/tests/c/test-capability-process_set.c +++ b/level_0/f_capability/tests/c/test-capability-process_set.c @@ -5,31 +5,10 @@ extern "C" { #endif -void test__f_capability_process_set__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_process_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_set_proc, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_process_set(capability); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_process_set__fails(void **state) { #if !defined(_di_libcap_) - f_capability_t capability = f_capability_t_initialize; + const f_capability_t capability = f_capability_t_initialize; int errnos[] = { EINVAL, @@ -57,6 +36,27 @@ void test__f_capability_process_set__fails(void **state) { #endif // !defined(_di_libcap_) } +void test__f_capability_process_set__works(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_process_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_set_proc, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_process_set(capability); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-process_set.h b/level_0/f_capability/tests/c/test-capability-process_set.h index dccdc6d..f27f7aa 100644 --- a/level_0/f_capability/tests/c/test-capability-process_set.h +++ b/level_0/f_capability/tests/c/test-capability-process_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__process_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_process_set() */ -extern void test__f_capability_process_set__works(void **state); +extern void test__f_capability_process_set__fails(void **state); + +// f_capability_process_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_process_set() */ -extern void test__f_capability_process_set__fails(void **state); +extern void test__f_capability_process_set__works(void **state); #endif // _TEST__F_capability__process_set diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_get.c b/level_0/f_capability/tests/c/test-capability-security_bits_get.c index d2bb8af..fc13d0b 100644 --- a/level_0/f_capability/tests/c/test-capability-security_bits_get.c +++ b/level_0/f_capability/tests/c/test-capability-security_bits_get.c @@ -5,27 +5,6 @@ extern "C" { #endif -void test__f_capability_security_bits_get__works(void **state) { - - f_capability_bits_t bits = f_capability_bits_t_initialize; - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - printf("[ WARN ] f_capability_security_bits_get() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_get_secbits, false); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - - { - const f_status_t status = f_capability_security_bits_get(&bits); - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - } -} - void test__f_capability_security_bits_get__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) @@ -57,6 +36,38 @@ void test__f_capability_security_bits_get__fails(void **state) { #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_security_bits_get__parameter_checking(void **state) { + + { + const f_status_t status = f_capability_security_bits_get(0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_security_bits_get__works(void **state) { + + f_capability_bits_t bits = f_capability_bits_t_initialize; + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + printf("[ WARN ] f_capability_security_bits_get() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_get_secbits, false); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + + { + const f_status_t status = f_capability_security_bits_get(&bits); + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_get.h b/level_0/f_capability/tests/c/test-capability-security_bits_get.h index c1ae696..72e1fd1 100644 --- a/level_0/f_capability/tests/c/test-capability-security_bits_get.h +++ b/level_0/f_capability/tests/c/test-capability-security_bits_get.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__security_bits_get /** - * Test that function works. + * Test that function fails. * * @see f_capability_security_bits_get() */ -extern void test__f_capability_security_bits_get__works(void **state); +extern void test__f_capability_security_bits_get__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_security_bits_get() */ -extern void test__f_capability_security_bits_get__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_security_bits_get__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_security_bits_get() + */ +extern void test__f_capability_security_bits_get__works(void **state); #endif // _TEST__F_capability__security_bits_get diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_set.c b/level_0/f_capability/tests/c/test-capability-security_bits_set.c index 55e2621..3e93ecf 100644 --- a/level_0/f_capability/tests/c/test-capability-security_bits_set.c +++ b/level_0/f_capability/tests/c/test-capability-security_bits_set.c @@ -5,31 +5,10 @@ extern "C" { #endif -void test__f_capability_security_bits_set__works(void **state) { - - f_capability_bits_t bits = f_capability_bits_t_initialize; - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - printf("[ WARN ] f_capability_security_bits_set() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_set_secbits, false); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - - { - const f_status_t status = f_capability_security_bits_set(bits); - - #if defined(_di_libcap_) || defined(_libcap_legacy_only_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) - } -} - void test__f_capability_security_bits_set__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) - f_capability_bits_t bits = f_capability_bits_t_initialize; + const f_capability_bits_t bits = f_capability_bits_t_initialize; int errnos[] = { EACCES, @@ -67,6 +46,27 @@ void test__f_capability_security_bits_set__fails(void **state) { #endif // !defined(_di_libcap_) && !defined(_libcap_legacy_only_) } +void test__f_capability_security_bits_set__works(void **state) { + + const f_capability_bits_t bits = f_capability_bits_t_initialize; + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + printf("[ WARN ] f_capability_security_bits_set() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_set_secbits, false); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + + { + const f_status_t status = f_capability_security_bits_set(bits); + + #if defined(_di_libcap_) || defined(_libcap_legacy_only_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + #endif // defined(_di_libcap_) || defined(_libcap_legacy_only_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-security_bits_set.h b/level_0/f_capability/tests/c/test-capability-security_bits_set.h index ec29fa3..3e7bb2d 100644 --- a/level_0/f_capability/tests/c/test-capability-security_bits_set.h +++ b/level_0/f_capability/tests/c/test-capability-security_bits_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__security_bits_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_security_bits_set() */ -extern void test__f_capability_security_bits_set__works(void **state); +extern void test__f_capability_security_bits_set__fails(void **state); + +// f_capability_security_bits_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_security_bits_set() */ -extern void test__f_capability_security_bits_set__fails(void **state); +extern void test__f_capability_security_bits_set__works(void **state); #endif // _TEST__F_capability__security_bits_set diff --git a/level_0/f_capability/tests/c/test-capability-size.c b/level_0/f_capability/tests/c/test-capability-size.c index 10378c3..0547599 100644 --- a/level_0/f_capability/tests/c/test-capability-size.c +++ b/level_0/f_capability/tests/c/test-capability-size.c @@ -5,33 +5,10 @@ extern "C" { #endif -void test__f_capability_size__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - ssize_t size = 0; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_size() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_size, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_size(capability, &size); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_int_equal(status, F_none); - assert_int_equal(size, 1); - #endif // defined(_di_libcap_) - } -} - void test__f_capability_size__fails(void **state) { #if !defined(_di_libcap_) - f_capability_t capability = f_capability_t_initialize; + const f_capability_t capability = f_capability_t_initialize; ssize_t size = 0; int errnos[] = { @@ -60,6 +37,42 @@ void test__f_capability_size__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_size__parameter_checking(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + + { + const f_status_t status = f_capability_size(capability, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_size__works(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + ssize_t size = 0; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_size() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_size, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_size(capability, &size); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_int_equal(status, F_none); + assert_int_equal(size, 1); + #endif // defined(_di_libcap_) + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-size.h b/level_0/f_capability/tests/c/test-capability-size.h index 5115f29..cf2701e 100644 --- a/level_0/f_capability/tests/c/test-capability-size.h +++ b/level_0/f_capability/tests/c/test-capability-size.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__size /** - * Test that function works. + * Test that function fails. * * @see f_capability_size() */ -extern void test__f_capability_size__works(void **state); +extern void test__f_capability_size__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_size() */ -extern void test__f_capability_size__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_size__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_size() + */ +extern void test__f_capability_size__works(void **state); #endif // _TEST__F_capability__size diff --git a/level_0/f_capability/tests/c/test-capability-supported.h b/level_0/f_capability/tests/c/test-capability-supported.h index 8cb9925..2519ea5 100644 --- a/level_0/f_capability/tests/c/test-capability-supported.h +++ b/level_0/f_capability/tests/c/test-capability-supported.h @@ -10,6 +10,10 @@ #ifndef _TEST__F_capability__supported #define _TEST__F_capability__supported +// f_capability_supported() doesn't return failure. + +// f_capability_supported() doesn't use parameter checking. + /** * Test that function works. * @@ -17,6 +21,4 @@ */ extern void test__f_capability_supported__works(void **state); -// f_capability_supported() doesn't return failure. - #endif // _TEST__F_capability__supported diff --git a/level_0/f_capability/tests/c/test-capability-supported_ambient.h b/level_0/f_capability/tests/c/test-capability-supported_ambient.h index 66bd54c..90db89c 100644 --- a/level_0/f_capability/tests/c/test-capability-supported_ambient.h +++ b/level_0/f_capability/tests/c/test-capability-supported_ambient.h @@ -10,6 +10,10 @@ #ifndef _TEST__F_capability__supported_ambient #define _TEST__F_capability__supported_ambient +// f_capability_supported_ambient() doesn't return failure. + +// f_capability_supported_ambient() doesn't use parameter checking. + /** * Test that function works. * @@ -17,6 +21,4 @@ */ extern void test__f_capability_supported_ambient__works(void **state); -// f_capability_supported_ambient() doesn't return failure. - #endif // _TEST__F_capability__supported_ambient diff --git a/level_0/f_capability/tests/c/test-capability-supported_code.c b/level_0/f_capability/tests/c/test-capability-supported_code.c index c1b54f2..c415e81 100644 --- a/level_0/f_capability/tests/c/test-capability-supported_code.c +++ b/level_0/f_capability/tests/c/test-capability-supported_code.c @@ -7,7 +7,7 @@ extern "C" { void test__f_capability_supported_code__works(void **state) { - f_capability_value_t value = f_capability_value_t_initialize; + const f_capability_value_t value = f_capability_value_t_initialize; #if defined(_di_libcap_) { diff --git a/level_0/f_capability/tests/c/test-capability-supported_code.h b/level_0/f_capability/tests/c/test-capability-supported_code.h index 7ec5a84..3a263e2 100644 --- a/level_0/f_capability/tests/c/test-capability-supported_code.h +++ b/level_0/f_capability/tests/c/test-capability-supported_code.h @@ -10,6 +10,10 @@ #ifndef _TEST__F_capability__supported_code #define _TEST__F_capability__supported_code +// f_capability_supported_code() doesn't return failure. + +// f_capability_supported_code() doesn't use parameter checking. + /** * Test that function works. * @@ -17,6 +21,4 @@ */ extern void test__f_capability_supported_code__works(void **state); -// f_capability_supported_code() doesn't return failure. - #endif // _TEST__F_capability__supported_code diff --git a/level_0/f_capability/tests/c/test-capability-to_name.c b/level_0/f_capability/tests/c/test-capability-to_name.c index 1d122f7..96ab543 100644 --- a/level_0/f_capability/tests/c/test-capability-to_name.c +++ b/level_0/f_capability/tests/c/test-capability-to_name.c @@ -5,38 +5,10 @@ extern "C" { #endif -void test__f_capability_to_name__works(void **state) { - - int code = CAP_CHOWN; - char string[] = "CAP_CHOWN"; - f_string_dynamic_t name = f_string_dynamic_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_to_name() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_to_name, false); - will_return(__wrap_cap_to_name, string); - will_return(__wrap_cap_free, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_to_name(code, &name); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_string_equal(name.string, string); - assert_int_equal(name.used, 9); - #endif // defined(_di_libcap_) - } - - f_string_dynamic_resize(0, &name); -} - void test__f_capability_to_name__fails(void **state) { #if !defined(_di_libcap_) - int code = CAP_CHOWN; + const int code = CAP_CHOWN; f_string_dynamic_t name = f_string_dynamic_t_initialize; int errnos[] = { @@ -64,6 +36,47 @@ void test__f_capability_to_name__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_to_name__parameter_checking(void **state) { + + const int code = CAP_CHOWN; + + { + const f_status_t status = f_capability_to_name(code, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_to_name__works(void **state) { + + const int code = CAP_CHOWN; + char string[] = "CAP_CHOWN"; + f_string_dynamic_t name = f_string_dynamic_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_to_name() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_to_name, false); + will_return(__wrap_cap_to_name, string); + will_return(__wrap_cap_free, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_to_name(code, &name); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_string_equal(name.string, string); + assert_int_equal(name.used, 9); + #endif // defined(_di_libcap_) + } + + f_string_dynamic_resize(0, &name); +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-to_name.h b/level_0/f_capability/tests/c/test-capability-to_name.h index c02cfb2..034fdc3 100644 --- a/level_0/f_capability/tests/c/test-capability-to_name.h +++ b/level_0/f_capability/tests/c/test-capability-to_name.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__to_name /** - * Test that function works. + * Test that function fails. * * @see f_capability_to_name() */ -extern void test__f_capability_to_name__works(void **state); +extern void test__f_capability_to_name__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_to_name() */ -extern void test__f_capability_to_name__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_to_name__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_to_name() + */ +extern void test__f_capability_to_name__works(void **state); #endif // _TEST__F_capability__to_name diff --git a/level_0/f_capability/tests/c/test-capability-to_text.c b/level_0/f_capability/tests/c/test-capability-to_text.c index e10069a..4308e3a 100644 --- a/level_0/f_capability/tests/c/test-capability-to_text.c +++ b/level_0/f_capability/tests/c/test-capability-to_text.c @@ -5,39 +5,10 @@ extern "C" { #endif -void test__f_capability_to_text__works(void **state) { - - f_capability_t capability = f_capability_t_initialize; - char string[] = "CAP_CHOWN"; - f_string_dynamic_t text = f_string_dynamic_t_initialize; - - #if defined(_di_libcap_) - printf("[ WARN ] f_capability_to_text() is not implemented and cannot be fully tested.\n"); - #else - will_return(__wrap_cap_to_text, false); - will_return(__wrap_cap_to_text, 9); - will_return(__wrap_cap_to_text, string); - will_return(__wrap_cap_free, false); - #endif // defined(_di_libcap_) - - { - const f_status_t status = f_capability_to_text(capability, &text); - - #if defined(_di_libcap_) - assert_int_equal(F_status_set_fine(status), F_implemented_not); - #else - assert_string_equal(text.string, string); - assert_int_equal(text.used, 9); - #endif // defined(_di_libcap_) - } - - f_string_dynamic_resize(0, &text); -} - void test__f_capability_to_text__fails(void **state) { #if !defined(_di_libcap_) - f_capability_t capability = f_capability_t_initialize; + const f_capability_t capability = f_capability_t_initialize; f_string_dynamic_t text = f_string_dynamic_t_initialize; int errnos[] = { @@ -65,6 +36,48 @@ void test__f_capability_to_text__fails(void **state) { #endif // !defined(_di_libcap_) } +#ifndef _di_level_0_parameter_checking_ + void test__f_capability_to_text__parameter_checking(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + + { + const f_status_t status = f_capability_to_text(capability, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + +void test__f_capability_to_text__works(void **state) { + + const f_capability_t capability = f_capability_t_initialize; + char string[] = "CAP_CHOWN"; + f_string_dynamic_t text = f_string_dynamic_t_initialize; + + #if defined(_di_libcap_) + printf("[ WARN ] f_capability_to_text() is not implemented and cannot be fully tested.\n"); + #else + will_return(__wrap_cap_to_text, false); + will_return(__wrap_cap_to_text, 9); + will_return(__wrap_cap_to_text, string); + will_return(__wrap_cap_free, false); + #endif // defined(_di_libcap_) + + { + const f_status_t status = f_capability_to_text(capability, &text); + + #if defined(_di_libcap_) + assert_int_equal(F_status_set_fine(status), F_implemented_not); + #else + assert_string_equal(text.string, string); + assert_int_equal(text.used, 9); + #endif // defined(_di_libcap_) + } + + f_string_dynamic_resize(0, &text); +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_capability/tests/c/test-capability-to_text.h b/level_0/f_capability/tests/c/test-capability-to_text.h index 4612b2c..5330e9c 100644 --- a/level_0/f_capability/tests/c/test-capability-to_text.h +++ b/level_0/f_capability/tests/c/test-capability-to_text.h @@ -11,17 +11,26 @@ #define _TEST__F_capability__to_text /** - * Test that function works. + * Test that function fails. * * @see f_capability_to_text() */ -extern void test__f_capability_to_text__works(void **state); +extern void test__f_capability_to_text__fails(void **state); /** - * Test that function fails. + * Test that parameter checking works as expected. * * @see f_capability_to_text() */ -extern void test__f_capability_to_text__fails(void **state); +#ifndef _di_level_0_parameter_checking_ + extern void test__f_capability_to_text__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** + * Test that function works. + * + * @see f_capability_to_text() + */ +extern void test__f_capability_to_text__works(void **state); #endif // _TEST__F_capability__to_text diff --git a/level_0/f_capability/tests/c/test-capability-user_set.c b/level_0/f_capability/tests/c/test-capability-user_set.c index 20e4d02..81aae3d 100644 --- a/level_0/f_capability/tests/c/test-capability-user_set.c +++ b/level_0/f_capability/tests/c/test-capability-user_set.c @@ -7,7 +7,7 @@ extern "C" { void test__f_capability_user_set__works(void **state) { - uid_t uid; + const uid_t uid = 0; #if defined(_di_libcap_) || defined(_libcap_legacy_only_) printf("[ WARN ] f_capability_user_set() is not implemented and cannot be fully tested.\n"); @@ -29,7 +29,7 @@ void test__f_capability_user_set__works(void **state) { void test__f_capability_user_set__fails(void **state) { #if !defined(_di_libcap_) && !defined(_libcap_legacy_only_) - uid_t uid; + const uid_t uid = 0; int errnos[] = { EINVAL, diff --git a/level_0/f_capability/tests/c/test-capability-user_set.h b/level_0/f_capability/tests/c/test-capability-user_set.h index 44b9b6d..c48355f 100644 --- a/level_0/f_capability/tests/c/test-capability-user_set.h +++ b/level_0/f_capability/tests/c/test-capability-user_set.h @@ -11,17 +11,19 @@ #define _TEST__F_capability__user_set /** - * Test that function works. + * Test that function fails. * * @see f_capability_user_set() */ -extern void test__f_capability_user_set__works(void **state); +extern void test__f_capability_user_set__fails(void **state); + +// f_capability_user_set() doesn't use parameter checking. /** - * Test that function fails. + * Test that function works. * * @see f_capability_user_set() */ -extern void test__f_capability_user_set__fails(void **state); +extern void test__f_capability_user_set__works(void **state); #endif // _TEST__F_capability__user_set diff --git a/level_0/f_capability/tests/c/test-capability.c b/level_0/f_capability/tests/c/test-capability.c index 96d9e27..4a2dbe6 100644 --- a/level_0/f_capability/tests/c/test-capability.c +++ b/level_0/f_capability/tests/c/test-capability.c @@ -19,122 +19,164 @@ int setdown(void **state) { int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test__f_capability_ambient_get__works), cmocka_unit_test(test__f_capability_ambient_get__fails), + cmocka_unit_test(test__f_capability_ambient_get__works), - cmocka_unit_test(test__f_capability_ambient_reset__works), cmocka_unit_test(test__f_capability_ambient_reset__fails), + cmocka_unit_test(test__f_capability_ambient_reset__works), - cmocka_unit_test(test__f_capability_ambient_set__works), cmocka_unit_test(test__f_capability_ambient_set__fails), + cmocka_unit_test(test__f_capability_ambient_set__works), - cmocka_unit_test(test__f_capability_clear__works), cmocka_unit_test(test__f_capability_clear__fails), + cmocka_unit_test(test__f_capability_clear__works), - cmocka_unit_test(test__f_capability_clear_flag__works), cmocka_unit_test(test__f_capability_clear_flag__fails), + cmocka_unit_test(test__f_capability_clear_flag__works), - cmocka_unit_test(test__f_capability_compare__works), cmocka_unit_test(test__f_capability_compare__fails), + cmocka_unit_test(test__f_capability_compare__works), - cmocka_unit_test(test__f_capability_copy__works), cmocka_unit_test(test__f_capability_copy__fails), + cmocka_unit_test(test__f_capability_copy__works), - cmocka_unit_test(test__f_capability_copy_external__works), cmocka_unit_test(test__f_capability_copy_external__fails), + cmocka_unit_test(test__f_capability_copy_external__works), - cmocka_unit_test(test__f_capability_copy_internal__works), cmocka_unit_test(test__f_capability_copy_internal__fails), + cmocka_unit_test(test__f_capability_copy_internal__works), - cmocka_unit_test(test__f_capability_delete__works), cmocka_unit_test(test__f_capability_delete__fails), + cmocka_unit_test(test__f_capability_delete__works), - cmocka_unit_test(test__f_capability_file_descriptor_get__works), cmocka_unit_test(test__f_capability_file_descriptor_get__fails), + cmocka_unit_test(test__f_capability_file_descriptor_get__works), - cmocka_unit_test(test__f_capability_file_descriptor_set__works), cmocka_unit_test(test__f_capability_file_descriptor_set__fails), + cmocka_unit_test(test__f_capability_file_descriptor_set__works), - cmocka_unit_test(test__f_capability_file_get__works), cmocka_unit_test(test__f_capability_file_get__fails), + cmocka_unit_test(test__f_capability_file_get__works), - cmocka_unit_test(test__f_capability_file_set__works), cmocka_unit_test(test__f_capability_file_set__fails), + cmocka_unit_test(test__f_capability_file_set__works), - cmocka_unit_test(test__f_capability_flag_get__works), cmocka_unit_test(test__f_capability_flag_get__fails), + cmocka_unit_test(test__f_capability_flag_get__works), - cmocka_unit_test(test__f_capability_flag_set__works), cmocka_unit_test(test__f_capability_flag_set__fails), + cmocka_unit_test(test__f_capability_flag_set__works), - cmocka_unit_test(test__f_capability_from_name__works), cmocka_unit_test(test__f_capability_from_name__fails), + cmocka_unit_test(test__f_capability_from_name__works), - cmocka_unit_test(test__f_capability_from_text__works), cmocka_unit_test(test__f_capability_from_text__fails), + cmocka_unit_test(test__f_capability_from_text__works), - cmocka_unit_test(test__f_capability_groups_set__works), cmocka_unit_test(test__f_capability_groups_set__fails), + cmocka_unit_test(test__f_capability_groups_set__works), - cmocka_unit_test(test__f_capability_initialize__works), cmocka_unit_test(test__f_capability_initialize__fails), + cmocka_unit_test(test__f_capability_initialize__works), - cmocka_unit_test(test__f_capability_mode_get__works), // cap_get_mode() doesn't return failure. + cmocka_unit_test(test__f_capability_mode_get__works), - cmocka_unit_test(test__f_capability_mode_get_name__works), // cap_mode_name() doesn't return failure. + cmocka_unit_test(test__f_capability_mode_get_name__works), - cmocka_unit_test(test__f_capability_mode_set__works), cmocka_unit_test(test__f_capability_mode_set__fails), + cmocka_unit_test(test__f_capability_mode_set__works), - cmocka_unit_test(test__f_capability_owner_get__works), // cap_get_nsowner() doesn't return failure. + cmocka_unit_test(test__f_capability_owner_get__works), - cmocka_unit_test(test__f_capability_owner_set__works), cmocka_unit_test(test__f_capability_owner_set__fails), + cmocka_unit_test(test__f_capability_owner_set__works), - cmocka_unit_test(test__f_capability_process_bound_drop__works), cmocka_unit_test(test__f_capability_process_bound_drop__fails), + cmocka_unit_test(test__f_capability_process_bound_drop__works), - cmocka_unit_test(test__f_capability_process_bound_get__works), cmocka_unit_test(test__f_capability_process_bound_get__fails), + cmocka_unit_test(test__f_capability_process_bound_get__works), - cmocka_unit_test(test__f_capability_process_get_by_id__works), cmocka_unit_test(test__f_capability_process_get_by_id__fails), + cmocka_unit_test(test__f_capability_process_get_by_id__works), - cmocka_unit_test(test__f_capability_process_get__works), cmocka_unit_test(test__f_capability_process_get__fails), + cmocka_unit_test(test__f_capability_process_get__works), - cmocka_unit_test(test__f_capability_process_set__works), cmocka_unit_test(test__f_capability_process_set__fails), + cmocka_unit_test(test__f_capability_process_set__works), - cmocka_unit_test(test__f_capability_security_bits_get__works), cmocka_unit_test(test__f_capability_security_bits_get__fails), + cmocka_unit_test(test__f_capability_security_bits_get__works), - cmocka_unit_test(test__f_capability_security_bits_set__works), cmocka_unit_test(test__f_capability_security_bits_set__fails), + cmocka_unit_test(test__f_capability_security_bits_set__works), - cmocka_unit_test(test__f_capability_size__works), cmocka_unit_test(test__f_capability_size__fails), + cmocka_unit_test(test__f_capability_size__works), - cmocka_unit_test(test__f_capability_supported__works), // f_capability_supported() doesn't return failure. + cmocka_unit_test(test__f_capability_supported__works), - cmocka_unit_test(test__f_capability_supported_ambient__works), // f_capability_supported_ambient() doesn't return failure. + cmocka_unit_test(test__f_capability_supported_ambient__works), - cmocka_unit_test(test__f_capability_supported_code__works), // f_capability_supported_code() doesn't return failure. + cmocka_unit_test(test__f_capability_supported_code__works), - cmocka_unit_test(test__f_capability_to_name__works), cmocka_unit_test(test__f_capability_to_name__fails), + cmocka_unit_test(test__f_capability_to_name__works), - cmocka_unit_test(test__f_capability_to_text__works), cmocka_unit_test(test__f_capability_to_text__fails), + cmocka_unit_test(test__f_capability_to_text__works), - cmocka_unit_test(test__f_capability_user_set__works), cmocka_unit_test(test__f_capability_user_set__fails), + cmocka_unit_test(test__f_capability_user_set__works), + + #ifndef _di_level_0_parameter_checking_ + cmocka_unit_test(test__f_capability_ambient_get__parameter_checking), + // f_capability_ambient_reset() doesn't use parameter checking. + // f_capability_ambient_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_clear__parameter_checking), + cmocka_unit_test(test__f_capability_clear_flag__parameter_checking), + // f_capability_compare() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_copy__parameter_checking), + cmocka_unit_test(test__f_capability_copy_external__parameter_checking), + cmocka_unit_test(test__f_capability_copy_internal__parameter_checking), + cmocka_unit_test(test__f_capability_delete__parameter_checking), + cmocka_unit_test(test__f_capability_file_descriptor_get__parameter_checking), + // f_capability_file_descriptor_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_file_get__parameter_checking), + // f_capability_file_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_flag_get__parameter_checking), + cmocka_unit_test(test__f_capability_flag_set__parameter_checking), + cmocka_unit_test(test__f_capability_from_name__parameter_checking), + cmocka_unit_test(test__f_capability_from_text__parameter_checking), + // f_capability_groups_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_initialize__parameter_checking), + cmocka_unit_test(test__f_capability_mode_get__parameter_checking), + cmocka_unit_test(test__f_capability_mode_get_name__parameter_checking), + // f_capability_mode_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_owner_get__parameter_checking), + // f_capability_owner_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_process_bound_drop__parameter_checking), + cmocka_unit_test(test__f_capability_process_bound_get__parameter_checking), + cmocka_unit_test(test__f_capability_process_get_by_id__parameter_checking), + cmocka_unit_test(test__f_capability_process_get__parameter_checking), + // f_capability_process_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_security_bits_get__parameter_checking), + // f_capability_security_bits_set() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_size__parameter_checking), + // f_capability_supported() doesn't use parameter checking. + // f_capability_supported_ambient() doesn't use parameter checking. + // f_capability_supported_code() doesn't use parameter checking. + cmocka_unit_test(test__f_capability_to_name__parameter_checking), + cmocka_unit_test(test__f_capability_to_text__parameter_checking), + // f_capability_user_set() doesn't use parameter checking. + #endif // _di_level_0_parameter_checking_ }; return cmocka_run_group_tests(tests, setup, setdown); -- 1.8.3.1