7 gchar
*applications_dir
;
11 setup (Fixture
*fixture
,
12 gconstpointer user_data
)
16 fixture
->data_dir
= g_dir_make_tmp ("gio-test-app-monitor_XXXXXX", &error
);
17 g_assert_no_error (error
);
19 fixture
->applications_dir
= g_build_filename (fixture
->data_dir
, "applications", NULL
);
20 g_assert_cmpint (g_mkdir (fixture
->applications_dir
, 0755), ==, 0);
22 g_setenv ("XDG_DATA_DIRS", fixture
->data_dir
, TRUE
);
23 g_setenv ("XDG_DATA_HOME", fixture
->data_dir
, TRUE
);
25 g_test_message ("Using data directory: %s", fixture
->data_dir
);
29 teardown (Fixture
*fixture
,
30 gconstpointer user_data
)
32 g_assert_cmpint (g_rmdir (fixture
->applications_dir
), ==, 0);
33 g_clear_pointer (&fixture
->applications_dir
, g_free
);
35 g_assert_cmpint (g_rmdir (fixture
->data_dir
), ==, 0);
36 g_clear_pointer (&fixture
->data_dir
, g_free
);
40 create_app (gpointer data
)
42 const gchar
*path
= data
;
44 const gchar
*contents
=
51 g_file_set_contents (path
, contents
, -1, &error
);
52 g_assert_no_error (error
);
54 return G_SOURCE_REMOVE
;
58 delete_app (gpointer data
)
60 const gchar
*path
= data
;
65 static gboolean changed_fired
;
68 changed_cb (GAppInfoMonitor
*monitor
, GMainLoop
*loop
)
71 g_main_loop_quit (loop
);
75 quit_loop (gpointer data
)
77 GMainLoop
*loop
= data
;
79 if (g_main_loop_is_running (loop
))
80 g_main_loop_quit (loop
);
82 return G_SOURCE_REMOVE
;
86 test_app_monitor (Fixture
*fixture
,
87 gconstpointer user_data
)
90 GAppInfoMonitor
*monitor
;
93 app_path
= g_build_filename (fixture
->applications_dir
, "app.desktop", NULL
);
95 /* FIXME: this shouldn't be required */
96 g_list_free_full (g_app_info_get_all (), g_object_unref
);
98 monitor
= g_app_info_monitor_get ();
99 loop
= g_main_loop_new (NULL
, FALSE
);
101 g_signal_connect (monitor
, "changed", G_CALLBACK (changed_cb
), loop
);
103 g_idle_add (create_app
, app_path
);
104 g_timeout_add_seconds (3, quit_loop
, loop
);
106 g_main_loop_run (loop
);
107 g_assert (changed_fired
);
108 changed_fired
= FALSE
;
110 /* FIXME: this shouldn't be required */
111 g_list_free_full (g_app_info_get_all (), g_object_unref
);
113 g_timeout_add_seconds (3, quit_loop
, loop
);
115 delete_app (app_path
);
117 g_main_loop_run (loop
);
119 g_assert (changed_fired
);
121 g_main_loop_unref (loop
);
124 g_object_unref (monitor
);
130 main (int argc
, char *argv
[])
132 g_test_init (&argc
, &argv
, NULL
);
134 g_test_add ("/monitor/app", Fixture
, NULL
, setup
, test_app_monitor
, teardown
);
136 return g_test_run ();