mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 14:10:36 +01:00
tests: minor code cleanup in tests
Use nmtst_assert_success(), nm_auto() macros, and minor cleanups.
This commit is contained in:
parent
1b448aeb30
commit
dd4a6f307c
5 changed files with 24 additions and 38 deletions
|
|
@ -5340,17 +5340,17 @@ test_hexstr2bin (void)
|
|||
{ "aab:ccc:ddd" },
|
||||
{ "aab::ccc:ddd" },
|
||||
};
|
||||
GBytes *b;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (items); i++) {
|
||||
gs_unref_bytes GBytes *b = NULL;
|
||||
|
||||
b = nm_utils_hexstr2bin (items[i].str);
|
||||
if (items[i].expected_len)
|
||||
g_assert (b);
|
||||
else
|
||||
g_assert (!b);
|
||||
g_assert (nm_utils_gbytes_equal_mem (b, items[i].expected, items[i].expected_len));
|
||||
g_bytes_unref (b);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -275,8 +275,9 @@ _keyfile_convert (NMConnection **con,
|
|||
|
||||
b1 = nm_setting_802_1x_get_ca_cert_blob (s1);
|
||||
b2 = nm_setting_802_1x_get_ca_cert_blob (s2);
|
||||
g_assert_cmpint (g_bytes_get_size (b1), ==, g_bytes_get_size (b2));
|
||||
g_assert (memcmp (g_bytes_get_data (b1, NULL), g_bytes_get_data (b2, NULL), g_bytes_get_size (b1)) == 0);
|
||||
g_assert (b1);
|
||||
g_assert (b2);
|
||||
g_assert (g_bytes_equal (b1, b2));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ compare_blob_data (const char *test,
|
|||
const char *key_path,
|
||||
GBytes *key)
|
||||
{
|
||||
char *contents = NULL;
|
||||
gs_free char *contents = NULL;
|
||||
gsize len = 0;
|
||||
GError *error = NULL;
|
||||
gboolean success;
|
||||
|
|
@ -61,8 +61,6 @@ compare_blob_data (const char *test,
|
|||
nmtst_assert_success (success, error);
|
||||
|
||||
g_assert_cmpmem (contents, len, g_bytes_get_data (key, NULL), g_bytes_get_size (key));
|
||||
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -675,22 +675,18 @@ test_existing_multiline_alsoreq (void)
|
|||
static void
|
||||
test_one_duid (const char *escaped, const guint8 *unescaped, guint len)
|
||||
{
|
||||
GBytes *t;
|
||||
char *w;
|
||||
gs_unref_bytes GBytes *t1 = NULL;
|
||||
gs_unref_bytes GBytes *t2 = NULL;
|
||||
gs_free char *w = NULL;
|
||||
|
||||
t = nm_dhcp_dhclient_unescape_duid (escaped);
|
||||
g_assert (t);
|
||||
g_assert (nm_utils_gbytes_equal_mem (t, unescaped, len));
|
||||
g_bytes_unref (t);
|
||||
t1 = nm_dhcp_dhclient_unescape_duid (escaped);
|
||||
g_assert (t1);
|
||||
g_assert (nm_utils_gbytes_equal_mem (t1, unescaped, len));
|
||||
|
||||
t = g_bytes_new_static (unescaped, len);
|
||||
w = nm_dhcp_dhclient_escape_duid (t);
|
||||
t2 = g_bytes_new (unescaped, len);
|
||||
w = nm_dhcp_dhclient_escape_duid (t2);
|
||||
g_assert (w);
|
||||
g_assert_cmpint (strlen (escaped), ==, strlen (w));
|
||||
g_assert_cmpstr (escaped, ==, w);
|
||||
|
||||
g_bytes_unref (t);
|
||||
g_free (w);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -732,8 +728,8 @@ test_read_duid_from_leasefile (void)
|
|||
GError *error = NULL;
|
||||
|
||||
duid = nm_dhcp_dhclient_read_duid (TEST_DIR"/test-dhclient-duid.leases", &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (duid);
|
||||
nmtst_assert_success (duid, error);
|
||||
|
||||
g_assert (nm_utils_gbytes_equal_mem (duid, expected, G_N_ELEMENTS (expected)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1021,14 +1021,11 @@ test_read_intlike_ssid (void)
|
|||
const char *expected_ssid = "101";
|
||||
|
||||
connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID", &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection);
|
||||
nmtst_assert_success (connection, error);
|
||||
|
||||
success = nm_connection_verify (connection, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
nmtst_assert_success (success, error);
|
||||
|
||||
/* SSID */
|
||||
s_wifi = nm_connection_get_setting_wireless (connection);
|
||||
g_assert (s_wifi);
|
||||
|
||||
|
|
@ -1048,14 +1045,11 @@ test_read_intlike_ssid_2 (void)
|
|||
const char *expected_ssid = "11;12;13;";
|
||||
|
||||
connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID_2", &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection);
|
||||
nmtst_assert_success (connection, error);
|
||||
|
||||
success = nm_connection_verify (connection, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
nmtst_assert_success (success, error);
|
||||
|
||||
/* SSID */
|
||||
s_wifi = nm_connection_get_setting_wireless (connection);
|
||||
g_assert (s_wifi);
|
||||
|
||||
|
|
@ -2231,13 +2225,11 @@ test_read_new_wireless_group_names (void)
|
|||
gboolean success;
|
||||
|
||||
connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR"/Test_New_Wireless_Group_Names", &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection);
|
||||
success = nm_connection_verify (connection, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
nmtst_assert_success (connection, error);
|
||||
|
||||
success = nm_connection_verify (connection, &error);
|
||||
nmtst_assert_success (success, error);
|
||||
|
||||
/* Wifi setting */
|
||||
s_wifi = nm_connection_get_setting_wireless (connection);
|
||||
g_assert (s_wifi);
|
||||
|
||||
|
|
@ -2247,7 +2239,6 @@ test_read_new_wireless_group_names (void)
|
|||
|
||||
g_assert_cmpstr (nm_setting_wireless_get_mode (s_wifi), ==, NM_SETTING_WIRELESS_MODE_INFRA);
|
||||
|
||||
/* Wifi security setting */
|
||||
s_wsec = nm_connection_get_setting_wireless_security (connection);
|
||||
g_assert (s_wsec);
|
||||
g_assert_cmpstr (nm_setting_wireless_security_get_key_mgmt (s_wsec), ==, "wpa-psk");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue