From: Daniel Wagner <[email protected]>
---
unit/test-ippool.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/unit/test-ippool.c b/unit/test-ippool.c
index cad5fb7..8a69a3b 100644
--- a/unit/test-ippool.c
+++ b/unit/test-ippool.c
@@ -135,6 +135,91 @@ static void test_ippool_basic1(gconstpointer user_data)
g_slist_free(list);
}
+static void collision_cb(struct connman_ippool *pool, void *user_data)
+{
+ int *flag = user_data;
+
+ LOG("collision detected");
+
+ g_assert(*flag == 0);
+ g_assert(pool);
+
+ *flag = 1;
+}
+
+static void test_ippool_collision0(gconstpointer user_data)
+{
+ struct connman_ippool *pool;
+ char *gateway0;
+ char *broadcast0;
+ char *start_ip0;
+ char *end_ip0;
+ const char *gateway1;
+ const char *broadcast1;
+ const char *subnet_mask;
+ const char *start_ip1;
+ const char *end_ip1;
+ int flag;
+
+ /* Test the IP range collision */
+
+ flag = 0;
+ pool = __connman_ippool_create(1, 100, collision_cb, &flag);
+ g_assert(pool);
+
+ gateway0 = g_strdup(__connman_ippool_get_gateway(pool));
+ broadcast0 = g_strdup(__connman_ippool_get_broadcast(pool));
+ subnet_mask = g_strdup(__connman_ippool_get_subnet_mask(pool));
+ start_ip0 = g_strdup(__connman_ippool_get_start_ip(pool));
+ end_ip0 = g_strdup(__connman_ippool_get_end_ip(pool));
+
+ g_assert(gateway0);
+ g_assert(broadcast0);
+ g_assert(subnet_mask);
+ g_assert(start_ip0);
+ g_assert(end_ip0);
+
+ LOG("\n\tIP range %s --> %s\n"
+ "\tgateway %s broadcast %s mask %s", start_ip0, end_ip0,
+ gateway0, broadcast0, subnet_mask);
+
+ __connman_ippool_newaddr(start_ip0);
+
+ g_assert(flag == 1);
+
+ __connman_ippool_unref(pool);
+
+ pool = __connman_ippool_create(1, 100, collision_cb, &flag);
+ g_assert(pool);
+
+ gateway1 = __connman_ippool_get_gateway(pool);
+ broadcast1 = __connman_ippool_get_broadcast(pool);
+ subnet_mask = __connman_ippool_get_subnet_mask(pool);
+ start_ip1 = __connman_ippool_get_start_ip(pool);
+ end_ip1 = __connman_ippool_get_end_ip(pool);
+
+ g_assert(gateway1);
+ g_assert(broadcast1);
+ g_assert(start_ip1);
+ g_assert(end_ip1);
+
+ LOG("\n\tIP range %s --> %s\n"
+ "\tgateway %s broadcast %s mask %s", start_ip1, end_ip1,
+ gateway1, broadcast1, subnet_mask);
+
+ g_assert(g_strcmp0(gateway0, gateway1) != 0);
+ g_assert(g_strcmp0(broadcast0, broadcast1) != 0);
+ g_assert(g_strcmp0(start_ip0, start_ip1) != 0);
+ g_assert(g_strcmp0(end_ip0, end_ip1) != 0);
+
+ __connman_ippool_unref(pool);
+
+ g_free(gateway0);
+ g_free(broadcast0);
+ g_free(start_ip0);
+ g_free(end_ip0);
+}
+
int main(int argc, char *argv[])
{
int err;
@@ -145,6 +230,7 @@ int main(int argc, char *argv[])
g_test_add_data_func("/basic0", NULL, test_ippool_basic0);
g_test_add_data_func("/basic1", NULL, test_ippool_basic1);
+ g_test_add_data_func("/collision0", NULL, test_ippool_collision0);
err = g_test_run();
--
1.7.8.2.325.g247f9
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman