From 2c042cd4666f08e72d664a1b86100ee82cceb912 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 3 Apr 2024 22:10:18 +0200 Subject: [PATCH] tests: find update-desktop-database Disable tests that require update-desktop-database when it is missing. It requires glib to build so it will be missing when bootstrapping glib. Refactor the ifdef for Windows and MacOS while at it and reduce number of ifdefs. Ref: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3658 Signed-off-by: Natanael Copa --- gio/tests/desktop-app-info.c | 35 +++++++++++++++++++++++++++++++++ gio/tests/file.c | 38 +++++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index 0571c2cc0..c16e15a71 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -125,6 +125,20 @@ create_app_info (const char *name) return info; } +static gboolean +skip_missing_update_desktop_database (void) +{ + gchar *path = g_find_program_in_path ("update-desktop-database"); + + if (path == NULL) + { + g_test_skip ("update-desktop-database is required to run this test"); + return TRUE; + } + g_free (path); + return FALSE; +} + static void test_delete (void) { @@ -134,6 +148,9 @@ test_delete (void) char *filename; gboolean res; + if (skip_missing_update_desktop_database ()) + return; + info = create_app_info ("Blah"); id = g_app_info_get_id (info); @@ -177,6 +194,9 @@ test_default (void) GList *list; GError *error = NULL; +if (skip_missing_update_desktop_database ()) + return; + info1 = create_app_info ("Blah1"); info2 = create_app_info ("Blah2"); info3 = create_app_info ("Blah3"); @@ -316,6 +336,9 @@ test_default_async (void) GList *list; GError *error = NULL; + if (skip_missing_update_desktop_database ()) + return; + data.loop = g_main_loop_new (NULL, TRUE); info1 = create_app_info ("Blah1"); @@ -418,6 +441,9 @@ test_fallback (void) GError *error = NULL; gint old_length; + if (skip_missing_update_desktop_database ()) + return; + info1 = create_app_info ("Test1"); info2 = create_app_info ("Test2"); @@ -492,6 +518,9 @@ test_last_used (void) GAppInfo *info1, *info2, *default_app; GError *error = NULL; + if (skip_missing_update_desktop_database ()) + return; + info1 = create_app_info ("Test1"); info2 = create_app_info ("Test2"); @@ -1222,6 +1251,9 @@ test_default_uri_handler (void) gchar *file_path = NULL; GAppInfo *info; + if (skip_missing_update_desktop_database ()) + return; + info = create_app_info_toucher ("Touch Handled", "handled", "x-scheme-handler/glib-touch", &file_path); @@ -1298,6 +1330,9 @@ test_default_uri_handler_async (void) gboolean called = FALSE; gint64 start_time, touch_time; + if (skip_missing_update_desktop_database ()) + return; + loop = g_main_loop_new (NULL, FALSE); info = create_app_info_toucher ("Touch Handled", "handled-async", "x-scheme-handler/glib-async-touch", diff --git a/gio/tests/file.c b/gio/tests/file.c index 72296d008..b8732c0fe 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -3784,6 +3784,20 @@ create_command_line_app_info (const char *name, return g_steal_pointer (&info); } +static gboolean +skip_missing_update_desktop_database (void) +{ + gchar *path = g_find_program_in_path ("update-desktop-database"); + + if (path == NULL) + { + g_test_skip ("update-desktop-database is required to run this test"); + return TRUE; + } + g_free (path); + return FALSE; +} + static void test_query_default_handler_uri (void) { @@ -3793,10 +3807,8 @@ test_query_default_handler_uri (void) GFile *file; GFile *invalid_file; -#if defined(G_OS_WIN32) || defined(__APPLE__) - g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); - return; -#endif + if (skip_missing_update_desktop_database ()) + return; info = create_command_line_app_info ("Gio File Handler", "true", "x-scheme-handler/gio-file"); @@ -3878,10 +3890,8 @@ test_query_default_handler_file (void) const char buffer[] = "Text file!\n"; const guint8 binary_buffer[] = "\xde\xad\xbe\xff"; -#if defined(G_OS_WIN32) || defined(__APPLE__) - g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); - return; -#endif + if (skip_missing_update_desktop_database ()) + return; text_file = g_file_new_tmp ("query-default-handler-XXXXXX", &iostream, &error); g_assert_no_error (error); @@ -3974,10 +3984,8 @@ test_query_default_handler_file_async (void) const guint8 binary_buffer[] = "\xde\xad\xbe\xff"; GError *error = NULL; -#if defined(G_OS_WIN32) || defined(__APPLE__) - g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); - return; -#endif + if (skip_missing_update_desktop_database ()) + return; data.loop = g_main_loop_new (NULL, FALSE); @@ -4064,10 +4072,8 @@ test_query_default_handler_uri_async (void) GFile *file; GFile *invalid_file; -#if defined(G_OS_WIN32) || defined(__APPLE__) - g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); - return; -#endif + if (skip_missing_update_desktop_database ()) + return; info = create_command_line_app_info ("Gio File Handler", "true", "x-scheme-handler/gio-file");