diff options
-rw-r--r-- | tests/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tests/accounts-service-mock.h | 15 | ||||
-rw-r--r-- | tests/media-player-user.cc | 42 |
3 files changed, 53 insertions, 10 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9049045..9b0586a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -151,4 +151,10 @@ target_link_libraries ( add_test(media-player-user-test-basic media-player-user-test --gtest_filter=MediaPlayerUserTest.BasicObject ) +add_test(media-player-user-test-dataset + media-player-user-test --gtest_filter=MediaPlayerUserTest.DataSet +) +add_test(media-player-user-test-timeout + media-player-user-test --gtest_filter=MediaPlayerUserTest.TimeoutTest +) diff --git a/tests/accounts-service-mock.h b/tests/accounts-service-mock.h index 225d7b5..d4dae7e 100644 --- a/tests/accounts-service-mock.h +++ b/tests/accounts-service-mock.h @@ -22,6 +22,8 @@ class AccountsServiceMock { DbusTestDbusMock * mock = nullptr; + DbusTestDbusMockObject * soundobj = nullptr; + DbusTestDbusMockObject * userobj = nullptr; public: AccountsServiceMock () { @@ -45,12 +47,12 @@ class AccountsServiceMock "UncacheUser", G_VARIANT_TYPE_STRING, NULL, "", NULL); - DbusTestDbusMockObject * userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL); + userobj = dbus_test_dbus_mock_get_object(mock, "/user", "org.freedesktop.Accounts.User", NULL); dbus_test_dbus_mock_object_add_property(mock, userobj, "UserName", G_VARIANT_TYPE_STRING, g_variant_new_string(g_get_user_name()), NULL); - DbusTestDbusMockObject * soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); + soundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.canonical.indicator.sound.AccountsService", NULL); dbus_test_dbus_mock_object_add_property(mock, soundobj, "Timestamp", G_VARIANT_TYPE_UINT64, g_variant_new_uint64(0), NULL); @@ -81,10 +83,19 @@ class AccountsServiceMock } ~AccountsServiceMock () { + g_debug("Destroying the Accounts Service Mock"); g_clear_object(&mock); } operator DbusTestTask* () { return DBUS_TEST_TASK(mock); } + + operator DbusTestDbusMock* () { + return mock; + } + + DbusTestDbusMockObject * get_sound () { + return soundobj; + } }; diff --git a/tests/media-player-user.cc b/tests/media-player-user.cc index 1f8b48d..2132e14 100644 --- a/tests/media-player-user.cc +++ b/tests/media-player-user.cc @@ -32,7 +32,7 @@ class MediaPlayerUserTest : public ::testing::Test protected: DbusTestService * service = NULL; - DbusTestDbusMock * mock = NULL; + AccountsServiceMock service_mock; GDBusConnection * session = NULL; GDBusConnection * system = NULL; @@ -41,7 +41,6 @@ class MediaPlayerUserTest : public ::testing::Test virtual void SetUp() { service = dbus_test_service_new(NULL); - AccountsServiceMock service_mock; dbus_test_service_add_task(service, (DbusTestTask*)service_mock); dbus_test_service_start_tasks(service); @@ -103,12 +102,7 @@ class MediaPlayerUserTest : public ::testing::Test } void set_property (const gchar * name, GVariant * value) { - g_dbus_proxy_call_sync(proxy, - "Set", - g_variant_new("(ssv)", "com.canonical.indicator.sound.AccountsService", name, value), - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, NULL - ); + dbus_test_dbus_mock_object_update_property((DbusTestDbusMock *)service_mock, service_mock.get_sound(), name, value, NULL); } }; @@ -182,3 +176,35 @@ TEST_F(MediaPlayerUserTest, DataSet) { g_clear_object(&in_icon); g_clear_object(&player); } + +TEST_F(MediaPlayerUserTest, TimeoutTest) { + /* Put data into Acts -- but 15 minutes ago */ + set_property("Timestamp", g_variant_new_uint64(g_get_monotonic_time() - 15 * 60 * 1000 * 1000)); + set_property("PlayerName", g_variant_new_string("The Player Formerly Known as Prince")); + GIcon * in_icon = g_themed_icon_new_with_default_fallbacks("foo-bar-fallback"); + set_property("PlayerIcon", g_variant_new_variant(g_icon_serialize(in_icon))); + set_property("State", g_variant_new_string("Chillin'")); + set_property("Title", g_variant_new_string("Dictator")); + set_property("Artist", g_variant_new_string("Bansky")); + set_property("Album", g_variant_new_string("Vinyl is dead")); + set_property("ArtUrl", g_variant_new_string("http://art.url")); + + /* Build our media player */ + MediaPlayerUser * player = media_player_user_new("user"); + ASSERT_NE(nullptr, player); + + /* Get the proxy -- and the old data, so old, like forever */ + loop(100); + + /* Ensure that we show up as not running */ + EXPECT_FALSE(media_player_get_is_running(MEDIA_PLAYER(player))); + + /* Update to make running */ + set_property("Timestamp", g_variant_new_uint64(g_get_monotonic_time())); + loop(100); + + EXPECT_TRUE(media_player_get_is_running(MEDIA_PLAYER(player))); + + g_clear_object(&in_icon); + g_clear_object(&player); +} |