From 91ace50878a31fd0138d1b1d6dfecaf3c4dd9eaf Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 3 Mar 2023 23:22:31 +0100 Subject: [PATCH] Add tests. --- test/test_timer_utils.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/test/test_timer_utils.c b/test/test_timer_utils.c index a403e09..32054c3 100644 --- a/test/test_timer_utils.c +++ b/test/test_timer_utils.c @@ -16,18 +16,38 @@ int clean_suite1(void) return 0; } -void test_tmr_add_ns_to_current_time(void) +void test_add_time_1(void) { struct itimerspec test_time = { .it_value = { .tv_nsec = 0, - .tv_sec = 0 - } - }; + .tv_sec = 0}}; tmr_add_ns_to_current_time(&test_time, 1); - - CU_ASSERT(test_time.it_value.tv_nsec == 2); + + CU_ASSERT(test_time.it_value.tv_nsec == 1); +} + +void test_add_time_2(void) +{ + struct itimerspec test_time = { + .it_value = { + .tv_nsec = 999999999, + .tv_sec = 0}}; + tmr_add_ns_to_current_time(&test_time, 1); + CU_ASSERT(test_time.it_value.tv_sec == 1); + CU_ASSERT(test_time.it_value.tv_nsec == 0); +} + +void test_add_time_3(void) +{ + struct itimerspec test_time = { + .it_value = { + .tv_nsec = 999999999, + .tv_sec = 0}}; + tmr_add_ns_to_current_time(&test_time, 1000); + CU_ASSERT(test_time.it_value.tv_sec == 1); + CU_ASSERT(test_time.it_value.tv_nsec == 999); } int main() @@ -44,7 +64,10 @@ int main() return CU_get_error(); } - if ((NULL == CU_add_test(pSuite, "test of fprintf()", test_tmr_add_ns_to_current_time))) + if ((NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_1)) || + (NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_2))|| + (NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_3))|| + (NULL == CU_add_test(pSuite, "test if time is added correctly with tmr_add_ns_to_current_time()", test_add_time_2))) { CU_cleanup_registry(); return CU_get_error();