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/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
20 #include "webrtc/test/rtcp_packet_parser.h" | 21 #include "webrtc/test/rtcp_packet_parser.h" |
21 | 22 |
22 using ::testing::ElementsAre; | 23 using ::testing::ElementsAre; |
23 | 24 |
24 using webrtc::rtcp::App; | 25 using webrtc::rtcp::App; |
25 using webrtc::rtcp::Bye; | 26 using webrtc::rtcp::Bye; |
26 using webrtc::rtcp::Dlrr; | 27 using webrtc::rtcp::Dlrr; |
27 using webrtc::rtcp::Empty; | 28 using webrtc::rtcp::Empty; |
28 using webrtc::rtcp::Fir; | 29 using webrtc::rtcp::Fir; |
29 using webrtc::rtcp::RawPacket; | 30 using webrtc::rtcp::RawPacket; |
30 using webrtc::rtcp::ReceiverReport; | 31 using webrtc::rtcp::ReceiverReport; |
31 using webrtc::rtcp::Remb; | 32 using webrtc::rtcp::Remb; |
32 using webrtc::rtcp::ReportBlock; | 33 using webrtc::rtcp::ReportBlock; |
33 using webrtc::rtcp::Rpsi; | 34 using webrtc::rtcp::Rpsi; |
34 using webrtc::rtcp::Rrtr; | 35 using webrtc::rtcp::Rrtr; |
35 using webrtc::rtcp::Sdes; | 36 using webrtc::rtcp::Sdes; |
36 using webrtc::rtcp::SenderReport; | 37 using webrtc::rtcp::SenderReport; |
37 using webrtc::rtcp::Sli; | 38 using webrtc::rtcp::Sli; |
38 using webrtc::rtcp::Tmmbn; | 39 using webrtc::rtcp::Tmmbn; |
39 using webrtc::rtcp::Tmmbr; | 40 using webrtc::rtcp::Tmmbr; |
40 using webrtc::rtcp::VoipMetric; | 41 using webrtc::rtcp::VoipMetric; |
41 using webrtc::rtcp::Xr; | 42 using webrtc::rtcp::Xr; |
42 using webrtc::test::RtcpPacketParser; | 43 using webrtc::test::RtcpPacketParser; |
43 | 44 |
44 namespace webrtc { | 45 namespace webrtc { |
45 | 46 |
46 const uint32_t kSenderSsrc = 0x12345678; | 47 const uint32_t kSenderSsrc = 0x12345678; |
47 const uint32_t kRemoteSsrc = 0x23456789; | 48 const uint32_t kRemoteSsrc = 0x23456789; |
48 | 49 |
49 TEST(RtcpPacketTest, Sr) { | |
50 SenderReport sr; | |
51 sr.From(kSenderSsrc); | |
52 sr.WithNtpSec(0x11111111); | |
53 sr.WithNtpFrac(0x22222222); | |
54 sr.WithRtpTimestamp(0x33333333); | |
55 sr.WithPacketCount(0x44444444); | |
56 sr.WithOctetCount(0x55555555); | |
57 | |
58 rtc::scoped_ptr<RawPacket> packet(sr.Build()); | |
59 RtcpPacketParser parser; | |
60 parser.Parse(packet->Buffer(), packet->Length()); | |
61 | |
62 EXPECT_EQ(1, parser.sender_report()->num_packets()); | |
63 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); | |
64 EXPECT_EQ(0x11111111U, parser.sender_report()->NtpSec()); | |
65 EXPECT_EQ(0x22222222U, parser.sender_report()->NtpFrac()); | |
66 EXPECT_EQ(0x33333333U, parser.sender_report()->RtpTimestamp()); | |
67 EXPECT_EQ(0x44444444U, parser.sender_report()->PacketCount()); | |
68 EXPECT_EQ(0x55555555U, parser.sender_report()->OctetCount()); | |
69 EXPECT_EQ(0, parser.report_block()->num_packets()); | |
70 } | |
71 | |
72 TEST(RtcpPacketTest, SrWithOneReportBlock) { | |
73 ReportBlock rb; | |
74 rb.To(kRemoteSsrc); | |
75 | |
76 SenderReport sr; | |
77 sr.From(kSenderSsrc); | |
78 EXPECT_TRUE(sr.WithReportBlock(rb)); | |
79 | |
80 rtc::scoped_ptr<RawPacket> packet(sr.Build()); | |
81 RtcpPacketParser parser; | |
82 parser.Parse(packet->Buffer(), packet->Length()); | |
83 EXPECT_EQ(1, parser.sender_report()->num_packets()); | |
84 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); | |
85 EXPECT_EQ(1, parser.report_block()->num_packets()); | |
86 EXPECT_EQ(kRemoteSsrc, parser.report_block()->Ssrc()); | |
87 } | |
88 | |
89 TEST(RtcpPacketTest, SrWithTwoReportBlocks) { | |
90 ReportBlock rb1; | |
91 rb1.To(kRemoteSsrc); | |
92 ReportBlock rb2; | |
93 rb2.To(kRemoteSsrc + 1); | |
94 | |
95 SenderReport sr; | |
96 sr.From(kSenderSsrc); | |
97 EXPECT_TRUE(sr.WithReportBlock(rb1)); | |
98 EXPECT_TRUE(sr.WithReportBlock(rb2)); | |
99 | |
100 rtc::scoped_ptr<RawPacket> packet(sr.Build()); | |
101 RtcpPacketParser parser; | |
102 parser.Parse(packet->Buffer(), packet->Length()); | |
103 EXPECT_EQ(1, parser.sender_report()->num_packets()); | |
104 EXPECT_EQ(kSenderSsrc, parser.sender_report()->Ssrc()); | |
105 EXPECT_EQ(2, parser.report_block()->num_packets()); | |
106 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc)); | |
107 EXPECT_EQ(1, parser.report_blocks_per_ssrc(kRemoteSsrc + 1)); | |
108 } | |
109 | |
110 TEST(RtcpPacketTest, SrWithTooManyReportBlocks) { | |
111 SenderReport sr; | |
112 sr.From(kSenderSsrc); | |
113 const int kMaxReportBlocks = (1 << 5) - 1; | |
114 ReportBlock rb; | |
115 for (int i = 0; i < kMaxReportBlocks; ++i) { | |
116 rb.To(kRemoteSsrc + i); | |
117 EXPECT_TRUE(sr.WithReportBlock(rb)); | |
118 } | |
119 rb.To(kRemoteSsrc + kMaxReportBlocks); | |
120 EXPECT_FALSE(sr.WithReportBlock(rb)); | |
121 } | |
122 | |
123 TEST(RtcpPacketTest, AppWithNoData) { | 50 TEST(RtcpPacketTest, AppWithNoData) { |
124 App app; | 51 App app; |
125 app.WithSubType(30); | 52 app.WithSubType(30); |
126 uint32_t name = 'n' << 24; | 53 uint32_t name = 'n' << 24; |
127 name += 'a' << 16; | 54 name += 'a' << 16; |
128 name += 'm' << 8; | 55 name += 'm' << 8; |
129 name += 'e'; | 56 name += 'e'; |
130 app.WithName(name); | 57 app.WithName(name); |
131 | 58 |
132 rtc::scoped_ptr<RawPacket> packet(app.Build()); | 59 rtc::scoped_ptr<RawPacket> packet(app.Build()); |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 EXPECT_TRUE(xr.WithDlrr(&dlrr)); | 736 EXPECT_TRUE(xr.WithDlrr(&dlrr)); |
810 EXPECT_FALSE(xr.WithDlrr(&dlrr)); | 737 EXPECT_FALSE(xr.WithDlrr(&dlrr)); |
811 | 738 |
812 VoipMetric voip_metric; | 739 VoipMetric voip_metric; |
813 for (int i = 0; i < kMaxBlocks; ++i) | 740 for (int i = 0; i < kMaxBlocks; ++i) |
814 EXPECT_TRUE(xr.WithVoipMetric(&voip_metric)); | 741 EXPECT_TRUE(xr.WithVoipMetric(&voip_metric)); |
815 EXPECT_FALSE(xr.WithVoipMetric(&voip_metric)); | 742 EXPECT_FALSE(xr.WithVoipMetric(&voip_metric)); |
816 } | 743 } |
817 | 744 |
818 } // namespace webrtc | 745 } // namespace webrtc |
OLD | NEW |