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/sender_report.h" |
| 12 |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 using webrtc::rtcp::RawPacket; |
| 16 using webrtc::rtcp::ReportBlock; |
| 17 using webrtc::rtcp::SenderReport; |
| 18 using webrtc::RTCPUtility::RtcpCommonHeader; |
| 19 using webrtc::RTCPUtility::RtcpParseCommonHeader; |
| 20 |
| 21 namespace webrtc { |
| 22 |
| 23 class RtcpPacketSenderReportTest : public ::testing::Test { |
| 24 protected: |
| 25 const uint32_t kSenderSsrc = 0x12345678; |
| 26 const uint32_t kRemoteSsrc = 0x23456789; |
| 27 |
| 28 void ParsePacket(const RawPacket& packet) { |
| 29 RtcpCommonHeader header; |
| 30 EXPECT_TRUE( |
| 31 RtcpParseCommonHeader(packet.Buffer(), packet.Length(), &header)); |
| 32 EXPECT_EQ(packet.Length(), header.BlockSize()); |
| 33 EXPECT_TRUE(parsed_.Parse( |
| 34 header, packet.Buffer() + RtcpCommonHeader::kHeaderSizeBytes)); |
| 35 } |
| 36 |
| 37 // Only ParsePacket can change parsed, tests should use it in readonly mode. |
| 38 const SenderReport& parsed() { return parsed_; } |
| 39 |
| 40 private: |
| 41 SenderReport parsed_; |
| 42 }; |
| 43 |
| 44 TEST_F(RtcpPacketSenderReportTest, WithoutReportBlocks) { |
| 45 const NtpTime kNtp(0x11121418, 0x22242628); |
| 46 const uint32_t kRtpTimestamp = 0x33343536; |
| 47 const uint32_t kPacketCount = 0x44454647; |
| 48 const uint32_t kOctetCount = 0x55565758; |
| 49 |
| 50 SenderReport sr; |
| 51 sr.From(kSenderSsrc); |
| 52 sr.WithNtp(kNtp); |
| 53 sr.WithRtpTimestamp(kRtpTimestamp); |
| 54 sr.WithPacketCount(kPacketCount); |
| 55 sr.WithOctetCount(kOctetCount); |
| 56 |
| 57 rtc::scoped_ptr<RawPacket> packet = sr.Build(); |
| 58 ParsePacket(*packet); |
| 59 |
| 60 EXPECT_EQ(kSenderSsrc, parsed().sender_ssrc()); |
| 61 EXPECT_EQ(kNtp, parsed().ntp()); |
| 62 EXPECT_EQ(kRtpTimestamp, parsed().rtp_timestamp()); |
| 63 EXPECT_EQ(kPacketCount, parsed().sender_packet_count()); |
| 64 EXPECT_EQ(kOctetCount, parsed().sender_octet_count()); |
| 65 EXPECT_TRUE(parsed().report_blocks().empty()); |
| 66 } |
| 67 |
| 68 TEST_F(RtcpPacketSenderReportTest, WithOneReportBlock) { |
| 69 ReportBlock rb; |
| 70 rb.To(kRemoteSsrc); |
| 71 |
| 72 SenderReport sr; |
| 73 sr.From(kSenderSsrc); |
| 74 EXPECT_TRUE(sr.WithReportBlock(rb)); |
| 75 |
| 76 rtc::scoped_ptr<RawPacket> packet = sr.Build(); |
| 77 ParsePacket(*packet); |
| 78 |
| 79 EXPECT_EQ(kSenderSsrc, parsed().sender_ssrc()); |
| 80 EXPECT_EQ(1u, parsed().report_blocks().size()); |
| 81 EXPECT_EQ(kRemoteSsrc, parsed().report_blocks()[0].source_ssrc()); |
| 82 } |
| 83 |
| 84 TEST_F(RtcpPacketSenderReportTest, WithTwoReportBlocks) { |
| 85 ReportBlock rb1; |
| 86 rb1.To(kRemoteSsrc); |
| 87 ReportBlock rb2; |
| 88 rb2.To(kRemoteSsrc + 1); |
| 89 |
| 90 SenderReport sr; |
| 91 sr.From(kSenderSsrc); |
| 92 EXPECT_TRUE(sr.WithReportBlock(rb1)); |
| 93 EXPECT_TRUE(sr.WithReportBlock(rb2)); |
| 94 |
| 95 rtc::scoped_ptr<RawPacket> packet = sr.Build(); |
| 96 ParsePacket(*packet); |
| 97 |
| 98 EXPECT_EQ(kSenderSsrc, parsed().sender_ssrc()); |
| 99 EXPECT_EQ(2u, parsed().report_blocks().size()); |
| 100 EXPECT_EQ(kRemoteSsrc, parsed().report_blocks()[0].source_ssrc()); |
| 101 EXPECT_EQ(kRemoteSsrc + 1, parsed().report_blocks()[1].source_ssrc()); |
| 102 } |
| 103 |
| 104 TEST_F(RtcpPacketSenderReportTest, WithTooManyReportBlocks) { |
| 105 SenderReport sr; |
| 106 sr.From(kSenderSsrc); |
| 107 const size_t kMaxReportBlocks = (1 << 5) - 1; |
| 108 ReportBlock rb; |
| 109 for (size_t i = 0; i < kMaxReportBlocks; ++i) { |
| 110 rb.To(kRemoteSsrc + i); |
| 111 EXPECT_TRUE(sr.WithReportBlock(rb)); |
| 112 } |
| 113 rb.To(kRemoteSsrc + kMaxReportBlocks); |
| 114 EXPECT_FALSE(sr.WithReportBlock(rb)); |
| 115 } |
| 116 |
| 117 } // namespace webrtc |
OLD | NEW |