Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc

Issue 1592763002: [rtp_rtcp] rtcp::Sdes moved into own file (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/test/rtcp_packet_parser.h" 20 #include "webrtc/test/rtcp_packet_parser.h"
21 21
22 using ::testing::ElementsAre; 22 using ::testing::ElementsAre;
23 23
24 using webrtc::rtcp::App; 24 using webrtc::rtcp::App;
25 using webrtc::rtcp::Bye; 25 using webrtc::rtcp::Bye;
26 using webrtc::rtcp::RawPacket; 26 using webrtc::rtcp::RawPacket;
27 using webrtc::rtcp::ReceiverReport; 27 using webrtc::rtcp::ReceiverReport;
28 using webrtc::rtcp::ReportBlock; 28 using webrtc::rtcp::ReportBlock;
29 using webrtc::rtcp::Sdes;
30 using webrtc::rtcp::SenderReport; 29 using webrtc::rtcp::SenderReport;
31 using webrtc::test::RtcpPacketParser; 30 using webrtc::test::RtcpPacketParser;
32 31
33 namespace webrtc { 32 namespace webrtc {
34 33
35 const uint32_t kSenderSsrc = 0x12345678; 34 const uint32_t kSenderSsrc = 0x12345678;
36 const uint32_t kRemoteSsrc = 0x23456789; 35 const uint32_t kRemoteSsrc = 0x23456789;
37 36
38 TEST(RtcpPacketTest, Sr) { 37 TEST(RtcpPacketTest, Sr) {
39 SenderReport sr; 38 SenderReport sr;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 parser.Parse(packet->Buffer(), packet->Length()); 144 parser.Parse(packet->Buffer(), packet->Length());
146 EXPECT_EQ(1, parser.app()->num_packets()); 145 EXPECT_EQ(1, parser.app()->num_packets());
147 EXPECT_EQ(30U, parser.app()->SubType()); 146 EXPECT_EQ(30U, parser.app()->SubType());
148 EXPECT_EQ(name, parser.app()->Name()); 147 EXPECT_EQ(name, parser.app()->Name());
149 EXPECT_EQ(1, parser.app_item()->num_packets()); 148 EXPECT_EQ(1, parser.app_item()->num_packets());
150 EXPECT_EQ(kDataLength, parser.app_item()->DataLength()); 149 EXPECT_EQ(kDataLength, parser.app_item()->DataLength());
151 EXPECT_EQ(0, strncmp(kData, (const char*)parser.app_item()->Data(), 150 EXPECT_EQ(0, strncmp(kData, (const char*)parser.app_item()->Data(),
152 parser.app_item()->DataLength())); 151 parser.app_item()->DataLength()));
153 } 152 }
154 153
155 TEST(RtcpPacketTest, SdesWithOneChunk) {
156 Sdes sdes;
157 EXPECT_TRUE(sdes.WithCName(kSenderSsrc, "alice@host"));
158
159 rtc::scoped_ptr<RawPacket> packet(sdes.Build());
160 RtcpPacketParser parser;
161 parser.Parse(packet->Buffer(), packet->Length());
162 EXPECT_EQ(1, parser.sdes()->num_packets());
163 EXPECT_EQ(1, parser.sdes_chunk()->num_packets());
164 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc());
165 EXPECT_EQ("alice@host", parser.sdes_chunk()->Cname());
166 }
167
168 TEST(RtcpPacketTest, SdesWithMultipleChunks) {
169 Sdes sdes;
170 EXPECT_TRUE(sdes.WithCName(kSenderSsrc, "a"));
171 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 1, "ab"));
172 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 2, "abc"));
173 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 3, "abcd"));
174 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 4, "abcde"));
175 EXPECT_TRUE(sdes.WithCName(kSenderSsrc + 5, "abcdef"));
176
177 rtc::scoped_ptr<RawPacket> packet(sdes.Build());
178 RtcpPacketParser parser;
179 parser.Parse(packet->Buffer(), packet->Length());
180 EXPECT_EQ(1, parser.sdes()->num_packets());
181 EXPECT_EQ(6, parser.sdes_chunk()->num_packets());
182 EXPECT_EQ(kSenderSsrc + 5, parser.sdes_chunk()->Ssrc());
183 EXPECT_EQ("abcdef", parser.sdes_chunk()->Cname());
184 }
185
186 TEST(RtcpPacketTest, SdesWithTooManyChunks) {
187 Sdes sdes;
188 const int kMaxChunks = (1 << 5) - 1;
189 for (int i = 0; i < kMaxChunks; ++i) {
190 uint32_t ssrc = kSenderSsrc + i;
191 std::ostringstream oss;
192 oss << "cname" << i;
193 EXPECT_TRUE(sdes.WithCName(ssrc, oss.str()));
194 }
195 EXPECT_FALSE(sdes.WithCName(kSenderSsrc + kMaxChunks, "foo"));
196 }
197
198 TEST(RtcpPacketTest, CnameItemWithEmptyString) {
199 Sdes sdes;
200 EXPECT_TRUE(sdes.WithCName(kSenderSsrc, ""));
201
202 rtc::scoped_ptr<RawPacket> packet(sdes.Build());
203 RtcpPacketParser parser;
204 parser.Parse(packet->Buffer(), packet->Length());
205 EXPECT_EQ(1, parser.sdes()->num_packets());
206 EXPECT_EQ(1, parser.sdes_chunk()->num_packets());
207 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc());
208 EXPECT_EQ("", parser.sdes_chunk()->Cname());
209 }
210
211
212 TEST(RtcpPacketTest, BuildWithTooSmallBuffer) { 154 TEST(RtcpPacketTest, BuildWithTooSmallBuffer) {
213 ReportBlock rb; 155 ReportBlock rb;
214 ReceiverReport rr; 156 ReceiverReport rr;
215 rr.From(kSenderSsrc); 157 rr.From(kSenderSsrc);
216 EXPECT_TRUE(rr.WithReportBlock(rb)); 158 EXPECT_TRUE(rr.WithReportBlock(rb));
217 159
218 const size_t kRrLength = 8; 160 const size_t kRrLength = 8;
219 const size_t kReportBlockLength = 24; 161 const size_t kReportBlockLength = 24;
220 162
221 // No packet. 163 // No packet.
222 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback { 164 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback {
223 void OnPacketReady(uint8_t* data, size_t length) override { 165 void OnPacketReady(uint8_t* data, size_t length) override {
224 ADD_FAILURE() << "Packet should not fit within max size."; 166 ADD_FAILURE() << "Packet should not fit within max size.";
225 } 167 }
226 } verifier; 168 } verifier;
227 const size_t kBufferSize = kRrLength + kReportBlockLength - 1; 169 const size_t kBufferSize = kRrLength + kReportBlockLength - 1;
228 uint8_t buffer[kBufferSize]; 170 uint8_t buffer[kBufferSize];
229 EXPECT_FALSE(rr.BuildExternalBuffer(buffer, kBufferSize, &verifier)); 171 EXPECT_FALSE(rr.BuildExternalBuffer(buffer, kBufferSize, &verifier));
230 } 172 }
231 } // namespace webrtc 173 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes_unittest.cc ('k') | webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698