Add tests.

This commit is contained in:
Marco 2023-03-03 23:22:31 +01:00
parent d787da74bb
commit 91ace50878

View File

@ -16,18 +16,38 @@ int clean_suite1(void)
return 0; return 0;
} }
void test_tmr_add_ns_to_current_time(void) void test_add_time_1(void)
{ {
struct itimerspec test_time = { struct itimerspec test_time = {
.it_value = { .it_value = {
.tv_nsec = 0, .tv_nsec = 0,
.tv_sec = 0 .tv_sec = 0}};
}
};
tmr_add_ns_to_current_time(&test_time, 1); 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() int main()
@ -44,7 +64,10 @@ int main()
return CU_get_error(); 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(); CU_cleanup_registry();
return CU_get_error(); return CU_get_error();