| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 * This file includes unit tests for the RtcpPacket. | 10 * This file includes unit tests for the RtcpPacket. |
| 11 */ | 11 */ |
| 12 | 12 |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" | 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" |
| 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 19 #include "webrtc/test/rtcp_packet_parser.h" | 20 #include "webrtc/test/rtcp_packet_parser.h" |
| 20 | 21 |
| 21 using ::testing::ElementsAre; | 22 using ::testing::ElementsAre; |
| 22 | 23 |
| 23 using webrtc::rtcp::App; | 24 using webrtc::rtcp::App; |
| 24 using webrtc::rtcp::Bye; | 25 using webrtc::rtcp::Bye; |
| 25 using webrtc::rtcp::Dlrr; | 26 using webrtc::rtcp::Dlrr; |
| 26 using webrtc::rtcp::Empty; | 27 using webrtc::rtcp::Empty; |
| 27 using webrtc::rtcp::Fir; | 28 using webrtc::rtcp::Fir; |
| 28 using webrtc::rtcp::Nack; | 29 using webrtc::rtcp::Nack; |
| 29 using webrtc::rtcp::Sdes; | |
| 30 using webrtc::rtcp::SenderReport; | |
| 31 using webrtc::rtcp::Sli; | |
| 32 using webrtc::rtcp::RawPacket; | 30 using webrtc::rtcp::RawPacket; |
| 33 using webrtc::rtcp::ReceiverReport; | 31 using webrtc::rtcp::ReceiverReport; |
| 34 using webrtc::rtcp::Remb; | 32 using webrtc::rtcp::Remb; |
| 35 using webrtc::rtcp::ReportBlock; | 33 using webrtc::rtcp::ReportBlock; |
| 36 using webrtc::rtcp::Rpsi; | 34 using webrtc::rtcp::Rpsi; |
| 37 using webrtc::rtcp::Rrtr; | 35 using webrtc::rtcp::Rrtr; |
| 36 using webrtc::rtcp::Sdes; |
| 38 using webrtc::rtcp::SenderReport; | 37 using webrtc::rtcp::SenderReport; |
| 38 using webrtc::rtcp::Sli; |
| 39 using webrtc::rtcp::Tmmbn; | 39 using webrtc::rtcp::Tmmbn; |
| 40 using webrtc::rtcp::Tmmbr; | 40 using webrtc::rtcp::Tmmbr; |
| 41 using webrtc::rtcp::VoipMetric; | 41 using webrtc::rtcp::VoipMetric; |
| 42 using webrtc::rtcp::Xr; | 42 using webrtc::rtcp::Xr; |
| 43 using webrtc::test::RtcpPacketParser; | 43 using webrtc::test::RtcpPacketParser; |
| 44 | 44 |
| 45 namespace webrtc { | 45 namespace webrtc { |
| 46 | 46 |
| 47 const uint32_t kSenderSsrc = 0x12345678; | 47 const uint32_t kSenderSsrc = 0x12345678; |
| 48 const uint32_t kRemoteSsrc = 0x23456789; | 48 const uint32_t kRemoteSsrc = 0x23456789; |
| 49 | 49 |
| 50 TEST(RtcpPacketTest, Rr) { | |
| 51 ReceiverReport rr; | |
| 52 rr.From(kSenderSsrc); | |
| 53 | |
| 54 rtc::scoped_ptr<RawPacket> packet(rr.Build()); | |
| 55 RtcpPacketParser parser; | |
| 56 parser.Parse(packet->Buffer(), packet->Length()); | |
| 57 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | |
| 58 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); | |
| 59 EXPECT_EQ(0, parser.report_block()->num_packets()); | |
| 60 } | |
| 61 | |
| 62 TEST(RtcpPacketTest, RrWithOneReportBlock) { | |
| 63 ReportBlock rb; | |
| 64 rb.To(kRemoteSsrc); | |
| 65 rb.WithFractionLost(55); | |
| 66 rb.WithCumulativeLost(0x111111); | |
| 67 rb.WithExtHighestSeqNum(0x22222222); | |
| 68 rb.WithJitter(0x33333333); | |
| 69 rb.WithLastSr(0x44444444); | |
| 70 rb.WithDelayLastSr(0x55555555); | |
| 71 | |
| 72 ReceiverReport rr; | |
| 73 rr.From(kSenderSsrc); | |
| 74 EXPECT_TRUE(rr.WithReportBlock(rb)); | |
| 75 | |
| 76 rtc::scoped_ptr<RawPacket> packet(rr.Build()); | |
| 77 RtcpPacketParser parser; | |
| 78 parser.Parse(packet->Buffer(), packet->Length()); | |
| 79 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | |
| 80 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); | |
| 81 EXPECT_EQ(1, parser.report_block()->num_packets()); | |
| 82 EXPECT_EQ(kRemoteSsrc, parser.report_block()->Ssrc()); | |
| 83 EXPECT_EQ(55U, parser.report_block()->FractionLost()); | |
| 84 EXPECT_EQ(0x111111U, parser.report_block()->CumPacketLost()); | |
| 85 EXPECT_EQ(0x22222222U, parser.report_block()->ExtHighestSeqNum()); | |
| 86 EXPECT_EQ(0x33333333U, parser.report_block()->Jitter()); | |
| 87 EXPECT_EQ(0x44444444U, parser.report_block()->LastSr()); | |
| 88 EXPECT_EQ(0x55555555U, parser.report_block()->DelayLastSr()); | |
| 89 } | |
| 90 | |
| 91 TEST(RtcpPacketTest, RrWithTwoReportBlocks) { | |
| 92 ReportBlock rb1; | |
| 93 rb1.To(kRemoteSsrc); | |
| 94 ReportBlock rb2; | |
| 95 rb2.To(kRemoteSsrc + 1); | |
| 96 | |
| 97 ReceiverReport rr; | |
| 98 rr.From(kSenderSsrc); | |
| 99 EXPECT_TRUE(rr.WithReportBlock(rb1)); | |
| 100 EXPECT_TRUE(rr.WithReportBlock(rb2)); | |
| 101 | |
| 102 rtc::scoped_ptr<RawPacket> packet(rr.Build()); | |
| 103 RtcpPacketParser parser; | |
| 104 parser.Parse(packet->Buffer(), packet->Length()); | |
| 105 EXPECT_EQ(1, parser.receiver_report()->num_packets()); | |
| 106 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); | |
| 107 EXPECT_EQ(2, parser.report_block()->num_packets()); | |
| 108 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc)); | |
| 109 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc + 1)); | |
| 110 } | |
| 111 | |
| 112 TEST(RtcpPacketTest, RrWithTooManyReportBlocks) { | |
| 113 ReceiverReport rr; | |
| 114 rr.From(kSenderSsrc); | |
| 115 const int kMaxReportBlocks = (1 << 5) - 1; | |
| 116 ReportBlock rb; | |
| 117 for (int i = 0; i < kMaxReportBlocks; ++i) { | |
| 118 rb.To(kRemoteSsrc + i); | |
| 119 EXPECT_TRUE(rr.WithReportBlock(rb)); | |
| 120 } | |
| 121 rb.To(kRemoteSsrc + kMaxReportBlocks); | |
| 122 EXPECT_FALSE(rr.WithReportBlock(rb)); | |
| 123 } | |
| 124 | |
| 125 TEST(RtcpPacketTest, Sr) { | 50 TEST(RtcpPacketTest, Sr) { |
| 126 SenderReport sr; | 51 SenderReport sr; |
| 127 sr.From(kSenderSsrc); | 52 sr.From(kSenderSsrc); |
| 128 sr.WithNtpSec(0x11111111); | 53 sr.WithNtpSec(0x11111111); |
| 129 sr.WithNtpFrac(0x22222222); | 54 sr.WithNtpFrac(0x22222222); |
| 130 sr.WithRtpTimestamp(0x33333333); | 55 sr.WithRtpTimestamp(0x33333333); |
| 131 sr.WithPacketCount(0x44444444); | 56 sr.WithPacketCount(0x44444444); |
| 132 sr.WithOctetCount(0x55555555); | 57 sr.WithOctetCount(0x55555555); |
| 133 | 58 |
| 134 rtc::scoped_ptr<RawPacket> packet(sr.Build()); | 59 rtc::scoped_ptr<RawPacket> packet(sr.Build()); |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 EXPECT_TRUE(xr.WithDlrr(&dlrr)); | 910 EXPECT_TRUE(xr.WithDlrr(&dlrr)); |
| 986 EXPECT_FALSE(xr.WithDlrr(&dlrr)); | 911 EXPECT_FALSE(xr.WithDlrr(&dlrr)); |
| 987 | 912 |
| 988 VoipMetric voip_metric; | 913 VoipMetric voip_metric; |
| 989 for (int i = 0; i < kMaxBlocks; ++i) | 914 for (int i = 0; i < kMaxBlocks; ++i) |
| 990 EXPECT_TRUE(xr.WithVoipMetric(&voip_metric)); | 915 EXPECT_TRUE(xr.WithVoipMetric(&voip_metric)); |
| 991 EXPECT_FALSE(xr.WithVoipMetric(&voip_metric)); | 916 EXPECT_FALSE(xr.WithVoipMetric(&voip_metric)); |
| 992 } | 917 } |
| 993 | 918 |
| 994 } // namespace webrtc | 919 } // namespace webrtc |
| OLD | NEW |