6 gchar *applications_dir;
10 setup (Fixture *fixture,
11 gconstpointer user_data)
13 fixture->applications_dir = g_build_filename (g_get_user_data_dir (), "applications", NULL);
14 g_assert_no_errno (g_mkdir_with_parents (fixture->applications_dir, 0755));
16 g_test_message ("Using data directory: %s", g_get_user_data_dir ());
20 teardown (Fixture *fixture,
21 gconstpointer user_data)
23 g_assert_no_errno (g_rmdir (fixture->applications_dir));
24 g_clear_pointer (&fixture->applications_dir, g_free);
28 create_app (gpointer data)
30 const gchar *path = data;
32 const gchar *contents =
39 g_file_set_contents (path, contents, -1, &error);
40 g_assert_no_error (error);
42 return G_SOURCE_REMOVE;
46 delete_app (gpointer data)
48 const gchar *path = data;
53 static gboolean changed_fired;
56 changed_cb (GAppInfoMonitor *monitor, GMainLoop *loop)
59 g_main_loop_quit (loop);
63 quit_loop (gpointer data)
65 GMainLoop *loop = data;
67 if (g_main_loop_is_running (loop))
68 g_main_loop_quit (loop);
70 return G_SOURCE_REMOVE;
74 test_app_monitor (Fixture *fixture,
75 gconstpointer user_data)
78 GAppInfoMonitor *monitor;
81 app_path = g_build_filename (fixture->applications_dir, "app.desktop", NULL);
83 /* FIXME: this shouldn't be required */
84 g_list_free_full (g_app_info_get_all (), g_object_unref);
86 monitor = g_app_info_monitor_get ();
87 loop = g_main_loop_new (NULL, FALSE);
89 g_signal_connect (monitor, "changed", G_CALLBACK (changed_cb), loop);
91 g_idle_add (create_app, app_path);
92 g_timeout_add_seconds (3, quit_loop, loop);
94 g_main_loop_run (loop);
95 g_assert (changed_fired);
96 changed_fired = FALSE;
98 /* FIXME: this shouldn't be required */
99 g_list_free_full (g_app_info_get_all (), g_object_unref);
101 g_timeout_add_seconds (3, quit_loop, loop);
103 delete_app (app_path);
105 g_main_loop_run (loop);
107 g_assert (changed_fired);
109 g_main_loop_unref (loop);
112 g_object_unref (monitor);
118 main (int argc, char *argv[])
120 g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
122 g_test_add ("/monitor/app", Fixture, NULL, setup, test_app_monitor, teardown);
124 return g_test_run ();