- memory allocation now works with allocator-functions...
[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 "allocator.h"
27 #include "tester.h"
28 #include "job_queue.h"
29 #include "event_queue.h"
30 #include "send_queue.h"
31 #include "socket.h"
32 #include "tests/linked_list_test.h"
33 #include "tests/thread_pool_test.h"
34 #include "tests/job_queue_test.h"
35 #include "tests/event_queue_test.h"
36 #include "tests/send_queue_test.h"
37 #include "tests/socket_test.h"
38 #include "tests/sender_test.h"
39 #include "tests/scheduler_test.h"
40 #include "tests/receiver_test.h"
41 #include "tests/ike_sa_id_test.h"
42 #include "tests/ike_sa_test.h"
43 #include "tests/generator_test.h"
44
45
46 /* output for test messages */
47 extern FILE * stderr;
48
49 /**
50 * Test for linked_list_t
51 */
52 test_t linked_list_test = {test_linked_list,"Linked List"};
53
54 /**
55 * Test for linked_list_t with iterator
56 */
57 test_t linked_list_iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
58
59 /**
60 * Test for linked_list_t insert and remove
61 */
62 test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
63
64 /**
65 * Test for event_queue_t
66 */
67 test_t event_queue_test = {test_event_queue,"Event-Queue"};
68
69 /**
70 * Test 1 for job_queue_t
71 */
72 test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
73
74 /**
75 * Test 1 for linked_list_t
76 */
77 test_t send_queue_test = {test_send_queue,"Send-Queue"};
78
79 /**
80 * Test for socket_t
81 */
82 test_t socket_test = {test_socket,"Socket"};
83
84 /**
85 * Test for thread_pool_t
86 */
87 test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
88
89 /**
90 * Test for sender_t
91 */
92 test_t sender_test = {test_sender,"Sender"};
93
94 /**
95 * Test for scheduler_t
96 */
97 test_t scheduler_test = {test_scheduler,"Scheduler"};
98
99 /**
100 * Test for receiver_t
101 */
102 test_t receiver_test = {test_receiver,"Receiver"};
103
104 /**
105 * Test for ike_sa_id_t
106 */
107 test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
108
109 /**
110 * Test for ike_sa_t
111 */
112 test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
113
114
115 /**
116 * Test for generator_t
117 */
118 test_t generator_test = {test_generator_with_unsupported_payload,"Generator: unsupported payload"};
119
120 /**
121 * Global job-queue
122 */
123 job_queue_t *global_job_queue;
124
125 /**
126 * Global event-queue
127 */
128 event_queue_t *global_event_queue;
129
130 /**
131 * Global send-queue
132 */
133 send_queue_t *global_send_queue;
134
135 /**
136 * Global socket
137 */
138 socket_t *global_socket;
139
140 int main()
141 {
142 FILE * test_output = stderr;
143
144 test_t *all_tests[] ={
145 &linked_list_test,
146 &linked_list_iterator_test,
147 &linked_list_insert_and_remove_test,
148 &thread_pool_test,
149 &job_queue_test1,
150 &event_queue_test,
151 &send_queue_test,
152 &scheduler_test,
153 &socket_test,
154 &sender_test,
155 &receiver_test,
156 &ike_sa_id_test,
157 &ike_sa_test,
158 &generator_test,
159 NULL
160 };
161
162 global_socket = socket_create(4600);
163
164 global_job_queue = job_queue_create();
165 global_event_queue = event_queue_create();
166 global_send_queue = send_queue_create();
167
168 tester_t *tester = tester_create(test_output, FALSE);
169
170 tester->perform_tests(tester,all_tests);
171 /* tester->perform_test(tester,&scheduler_test); */
172
173 tester->destroy(tester);
174
175 /* Destroy all queues */
176 global_job_queue->destroy(global_job_queue);
177 global_event_queue->destroy(global_event_queue);
178 global_send_queue->destroy(global_send_queue);
179
180 global_socket->destroy(global_socket);
181
182 #ifdef LEAK_DETECTIVE
183 /* Leaks are reported on stderr */
184 report_memory_leaks();
185 #endif
186
187 return 0;
188 }