ifcfg-rh: use GLib test functions in new testcases for DNS options

This commit is contained in:
Beniamino Galvani
2015-05-13 08:40:05 +02:00
parent 66e63c1632
commit 58236b0ab2

View File

@@ -2511,54 +2511,28 @@ test_read_dns_options (void)
TYPE_ETHERNET, TYPE_ETHERNET,
&unmanaged, &unmanaged,
&error); &error);
ASSERT (connection != NULL, g_assert (connection);
"read-dns-options", g_assert (nm_connection_verify (connection, &error));
"failed to read %s: %s", TEST_IFCFG_DNS_OPTIONS, error->message); g_assert_cmpstr (unmanaged, ==, NULL);
ASSERT (nm_connection_verify (connection, &error),
"read-dns-options",
"failed to verify %s: %s", TEST_IFCFG_DNS_OPTIONS, error->message);
ASSERT (unmanaged == NULL,
"read-dns-options",
"failed to verify %s: unexpected unmanaged value", TEST_IFCFG_DNS_OPTIONS);
s_ip4 = nm_connection_get_setting_ip4_config (connection); s_ip4 = nm_connection_get_setting_ip4_config (connection);
ASSERT (s_ip4 != NULL, g_assert (s_ip4);
"read-dns-options",
"failed to verify %s: missing %s setting", TEST_IFCFG_DNS_OPTIONS,
NM_SETTING_IP4_CONFIG_SETTING_NAME);
s_ip6 = nm_connection_get_setting_ip6_config (connection); s_ip6 = nm_connection_get_setting_ip6_config (connection);
ASSERT (s_ip6 != NULL, g_assert (s_ip6);
"read-dns-options",
"failed to verify %s: missing %s setting", TEST_IFCFG_DNS_OPTIONS,
NM_SETTING_IP6_CONFIG_SETTING_NAME);
i = nm_setting_ip_config_get_num_dns_options (s_ip4); i = nm_setting_ip_config_get_num_dns_options (s_ip4);
ASSERT (i == options_len, g_assert_cmpint (i, ==, options_len);
"read-dns-options",
"failed to verify %s: wrong IPv4 DNS options number %u",
TEST_IFCFG_DNS_OPTIONS, i);
i = nm_setting_ip_config_get_num_dns_options (s_ip6); i = nm_setting_ip_config_get_num_dns_options (s_ip6);
ASSERT (i == options_len, g_assert_cmpint (i, ==, options_len);
"read-dns-options",
"failed to verify %s: wrong IPv6 DNS options number %u",
TEST_IFCFG_DNS_OPTIONS, i);
for (i = 0; i < options_len; i++) { for (i = 0; i < options_len; i++) {
option = nm_setting_ip_config_get_dns_option (s_ip4, i); option = nm_setting_ip_config_get_dns_option (s_ip4, i);
ASSERT (strcmp (options[i], option) == 0, g_assert_cmpstr (options[i], ==, option);
"read-dns-options",
"failed to verify %s: wrong IPv4 DNS option %u '%s'",
TEST_IFCFG_DNS_OPTIONS, i, option);
option = nm_setting_ip_config_get_dns_option (s_ip6, i); option = nm_setting_ip_config_get_dns_option (s_ip6, i);
ASSERT (strcmp (options[i], option) == 0, g_assert_cmpstr (options[i], ==, option);
"read-dns-options",
"failed to verify %s: wrong IPv6 DNS option %u '%s'"
TEST_IFCFG_DNS_OPTIONS, i, option);
} }
g_object_unref (connection); g_object_unref (connection);
@@ -2639,24 +2613,15 @@ test_write_dns_options (void)
nm_setting_ip_config_add_dns_option (s_ip4, "debug"); nm_setting_ip_config_add_dns_option (s_ip4, "debug");
nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3"); nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3");
ASSERT (nm_connection_verify (connection, &error) == TRUE, g_assert (nm_connection_verify (connection, &error));
"write-dns-options",
"failed to verify connection: %s",
(error && error->message) ? error->message : "(unknown)");
/* Save the ifcfg */ /* Save the ifcfg */
success = writer_new_connection (connection, success = writer_new_connection (connection,
TEST_SCRATCH_DIR "/network-scripts/", TEST_SCRATCH_DIR "/network-scripts/",
&testfile, &testfile,
&error); &error);
ASSERT (success == TRUE, g_assert (success);
"write-dns-options", g_assert (testfile);
"failed to write connection to disk: %s",
(error && error->message) ? error->message : "(unknown)");
ASSERT (testfile != NULL,
"write-dns-options",
"didn't get ifcfg file path back after writing connection");
/* reread will be normalized, so we must normalize connection too. */ /* reread will be normalized, so we must normalize connection too. */
nm_connection_normalize (connection, NULL, NULL, NULL); nm_connection_normalize (connection, NULL, NULL, NULL);
@@ -2678,17 +2643,9 @@ test_write_dns_options (void)
nm_setting_ip_config_add_dns_option (s_ip6, "debug"); nm_setting_ip_config_add_dns_option (s_ip6, "debug");
nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3"); nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3");
ASSERT (reread != NULL, g_assert (reread);
"write-dns-options", g_assert (nm_connection_verify (reread, &error));
"failed to read %s: %s", testfile, error->message); g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT));
ASSERT (nm_connection_verify (reread, &error),
"write-dns-options",
"failed to verify %s: %s", testfile, error->message);
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
"write-dns-options",
"written and re-read connection weren't the same.");
g_free (testfile); g_free (testfile);
g_object_unref (connection); g_object_unref (connection);
@@ -12663,7 +12620,7 @@ int main (int argc, char **argv)
g_test_add_data_func (TPATH "static-ip6-only-gw/::", "::", test_write_wired_static_ip6_only_gw); g_test_add_data_func (TPATH "static-ip6-only-gw/::", "::", test_write_wired_static_ip6_only_gw);
g_test_add_data_func (TPATH "static-ip6-only-gw/2001:db8:8:4::2", "2001:db8:8:4::2", test_write_wired_static_ip6_only_gw); g_test_add_data_func (TPATH "static-ip6-only-gw/2001:db8:8:4::2", "2001:db8:8:4::2", test_write_wired_static_ip6_only_gw);
g_test_add_data_func (TPATH "static-ip6-only-gw/::ffff:255.255.255.255", "::ffff:255.255.255.255", test_write_wired_static_ip6_only_gw); g_test_add_data_func (TPATH "static-ip6-only-gw/::ffff:255.255.255.255", "::ffff:255.255.255.255", test_write_wired_static_ip6_only_gw);
test_read_dns_options (); g_test_add_func (TPATH "read-dns-options", test_read_dns_options);
test_read_wired_static (TEST_IFCFG_WIRED_STATIC, "System test-wired-static", TRUE); test_read_wired_static (TEST_IFCFG_WIRED_STATIC, "System test-wired-static", TRUE);
test_read_wired_static (TEST_IFCFG_WIRED_STATIC_BOOTPROTO, "System test-wired-static-bootproto", FALSE); test_read_wired_static (TEST_IFCFG_WIRED_STATIC_BOOTPROTO, "System test-wired-static-bootproto", FALSE);
@@ -12814,7 +12771,7 @@ int main (int argc, char **argv)
test_write_vlan (); test_write_vlan ();
test_write_vlan_only_vlanid (); test_write_vlan_only_vlanid ();
test_write_ethernet_missing_ipv6 (); test_write_ethernet_missing_ipv6 ();
test_write_dns_options(); g_test_add_func (TPATH "write-dns-options", test_write_dns_options);
/* iSCSI / ibft */ /* iSCSI / ibft */
g_test_add_func (TPATH "ibft/ignored", test_read_ibft_ignored); g_test_add_func (TPATH "ibft/ignored", test_read_ibft_ignored);