From 8a37af7f0ec434c8e283d3b8da4e4833e767574e Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 8 Jun 2013 21:59:59 +0200 Subject: [PATCH] tests: Add a test for a specific invariant See the documentation in the test. The invariant is used by gnome-test-runner. https://bugzilla.gnome.org/show_bug.cgi?id=701878 --- glib/tests/mainloop.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c index 530a53c..b37821d 100644 --- a/glib/tests/mainloop.c +++ b/glib/tests/mainloop.c @@ -878,6 +878,34 @@ test_ready_time (void) g_source_destroy (source); } +static void +test_wakeup(void) +{ + GMainContext *ctx; + int i; + + ctx = g_main_context_new (); + + /* run a random large enough number of times because + * main contexts tend to wake up a few times after creation. + */ + for (i = 0; i < 100; i++) + { + /* This is the invariant we care about: + * g_main_context_wakeup(ctx,) ensures that the next call to + * g_main_context_iteration (ctx, TRUE) returns and doesn't + * block. + * This is important in threaded apps where we might not know + * if the thread calls g_main_context_wakeup() before or after + * we enter g_main_context_iteration(). + */ + g_main_context_wakeup (ctx); + g_main_context_iteration (ctx, TRUE); + } + + g_main_context_unref (ctx); +} + #ifdef G_OS_UNIX #include @@ -1265,6 +1293,7 @@ main (int argc, char *argv[]) g_test_add_func ("/mainloop/source_time", test_source_time); g_test_add_func ("/mainloop/overflow", test_mainloop_overflow); g_test_add_func ("/mainloop/ready-time", test_ready_time); + g_test_add_func ("/mainloop/wakeup", test_wakeup); #ifdef G_OS_UNIX g_test_add_func ("/mainloop/unix-fd", test_unix_fd); g_test_add_func ("/mainloop/unix-fd-source", test_unix_fd_source); -- 2.7.4