summaryrefslogtreecommitdiff
path: root/src/network/test-network.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-16 00:27:56 +0200
committerTom Gundersen <teg@jklm.no>2014-05-17 20:46:11 +0200
commit9505d3c6deda0452c22ab2ed47bca74b98d87a17 (patch)
tree36abb35e666d895aca033dad602f699aa1658e29 /src/network/test-network.c
parentac976532063da637a70af3e39e0e1876267018ed (diff)
networkd: IP address equality
Diffstat (limited to 'src/network/test-network.c')
-rw-r--r--src/network/test-network.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 38d57cc6a6..a0e04f8fd2 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -42,11 +42,58 @@ static void test_network_get(Manager *manager, struct udev_device *loopback) {
assert_se(!network);
}
+static void test_address_equality(void) {
+ Address *a1, *a2;
+
+ assert_se(address_new_dynamic(&a1) >= 0);
+ assert_se(address_new_dynamic(&a2) >= 0);
+
+ assert_se(address_equal(NULL, NULL));
+ assert_se(!address_equal(a1, NULL));
+ assert_se(!address_equal(NULL, a2));
+ assert_se(address_equal(a1, a2));
+
+ a1->family = AF_INET;
+ assert_se(!address_equal(a1, a2));
+
+ a2->family = AF_INET;
+ assert_se(address_equal(a1, a2));
+
+ assert_se(inet_pton(AF_INET, "192.168.3.9", &a1->in_addr.in));
+ assert_se(!address_equal(a1, a2));
+ assert_se(inet_pton(AF_INET, "192.168.3.9", &a2->in_addr.in));
+ assert_se(address_equal(a1, a2));
+
+ a1->prefixlen = 10;
+ assert_se(!address_equal(a1, a2));
+ a2->prefixlen = 10;
+ assert_se(address_equal(a1, a2));
+
+ assert_se(inet_pton(AF_INET, "192.168.3.10", &a2->in_addr.in));
+ assert_se(address_equal(a1, a2));
+
+ a1->family = AF_INET6;
+ assert_se(!address_equal(a1, a2));
+
+ a2->family = AF_INET6;
+ assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::2", &a1->in_addr.in6));
+ assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::2", &a2->in_addr.in6));
+ assert_se(address_equal(a1, a2));
+
+ a2->prefixlen = 8;
+ assert_se(address_equal(a1, a2));
+
+ assert_se(inet_pton(AF_INET6, "2001:4ca0:4f01::1", &a2->in_addr.in6));
+ assert_se(!address_equal(a1, a2));
+}
+
int main(void) {
_cleanup_manager_free_ Manager *manager = NULL;
struct udev *udev;
struct udev_device *loopback;
+ test_address_equality();
+
assert_se(manager_new(&manager) >= 0);
test_load_config(manager);