aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_http_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_http_common.c')
-rw-r--r--src/transport/test_http_common.c392
1 files changed, 374 insertions, 18 deletions
diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c
index 60aa3bfd3..05c4adb64 100644
--- a/src/transport/test_http_common.c
+++ b/src/transport/test_http_common.c
@@ -18,13 +18,8 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file transport/test_transport_api.c 21 * @file transport/test_http_common.c
22 * @brief base test case for transport implementations 22 * @brief base test case for common http functionality
23 *
24 * This test case serves as a base for tcp, udp, and udp-nat
25 * transport test cases. Based on the executable being run
26 * the correct test case will be performed. Conservation of
27 * C code apparently.
28 */ 23 */
29#include "platform.h" 24#include "platform.h"
30#include "gnunet_transport_service.h" 25#include "gnunet_transport_service.h"
@@ -33,10 +28,10 @@
33 28
34struct SplittedHTTPAddress 29struct SplittedHTTPAddress
35{ 30{
36 char *protocoll; 31 char *protocol;
37 char *host; 32 char *host;
38 char *port;
39 char *path; 33 char *path;
34 int port;
40}; 35};
41 36
42void 37void
@@ -46,25 +41,386 @@ clean (struct SplittedHTTPAddress *addr)
46 { 41 {
47 GNUNET_free_non_null (addr->host); 42 GNUNET_free_non_null (addr->host);
48 GNUNET_free_non_null (addr->path); 43 GNUNET_free_non_null (addr->path);
49 GNUNET_free_non_null (addr->port); 44 GNUNET_free_non_null (addr->protocol);
50 GNUNET_free_non_null (addr->protocoll);
51 GNUNET_free_non_null (addr); 45 GNUNET_free_non_null (addr);
52 } 46 }
53} 47}
54 48
49
50int
51check (struct SplittedHTTPAddress *addr,
52 char * protocol,
53 char * host,
54 int port,
55 char * path)
56{
57
58 if (NULL == addr)
59 return GNUNET_NO;
60 if (((NULL == addr->protocol) && (NULL != protocol)) ||
61 ((NULL != addr->protocol) && (NULL == protocol)))
62 {
63 GNUNET_break (0);
64 return GNUNET_NO;
65 }
66 else if ((NULL != addr->protocol) && (NULL != protocol))
67 {
68 if (0 != strcmp(addr->protocol, protocol))
69 {
70 GNUNET_break (0);
71 return GNUNET_NO;
72 }
73 }
74
75 if (((NULL == addr->host) && (NULL != host)) ||
76 ((NULL != addr->host) && (NULL == host)))
77 {
78 GNUNET_break (0);
79 return GNUNET_NO;
80 }
81 else if ((NULL != addr->host) && (NULL != host))
82 {
83 if (0 != strcmp(addr->host, host))
84 {
85 GNUNET_break (0);
86 return GNUNET_NO;
87 }
88 }
89
90
91 if (((NULL == addr->path) && (NULL != path)) ||
92 ((NULL != addr->path) && (NULL == path)))
93 {
94 GNUNET_break (0);
95 return GNUNET_NO;
96 }
97 else if ((NULL != addr->path) && (NULL != path))
98 {
99 if (0 != strcmp(addr->path, path))
100 {
101 GNUNET_break (0);
102 return GNUNET_NO;
103 }
104 }
105
106 if ((addr->port != port))
107 {
108 GNUNET_break (0);
109 return GNUNET_NO;
110 }
111
112 return GNUNET_OK;
113}
114
115void
116test_hostname ()
117{
118 struct SplittedHTTPAddress * spa;
119 spa = http_split_address ("http://test.local");
120 if (NULL == spa)
121 {
122 GNUNET_break (0);
123 }
124 else
125 {
126 if (GNUNET_OK != check(spa, "http", "test.local", HTTP_DEFAULT_PORT, ""))
127 {
128 GNUNET_break (0);
129 }
130 clean (spa);
131 }
132
133 spa = http_split_address ("http://test.local");
134 if (NULL == spa)
135 {
136 GNUNET_break (0);
137 }
138 else
139 {
140 if (GNUNET_OK != check(spa, "http", "test.local", HTTP_DEFAULT_PORT, ""))
141 {
142 GNUNET_break (0);
143 }
144 clean (spa);
145 }
146
147
148 spa = http_split_address ("http://test.local/");
149 if (NULL == spa)
150 {
151 GNUNET_break (0);
152 }
153 else
154 {
155 if (GNUNET_OK != check(spa, "http", "test.local", HTTP_DEFAULT_PORT, "/"))
156 {
157 GNUNET_break (0);
158 }
159 clean (spa);
160 }
161
162 spa = http_split_address ("http://test.local/path");
163 if (NULL == spa)
164 {
165 GNUNET_break (0);
166 }
167 else
168 {
169 if (GNUNET_OK != check(spa, "http", "test.local", HTTP_DEFAULT_PORT, "/path"))
170 {
171 GNUNET_break (0);
172 }
173 clean (spa);
174 }
175
176 spa = http_split_address ("http://test.local/path/");
177 if (NULL == spa)
178 {
179 GNUNET_break (0);
180 }
181 else
182 {
183 if (GNUNET_OK != check(spa, "http", "test.local", HTTP_DEFAULT_PORT, "/path/"))
184 {
185 GNUNET_break (0);
186 }
187 clean (spa);
188
189
190 }
191
192 spa = http_split_address ("http://test.local:1000/path/");
193 if (NULL == spa)
194 {
195 GNUNET_break (0);
196 }
197 else
198 {
199 if (GNUNET_OK != check(spa, "http", "test.local", 1000, "/path/"))
200 {
201 GNUNET_break (0);
202 }
203 clean (spa);
204 }
205}
206
207void
208test_ipv4 ()
209{
210 struct SplittedHTTPAddress * spa;
211 spa = http_split_address ("http://127.0.0.1");
212 if (NULL == spa)
213 {
214 GNUNET_break (0);
215 }
216 else
217 {
218 if (GNUNET_OK != check(spa, "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""))
219 {
220 GNUNET_break (0);
221 }
222 clean (spa);
223 }
224
225 spa = http_split_address ("http://127.0.0.1");
226 if (NULL == spa)
227 {
228 GNUNET_break (0);
229 }
230 else
231 {
232 if (GNUNET_OK != check(spa, "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""))
233 {
234 GNUNET_break (0);
235 }
236 clean (spa);
237 }
238
239
240 spa = http_split_address ("http://127.0.0.1/");
241 if (NULL == spa)
242 {
243 GNUNET_break (0);
244 }
245 else
246 {
247 if (GNUNET_OK != check(spa, "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"))
248 {
249 GNUNET_break (0);
250 }
251 clean (spa);
252 }
253
254 spa = http_split_address ("http://127.0.0.1/path");
255 if (NULL == spa)
256 {
257 GNUNET_break (0);
258 }
259 else
260 {
261 if (GNUNET_OK != check(spa, "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path"))
262 {
263 GNUNET_break (0);
264 }
265 clean (spa);
266 }
267
268 spa = http_split_address ("http://127.0.0.1/path/");
269 if (NULL == spa)
270 {
271 GNUNET_break (0);
272 }
273 else
274 {
275 if (GNUNET_OK != check(spa, "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/path/"))
276 {
277 GNUNET_break (0);
278 }
279 clean (spa);
280
281
282 }
283
284 spa = http_split_address ("http://127.0.0.1:1000/path/");
285 if (NULL == spa)
286 {
287 GNUNET_break (0);
288 }
289 else
290 {
291 if (GNUNET_OK != check(spa, "http", "127.0.0.1", 1000, "/path/"))
292 {
293 GNUNET_break (0);
294 }
295 clean (spa);
296 }
297}
298
299void
300test_ipv6 ()
301{
302 struct SplittedHTTPAddress * spa;
303 spa = http_split_address ("http://[::1]");
304 if (NULL == spa)
305 {
306 GNUNET_break (0);
307 }
308 else
309 {
310 if (GNUNET_OK != check(spa, "http", "[::1]", HTTP_DEFAULT_PORT, ""))
311 {
312 GNUNET_break (0);
313 }
314 clean (spa);
315 }
316
317 spa = http_split_address ("http://[::1]");
318 if (NULL == spa)
319 {
320 GNUNET_break (0);
321 }
322 else
323 {
324 if (GNUNET_OK != check(spa, "http", "[::1]", HTTP_DEFAULT_PORT, ""))
325 {
326 GNUNET_break (0);
327 }
328 clean (spa);
329 }
330
331
332 spa = http_split_address ("http://[::1]/");
333 if (NULL == spa)
334 {
335 GNUNET_break (0);
336 }
337 else
338 {
339 if (GNUNET_OK != check(spa, "http", "[::1]", HTTP_DEFAULT_PORT, "/"))
340 {
341 GNUNET_break (0);
342 }
343 clean (spa);
344 }
345
346 spa = http_split_address ("http://[::1]/path");
347 if (NULL == spa)
348 {
349 GNUNET_break (0);
350 }
351 else
352 {
353 if (GNUNET_OK != check(spa, "http", "[::1]", HTTP_DEFAULT_PORT, "/path"))
354 {
355 GNUNET_break (0);
356 }
357 clean (spa);
358 }
359
360 spa = http_split_address ("http://[::1]/path/");
361 if (NULL == spa)
362 {
363 GNUNET_break (0);
364 }
365 else
366 {
367 if (GNUNET_OK != check(spa, "http", "[::1]", HTTP_DEFAULT_PORT, "/path/"))
368 {
369 GNUNET_break (0);
370 }
371 clean (spa);
372
373
374 }
375
376 spa = http_split_address ("http://[::1]:1000/path/");
377 if (NULL == spa)
378 {
379 GNUNET_break (0);
380 }
381 else
382 {
383 if (GNUNET_OK != check(spa, "http", "[::1]", 1000, "/path/"))
384 {
385 GNUNET_break (0);
386 }
387 clean (spa);
388 }
389}
390
55int 391int
56main (int argc, char *argv[]) 392main (int argc, char *argv[])
57{ 393{
58 int ret = 0; 394 int ret = 0;
395 struct SplittedHTTPAddress * spa;
396 GNUNET_log_setup ("test", "DEBUG", NULL);
397
398 spa = http_split_address ("");
399 if (NULL != spa)
400 {
401 clean (spa);
402 GNUNET_break (0);
403 }
404
405 http_split_address ("http://");
406 if (NULL != spa)
407 {
408 clean (spa);
409 GNUNET_break (0);
410 }
411
412 http_split_address ("://");
413 if (NULL != spa)
414 {
415 clean (spa);
416 GNUNET_break (0);
417 }
59 418
60 clean(http_split_address ("")); 419 test_hostname ();
61 clean(http_split_address ("http://")); 420 test_ipv4 ();
62 clean(http_split_address ("http://test/path")); 421 test_ipv6 ();
63 clean(http_split_address ("http://test:8999/path"));
64 clean(http_split_address ("http://1.2.3.4:8999/path"));
65 clean(http_split_address ("http://1.2.3.4:8999"));
66 422
67 return ret; 423 return ret;
68} 424}
69 425
70/* end of test_transport_api.c */ 426/* end of test_http_common.c */