From c0ca3f995ba7755c797f15981429ba4156afc8ed Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 22 Mar 2023 14:42:22 +0000 Subject: [PATCH] tests: Fix a FIXME in the appmonitor test The test thought that calling `g_app_info_get()` was a bit of a hack, but actually it (or calling another `g_app_info_*()` function) is the right way to use the `GAppInfoMonitor` API. See the documentation improvements a couple of commits back for details. The remaining FIXME higher up in the test should probably be fixed by getting `g_app_info_monitor_get()` to arm the signal. That requires changes in `g_app_info_monitor_get()` to call `desktop_file_dir_init()`. That will have to happen another time. Signed-off-by: Philip Withnall Helps: #799 --- gio/tests/appmonitor.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/gio/tests/appmonitor.c b/gio/tests/appmonitor.c index 50a0c5863..e973b990d 100644 --- a/gio/tests/appmonitor.c +++ b/gio/tests/appmonitor.c @@ -22,6 +22,10 @@ #include #include +#ifdef G_OS_UNIX +#include +#endif + typedef struct { gchar *applications_dir; @@ -45,6 +49,7 @@ teardown (Fixture *fixture, g_clear_pointer (&fixture->applications_dir, g_free); } +#ifdef G_OS_UNIX static gboolean create_app (gpointer data) { @@ -90,19 +95,17 @@ quit_loop (gpointer data) return G_SOURCE_REMOVE; } +#endif /* G_OS_UNIX */ static void test_app_monitor (Fixture *fixture, gconstpointer user_data) { +#ifdef G_OS_UNIX gchar *app_path; GAppInfoMonitor *monitor; GMainLoop *loop; - -#ifdef G_OS_WIN32 - g_test_skip (".desktop monitor on win32"); - return; -#endif + GDesktopAppInfo *app = NULL; app_path = g_build_filename (fixture->applications_dir, "app.desktop", NULL); @@ -121,8 +124,11 @@ test_app_monitor (Fixture *fixture, g_assert_true (changed_fired); changed_fired = FALSE; - /* FIXME: this shouldn't be required */ - g_list_free_full (g_app_info_get_all (), g_object_unref); + /* Check that the app is now queryable. This has the side-effect of re-arming + * the #GAppInfoMonitor::changed signal for the next part of the test. */ + app = g_desktop_app_info_new ("app.desktop"); + g_assert_nonnull (app); + g_clear_object (&app); g_timeout_add_seconds (3, quit_loop, loop); @@ -138,6 +144,9 @@ test_app_monitor (Fixture *fixture, g_object_unref (monitor); g_free (app_path); +#else /* if !G_OS_UNIX */ + g_test_skip (".desktop monitor on win32"); +#endif /* !G_OS_UNIX */ } int