]> git.proxmox.com Git - mirror_frr.git/blob - pceplib/test/pcep_timers_test.c
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <stdbool.h>
29 #include <CUnit/CUnit.h>
30
31 #include "pcep_timers.h"
32 #include "pcep_timers_test.h"
33
34 /* Test case teardown called after each test.
35 * Declared in pcep_timers_tests.c */
36 void pcep_timers_test_teardown()
37 {
38 teardown_timers();
39 }
40
41 static void test_timer_expire_handler(void *data, int timerId)
42 {
43 (void)data;
44 (void)timerId;
45 }
46
47
48 void test_double_initialization(void)
49 {
50 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
51 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), false);
52 }
53
54
55 void test_initialization_null_callback(void)
56 {
57 CU_ASSERT_EQUAL(initialize_timers(NULL), false);
58 }
59
60
61 void test_not_initialized(void)
62 {
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);
68 }
69
70
71 void test_create_timer(void)
72 {
73 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
74
75 int timer_id = create_timer(0, NULL);
76 CU_ASSERT_TRUE(timer_id > -1);
77 }
78
79
80 void test_cancel_timer(void)
81 {
82 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
83
84 int timer_id = create_timer(10, NULL);
85 CU_ASSERT_TRUE(timer_id > -1);
86
87 CU_ASSERT_EQUAL(cancel_timer(timer_id), true);
88 }
89
90
91 void test_cancel_timer_invalid(void)
92 {
93 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
94 CU_ASSERT_EQUAL(cancel_timer(1), false);
95 }
96
97
98 void test_reset_timer(void)
99 {
100 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
101
102 int timer_id = create_timer(10, NULL);
103 CU_ASSERT_TRUE(timer_id > -1);
104
105 CU_ASSERT_EQUAL(reset_timer(timer_id), true);
106 }
107
108
109 void test_reset_timer_invalid(void)
110 {
111 CU_ASSERT_EQUAL(initialize_timers(test_timer_expire_handler), true);
112 CU_ASSERT_EQUAL(reset_timer(1), false);
113 }