From 7aa6620d20dde01484d3aae73c486b43332dd9cc Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 14 Feb 2011 23:20:38 -0500 Subject: [PATCH] Bug 642052: add currently-broken test case The test case fails for now. It will be fixed by the next commit. --- glib/tests/Makefile.am | 4 ++++ glib/tests/timeout.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 glib/tests/timeout.c diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am index 14b987bf0..791179754 100644 --- a/glib/tests/Makefile.am +++ b/glib/tests/Makefile.am @@ -148,6 +148,10 @@ TEST_PROGS += gdatetime gdatetime_SOURCES = gdatetime.c gdatetime_LDADD = $(progs_ldadd) +TEST_PROGS += timeout +timeout_SOURCES = timeout.c +timeout_LDADD = $(progs_ldadd) + TEST_PROGS += environment environment_LDADD = $(progs_ldadd) diff --git a/glib/tests/timeout.c b/glib/tests/timeout.c new file mode 100644 index 000000000..ff33aa6a2 --- /dev/null +++ b/glib/tests/timeout.c @@ -0,0 +1,53 @@ +#include + +static GMainLoop *loop; + +static gboolean +stop_waiting (gpointer data) +{ + g_main_loop_quit (loop); + + return FALSE; +} + +static gboolean +function (gpointer data) +{ + g_assert_not_reached (); +} + +static void +test_seconds (void) +{ + /* Bug 642052 mentions that g_timeout_add_seconds(21475) schedules a + * job that runs once per second. + * + * Test that that isn't true anymore by scheduling two jobs: + * - one, as above + * - another that runs in 2100ms + * + * If everything is working properly, the 2100ms one should run first + * (and exit the mainloop). If we ever see the 21475 second job run + * then we have trouble (since it ran in less than 2 seconds). + * + * We need a timeout of at least 2 seconds because + * g_timeout_add_second can add as much as an additional second of + * latency. + */ + loop = g_main_loop_new (NULL, FALSE); + + g_timeout_add (2100, stop_waiting, NULL); + g_timeout_add_seconds (21475, function, NULL); + + g_main_loop_run (loop); +} + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/timeout/seconds", test_seconds); + + return g_test_run (); +}