80 lines
1.8 KiB
C
80 lines
1.8 KiB
C
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
#include "CUnit/Basic.h"
|
|
#include "timer_utils.h"
|
|
|
|
int init_suite1(void)
|
|
{
|
|
printf("init_suit1()");
|
|
return 0;
|
|
}
|
|
|
|
int clean_suite1(void)
|
|
{
|
|
printf("clean_suit1()");
|
|
return 0;
|
|
}
|
|
|
|
void test_add_time_1(void)
|
|
{
|
|
struct itimerspec test_time = {
|
|
.it_value = {
|
|
.tv_nsec = 0,
|
|
.tv_sec = 0}};
|
|
|
|
tmr_add_ns_to_current_time(&test_time, 1);
|
|
|
|
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()
|
|
{
|
|
CU_pSuite pSuite = NULL;
|
|
|
|
if (CUE_SUCCESS != CU_initialize_registry())
|
|
return CU_get_error();
|
|
|
|
pSuite = CU_add_suite("Suite_1", init_suite1, clean_suite1);
|
|
if (NULL == pSuite)
|
|
{
|
|
CU_cleanup_registry();
|
|
return CU_get_error();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
CU_basic_set_mode(CU_BRM_VERBOSE);
|
|
CU_basic_run_tests();
|
|
CU_cleanup_registry();
|
|
return CU_get_error();
|
|
} |