From 7daa0a5e405efe0ba056079e2d77975e0a17d6a0 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 16 Jan 2022 16:49:43 -0600 Subject: [PATCH] Update: Add parameter checking to unit tests and fix ordering. --- level_0/f_memory/tests/c/test-memory-adjust.c | 17 +++++++++++++++++ level_0/f_memory/tests/c/test-memory-adjust.h | 9 +++++++++ level_0/f_memory/tests/c/test-memory-delete.c | 11 +++++++++++ level_0/f_memory/tests/c/test-memory-delete.h | 9 +++++++++ level_0/f_memory/tests/c/test-memory-destroy.c | 11 +++++++++++ level_0/f_memory/tests/c/test-memory-destroy.h | 9 +++++++++ level_0/f_memory/tests/c/test-memory-new.c | 11 +++++++++++ level_0/f_memory/tests/c/test-memory-new.h | 9 +++++++++ level_0/f_memory/tests/c/test-memory-new_aligned.c | 11 +++++++++++ level_0/f_memory/tests/c/test-memory-new_aligned.h | 9 +++++++++ level_0/f_memory/tests/c/test-memory-resize.c | 17 +++++++++++++++++ level_0/f_memory/tests/c/test-memory-resize.h | 9 +++++++++ level_0/f_memory/tests/c/test-memory.c | 8 ++++++++ 13 files changed, 140 insertions(+) diff --git a/level_0/f_memory/tests/c/test-memory-adjust.c b/level_0/f_memory/tests/c/test-memory-adjust.c index fa6bb47..892e2d5 100644 --- a/level_0/f_memory/tests/c/test-memory-adjust.c +++ b/level_0/f_memory/tests/c/test-memory-adjust.c @@ -5,6 +5,23 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_memory_adjust__parameter_checking(void **state) { + + { + const f_status_t status = f_memory_adjust(1, 4, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + + { + const f_status_t status = f_memory_adjust(1, 4, 1, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_memory_adjust__works(void **state) { uint16_t *data = 0; diff --git a/level_0/f_memory/tests/c/test-memory-adjust.h b/level_0/f_memory/tests/c/test-memory-adjust.h index 63532d9..534080e 100644 --- a/level_0/f_memory/tests/c/test-memory-adjust.h +++ b/level_0/f_memory/tests/c/test-memory-adjust.h @@ -11,6 +11,15 @@ #define _TEST__F_memory__adjust /** + * Test that parameter checking works as expected. + * + * @see f_memory_adjust() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_memory_adjust__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** * Test that reallocation works. * * @see f_memory_new() diff --git a/level_0/f_memory/tests/c/test-memory-delete.c b/level_0/f_memory/tests/c/test-memory-delete.c index f2e538c..85ddd6a 100644 --- a/level_0/f_memory/tests/c/test-memory-delete.c +++ b/level_0/f_memory/tests/c/test-memory-delete.c @@ -95,6 +95,17 @@ void test__f_memory_delete__frees_resized_memory(void **state) { } } +#ifndef _di_level_0_parameter_checking_ + void test__f_memory_delete__parameter_checking(void **state) { + + { + const f_status_t status = f_memory_delete(4, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_memory/tests/c/test-memory-delete.h b/level_0/f_memory/tests/c/test-memory-delete.h index c78a5b1..fe9626c 100644 --- a/level_0/f_memory/tests/c/test-memory-delete.h +++ b/level_0/f_memory/tests/c/test-memory-delete.h @@ -44,4 +44,13 @@ extern void test__f_memory_delete__frees_memory(void **state); */ extern void test__f_memory_delete__frees_resized_memory(void **state); +/** + * Test that parameter checking works as expected. + * + * @see f_memory_delete() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_memory_delete__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + #endif // _TEST__F_memory__delete diff --git a/level_0/f_memory/tests/c/test-memory-destroy.c b/level_0/f_memory/tests/c/test-memory-destroy.c index cc6732f..75c3046 100644 --- a/level_0/f_memory/tests/c/test-memory-destroy.c +++ b/level_0/f_memory/tests/c/test-memory-destroy.c @@ -95,6 +95,17 @@ void test__f_memory_destroy__frees_resized_memory(void **state) { } } +#ifndef _di_level_0_parameter_checking_ + void test__f_memory_destroy__parameter_checking(void **state) { + + { + const f_status_t status = f_memory_destroy(4, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_memory/tests/c/test-memory-destroy.h b/level_0/f_memory/tests/c/test-memory-destroy.h index 4a57ce6..561aec2 100644 --- a/level_0/f_memory/tests/c/test-memory-destroy.h +++ b/level_0/f_memory/tests/c/test-memory-destroy.h @@ -44,4 +44,13 @@ extern void test__f_memory_destroy__frees_memory(void **state); */ extern void test__f_memory_destroy__frees_resized_memory(void **state); +/** + * Test that parameter checking works as expected. + * + * @see f_memory_destroy() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_memory_destroy__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + #endif // _TEST__F_memory__destroy diff --git a/level_0/f_memory/tests/c/test-memory-new.c b/level_0/f_memory/tests/c/test-memory-new.c index c52f195..257500e 100644 --- a/level_0/f_memory/tests/c/test-memory-new.c +++ b/level_0/f_memory/tests/c/test-memory-new.c @@ -5,6 +5,17 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_memory_new__parameter_checking(void **state) { + + { + const f_status_t status = f_memory_new(1, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_memory_new__works(void **state) { uint16_t *data = 0; diff --git a/level_0/f_memory/tests/c/test-memory-new.h b/level_0/f_memory/tests/c/test-memory-new.h index 08a2807..a3ab867 100644 --- a/level_0/f_memory/tests/c/test-memory-new.h +++ b/level_0/f_memory/tests/c/test-memory-new.h @@ -11,6 +11,15 @@ #define _TEST__F_memory__new /** + * Test that parameter checking works as expected. + * + * @see f_memory_new() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_memory_new__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** * Test that allocation works. * * @see f_memory_new() diff --git a/level_0/f_memory/tests/c/test-memory-new_aligned.c b/level_0/f_memory/tests/c/test-memory-new_aligned.c index 7849823..859727b 100644 --- a/level_0/f_memory/tests/c/test-memory-new_aligned.c +++ b/level_0/f_memory/tests/c/test-memory-new_aligned.c @@ -5,6 +5,17 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_memory_new_aligned__parameter_checking(void **state) { + + { + const f_status_t status = f_memory_new_aligned(1, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_memory_new_aligned__works(void **state) { uint16_t *data = 0; diff --git a/level_0/f_memory/tests/c/test-memory-new_aligned.h b/level_0/f_memory/tests/c/test-memory-new_aligned.h index a819b5a..9b520f6 100644 --- a/level_0/f_memory/tests/c/test-memory-new_aligned.h +++ b/level_0/f_memory/tests/c/test-memory-new_aligned.h @@ -11,6 +11,15 @@ #define _TEST__F_memory__new_aligned /** + * Test that parameter checking works as expected. + * + * @see f_memory_new_aligned() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_memory_new_aligned__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** * Test that allocation works. * * @see f_memory_new_aligned() diff --git a/level_0/f_memory/tests/c/test-memory-resize.c b/level_0/f_memory/tests/c/test-memory-resize.c index a0d77dc..8070bf0 100644 --- a/level_0/f_memory/tests/c/test-memory-resize.c +++ b/level_0/f_memory/tests/c/test-memory-resize.c @@ -5,6 +5,23 @@ extern "C" { #endif +#ifndef _di_level_0_parameter_checking_ + void test__f_memory_resize__parameter_checking(void **state) { + + { + const f_status_t status = f_memory_resize(1, 4, 0, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + + { + const f_status_t status = f_memory_resize(1, 4, 1, 0); + + assert_int_equal(F_status_set_fine(status), F_parameter); + } + } +#endif // _di_level_0_parameter_checking_ + void test__f_memory_resize__works(void **state) { uint16_t *data = 0; diff --git a/level_0/f_memory/tests/c/test-memory-resize.h b/level_0/f_memory/tests/c/test-memory-resize.h index fc91c53..58efe23 100644 --- a/level_0/f_memory/tests/c/test-memory-resize.h +++ b/level_0/f_memory/tests/c/test-memory-resize.h @@ -11,6 +11,15 @@ #define _TEST__F_memory__resize /** + * Test that parameter checking works as expected. + * + * @see f_memory_resize() + */ +#ifndef _di_level_0_parameter_checking_ + extern void test__f_memory_resize__parameter_checking(void **state); +#endif // _di_level_0_parameter_checking_ + +/** * Test that reallocation works. * * @see f_memory_new() diff --git a/level_0/f_memory/tests/c/test-memory.c b/level_0/f_memory/tests/c/test-memory.c index 9d868c6..e45960e 100644 --- a/level_0/f_memory/tests/c/test-memory.c +++ b/level_0/f_memory/tests/c/test-memory.c @@ -33,6 +33,14 @@ int main(void) { cmocka_unit_test(test__f_memory_new_aligned__works), cmocka_unit_test(test__f_memory_resize__works), + + #ifndef _di_level_0_parameter_checking_ + cmocka_unit_test(test__f_memory_adjust__parameter_checking), + cmocka_unit_test(test__f_memory_delete__parameter_checking), + cmocka_unit_test(test__f_memory_destroy__parameter_checking), + cmocka_unit_test(test__f_memory_new__parameter_checking), + cmocka_unit_test(test__f_memory_resize__parameter_checking), + #endif // _di_level_0_parameter_checking_ }; return cmocka_run_group_tests(tests, setup, setdown); -- 1.8.3.1