mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-16 10:06:41 +00:00
Fix the self tests when using glib2 >=2.59.0
Replace the non-breaking space with a traditional space rather than changing the expected output with #ifdef to allow running the tests with a daemon compiled against an older glib2 version.
This commit is contained in:
parent
96e6783982
commit
b1d1c3b089
@ -43,6 +43,60 @@ fu_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* https://gitlab.gnome.org/GNOME/glib/issues/225 */
|
||||||
|
static guint
|
||||||
|
_g_string_replace (GString *string, const gchar *search, const gchar *replace)
|
||||||
|
{
|
||||||
|
gchar *tmp;
|
||||||
|
guint count = 0;
|
||||||
|
gsize search_idx = 0;
|
||||||
|
gsize replace_len;
|
||||||
|
gsize search_len;
|
||||||
|
|
||||||
|
g_return_val_if_fail (string != NULL, 0);
|
||||||
|
g_return_val_if_fail (search != NULL, 0);
|
||||||
|
g_return_val_if_fail (replace != NULL, 0);
|
||||||
|
|
||||||
|
/* nothing to do */
|
||||||
|
if (string->len == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
search_len = strlen (search);
|
||||||
|
replace_len = strlen (replace);
|
||||||
|
|
||||||
|
do {
|
||||||
|
tmp = g_strstr_len (string->str + search_idx, -1, search);
|
||||||
|
if (tmp == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* advance the counter in case @replace contains @search */
|
||||||
|
search_idx = (gsize) (tmp - string->str);
|
||||||
|
|
||||||
|
/* reallocate the string if required */
|
||||||
|
if (search_len > replace_len) {
|
||||||
|
g_string_erase (string,
|
||||||
|
(gssize) search_idx,
|
||||||
|
(gssize) (search_len - replace_len));
|
||||||
|
memcpy (tmp, replace, replace_len);
|
||||||
|
} else if (search_len < replace_len) {
|
||||||
|
g_string_insert_len (string,
|
||||||
|
(gssize) search_idx,
|
||||||
|
replace,
|
||||||
|
(gssize) (replace_len - search_len));
|
||||||
|
/* we have to treat this specially as it could have
|
||||||
|
* been reallocated when the insertion happened */
|
||||||
|
memcpy (string->str + search_idx, replace, replace_len);
|
||||||
|
} else {
|
||||||
|
/* just memcmp in the new string */
|
||||||
|
memcpy (tmp, replace, replace_len);
|
||||||
|
}
|
||||||
|
search_idx += replace_len;
|
||||||
|
count++;
|
||||||
|
} while (TRUE);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fwupd_enums_func (void)
|
fwupd_enums_func (void)
|
||||||
{
|
{
|
||||||
@ -211,6 +265,7 @@ fwupd_device_func (void)
|
|||||||
g_autoptr(FwupdDevice) dev = NULL;
|
g_autoptr(FwupdDevice) dev = NULL;
|
||||||
g_autoptr(FwupdRelease) rel = NULL;
|
g_autoptr(FwupdRelease) rel = NULL;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
g_autoptr(GString) str_ascii = NULL;
|
||||||
|
|
||||||
/* create dummy object */
|
/* create dummy object */
|
||||||
dev = fwupd_device_new ();
|
dev = fwupd_device_new ();
|
||||||
@ -243,7 +298,11 @@ fwupd_device_func (void)
|
|||||||
g_assert (fwupd_device_has_guid (dev, "00000000-0000-0000-0000-000000000000"));
|
g_assert (fwupd_device_has_guid (dev, "00000000-0000-0000-0000-000000000000"));
|
||||||
g_assert (!fwupd_device_has_guid (dev, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
|
g_assert (!fwupd_device_has_guid (dev, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
|
||||||
|
|
||||||
ret = fu_test_compare_lines (str,
|
/* convert the new non-breaking space back into a normal space:
|
||||||
|
* https://gitlab.gnome.org/GNOME/glib/commit/76af5dabb4a25956a6c41a75c0c7feeee74496da */
|
||||||
|
str_ascii = g_string_new (str);
|
||||||
|
_g_string_replace (str_ascii, " ", " ");
|
||||||
|
ret = fu_test_compare_lines (str_ascii->str,
|
||||||
"ColorHug2\n"
|
"ColorHug2\n"
|
||||||
" DeviceId: USB:foo\n"
|
" DeviceId: USB:foo\n"
|
||||||
" Guid: 2082b5e0-7a64-478a-b1b2-e3404fab6dad\n"
|
" Guid: 2082b5e0-7a64-478a-b1b2-e3404fab6dad\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user