OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2017 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 #include "webrtc/pc/srtptransport.h" |
| 12 |
| 13 #include "webrtc/pc/rtptransport.h" |
| 14 #include "webrtc/pc/rtptransporttestutil.h" |
| 15 #include "webrtc/rtc_base/asyncpacketsocket.h" |
| 16 #include "webrtc/rtc_base/gunit.h" |
| 17 #include "webrtc/rtc_base/ptr_util.h" |
| 18 #include "webrtc/test/gmock.h" |
| 19 |
| 20 namespace webrtc { |
| 21 |
| 22 using testing::_; |
| 23 using testing::Return; |
| 24 |
| 25 class MockRtpTransport : public RtpTransport { |
| 26 public: |
| 27 MockRtpTransport() : RtpTransport(true) {} |
| 28 |
| 29 MOCK_METHOD4(SendPacket, |
| 30 bool(bool rtcp, |
| 31 rtc::CopyOnWriteBuffer* packet, |
| 32 const rtc::PacketOptions& options, |
| 33 int flags)); |
| 34 |
| 35 void PretendReceivedPacket() { |
| 36 bool rtcp = false; |
| 37 rtc::CopyOnWriteBuffer buffer; |
| 38 rtc::PacketTime time; |
| 39 SignalPacketReceived(rtcp, &buffer, time); |
| 40 } |
| 41 }; |
| 42 |
| 43 TEST(SrtpTransportTest, SendPacket) { |
| 44 auto rtp_transport = rtc::MakeUnique<MockRtpTransport>(); |
| 45 EXPECT_CALL(*rtp_transport, SendPacket(_, _, _, _)).WillOnce(Return(true)); |
| 46 |
| 47 SrtpTransport srtp_transport(std::move(rtp_transport), "a"); |
| 48 |
| 49 const bool rtcp = false; |
| 50 rtc::CopyOnWriteBuffer packet; |
| 51 rtc::PacketOptions options; |
| 52 int flags = 0; |
| 53 EXPECT_TRUE(srtp_transport.SendPacket(rtcp, &packet, options, flags)); |
| 54 |
| 55 // TODO(zstein): Also verify that the packet received by RtpTransport has been |
| 56 // protected once SrtpTransport handles that. |
| 57 } |
| 58 |
| 59 // Test that SrtpTransport fires SignalPacketReceived when the underlying |
| 60 // RtpTransport fires SignalPacketReceived. |
| 61 TEST(SrtpTransportTest, SignalPacketReceived) { |
| 62 auto rtp_transport = rtc::MakeUnique<MockRtpTransport>(); |
| 63 MockRtpTransport* rtp_transport_raw = rtp_transport.get(); |
| 64 SrtpTransport srtp_transport(std::move(rtp_transport), "a"); |
| 65 |
| 66 SignalPacketReceivedCounter counter(&srtp_transport); |
| 67 |
| 68 rtp_transport_raw->PretendReceivedPacket(); |
| 69 |
| 70 EXPECT_EQ(1, counter.rtp_count()); |
| 71 |
| 72 // TODO(zstein): Also verify that the packet is unprotected once SrtpTransport |
| 73 // handles that. |
| 74 } |
| 75 |
| 76 } // namespace webrtc |
OLD | NEW |