68575f730ddebedc17186b37b1ebd33a8c28c67d
[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
47
48 /* output for test messages */
49 extern FILE * stderr;
50
51 /**
52 * Test for linked_list_t
53 */
54 test_t linked_list_test = {test_linked_list,"Linked List"};
55
56 /**
57 * Test for linked_list_t with iterator
58 */
59 test_t linked_list_iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
60
61 /**
62 * Test for linked_list_t insert and remove
63 */
64 test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
65
66 /**
67 * Test for event_queue_t
68 */
69 test_t event_queue_test = {test_event_queue,"Event-Queue"};
70
71 /**
72 * Test 1 for job_queue_t
73 */
74 test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
75
76 /**
77 * Test 1 for linked_list_t
78 */
79 test_t send_queue_test = {test_send_queue,"Send-Queue"};
80
81 /**
82 * Test for socket_t
83 */
84 test_t socket_test = {test_socket,"Socket"};
85
86 /**
87 * Test for thread_pool_t
88 */
89 test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
90
91 /**
92 * Test for sender_t
93 */
94 test_t sender_test = {test_sender,"Sender"};
95
96 /**
97 * Test for scheduler_t
98 */
99 test_t scheduler_test = {test_scheduler,"Scheduler"};
100
101 /**
102 * Test for receiver_t
103 */
104 test_t receiver_test = {test_receiver,"Receiver"};
105
106 /**
107 * Test for ike_sa_id_t
108 */
109 test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
110
111 /**
112 * Test for ike_sa_t
113 */
114 test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
115
116
117 /**
118 * Test for ike_sa_manager_t
119 */
120 test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
121
122 /**
123 * Test for generator_t
124 */
125 test_t generator_test1 = {test_generator_with_unsupported_payload,"Generator: unsupported payload"};
126
127 /**
128 * Test 2 for generator_t
129 */
130 test_t generator_test2 = {test_generator_with_header_payload,"Generator: header payload"};
131
132 /**
133 * Global job-queue
134 */
135 job_queue_t *global_job_queue;
136
137 /**
138 * Global event-queue
139 */
140 event_queue_t *global_event_queue;
141
142 /**
143 * Global send-queue
144 */
145 send_queue_t *global_send_queue;
146
147 /**
148 * Global socket
149 */
150 socket_t *global_socket;
151
152
153 /**
154 * Global logger
155 */
156 logger_t *global_logger;
157
158 int main()
159 {
160 FILE * test_output = stderr;
161
162 test_t *all_tests[] ={
163 &linked_list_test,
164 &linked_list_iterator_test,
165 &linked_list_insert_and_remove_test,
166 &thread_pool_test,
167 &job_queue_test1,
168 &event_queue_test,
169 &send_queue_test,
170 &scheduler_test,
171 &socket_test,
172 &sender_test,
173 &receiver_test,
174 &ike_sa_id_test,
175 &ike_sa_test,
176 &generator_test1,
177 &generator_test2,
178 &ike_sa_manager_test,
179 NULL
180 };
181 global_logger = logger_create("Tester",ALL);
182
183 global_socket = socket_create(4600);
184
185 global_job_queue = job_queue_create();
186 global_event_queue = event_queue_create();
187 global_send_queue = send_queue_create();
188
189
190
191 tester_t *tester = tester_create(test_output, FALSE);
192
193 tester->perform_tests(tester,all_tests);
194 /* tester->perform_test(tester,&generator_test2); */
195
196 tester->destroy(tester);
197
198
199 /* Destroy all queues */
200 global_job_queue->destroy(global_job_queue);
201 global_event_queue->destroy(global_event_queue);
202 global_send_queue->destroy(global_send_queue);
203
204 global_socket->destroy(global_socket);
205
206 global_logger->destroy(global_logger);
207
208 #ifdef LEAK_DETECTIVE
209 /* Leaks are reported on stderr */
210 report_memory_leaks();
211 #endif
212
213 return 0;
214 }