Chromium Code Reviews| Index: talk/media/webrtc/webrtcvoiceengine_unittest.cc |
| diff --git a/talk/media/webrtc/webrtcvoiceengine_unittest.cc b/talk/media/webrtc/webrtcvoiceengine_unittest.cc |
| index a62bcb225fc7c6111fed44c0a43507f1ecf7b353..8b44253285e62927bc30c18a0038b14d179d6208 100644 |
| --- a/talk/media/webrtc/webrtcvoiceengine_unittest.cc |
| +++ b/talk/media/webrtc/webrtcvoiceengine_unittest.cc |
| @@ -72,6 +72,11 @@ class FakeVoEWrapper : public cricket::VoEWrapper { |
| }; |
| } // namespace |
| +class FakeAudioSink : public rtc::RefCountedObject<webrtc::AudioSinkInterface> { |
| + public: |
| + void OnData(const Data& audio) override {} |
| +}; |
| + |
| class WebRtcVoiceEngineTestFake : public testing::Test { |
| public: |
| WebRtcVoiceEngineTestFake() |
| @@ -3245,3 +3250,54 @@ TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
| parameters.codecs = engine.codecs(); |
| EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
| } |
| + |
| +TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSink) { |
|
the sun
2016/01/08 13:14:27
nit: move these tests up to the other WebRtcVoiceE
Taylor Brandstetter
2016/01/08 19:46:58
Done.
|
| + EXPECT_TRUE(SetupEngine()); |
| + rtc::scoped_refptr<FakeAudioSink> fake_sink = new FakeAudioSink(); |
| + |
| + // This should do nothing, since there's no recv stream yet. |
| + channel_->SetRawAudioSink(kSsrc1, fake_sink); |
| + // Ensure the ref count wasn't incremented. |
| + EXPECT_TRUE(fake_sink->HasOneRef()); |
| + |
| + cricket::StreamParams stream; |
| + stream.ssrcs.push_back(kSsrc1); |
| + EXPECT_TRUE(channel_->AddRecvStream(stream)); |
|
the sun
2016/01/08 13:14:26
EXPECT_TRUE(channel_->AddRecvStream(
cricket
Taylor Brandstetter
2016/01/08 19:46:58
Done.
|
| + // Now, the channel should latch on to the sink. |
| + channel_->SetRawAudioSink(kSsrc1, fake_sink); |
| + EXPECT_FALSE(fake_sink->HasOneRef()); |
| + EXPECT_EQ(fake_sink, call_.GetAudioReceiveStream(kSsrc1)->sink()); |
|
the sun
2016/01/08 13:14:26
EXPECT_EQ(fake_sink, GetRecvStream(kSsrc1).sink())
the sun
2016/01/08 13:26:19
Oops, that function isn't committed yet (https://c
Taylor Brandstetter
2016/01/08 19:46:58
Ok, copied.
|
| + |
| + // Setting a nullptr should release the reference. |
| + channel_->SetRawAudioSink(kSsrc1, nullptr); |
| + EXPECT_TRUE(fake_sink->HasOneRef()); |
| +} |
| + |
| +TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) { |
| + EXPECT_TRUE(SetupEngine()); |
| + rtc::scoped_refptr<FakeAudioSink> fake_sink_1 = new FakeAudioSink(); |
| + rtc::scoped_refptr<FakeAudioSink> fake_sink_2 = new FakeAudioSink(); |
| + |
| + // Should be able to set a default sink even when no stream exists. |
| + channel_->SetRawAudioSink(0, fake_sink_1); |
| + EXPECT_FALSE(fake_sink_1->HasOneRef()); |
| + |
|
the sun
2016/01/08 13:14:26
nit: Add comment:
// Create default channel.
Taylor Brandstetter
2016/01/08 19:46:58
Done.
|
| + DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| + EXPECT_EQ(fake_sink_1, call_.GetAudioReceiveStream(0x01)->sink()); |
| + |
| + // Should be able to set the default sink after a stream exists. |
| + channel_->SetRawAudioSink(0, fake_sink_2); |
| + EXPECT_TRUE(fake_sink_1->HasOneRef()); |
| + EXPECT_FALSE(fake_sink_2->HasOneRef()); |
| + EXPECT_EQ(fake_sink_2, call_.GetAudioReceiveStream(0x01)->sink()); |
| + |
| + // If we remove and add a default stream, it should get the same sink. |
| + EXPECT_TRUE(channel_->RemoveRecvStream(0x01)); |
| + DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| + EXPECT_FALSE(fake_sink_2->HasOneRef()); |
| + EXPECT_EQ(fake_sink_2, call_.GetAudioReceiveStream(0x01)->sink()); |
| + |
| + // Finally, try resetting the default sink. |
| + channel_->SetRawAudioSink(0, nullptr); |
| + EXPECT_TRUE(fake_sink_2->HasOneRef()); |
| +} |