- added parser test case for ike_header
[strongswan.git] / Source / charon / tests.c
1 /**
2 * @file tests.c
3 *
4 * @brief Main for all tests
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23
24 #include <stdio.h>
25
26 #include "logger.h"
27 #include "allocator.h"
28 #include "tester.h"
29 #include "job_queue.h"
30 #include "event_queue.h"
31 #include "send_queue.h"
32 #include "socket.h"
33 #include "tests/linked_list_test.h"
34 #include "tests/thread_pool_test.h"
35 #include "tests/job_queue_test.h"
36 #include "tests/event_queue_test.h"
37 #include "tests/send_queue_test.h"
38 #include "tests/socket_test.h"
39 #include "tests/sender_test.h"
40 #include "tests/scheduler_test.h"
41 #include "tests/receiver_test.h"
42 #include "tests/ike_sa_id_test.h"
43 #include "tests/ike_sa_test.h"
44 #include "tests/ike_sa_manager_test.h"
45 #include "tests/generator_test.h"
46 #include "tests/parser_test.h"
47 #include "tests/packet_test.h"
48
49
50 /* output for test messages */
51 extern FILE * stderr;
52
53 /**
54 * Test for linked_list_t
55 */
56 test_t linked_list_test = {test_linked_list,"Linked List"};
57
58 /**
59 * Test for linked_list_t with iterator
60 */
61 test_t linked_list_iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
62
63 /**
64 * Test for linked_list_t insert and remove
65 */
66 test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
67
68 /**
69 * Test for event_queue_t
70 */
71 test_t event_queue_test = {test_event_queue,"Event-Queue"};
72
73 /**
74 * Test 1 for job_queue_t
75 */
76 test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
77
78 /**
79 * Test 1 for linked_list_t
80 */
81 test_t send_queue_test = {test_send_queue,"Send-Queue"};
82
83 /**
84 * Test for socket_t
85 */
86 test_t socket_test = {test_socket,"Socket"};
87
88 /**
89 * Test for thread_pool_t
90 */
91 test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
92
93 /**
94 * Test for sender_t
95 */
96 test_t sender_test = {test_sender,"Sender"};
97
98 /**
99 * Test for scheduler_t
100 */
101 test_t scheduler_test = {test_scheduler,"Scheduler"};
102
103 /**
104 * Test for receiver_t
105 */
106 test_t receiver_test = {test_receiver,"Receiver"};
107
108 /**
109 * Test for ike_sa_id_t
110 */
111 test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
112
113 /**
114 * Test for ike_sa_t
115 */
116 test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
117
118
119 /**
120 * Test for ike_sa_manager_t
121 */
122 test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
123
124 /**
125 * Test for generator_t
126 */
127 test_t generator_test1 = {test_generator_with_unsupported_payload,"Generator: unsupported payload"};
128
129 /**
130 * Test 2 for generator_t
131 */
132 test_t generator_test2 = {test_generator_with_header_payload,"Generator: header payload"};
133
134 /**
135 * Test 2 for generator_t
136 */
137 test_t parser_test = {test_parser_with_header_payload, "Parser: header payload"};
138
139
140 /**
141 * Test for packet_t
142 */
143 test_t packet_test = {test_packet,"Packet"};
144
145
146 /**
147 * Global job-queue
148 */
149 job_queue_t *global_job_queue;
150
151 /**
152 * Global event-queue
153 */
154 event_queue_t *global_event_queue;
155
156 /**
157 * Global send-queue
158 */
159 send_queue_t *global_send_queue;
160
161 /**
162 * Global socket
163 */
164 socket_t *global_socket;
165
166
167 /**
168 * Global logger
169 */
170 logger_t *global_logger;
171
172 int main()
173 {
174 FILE * test_output = stderr;
175
176 test_t *all_tests[] ={
177 &linked_list_test,
178 &linked_list_iterator_test,
179 &linked_list_insert_and_remove_test,
180 &thread_pool_test,
181 &job_queue_test1,
182 &event_queue_test,
183 &send_queue_test,
184 &scheduler_test,
185 &socket_test,
186 &sender_test,
187 &receiver_test,
188 &ike_sa_id_test,
189 &ike_sa_test,
190 &generator_test1,
191 &generator_test2,
192 &parser_test,
193 &ike_sa_manager_test,
194 &packet_test,
195 NULL
196 };
197 global_logger = logger_create("Tester",ALL);
198
199 global_socket = socket_create(4600);
200
201 global_job_queue = job_queue_create();
202 global_event_queue = event_queue_create();
203 global_send_queue = send_queue_create();
204
205
206
207 tester_t *tester = tester_create(test_output, FALSE);
208
209 tester->perform_tests(tester,all_tests);
210 /*tester->perform_test(tester,&parser_test); */
211
212 tester->destroy(tester);
213
214
215 /* Destroy all queues */
216 global_job_queue->destroy(global_job_queue);
217 global_event_queue->destroy(global_event_queue);
218 global_send_queue->destroy(global_send_queue);
219
220 global_socket->destroy(global_socket);
221
222 global_logger->destroy(global_logger);
223
224 #ifdef LEAK_DETECTIVE
225 /* Leaks are reported on stderr */
226 report_memory_leaks(void);
227 #endif
228
229 return 0;
230 }