]> git.proxmox.com Git - mirror_frr.git/blob - pceplib/test/pcep_timers_test.c
Merge pull request #8255 from pjdruddy/fix-ifindex-test
[mirror_frr.git] / pceplib / test / pcep_timers_test.c
1 /*
2 * This file is part of the PCEPlib, a PCEP protocol library.
3 *
4 * Copyright (C) 2020 Volta Networks https://voltanet.io/
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author : Brady Johnson <brady@voltanet.io>
20 *
21 */
22
23
24 #include <stdbool.h>
25 #include <CUnit/CUnit.h>
26
27 #include "pcep_timers.h"
28 #include "pcep_timers_test.h"
29
30 /* Test case teardown called after each test.
31 * Declared in pcep_timers_tests.c */
32 void pcep_timers_test_teardown()
33 {
34 teardown_timers();
35 }
36
37 static void test_timer_expire_handler(void *data, int timerId)
38 {
39 (void)data;
40 (void)timerId;
41 }
42
43
44 void test_double_initialization(void)
45 {
46 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
47 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), false);
48 }
49
50
51 void test_initialization_null_callback(void)
52 {
53 CU_ASSERT_EQUAL(initialize_timers(NULL), false);
54 }
55
56
57 void test_not_initialized(void)
58 {
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);
64 }
65
66
67 void test_create_timer(void)
68 {
69 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
70
71 int timer_id = create_timer(0, NULL);
72 CU_ASSERT_TRUE(timer_id > -1);
73 }
74
75
76 void test_cancel_timer(void)
77 {
78 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
79
80 int timer_id = create_timer(10, NULL);
81 CU_ASSERT_TRUE(timer_id > -1);
82
83 CU_ASSERT_EQUAL(cancel_timer(timer_id), true);
84 }
85
86
87 void test_cancel_timer_invalid(void)
88 {
89 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
90 CU_ASSERT_EQUAL(cancel_timer(1), false);
91 }
92
93
94 void test_reset_timer(void)
95 {
96 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
97
98 int timer_id = create_timer(10, NULL);
99 CU_ASSERT_TRUE(timer_id > -1);
100
101 CU_ASSERT_EQUAL(reset_timer(timer_id), true);
102 }
103
104
105 void test_reset_timer_invalid(void)
106 {
107 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
108 CU_ASSERT_EQUAL(reset_timer(1), false);
109 }