Annotation of embedaddon/strongswan/src/libcharon/tests/suites/test_ike_cfg.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2015 Tobias Brunner
! 3: * HSR 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 <config/ike_cfg.h>
! 19:
! 20: static void assert_family(int expected, char *addr, bool local)
! 21: {
! 22: ike_cfg_create_t ike = {
! 23: .version = IKEV2,
! 24: .local = local ? addr : "%any",
! 25: .local_port = 500,
! 26: .remote = local ? "%any" : addr,
! 27: .remote_port = 500,
! 28: };
! 29: ike_cfg_t *cfg;
! 30: int family;
! 31:
! 32: cfg = ike_cfg_create(&ike);
! 33: family = ike_cfg_get_family(cfg, local);
! 34: ck_assert_msg(expected == family, "expected family %d != %d (addr: '%s')",
! 35: expected, family, addr);
! 36: cfg->destroy(cfg);
! 37: }
! 38:
! 39: START_TEST(test_get_address_family_empty)
! 40: {
! 41: assert_family(AF_UNSPEC, "", _i);
! 42: }
! 43: END_TEST
! 44:
! 45: START_TEST(test_get_address_family_addr)
! 46: {
! 47: assert_family(AF_INET, "192.168.1.1", _i);
! 48: assert_family(AF_INET6, "fec::1", _i);
! 49: }
! 50: END_TEST
! 51:
! 52: START_TEST(test_get_address_family_multi)
! 53: {
! 54: assert_family(AF_INET, "192.168.1.1,192.168.2.2", _i);
! 55: assert_family(AF_INET6, "fec::1,fec::2", _i);
! 56:
! 57: assert_family(AF_UNSPEC, "192.168.1.1,fec::1", _i);
! 58: assert_family(AF_UNSPEC, "fec::1,192.168.1.1", _i);
! 59: }
! 60: END_TEST
! 61:
! 62: START_TEST(test_get_address_family_any)
! 63: {
! 64: assert_family(AF_UNSPEC, "%any", _i);
! 65:
! 66: assert_family(AF_INET, "%any4", _i);
! 67: assert_family(AF_INET, "0.0.0.0", _i);
! 68:
! 69: assert_family(AF_INET6, "%any6", _i);
! 70: assert_family(AF_INET6, "::", _i);
! 71:
! 72: assert_family(AF_INET, "192.168.1.1,%any", _i);
! 73: assert_family(AF_INET, "192.168.1.1,%any4", _i);
! 74: assert_family(AF_UNSPEC, "192.168.1.1,%any6", _i);
! 75:
! 76: assert_family(AF_INET6, "fec::1,%any", _i);
! 77: assert_family(AF_UNSPEC, "fec::1,%any4", _i);
! 78: assert_family(AF_INET6, "fec::1,%any6", _i);
! 79: }
! 80: END_TEST
! 81:
! 82: START_TEST(test_get_address_family_other)
! 83: {
! 84: assert_family(AF_INET, "192.168.1.0", _i);
! 85: assert_family(AF_UNSPEC, "192.168.1.0/24", _i);
! 86: assert_family(AF_UNSPEC, "192.168.1.0-192.168.1.10", _i);
! 87:
! 88: assert_family(AF_INET, "192.168.1.0/24,192.168.2.1", _i);
! 89: assert_family(AF_INET, "192.168.1.0-192.168.1.10,192.168.2.1", _i);
! 90: assert_family(AF_INET6, "192.168.1.0/24,fec::1", _i);
! 91: assert_family(AF_INET6, "192.168.1.0-192.168.1.10,fec::1", _i);
! 92:
! 93: assert_family(AF_INET6, "fec::", _i);
! 94: assert_family(AF_UNSPEC, "fec::/64", _i);
! 95: assert_family(AF_UNSPEC, "fec::1-fec::10", _i);
! 96:
! 97: assert_family(AF_INET6, "fec::/64,fed::1", _i);
! 98: assert_family(AF_INET6, "fec::1-fec::10,fec::1", _i);
! 99: assert_family(AF_INET, "fec::/64,192.168.1.1", _i);
! 100: assert_family(AF_INET, "fec::1-fec::10,192.168.1.1", _i);
! 101:
! 102: assert_family(AF_UNSPEC, "strongswan.org", _i);
! 103: assert_family(AF_INET, "192.168.1.0,strongswan.org", _i);
! 104: assert_family(AF_INET6, "fec::1,strongswan.org", _i);
! 105: }
! 106: END_TEST
! 107:
! 108: Suite *ike_cfg_suite_create()
! 109: {
! 110: Suite *s;
! 111: TCase *tc;
! 112:
! 113: s = suite_create("ike_cfg");
! 114:
! 115: tc = tcase_create("ike_cfg_get_address_family");
! 116: tcase_add_loop_test(tc, test_get_address_family_empty, 0, 2);
! 117: tcase_add_loop_test(tc, test_get_address_family_addr, 0, 2);
! 118: tcase_add_loop_test(tc, test_get_address_family_multi, 0, 2);
! 119: tcase_add_loop_test(tc, test_get_address_family_any, 0, 2);
! 120: tcase_add_loop_test(tc, test_get_address_family_other, 0, 2);
! 121: suite_add_tcase(s, tc);
! 122:
! 123: return s;
! 124: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>