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>
25 #include <CUnit/CUnit.h>
27 #include "pcep_timers.h"
28 #include "pcep_timers_test.h"
30 /* Test case teardown called after each test.
31 * Declared in pcep_timers_tests.c */
32 void pcep_timers_test_teardown()
37 static void test_timer_expire_handler(void *data
, int timerId
)
44 void test_double_initialization(void)
46 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
47 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), false);
51 void test_initialization_null_callback(void)
53 CU_ASSERT_EQUAL(initialize_timers(NULL
), false);
57 void test_not_initialized(void)
59 /* All of these should fail if initialize_timers() hasnt been called */
60 CU_ASSERT_EQUAL(create_timer(5, NULL
), -1);
61 CU_ASSERT_EQUAL(cancel_timer(7), false);
62 CU_ASSERT_EQUAL(reset_timer(7), false);
63 CU_ASSERT_EQUAL(teardown_timers(), false);
67 void test_create_timer(void)
69 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
71 int timer_id
= create_timer(0, NULL
);
72 CU_ASSERT_TRUE(timer_id
> -1);
76 void test_cancel_timer(void)
78 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
80 int timer_id
= create_timer(10, NULL
);
81 CU_ASSERT_TRUE(timer_id
> -1);
83 CU_ASSERT_EQUAL(cancel_timer(timer_id
), true);
87 void test_cancel_timer_invalid(void)
89 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
90 CU_ASSERT_EQUAL(cancel_timer(1), false);
94 void test_reset_timer(void)
96 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
98 int timer_id
= create_timer(10, NULL
);
99 CU_ASSERT_TRUE(timer_id
> -1);
101 CU_ASSERT_EQUAL(reset_timer(timer_id
), true);
105 void test_reset_timer_invalid(void)
107 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler
), true);
108 CU_ASSERT_EQUAL(reset_timer(1), false);