END_TEST START_TEST(test_ipv4_iterate_01) { struct ip_set set; ipset_init(&set); struct cork_ip ip1; cork_ip_init(&ip1, "192.168.0.1"); fail_if(ipset_ip_add(&set, &ip1), "Element should not be present"); struct ipset_iterator *it = ipset_iterate(&set, true); fail_if(it == NULL, "IP set iterator is NULL"); fail_if(it->finished, "IP set shouldn't be empty"); fail_unless(cork_ip_equal(&ip1, &it->addr), "IP address 0 doesn't match"); fail_unless(it->cidr_prefix == IPV4_BIT_SIZE, "IP CIDR prefix 0 doesn't match"); ipset_iterator_advance(it); fail_unless(it->finished, "IP set should contain 1 element"); ipset_iterator_free(it); ipset_done(&set); }
END_TEST START_TEST(test_ipv6_iterate_network_03) { struct ip_set set; ipset_init(&set); /* * If we add all of the IP addresses in a network individually, we * should still get the network as a whole from the iterator. */ struct cork_ip ip1; cork_ip_init(&ip1, "fe80::"); struct cork_ip ip2; cork_ip_init(&ip2, "fe80::1"); fail_if(ipset_ip_add(&set, &ip1), "Element should not be present"); fail_if(ipset_ip_add(&set, &ip2), "Element should not be present"); struct ipset_iterator *it = ipset_iterate_networks(&set, true); fail_if(it == NULL, "IP set iterator is NULL"); fail_if(it->finished, "IP set shouldn't be empty"); fail_unless(cork_ip_equal(&ip1, &it->addr), "IP address 0 doesn't match"); fail_unless(it->cidr_prefix == 127, "IP CIDR prefix 0 doesn't match"); ipset_iterator_advance(it); fail_unless(it->finished, "IP set should contain 1 elements"); ipset_iterator_free(it); ipset_done(&set); }
END_TEST START_TEST(test_generic_ip_iterate_02) { struct ip_set set; ipset_init(&set); /* * These addresses are carefully constructed so that the same BDD * variable assignments are used to store both, apart from the * IPv4/v6 discriminator variable. The goal is get a BDD that has * EITHER in the assignment for variable 0, but isn't simply the * empty or full set. */ struct cork_ip ip1; cork_ip_init(&ip1, "192.168.0.1"); /* 0xc0a80001 */ struct cork_ip ip2; cork_ip_init(&ip2, "c0a8:0001::"); fail_if(ipset_ip_add(&set, &ip1), "Element should not be present"); fail_if(ipset_ip_add_network(&set, &ip2, 32), "Element should not be present"); struct ipset_iterator *it = ipset_iterate_networks(&set, true); fail_if(it == NULL, "IP set iterator is NULL"); fail_if(it->finished, "IP set shouldn't be empty"); fail_unless(cork_ip_equal(&ip1, &it->addr), "IP address 0 doesn't match"); fail_unless(it->cidr_prefix == 32, "IP CIDR prefix 0 doesn't match"); ipset_iterator_advance(it); fail_if(it->finished, "IP set should have more than 1 element"); fail_unless(cork_ip_equal(&ip2, &it->addr), "IP address 1 doesn't match"); fail_unless(it->cidr_prefix == 32, "IP CIDR prefix 1 doesn't match"); ipset_iterator_advance(it); fail_unless(it->finished, "IP set should contain 2 elements"); ipset_iterator_free(it); ipset_done(&set); }
END_TEST START_TEST(test_ipv6_insert_02) { ip_set_t set; ipset_init(&set); ipset_ip_t ip; ipset_ip_from_string(&ip, "fe80::21e:c2ff:fe9f:e8e1"); fail_if(ipset_ip_add(&set, &ip), "Element should not be present"); fail_unless(ipset_ipv6_add(&set, &IPV6_ADDR_1), "Element should be present"); ipset_done(&set); }
END_TEST START_TEST(test_ipv4_insert_02) { ip_set_t set; ipset_init(&set); ipset_ip_t ip; ipset_ip_from_string(&ip, "192.168.1.100"); fail_if(ipset_ip_add(&set, &ip), "Element should not be present"); fail_unless(ipset_ipv4_add(&set, &IPV4_ADDR_1), "Element should be present"); ipset_done(&set); }