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

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

Issue 1583233007: [rtp_rtcp] rtcp::Rpsi moved into own file (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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::Rpsi;
30 using webrtc::rtcp::Sdes; 29 using webrtc::rtcp::Sdes;
31 using webrtc::rtcp::SenderReport; 30 using webrtc::rtcp::SenderReport;
32 using webrtc::test::RtcpPacketParser; 31 using webrtc::test::RtcpPacketParser;
33 32
34 namespace webrtc { 33 namespace webrtc {
35 34
36 const uint32_t kSenderSsrc = 0x12345678; 35 const uint32_t kSenderSsrc = 0x12345678;
37 const uint32_t kRemoteSsrc = 0x23456789; 36 const uint32_t kRemoteSsrc = 0x23456789;
38 37
39 TEST(RtcpPacketTest, Sr) { 38 TEST(RtcpPacketTest, Sr) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 201
203 rtc::scoped_ptr<RawPacket> packet(sdes.Build()); 202 rtc::scoped_ptr<RawPacket> packet(sdes.Build());
204 RtcpPacketParser parser; 203 RtcpPacketParser parser;
205 parser.Parse(packet->Buffer(), packet->Length()); 204 parser.Parse(packet->Buffer(), packet->Length());
206 EXPECT_EQ(1, parser.sdes()->num_packets()); 205 EXPECT_EQ(1, parser.sdes()->num_packets());
207 EXPECT_EQ(1, parser.sdes_chunk()->num_packets()); 206 EXPECT_EQ(1, parser.sdes_chunk()->num_packets());
208 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc()); 207 EXPECT_EQ(kSenderSsrc, parser.sdes_chunk()->Ssrc());
209 EXPECT_EQ("", parser.sdes_chunk()->Cname()); 208 EXPECT_EQ("", parser.sdes_chunk()->Cname());
210 } 209 }
211 210
212 TEST(RtcpPacketTest, Rpsi) {
213 Rpsi rpsi;
214 // 1000001 (7 bits = 1 byte in native string).
215 const uint64_t kPictureId = 0x41;
216 const uint16_t kNumberOfValidBytes = 1;
217 rpsi.WithPayloadType(100);
218 rpsi.WithPictureId(kPictureId);
219
220 rtc::scoped_ptr<RawPacket> packet(rpsi.Build());
221 RtcpPacketParser parser;
222 parser.Parse(packet->Buffer(), packet->Length());
223 EXPECT_EQ(100, parser.rpsi()->PayloadType());
224 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits());
225 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId());
226 }
227
228 TEST(RtcpPacketTest, RpsiWithTwoByteNativeString) {
229 Rpsi rpsi;
230 // |1 0000001 (7 bits = 1 byte in native string).
231 const uint64_t kPictureId = 0x81;
232 const uint16_t kNumberOfValidBytes = 2;
233 rpsi.WithPictureId(kPictureId);
234
235 rtc::scoped_ptr<RawPacket> packet(rpsi.Build());
236 RtcpPacketParser parser;
237 parser.Parse(packet->Buffer(), packet->Length());
238 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits());
239 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId());
240 }
241
242 TEST(RtcpPacketTest, RpsiWithThreeByteNativeString) {
243 Rpsi rpsi;
244 // 10000|00 100000|0 1000000 (7 bits = 1 byte in native string).
245 const uint64_t kPictureId = 0x102040;
246 const uint16_t kNumberOfValidBytes = 3;
247 rpsi.WithPictureId(kPictureId);
248
249 rtc::scoped_ptr<RawPacket> packet(rpsi.Build());
250 RtcpPacketParser parser;
251 parser.Parse(packet->Buffer(), packet->Length());
252 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits());
253 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId());
254 }
255
256 TEST(RtcpPacketTest, RpsiWithFourByteNativeString) {
257 Rpsi rpsi;
258 // 1000|001 00001|01 100001|1 1000010 (7 bits = 1 byte in native string).
259 const uint64_t kPictureId = 0x84161C2;
260 const uint16_t kNumberOfValidBytes = 4;
261 rpsi.WithPictureId(kPictureId);
262
263 rtc::scoped_ptr<RawPacket> packet(rpsi.Build());
264 RtcpPacketParser parser;
265 parser.Parse(packet->Buffer(), packet->Length());
266 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits());
267 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId());
268 }
269
270 TEST(RtcpPacketTest, RpsiWithMaxPictureId) {
271 Rpsi rpsi;
272 // 1 1111111| 1111111 1|111111 11|11111 111|1111 1111|111 11111|
273 // 11 111111|1 1111111 (7 bits = 1 byte in native string).
274 const uint64_t kPictureId = 0xffffffffffffffff;
275 const uint16_t kNumberOfValidBytes = 10;
276 rpsi.WithPictureId(kPictureId);
277
278 rtc::scoped_ptr<RawPacket> packet(rpsi.Build());
279 RtcpPacketParser parser;
280 parser.Parse(packet->Buffer(), packet->Length());
281 EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits());
282 EXPECT_EQ(kPictureId, parser.rpsi()->PictureId());
283 }
284 211
285 TEST(RtcpPacketTest, BuildWithTooSmallBuffer) { 212 TEST(RtcpPacketTest, BuildWithTooSmallBuffer) {
286 ReportBlock rb; 213 ReportBlock rb;
287 ReceiverReport rr; 214 ReceiverReport rr;
288 rr.From(kSenderSsrc); 215 rr.From(kSenderSsrc);
289 EXPECT_TRUE(rr.WithReportBlock(rb)); 216 EXPECT_TRUE(rr.WithReportBlock(rb));
290 217
291 const size_t kRrLength = 8; 218 const size_t kRrLength = 8;
292 const size_t kReportBlockLength = 24; 219 const size_t kReportBlockLength = 24;
293 220
294 // No packet. 221 // No packet.
295 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback { 222 class Verifier : public rtcp::RtcpPacket::PacketReadyCallback {
296 void OnPacketReady(uint8_t* data, size_t length) override { 223 void OnPacketReady(uint8_t* data, size_t length) override {
297 ADD_FAILURE() << "Packet should not fit within max size."; 224 ADD_FAILURE() << "Packet should not fit within max size.";
298 } 225 }
299 } verifier; 226 } verifier;
300 const size_t kBufferSize = kRrLength + kReportBlockLength - 1; 227 const size_t kBufferSize = kRrLength + kReportBlockLength - 1;
301 uint8_t buffer[kBufferSize]; 228 uint8_t buffer[kBufferSize];
302 EXPECT_FALSE(rr.BuildExternalBuffer(buffer, kBufferSize, &verifier)); 229 EXPECT_FALSE(rr.BuildExternalBuffer(buffer, kBufferSize, &verifier));
303 } 230 }
304 } // namespace webrtc 231 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi_unittest.cc ('k') | webrtc/modules/rtp_rtcp/source/rtcp_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698