diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2012-01-26 15:07:45 +0100 |
---|---|---|
committer | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2012-02-01 10:13:19 +0100 |
commit | 987c55eb3a6aaffe415ad782da21fa8cd605932d (patch) | |
tree | 97b4a620dac4b058cc6d3190129f47dc083c4b03 /unit | |
parent | c92a03edebc7e3e37a71d3e1350619031bc17ddf (diff) | |
download | connman-987c55eb3a6aaffe415ad782da21fa8cd605932d.tar.gz connman-987c55eb3a6aaffe415ad782da21fa8cd605932d.tar.bz2 connman-987c55eb3a6aaffe415ad782da21fa8cd605932d.zip |
test-ippool: Add collision unit test
Diffstat (limited to 'unit')
-rw-r--r-- | unit/test-ippool.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/unit/test-ippool.c b/unit/test-ippool.c index e7f6de0e..de253487 100644 --- a/unit/test-ippool.c +++ b/unit/test-ippool.c @@ -135,6 +135,61 @@ static void test_ippool_basic1(void) 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(void) +{ + struct connman_ippool *pool; + const char *gateway; + const char *broadcast; + const char *subnet_mask; + const char *start_ip; + const char *end_ip; + int flag; + + /* Test the IP range collision */ + + flag = 0; + pool = __connman_ippool_create(23, 1, 100, collision_cb, &flag); + g_assert(pool); + + gateway = __connman_ippool_get_gateway(pool); + broadcast = __connman_ippool_get_broadcast(pool); + subnet_mask = __connman_ippool_get_subnet_mask(pool); + start_ip = __connman_ippool_get_start_ip(pool); + end_ip = __connman_ippool_get_end_ip(pool); + + g_assert(gateway); + g_assert(broadcast); + g_assert(subnet_mask); + g_assert(start_ip); + g_assert(end_ip); + + LOG("\n\tIP range %s --> %s\n" + "\tgateway %s broadcast %s mask %s", start_ip, end_ip, + gateway, broadcast, subnet_mask); + + __connman_ippool_newaddr(23, start_ip); + + g_assert(flag == 0); + + __connman_ippool_newaddr(42, end_ip); + + g_assert(flag == 1); + + __connman_ippool_unref(pool); +} + int main(int argc, char *argv[]) { int err; @@ -145,6 +200,7 @@ int main(int argc, char *argv[]) g_test_add_func("/basic0", test_ippool_basic0); g_test_add_func("/basic1", test_ippool_basic1); + g_test_add_func("/collision0", test_ippool_collision0); err = g_test_run(); |