diff options
author | Thomas Haller <thaller@redhat.com> | 2016-10-05 12:35:25 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-10-05 14:46:18 +0200 |
commit | 3e13ebd1c9b0147ef03306a134baed3fb080a633 (patch) | |
tree | 315201581b1105756a974c9c13926c10b7d7b309 | |
parent | 84346d172ae0c4f02e9327feea1d6da26fa3f38d (diff) | |
download | NetworkManager-3e13ebd1c9b0147ef03306a134baed3fb080a633.tar.gz |
keyfile/tests: refactor tests to use cleanup attributes
-rw-r--r-- | src/settings/plugins/keyfile/tests/test-keyfile.c | 439 |
1 files changed, 142 insertions, 297 deletions
diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index e63fa495db..381ae5a14b 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -62,7 +62,7 @@ check_ip_route (NMSettingIPConfig *config, int idx, const char *destination, int static NMConnection * keyfile_read_connection_from_file (const char *filename) { - GError *error = NULL; + gs_free_error GError *error = NULL; NMConnection *connection; g_assert (filename); @@ -78,12 +78,12 @@ keyfile_read_connection_from_file (const char *filename) static void test_read_valid_wired_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; gboolean success; @@ -215,7 +215,6 @@ test_read_valid_wired_connection (void) check_ip_route (s_ip6, 4, "7:8:9:0:1:2:3:4", 125, NULL, 5); check_ip_route (s_ip6, 5, "8:9:0:1:2:3:4:5", 124, NULL, 6); check_ip_route (s_ip6, 6, "8:9:0:1:2:3:4:6", 123, NULL, -1); - g_object_unref (connection); } static void @@ -224,7 +223,7 @@ add_one_ip_address (NMSettingIPConfig *s_ip, guint32 prefix) { NMIPAddress *ip_addr; - GError *error = NULL; + gs_free_error GError *error = NULL; ip_addr = nm_ip_address_new (NM_IS_SETTING_IP4_CONFIG (s_ip) ? AF_INET : AF_INET6, addr, prefix, &error); @@ -241,7 +240,7 @@ add_one_ip_route (NMSettingIPConfig *s_ip, gint64 metric) { NMIPRoute *route; - GError *error = NULL; + gs_free_error GError *error = NULL; g_assert (prefix > 0); route = nm_ip_route_new (NM_IS_SETTING_IP4_CONFIG (s_ip) ? AF_INET : AF_INET6, @@ -255,7 +254,8 @@ add_one_ip_route (NMSettingIPConfig *s_ip, static void test_write_wired_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; @@ -263,9 +263,8 @@ test_write_wired_connection (void) char *uuid; const char *mac = "99:88:77:66:55:44"; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; const char *dns1 = "4.2.2.1"; @@ -382,26 +381,20 @@ test_write_wired_connection (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); - g_assert (reread); - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_ip6_wired_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/Test_Wired_Connection_IP6", NULL); @@ -433,23 +426,21 @@ test_read_ip6_wired_connection (void) g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip6), ==, 1); check_ip_address (s_ip6, 0, "abcd:1234:ffff::cdde", 64); g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip6), ==, "abcd:1234:ffff::cdd1"); - - g_object_unref (connection); } static void test_write_ip6_wired_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; char *uuid; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; const char *dns = "1::cafe"; @@ -515,24 +506,18 @@ test_write_ip6_wired_connection (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); - g_assert (reread); - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_wired_mac_case (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *mac; char expected_mac_address[ETH_ALEN] = { 0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55 }; gboolean success; @@ -562,16 +547,14 @@ test_read_wired_mac_case (void) mac = nm_setting_wired_get_mac_address (s_wired); g_assert (mac); g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac_address, sizeof (expected_mac_address))); - - g_object_unref (connection); } static void test_read_mac_old_format (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWired *s_wired; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; const char *mac; char expected_mac[ETH_ALEN] = { 0x00, 0x11, 0xaa, 0xbb, 0xcc, 0x55 }; @@ -597,16 +580,14 @@ test_read_mac_old_format (void) mac = nm_setting_wired_get_cloned_mac_address (s_wired); g_assert (mac); g_assert (nm_utils_hwaddr_matches (mac, -1, expected_cloned_mac, ETH_ALEN)); - - g_object_unref (connection); } static void test_read_mac_ib_old_format (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingInfiniband *s_ib; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; const char *mac; guint8 expected_mac[INFINIBAND_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, @@ -628,18 +609,16 @@ test_read_mac_ib_old_format (void) mac = nm_setting_infiniband_get_mac_address (s_ib); g_assert (mac); g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, sizeof (expected_mac))); - - g_object_unref (connection); } static void test_read_valid_wireless_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingIPConfig *s_ip4; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *bssid; const guint8 expected_bssid[ETH_ALEN] = { 0x00, 0x1a, 0x33, 0x44, 0x99, 0x82 }; gboolean success; @@ -669,14 +648,13 @@ test_read_valid_wireless_connection (void) s_ip4 = nm_connection_get_setting_ip4_config (connection); g_assert (s_ip4); g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); - - g_object_unref (connection); } static void test_write_wireless_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingIPConfig *s_ip4; @@ -686,9 +664,8 @@ test_write_wireless_connection (void) GBytes *ssid; unsigned char tmpssid[] = { 0x31, 0x33, 0x33, 0x37 }; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; guint64 timestamp = 0x12344433L; @@ -753,23 +730,17 @@ test_write_wireless_connection (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); - g_assert (reread); - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_string_ssid (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWireless *s_wireless; - GError *error = NULL; + gs_free_error GError *error = NULL; GBytes *ssid; const guint8 *ssid_data; gsize ssid_len; @@ -789,23 +760,22 @@ test_read_string_ssid (void) g_assert (ssid); ssid_data = g_bytes_get_data (ssid, &ssid_len); g_assert_cmpmem (ssid_data, ssid_len, expected_ssid, strlen (expected_ssid)); - - g_object_unref (connection); } static void test_write_string_ssid (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wireless; NMSettingIPConfig *s_ip4; - char *uuid, *testfile = NULL, *tmp; + char *uuid, *tmp; + gs_free char *testfile = NULL; GBytes *ssid; unsigned char tmpssid[] = { 65, 49, 50, 51, 32, 46, 92, 46, 36, 37, 126, 93 }; gboolean success; - NMConnection *reread; - GError *error = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; GKeyFile *keyfile; @@ -862,24 +832,17 @@ test_write_string_ssid (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); - g_assert (reread); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_intlist_ssid (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWireless *s_wifi; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; GBytes *ssid; const guint8 *ssid_data; @@ -902,23 +865,22 @@ test_read_intlist_ssid (void) g_assert (ssid != NULL); ssid_data = g_bytes_get_data (ssid, &ssid_len); g_assert_cmpmem (ssid_data, ssid_len, expected_ssid, strlen (expected_ssid)); - - g_object_unref (connection); } static void test_write_intlist_ssid (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; - char *uuid, *testfile = NULL; + char *uuid; + gs_free char *testfile = NULL; GBytes *ssid; unsigned char tmpssid[] = { 65, 49, 50, 51, 0, 50, 50 }; gboolean success; - NMConnection *reread; - GError *error = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; GKeyFile *keyfile; @@ -985,24 +947,17 @@ test_write_intlist_ssid (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_intlike_ssid (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWireless *s_wifi; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; GBytes *ssid; const guint8 *ssid_data; @@ -1026,16 +981,14 @@ test_read_intlike_ssid (void) ssid_data = g_bytes_get_data (ssid, &ssid_len); g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0); - - g_object_unref (connection); } static void test_read_intlike_ssid_2 (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWireless *s_wifi; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; GBytes *ssid; const guint8 *ssid_data; @@ -1059,23 +1012,22 @@ test_read_intlike_ssid_2 (void) ssid_data = g_bytes_get_data (ssid, &ssid_len); g_assert_cmpint (ssid_len, ==, strlen (expected_ssid)); g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0); - - g_object_unref (connection); } static void test_write_intlike_ssid (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; - char *uuid, *testfile = NULL; + char *uuid; + gs_free char *testfile = NULL; GBytes *ssid; unsigned char tmpssid[] = { 49, 48, 49 }; gboolean success; - NMConnection *reread; - GError *error = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; GKeyFile *keyfile; @@ -1138,31 +1090,25 @@ test_write_intlike_ssid (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_write_intlike_ssid_2 (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; - char *uuid, *testfile = NULL; + char *uuid; + gs_free char *testfile = NULL; GBytes *ssid; unsigned char tmpssid[] = { 49, 49, 59, 49, 50, 59, 49, 51, 59}; gboolean success; - NMConnection *reread; - GError *error = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; GKeyFile *keyfile; @@ -1225,27 +1171,20 @@ test_write_intlike_ssid_2 (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_bt_dun_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingBluetooth *s_bluetooth; NMSettingSerial *s_serial; NMSettingGsm *s_gsm; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *bdaddr; const guint8 expected_bdaddr[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; gboolean success; @@ -1281,14 +1220,13 @@ test_read_bt_dun_connection (void) s_serial = nm_connection_get_setting_serial (connection); g_assert (s_serial); g_assert (nm_setting_serial_get_parity (s_serial) == NM_SETTING_SERIAL_PARITY_ODD); - - g_object_unref (connection); } static void test_write_bt_dun_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBluetooth *s_bt; NMSettingIPConfig *s_ip4; @@ -1296,9 +1234,8 @@ test_write_bt_dun_connection (void) char *uuid; const char *bdaddr = "aa:b9:a1:74:55:44"; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; guint64 timestamp = 0x12344433L; @@ -1360,26 +1297,19 @@ test_write_bt_dun_connection (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, NULL); - g_assert (reread); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_gsm_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingSerial *s_serial; NMSettingGsm *s_gsm; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR "/ATT_Data_Connect_Plain", &error); @@ -1416,22 +1346,20 @@ test_read_gsm_connection (void) s_serial = nm_connection_get_setting_serial (connection); g_assert (s_serial); g_assert_cmpint (nm_setting_serial_get_parity (s_serial), ==, NM_SETTING_SERIAL_PARITY_ODD); - - g_object_unref (connection); } static void test_write_gsm_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; NMSettingGsm *s_gsm; char *uuid; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; guint64 timestamp = 0x12344433L; @@ -1490,25 +1418,18 @@ test_write_gsm_connection (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_clear_error (&error); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_wired_8021x_tls_blob_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWired *s_wired; NMSetting8021x *s_8021x; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *tmp; gboolean success; GBytes *blob; @@ -1561,17 +1482,15 @@ test_read_wired_8021x_tls_blob_connection (void) tmp = nm_setting_802_1x_get_private_key_path (s_8021x); g_assert_cmpstr (tmp, ==, "/CASA/dcbw/Desktop/certinfra/client.pem"); - - g_object_unref (connection); } static void test_read_wired_8021x_tls_bad_path_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWired *s_wired; NMSetting8021x *s_8021x; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *tmp; char *tmp2; gboolean success; @@ -1618,16 +1537,15 @@ test_read_wired_8021x_tls_bad_path_connection (void) g_assert_cmpstr (tmp, ==, tmp2); g_free (tmp2); - g_object_unref (connection); } static void test_read_wired_8021x_tls_old_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWired *s_wired; NMSetting8021x *s_8021x; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *tmp; gboolean success; @@ -1670,17 +1588,15 @@ test_read_wired_8021x_tls_old_connection (void) tmp = nm_setting_802_1x_get_private_key_path (s_8021x); g_assert (g_strcmp0 (tmp, "/CASA/dcbw/Desktop/certinfra/client.pem") == 0); - - g_object_unref (connection); } static void test_read_wired_8021x_tls_new_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWired *s_wired; NMSetting8021x *s_8021x; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *tmp; char *tmp2; gboolean success; @@ -1724,7 +1640,6 @@ test_read_wired_8021x_tls_new_connection (void) g_assert_cmpstr (tmp, ==, tmp2); g_free (tmp2); - g_object_unref (connection); } #define TEST_WIRED_TLS_CA_CERT TEST_KEYFILES_DIR"/test-ca-cert.pem" @@ -1741,7 +1656,7 @@ create_wired_tls_connection (NMSetting8021xCKScheme scheme) NMSetting8021x *s_8021x; char *uuid; gboolean success; - GError *error = NULL; + gs_free_error GError *error = NULL; connection = nm_simple_connection_new (); g_assert (connection != NULL); @@ -1815,12 +1730,12 @@ get_path (const char *file, gboolean relative) static void test_write_wired_8021x_tls_connection_path (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; char *tmp, *tmp2; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; GKeyFile *keyfile; gboolean relative = FALSE; @@ -1901,26 +1816,22 @@ test_write_wired_8021x_tls_connection_path (void) g_key_file_free (keyfile); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_write_wired_8021x_tls_connection_blob (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSetting8021x *s_8021x; gboolean success; - NMConnection *reread; - char *testfile = NULL; + gs_free char *testfile = NULL; char *new_ca_cert; char *new_client_cert; char *new_priv_key; const char *uuid; - GError *error = NULL; + gs_free_error GError *error = NULL; GBytes *password_raw = NULL; #define PASSWORD_RAW "password-raw\0test" @@ -1985,7 +1896,6 @@ test_write_wired_8021x_tls_connection_blob (void) g_assert (!memcmp (g_bytes_get_data (password_raw, NULL), PASSWORD_RAW, NM_STRLEN (PASSWORD_RAW))); unlink (testfile); - g_free (testfile); /* Clean up written certs */ unlink (new_ca_cert); @@ -1996,18 +1906,15 @@ test_write_wired_8021x_tls_connection_blob (void) unlink (new_priv_key); g_free (new_priv_key); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_infiniband_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_ib; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *mac; guint8 expected_mac[INFINIBAND_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, @@ -2036,14 +1943,13 @@ test_read_infiniband_connection (void) mac = nm_setting_infiniband_get_mac_address (s_ib); g_assert (mac); g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, sizeof (expected_mac))); - - g_object_unref (connection); } static void test_write_infiniband_connection (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_ib; NMSettingIPConfig *s_ip4; @@ -2051,9 +1957,8 @@ test_write_infiniband_connection (void) char *uuid; const char *mac = "99:88:77:66:55:44:ab:bc:cd:de:ef:f0:0a:1b:2c:3d:4e:5f:6f:ba"; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; @@ -2109,25 +2014,19 @@ test_write_infiniband_connection (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_bridge_main (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; NMSettingBridge *s_bridge; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *expected_id = "Test Bridge Main"; const char *expected_uuid = "8f061643-fe41-4d4c-a8d9-097d26e2ad3a"; gboolean success; @@ -2161,23 +2060,21 @@ test_read_bridge_main (void) g_assert_cmpuint (nm_setting_bridge_get_max_age (s_bridge), ==, 39); g_assert_cmpuint (nm_setting_bridge_get_ageing_time (s_bridge), ==, 235352); g_assert_cmpuint (nm_setting_bridge_get_multicast_snooping (s_bridge), ==, FALSE); - - g_object_unref (connection); } static void test_write_bridge_main (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBridge *s_bridge; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; char *uuid; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; @@ -2233,27 +2130,21 @@ test_write_bridge_main (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_bridge_component (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; NMSettingBridgePort *s_port; NMSettingWired *s_wired; const char *mac; guint8 expected_mac[ETH_ALEN] = { 0x00, 0x22, 0x15, 0x59, 0x62, 0x97 }; - GError *error = NULL; + gs_free_error GError *error = NULL; const char *expected_id = "Test Bridge Component"; const char *expected_uuid = "d7b4f96c-c45e-4298-bef8-f48574f8c1c0"; gboolean success; @@ -2286,23 +2177,21 @@ test_read_bridge_component (void) g_assert (nm_setting_bridge_port_get_hairpin_mode (s_port)); g_assert_cmpuint (nm_setting_bridge_port_get_priority (s_port), ==, 28); g_assert_cmpuint (nm_setting_bridge_port_get_path_cost (s_port), ==, 100); - - g_object_unref (connection); } static void test_write_bridge_component (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBridgePort *s_port; NMSettingWired *s_wired; char *uuid; const char *mac = "99:88:77:66:55:44"; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; @@ -2356,25 +2245,19 @@ test_write_bridge_component (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - - g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_new_wired_group_name (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWired *s_wired; const char *mac; guint8 expected_mac[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_New_Wired_Group_Name", &error); @@ -2392,24 +2275,22 @@ test_read_new_wired_group_name (void) mac = nm_setting_wired_get_mac_address (s_wired); g_assert (mac); g_assert (nm_utils_hwaddr_matches (mac, -1, expected_mac, sizeof (expected_mac))); - - g_object_unref (connection); } static void test_write_new_wired_group_name (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + gs_unref_keyfile GKeyFile *kf = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; char *uuid; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; - GKeyFile *kf; char *s; gint mtu; @@ -2446,7 +2327,6 @@ test_write_new_wired_group_name (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); /* Look at the keyfile itself to ensure we wrote out the new group names and type */ @@ -2465,24 +2345,19 @@ test_write_new_wired_group_name (void) g_assert_cmpint (mtu, ==, 1400); unlink (testfile); - g_free (testfile); - - g_key_file_unref (kf); - g_object_unref (reread); - g_object_unref (connection); } static void test_read_new_wireless_group_names (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; GBytes *ssid; const guint8 *ssid_data; gsize ssid_len; const char *expected_ssid = "foobar"; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_New_Wireless_Group_Names", &error); @@ -2509,14 +2384,14 @@ test_read_new_wireless_group_names (void) g_assert (s_wsec); g_assert_cmpstr (nm_setting_wireless_security_get_key_mgmt (s_wsec), ==, "wpa-psk"); g_assert_cmpstr (nm_setting_wireless_security_get_psk (s_wsec), ==, "s3cu4e passphrase"); - - g_object_unref (connection); } static void test_write_new_wireless_group_names (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + gs_unref_keyfile GKeyFile *kf = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; @@ -2525,12 +2400,10 @@ test_write_new_wireless_group_names (void) unsigned char tmpssid[] = { 0x31, 0x33, 0x33, 0x37 }; const char *expected_psk = "asdfasdfasdfa12315"; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; - GKeyFile *kf; char *s; connection = nm_simple_connection_new (); @@ -2579,7 +2452,6 @@ test_write_new_wireless_group_names (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); /* Look at the keyfile itself to ensure we wrote out the new group names and type */ @@ -2604,19 +2476,14 @@ test_write_new_wireless_group_names (void) g_free (s); unlink (testfile); - g_free (testfile); - - g_key_file_unref (kf); - g_object_unref (reread); - g_object_unref (connection); } static void test_read_missing_vlan_setting (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingVlan *s_vlan; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Setting", &error); @@ -2631,16 +2498,14 @@ test_read_missing_vlan_setting (void) g_assert (s_vlan); g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 0); g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref (connection); } static void test_read_missing_vlan_flags (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingVlan *s_vlan; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_Vlan_Flags", &error); @@ -2657,15 +2522,13 @@ test_read_missing_vlan_flags (void) g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 444); g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "em1"); g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); - - g_object_unref (connection); } static void test_read_missing_id_uuid (void) { - NMConnection *connection; - GError *error = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Missing_ID_UUID", &error); @@ -2678,14 +2541,12 @@ test_read_missing_id_uuid (void) /* Ensure the ID and UUID properties are there */ g_assert_cmpstr (nm_connection_get_id (connection), ==, "Test_Missing_ID_UUID"); g_assert (nm_connection_get_uuid (connection)); - - g_object_unref (connection); } static void test_read_minimal (void) { - NMConnection *connection = NULL; + gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *con_archetype = NULL; NMSettingConnection *s_con; @@ -2717,7 +2578,7 @@ test_read_minimal (void) static void test_read_minimal_slave (void) { - NMConnection *connection = NULL; + gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *con_archetype = NULL; NMSettingConnection *s_con; @@ -2769,9 +2630,9 @@ test_read_minimal_slave (void) static void test_read_enum_property (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingIPConfig *s_ip6; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Enum_Property", &error); @@ -2785,22 +2646,20 @@ test_read_enum_property (void) s_ip6 = nm_connection_get_setting_ip6_config (connection); g_assert (s_ip6); g_assert_cmpint (nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6)), ==, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR); - - g_object_unref (connection); } static void test_write_enum_property (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip6; char *uuid; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; @@ -2844,23 +2703,17 @@ test_write_enum_property (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - nmtst_assert_connection_equals (reread, FALSE, connection, FALSE); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } static void test_read_flags_property (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingGsm *s_gsm; - GError *error = NULL; + gs_free_error GError *error = NULL; gboolean success; connection = nm_keyfile_plugin_connection_from_file (TEST_KEYFILES_DIR"/Test_Flags_Property", &error); @@ -2875,21 +2728,19 @@ test_read_flags_property (void) g_assert (s_gsm); g_assert_cmpint (nm_setting_gsm_get_password_flags (s_gsm), ==, NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED); - - g_object_unref (connection); } static void test_write_flags_property (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSetting *s_gsm; char *uuid; gboolean success; - NMConnection *reread; - char *testfile = NULL; - GError *error = NULL; + gs_free char *testfile = NULL; + gs_free_error GError *error = NULL; pid_t owner_grp; uid_t owner_uid; @@ -2931,15 +2782,9 @@ test_write_flags_property (void) /* Read the connection back in and compare it to the one we just wrote out */ reread = nm_keyfile_plugin_connection_from_file (testfile, &error); g_assert_no_error (error); - g_assert (reread); - nmtst_assert_connection_equals (reread, FALSE, connection, FALSE); unlink (testfile); - g_free (testfile); - - g_object_unref (reread); - g_object_unref (connection); } /*****************************************************************************/ |