You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. // This file contains tests for |RtpTransceiver|.
  11. #include "pc/rtp_transceiver.h"
  12. #include "pc/test/mock_channel_interface.h"
  13. #include "test/gmock.h"
  14. #include "test/gtest.h"
  15. using ::testing::Return;
  16. using ::testing::ReturnRef;
  17. namespace webrtc {
  18. // Checks that a channel cannot be set on a stopped |RtpTransceiver|.
  19. TEST(RtpTransceiverTest, CannotSetChannelOnStoppedTransceiver) {
  20. RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_AUDIO);
  21. cricket::MockChannelInterface channel1;
  22. sigslot::signal1<cricket::ChannelInterface*> signal;
  23. EXPECT_CALL(channel1, media_type())
  24. .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
  25. EXPECT_CALL(channel1, SignalFirstPacketReceived())
  26. .WillRepeatedly(ReturnRef(signal));
  27. transceiver.SetChannel(&channel1);
  28. EXPECT_EQ(&channel1, transceiver.channel());
  29. // Stop the transceiver.
  30. transceiver.Stop();
  31. EXPECT_EQ(&channel1, transceiver.channel());
  32. cricket::MockChannelInterface channel2;
  33. EXPECT_CALL(channel2, media_type())
  34. .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_AUDIO));
  35. // Channel can no longer be set, so this call should be a no-op.
  36. transceiver.SetChannel(&channel2);
  37. EXPECT_EQ(&channel1, transceiver.channel());
  38. }
  39. // Checks that a channel can be unset on a stopped |RtpTransceiver|
  40. TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) {
  41. RtpTransceiver transceiver(cricket::MediaType::MEDIA_TYPE_VIDEO);
  42. cricket::MockChannelInterface channel;
  43. sigslot::signal1<cricket::ChannelInterface*> signal;
  44. EXPECT_CALL(channel, media_type())
  45. .WillRepeatedly(Return(cricket::MediaType::MEDIA_TYPE_VIDEO));
  46. EXPECT_CALL(channel, SignalFirstPacketReceived())
  47. .WillRepeatedly(ReturnRef(signal));
  48. transceiver.SetChannel(&channel);
  49. EXPECT_EQ(&channel, transceiver.channel());
  50. // Stop the transceiver.
  51. transceiver.Stop();
  52. EXPECT_EQ(&channel, transceiver.channel());
  53. // Set the channel to |nullptr|.
  54. transceiver.SetChannel(nullptr);
  55. EXPECT_EQ(nullptr, transceiver.channel());
  56. }
  57. } // namespace webrtc