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

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

Issue 2506373004: RtpPacket::payload() return rtc::ArrayView instead of raw pointer (Closed)
Patch Set: Created 4 years, 1 month 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" 10 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 212
213 RtpPacketReceived packet(&extensions); 213 RtpPacketReceived packet(&extensions);
214 EXPECT_TRUE(packet.Parse(kPacketWithInvalidExtension, 214 EXPECT_TRUE(packet.Parse(kPacketWithInvalidExtension,
215 sizeof(kPacketWithInvalidExtension))); 215 sizeof(kPacketWithInvalidExtension)));
216 216
217 // Extension should be ignored. 217 // Extension should be ignored.
218 int32_t time_offset; 218 int32_t time_offset;
219 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); 219 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset));
220 220
221 // But shouldn't prevent reading payload. 221 // But shouldn't prevent reading payload.
222 EXPECT_THAT(make_tuple(packet.payload(), packet.payload_size()), 222 EXPECT_THAT(packet.payload(), ElementsAreArray(kPayload));
223 ElementsAreArray(kPayload));
224 } 223 }
225 224
226 TEST(RtpPacketTest, ParseWithOverSizedExtension) { 225 TEST(RtpPacketTest, ParseWithOverSizedExtension) {
227 // clang-format off 226 // clang-format off
228 const uint8_t bad_packet[] = { 227 const uint8_t bad_packet[] = {
229 0x90, kPayloadType, 0x00, kSeqNum, 228 0x90, kPayloadType, 0x00, kSeqNum,
230 0x65, 0x43, 0x12, 0x78, // kTimestamp. 229 0x65, 0x43, 0x12, 0x78, // kTimestamp.
231 0x12, 0x34, 0x56, 0x78, // kSsrc. 230 0x12, 0x34, 0x56, 0x78, // kSsrc.
232 0xbe, 0xde, 0x00, 0x01, // Extension of size 1x32bit word. 231 0xbe, 0xde, 0x00, 0x01, // Extension of size 1x32bit word.
233 0x00, // Add a byte of padding. 232 0x00, // Add a byte of padding.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 RtpPacketToSend::ExtensionManager extensions; 266 RtpPacketToSend::ExtensionManager extensions;
268 extensions.Register(kRtpExtensionTransmissionTimeOffset, 267 extensions.Register(kRtpExtensionTransmissionTimeOffset,
269 kTransmissionOffsetExtensionId); 268 kTransmissionOffsetExtensionId);
270 RtpPacketReceived packet(&extensions); 269 RtpPacketReceived packet(&extensions);
271 EXPECT_TRUE(packet.Parse(kPacket, sizeof(kPacket))); 270 EXPECT_TRUE(packet.Parse(kPacket, sizeof(kPacket)));
272 EXPECT_EQ(kPayloadType, packet.PayloadType()); 271 EXPECT_EQ(kPayloadType, packet.PayloadType());
273 EXPECT_EQ(kSeqNum, packet.SequenceNumber()); 272 EXPECT_EQ(kSeqNum, packet.SequenceNumber());
274 EXPECT_EQ(kTimestamp, packet.Timestamp()); 273 EXPECT_EQ(kTimestamp, packet.Timestamp());
275 EXPECT_EQ(kSsrc, packet.Ssrc()); 274 EXPECT_EQ(kSsrc, packet.Ssrc());
276 EXPECT_THAT(packet.Csrcs(), ElementsAreArray(kCsrcs)); 275 EXPECT_THAT(packet.Csrcs(), ElementsAreArray(kCsrcs));
277 EXPECT_THAT(make_tuple(packet.payload(), packet.payload_size()), 276 EXPECT_THAT(packet.payload(), ElementsAreArray(kPayload));
278 ElementsAreArray(kPayload));
279 EXPECT_EQ(kPacketPaddingSize, packet.padding_size()); 277 EXPECT_EQ(kPacketPaddingSize, packet.padding_size());
280 int32_t time_offset; 278 int32_t time_offset;
281 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); 279 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset));
282 } 280 }
283 281
284 TEST(RtpPacketTest, ParseWithExtensionDelayed) { 282 TEST(RtpPacketTest, ParseWithExtensionDelayed) {
285 RtpPacketReceived packet; 283 RtpPacketReceived packet;
286 EXPECT_TRUE(packet.Parse(kPacketWithTO, sizeof(kPacketWithTO))); 284 EXPECT_TRUE(packet.Parse(kPacketWithTO, sizeof(kPacketWithTO)));
287 EXPECT_EQ(kPayloadType, packet.PayloadType()); 285 EXPECT_EQ(kPayloadType, packet.PayloadType());
288 EXPECT_EQ(kSeqNum, packet.SequenceNumber()); 286 EXPECT_EQ(kSeqNum, packet.SequenceNumber());
289 EXPECT_EQ(kTimestamp, packet.Timestamp()); 287 EXPECT_EQ(kTimestamp, packet.Timestamp());
290 EXPECT_EQ(kSsrc, packet.Ssrc()); 288 EXPECT_EQ(kSsrc, packet.Ssrc());
291 289
292 RtpPacketToSend::ExtensionManager extensions; 290 RtpPacketToSend::ExtensionManager extensions;
293 extensions.Register(kRtpExtensionTransmissionTimeOffset, 291 extensions.Register(kRtpExtensionTransmissionTimeOffset,
294 kTransmissionOffsetExtensionId); 292 kTransmissionOffsetExtensionId);
295 293
296 int32_t time_offset; 294 int32_t time_offset;
297 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); 295 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset));
298 packet.IdentifyExtensions(&extensions); 296 packet.IdentifyExtensions(&extensions);
299 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); 297 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset));
300 EXPECT_EQ(kTimeOffset, time_offset); 298 EXPECT_EQ(kTimeOffset, time_offset);
301 EXPECT_EQ(0u, packet.payload_size()); 299 EXPECT_EQ(0u, packet.payload_size());
302 EXPECT_EQ(0u, packet.padding_size()); 300 EXPECT_EQ(0u, packet.padding_size());
303 } 301 }
304 302
305 } // namespace webrtc 303 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698