4 static GMainLoop *loop;
7 stop_waiting (gpointer data)
9 g_main_loop_quit (loop);
15 function (gpointer data)
17 g_assert_not_reached ();
23 /* Bug 642052 mentions that g_timeout_add_seconds(21475) schedules a
24 * job that runs once per second.
26 * Test that that isn't true anymore by scheduling two jobs:
28 * - another that runs in 2100ms
30 * If everything is working properly, the 2100ms one should run first
31 * (and exit the mainloop). If we ever see the 21475 second job run
32 * then we have trouble (since it ran in less than 2 seconds).
34 * We need a timeout of at least 2 seconds because
35 * g_timeout_add_second can add as much as an additional second of
38 loop = g_main_loop_new (NULL, FALSE);
40 g_timeout_add (2100, stop_waiting, NULL);
41 g_timeout_add_seconds (21475, function, NULL);
43 g_main_loop_run (loop);
46 static gint64 last_time;
50 test_func (gpointer data)
54 current_time = g_get_monotonic_time ();
56 g_assert (current_time / 1000000 - last_time / 1000000 == 1);
58 last_time = current_time;
61 /* Make the timeout take up to 0.1 seconds.
62 * We should still get scheduled for the next second.
64 usleep (count * 10000);
69 g_main_loop_quit (loop);
77 loop = g_main_loop_new (NULL, FALSE);
79 last_time = g_get_monotonic_time ();
80 g_timeout_add_seconds (1, test_func, NULL);
82 g_main_loop_run (loop);
86 main (int argc, char *argv[])
88 g_test_init (&argc, &argv, NULL);
90 g_test_add_func ("/timeout/seconds", test_seconds);
91 g_test_add_func ("/timeout/rounding", test_rounding);