From ecda08e1d13154c991bd54ae9159254584afc4a5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 6 Nov 2016 14:00:51 +0100 Subject: [PATCH] ifcfg-rh/tests: some refactoring of tests When introducing the macro _svGetValue_check() we replace the call to svGetValueString() with svGetValue(). That makes a difference only when asserting against a %NULL value. It's fair to assume that in such case we actually want to assert that the value is unset, and not possibly empty. --- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 1327 +++++------------ 1 file changed, 353 insertions(+), 974 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index e5a0e9d992..c5e5456af2 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -61,6 +61,41 @@ /*****************************************************************************/ +#define _svOpenFile(testfile) \ + ({ \ + shvarFile *_f; \ + GError *_error = NULL; \ + const char *_testfile = (testfile); \ + \ + g_assert (_testfile); \ + _f = svOpenFile (_testfile, &_error); \ + nmtst_assert_success (_f, _error); \ + _f; \ + }) + +#define _svGetValue_check(sv, key, expected_value) \ + G_STMT_START { \ + gs_free char *_to_free = NULL; \ + \ + g_assert_cmpstr (svGetValue (sv, key, &_to_free), ==, expected_value); \ + } G_STMT_END + +#define _writer_update_connection(connection, ifcfg_dir, filename) \ + G_STMT_START { \ + NMConnection *_connection = (connection); \ + const char *_ifcfg_dir = (ifcfg_dir); \ + const char *_filename = (filename); \ + GError *_error = NULL; \ + gboolean _success; \ + \ + g_assert (NM_IS_CONNECTION (connection)); \ + g_assert (_ifcfg_dir && _ifcfg_dir[0]); \ + g_assert (_filename && _filename[0]); \ + \ + _success = writer_update_connection (_connection, _ifcfg_dir, _filename, &_error); \ + nmtst_assert_success (_success, _error); \ + } G_STMT_END + static NMConnection * _connection_from_file (const char *filename, const char *network_file, @@ -1497,7 +1532,7 @@ test_read_wired_8021x_tls_secret_flags (gconstpointer test_data) static void test_read_write_802_1X_subj_matches (void) { - nmtst_auto_unlinkfile char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; gs_unref_object NMConnection *connection = NULL; gs_unref_object NMConnection *reread = NULL; NMSetting8021x *s_8021x; @@ -1526,11 +1561,11 @@ test_read_write_802_1X_subj_matches (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*missing IEEE_8021X_CA_CERT*peap*"); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); g_test_assert_expected_messages (); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -1746,10 +1781,7 @@ test_clear_master (void) gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; char *unmanaged = NULL; - GError *error = NULL; - gboolean success; shvarFile *f; - char *val; /* 1. load the bridge slave connection from disk */ connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bridge-component", @@ -1777,21 +1809,15 @@ test_clear_master (void) g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NULL); /* 4. update the connection on disk */ - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - &error); - nmtst_assert_success (success, error); + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); keyfile = utils_get_keys_path (testfile); g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); /* 5. check that BRIDGE variable has been removed */ - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - val = svGetValueString (f, "BRIDGE"); - g_assert (!val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "BRIDGE", NULL); svCloseFile (f); } @@ -1807,7 +1833,6 @@ test_write_dns_options (void) NMSettingIPConfig *s_ip6; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; NMIPAddress *addr; NMIPAddress *addr6; GError *error = NULL; @@ -1818,14 +1843,12 @@ test_write_dns_options (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test DNS options", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -2402,16 +2425,10 @@ test_read_wifi_leap_secret_flags (gconstpointer test_data) static void test_ifcfg_no_trailing_newline (void) { - gs_free_error GError *error = NULL; shvarFile *sv; - gs_free char *value = NULL; - - sv = svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk", &error); - nmtst_assert_success (sv, error); - - value = svGetValueString (sv, "LAST_ENTRY"); - g_assert_cmpstr (value, ==, "no-newline"); + sv = _svOpenFile (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-wifi-wpa-psk"); + _svGetValue_check (sv, "LAST_ENTRY", "no-newline"); svCloseFile (sv); } @@ -2983,11 +3000,11 @@ test_read_wifi_hidden (void) static void test_write_wifi_hidden (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -2998,13 +3015,11 @@ test_write_wifi_hidden (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write WiFi Hidden", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -3026,33 +3041,21 @@ test_write_wifi_hidden (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "SSID_HIDDEN"); - g_assert (val); - g_assert_cmpstr (val, ==, "yes"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "SSID_HIDDEN", "yes"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_wifi_mac_random (gconstpointer user_data) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; + gs_free char *path = NULL; NMSettingWireless *s_wifi; - char *path; const char *name; gpointer value_p; NMSettingMacRandomization value; @@ -3062,23 +3065,21 @@ test_read_wifi_mac_random (gconstpointer user_data) path = g_strdup_printf (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-mac-random-%s", name); connection = _connection_from_file (path, NULL, TYPE_WIRELESS, NULL); - g_free (path); s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); g_assert_cmpint (nm_setting_wireless_get_mac_address_randomization (s_wifi), ==, value); - - g_object_unref (connection); } static void test_write_wifi_mac_random (gconstpointer user_data) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; + char *val; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -3097,14 +3098,12 @@ test_write_wifi_mac_random (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); val = g_strdup_printf ("Test Write WiFi MAC %s", name); g_object_set (s_con, NM_SETTING_CONNECTION_ID, val, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); g_free (val); /* Wifi setting */ @@ -3125,35 +3124,25 @@ test_write_wifi_mac_random (gconstpointer user_data) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "MAC_ADDRESS_RANDOMIZATION"); - g_assert_cmpstr (val, ==, write_expected); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "MAC_ADDRESS_RANDOMIZATION", write_expected); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_wake_on_lan (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingWiredWakeOnLan wol; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; + char *val; shvarFile *f; connection = nm_simple_connection_new (); @@ -3162,13 +3151,11 @@ test_write_wired_wake_on_lan (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Wake-on-LAN", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3189,11 +3176,7 @@ test_write_wired_wake_on_lan (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that the key was written. */ + f = _svOpenFile (testfile); val = svGetValueString (f, "ETHTOOL_OPTS"); g_assert (val); g_assert (strstr (val, "wol")); @@ -3202,13 +3185,8 @@ test_write_wired_wake_on_lan (void) svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -3235,11 +3213,11 @@ test_read_wifi_band_a (void) static void test_write_wifi_band_a (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; shvarFile *f; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; @@ -3250,13 +3228,11 @@ test_write_wifi_band_a (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write WiFi Band A", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -3278,25 +3254,13 @@ test_write_wifi_band_a (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "BAND"); - g_assert (val); - g_assert_cmpstr (val, ==, "a"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "BAND", "a"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -3537,19 +3501,18 @@ test_read_wifi_wep_agent_keys (void) static void test_write_wired_static (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4, *reread_s_ip4; NMSettingIPConfig *s_ip6, *reread_s_ip6; - char *uuid; NMIPAddress *addr; NMIPAddress *addr6; NMIPRoute *route6; GError *error = NULL; - char *testfile = NULL; - char *route6file = NULL; connection = nm_simple_connection_new (); @@ -3557,15 +3520,13 @@ test_write_wired_static (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, 1, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3655,9 +3616,9 @@ test_write_wired_static (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", &testfile); + route6file = utils_get_route6_path (testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); /* FIXME: currently DNS domains from IPv6 setting are stored in 'DOMAIN' key in ifcfg-file * However after re-reading they are dropped into IPv4 setting. @@ -3676,27 +3637,18 @@ test_write_wired_static (void) nm_connection_add_setting (connection, nm_setting_proxy_new ()); nmtst_assert_connection_equals (connection, FALSE, reread, FALSE); - - route6file = utils_get_route6_path (testfile); - unlink (route6file); - - g_free (testfile); - g_free (route6file); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + 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; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -3704,14 +3656,12 @@ test_write_wired_dhcp (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3745,46 +3695,38 @@ test_write_wired_dhcp (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_dhcp_plus_ip (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-plus-ip", NULL, TYPE_ETHERNET, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_read_write_wired_dhcp_send_hostname (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; const char * dhcp_hostname = "kamil-patka"; - char *written = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-dhcp-send-hostname", NULL, TYPE_ETHERNET, NULL); @@ -3805,11 +3747,9 @@ test_read_write_wired_dhcp_send_hostname (void) _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -3821,24 +3761,20 @@ test_read_write_wired_dhcp_send_hostname (void) g_assert (nm_setting_ip_config_get_dhcp_send_hostname (s_ip4) == FALSE); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, dhcp_hostname); g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip6), ==, dhcp_hostname); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_static_ip6_only (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + 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; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -3846,14 +3782,12 @@ test_write_wired_static_ip6_only (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static IP6 Only", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -3893,13 +3827,8 @@ test_write_wired_static_ip6_only (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } /* Test writing an IPv6 config with varying gateway address. @@ -3913,19 +3842,19 @@ test_write_wired_static_ip6_only (void) static void test_write_wired_static_ip6_only_gw (gconstpointer user_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + 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; NMIPAddress *addr6; GError *error = NULL; - char *testfile = NULL; char *id = NULL; - char *written_ifcfg_gateway; + gs_free char *written_ifcfg_gateway = NULL; const char *gateway6 = user_data; + shvarFile *ifcfg; connection = nm_simple_connection_new (); @@ -3933,15 +3862,13 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); id = g_strdup_printf ("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ? gateway6 : "NULL"); g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); g_free (id); /* Wired setting */ @@ -3986,17 +3913,9 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - { - /* re-read the file to check that what key was written. */ - shvarFile *ifcfg = svOpenFile (testfile, &error); - - g_assert_no_error (error); - g_assert (ifcfg); - written_ifcfg_gateway = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); - svCloseFile (ifcfg); - } - - unlink (testfile); + ifcfg = _svOpenFile (testfile); + written_ifcfg_gateway = svGetValueString (ifcfg, "IPV6_DEFAULTGW"); + svCloseFile (ifcfg); /* access the gateway from the loaded connection. */ s_ip6 = nm_connection_get_setting_ip6_config (reread); @@ -4013,23 +3932,19 @@ test_write_wired_static_ip6_only_gw (gconstpointer user_data) g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip6), ==, gateway6); g_assert_cmpstr (written_ifcfg_gateway, ==, gateway6); } - - g_free (testfile); - g_free (written_ifcfg_gateway); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_write_static_routes_legacy (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_free char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *testfile = NULL; - char *routefile = NULL; - char *route6file = NULL; const char *tmp; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-static-routes-legacy", @@ -4069,36 +3984,27 @@ test_read_write_static_routes_legacy (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); routefile = utils_get_route_path (testfile); - unlink (routefile); route6file = utils_get_route6_path (testfile); - unlink (route6file); + g_assert (!g_file_test (route6file, G_FILE_TEST_EXISTS)); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (routefile); - g_free (route6file); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_static_routes (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + 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; NMIPAddress *addr; NMIPRoute *route; GError *error = NULL; - char *testfile = NULL; - char *routefile = NULL; connection = nm_simple_connection_new (); @@ -4106,14 +4012,12 @@ test_write_wired_static_routes (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired Static Routes", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4176,17 +4080,10 @@ test_write_wired_static_routes (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); routefile = utils_get_route_path (testfile); - unlink (routefile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (routefile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -4201,7 +4098,6 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; - char *uuid; gboolean success; GError *error = NULL; @@ -4211,14 +4107,12 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired DHCP 802.1x PEAP MSCHAPv2", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4269,26 +4163,25 @@ test_write_wired_dhcp_8021x_peap_mschapv2 (void) reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - keyfile = utils_get_keys_path (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); + + keyfile = utils_get_keys_path (testfile); } static void test_write_wired_8021x_tls (gconstpointer test_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSetting8021x *s_8021x; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *pw; char *tmp; @@ -4301,36 +4194,29 @@ test_write_wired_8021x_tls (gconstpointer test_data) flags = GPOINTER_TO_INT (flags_p); connection = nm_simple_connection_new (); - g_assert (connection != NULL); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired 802.1x TLS Blobs", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, @@ -4339,7 +4225,6 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* 802.1x setting */ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - g_assert (s_8021x); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); @@ -4388,9 +4273,9 @@ test_write_wired_8021x_tls (gconstpointer test_data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); + keyfile = utils_get_keys_path (testfile); - unlink (keyfile); + nmtst_file_unlink_if_exists (keyfile); /* Ensure the reread connection's certificates and private key are paths; no * matter what scheme was used in the original connection they will be read @@ -4434,21 +4319,16 @@ test_write_wired_8021x_tls (gconstpointer test_data) /* Clean up created certs and keys */ tmp = utils_cert_path (testfile, "ca-cert.der"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); tmp = utils_cert_path (testfile, "client-cert.der"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); tmp = utils_cert_path (testfile, "private-key.pem"); - unlink (tmp); + nmtst_file_unlink_if_exists (tmp); g_free (tmp); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } #define TEST_SCRATCH_ALIAS_BASE TEST_SCRATCH_DIR "/network-scripts/ifcfg-alias0" @@ -4456,45 +4336,43 @@ test_write_wired_8021x_tls (gconstpointer test_data) static void test_write_wired_aliases (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid; int num_addresses = 4; const char *ip[] = { "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" }; const char *label[] = { NULL, "alias0:2", NULL, "alias0:3" }; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; shvarFile *ifcfg; int i, j; + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":3"); + nmtst_file_unlink_if_exists (TEST_SCRATCH_ALIAS_BASE ":5"); + connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "alias0", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -4539,9 +4417,8 @@ test_write_wired_aliases (void) g_assert (!g_file_test (TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); - unlink (TEST_SCRATCH_ALIAS_BASE ":2"); - unlink (TEST_SCRATCH_ALIAS_BASE ":3"); + nmtst_file_unlink (TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink (TEST_SCRATCH_ALIAS_BASE ":3"); /* nm_connection_compare() is not guaranteed to succeed, because the * aliases get read back in essentially random order. So just @@ -4578,20 +4455,17 @@ test_write_wired_aliases (void) /* Gateway */ g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1"); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_gateway (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid, *testfile = NULL, *val; GError *error = NULL; shvarFile *f; NMIPAddress *addr; @@ -4602,13 +4476,11 @@ test_write_gateway (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Static Addresses Gateway", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -4640,77 +4512,37 @@ test_write_gateway (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */ - val = svGetValueString (f, "IPADDR"); - g_assert (val); - g_assert_cmpstr (val, ==, "1.1.1.3"); - g_free (val); - - val = svGetValueString (f, "IPADDR1"); - g_assert (val); - g_assert_cmpstr (val, ==, "2.2.2.5"); - g_free (val); - - val = svGetValueString (f, "IPADDR0"); - g_assert (val == NULL); - - val = svGetValueString (f, "PREFIX"); - g_assert (val); - g_assert_cmpstr (val, ==, "24"); - g_free (val); - - val = svGetValueString (f, "PREFIX1"); - g_assert (val); - g_assert_cmpstr (val, ==, "24"); - g_free (val); - - val = svGetValueString (f, "PREFIX0"); - g_assert (val == NULL); - - val = svGetValueString (f, "GATEWAY"); - g_assert (val); - g_assert_cmpstr (val, ==, "1.1.1.254"); - g_free (val); - - val = svGetValueString (f, "GATEWAY0"); - g_assert (val == NULL); - - val = svGetValueString (f, "GATEWAY1"); - g_assert (val == NULL); - + f = _svOpenFile (testfile); + _svGetValue_check (f, "IPADDR", "1.1.1.3"); + _svGetValue_check (f, "IPADDR1", "2.2.2.5"); + _svGetValue_check (f, "IPADDR0", NULL); + _svGetValue_check (f, "PREFIX", "24"); + _svGetValue_check (f, "PREFIX1", "24"); + _svGetValue_check (f, "PREFIX0", NULL); + _svGetValue_check (f, "GATEWAY", "1.1.1.254"); + _svGetValue_check (f, "GATEWAY0", NULL); + _svGetValue_check (f, "GATEWAY1", NULL); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_open (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - GError *error = NULL; - char *testfile = NULL; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); @@ -4718,14 +4550,12 @@ test_write_wifi_open (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4768,37 +4598,23 @@ test_write_wifi_open (void) reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - /* Now make sure that the ESSID item isn't double-quoted (rh #606518) */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg != NULL); - - tmp = svGetValueString (ifcfg, "ESSID"); - g_assert_cmpstr (tmp, ==, "Test SSID"); - - g_free (tmp); + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "ESSID", "Test SSID"); svCloseFile (ifcfg); - unlink (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_open_hex_ssid (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; GBytes *ssid; const unsigned char ssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd }; @@ -4808,14 +4624,12 @@ test_write_wifi_open_hex_ssid (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Open Hex SSID", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4852,28 +4666,22 @@ test_write_wifi_open_hex_ssid (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -4884,14 +4692,12 @@ test_write_wifi_wep (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -4942,36 +4748,28 @@ test_write_wifi_wep (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_adhoc (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -4983,14 +4781,12 @@ test_write_wifi_wep_adhoc (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP AdHoc", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5045,35 +4841,27 @@ test_write_wifi_wep_adhoc (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_passphrase (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -5084,14 +4872,12 @@ test_write_wifi_wep_passphrase (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Passphrase", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5140,35 +4926,27 @@ test_write_wifi_wep_passphrase (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_40_ascii (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah40"; struct stat statbuf; @@ -5179,14 +4957,12 @@ test_write_wifi_wep_40_ascii (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 40 ASCII", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5237,35 +5013,27 @@ test_write_wifi_wep_40_ascii (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_104_ascii (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah104"; struct stat statbuf; @@ -5276,14 +5044,12 @@ test_write_wifi_wep_104_ascii (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 104 ASCII", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5334,36 +5100,27 @@ test_write_wifi_wep_104_ascii (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_leap (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct stat statbuf; @@ -5374,14 +5131,12 @@ test_write_wifi_leap (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5429,35 +5184,27 @@ test_write_wifi_leap (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); g_assert_cmpint (stat (keyfile, &statbuf), ==, 0); g_assert (S_ISREG (statbuf.st_mode)); g_assert_cmpint ((statbuf.st_mode & 0077), ==, 0); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_leap_secret_flags (gconstpointer data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; NMSettingSecretFlags flags = GPOINTER_TO_UINT (data); @@ -5467,20 +5214,16 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi LEAP Secret Flags", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -5492,7 +5235,6 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -5505,13 +5247,11 @@ test_write_wifi_leap_secret_flags (gconstpointer data) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -5526,7 +5266,6 @@ test_write_wifi_leap_secret_flags (gconstpointer data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); /* No key should be written out since the secret is not system owned */ keyfile = utils_get_keys_path (testfile); @@ -5537,26 +5276,20 @@ test_write_wifi_leap_secret_flags (gconstpointer data) */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, NULL, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_psk (gconstpointer test_data) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; struct { @@ -5574,14 +5307,12 @@ test_write_wifi_wpa_psk (gconstpointer test_data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, args.name, - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5642,33 +5373,25 @@ test_write_wifi_wpa_psk (gconstpointer test_data) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_psk_adhoc (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; NMIPAddress *addr; @@ -5679,14 +5402,12 @@ test_write_wifi_wpa_psk_adhoc (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA PSK", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5748,35 +5469,27 @@ test_write_wifi_wpa_psk_adhoc (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_tls (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -5786,14 +5499,12 @@ test_write_wifi_wpa_eap_tls (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TLS", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -5869,35 +5580,27 @@ test_write_wifi_wpa_eap_tls (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_ttls_tls (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -5907,14 +5610,12 @@ test_write_wifi_wpa_eap_ttls_tls (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (TLS)", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -6006,35 +5707,27 @@ test_write_wifi_wpa_eap_ttls_tls (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wpa_eap_ttls_mschapv2 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -6044,14 +5737,12 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WPA EAP-TTLS (MSCHAPv2)", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); @@ -6120,34 +5811,24 @@ test_write_wifi_wpa_eap_ttls_mschapv2 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); - - keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); + keyfile = utils_get_keys_path (testfile); } static void test_write_wifi_wpa_then_open (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - gboolean success; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; @@ -6156,25 +5837,20 @@ test_write_wifi_wpa_then_open (void) */ connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "random wifi connection", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6188,7 +5864,6 @@ test_write_wifi_wpa_then_open (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6206,16 +5881,12 @@ test_write_wifi_wpa_then_open (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); - g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); - g_object_set (s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, @@ -6239,50 +5910,30 @@ test_write_wifi_wpa_then_open (void) nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); /* Write it back out */ + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); keyfile = utils_get_keys_path (testfile); - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - &error); - g_assert_no_error (error); - g_assert (success); - - unlink (keyfile); - g_free (keyfile); - keyfile = NULL; + g_assert (!g_file_test (keyfile, G_FILE_TEST_EXISTS)); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); - - /* No keyfile since it's an open connection this time */ - keyfile = utils_get_keys_path (testfile); - g_assert (g_file_test (keyfile, G_FILE_TEST_EXISTS) == FALSE); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - unlink (testfile); - g_free (testfile); - g_free (keyfile); - g_object_unref (reread); - - g_object_unref (connection); } static void test_write_wifi_wpa_then_wep_with_perms (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; gboolean success; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; char **perms; const char *ssid_data = "SomeSSID"; @@ -6296,25 +5947,21 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); perms = g_strsplit ("user:superman:", ",", -1); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "random wifi connection 2", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_PERMISSIONS, perms, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); g_strfreev (perms); g_assert_cmpint (nm_setting_connection_get_num_permissions (s_con), ==, 1); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6328,7 +5975,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6346,14 +5992,12 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6377,7 +6021,6 @@ test_write_wifi_wpa_then_wep_with_perms (void) /* Now change the connection to WEP and recheck */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6386,16 +6029,9 @@ test_write_wifi_wpa_then_wep_with_perms (void) nm_setting_wireless_security_set_wep_key (s_wsec, 0, "abraka dabra"); /* Write it back out */ - keyfile = utils_get_keys_path (testfile); - success = writer_update_connection (connection, - TEST_SCRATCH_DIR "/network-scripts/", - testfile, - &error); - g_assert_no_error (error); - g_assert (success); - - g_free (keyfile); - keyfile = NULL; + _writer_update_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); @@ -6406,55 +6042,38 @@ test_write_wifi_wpa_then_wep_with_perms (void) g_assert (success); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); - unlink (testfile); - g_free (keyfile); - - g_free (testfile); - g_object_unref (reread); - - g_object_unref (connection); } static void test_write_wifi_dynamic_wep_leap (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; - GError *error = NULL; - char *testfile = NULL; - char *keyfile = NULL; GBytes *ssid; const char *ssid_data = "blahblah"; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi Dynamic WEP LEAP", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, strlen (ssid_data)); @@ -6468,14 +6087,12 @@ test_write_wifi_dynamic_wep_leap (void) /* Wireless security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); /* Wireless security setting */ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - g_assert (s_8021x); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); nm_setting_802_1x_add_eap_method (s_8021x, "leap"); @@ -6487,13 +6104,11 @@ test_write_wifi_dynamic_wep_leap (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6510,7 +6125,6 @@ test_write_wifi_dynamic_wep_leap (void) reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); keyfile = utils_get_keys_path (testfile); - unlink (keyfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); @@ -6518,38 +6132,23 @@ test_write_wifi_dynamic_wep_leap (void) * did not get written. Check first that the auth alg is not set to "LEAP" * and next that the only IEEE 802.1x EAP method is "LEAP". */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg); - tmp = svGetValueString (ifcfg, "SECURITYMODE"); - g_assert_cmpstr (tmp, ==, NULL); - g_free (tmp); - - tmp = svGetValueString (ifcfg, "IEEE_8021X_EAP_METHODS"); - g_assert_cmpstr (tmp, ==, "LEAP"); - g_free (tmp); - + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "SECURITYMODE", NULL); + _svGetValue_check (ifcfg, "IEEE_8021X_EAP_METHODS", "LEAP"); svCloseFile (ifcfg); - unlink (testfile); - - g_free (testfile); - g_free (keyfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_qeth_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + 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; char **subchans; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -6557,14 +6156,12 @@ test_write_wired_qeth_dhcp (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired qeth Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -6606,50 +6203,37 @@ test_write_wired_qeth_dhcp (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wired_ctc_dhcp (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + 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; char **subchans; - GError *error = NULL; - char *testfile = NULL; shvarFile *ifcfg; - char *tmp; connection = nm_simple_connection_new (); - g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired ctc Static", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); subchans = g_strsplit ("0.0.600,0.0.601", ",", -1); @@ -6662,13 +6246,11 @@ test_write_wired_ctc_dhcp (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6683,43 +6265,30 @@ test_write_wired_ctc_dhcp (void) &testfile); /* Ensure the CTCPROT item gets written out as it's own option */ - ifcfg = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (ifcfg); + ifcfg = _svOpenFile (testfile); - tmp = svGetValueString (ifcfg, "CTCPROT"); - g_assert (tmp); - g_assert_cmpstr (tmp, ==, "0"); - g_free (tmp); + _svGetValue_check (ifcfg, "CTCPROT", "0"); /* And that it's not in the generic OPTIONS string */ - tmp = svGetValueString (ifcfg, "OPTIONS"); - g_assert (tmp == NULL); - g_free (tmp); + _svGetValue_check (ifcfg, "OPTIONS", NULL); svCloseFile (ifcfg); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_permissions (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + 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; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -6727,14 +6296,12 @@ test_write_permissions (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Permissions", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); nm_setting_connection_add_permission (s_con, "user", "blahblah", NULL); nm_setting_connection_add_permission (s_con, "user", "foobar", NULL); @@ -6768,55 +6335,44 @@ test_write_permissions (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_write_wifi_wep_agent_keys (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid; const char *str_ssid = "foobarbaz"; GBytes *ssid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection != NULL); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP Agent Owned", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); - g_free (uuid); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -6826,7 +6382,6 @@ test_write_wifi_wep_agent_keys (void) /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); - g_assert (s_wifi); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (str_ssid, strlen (str_ssid)); @@ -6838,7 +6393,6 @@ test_write_wifi_wep_agent_keys (void) /* Wifi security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - g_assert (s_wsec); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, @@ -6855,7 +6409,6 @@ test_write_wifi_wep_agent_keys (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL); - unlink (testfile); /* Remove the WEP key from the original, because it should not have been * written out to disk as it was agent-owned. The new connection should @@ -6868,10 +6421,6 @@ test_write_wifi_wep_agent_keys (void) NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -6883,7 +6432,6 @@ test_write_wired_pppoe (void) NMSettingIPConfig *s_ip4; NMSettingPppoe *s_pppoe; NMSettingPpp *s_ppp; - char *uuid; GError *error = NULL; connection = nm_simple_connection_new (); @@ -6892,14 +6440,12 @@ test_write_wired_pppoe (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Wired PPPoE", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -6944,7 +6490,6 @@ test_write_vpn (void) NMSettingConnection *s_con; NMSettingIPConfig *s_ip4; NMSettingVpn *s_vpn; - char *uuid; GError *error = NULL; connection = nm_simple_connection_new (); @@ -6953,14 +6498,12 @@ test_write_vpn (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write VPN", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VPN_SETTING_NAME, NULL); - g_free (uuid); /* VPN setting */ s_vpn = (NMSettingVpn *) nm_setting_vpn_new (); @@ -7002,7 +6545,6 @@ test_write_mobile_broadband (gconstpointer data) NMSettingCdma *s_cdma; NMSettingPpp *s_ppp; NMSettingSerial *s_serial; - char *uuid; GError *error = NULL; gboolean gsm = GPOINTER_TO_UINT (data); @@ -7012,14 +6554,12 @@ test_write_mobile_broadband (gconstpointer data) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, gsm ? "Test Write GSM" : "Test Write CDMA", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, gsm ? NM_SETTING_GSM_SETTING_NAME : NM_SETTING_CDMA_SETTING_NAME, NULL); - g_free (uuid); if (gsm) { /* GSM setting */ @@ -7104,39 +6644,34 @@ test_read_bridge_main (void) static void test_write_bridge_main (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + 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; NMIPAddress *addr; static const char *mac = "31:33:33:37:be:cd"; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Main", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, "br0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BRIDGE_SETTING_NAME, NULL); - g_free (uuid); /* bridge setting */ s_bridge = (NMSettingBridge *) nm_setting_bridge_new (); - g_assert (s_bridge); nm_connection_add_setting (connection, NM_SETTING (s_bridge)); g_object_set (s_bridge, @@ -7145,7 +6680,6 @@ test_write_bridge_main (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -7161,7 +6695,6 @@ test_write_bridge_main (void) /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -7177,13 +6710,8 @@ test_write_bridge_main (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BRIDGE, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7213,38 +6741,33 @@ test_read_bridge_component (void) static void test_write_bridge_component (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSetting *s_port; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bridge Component", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "br0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BRIDGE_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); g_object_set (s_wired, @@ -7267,13 +6790,8 @@ test_write_bridge_component (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7506,78 +7024,64 @@ test_read_vlan_flags_2 (void) static void test_write_vlan (void) { - NMConnection *connection; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; connection = _connection_from_file (TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); - - unlink (written); - g_free (written); - - g_object_unref (connection); + &testfile); } static void test_write_vlan_flags (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-flags-2", NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_vlan_only_vlanid (void) { - NMConnection *connection, *reread; - char *written = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; connection = _connection_from_file (TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_VLAN, NULL); _writer_new_connection (connection, TEST_SCRATCH_DIR "/network-scripts/", - &written); + &testfile); - reread = _connection_from_file (written, NULL, TYPE_ETHERNET, NULL); - unlink (written); - g_free (written); + reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); } static void test_write_vlan_reorder_hdr (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingVlan *s_vlan; NMSettingWired *s_wired; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7585,14 +7089,12 @@ test_write_vlan_reorder_hdr (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write VLAN reorder_hdr", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VLAN_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7613,51 +7115,40 @@ test_write_vlan_reorder_hdr (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void test_write_ethernet_missing_ipv6 (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); - g_assert (s_con); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Ethernet Without IPv6 Setting", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); - g_assert (s_wired); nm_connection_add_setting (connection, NM_SETTING (s_wired)); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, @@ -7679,13 +7170,8 @@ test_write_ethernet_missing_ipv6 (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7722,17 +7208,16 @@ test_read_bond_main (void) static void test_write_bond_main (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingBond *s_bond; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; NMSettingWired *s_wired; - char *uuid; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7740,15 +7225,13 @@ test_write_bond_main (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Main", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_INTERFACE_NAME, "bond0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7790,13 +7273,8 @@ test_write_bond_main (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_BOND, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7822,14 +7300,13 @@ test_read_bond_slave (void) static void test_write_bond_slave (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; static const char *mac = "31:33:33:37:be:cd"; guint32 mtu = 1492; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7837,16 +7314,14 @@ test_write_bond_slave (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "bond0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -7864,13 +7339,8 @@ test_write_bond_slave (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -7908,18 +7378,17 @@ test_read_infiniband (void) static void test_write_infiniband (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; guint32 mtu = 65520; - char *uuid; NMIPAddress *addr; GError *error = NULL; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -7927,14 +7396,12 @@ test_write_infiniband (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write InfiniBand", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME, NULL); - g_free (uuid); /* InfiniBand setting */ s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); @@ -7976,19 +7443,14 @@ test_write_infiniband (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_INFINIBAND, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void test_read_bond_slave_ib (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingConnection *s_con; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-bond-slave-ib", @@ -7998,22 +7460,18 @@ test_read_bond_slave_ib (void) g_assert (s_con); g_assert_cmpstr (nm_setting_connection_get_master (s_con), ==, "bond0"); - g_assert_cmpstr (nm_setting_connection_get_slave_type (s_con), ==, NM_SETTING_BOND_SETTING_NAME); - - g_object_unref (connection); } static void test_write_bond_slave_ib (void) { - NMConnection *connection; - NMConnection *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; static const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; - char *uuid; - char *testfile = NULL; connection = nm_simple_connection_new (); @@ -8021,16 +7479,14 @@ test_write_bond_slave_ib (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Bond Slave InfiniBand", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "bond0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME, NULL); - g_free (uuid); /* InfiniBand setting */ s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); @@ -8049,13 +7505,8 @@ test_write_bond_slave_ib (void) &testfile); reread = _connection_from_file (testfile, NULL, NULL, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8145,14 +7596,15 @@ test_read_dcb_basic (void) static void test_write_dcb_basic (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; guint i; - char *uuid, *testfile; const guint group_ids[8] = { 4, 0xF, 6, 0xF, 1, 7, 3, 0xF }; const guint group_bandwidths[8] = { 10, 20, 15, 10, 2, 3, 35, 5 }; const guint bandwidths[8] = { 10, 20, 30, 40, 50, 10, 0, 25 }; @@ -8164,14 +7616,12 @@ test_write_dcb_basic (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, "dcb-test", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, "eth0", NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -8217,19 +7667,14 @@ test_write_dcb_basic (void) &testfile); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void test_read_dcb_default_app_priorities (void) { - NMConnection *connection; + gs_unref_object NMConnection *connection = NULL; NMSettingDcb *s_dcb; connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dcb-default-app-priorities", @@ -8246,8 +7691,6 @@ test_read_dcb_default_app_priorities (void) g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpint (nm_setting_dcb_get_app_fip_priority (s_dcb), ==, -1); - - g_object_unref (connection); } static void @@ -8358,49 +7801,45 @@ test_read_dcb_pgpct_not_100 (void) static void test_read_fcoe_mode (gconstpointer user_data) { + gs_unref_object NMConnection *connection = NULL; + gs_free char *file = NULL; const char *expected_mode = user_data; - NMConnection *connection; NMSettingDcb *s_dcb; - char *file; file = g_strdup_printf (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-fcoe-%s", expected_mode); connection = _connection_from_file (file, NULL, TYPE_ETHERNET, NULL); - g_free (file); s_dcb = nm_connection_get_setting_dcb (connection); g_assert (s_dcb); g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); g_assert_cmpstr (nm_setting_dcb_get_app_fcoe_mode (s_dcb), ==, expected_mode); - - g_object_unref (connection); } static void test_write_fcoe_mode (gconstpointer user_data) { + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; const char *expected_mode = user_data; - NMConnection *connection, *reread; - GError *error = NULL; NMSettingConnection *s_con; NMSettingWired *s_wired; NMSettingDcb *s_dcb; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid, *testfile; + shvarFile *ifcfg; connection = nm_simple_connection_new (); s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, "fcoe-test", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME, "eth0", NULL); - g_free (uuid); /* Wired setting */ s_wired = (NMSettingWired *) nm_setting_wired_new (); @@ -8430,26 +7869,13 @@ test_write_fcoe_mode (gconstpointer user_data) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - { - shvarFile *ifcfg = svOpenFile (testfile, &error); - char *written_mode; - - g_assert_no_error (error); - g_assert (ifcfg); - written_mode = svGetValueString (ifcfg, "DCB_APP_FCOE_MODE"); - svCloseFile (ifcfg); - g_assert_cmpstr (written_mode, ==, expected_mode); - g_free (written_mode); - } + ifcfg = _svOpenFile (testfile); + _svGetValue_check (ifcfg, "DCB_APP_FCOE_MODE", expected_mode); + svCloseFile (ifcfg); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_object_unref (connection); - g_object_unref (reread); - g_free (testfile); } static void @@ -8504,14 +7930,14 @@ test_read_team_master_invalid (gconstpointer user_data) static void test_write_team_master (void) { - NMConnection *connection, *reread; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; NMSettingConnection *s_con; NMSettingTeam *s_team; NMSettingWired *s_wired; NMSettingIPConfig *s_ip4; NMSettingIPConfig *s_ip6; - char *uuid, *testfile = NULL, *val; - GError *error = NULL; const char *expected_config = "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"; shvarFile *f; @@ -8521,14 +7947,12 @@ test_write_team_master (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Master", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_INTERFACE_NAME, "team0", NM_SETTING_CONNECTION_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - g_free (uuid); /* Team setting */ s_team = (NMSettingTeam *) nm_setting_team_new (); @@ -8544,7 +7968,6 @@ test_write_team_master (void) /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - g_assert (s_ip4); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, @@ -8553,7 +7976,6 @@ test_write_team_master (void) /* IP6 setting */ s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - g_assert (s_ip6); nm_connection_add_setting (connection, NM_SETTING (s_ip6)); g_object_set (s_ip6, @@ -8568,30 +7990,14 @@ test_write_team_master (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "DEVICETYPE"); - g_assert (val); - g_assert_cmpstr (val, ==, "Team"); - g_free (val); - val = svGetValueString (f, "TEAM_CONFIG"); - g_assert (val); - g_assert_cmpstr (val, ==, expected_config); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "DEVICETYPE", "Team"); + _svGetValue_check (f, "TEAM_CONFIG", expected_config); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL); - unlink (testfile); - nmtst_assert_connection_equals (connection, TRUE, reread, FALSE); - - g_free (testfile); - g_object_unref (connection); - g_object_unref (reread); } static void @@ -8626,8 +8032,6 @@ test_write_team_port (void) NMSettingConnection *s_con; NMSettingTeamPort *s_team_port; NMSettingWired *s_wired; - char *uuid, *val; - GError *error = NULL; const char *expected_config = "{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }"; shvarFile *f; @@ -8637,15 +8041,13 @@ test_write_team_port (void) s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); - uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Write Team Port", - NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_UUID, nm_utils_uuid_generate_a (), NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, "team0", NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - g_free (uuid); /* Team setting */ s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new (); @@ -8662,23 +8064,11 @@ test_write_team_port (void) TEST_SCRATCH_DIR "/network-scripts/", &testfile); - f = svOpenFile (testfile, &error); - g_assert_no_error (error); - g_assert (f); - - /* re-read the file to check that what key was written. */ - val = svGetValueString (f, "TYPE"); - g_assert (!val); - val = svGetValueString (f, "DEVICETYPE"); - g_assert (val); - g_assert_cmpstr (val, ==, "TeamPort"); - g_free (val); - val = svGetValueString (f, "TEAM_PORT_CONFIG"); - g_assert_cmpstr (val, ==, expected_config); - g_free (val); - val = svGetValueString (f, "TEAM_MASTER"); - g_assert_cmpstr (val, ==, "team0"); - g_free (val); + f = _svOpenFile (testfile); + _svGetValue_check (f, "TYPE", NULL); + _svGetValue_check (f, "DEVICETYPE", "TeamPort"); + _svGetValue_check (f, "TEAM_PORT_CONFIG", expected_config); + _svGetValue_check (f, "TEAM_MASTER", "team0"); svCloseFile (f); reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, @@ -9025,34 +8415,23 @@ test_write_unknown (gconstpointer test_data) gs_free char *file_contents_exp = NULL; gs_free char *tmp = NULL; - sv = svOpenFile (testfile, &error); - nmtst_assert_success (sv, error); + sv = _svOpenFile (testfile); svFileSetName (sv, filename_tmp_1); svFileSetModified (sv); if (g_str_has_suffix (testfile, "ifcfg-test-write-unknown-4")) { - g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "l4x"); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, NULL); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "name3-value"); - nm_clear_g_free (&tmp); + _svGetValue_check (sv, "NAME", "l4x"); + _svGetValue_check (sv, "NAME2", NULL); + _svGetValue_check (sv, "NAME3", "name3-value"); svSetValue (sv, "NAME", "set-by-test1"); svSetValue (sv, "NAME2", "set-by-test2"); svSetValue (sv, "NAME3", "set-by-test3"); - g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "set-by-test1"); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, "set-by-test2"); - nm_clear_g_free (&tmp); - - g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "set-by-test3"); - nm_clear_g_free (&tmp); + _svGetValue_check (sv, "NAME", "set-by-test1"); + _svGetValue_check (sv, "NAME2", "set-by-test2"); + _svGetValue_check (sv, "NAME3", "set-by-test3"); } success = svWriteFile (sv, 0644, &error);