blob: b57d2123d152fb2bf335a896965e7fe61052f587 [file] [log] [blame]
Amit Hilbuchdd9390c2018-11-13 16:26:05 -08001/*
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
13#include "pc/rtptransceiver.h"
14#include "rtc_base/gunit.h"
15#include "test/gmock.h"
16#include "test/mock_channelinterface.h"
17
18using ::testing::Return;
19using ::testing::ReturnRef;
20
21namespace webrtc {
22
23// Checks that a channel cannot be set on a stopped |RtpTransceiver|.
24TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) {
25 RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_AUDIO);
26 cricket::MockChannelInterface channel1;
27 sigslot::signal1<cricket::ChannelInterface*> signal;
28 EXPECT_CALL(channel1, media_type())
29 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
30 EXPECT_CALL(channel1, SignalFirstPacketReceived())
31 .WillRepeatedly(ReturnRef(signal));
32
33 transceiver.SetChannel(&channel1);
34 EXPECT_EQ(&channel1, transceiver.channel());
35
36 // Stop the transceiver.
37 transceiver.Stop();
38 EXPECT_EQ(&channel1, transceiver.channel());
39
40 cricket::MockChannelInterface channel2;
41 EXPECT_CALL(channel2, media_type())
42 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
43
44 // Channel can no longer be set, so this call should be a no-op.
45 transceiver.SetChannel(&channel2);
46 EXPECT_EQ(&channel1, transceiver.channel());
47}
48
49// Checks that a channel can be unset on a stopped |RtpTransceiver|
50TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) {
51 RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_VIDEO);
52 cricket::MockChannelInterface channel;
53 sigslot::signal1<cricket::ChannelInterface*> signal;
54 EXPECT_CALL(channel, media_type())
55 .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO));
56 EXPECT_CALL(channel, SignalFirstPacketReceived())
57 .WillRepeatedly(ReturnRef(signal));
58
59 transceiver.SetChannel(&channel);
60 EXPECT_EQ(&channel, transceiver.channel());
61
62 // Stop the transceiver.
63 transceiver.Stop();
64 EXPECT_EQ(&channel, transceiver.channel());
65
66 // Set the channel to |nullptr|.
67 transceiver.SetChannel(nullptr);
68 EXPECT_EQ(nullptr, transceiver.channel());
69}
70
71} // namespace webrtc