pli_unittest.cc (1850B)
1 /* 2 * Copyright (c) 2015 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 "modules/rtp_rtcp/source/rtcp_packet/pli.h" 12 13 #include <cstdint> 14 15 #include "rtc_base/buffer.h" 16 #include "test/gmock.h" 17 #include "test/gtest.h" 18 #include "test/rtcp_packet_parser.h" 19 20 using ::testing::ElementsAreArray; 21 using ::testing::make_tuple; 22 using webrtc::rtcp::Pli; 23 24 namespace webrtc { 25 namespace { 26 constexpr uint32_t kSenderSsrc = 0x12345678; 27 constexpr uint32_t kRemoteSsrc = 0x23456789; 28 // Manually created Pli packet matching constants above. 29 constexpr uint8_t kPacket[] = {0x81, 206, 0x00, 0x02, 0x12, 0x34, 30 0x56, 0x78, 0x23, 0x45, 0x67, 0x89}; 31 } // namespace 32 33 TEST(RtcpPacketPliTest, Parse) { 34 Pli mutable_parsed; 35 EXPECT_TRUE(test::ParseSinglePacket(kPacket, &mutable_parsed)); 36 const Pli& parsed = mutable_parsed; // Read values from constant object. 37 38 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); 39 EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc()); 40 } 41 42 TEST(RtcpPacketPliTest, Create) { 43 Pli pli; 44 pli.SetSenderSsrc(kSenderSsrc); 45 pli.SetMediaSsrc(kRemoteSsrc); 46 47 Buffer packet = pli.Build(); 48 49 EXPECT_THAT(make_tuple(packet.data(), packet.size()), 50 ElementsAreArray(kPacket)); 51 } 52 53 TEST(RtcpPacketPliTest, ParseFailsOnTooSmallPacket) { 54 const uint8_t kTooSmallPacket[] = {0x81, 206, 0x00, 0x01, 55 0x12, 0x34, 0x56, 0x78}; 56 57 Pli parsed; 58 EXPECT_FALSE(test::ParseSinglePacket(kTooSmallPacket, &parsed)); 59 } 60 61 } // namespace webrtc