Merge lp:~jhodapp/media-hub/add-integrations-tests into lp:~thomas-voss/media-hub/add-integration-tests

Proposed by Jim Hodapp
Status: Needs review
Proposed branch: lp:~jhodapp/media-hub/add-integrations-tests
Merge into: lp:~thomas-voss/media-hub/add-integration-tests
Diff against target: 102 lines (+60/-0)
2 files modified
tests/integration-tests/service_implementation_test.cpp (+53/-0)
tests/mock/keyed_player_store.h (+7/-0)
To merge this branch: bzr merge lp:~jhodapp/media-hub/add-integrations-tests
Reviewer Review Type Date Requested Status
Thomas Voß Needs Fixing
Review via email: mp+244795@code.launchpad.net

Commit message

ServiceImplementation unit test that tests pausing a multimedia player session when another player instance is played.

Description of the change

ServiceImplementation unit test that tests pausing a multimedia player session when another player instance is played.

To post a comment you must log in.
Revision history for this message
Thomas Voß (thomas-voss) wrote :

Thanks for the test. Some minor niggles noted down inline.

review: Needs Fixing
125. By Jim Hodapp

Make test name make_keyed_multimedia_player into make_keyed_playing_multimedia_player to be more verbose.

Revision history for this message
Jim Hodapp (jhodapp) :
126. By Jim Hodapp

Get rid of unneeded cout debug statements since they're redundant with Google Mock's built in tracing.

Unmerged revisions

126. By Jim Hodapp

Get rid of unneeded cout debug statements since they're redundant with Google Mock's built in tracing.

125. By Jim Hodapp

Make test name make_keyed_multimedia_player into make_keyed_playing_multimedia_player to be more verbose.

124. By Jim Hodapp

ServiceImplementation unit test that tests pausing a multimedia player session when another player instance is played.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/integration-tests/service_implementation_test.cpp'
2--- tests/integration-tests/service_implementation_test.cpp 2014-11-22 21:29:28 +0000
3+++ tests/integration-tests/service_implementation_test.cpp 2015-03-05 16:20:25 +0000
4@@ -219,6 +219,19 @@
5 };
6 }
7
8+// Provide a version of the MockPlayer that has a useful key instead of
9+// only having one static value for all instances.
10+struct KeyedMockPlayer : public MockPlayer
11+{
12+ KeyedMockPlayer()
13+ {
14+ using namespace ::testing;
15+
16+ static unsigned int the_key = 0;
17+ ON_CALL(*this, key()).WillByDefault(Return(++the_key));
18+ }
19+};
20+
21 std::shared_ptr<::testing::NiceMock<MockPlayer>> make_alarm_player()
22 {
23 auto player = std::make_shared<::testing::NiceMock<MockPlayer>>();
24@@ -235,6 +248,14 @@
25 return player;
26 }
27
28+std::shared_ptr<::testing::NiceMock<KeyedMockPlayer>> make_keyed_playing_multimedia_player()
29+{
30+ auto player = std::make_shared<::testing::NiceMock<KeyedMockPlayer>>();
31+ player->playback_status() = media::Player::PlaybackStatus::playing;
32+ player->audio_stream_role() = media::Player::AudioStreamRole::multimedia;
33+ return player;
34+}
35+
36 // Our default player key we use in testing.
37 constexpr const media::Player::PlayerKey the_player_key{42};
38 }
39@@ -363,6 +384,38 @@
40 audio_output_observer->properties.external_output_state = media::audio::OutputState::disconnected;
41 }
42
43+TEST(ServiceImplementation, pauses_first_multimedia_session_when_second_multimedia_session_plays)
44+{
45+ using namespace ::testing;
46+
47+ // Create 2 mocked player instances
48+ auto multimedia_player1 = make_keyed_playing_multimedia_player();
49+ auto multimedia_player2 = make_keyed_playing_multimedia_player();
50+
51+ // Layout the test expectations. Player 1 will first play test.mp3,
52+ // and player 2 will play test.mp3. Player 1 should automatically
53+ // be paused when we call pause_other_session with key 2.
54+ EXPECT_CALL(*multimedia_player1, pause()).Times(1);
55+ EXPECT_CALL(*multimedia_player2, pause()).Times(0);
56+
57+ auto mc = make_mocked_configuration();
58+
59+ auto keyed_player_store = std::get<idx::keyed_player_store>(mc);
60+
61+ keyed_player_store->properties.map[multimedia_player1->key()] = multimedia_player1;
62+ keyed_player_store->properties.map[multimedia_player2->key()] = multimedia_player2;
63+
64+ auto impl = media::ServiceImplementation::create(tie_to_mocked_configuration(mc));
65+
66+ multimedia_player1->open_uri("../test.mp3");
67+ multimedia_player1->play();
68+
69+ // multimedia_player1 should pause before multimedia_player2 starts playing
70+ multimedia_player2->open_uri("../test.mp3");
71+ impl->pause_other_sessions(multimedia_player2->key());
72+ multimedia_player2->play();
73+}
74+
75 TEST(ServiceImplementation, pauses_all_multimedia_sessions_when_accepting_a_call)
76 {
77 auto multimedia_player = make_multimedia_player();
78
79=== modified file 'tests/mock/keyed_player_store.h'
80--- tests/mock/keyed_player_store.h 2014-11-24 13:24:08 +0000
81+++ tests/mock/keyed_player_store.h 2015-03-05 16:20:25 +0000
82@@ -38,6 +38,8 @@
83 .WillByDefault(Invoke(this, &MockKeyedPlayerStore::do_enumerate));
84 ON_CALL(*this, player_for_key(_))
85 .WillByDefault(Invoke(this, &MockKeyedPlayerStore::do_player_for_key));
86+ ON_CALL(*this, has_player_for_key(_))
87+ .WillByDefault(Invoke(this, &MockKeyedPlayerStore::do_has_player_for_key));
88 }
89
90 MOCK_CONST_METHOD0(current_player, const core::Property<std::shared_ptr<core::ubuntu::media::Player>>&());
91@@ -59,6 +61,11 @@
92 return properties.map.at(key);
93 }
94
95+ bool do_has_player_for_key(const core::ubuntu::media::Player::PlayerKey& key)
96+ {
97+ return do_player_for_key(key) != nullptr;
98+ }
99+
100 struct
101 {
102 std::map<core::ubuntu::media::Player::PlayerKey, std::shared_ptr<core::ubuntu::media::Player>> map;

Subscribers

People subscribed via source and target branches

to all changes: