From 730b3c7005e53e7f76db15b39499b62ccd4c49d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 18:53:39 -0600 Subject: Setup actions to get the action groups --- tests/indicator-fixture.h | 60 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'tests/indicator-fixture.h') diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 4b510a0..063a966 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -25,12 +25,23 @@ #include #include +extern "C" { + +/* Super useful function that GLib has hidden from us :-( */ +gboolean +g_dbus_action_group_sync (GDBusActionGroup *group, + GCancellable *cancellable, + GError **error); + +} + class IndicatorFixture : public ::testing::Test { private: std::string _indicatorPath; std::string _indicatorAddress; std::shared_ptr _menu; + std::shared_ptr _actions; DbusTestService * _test_service; DbusTestTask * _test_indicator; DbusTestTask * _test_dummy; @@ -79,6 +90,7 @@ class IndicatorFixture : public ::testing::Test virtual void TearDown() override { _menu.reset(); + _actions.reset(); /* D-Bus Test Stuff */ g_clear_object(&_test_dummy); @@ -93,41 +105,49 @@ class IndicatorFixture : public ::testing::Test } private: - static void _changed_quit (GMenuModel * model, gint position, gint removed, gint added, GMainLoop * loop) { - g_debug("Got Menus"); - g_main_loop_quit(loop); - } - static gboolean _loop_quit (gpointer user_data) { g_warning("Menu Timeout"); g_main_loop_quit((GMainLoop *)user_data); return G_SOURCE_CONTINUE; } - void menuWaitForItems (const std::shared_ptr& menu) { - auto count = g_menu_model_get_n_items(menu.get()); - - if (count != 0) - return; - + void waitForCore (GObject * obj, const gchar * signalname) { auto loop = g_main_loop_new(nullptr, FALSE); /* Our two exit criteria */ - gulong signal = g_signal_connect(G_OBJECT(menu.get()), "items-changed", G_CALLBACK(_changed_quit), loop); + gulong signal = g_signal_connect_swapped(obj, signalname, G_CALLBACK(g_main_loop_quit), loop); guint timer = g_timeout_add_seconds(5, _loop_quit, loop); - g_menu_model_get_n_items(menu.get()); - /* Wait for sync */ g_main_loop_run(loop); /* Clean up */ g_source_remove(timer); - g_signal_handler_disconnect(G_OBJECT(menu.get()), signal); + g_signal_handler_disconnect(obj, signal); g_main_loop_unref(loop); } + void menuWaitForItems (const std::shared_ptr& menu) { + auto count = g_menu_model_get_n_items(menu.get()); + + if (count != 0) + return; + + waitForCore(G_OBJECT(menu.get()), "items-changed"); + } + + void agWaitForActions (const std::shared_ptr& group) { + auto list = g_action_group_list_actions(group.get()); + + if (list != nullptr) { + g_strfreev(list); + return; + } + + waitForCore(G_OBJECT(group.get()), "action-added"); + } + protected: void setMenu (const std::string& path) { _menu.reset(); @@ -140,6 +160,16 @@ class IndicatorFixture : public ::testing::Test menuWaitForItems(_menu); } + void setActions (const std::string& path) { + _actions.reset(); + + _actions = std::shared_ptr(G_ACTION_GROUP(g_dbus_action_group_get(_session, _indicatorAddress.c_str(), path.c_str())), [](GActionGroup * groupptr) { + g_clear_object(&groupptr); + }); + + agWaitForActions(_actions); + } + void expectActionExists (const std::string& name) { } -- cgit v1.2.3