f2b2bc03b61f79e60f2b2fc2507954101afd5aee
[strongswan.git] / Source / charon / testcases / testcases.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 "../queues/job_queue.h"
27 #include "../queues/event_queue.h"
28 #include "../queues/send_queue.h"
29 #include "../configuration_manager.h"
30 #include "../ike_sa_manager.h"
31 #include "../socket.h"
32 #include "../utils/logger_manager.h"
33 #include "../utils/allocator.h"
34 #include "../utils/tester.h"
35 #include "linked_list_test.h"
36 #include "thread_pool_test.h"
37 #include "job_queue_test.h"
38 #include "event_queue_test.h"
39 #include "send_queue_test.h"
40 #include "socket_test.h"
41 #include "sender_test.h"
42 #include "scheduler_test.h"
43 #include "receiver_test.h"
44 #include "ike_sa_id_test.h"
45 #include "ike_sa_test.h"
46 #include "ike_sa_manager_test.h"
47 #include "generator_test.h"
48 #include "parser_test.h"
49 #include "packet_test.h"
50 #include "diffie_hellman_test.h"
51
52
53 /* output for test messages */
54 extern FILE * stderr;
55
56 /**
57 * Test for linked_list_t
58 */
59 test_t linked_list_test = {test_linked_list,"Linked List"};
60
61 /**
62 * Test for linked_list_t with iterator
63 */
64 test_t linked_list_iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
65
66 /**
67 * Test for linked_list_t insert and remove
68 */
69 test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
70
71 /**
72 * Test for event_queue_t
73 */
74 test_t event_queue_test = {test_event_queue,"Event-Queue"};
75
76 /**
77 * Test 1 for job_queue_t
78 */
79 test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
80
81 /**
82 * Test 1 for linked_list_t
83 */
84 test_t send_queue_test = {test_send_queue,"Send-Queue"};
85
86 /**
87 * Test for socket_t
88 */
89 test_t socket_test = {test_socket,"Socket"};
90
91 /**
92 * Test for thread_pool_t
93 */
94 test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
95
96 /**
97 * Test for sender_t
98 */
99 test_t sender_test = {test_sender,"Sender"};
100
101 /**
102 * Test for scheduler_t
103 */
104 test_t scheduler_test = {test_scheduler,"Scheduler"};
105
106 /**
107 * Test for receiver_t
108 */
109 test_t receiver_test = {test_receiver,"Receiver"};
110
111 /**
112 * Test for ike_sa_id_t
113 */
114 test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
115
116 /**
117 * Test for ike_sa_t
118 */
119 test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
120
121
122 /**
123 * Test for ike_sa_manager_t
124 */
125 test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
126
127 test_t generator_test1 = {test_generator_with_header_payload,"Generator: header payload"};
128 test_t generator_test2 = {test_generator_with_transform_attribute,"Generator: transform attribute"};
129 test_t generator_test3 = {test_generator_with_transform_substructure,"Generator: transform substructure"};
130 test_t generator_test4 = {test_generator_with_proposal_substructure,"Generator: proposal substructure"};
131 test_t generator_test5 = {test_generator_with_sa_payload,"Generator: Message with SA Payload"};
132 test_t generator_test6 = {test_generator_with_ke_payload,"Generator: KE Payload"};
133 test_t generator_test7 = {test_generator_with_notify_payload,"Generator: Notify Payload"};
134 test_t generator_test8 = {test_generator_with_nonce_payload,"Generator: Nonce Payload"};
135
136
137 /**
138 * Parser test for ike header
139 */
140 test_t parser_test1 = {test_parser_with_header_payload, "Parser: header payload"};
141
142
143 /**
144 * Parser test for ike security association
145 */
146 test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"};
147
148 /**
149 * Parser test for ike nonce payload
150 */
151 test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"};
152
153 /**
154 * Parser test for ike nonce payload
155 */
156 test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payload"};
157
158 /**
159 * Parser test for ike notify payload
160 */
161 test_t parser_test5 = {test_parser_with_notify_payload, "Parser: notify payload"};
162
163
164 /**
165 * Test for packet_t
166 */
167 test_t packet_test = {test_packet,"Packet"};
168
169
170 /**
171 * Test for packet_t
172 */
173 test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"};
174
175
176 /**
177 * Global job-queue
178 */
179 job_queue_t *global_job_queue;
180
181 /**
182 * Global event-queue
183 */
184 event_queue_t *global_event_queue;
185
186 /**
187 * Global send-queue
188 */
189 send_queue_t *global_send_queue;
190
191 /**
192 * Global configuration_manager
193 */
194 configuration_manager_t *global_configuration_manager;
195
196 /**
197 * Global configuration_manager
198 */
199 ike_sa_manager_t *global_ike_sa_manager;
200
201 /**
202 * Global socket
203 */
204 socket_t *global_socket;
205
206
207 /**
208 * Global logger
209 */
210 logger_manager_t *global_logger_manager;
211
212 int main()
213 {
214 FILE * test_output = stderr;
215
216 test_t *all_tests[] ={
217 &linked_list_test,
218 &linked_list_iterator_test,
219 &linked_list_insert_and_remove_test,
220 &thread_pool_test,
221 &job_queue_test1,
222 &event_queue_test,
223 &send_queue_test,
224 &scheduler_test,
225 &socket_test,
226 &sender_test,
227 &receiver_test,
228 &ike_sa_id_test,
229 &ike_sa_test,
230 &generator_test1,
231 &generator_test2,
232 &parser_test1,
233 &parser_test2,
234 &parser_test3,
235 &parser_test4,
236 &parser_test5,
237 &generator_test3,
238 &generator_test4,
239 &generator_test5,
240 &generator_test6,
241 &generator_test7,
242 &generator_test8,
243 &ike_sa_manager_test,
244 &packet_test,
245 &diffie_hellman_test,
246 NULL
247 };
248 global_logger_manager = logger_manager_create(ALL);
249
250 global_socket = socket_create(4600);
251
252 global_job_queue = job_queue_create();
253 global_event_queue = event_queue_create();
254 global_send_queue = send_queue_create();
255 global_configuration_manager = configuration_manager_create();
256 global_ike_sa_manager = ike_sa_manager_create();
257
258 //global_logger_manager->disable_logger_level(global_logger_manager,TESTER,ALL);
259
260 tester_t *tester = tester_create(test_output, FALSE);
261
262
263 //tester->perform_tests(tester,all_tests);
264 tester->perform_test(tester,&diffie_hellman_test);
265
266
267
268 tester->destroy(tester);
269
270
271 /* Destroy all queues */
272 global_job_queue->destroy(global_job_queue);
273 global_event_queue->destroy(global_event_queue);
274 global_send_queue->destroy(global_send_queue);
275
276 global_socket->destroy(global_socket);
277
278 global_logger_manager->destroy(global_logger_manager);
279
280 #ifdef LEAK_DETECTIVE
281 /* Leaks are reported on stderr */
282 report_memory_leaks(void);
283 #endif
284
285 return 0;
286 }