5 * Copyright (C) 2012 BWM CarIT GmbH. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "../src/connman.h"
34 #define LOG(fmt, arg...) do { \
35 fprintf(stdout, "%s:%s() " fmt "\n", \
36 __FILE__, __func__ , ## arg); \
39 #define LOG(fmt, arg...)
42 static void test_ippool_basic0(void)
44 struct connman_ippool *pool;
46 const char *broadcast;
47 const char *subnet_mask;
52 /* Test the IP range */
54 pool = __connman_ippool_create(1, 500);
55 g_assert(pool == NULL);
57 for (i = 1; i < 254; i++) {
58 pool = __connman_ippool_create(1, i);
61 gateway = __connman_ippool_get_gateway(pool);
62 broadcast = __connman_ippool_get_broadcast(pool);
63 subnet_mask = __connman_ippool_get_subnet_mask(pool);
64 start_ip = __connman_ippool_get_start_ip(pool);
65 end_ip = __connman_ippool_get_end_ip(pool);
69 g_assert(subnet_mask);
73 LOG("\n\tIP range %s --> %s\n"
74 "\tgateway %s broadcast %s mask %s", start_ip, end_ip,
75 gateway, broadcast, subnet_mask);
77 __connman_ippool_unref(pool);
81 static void test_ippool_basic1(void)
83 struct connman_ippool *pool;
85 const char *broadcast;
86 const char *subnet_mask;
89 GSList *list = NULL, *it;
92 /* Allocate all possible pools */
96 * 24-bit block 10.0.0.0 – 10.255.255.255 16,777,216
97 * 20-bit block 172.16.0.0 – 172.31.255.255 1,048,576
98 * 16-bit block 192.168.0.0 – 192.168.255.255 65,536
102 * Total numbers of 256 blocks: 69,888
106 pool = __connman_ippool_create(1, 100);
112 list = g_slist_prepend(list, pool);
114 gateway = __connman_ippool_get_gateway(pool);
115 broadcast = __connman_ippool_get_broadcast(pool);
116 subnet_mask = __connman_ippool_get_subnet_mask(pool);
117 start_ip = __connman_ippool_get_start_ip(pool);
118 end_ip = __connman_ippool_get_end_ip(pool);
122 g_assert(subnet_mask);
127 LOG("Number of blocks %d", i);
129 for (it = list; it != NULL; it = it->next) {
132 __connman_ippool_unref(pool);
138 int main(int argc, char *argv[])
142 g_test_init(&argc, &argv, NULL);
144 __connman_ippool_init();
146 g_test_add_func("/basic0", test_ippool_basic0);
147 g_test_add_func("/basic1", test_ippool_basic1);
151 __connman_ippool_cleanup();