OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" |
| 12 |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 using testing::ElementsAreArray; |
| 17 using testing::make_tuple; |
| 18 using webrtc::rtcp::RapidResyncRequest; |
| 19 using webrtc::rtcp::RawPacket; |
| 20 using webrtc::RTCPUtility::RtcpCommonHeader; |
| 21 using webrtc::RTCPUtility::RtcpParseCommonHeader; |
| 22 |
| 23 namespace webrtc { |
| 24 namespace { |
| 25 const uint32_t kSenderSsrc = 0x12345678; |
| 26 const uint32_t kRemoteSsrc = 0x23456789; |
| 27 // Manually created packet matching constants above. |
| 28 const uint8_t kPacket[] = {0x85, 205, 0x00, 0x02, |
| 29 0x12, 0x34, 0x56, 0x78, |
| 30 0x23, 0x45, 0x67, 0x89}; |
| 31 const size_t kPacketLength = sizeof(kPacket); |
| 32 } // namespace |
| 33 |
| 34 TEST(RtcpPacketRapidResyncRequestTest, Parse) { |
| 35 RtcpCommonHeader header; |
| 36 ASSERT_TRUE(RtcpParseCommonHeader(kPacket, kPacketLength, &header)); |
| 37 RapidResyncRequest mutable_parsed; |
| 38 EXPECT_TRUE(mutable_parsed.Parse( |
| 39 header, kPacket + RtcpCommonHeader::kHeaderSizeBytes)); |
| 40 const RapidResyncRequest& parsed = mutable_parsed; |
| 41 |
| 42 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); |
| 43 EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc()); |
| 44 } |
| 45 |
| 46 TEST(RtcpPacketRapidResyncRequestTest, Create) { |
| 47 RapidResyncRequest rrr; |
| 48 rrr.From(kSenderSsrc); |
| 49 rrr.To(kRemoteSsrc); |
| 50 |
| 51 rtc::scoped_ptr<RawPacket> packet = rrr.Build(); |
| 52 |
| 53 EXPECT_THAT(make_tuple(packet->Buffer(), packet->Length()), |
| 54 ElementsAreArray(kPacket)); |
| 55 } |
| 56 |
| 57 TEST(RtcpPacketRapidResyncRequestTest, ParseFailsOnWrongSizePacket) { |
| 58 RapidResyncRequest parsed; |
| 59 RtcpCommonHeader header; |
| 60 ASSERT_TRUE(RtcpParseCommonHeader(kPacket, kPacketLength, &header)); |
| 61 const size_t kCorrectPayloadSize = header.payload_size_bytes; |
| 62 const uint8_t* payload = kPacket + RtcpCommonHeader::kHeaderSizeBytes; |
| 63 |
| 64 header.payload_size_bytes = kCorrectPayloadSize - 1; |
| 65 EXPECT_FALSE(parsed.Parse(header, payload)); |
| 66 |
| 67 header.payload_size_bytes = kCorrectPayloadSize + 1; |
| 68 EXPECT_FALSE(parsed.Parse(header, payload)); |
| 69 } |
| 70 } // namespace webrtc |
OLD | NEW |