diff options
author | Dan Williams <dcbw@redhat.com> | 2014-07-01 11:15:19 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2014-07-18 17:03:28 -0500 |
commit | 2398fbb9f76d6365b0016274a45ff77041c9eca5 (patch) | |
tree | 369373e845e2e76e3ac15b012410a4107eaf4bc4 | |
parent | 831a5918674a5f214de627e13791bea170d25743 (diff) | |
download | NetworkManager-2398fbb9f76d6365b0016274a45ff77041c9eca5.tar.gz |
dhcp: convert options testcases to g_assert()
-rw-r--r-- | src/dhcp-manager/tests/test-dhcp-options.c | 390 |
1 files changed, 133 insertions, 257 deletions
diff --git a/src/dhcp-manager/tests/test-dhcp-options.c b/src/dhcp-manager/tests/test-dhcp-options.c index e3a6762944..ac6c22a6c3 100644 --- a/src/dhcp-manager/tests/test-dhcp-options.c +++ b/src/dhcp-manager/tests/test-dhcp-options.c @@ -35,9 +35,9 @@ typedef struct { } Option; static GHashTable * -fill_table (Option *test_options, GHashTable *table) +fill_table (const Option *test_options, GHashTable *table) { - Option *opt; + const Option *opt; if (!table) table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); @@ -46,7 +46,7 @@ fill_table (Option *test_options, GHashTable *table) return table; } -static Option generic_options[] = { +static const Option generic_options[] = { { "subnet_mask", "255.255.255.0" }, { "ip_address", "192.168.1.106" }, { "network_number", "192.168.1.0" }, @@ -86,102 +86,60 @@ test_generic_options (void) options = fill_table (generic_options, NULL); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-generic", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* IP4 address */ - ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1, - "dhcp-generic", "unexpected number of IP addresses"); + g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); address = nm_ip4_config_get_address (ip4_config, 0); - - ASSERT (inet_pton (AF_INET, expected_addr, &tmp) > 0, - "dhcp-generic", "couldn't convert expected IP address"); - ASSERT (address->address == tmp, - "dhcp-generic", "unexpected IP address"); - ASSERT (address->peer_address == 0, - "dhcp-generic", "unexpected PTP address"); - - ASSERT (address->plen == 24, - "dhcp-generic", "unexpected IP address prefix length"); + g_assert (inet_pton (AF_INET, expected_addr, &tmp) > 0); + g_assert (address->address == tmp); + g_assert (address->peer_address == 0); + g_assert_cmpint (address->plen, ==, 24); /* Gateway */ - ASSERT (inet_pton (AF_INET, expected_gw, &tmp) > 0, - "dhcp-generic", "couldn't convert expected IP gateway"); - ASSERT (nm_ip4_config_get_gateway (ip4_config) == tmp, - "dhcp-generic", "unexpected IP gateway"); + g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0); + g_assert (nm_ip4_config_get_gateway (ip4_config) == tmp); - ASSERT (nm_ip4_config_get_num_wins (ip4_config) == 0, - "dhcp-generic", "unexpected number of WINS servers"); + g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 0); - ASSERT (nm_ip4_config_get_mtu (ip4_config) == 987, - "dhcp-generic", "unexpected MTU"); + g_assert_cmpint (nm_ip4_config_get_mtu (ip4_config), ==, 987); /* Domain searches */ - ASSERT (nm_ip4_config_get_num_searches (ip4_config) == 2, - "dhcp-generic", "unexpected number of domain searches"); - ASSERT (strcmp (nm_ip4_config_get_search (ip4_config, 0), expected_search1) == 0, - "dhcp-generic", "unexpected domain search #1"); - ASSERT (strcmp (nm_ip4_config_get_search (ip4_config, 1), expected_search2) == 0, - "dhcp-generic", "unexpected domain search #2"); + g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 2); + g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 0), ==, expected_search1); + g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 1), ==, expected_search2); /* DNS servers */ - ASSERT (nm_ip4_config_get_num_nameservers (ip4_config) == 2, - "dhcp-generic", "unexpected number of domain name servers"); - ASSERT (inet_pton (AF_INET, expected_dns1, &tmp) > 0, - "dhcp-generic", "couldn't convert expected DNS server address #1"); - ASSERT (nm_ip4_config_get_nameserver (ip4_config, 0) == tmp, - "dhcp-generic", "unexpected domain name server #1"); - ASSERT (inet_pton (AF_INET, expected_dns2, &tmp) > 0, - "dhcp-generic", "couldn't convert expected DNS server address #2"); - ASSERT (nm_ip4_config_get_nameserver (ip4_config, 1) == tmp, - "dhcp-generic", "unexpected domain name server #2"); + g_assert_cmpint (nm_ip4_config_get_num_nameservers (ip4_config), ==, 2); + g_assert (inet_pton (AF_INET, expected_dns1, &tmp) > 0); + g_assert (nm_ip4_config_get_nameserver (ip4_config, 0) == tmp); + g_assert (inet_pton (AF_INET, expected_dns2, &tmp) > 0); + g_assert (nm_ip4_config_get_nameserver (ip4_config, 1) == tmp); /* Routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2, - "dhcp-generic", "unexpected number of routes"); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); /* Route #1 */ route = nm_ip4_config_get_route (ip4_config, 0); - ASSERT (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0, - "dhcp-generic", "couldn't convert expected route destination #1"); - ASSERT (route->network == tmp, - "dhcp-generic", "unexpected route #1 destination"); - - ASSERT (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0, - "dhcp-generic", "couldn't convert expected route next hop #1"); - ASSERT (route->gateway == tmp, - "dhcp-generic", "unexpected route #1 next hop"); - - ASSERT (route->plen == 32, - "dhcp-generic", "unexpected route #1 prefix"); - ASSERT (route->metric == 0, - "dhcp-generic", "unexpected route #1 metric"); + g_assert (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0); + g_assert (route->network == tmp); + g_assert (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0); + g_assert (route->gateway == tmp); + g_assert_cmpint (route->plen, ==, 32); + g_assert_cmpint (route->metric, ==, 0); /* Route #2 */ route = nm_ip4_config_get_route (ip4_config, 1); - ASSERT (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0, - "dhcp-generic", "couldn't convert expected route destination #2"); - ASSERT (route->network == tmp, - "dhcp-generic", "unexpected route #2 destination"); - - ASSERT (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0, - "dhcp-generic", "couldn't convert expected route next hop #2"); - ASSERT (route->gateway == tmp, - "dhcp-generic", "unexpected route #2 next hop"); - - ASSERT (route->plen == 32, - "dhcp-generic", "unexpected route #2 prefix"); - ASSERT (route->metric == 0, - "dhcp-generic", "unexpected route #2 metric"); + g_assert (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0); + g_assert (route->network == tmp); + g_assert (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0); + g_assert (route->gateway == tmp); + g_assert_cmpint (route->plen, ==, 32); + g_assert_cmpint (route->metric, ==, 0); g_hash_table_destroy (options); } -static Option wins_options[] = { - { "netbios_name_servers", "63.12.199.5 150.4.88.120" }, - { NULL, NULL } -}; - static void test_wins_options (void) { @@ -191,36 +149,31 @@ test_wins_options (void) guint32 tmp; const char *expected_wins1 = "63.12.199.5"; const char *expected_wins2 = "150.4.88.120"; + static const Option data[] = { + { "netbios_name_servers", "63.12.199.5 150.4.88.120" }, + { NULL, NULL } + }; options = fill_table (generic_options, NULL); - options = fill_table (wins_options, options); + options = fill_table (data, options); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-wins", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* IP4 address */ - ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1, - "dhcp-wins", "unexpected number of IP addresses"); + g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); address = nm_ip4_config_get_address (ip4_config, 0); - ASSERT (address != NULL, "dhcp-wins", "unexpectedly did not get address #0"); - - ASSERT (nm_ip4_config_get_num_wins (ip4_config) == 2, - "dhcp-wins", "unexpected number of WINS servers"); - ASSERT (inet_pton (AF_INET, expected_wins1, &tmp) > 0, - "dhcp-wins", "couldn't convert expected WINS server address #1"); - ASSERT (nm_ip4_config_get_wins (ip4_config, 0) == tmp, - "dhcp-wins", "unexpected WINS server #1"); - ASSERT (inet_pton (AF_INET, expected_wins2, &tmp) > 0, - "dhcp-wins", "couldn't convert expected WINS server address #1"); - ASSERT (nm_ip4_config_get_wins (ip4_config, 1) == tmp, - "dhcp-wins", "unexpected WINS server #1"); + g_assert (address); + g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 2); + g_assert (inet_pton (AF_INET, expected_wins1, &tmp) > 0); + g_assert (nm_ip4_config_get_wins (ip4_config, 0) == tmp); + g_assert (inet_pton (AF_INET, expected_wins2, &tmp) > 0); + g_assert (nm_ip4_config_get_wins (ip4_config, 1) == tmp); g_hash_table_destroy (options); } static void -ip4_test_route (const char *test, - NMIP4Config *ip4_config, +ip4_test_route (NMIP4Config *ip4_config, guint route_num, const char *expected_dest, const char *expected_gw, @@ -230,36 +183,22 @@ ip4_test_route (const char *test, guint32 tmp; route = nm_ip4_config_get_route (ip4_config, route_num); - ASSERT (inet_pton (AF_INET, expected_dest, &tmp) > 0, - test, "couldn't convert expected route destination #1"); - ASSERT (route->network == tmp, - test, "unexpected route %d destination", route_num + 1); - - ASSERT (inet_pton (AF_INET, expected_gw, &tmp) > 0, - test, "couldn't convert expected route next hop %d", - route_num + 1); - ASSERT (route->gateway == tmp, - test, "unexpected route %d next hop", route_num + 1); - - ASSERT (route->plen == expected_prefix, - test, "unexpected route %d prefix", route_num + 1); - ASSERT (route->metric == 0, - test, "unexpected route %d metric", route_num + 1); + g_assert (inet_pton (AF_INET, expected_dest, &tmp) > 0); + g_assert (route->network == tmp); + g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0); + g_assert (route->gateway == tmp); + g_assert_cmpint (route->plen, ==, expected_prefix); + g_assert_cmpint (route->metric, ==, 0); } static void -ip4_test_gateway (const char *test, - NMIP4Config *ip4_config, - const char *expected_gw) +ip4_test_gateway (NMIP4Config *ip4_config, const char *expected_gw) { guint32 tmp; - ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1, - test, "unexpected number of IP addresses"); - ASSERT (inet_pton (AF_INET, expected_gw, &tmp) > 0, - test, "couldn't convert expected IP gateway"); - ASSERT (nm_ip4_config_get_gateway (ip4_config) == tmp, - test, "unexpected IP gateway"); + g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); + g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0); + g_assert (nm_ip4_config_get_gateway (ip4_config) == tmp); } static void @@ -271,7 +210,7 @@ test_classless_static_routes_1 (void) const char *expected_route1_gw = "192.168.1.1"; const char *expected_route2_dest = "10.0.0.0"; const char *expected_route2_gw = "10.17.66.41"; - static Option data[] = { + static const Option data[] = { /* dhclient custom format */ { "rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 8 10 10 17 66 41" }, { NULL, NULL } @@ -280,16 +219,12 @@ test_classless_static_routes_1 (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-classless-1", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2, - "dhcp-classless-1", "unexpected number of IP routes"); - ip4_test_route ("dhcp-classless-1", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 24); - ip4_test_route ("dhcp-classless-1", ip4_config, 1, - expected_route2_dest, expected_route2_gw, 8); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 8); g_hash_table_destroy (options); } @@ -303,7 +238,7 @@ test_classless_static_routes_2 (void) const char *expected_route1_gw = "192.168.1.1"; const char *expected_route2_dest = "10.0.0.0"; const char *expected_route2_gw = "10.17.66.41"; - static Option data[] = { + static const Option data[] = { /* dhcpcd format */ { "classless_static_routes", "192.168.10.0/24 192.168.1.1 10.0.0.0/8 10.17.66.41" }, { NULL, NULL } @@ -312,16 +247,12 @@ test_classless_static_routes_2 (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-classless-2", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2, - "dhcp-classless-2", "unexpected number of IP routes"); - ip4_test_route ("dhcp-classless-2", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 24); - ip4_test_route ("dhcp-classless-2", ip4_config, 1, - expected_route2_dest, expected_route2_gw, 8); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); + ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 8); g_hash_table_destroy (options); } @@ -336,7 +267,7 @@ test_fedora_dhclient_classless_static_routes (void) const char *expected_route2_dest = "2.0.0.0"; const char *expected_route2_gw = "10.34.255.6"; const char *expected_gateway = "192.168.0.113"; - static Option data[] = { + static const Option data[] = { /* Fedora dhclient format */ { "classless_static_routes", "0 192.168.0.113 25.129.210.177.132 192.168.0.113 7.2 10.34.255.6" }, { NULL, NULL } @@ -345,19 +276,15 @@ test_fedora_dhclient_classless_static_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-fedora-dhclient-classless", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2, - "dhcp-fedora-dhclient-classless", "unexpected number of IP routes"); - ip4_test_route ("dhcp-fedora-dhclient-classless", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 25); - ip4_test_route ("dhcp-fedora-dhclient-classless", ip4_config, 1, - expected_route2_dest, expected_route2_gw, 7); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 25); + ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 7); /* Gateway */ - ip4_test_gateway ("dhcp-fedora-dhclient-classless", ip4_config, expected_gateway); + ip4_test_gateway (ip4_config, expected_gateway); g_hash_table_destroy (options); } @@ -369,7 +296,7 @@ test_dhclient_invalid_classless_routes_1 (void) NMIP4Config *ip4_config; const char *expected_route1_dest = "192.168.10.0"; const char *expected_route1_gw = "192.168.1.1"; - static Option data[] = { + static const Option data[] = { /* dhclient format */ { "rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 45 10 17 66 41" }, { NULL, NULL } @@ -381,16 +308,12 @@ test_dhclient_invalid_classless_routes_1 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*ignoring invalid classless static routes*"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhclient-classless-invalid-1", "failed to parse DHCP4 options"); + g_assert (ip4_config); g_test_assert_expected_messages (); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1, - "dhcp-dhclient-classless-invalid-1", "unexpected number of IP routes"); - - ip4_test_route ("dhcp-dhclient-classless-invalid-1", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 24); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); g_hash_table_destroy (options); } @@ -404,7 +327,7 @@ test_dhcpcd_invalid_classless_routes_1 (void) const char *expected_route1_gw = "10.1.1.1"; const char *expected_route2_dest = "100.99.88.56"; const char *expected_route2_gw = "10.1.1.1"; - static Option data[] = { + static const Option data[] = { /* dhcpcd format */ { "classless_static_routes", "192.168.10.0/24 192.168.1.1 10.0.adfadf/44 10.17.66.41" }, { NULL, NULL } @@ -416,19 +339,15 @@ test_dhcpcd_invalid_classless_routes_1 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*ignoring invalid classless static routes*"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhcpcd-classless-invalid-1", "failed to parse DHCP4 options"); + g_assert (ip4_config); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static * routes are invalid. */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2, - "dhcp-dhcpcdp-classless-invalid-1", "unexpected number of routes"); - ip4_test_route ("dhcp-dhcpcdp-classless-invalid-1", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 32); - ip4_test_route ("dhcp-dhcpcdp-classless-invalid-1", ip4_config, 1, - expected_route2_dest, expected_route2_gw, 32); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); + ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); g_hash_table_destroy (options); } @@ -442,7 +361,7 @@ test_dhclient_invalid_classless_routes_2 (void) const char *expected_route1_gw = "10.1.1.1"; const char *expected_route2_dest = "100.99.88.56"; const char *expected_route2_gw = "10.1.1.1"; - static Option data[] = { + static const Option data[] = { { "rfc3442_classless_static_routes", "45 10 17 66 41 24 192 168 10 192 168 1 1" }, { NULL, NULL } }; @@ -453,19 +372,15 @@ test_dhclient_invalid_classless_routes_2 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*ignoring invalid classless static routes*"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhclient-classless-invalid-2", "failed to parse DHCP4 options"); + g_assert (ip4_config); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static * routes are invalid. */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2, - "dhcp-dhclient-classless-invalid-2", "unexpected number of routes"); - ip4_test_route ("dhcp-dhclient-classless-invalid-2", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 32); - ip4_test_route ("dhcp-dhclient-classless-invalid-2", ip4_config, 1, - expected_route2_dest, expected_route2_gw, 32); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); + ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); g_hash_table_destroy (options); } @@ -479,7 +394,7 @@ test_dhcpcd_invalid_classless_routes_2 (void) const char *expected_route1_gw = "10.1.1.1"; const char *expected_route2_dest = "100.99.88.56"; const char *expected_route2_gw = "10.1.1.1"; - static Option data[] = { + static const Option data[] = { { "classless_static_routes", "10.0.adfadf/44 10.17.66.41 192.168.10.0/24 192.168.1.1" }, { NULL, NULL } }; @@ -490,8 +405,7 @@ test_dhcpcd_invalid_classless_routes_2 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*ignoring invalid classless static routes*"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhcpcd-classless-invalid-2", "failed to parse DHCP4 options"); + g_assert (ip4_config); g_test_assert_expected_messages (); /* Test falling back to old-style static routes if the classless static @@ -499,12 +413,9 @@ test_dhcpcd_invalid_classless_routes_2 (void) */ /* Routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 2, - "dhcp-dhcpcd-classless-invalid-2", "unexpected number of routes"); - ip4_test_route ("dhcp-dhcpcd-classless-invalid-2", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 32); - ip4_test_route ("dhcp-dhcpcd-classless-invalid-2", ip4_config, 1, - expected_route2_dest, expected_route2_gw, 32); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32); + ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32); g_hash_table_destroy (options); } @@ -516,7 +427,7 @@ test_dhclient_invalid_classless_routes_3 (void) NMIP4Config *ip4_config; const char *expected_route1_dest = "192.168.10.0"; const char *expected_route1_gw = "192.168.1.1"; - static Option data[] = { + static const Option data[] = { { "rfc3442_classless_static_routes", "24 192 168 10 192 168 1 1 32 128 10 17 66 41" }, { NULL, NULL } }; @@ -527,15 +438,12 @@ test_dhclient_invalid_classless_routes_3 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*ignoring invalid classless static routes*"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhclient-classless-invalid-3", "failed to parse DHCP4 options"); + g_assert (ip4_config); g_test_assert_expected_messages (); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1, - "dhcp-dhclient-classless-invalid-3", "unexpected number of IP routes"); - ip4_test_route ("dhcp-dhclient-classless-invalid-3", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 24); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); g_hash_table_destroy (options); } @@ -558,15 +466,12 @@ test_dhcpcd_invalid_classless_routes_3 (void) g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*DHCP provided invalid classless static route*"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhcpcd-classless-invalid-3", "failed to parse DHCP4 options"); + g_assert (ip4_config); g_test_assert_expected_messages (); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1, - "dhcp-dhcpcd-classless-invalid-3", "unexpected number of IP routes"); - ip4_test_route ("dhcp-dhcpcd-classless-invalid-3", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 24); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); g_hash_table_destroy (options); } @@ -587,17 +492,14 @@ test_dhclient_gw_in_classless_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhclient-classless-gateway", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1, - "dhcp-dhclient-classless-gateway", "unexpected number of IP routes"); - ip4_test_route ("dhcp-dhclient-classless-gateway", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 24); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); /* Gateway */ - ip4_test_gateway ("dhcp-dhclient-classless-gateway", ip4_config, expected_gateway); + ip4_test_gateway (ip4_config, expected_gateway); g_hash_table_destroy (options); } @@ -618,26 +520,18 @@ test_dhcpcd_gw_in_classless_routes (void) options = fill_table (generic_options, NULL); options = fill_table (data, options); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-dhcpcd-classless-gateway", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* IP4 routes */ - ASSERT (nm_ip4_config_get_num_routes (ip4_config) == 1, - "dhcp-dhcpcd-classless-gateway", "unexpected number of IP routes"); - ip4_test_route ("dhcp-dhcpcd-classless-gateway", ip4_config, 0, - expected_route1_dest, expected_route1_gw, 24); + g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1); + ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24); /* Gateway */ - ip4_test_gateway ("dhcp-dhcpcd-classless-gateway", ip4_config, expected_gateway); + ip4_test_gateway (ip4_config, expected_gateway); g_hash_table_destroy (options); } -static Option escaped_searches_options[] = { - { "domain_search", "host1\\032host2\\032host3" }, - { NULL, NULL } -}; - static void test_escaped_domain_searches (void) { @@ -646,50 +540,46 @@ test_escaped_domain_searches (void) const char *expected_search0 = "host1"; const char *expected_search1 = "host2"; const char *expected_search2 = "host3"; + static const Option data[] = { + { "domain_search", "host1\\032host2\\032host3" }, + { NULL, NULL } + }; options = fill_table (generic_options, NULL); - options = fill_table (escaped_searches_options, options); + options = fill_table (data, options); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-escaped-domain-searches", "failed to parse DHCP4 options"); + g_assert (ip4_config); /* domain searches */ - ASSERT (nm_ip4_config_get_num_searches (ip4_config) == 3, - "dhcp-escaped-domain-searches", "unexpected number of searches"); - ASSERT (!strcmp (nm_ip4_config_get_search (ip4_config, 0), expected_search0), - "dhcp-escaped-domain-searches", "unexpected domain search #1"); - ASSERT (!strcmp (nm_ip4_config_get_search (ip4_config, 1), expected_search1), - "dhcp-escaped-domain-searches", "unexpected domain search #1"); - ASSERT (!strcmp (nm_ip4_config_get_search (ip4_config, 2), expected_search2), - "dhcp-escaped-domain-searches", "unexpected domain search #1"); + g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 3); + g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 0), ==, expected_search0); + g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 1), ==, expected_search1); + g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 2), ==, expected_search2); g_hash_table_destroy (options); } -static Option invalid_escaped_searches_options[] = { - { "domain_search", "host1\\aahost2\\032host3" }, - { NULL, NULL } -}; - static void test_invalid_escaped_domain_searches (void) { GHashTable *options; NMIP4Config *ip4_config; + static const Option data[] = { + { "domain_search", "host1\\aahost2\\032host3" }, + { NULL, NULL } + }; options = fill_table (generic_options, NULL); - options = fill_table (invalid_escaped_searches_options, options); + options = fill_table (data, options); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, "*invalid domain search*"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-invalid-escaped-domain-searches", "failed to parse DHCP4 options"); + g_assert (ip4_config); g_test_assert_expected_messages (); /* domain searches */ - ASSERT (nm_ip4_config_get_num_searches (ip4_config) == 0, - "dhcp-invalid-escaped-domain-searches", "unexpected domain searches"); + g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 0); g_hash_table_destroy (options); } @@ -706,19 +596,12 @@ test_ip4_missing_prefix (const char *ip, guint32 expected_prefix) g_hash_table_remove (options, "subnet_mask"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-ip4-missing-prefix", "failed to parse DHCP4 options"); - - ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1, - "dhcp-ip4-missing-prefix", "unexpected number of IP4 addresses (not 1)"); + g_assert (ip4_config); + g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); address = nm_ip4_config_get_address (ip4_config, 0); - ASSERT (address, - "dhcp-ip4-missing-prefix", "missing IP4 address #1"); - - ASSERT (address->plen == expected_prefix, - "dhcp-ip4-missing-prefix", "unexpected IP4 address prefix %d (expected %d)", - address->plen, expected_prefix); + g_assert (address); + g_assert_cmpint (address->plen, ==, expected_prefix); g_hash_table_destroy (options); } @@ -758,19 +641,12 @@ test_ip4_prefix_classless (void) g_hash_table_insert (options, "subnet_mask", "255.255.252.0"); ip4_config = nm_dhcp_utils_ip4_config_from_options ("eth0", options, 0); - ASSERT (ip4_config != NULL, - "dhcp-ip4-prefix-classless", "failed to parse DHCP4 options"); - - ASSERT (nm_ip4_config_get_num_addresses (ip4_config) == 1, - "dhcp-ip4-prefix-classless", "unexpected number of IP4 addresses (not 1)"); + g_assert (ip4_config); + g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1); address = nm_ip4_config_get_address (ip4_config, 0); - ASSERT (address, - "dhcp-ip4-prefix-classless", "missing IP4 address #1"); - - ASSERT (address->plen == 22, - "dhcp-ip4-prefix-classless", "unexpected IP4 address prefix %d (expected 22)", - address->plen); + g_assert (address); + g_assert_cmpint (address->plen, ==, 22); g_hash_table_destroy (options); } |