all: use nm_utils_gbytes_equal_mem()
This commit is contained in:
@@ -5345,13 +5345,12 @@ test_hexstr2bin (void)
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (items); i++) {
|
||||
b = nm_utils_hexstr2bin (items[i].str);
|
||||
if (items[i].expected_len) {
|
||||
if (items[i].expected_len)
|
||||
g_assert (b);
|
||||
g_assert_cmpint (g_bytes_get_size (b), ==, items[i].expected_len);
|
||||
g_assert (memcmp (g_bytes_get_data (b, NULL), items[i].expected, g_bytes_get_size (b)) == 0);
|
||||
else
|
||||
g_assert (!b);
|
||||
g_assert (nm_utils_gbytes_equal_mem (b, items[i].expected, items[i].expected_len));
|
||||
g_bytes_unref (b);
|
||||
} else
|
||||
g_assert (b == NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -127,10 +127,8 @@ _assert_gbytes (GBytes *bytes, gconstpointer data, gssize len)
|
||||
|
||||
if (!len)
|
||||
g_assert (!bytes);
|
||||
else {
|
||||
g_assert_cmpint (g_bytes_get_size (bytes), ==, len);
|
||||
g_assert (memcmp (g_bytes_get_data (bytes, NULL), data, len) == 0);
|
||||
}
|
||||
|
||||
g_assert (nm_utils_gbytes_equal_mem (bytes, data, len));
|
||||
}
|
||||
|
||||
static GKeyFile *
|
||||
@@ -344,8 +342,7 @@ _test_8021x_cert_check (NMConnection *con,
|
||||
}
|
||||
|
||||
g_assert (blob);
|
||||
g_assert_cmpint (g_bytes_get_size (blob), ==, val_len);
|
||||
g_assert (!memcmp (g_bytes_get_data (blob, NULL), value, val_len));
|
||||
g_assert (nm_utils_gbytes_equal_mem (blob, value, val_len));
|
||||
|
||||
kval = g_key_file_get_string (keyfile, "802-1x", "ca-cert", NULL);
|
||||
g_assert (kval);
|
||||
|
@@ -844,16 +844,12 @@ demarshal_generic (NMObject *object,
|
||||
g_free (newval);
|
||||
} else if (pspec->value_type == G_TYPE_BYTES) {
|
||||
GBytes **param = (GBytes **)field;
|
||||
gconstpointer val, old_val = NULL;
|
||||
gsize length, old_length = 0;
|
||||
gconstpointer val;
|
||||
gsize length = 0;
|
||||
|
||||
val = g_variant_get_fixed_array (value, &length, 1);
|
||||
|
||||
if (*param)
|
||||
old_val = g_bytes_get_data (*param, &old_length);
|
||||
different = old_length != length
|
||||
|| ( length > 0
|
||||
&& memcmp (old_val, val, length) != 0);
|
||||
different = !nm_utils_gbytes_equal_mem (*param, val, length);
|
||||
if (different) {
|
||||
if (*param)
|
||||
g_bytes_unref (*param);
|
||||
|
@@ -109,8 +109,6 @@ nm_wifi_ap_set_ssid_arr (NMWifiAP *ap,
|
||||
gsize ssid_len)
|
||||
{
|
||||
NMWifiAPPrivate *priv;
|
||||
const guint8 *my_data;
|
||||
gsize my_len;
|
||||
|
||||
g_return_val_if_fail (NM_IS_WIFI_AP (ap), FALSE);
|
||||
|
||||
@@ -119,15 +117,7 @@ nm_wifi_ap_set_ssid_arr (NMWifiAP *ap,
|
||||
|
||||
priv = NM_WIFI_AP_GET_PRIVATE (ap);
|
||||
|
||||
if (priv->ssid)
|
||||
my_data = g_bytes_get_data (priv->ssid, &my_len);
|
||||
else {
|
||||
my_data = NULL;
|
||||
my_len = 0;
|
||||
}
|
||||
|
||||
if ( my_len == ssid_len
|
||||
&& memcmp (ssid, my_data, ssid_len) == 0)
|
||||
if (nm_utils_gbytes_equal_mem (priv->ssid, ssid, ssid_len))
|
||||
return FALSE;
|
||||
|
||||
nm_clear_pointer (&priv->ssid, g_bytes_unref);
|
||||
|
@@ -677,15 +677,10 @@ test_one_duid (const char *escaped, const guint8 *unescaped, guint len)
|
||||
{
|
||||
GBytes *t;
|
||||
char *w;
|
||||
gsize t_len;
|
||||
gconstpointer t_arr;
|
||||
|
||||
t = nm_dhcp_dhclient_unescape_duid (escaped);
|
||||
g_assert (t);
|
||||
t_arr = g_bytes_get_data (t, &t_len);
|
||||
g_assert (t_arr);
|
||||
g_assert_cmpint (t_len, ==, len);
|
||||
g_assert_cmpint (memcmp (t_arr, unescaped, len), ==, 0);
|
||||
g_assert (nm_utils_gbytes_equal_mem (t, unescaped, len));
|
||||
g_bytes_unref (t);
|
||||
|
||||
t = g_bytes_new_static (unescaped, len);
|
||||
@@ -735,15 +730,11 @@ test_read_duid_from_leasefile (void)
|
||||
0x13, 0x60, 0x67, 0x20, 0xec, 0x4c, 0x70 };
|
||||
gs_unref_bytes GBytes *duid = NULL;
|
||||
GError *error = NULL;
|
||||
gconstpointer duid_arr;
|
||||
gsize duid_len;
|
||||
|
||||
duid = nm_dhcp_dhclient_read_duid (TEST_DIR"/test-dhclient-duid.leases", &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (duid);
|
||||
duid_arr = g_bytes_get_data (duid, &duid_len);
|
||||
g_assert_cmpint (duid_len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (duid_arr, expected, duid_len), ==, 0);
|
||||
g_assert (nm_utils_gbytes_equal_mem (duid, expected, G_N_ELEMENTS (expected)));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -3120,8 +3120,7 @@ test_read_wifi_wpa_psk_hex (void)
|
||||
|
||||
ssid = nm_setting_wireless_get_ssid (s_wireless);
|
||||
g_assert (ssid);
|
||||
g_assert_cmpint (g_bytes_get_size (ssid), ==, strlen (expected_ssid));
|
||||
g_assert (memcmp (g_bytes_get_data (ssid, NULL), expected_ssid, strlen (expected_ssid)) == 0);
|
||||
g_assert (nm_utils_gbytes_equal_mem (ssid, expected_ssid, strlen (expected_ssid)));
|
||||
|
||||
/* ===== WIRELESS SECURITY SETTING ===== */
|
||||
|
||||
|
@@ -1018,8 +1018,6 @@ test_read_intlike_ssid (void)
|
||||
gs_free_error GError *error = NULL;
|
||||
gboolean success;
|
||||
GBytes *ssid;
|
||||
const guint8 *ssid_data;
|
||||
gsize ssid_len;
|
||||
const char *expected_ssid = "101";
|
||||
|
||||
connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID", &error);
|
||||
@@ -1035,10 +1033,8 @@ test_read_intlike_ssid (void)
|
||||
g_assert (s_wifi);
|
||||
|
||||
ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
g_assert (ssid != NULL);
|
||||
ssid_data = g_bytes_get_data (ssid, &ssid_len);
|
||||
g_assert_cmpint (ssid_len, ==, strlen (expected_ssid));
|
||||
g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0);
|
||||
g_assert (ssid);
|
||||
g_assert (nm_utils_gbytes_equal_mem (ssid, expected_ssid, strlen (expected_ssid)));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1049,8 +1045,6 @@ test_read_intlike_ssid_2 (void)
|
||||
gs_free_error GError *error = NULL;
|
||||
gboolean success;
|
||||
GBytes *ssid;
|
||||
const guint8 *ssid_data;
|
||||
gsize ssid_len;
|
||||
const char *expected_ssid = "11;12;13;";
|
||||
|
||||
connection = nms_keyfile_reader_from_file (TEST_KEYFILES_DIR "/Test_Intlike_SSID_2", &error);
|
||||
@@ -1066,10 +1060,8 @@ test_read_intlike_ssid_2 (void)
|
||||
g_assert (s_wifi);
|
||||
|
||||
ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
g_assert (ssid != NULL);
|
||||
ssid_data = g_bytes_get_data (ssid, &ssid_len);
|
||||
g_assert_cmpint (ssid_len, ==, strlen (expected_ssid));
|
||||
g_assert_cmpint (memcmp (ssid_data, expected_ssid, strlen (expected_ssid)), ==, 0);
|
||||
g_assert (ssid);
|
||||
g_assert (nm_utils_gbytes_equal_mem (ssid, expected_ssid, strlen (expected_ssid)));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1787,7 +1779,8 @@ test_write_wired_8021x_tls_connection_blob (void)
|
||||
const char *uuid;
|
||||
gboolean reread_same = FALSE;
|
||||
gs_free_error GError *error = NULL;
|
||||
GBytes *password_raw = NULL;
|
||||
GBytes *password_raw;
|
||||
|
||||
#define PASSWORD_RAW "password-raw\0test"
|
||||
|
||||
connection = create_wired_tls_connection (NM_SETTING_802_1X_CK_SCHEME_BLOB);
|
||||
@@ -1846,8 +1839,7 @@ test_write_wired_8021x_tls_connection_blob (void)
|
||||
|
||||
password_raw = nm_setting_802_1x_get_password_raw (s_8021x);
|
||||
g_assert (password_raw);
|
||||
g_assert (g_bytes_get_size (password_raw) == NM_STRLEN (PASSWORD_RAW));
|
||||
g_assert (!memcmp (g_bytes_get_data (password_raw, NULL), PASSWORD_RAW, NM_STRLEN (PASSWORD_RAW)));
|
||||
g_assert (nm_utils_gbytes_equal_mem (password_raw, PASSWORD_RAW, NM_STRLEN (PASSWORD_RAW)));
|
||||
|
||||
unlink (testfile);
|
||||
|
||||
@@ -2234,8 +2226,6 @@ test_read_new_wireless_group_names (void)
|
||||
NMSettingWireless *s_wifi;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
GBytes *ssid;
|
||||
const guint8 *ssid_data;
|
||||
gsize ssid_len;
|
||||
const char *expected_ssid = "foobar";
|
||||
gs_free_error GError *error = NULL;
|
||||
gboolean success;
|
||||
@@ -2253,9 +2243,7 @@ test_read_new_wireless_group_names (void)
|
||||
|
||||
ssid = nm_setting_wireless_get_ssid (s_wifi);
|
||||
g_assert (ssid);
|
||||
ssid_data = g_bytes_get_data (ssid, &ssid_len);
|
||||
g_assert_cmpint (ssid_len, ==, strlen (expected_ssid));
|
||||
g_assert_cmpint (memcmp (ssid_data, expected_ssid, ssid_len), ==, 0);
|
||||
g_assert (nm_utils_gbytes_equal_mem (ssid, expected_ssid, strlen (expected_ssid)));
|
||||
|
||||
g_assert_cmpstr (nm_setting_wireless_get_mode (s_wifi), ==, NM_SETTING_WIRELESS_MODE_INFRA);
|
||||
|
||||
|
Reference in New Issue
Block a user