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 <ncopa@alpinelinux.org>
This commit is contained in:
Natanael Copa 2024-04-03 22:10:18 +02:00 committed by Philip Withnall
parent 7322a925e2
commit 2c042cd466
2 changed files with 57 additions and 16 deletions

View File

@ -125,6 +125,20 @@ create_app_info (const char *name)
return info; 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 static void
test_delete (void) test_delete (void)
{ {
@ -134,6 +148,9 @@ test_delete (void)
char *filename; char *filename;
gboolean res; gboolean res;
if (skip_missing_update_desktop_database ())
return;
info = create_app_info ("Blah"); info = create_app_info ("Blah");
id = g_app_info_get_id (info); id = g_app_info_get_id (info);
@ -177,6 +194,9 @@ test_default (void)
GList *list; GList *list;
GError *error = NULL; GError *error = NULL;
if (skip_missing_update_desktop_database ())
return;
info1 = create_app_info ("Blah1"); info1 = create_app_info ("Blah1");
info2 = create_app_info ("Blah2"); info2 = create_app_info ("Blah2");
info3 = create_app_info ("Blah3"); info3 = create_app_info ("Blah3");
@ -316,6 +336,9 @@ test_default_async (void)
GList *list; GList *list;
GError *error = NULL; GError *error = NULL;
if (skip_missing_update_desktop_database ())
return;
data.loop = g_main_loop_new (NULL, TRUE); data.loop = g_main_loop_new (NULL, TRUE);
info1 = create_app_info ("Blah1"); info1 = create_app_info ("Blah1");
@ -418,6 +441,9 @@ test_fallback (void)
GError *error = NULL; GError *error = NULL;
gint old_length; gint old_length;
if (skip_missing_update_desktop_database ())
return;
info1 = create_app_info ("Test1"); info1 = create_app_info ("Test1");
info2 = create_app_info ("Test2"); info2 = create_app_info ("Test2");
@ -492,6 +518,9 @@ test_last_used (void)
GAppInfo *info1, *info2, *default_app; GAppInfo *info1, *info2, *default_app;
GError *error = NULL; GError *error = NULL;
if (skip_missing_update_desktop_database ())
return;
info1 = create_app_info ("Test1"); info1 = create_app_info ("Test1");
info2 = create_app_info ("Test2"); info2 = create_app_info ("Test2");
@ -1222,6 +1251,9 @@ test_default_uri_handler (void)
gchar *file_path = NULL; gchar *file_path = NULL;
GAppInfo *info; GAppInfo *info;
if (skip_missing_update_desktop_database ())
return;
info = create_app_info_toucher ("Touch Handled", "handled", info = create_app_info_toucher ("Touch Handled", "handled",
"x-scheme-handler/glib-touch", "x-scheme-handler/glib-touch",
&file_path); &file_path);
@ -1298,6 +1330,9 @@ test_default_uri_handler_async (void)
gboolean called = FALSE; gboolean called = FALSE;
gint64 start_time, touch_time; gint64 start_time, touch_time;
if (skip_missing_update_desktop_database ())
return;
loop = g_main_loop_new (NULL, FALSE); loop = g_main_loop_new (NULL, FALSE);
info = create_app_info_toucher ("Touch Handled", "handled-async", info = create_app_info_toucher ("Touch Handled", "handled-async",
"x-scheme-handler/glib-async-touch", "x-scheme-handler/glib-async-touch",

View File

@ -3784,6 +3784,20 @@ create_command_line_app_info (const char *name,
return g_steal_pointer (&info); 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 static void
test_query_default_handler_uri (void) test_query_default_handler_uri (void)
{ {
@ -3793,10 +3807,8 @@ test_query_default_handler_uri (void)
GFile *file; GFile *file;
GFile *invalid_file; GFile *invalid_file;
#if defined(G_OS_WIN32) || defined(__APPLE__) if (skip_missing_update_desktop_database ())
g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return;
return;
#endif
info = create_command_line_app_info ("Gio File Handler", "true", info = create_command_line_app_info ("Gio File Handler", "true",
"x-scheme-handler/gio-file"); "x-scheme-handler/gio-file");
@ -3878,10 +3890,8 @@ test_query_default_handler_file (void)
const char buffer[] = "Text file!\n"; const char buffer[] = "Text file!\n";
const guint8 binary_buffer[] = "\xde\xad\xbe\xff"; const guint8 binary_buffer[] = "\xde\xad\xbe\xff";
#if defined(G_OS_WIN32) || defined(__APPLE__) if (skip_missing_update_desktop_database ())
g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return;
return;
#endif
text_file = g_file_new_tmp ("query-default-handler-XXXXXX", &iostream, &error); text_file = g_file_new_tmp ("query-default-handler-XXXXXX", &iostream, &error);
g_assert_no_error (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"; const guint8 binary_buffer[] = "\xde\xad\xbe\xff";
GError *error = NULL; GError *error = NULL;
#if defined(G_OS_WIN32) || defined(__APPLE__) if (skip_missing_update_desktop_database ())
g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return;
return;
#endif
data.loop = g_main_loop_new (NULL, FALSE); data.loop = g_main_loop_new (NULL, FALSE);
@ -4064,10 +4072,8 @@ test_query_default_handler_uri_async (void)
GFile *file; GFile *file;
GFile *invalid_file; GFile *invalid_file;
#if defined(G_OS_WIN32) || defined(__APPLE__) if (skip_missing_update_desktop_database ())
g_test_skip ("Default URI handlers are not currently supported on Windows or macOS"); return;
return;
#endif
info = create_command_line_app_info ("Gio File Handler", "true", info = create_command_line_app_info ("Gio File Handler", "true",
"x-scheme-handler/gio-file"); "x-scheme-handler/gio-file");