2 * This file is part of the PCEPlib, a PCEP protocol library.
4 * Copyright (C) 2020 Volta Networks https://voltanet.io/
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * Author : Brady Johnson <brady@voltanet.io>
29 #include <CUnit/CUnit.h>
31 #include "pcep_timers.h"
32 #include "pcep_timers_test.h"
34 /* Test case teardown called after each test.
35 * Declared in pcep_timers_tests.c */
36 void pcep_timers_test_teardown()
41 static void test_timer_expire_handler(void *data
, int timerId
)
48 void test_double_initialization(void)
50 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
51 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), false);
55 void test_initialization_null_callback(void)
57 CU_ASSERT_EQUAL(initialize_timers(NULL
), false);
61 void test_not_initialized(void)
63 /* All of these should fail if initialize_timers() hasnt been called */
64 CU_ASSERT_EQUAL(create_timer(5, NULL
), -1);
65 CU_ASSERT_EQUAL(cancel_timer(7), false);
66 CU_ASSERT_EQUAL(reset_timer(7), false);
67 CU_ASSERT_EQUAL(teardown_timers(), false);
71 void test_create_timer(void)
73 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
75 int timer_id
= create_timer(0, NULL
);
76 CU_ASSERT_TRUE(timer_id
> -1);
80 void test_cancel_timer(void)
82 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
84 int timer_id
= create_timer(10, NULL
);
85 CU_ASSERT_TRUE(timer_id
> -1);
87 CU_ASSERT_EQUAL(cancel_timer(timer_id
), true);
91 void test_cancel_timer_invalid(void)
93 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
94 CU_ASSERT_EQUAL(cancel_timer(1), false);
98 void test_reset_timer(void)
100 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
102 int timer_id
= create_timer(10, NULL
);
103 CU_ASSERT_TRUE(timer_id
> -1);
105 CU_ASSERT_EQUAL(reset_timer(timer_id
), true);
109 void test_reset_timer_invalid(void)
111 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
112 CU_ASSERT_EQUAL(reset_timer(1), false);