diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2014-01-27 01:26:52 -0600 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2014-01-27 01:26:52 -0600 |
commit | f320760f20b282e9b2695477ab602d4041a3ada8 (patch) | |
tree | 086cb8f0c1fca0d4e7c5815b51772090584620d2 /tests/test-exporter.cpp | |
parent | 1c547710eb14d7805e47205f7c62fb7b0d0f3756 (diff) | |
download | ayatana-indicator-datetime-f320760f20b282e9b2695477ab602d4041a3ada8.tar.gz ayatana-indicator-datetime-f320760f20b282e9b2695477ab602d4041a3ada8.tar.bz2 ayatana-indicator-datetime-f320760f20b282e9b2695477ab602d4041a3ada8.zip |
add test coverage for Exporter's name_lost signal
Diffstat (limited to 'tests/test-exporter.cpp')
-rw-r--r-- | tests/test-exporter.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index aa9e89d..104fb4b 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -36,17 +36,6 @@ private: typedef GlibFixture super; - static void on_bus_closed(GObject * object, - GAsyncResult * res, - gpointer gself) - { - auto self = static_cast<ExporterFixture*>(gself); - GError* err = nullptr; - g_dbus_connection_close_finish(G_DBUS_CONNECTION(object), res, &err); - g_assert_no_error(err); - g_main_loop_quit(self->loop); - } - protected: GTestDBus* bus = nullptr; @@ -65,9 +54,11 @@ protected: void TearDown() { - GDBusConnection* connection = g_bus_get_sync (G_BUS_TYPE_SESSION, nullptr, nullptr); - g_dbus_connection_close(connection, nullptr, on_bus_closed, this); - g_main_loop_run(loop); + GError * error = nullptr; + GDBusConnection* connection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error); + if(!g_dbus_connection_is_closed(connection)) + g_dbus_connection_close_sync(connection, nullptr, &error); + g_assert_no_error(error); g_clear_object(&connection); g_test_dbus_down(bus); g_clear_object(&bus); @@ -87,6 +78,10 @@ TEST_F(ExporterFixture, Publish) std::shared_ptr<Actions> actions(new MockActions(state)); std::vector<std::shared_ptr<Menu>> menus; + MenuFactory menu_factory (actions, state); + for(int i=0; i<Menu::NUM_PROFILES; i++) + menus.push_back(menu_factory.buildMenu(Menu::Profile(i))); + Exporter exporter; exporter.publish(actions, menus); wait_msec(); @@ -121,6 +116,17 @@ TEST_F(ExporterFixture, Publish) EXPECT_EQ(1, names.count("phone-header")); EXPECT_EQ(1, names.count("set-location")); + // try closing the connection prematurely + // to test Exporter's name-lost signal + bool name_lost = false; + exporter.name_lost.connect([this,&name_lost](){ + name_lost = true; + g_main_loop_quit(loop); + }); + g_dbus_connection_close_sync(connection, nullptr, nullptr); + g_main_loop_run(loop); + EXPECT_TRUE(name_lost); + // cleanup g_strfreev(names_strv); g_clear_object(&exported); |