diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2014-03-19 10:46:44 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2014-03-19 10:46:44 -0500 |
commit | 9af35685d7fb590ca4c43131cc129632ec8e6f98 (patch) | |
tree | f83fc1e6a92e95ef12d0fdeeeaccc2d2402d94a1 /tests | |
parent | 94fd55e9a054d7d066fcd9a4b4fc97c96bb1b33d (diff) | |
download | ayatana-indicator-session-9af35685d7fb590ca4c43131cc129632ec8e6f98.tar.gz ayatana-indicator-session-9af35685d7fb590ca4c43131cc129632ec8e6f98.tar.bz2 ayatana-indicator-session-9af35685d7fb590ca4c43131cc129632ec8e6f98.zip |
copy newer GLibTestFixture wait_for_signal() and wait_msec() methods from indicator-datetime's tests to fix noisy g_warnings
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gtest-dbus-fixture.h | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/tests/gtest-dbus-fixture.h b/tests/gtest-dbus-fixture.h index e6cd9c7..dedb727 100644 --- a/tests/gtest-dbus-fixture.h +++ b/tests/gtest-dbus-fixture.h @@ -54,13 +54,6 @@ class GTestDBusFixture : public ::testing::Test g_main_loop_quit (self->loop); } - static gboolean - wait_for_signal__timeout (gpointer name) - { - g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name); - return G_SOURCE_REMOVE; - } - protected: virtual void SetUp () @@ -103,29 +96,45 @@ class GTestDBusFixture : public ::testing::Test g_clear_pointer (&loop, g_main_loop_unref); } - /* convenience func to loop while waiting for a GObject's signal */ - void wait_for_signal (gpointer o, const gchar * signal) + private: + + static gboolean + wait_for_signal__timeout(gpointer name) { - const int timeout_seconds = 5; // arbitrary + g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name); + return G_SOURCE_REMOVE; + } + static gboolean + wait_msec__timeout(gpointer loop) + { + g_main_loop_quit(static_cast<GMainLoop*>(loop)); + return G_SOURCE_CONTINUE; + } + + protected: + + /* convenience func to loop while waiting for a GObject's signal */ + void wait_for_signal(gpointer o, const gchar * signal, const int timeout_seconds=5) + { // wait for the signal or for timeout, whichever comes first - guint handler_id = g_signal_connect_swapped (o, signal, - G_CALLBACK(g_main_loop_quit), - loop); - gulong timeout_id = g_timeout_add_seconds (timeout_seconds, - wait_for_signal__timeout, - loop); - g_main_loop_run (loop); - g_source_remove (timeout_id); - g_signal_handler_disconnect (o, handler_id); + const auto handler_id = g_signal_connect_swapped(o, signal, + G_CALLBACK(g_main_loop_quit), + loop); + const auto timeout_id = g_timeout_add_seconds(timeout_seconds, + wait_for_signal__timeout, + loop); + g_main_loop_run(loop); + g_source_remove(timeout_id); + g_signal_handler_disconnect(o, handler_id); } /* convenience func to loop for N msec */ - void wait_msec (int msec) + void wait_msec(int msec=50) { - guint id = g_timeout_add (msec, (GSourceFunc)g_main_loop_quit, loop); - g_main_loop_run (loop); - g_source_remove (id); + const auto id = g_timeout_add(msec, wait_msec__timeout, loop); + g_main_loop_run(loop); + g_source_remove(id); } GMainLoop * loop; |