Bug 642052: add currently-broken test case
[platform/upstream/glib.git] / glib / tests / timeout.c
1 #include <glib.h>
2
3 static GMainLoop *loop;
4
5 static gboolean
6 stop_waiting (gpointer data)
7 {
8   g_main_loop_quit (loop);
9
10   return FALSE;
11 }
12
13 static gboolean
14 function (gpointer data)
15 {
16   g_assert_not_reached ();
17 }
18
19 static void
20 test_seconds (void)
21 {
22   /* Bug 642052 mentions that g_timeout_add_seconds(21475) schedules a
23    * job that runs once per second.
24    *
25    * Test that that isn't true anymore by scheduling two jobs:
26    *   - one, as above
27    *   - another that runs in 2100ms
28    *
29    * If everything is working properly, the 2100ms one should run first
30    * (and exit the mainloop).  If we ever see the 21475 second job run
31    * then we have trouble (since it ran in less than 2 seconds).
32    *
33    * We need a timeout of at least 2 seconds because
34    * g_timeout_add_second can add as much as an additional second of
35    * latency.
36    */
37   loop = g_main_loop_new (NULL, FALSE);
38
39   g_timeout_add (2100, stop_waiting, NULL);
40   g_timeout_add_seconds (21475, function, NULL);
41
42   g_main_loop_run (loop);
43 }
44
45 int
46 main (int argc, char *argv[])
47 {
48   g_test_init (&argc, &argv, NULL);
49
50   g_test_add_func ("/timeout/seconds", test_seconds);
51
52   return g_test_run ();
53 }