| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
| 12 | 12 |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | |
| 15 | 15 |
| 16 #include "webrtc/test/rtcp_packet_parser.h" |
| 17 |
| 18 using testing::ElementsAreArray; |
| 19 using testing::make_tuple; |
| 16 using webrtc::rtcp::Pli; | 20 using webrtc::rtcp::Pli; |
| 17 using webrtc::RTCPUtility::RtcpCommonHeader; | |
| 18 using webrtc::RTCPUtility::RtcpParseCommonHeader; | |
| 19 | 21 |
| 20 namespace webrtc { | 22 namespace webrtc { |
| 21 namespace { | 23 namespace { |
| 22 | |
| 23 const uint32_t kSenderSsrc = 0x12345678; | 24 const uint32_t kSenderSsrc = 0x12345678; |
| 24 const uint32_t kRemoteSsrc = 0x23456789; | 25 const uint32_t kRemoteSsrc = 0x23456789; |
| 25 // Manually created Pli packet matching constants above. | 26 // Manually created Pli packet matching constants above. |
| 26 const uint8_t kPacket[] = {0x81, 206, 0x00, 0x02, | 27 const uint8_t kPacket[] = {0x81, 206, 0x00, 0x02, |
| 27 0x12, 0x34, 0x56, 0x78, | 28 0x12, 0x34, 0x56, 0x78, |
| 28 0x23, 0x45, 0x67, 0x89}; | 29 0x23, 0x45, 0x67, 0x89}; |
| 29 const size_t kPacketLength = sizeof(kPacket); | 30 } // namespace |
| 30 | 31 |
| 31 TEST(RtcpPacketPliTest, Parse) { | 32 TEST(RtcpPacketPliTest, Parse) { |
| 32 RtcpCommonHeader header; | |
| 33 EXPECT_TRUE(RtcpParseCommonHeader(kPacket, kPacketLength, &header)); | |
| 34 Pli mutable_parsed; | 33 Pli mutable_parsed; |
| 35 EXPECT_TRUE(mutable_parsed.Parse( | 34 EXPECT_TRUE(test::ParseSinglePacket(kPacket, &mutable_parsed)); |
| 36 header, kPacket + RtcpCommonHeader::kHeaderSizeBytes)); | |
| 37 const Pli& parsed = mutable_parsed; // Read values from constant object. | 35 const Pli& parsed = mutable_parsed; // Read values from constant object. |
| 38 | 36 |
| 39 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); | 37 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); |
| 40 EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc()); | 38 EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc()); |
| 41 } | 39 } |
| 42 | 40 |
| 43 TEST(RtcpPacketPliTest, Create) { | 41 TEST(RtcpPacketPliTest, Create) { |
| 44 Pli pli; | 42 Pli pli; |
| 45 pli.From(kSenderSsrc); | 43 pli.From(kSenderSsrc); |
| 46 pli.To(kRemoteSsrc); | 44 pli.To(kRemoteSsrc); |
| 47 | 45 |
| 48 rtc::Buffer packet = pli.Build(); | 46 rtc::Buffer packet = pli.Build(); |
| 49 | 47 |
| 50 ASSERT_EQ(kPacketLength, packet.size()); | 48 EXPECT_THAT(make_tuple(packet.data(), packet.size()), |
| 51 EXPECT_EQ(0, memcmp(kPacket, packet.data(), kPacketLength)); | 49 ElementsAreArray(kPacket)); |
| 52 } | 50 } |
| 53 | 51 |
| 54 TEST(RtcpPacketPliTest, ParseFailsOnTooSmallPacket) { | 52 TEST(RtcpPacketPliTest, ParseFailsOnTooSmallPacket) { |
| 55 RtcpCommonHeader header; | 53 const uint8_t kTooSmallPacket[] = {0x81, 206, 0x00, 0x01, |
| 56 EXPECT_TRUE(RtcpParseCommonHeader(kPacket, kPacketLength, &header)); | 54 0x12, 0x34, 0x56, 0x78}; |
| 57 header.payload_size_bytes--; | |
| 58 | 55 |
| 59 Pli parsed; | 56 Pli parsed; |
| 60 EXPECT_FALSE( | 57 EXPECT_FALSE(test::ParseSinglePacket(kTooSmallPacket, &parsed)); |
| 61 parsed.Parse(header, kPacket + RtcpCommonHeader::kHeaderSizeBytes)); | |
| 62 } | 58 } |
| 63 | 59 |
| 64 } // namespace | |
| 65 } // namespace webrtc | 60 } // namespace webrtc |
| OLD | NEW |