host: Ignore spaces around - when parsing ranges
[strongswan.git] / src / libstrongswan / tests / suites / test_host.c
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "test_suite.h"
17
18 #include <networking/host.h>
19
20 /**
21 * Verify a netmask (a number of set bits starting at byte 0)
22 * Can also be used to check for %any (mask == 0)
23 */
24 static void verify_netmask(chunk_t addr, int mask)
25 {
26 int byte, bit;
27
28 for (byte = 0; byte < addr.len; byte++)
29 {
30 for (bit = 7; bit >= 0; bit--)
31 {
32 int val = (addr.ptr[byte] >> bit) & 0x01;
33 if (mask-- > 0)
34 {
35 ck_assert_int_eq(val, 1);
36 }
37 else
38 {
39 ck_assert_int_eq(val, 0);
40 }
41 }
42 }
43 }
44
45 /*******************************************************************************
46 * host_create_any
47 */
48
49 static void verify_any(host_t *host, int family, u_int16_t port)
50 {
51 verify_netmask(host->get_address(host), 0);
52 ck_assert(host->is_anyaddr(host));
53 ck_assert_int_eq(host->get_port(host), port);
54 ck_assert_int_eq(host->get_family(host), family);
55 }
56
57 static void test_create_any(int family)
58 {
59 host_t *host;
60
61 host = host_create_any(family);
62 verify_any(host, family, 0);
63 host->destroy(host);
64 }
65
66 START_TEST(test_create_any_v4)
67 {
68 test_create_any(AF_INET);
69 }
70 END_TEST
71
72 START_TEST(test_create_any_v6)
73 {
74 test_create_any(AF_INET6);
75 }
76 END_TEST
77
78 START_TEST(test_create_any_other)
79 {
80 host_t *host;
81
82 host = host_create_any(AF_UNSPEC);
83 ck_assert(host == NULL);
84 }
85 END_TEST
86
87 /*******************************************************************************
88 * host_create_from_string
89 */
90
91 static void verify_address(host_t *host, chunk_t addr, int family, u_int16_t port)
92 {
93 ck_assert(chunk_equals(host->get_address(host), addr));
94 ck_assert(!host->is_anyaddr(host));
95 ck_assert_int_eq(host->get_port(host), port);
96 ck_assert_int_eq(host->get_family(host), family);
97 }
98
99 static const chunk_t addr_v4 = chunk_from_chars(0xc0, 0xa8, 0x00, 0x01);
100 static const chunk_t addr_v6 = chunk_from_chars(0xfe, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01);
102
103 START_TEST(test_create_from_string_v4)
104 {
105 host_t *host;
106
107 host = host_create_from_string("%any", 500);
108 verify_any(host, AF_INET, 500);
109 host->destroy(host);
110
111 host = host_create_from_string("%any4", 500);
112 verify_any(host, AF_INET, 500);
113 host->destroy(host);
114
115 host = host_create_from_string("0.0.0.0", 500);
116 verify_any(host, AF_INET, 500);
117 host->destroy(host);
118
119 host = host_create_from_string("192.168.0.1", 500);
120 verify_address(host, addr_v4, AF_INET, 500);
121 host->destroy(host);
122
123 host = host_create_from_string("192.168.0.1::500", 500);
124 ck_assert(host == NULL);
125 host = host_create_from_string("123.456.789.012", 500);
126 ck_assert(host == NULL);
127 host = host_create_from_string("1.1.1.1.1.1.1.1", 500);
128 ck_assert(host == NULL);
129 host = host_create_from_string("foo.b.a.r", 500);
130 ck_assert(host == NULL);
131 }
132 END_TEST
133
134 START_TEST(test_create_from_string_any_v6)
135 {
136 host_t *host;
137
138 host = host_create_from_string("%any6", 500);
139 verify_any(host, AF_INET6, 500);
140 host->destroy(host);
141
142 host = host_create_from_string("::", 500);
143 verify_any(host, AF_INET6, 500);
144 host->destroy(host);
145
146 host = host_create_from_string("fec1::1", 500);
147 verify_address(host, addr_v6, AF_INET6, 500);
148 host->destroy(host);
149
150 host = host_create_from_string("fec1::1.500", 500);
151 ck_assert(host == NULL);
152 host = host_create_from_string("f::e::c::1::1", 500);
153 ck_assert(host == NULL);
154 host = host_create_from_string("foo::bar", 500);
155 ck_assert(host == NULL);
156 }
157 END_TEST
158
159 /*******************************************************************************
160 * host_create_from_string_and_family
161 */
162
163 static void test_create_from_string_and_family_any(char *string, int family,
164 int expected)
165 {
166 host_t *host;
167
168 host = host_create_from_string_and_family(string, family, 500);
169 if (expected == AF_UNSPEC)
170 {
171 ck_assert(host == NULL);
172 }
173 else
174 {
175 verify_any(host, expected, 500);
176 host->destroy(host);
177 }
178 }
179
180 static void test_create_from_string_and_family_addr(char *string, chunk_t addr,
181 int family, int expected)
182 {
183 host_t *host;
184
185 host = host_create_from_string_and_family(string, family, 500);
186 if (expected == AF_UNSPEC)
187 {
188 ck_assert(host == NULL);
189 }
190 else
191 {
192 verify_address(host, addr, expected, 500);
193 host->destroy(host);
194 }
195 }
196
197 START_TEST(test_create_from_string_and_family_v4)
198 {
199 test_create_from_string_and_family_any("%any", AF_INET, AF_INET);
200 test_create_from_string_and_family_any("%any4", AF_INET, AF_INET);
201 test_create_from_string_and_family_any("0.0.0.0", AF_INET, AF_INET);
202
203 test_create_from_string_and_family_any("%any4", AF_INET6, AF_UNSPEC);
204 test_create_from_string_and_family_any("0.0.0.0", AF_INET6, AF_UNSPEC);
205
206 test_create_from_string_and_family_addr("192.168.0.1", addr_v4, AF_INET, AF_INET);
207 test_create_from_string_and_family_addr("192.168.0.1", addr_v4, AF_INET6, AF_UNSPEC);
208 }
209 END_TEST
210
211 START_TEST(test_create_from_string_and_family_v6)
212 {
213 test_create_from_string_and_family_any("%any", AF_INET6, AF_INET6);
214 test_create_from_string_and_family_any("%any6", AF_INET6, AF_INET6);
215 test_create_from_string_and_family_any("::", AF_INET6, AF_INET6);
216
217 test_create_from_string_and_family_any("%any6", AF_INET, AF_UNSPEC);
218 test_create_from_string_and_family_any("::", AF_INET, AF_UNSPEC);
219
220 test_create_from_string_and_family_addr("fec1::1", addr_v6, AF_INET6, AF_INET6);
221 test_create_from_string_and_family_addr("fec1::1", addr_v6, AF_INET, AF_UNSPEC);
222 }
223 END_TEST
224
225 START_TEST(test_create_from_string_and_family_other)
226 {
227 test_create_from_string_and_family_any("%any", AF_UNSPEC, AF_INET);
228 test_create_from_string_and_family_any("%any4", AF_UNSPEC, AF_INET);
229 test_create_from_string_and_family_any("0.0.0.0", AF_UNSPEC, AF_INET);
230
231 test_create_from_string_and_family_any("%any6", AF_UNSPEC, AF_INET6);
232 test_create_from_string_and_family_any("::", AF_UNSPEC, AF_INET6);
233
234 test_create_from_string_and_family_addr("192.168.0.1", addr_v4, AF_UNSPEC, AF_INET);
235 test_create_from_string_and_family_addr("fec1::1", addr_v6, AF_UNSPEC, AF_INET6);
236 }
237 END_TEST
238
239 /*******************************************************************************
240 * host_create_from_sockaddr
241 */
242
243 START_TEST(test_create_from_sockaddr_v4)
244 {
245 struct sockaddr_in addr = {
246 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
247 .sin_len = sizeof(struct sockaddr_in),
248 #endif
249 .sin_family = AF_INET,
250 .sin_port = htons(500),
251 }, *val;
252 socklen_t *socklen;
253 host_t *host;
254
255 host = host_create_from_sockaddr((sockaddr_t*)&addr);
256 verify_any(host, AF_INET, 500);
257 val = (struct sockaddr_in*)host->get_sockaddr(host);
258 ck_assert(memeq(&addr, val, sizeof(addr)));
259 socklen = host->get_sockaddr_len(host);
260 ck_assert(*socklen == sizeof(addr));
261 host->destroy(host);
262 }
263 END_TEST
264
265 START_TEST(test_create_from_sockaddr_v6)
266 {
267 struct sockaddr_in6 addr = {
268 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
269 .sin6_len = sizeof(struct sockaddr_in6),
270 #endif
271 .sin6_family = AF_INET6,
272 .sin6_port = htons(500),
273 }, *val;
274 socklen_t *socklen;
275 host_t *host;
276
277 host = host_create_from_sockaddr((sockaddr_t*)&addr);
278 verify_any(host, AF_INET6, 500);
279 val = (struct sockaddr_in6*)host->get_sockaddr(host);
280 ck_assert(memeq(&addr, val, sizeof(addr)));
281 socklen = host->get_sockaddr_len(host);
282 ck_assert(*socklen == sizeof(addr));
283 host->destroy(host);
284 }
285 END_TEST
286
287 START_TEST(test_create_from_sockaddr_other)
288 {
289 struct sockaddr addr = {
290 .sa_family = AF_UNIX,
291 };
292 host_t *host;
293
294 host = host_create_from_sockaddr((sockaddr_t*)&addr);
295 ck_assert(host == NULL);
296 }
297 END_TEST
298
299 /*******************************************************************************
300 * host_create_from_chunk
301 */
302
303 START_TEST(test_create_from_chunk_v4)
304 {
305 host_t *host;
306
307 host = host_create_from_chunk(AF_INET, addr_v4, 500);
308 verify_address(host, addr_v4, AF_INET, 500);
309 host->destroy(host);
310
311 host = host_create_from_chunk(AF_UNSPEC, addr_v4, 500);
312 verify_address(host, addr_v4, AF_INET, 500);
313 host->destroy(host);
314
315 host = host_create_from_chunk(AF_INET, chunk_empty, 500);
316 ck_assert(host == NULL);
317 host = host_create_from_chunk(AF_UNSPEC, chunk_empty, 500);
318 ck_assert(host == NULL);
319 }
320 END_TEST
321
322 START_TEST(test_create_from_chunk_v6)
323 {
324 host_t *host;
325
326 host = host_create_from_chunk(AF_INET6, addr_v6, 500);
327 verify_address(host, addr_v6, AF_INET6, 500);
328 host->destroy(host);
329
330 host = host_create_from_chunk(AF_UNSPEC, addr_v6, 500);
331 verify_address(host, addr_v6, AF_INET6, 500);
332 host->destroy(host);
333
334 host = host_create_from_chunk(AF_INET6, chunk_empty, 500);
335 ck_assert(host == NULL);
336 }
337 END_TEST
338
339 START_TEST(test_create_from_chunk_other)
340 {
341 host_t *host;
342
343 host = host_create_from_chunk(AF_UNIX, addr_v6, 500);
344 ck_assert(host == NULL);
345 }
346 END_TEST
347
348 /*******************************************************************************
349 * host_create_from_subnet
350 */
351
352 START_TEST(test_create_from_subnet_v4)
353 {
354 host_t *host;
355 int bits = -1;
356
357 host = host_create_from_subnet("0.0.0.0/0", &bits);
358 verify_any(host, AF_INET, 0);
359 ck_assert_int_eq(bits, 0);
360 host->destroy(host);
361
362 host = host_create_from_subnet("192.168.0.1", &bits);
363 verify_address(host, addr_v4, AF_INET, 0);
364 ck_assert_int_eq(bits, 32);
365 host->destroy(host);
366
367 host = host_create_from_subnet("192.168.0.1/24", &bits);
368 verify_address(host, addr_v4, AF_INET, 0);
369 ck_assert_int_eq(bits, 24);
370 host->destroy(host);
371
372 host = host_create_from_subnet("foo.b.a.r", &bits);
373 ck_assert(host == NULL);
374 }
375 END_TEST
376
377 START_TEST(test_create_from_subnet_v6)
378 {
379 host_t *host;
380 int bits = -1;
381
382 host = host_create_from_subnet("::/0", &bits);
383 verify_any(host, AF_INET6, 0);
384 ck_assert_int_eq(bits, 0);
385 host->destroy(host);
386
387 host = host_create_from_subnet("fec1::1", &bits);
388 verify_address(host, addr_v6, AF_INET6, 0);
389 ck_assert_int_eq(bits, 128);
390 host->destroy(host);
391
392 host = host_create_from_subnet("fec1::1/64", &bits);
393 verify_address(host, addr_v6, AF_INET6, 0);
394 ck_assert_int_eq(bits, 64);
395 host->destroy(host);
396
397 host = host_create_from_subnet("foo::bar", &bits);
398 ck_assert(host == NULL);
399 }
400 END_TEST
401
402 /*******************************************************************************
403 * host_create_from_range
404 */
405
406 static const chunk_t addr_v4_to = chunk_from_chars(0xc0, 0xa8, 0x00, 0x05);
407 static const chunk_t addr_v6_to = chunk_from_chars(0xfe, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05);
409
410 static void verify_range(char *str, int family, chunk_t from_addr,
411 chunk_t to_addr)
412 {
413 host_t *from, *to;
414
415 if (!family)
416 {
417 ck_assert(!host_create_from_range(str, &from, &to));
418 }
419 else
420 {
421 ck_assert(host_create_from_range(str, &from, &to));
422 verify_address(from, from_addr, family, 0);
423 verify_address(to, to_addr, family, 0);
424 from->destroy(from);
425 to->destroy(to);
426 }
427 }
428
429 START_TEST(test_create_from_range_v4)
430 {
431 host_t *from, *to;
432
433 ck_assert(host_create_from_range("0.0.0.0-0.0.0.0", &from, &to));
434 verify_any(from, AF_INET, 0);
435 verify_any(to, AF_INET, 0);
436 from->destroy(from);
437 to->destroy(to);
438
439 verify_range("192.168.0.1-192.168.0.1", AF_INET, addr_v4, addr_v4);
440 verify_range("192.168.0.1-192.168.0.5", AF_INET, addr_v4, addr_v4_to);
441 verify_range("192.168.0.1- 192.168.0.5", AF_INET, addr_v4, addr_v4_to);
442 verify_range("192.168.0.1 -192.168.0.5", AF_INET, addr_v4, addr_v4_to);
443 verify_range("192.168.0.1 - 192.168.0.5", AF_INET, addr_v4, addr_v4_to);
444 verify_range("192.168.0.5-192.168.0.1", AF_INET, addr_v4_to, addr_v4);
445
446 verify_range("192.168.0.1", 0, chunk_empty, chunk_empty);
447 verify_range("192.168.0.1-", 0, chunk_empty, chunk_empty);
448 verify_range("-192.168.0.1", 0, chunk_empty, chunk_empty);
449 verify_range("192.168.0.1-192", 0, chunk_empty, chunk_empty);
450 verify_range("192.168.0.1-192.168", 0, chunk_empty, chunk_empty);
451 verify_range("192.168.0.1-192.168.0", 0, chunk_empty, chunk_empty);
452 verify_range("foo.b.a.r", 0, chunk_empty, chunk_empty);
453 verify_range("foo.b.a.r-b.a.r.f", 0, chunk_empty, chunk_empty);
454 }
455 END_TEST
456
457 START_TEST(test_create_from_range_v6)
458 {
459 host_t *from, *to;
460
461 ck_assert(host_create_from_range("::-::", &from, &to));
462 verify_any(from, AF_INET6, 0);
463 verify_any(to, AF_INET6, 0);
464 from->destroy(from);
465 to->destroy(to);
466
467 verify_range("fec1::1-fec1::1", AF_INET6, addr_v6, addr_v6);
468 verify_range("fec1::1-fec1::5", AF_INET6, addr_v6, addr_v6_to);
469 verify_range("fec1::1- fec1::5", AF_INET6, addr_v6, addr_v6_to);
470 verify_range("fec1::1 -fec1::5", AF_INET6, addr_v6, addr_v6_to);
471 verify_range("fec1::1 - fec1::5", AF_INET6, addr_v6, addr_v6_to);
472 verify_range("fec1::5-fec1::1", AF_INET6, addr_v6_to, addr_v6);
473
474 verify_range("fec1::1", 0, chunk_empty, chunk_empty);
475 verify_range("fec1::1-", 0, chunk_empty, chunk_empty);
476 verify_range("-fec1::1", 0, chunk_empty, chunk_empty);
477 verify_range("fec1::1-fec1", 0, chunk_empty, chunk_empty);
478 verify_range("foo::bar", 0, chunk_empty, chunk_empty);
479 verify_range("foo::bar-bar::foo", 0, chunk_empty, chunk_empty);
480
481 verify_range("fec1::1-192.168.0.1", 0, chunk_empty, chunk_empty);
482 verify_range("192.168.0.1-fec1::1", 0, chunk_empty, chunk_empty);
483 }
484 END_TEST
485
486 /*******************************************************************************
487 * host_create_netmask
488 */
489
490 static void test_create_netmask(int family)
491 {
492 host_t *netmask;
493 int i, len = (family == AF_INET) ? 32 : 128;
494
495 netmask = host_create_netmask(family, -1);
496 ck_assert(netmask == NULL);
497 for (i = 0; i <= len; i++)
498 {
499 netmask = host_create_netmask(family, i);
500 verify_netmask(netmask->get_address(netmask), i);
501 netmask->destroy(netmask);
502 }
503 netmask = host_create_netmask(family, len + 1);
504 ck_assert(netmask == NULL);
505 }
506
507 START_TEST(test_create_netmask_v4)
508 {
509 test_create_netmask(AF_INET);
510 }
511 END_TEST
512
513 START_TEST(test_create_netmask_v6)
514 {
515 test_create_netmask(AF_INET6);
516 }
517 END_TEST
518
519 START_TEST(test_create_netmask_other)
520 {
521 host_t *netmask;
522
523 netmask = host_create_netmask(AF_UNSPEC, 0);
524 ck_assert(netmask == NULL);
525 }
526 END_TEST
527
528 /*******************************************************************************
529 * equals, ip_equals
530 */
531
532 START_TEST(test_equals)
533 {
534 host_t *a, *b;
535
536 a = host_create_from_string("192.168.0.1", 500);
537 b = host_create_from_string("192.168.0.1", 0);
538 ck_assert(!a->equals(a, b));
539 ck_assert(!b->equals(b, a));
540 ck_assert(a->ip_equals(a, b));
541 ck_assert(b->ip_equals(b, a));
542 b->set_port(b, 500);
543 ck_assert(a->equals(a, b));
544 ck_assert(b->equals(b, a));
545 ck_assert(a->ip_equals(a, b));
546 ck_assert(b->ip_equals(b, a));
547 b->destroy(b);
548 b = host_create_from_string("192.168.0.2", 500);
549 ck_assert(!a->ip_equals(a, b));
550 ck_assert(!a->equals(a, b));
551 b->destroy(b);
552
553 b = host_create_from_string("fec1::1", 500);
554 ck_assert(!a->ip_equals(a, b));
555 ck_assert(!a->equals(a, b));
556 a->destroy(a);
557 a = host_create_from_string("fec1::1", 500);
558 ck_assert(a->equals(a, b));
559 ck_assert(a->ip_equals(a, b));
560 a->destroy(a);
561 b->destroy(b);
562 }
563 END_TEST
564
565 START_TEST(test_equals_any)
566 {
567 host_t *a, *b;
568
569 a = host_create_from_string("%any", 500);
570 b = host_create_from_string("%any", 0);
571 ck_assert(!a->equals(a, b));
572 ck_assert(a->ip_equals(a, b));
573 b->set_port(b, 500);
574 ck_assert(a->equals(a, b));
575 ck_assert(a->ip_equals(a, b));
576 b->destroy(b);
577 b = host_create_from_string("%any6", 0);
578 ck_assert(a->ip_equals(a, b));
579 ck_assert(!a->equals(a, b));
580 b->set_port(b, 500);
581 ck_assert(a->ip_equals(a, b));
582 ck_assert(a->equals(a, b));
583 a->destroy(a);
584 b->destroy(b);
585 }
586 END_TEST
587
588 /*******************************************************************************
589 * clone
590 */
591
592 START_TEST(test_clone)
593 {
594 host_t *a, *b;
595
596 a = host_create_from_string("192.168.0.1", 500);
597 b = a->clone(a);
598 ck_assert(a != b);
599 ck_assert(a->equals(a, b));
600 a->destroy(a);
601 b->destroy(b);
602 }
603 END_TEST
604
605 /*******************************************************************************
606 * printf hook
607 */
608
609 static struct {
610 char *addr;
611 u_int16_t port;
612 /* results for %H, %+H, %#H (falls back to [0]) */
613 char *result[3];
614 } printf_data[] = {
615 {NULL, 0, { "(null)" }},
616 {NULL, 500, { "(null)" }},
617 {"%any", 0, { "%any", "0.0.0.0", "0.0.0.0[0]" }},
618 {"%any", 500, { "%any", "0.0.0.0", "0.0.0.0[500]" }},
619 {"%any6", 0, { "%any6", "::", "::[0]" }},
620 {"%any6", 500, { "%any6", "::", "::[500]" }},
621 {"192.168.0.1", 0, { "192.168.0.1", "192.168.0.1", "192.168.0.1[0]" }},
622 {"192.168.0.1", 500, { "192.168.0.1", "192.168.0.1", "192.168.0.1[500]" }},
623 {"fec1::1", 0, { "fec1::1", "fec1::1", "fec1::1[0]" }},
624 {"fec1::1", 500, { "fec1::1", "fec1::1", "fec1::1[500]" }},
625 };
626
627 static void verify_printf(host_t *host, const char *format, char *expected)
628 {
629 char buf[64];
630
631 snprintf(buf, sizeof(buf), format, host);
632 ck_assert_str_eq(expected, buf);
633 }
634
635 START_TEST(test_printf_hook)
636 {
637 static const char *formats[] = { "%H", "%+H", "%#H" };
638 host_t *host = NULL;
639 char *expected;
640 int i;
641
642 if (printf_data[_i].addr)
643 {
644 host = host_create_from_string(printf_data[_i].addr,
645 printf_data[_i].port);
646 }
647 for (i = 0; i < countof(formats); i++)
648 {
649 expected = printf_data[_i].result[i];
650 expected = expected ?: printf_data[_i].result[0];
651 verify_printf(host, formats[i], expected);
652 }
653 DESTROY_IF(host);
654 }
655 END_TEST
656
657 START_TEST(test_printf_hook_align)
658 {
659 host_t *host;
660
661 verify_printf(NULL, "%14H", " (null)");
662 verify_printf(NULL, "%-14H", "(null) ");
663
664 host = host_create_from_string("192.168.0.1", 0);
665 verify_printf(host, "%14H", " 192.168.0.1");
666 verify_printf(host, "%-14H", "192.168.0.1 ");
667 verify_printf(host, "%4H", "192.168.0.1");
668 verify_printf(host, "%-4H", "192.168.0.1");
669 host->destroy(host);
670 }
671 END_TEST
672
673 Suite *host_suite_create()
674 {
675 Suite *s;
676 TCase *tc;
677
678 s = suite_create("host");
679
680 tc = tcase_create("host_create_any");
681 tcase_add_test(tc, test_create_any_v4);
682 tcase_add_test(tc, test_create_any_v6);
683 tcase_add_test(tc, test_create_any_other);
684 suite_add_tcase(s, tc);
685
686 tc = tcase_create("host_create_from_string");
687 tcase_add_test(tc, test_create_from_string_v4);
688 tcase_add_test(tc, test_create_from_string_any_v6);
689 suite_add_tcase(s, tc);
690
691 tc = tcase_create("host_create_from_string_and_family");
692 tcase_add_test(tc, test_create_from_string_and_family_v4);
693 tcase_add_test(tc, test_create_from_string_and_family_v6);
694 tcase_add_test(tc, test_create_from_string_and_family_other);
695 suite_add_tcase(s, tc);
696
697 tc = tcase_create("host_create_from_sockaddr");
698 tcase_add_test(tc, test_create_from_sockaddr_v4);
699 tcase_add_test(tc, test_create_from_sockaddr_v6);
700 tcase_add_test(tc, test_create_from_sockaddr_other);
701 suite_add_tcase(s, tc);
702
703 tc = tcase_create("host_create_from_chunk");
704 tcase_add_test(tc, test_create_from_chunk_v4);
705 tcase_add_test(tc, test_create_from_chunk_v6);
706 tcase_add_test(tc, test_create_from_chunk_other);
707 suite_add_tcase(s, tc);
708
709 tc = tcase_create("host_create_from_subnet");
710 tcase_add_test(tc, test_create_from_subnet_v4);
711 tcase_add_test(tc, test_create_from_subnet_v6);
712 suite_add_tcase(s, tc);
713
714 tc = tcase_create("host_create_from_range");
715 tcase_add_test(tc, test_create_from_range_v4);
716 tcase_add_test(tc, test_create_from_range_v6);
717 suite_add_tcase(s, tc);
718
719 tc = tcase_create("host_create_netmask");
720 tcase_add_test(tc, test_create_netmask_v4);
721 tcase_add_test(tc, test_create_netmask_v6);
722 tcase_add_test(tc, test_create_netmask_other);
723 suite_add_tcase(s, tc);
724
725 tc = tcase_create("equals, ip_equals");
726 tcase_add_test(tc, test_equals);
727 tcase_add_test(tc, test_equals_any);
728 suite_add_tcase(s, tc);
729
730 tc = tcase_create("clone");
731 tcase_add_test(tc, test_clone);
732 suite_add_tcase(s, tc);
733
734 tc = tcase_create("printf hook");
735 tcase_add_loop_test(tc, test_printf_hook, 0, countof(printf_data));
736 tcase_add_test(tc, test_printf_hook_align);
737 suite_add_tcase(s, tc);
738
739 return s;
740 }