diff options
author | Ted Gould <ted@gould.cx> | 2014-11-04 18:53:39 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2014-11-04 18:53:39 -0600 |
commit | 730b3c7005e53e7f76db15b39499b62ccd4c49d2 (patch) | |
tree | 875716a87fb8eb6ff9b1a1be86cd296ffb22b267 | |
parent | 5d1c2bc58614939a64a5d023f3b86d59fd8fb2a8 (diff) | |
download | ayatana-indicator-sound-730b3c7005e53e7f76db15b39499b62ccd4c49d2.tar.gz ayatana-indicator-sound-730b3c7005e53e7f76db15b39499b62ccd4c49d2.tar.bz2 ayatana-indicator-sound-730b3c7005e53e7f76db15b39499b62ccd4c49d2.zip |
Setup actions to get the action groups
-rw-r--r-- | tests/indicator-fixture.h | 60 | ||||
-rw-r--r-- | tests/indicator-test.cc | 6 |
2 files changed, 51 insertions, 15 deletions
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 <gio/gio.h> #include <libdbustest/dbus-test.h> +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<GMenuModel> _menu; + std::shared_ptr<GActionGroup> _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<GMenuModel>& 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<GMenuModel>& 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<GActionGroup>& 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<GActionGroup>(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) { } diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index fd2819e..c919e31 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -47,3 +47,9 @@ TEST_F(IndicatorTest, DesktopMenu) { EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); } + +TEST_F(IndicatorTest, SilentActions) { + setActions("/com/canonical/indicator/sound"); + + expectActionExists("indicator.root"); +} |