aboutsummaryrefslogtreecommitdiff
path: root/tests/sound-menu.cc
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-16 18:18:46 +0200
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-09-16 18:18:46 +0200
commit619162fa3519848d135b4502f782cb4f118b5fac (patch)
treee57cdba02003551ea00db616169f12f30aa24473 /tests/sound-menu.cc
parenta3b4aa7d5959ed275dd501ae2264e81b00b184b3 (diff)
downloadayatana-indicator-sound-619162fa3519848d135b4502f782cb4f118b5fac.tar.gz
ayatana-indicator-sound-619162fa3519848d135b4502f782cb4f118b5fac.tar.bz2
ayatana-indicator-sound-619162fa3519848d135b4502f782cb4f118b5fac.zip
Unit tests refactored
Diffstat (limited to 'tests/sound-menu.cc')
-rw-r--r--tests/sound-menu.cc240
1 files changed, 53 insertions, 187 deletions
diff --git a/tests/sound-menu.cc b/tests/sound-menu.cc
index 6fe2c90..75a661b 100644
--- a/tests/sound-menu.cc
+++ b/tests/sound-menu.cc
@@ -59,118 +59,68 @@ class SoundMenuTest : public ::testing::Test
GVariant * itemval = g_menu_model_get_item_attribute_value(mm, index, name, type);
EXPECT_EQ(itemval, nullptr);
}
-};
-TEST_F(SoundMenuTest, BasicObject) {
- SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
+ void check_player_control_buttons(bool canPlay, bool canNext, bool canPrev)
+ {
+ SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
- ASSERT_NE(nullptr, menu);
+ MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
- g_clear_object(&menu);
- return;
-}
+ MediaPlayerMock * media = MEDIA_PLAYER_MOCK(
+ g_object_new(TYPE_MEDIA_PLAYER_MOCK,
+ "mock-id", "player-id",
+ "mock-name", "Test Player",
+ "mock-state", "Playing",
+ "mock-is-running", TRUE,
+ "mock-can-raise", FALSE,
+ "mock-current-track", track,
+ "mock-can-do-play", canPlay,
+ "mock-can-do-next", canNext,
+ "mock-can-do-prev", canPrev,
+ NULL)
+ );
+ g_clear_object(&track);
-TEST_F(SoundMenuTest, AddRemovePlayer) {
- SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
+ sound_menu_add_player(menu, MEDIA_PLAYER(media));
- MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
+ ASSERT_NE(nullptr, menu->menu);
+ EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
- MediaPlayerMock * media = MEDIA_PLAYER_MOCK(
- g_object_new(TYPE_MEDIA_PLAYER_MOCK,
- "mock-id", "player-id",
- "mock-name", "Test Player",
- "mock-state", "Playing",
- "mock-is-running", TRUE,
- "mock-can-raise", FALSE,
- "mock-current-track", track,
- "mock-can-do-play", TRUE,
- "mock-can-do-next", TRUE,
- "mock-can-do-prev", TRUE,
- NULL)
- );
- g_clear_object(&track);
+ GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION);
+ ASSERT_NE(nullptr, section);
+ EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */
- sound_menu_add_player(menu, MEDIA_PLAYER(media));
+ /* Player display */
+ verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id"));
+ verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player"));
- ASSERT_NE(nullptr, menu->menu);
- EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
+ /* Player control */
+ verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item"));
+ verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string(canPlay ? "indicator.play.player-id" : "indicator.play.player-id.disabled"));
+ verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string(canNext ? "indicator.next.player-id" : "indicator.next.player-id.disabled"));
+ verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string(canPrev ? "indicator.previous.player-id" : "indicator.previous.player-id.disabled"));
- GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION);
- ASSERT_NE(nullptr, section);
- EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */
+ g_clear_object(&section);
- /* Player display */
- verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id"));
- verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player"));
+ sound_menu_remove_player(menu, MEDIA_PLAYER(media));
- /* Player control */
- verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item"));
- verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id"));
- verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id"));
- verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id"));
-
- g_clear_object(&section);
-
- sound_menu_remove_player(menu, MEDIA_PLAYER(media));
+ EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
- EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
-
- g_clear_object(&media);
- g_clear_object(&menu);
- return;
-}
+ g_clear_object(&media);
+ g_clear_object(&menu);
+ }
+};
-TEST_F(SoundMenuTest, AddRemovePlayerNoPlayNextPrev) {
+TEST_F(SoundMenuTest, BasicObject) {
SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
- MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
-
- MediaPlayerMock * media = MEDIA_PLAYER_MOCK(
- g_object_new(TYPE_MEDIA_PLAYER_MOCK,
- "mock-id", "player-id",
- "mock-name", "Test Player",
- "mock-state", "Playing",
- "mock-is-running", TRUE,
- "mock-can-raise", FALSE,
- "mock-current-track", track,
- "mock-can-do-play", FALSE,
- "mock-can-do-next", FALSE,
- "mock-can-do-prev", FALSE,
- NULL)
- );
- g_clear_object(&track);
-
- sound_menu_add_player(menu, MEDIA_PLAYER(media));
-
- ASSERT_NE(nullptr, menu->menu);
- EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
-
- GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION);
- ASSERT_NE(nullptr, section);
- EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */
-
- /* Player display */
- verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id"));
- verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player"));
-
- /* Player control */
- verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item"));
- verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id.disabled"));
- verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id.disabled"));
- verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id.disabled"));
-
- g_clear_object(&section);
-
- sound_menu_remove_player(menu, MEDIA_PLAYER(media));
-
- EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
+ ASSERT_NE(nullptr, menu);
- g_clear_object(&media);
g_clear_object(&menu);
return;
}
-TEST_F(SoundMenuTest, AddRemovePlayerNoNext) {
+TEST_F(SoundMenuTest, AddRemovePlayer) {
SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
@@ -184,7 +134,7 @@ TEST_F(SoundMenuTest, AddRemovePlayerNoNext) {
"mock-can-raise", FALSE,
"mock-current-track", track,
"mock-can-do-play", TRUE,
- "mock-can-do-next", FALSE,
+ "mock-can-do-next", TRUE,
"mock-can-do-prev", TRUE,
NULL)
);
@@ -206,7 +156,7 @@ TEST_F(SoundMenuTest, AddRemovePlayerNoNext) {
/* Player control */
verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item"));
verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id"));
- verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id.disabled"));
+ verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id"));
verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id"));
g_clear_object(&section);
@@ -220,104 +170,20 @@ TEST_F(SoundMenuTest, AddRemovePlayerNoNext) {
return;
}
-TEST_F(SoundMenuTest, AddRemovePlayerNoPrev) {
- SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
-
- MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
-
- MediaPlayerMock * media = MEDIA_PLAYER_MOCK(
- g_object_new(TYPE_MEDIA_PLAYER_MOCK,
- "mock-id", "player-id",
- "mock-name", "Test Player",
- "mock-state", "Playing",
- "mock-is-running", TRUE,
- "mock-can-raise", FALSE,
- "mock-current-track", track,
- "mock-can-do-play", TRUE,
- "mock-can-do-next", TRUE,
- "mock-can-do-prev", FALSE,
- NULL)
- );
- g_clear_object(&track);
-
- sound_menu_add_player(menu, MEDIA_PLAYER(media));
-
- ASSERT_NE(nullptr, menu->menu);
- EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
-
- GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION);
- ASSERT_NE(nullptr, section);
- EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */
-
- /* Player display */
- verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id"));
- verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player"));
-
- /* Player control */
- verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item"));
- verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id"));
- verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id"));
- verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id.disabled"));
-
- g_clear_object(&section);
-
- sound_menu_remove_player(menu, MEDIA_PLAYER(media));
+TEST_F(SoundMenuTest, AddRemovePlayerNoPlayNextPrev) {
+ check_player_control_buttons(false, false, false);
+}
- EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
+TEST_F(SoundMenuTest, AddRemovePlayerNoNext) {
+ check_player_control_buttons(true, false, true);
+}
- g_clear_object(&media);
- g_clear_object(&menu);
- return;
+TEST_F(SoundMenuTest, AddRemovePlayerNoPrev) {
+ check_player_control_buttons(true, true, false);
}
TEST_F(SoundMenuTest, AddRemovePlayerNoPlay) {
- SoundMenu * menu = sound_menu_new (nullptr, SOUND_MENU_DISPLAY_FLAGS_NONE);
-
- MediaPlayerTrack * track = media_player_track_new("Artist", "Title", "Album", "http://art.url");
-
- MediaPlayerMock * media = MEDIA_PLAYER_MOCK(
- g_object_new(TYPE_MEDIA_PLAYER_MOCK,
- "mock-id", "player-id",
- "mock-name", "Test Player",
- "mock-state", "Playing",
- "mock-is-running", TRUE,
- "mock-can-raise", FALSE,
- "mock-current-track", track,
- "mock-can-do-play", FALSE,
- "mock-can-do-next", TRUE,
- "mock-can-do-prev", TRUE,
- NULL)
- );
- g_clear_object(&track);
-
- sound_menu_add_player(menu, MEDIA_PLAYER(media));
-
- ASSERT_NE(nullptr, menu->menu);
- EXPECT_EQ(2, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
-
- GMenuModel * section = g_menu_model_get_item_link(G_MENU_MODEL(menu->menu), 1, G_MENU_LINK_SECTION);
- ASSERT_NE(nullptr, section);
- EXPECT_EQ(2, g_menu_model_get_n_items(section)); /* No playlists, so two items */
-
- /* Player display */
- verify_item_attribute(section, 0, "action", g_variant_new_string("indicator.player-id"));
- verify_item_attribute(section, 0, "x-canonical-type", g_variant_new_string("com.canonical.unity.media-player"));
-
- /* Player control */
- verify_item_attribute(section, 1, "x-canonical-type", g_variant_new_string("com.canonical.unity.playback-item"));
- verify_item_attribute(section, 1, "x-canonical-play-action", g_variant_new_string("indicator.play.player-id.disabled"));
- verify_item_attribute(section, 1, "x-canonical-next-action", g_variant_new_string("indicator.next.player-id"));
- verify_item_attribute(section, 1, "x-canonical-previous-action", g_variant_new_string("indicator.previous.player-id"));
-
- g_clear_object(&section);
-
- sound_menu_remove_player(menu, MEDIA_PLAYER(media));
-
- EXPECT_EQ(1, g_menu_model_get_n_items(G_MENU_MODEL(menu->menu)));
-
- g_clear_object(&media);
- g_clear_object(&menu);
- return;
+ check_player_control_buttons(false, true, true);
}
//