[glib] Bug 642052: add currently-broken test case



commit 10154d21f012ae4fc3d94cbdbb12ed32df4837ce
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Feb 14 23:20:38 2011 -0500

    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(+), 0 deletions(-)
---
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 17698eb..6cd51ae 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 0000000..ff33aa6
--- /dev/null
+++ b/glib/tests/timeout.c
@@ -0,0 +1,53 @@
+#include <glib.h>
+
+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 ();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]