tests: Fix calls to deprecated API in unix-mounts tests

This fixes commit aac56f1618 — I missed
this while reviewing it, but the unit tests were partially changed to
call the new APIs, without being fully changed. This caused the build to
succeed on Linux, but fail on macOS due to using a deprecated API.

Actually, a better approach for the unit tests would be to consistently
call the *old* APIs, as they all immediately call the new APIs. Then we
get coverage of both old and new for free, at the cost of putting
`G_GNUC_BEGIN_IGNORE_DEPRECATIONS` at the top of the test file.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3492
This commit is contained in:
Philip Withnall 2024-10-22 16:15:18 +01:00
parent e795c715b5
commit c14810e08f
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -38,6 +38,11 @@
#include <gio/gio.h>
#include <gio/gunixmounts.h>
/* We test all of the old g_unix_mount_*() API before it was renamed to
* g_unix_mount_entry_*(). The old API calls the new API, so both methods get
* tested at once. */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void
test_is_system_fs_type (void)
{
@ -313,7 +318,7 @@ test_get_mount_entries (void)
res = g_file_set_contents (tmp_file, fake_mtab, -1, NULL);
g_assert (res);
entries = g_unix_mount_entries_get_from_file (tmp_file, &time_read, &n_entries);
entries = g_unix_mounts_get_from_file (tmp_file, &time_read, &n_entries);
if (entries == NULL)
{
@ -331,25 +336,27 @@ test_get_mount_entries (void)
for (size_t i = 0; i < n_entries; i++)
{
g_assert_cmpstr (g_unix_mount_entry_get_device_path (entries[i]), ==, expected_entries[i].device_path);
g_assert_cmpstr (g_unix_mount_entry_get_fs_type (entries[i]), ==, expected_entries[i].fs_type);
g_assert_cmpstr (g_unix_mount_entry_get_mount_path (entries[i]), ==, expected_entries[i].mount_path);
g_assert_cmpstr (g_unix_mount_entry_get_options (entries[i]), ==, expected_entries[i].options);
g_assert_cmpstr (g_unix_mount_get_device_path (entries[i]), ==, expected_entries[i].device_path);
g_assert_cmpstr (g_unix_mount_get_fs_type (entries[i]), ==, expected_entries[i].fs_type);
g_assert_cmpstr (g_unix_mount_get_mount_path (entries[i]), ==, expected_entries[i].mount_path);
g_assert_cmpstr (g_unix_mount_get_options (entries[i]), ==, expected_entries[i].options);
/* root_path is only supported by libmount */
#ifdef HAVE_LIBMOUNT
g_assert_cmpstr (g_unix_mount_entry_get_root_path (entries[i]), ==, expected_entries[i].root_path);
g_assert_cmpstr (g_unix_mount_get_root_path (entries[i]), ==, expected_entries[i].root_path);
#else
g_assert_null (g_unix_mount_get_root_path (entries[i]));
#endif
}
for (size_t i = 0; i < n_entries; i++)
g_unix_mount_entry_free (entries[i]);
g_unix_mount_free (entries[i]);
g_free (entries);
g_free (tmp_file);
}
G_GNUC_END_IGNORE_DEPRECATIONS
int
main (int argc,
char *argv[])