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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header_unittest.cc

Issue 1575413002: [rtp_rtcp] rtcp header structure copied from RTCPUtility and extended (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: spelling Created 4 years, 9 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
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
12
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using webrtc::rtcp::CommonHeader;
16
17 namespace webrtc {
18 namespace {
19 const size_t kHeaderSizeBytes = 4;
20 } // namespace
21
22 TEST(RtcpCommonHeaderTest, TooSmallBuffer) {
23 uint8_t buffer[] = {0x80, 0x00, 0x00, 0x00};
24 CommonHeader header;
25 // Buffer needs to be able to hold the header.
26 EXPECT_FALSE(header.Parse(buffer, 0));
27 EXPECT_FALSE(header.Parse(buffer, 1));
28 EXPECT_FALSE(header.Parse(buffer, 2));
29 EXPECT_FALSE(header.Parse(buffer, 3));
30 EXPECT_TRUE(header.Parse(buffer, 4));
31 }
32
33 TEST(RtcpCommonHeaderTest, Version) {
34 uint8_t buffer[] = {0x00, 0x00, 0x00, 0x00};
35 CommonHeader header;
36 // Version 2 is the only allowed.
37 buffer[0] = 0 << 6;
38 EXPECT_FALSE(header.Parse(buffer, sizeof(buffer)));
39 buffer[0] = 1 << 6;
40 EXPECT_FALSE(header.Parse(buffer, sizeof(buffer)));
41 buffer[0] = 2 << 6;
42 EXPECT_TRUE(header.Parse(buffer, sizeof(buffer)));
43 buffer[0] = 3 << 6;
44 EXPECT_FALSE(header.Parse(buffer, sizeof(buffer)));
45 }
46
47 TEST(RtcpCommonHeaderTest, PacketSize) {
48 uint8_t buffer[] = {0x80, 0x00, 0x00, 0x02,
49 0x00, 0x00, 0x00, 0x00,
50 0x00, 0x00, 0x00, 0x00};
51 CommonHeader header;
52 EXPECT_FALSE(header.Parse(buffer, sizeof(buffer) - 1));
53 EXPECT_TRUE(header.Parse(buffer, sizeof(buffer)));
54 EXPECT_EQ(8u, header.payload_size_bytes());
55 EXPECT_EQ(buffer + sizeof(buffer), header.NextPacket());
56 }
57
58 TEST(RtcpCommonHeaderTest, PaddingAndPayloadSize) {
59 // Set v = 2, p = 1, but leave fmt, pt as 0.
60 uint8_t buffer[] = {0xa0, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x00};
63 CommonHeader header;
64 // Padding bit set, but no byte for padding (can't specify padding length).
65 EXPECT_FALSE(header.Parse(buffer, 4));
66
67 buffer[3] = 2; // Set payload size to 2x32bit.
68 const size_t kPayloadSizeBytes = buffer[3] * 4;
69 const size_t kPaddingAddress = kHeaderSizeBytes + kPayloadSizeBytes - 1;
70
71 // Padding one byte larger than possible.
72 buffer[kPaddingAddress] = kPayloadSizeBytes + 1;
73 EXPECT_FALSE(header.Parse(buffer, sizeof(buffer)));
74
75 // Invalid zero padding size.
76 buffer[kPaddingAddress] = 0;
77 EXPECT_FALSE(header.Parse(buffer, sizeof(buffer)));
78
79 // Pure padding packet.
80 buffer[kPaddingAddress] = kPayloadSizeBytes;
81 EXPECT_TRUE(header.Parse(buffer, sizeof(buffer)));
82 EXPECT_EQ(0u, header.payload_size_bytes());
83 EXPECT_EQ(buffer + sizeof(buffer), header.NextPacket());
84 EXPECT_EQ(header.payload(), buffer + kHeaderSizeBytes);
85
86 // Single byte of actual data.
87 buffer[kPaddingAddress] = kPayloadSizeBytes - 1;
88 EXPECT_TRUE(header.Parse(buffer, sizeof(buffer)));
89 EXPECT_EQ(1u, header.payload_size_bytes());
90 EXPECT_EQ(buffer + sizeof(buffer), header.NextPacket());
91 }
92
93 TEST(RtcpCommonHeaderTest, FormatAndPayloadType) {
94 uint8_t buffer[] = {0x9e, 0xab, 0x00, 0x00};
95 CommonHeader header;
96 EXPECT_TRUE(header.Parse(buffer, sizeof(buffer)));
97
98 EXPECT_EQ(header.count(), 0x1e);
99 EXPECT_EQ(header.fmt(), 0x1e);
100 EXPECT_EQ(header.type(), 0xab);
101 EXPECT_EQ(header.payload_size_bytes(), 0u);
102 EXPECT_EQ(header.payload(), buffer + kHeaderSizeBytes);
103 }
104 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698