blob: 885a5a10c8b67c9c9060fb3ae1589c7ad32803e0 [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
Steve Anton10542f22019-01-11 09:11:00 -080013#include "pc/rtp_transceiver.h"
Yves Gerey3e707812018-11-28 16:47:49 +010014
Steve Anton10542f22019-01-11 09:11:00 -080015#include "pc/test/mock_channel_interface.h"
Amit Hilbuchdd9390c2018-11-13 16:26:05 -080016#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "test/gtest.h"
Amit Hilbuchdd9390c2018-11-13 16:26:05 -080018
19using ::testing::Return;
20using ::testing::ReturnRef;
21
22namespace webrtc {
23
24// Checks that a channel cannot be set on a stopped |RtpTransceiver|.
25TEST(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|
51TEST(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