5 create_app (gpointer data
)
7 const gchar
*path
= data
;
9 const gchar
*contents
=
16 g_file_set_contents (path
, contents
, -1, &error
);
17 g_assert_no_error (error
);
19 return G_SOURCE_REMOVE
;
23 delete_app (gpointer data
)
25 const gchar
*path
= data
;
30 static gboolean changed_fired
;
33 changed_cb (GAppInfoMonitor
*monitor
, GMainLoop
*loop
)
36 g_main_loop_quit (loop
);
40 quit_loop (gpointer data
)
42 GMainLoop
*loop
= data
;
44 if (g_main_loop_is_running (loop
))
45 g_main_loop_quit (loop
);
47 return G_SOURCE_REMOVE
;
51 test_app_monitor (void)
53 gchar
*path
, *app_path
;
54 GAppInfoMonitor
*monitor
;
57 path
= g_build_filename (g_get_user_data_dir (), "applications", NULL
);
60 app_path
= g_build_filename (path
, "app.desktop", NULL
);
62 /* FIXME: this shouldn't be required */
63 g_list_free_full (g_app_info_get_all (), g_object_unref
);
65 monitor
= g_app_info_monitor_get ();
66 loop
= g_main_loop_new (NULL
, FALSE
);
68 g_signal_connect (monitor
, "changed", G_CALLBACK (changed_cb
), loop
);
70 g_idle_add (create_app
, app_path
);
71 g_timeout_add_seconds (3, quit_loop
, loop
);
73 g_main_loop_run (loop
);
74 g_assert (changed_fired
);
75 changed_fired
= FALSE
;
77 /* FIXME: this shouldn't be required */
78 g_list_free_full (g_app_info_get_all (), g_object_unref
);
80 g_timeout_add_seconds (3, quit_loop
, loop
);
82 delete_app (app_path
);
84 g_main_loop_run (loop
);
86 g_assert (changed_fired
);
88 g_main_loop_unref (loop
);
91 g_object_unref (monitor
);
98 main (int argc
, char *argv
[])
102 path
= g_mkdtemp (g_strdup ("app_monitor_XXXXXX"));
103 g_setenv ("XDG_DATA_DIRS", path
, TRUE
);
104 g_setenv ("XDG_DATA_HOME", path
, TRUE
);
106 g_test_init (&argc
, &argv
, NULL
);
108 g_test_add_func ("/monitor/app", test_app_monitor
);
110 return g_test_run ();