Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // This file contains tests for |RtpTransceiver|. |
| 12 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 13 | #include "pc/rtp_transceiver.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 15 | #include "pc/test/mock_channel_interface.h" |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 16 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include "test/gtest.h" |
Amit Hilbuch | dd9390c | 2018-11-13 16:26:05 -0800 | [diff] [blame] | 18 | |
| 19 | using ::testing::Return; |
| 20 | using ::testing::ReturnRef; |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | // Checks that a channel cannot be set on a stopped |RtpTransceiver|. |
| 25 | TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) { |
| 26 | RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_AUDIO); |
| 27 | cricket::MockChannelInterface channel1; |
| 28 | sigslot::signal1<cricket::ChannelInterface*> signal; |
| 29 | EXPECT_CALL(channel1, media_type()) |
| 30 | .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO)); |
| 31 | EXPECT_CALL(channel1, SignalFirstPacketReceived()) |
| 32 | .WillRepeatedly(ReturnRef(signal)); |
| 33 | |
| 34 | transceiver.SetChannel(&channel1); |
| 35 | EXPECT_EQ(&channel1, transceiver.channel()); |
| 36 | |
| 37 | // Stop the transceiver. |
| 38 | transceiver.Stop(); |
| 39 | EXPECT_EQ(&channel1, transceiver.channel()); |
| 40 | |
| 41 | cricket::MockChannelInterface channel2; |
| 42 | EXPECT_CALL(channel2, media_type()) |
| 43 | .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO)); |
| 44 | |
| 45 | // Channel can no longer be set, so this call should be a no-op. |
| 46 | transceiver.SetChannel(&channel2); |
| 47 | EXPECT_EQ(&channel1, transceiver.channel()); |
| 48 | } |
| 49 | |
| 50 | // Checks that a channel can be unset on a stopped |RtpTransceiver| |
| 51 | TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) { |
| 52 | RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_VIDEO); |
| 53 | cricket::MockChannelInterface channel; |
| 54 | sigslot::signal1<cricket::ChannelInterface*> signal; |
| 55 | EXPECT_CALL(channel, media_type()) |
| 56 | .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO)); |
| 57 | EXPECT_CALL(channel, SignalFirstPacketReceived()) |
| 58 | .WillRepeatedly(ReturnRef(signal)); |
| 59 | |
| 60 | transceiver.SetChannel(&channel); |
| 61 | EXPECT_EQ(&channel, transceiver.channel()); |
| 62 | |
| 63 | // Stop the transceiver. |
| 64 | transceiver.Stop(); |
| 65 | EXPECT_EQ(&channel, transceiver.channel()); |
| 66 | |
| 67 | // Set the channel to |nullptr|. |
| 68 | transceiver.SetChannel(nullptr); |
| 69 | EXPECT_EQ(nullptr, transceiver.channel()); |
| 70 | } |
| 71 | |
| 72 | } // namespace webrtc |