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

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

Issue 2680183004: Remove rtcp_utility as mostly unused. (Closed)
Patch Set: NackStats -> RtcpNackStats Created 3 years, 10 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_utility.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) 2014 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/base/checks.h"
12 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
13 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
14 #include "webrtc/test/gtest.h"
15
16 namespace webrtc {
17
18 using RTCPUtility::RtcpCommonHeader;
19
20 namespace rtcp {
21
22 TEST(RtcpUtilityTest, MidNtp) {
23 const uint32_t kNtpSec = 0x12345678;
24 const uint32_t kNtpFrac = 0x23456789;
25 const uint32_t kNtpMid = 0x56782345;
26 EXPECT_EQ(kNtpMid, RTCPUtility::MidNtp(kNtpSec, kNtpFrac));
27 }
28
29 TEST(RtcpUtilityTest, NackRequests) {
30 RTCPUtility::NackStats stats;
31 EXPECT_EQ(0U, stats.unique_requests());
32 EXPECT_EQ(0U, stats.requests());
33 stats.ReportRequest(10);
34 EXPECT_EQ(1U, stats.unique_requests());
35 EXPECT_EQ(1U, stats.requests());
36
37 stats.ReportRequest(10);
38 EXPECT_EQ(1U, stats.unique_requests());
39 stats.ReportRequest(11);
40 EXPECT_EQ(2U, stats.unique_requests());
41
42 stats.ReportRequest(11);
43 EXPECT_EQ(2U, stats.unique_requests());
44 stats.ReportRequest(13);
45 EXPECT_EQ(3U, stats.unique_requests());
46
47 stats.ReportRequest(11);
48 EXPECT_EQ(3U, stats.unique_requests());
49 EXPECT_EQ(6U, stats.requests());
50 }
51
52 TEST(RtcpUtilityTest, NackRequestsWithWrap) {
53 RTCPUtility::NackStats stats;
54 stats.ReportRequest(65534);
55 EXPECT_EQ(1U, stats.unique_requests());
56
57 stats.ReportRequest(65534);
58 EXPECT_EQ(1U, stats.unique_requests());
59 stats.ReportRequest(65535);
60 EXPECT_EQ(2U, stats.unique_requests());
61
62 stats.ReportRequest(65535);
63 EXPECT_EQ(2U, stats.unique_requests());
64 stats.ReportRequest(0);
65 EXPECT_EQ(3U, stats.unique_requests());
66
67 stats.ReportRequest(65535);
68 EXPECT_EQ(3U, stats.unique_requests());
69 stats.ReportRequest(0);
70 EXPECT_EQ(3U, stats.unique_requests());
71 stats.ReportRequest(1);
72 EXPECT_EQ(4U, stats.unique_requests());
73 EXPECT_EQ(8U, stats.requests());
74 }
75
76 class RtcpParseCommonHeaderTest : public ::testing::Test {
77 public:
78 RtcpParseCommonHeaderTest() { memset(buffer, 0, kBufferCapacityBytes); }
79 virtual ~RtcpParseCommonHeaderTest() {}
80
81 protected:
82 static const size_t kBufferCapacityBytes = 40;
83 uint8_t buffer[kBufferCapacityBytes];
84 RtcpCommonHeader header;
85 };
86
87 TEST_F(RtcpParseCommonHeaderTest, TooSmallBuffer) {
88 // Buffer needs to be able to hold the header.
89 for (size_t i = 0; i < RtcpCommonHeader::kHeaderSizeBytes; ++i)
90 EXPECT_FALSE(RtcpParseCommonHeader(buffer, i, &header));
91 }
92
93 TEST_F(RtcpParseCommonHeaderTest, Version) {
94 // Version 2 is the only allowed for now.
95 for (int v = 0; v < 4; ++v) {
96 buffer[0] = v << 6;
97 EXPECT_EQ(v == 2, RtcpParseCommonHeader(
98 buffer, RtcpCommonHeader::kHeaderSizeBytes, &header));
99 }
100 }
101
102 TEST_F(RtcpParseCommonHeaderTest, PacketSize) {
103 // Set v = 2, leave p, fmt, pt as 0.
104 buffer[0] = 2 << 6;
105
106 const size_t kBlockSize = 3;
107 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize);
108 const size_t kSizeInBytes = (kBlockSize + 1) * 4;
109
110 EXPECT_FALSE(RtcpParseCommonHeader(buffer, kSizeInBytes - 1, &header));
111 EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
112 }
113
114 TEST_F(RtcpParseCommonHeaderTest, PayloadSize) {
115 // Set v = 2, p = 1, but leave fmt, pt as 0.
116 buffer[0] = (2 << 6) | (1 << 5);
117
118 // Padding bit set, but no byte for padding (can't specify padding length).
119 EXPECT_FALSE(RtcpParseCommonHeader(buffer, 4, &header));
120
121 const size_t kBlockSize = 3;
122 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize);
123 const size_t kSizeInBytes = (kBlockSize + 1) * 4;
124 const size_t kPayloadSizeBytes =
125 kSizeInBytes - RtcpCommonHeader::kHeaderSizeBytes;
126
127 // Padding one byte larger than possible.
128 buffer[kSizeInBytes - 1] = kPayloadSizeBytes + 1;
129 EXPECT_FALSE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
130
131 // Pure padding packet?
132 buffer[kSizeInBytes - 1] = kPayloadSizeBytes;
133 EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
134 EXPECT_EQ(kPayloadSizeBytes, header.padding_bytes);
135 EXPECT_EQ(0u, header.payload_size_bytes);
136
137 // Single byte of actual data.
138 buffer[kSizeInBytes - 1] = kPayloadSizeBytes - 1;
139 EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
140 EXPECT_EQ(kPayloadSizeBytes - 1, header.padding_bytes);
141 EXPECT_EQ(1u, header.payload_size_bytes);
142 }
143
144 TEST_F(RtcpParseCommonHeaderTest, FormatAndPayloadType) {
145 // Format/count and packet type both set to max values.
146 const uint8_t kCountOrFormat = 0x1F;
147 const uint8_t kPacketType = 0xFF;
148 buffer[0] = 2 << 6; // V = 2.
149 buffer[0] |= kCountOrFormat;
150 buffer[1] = kPacketType;
151
152 EXPECT_TRUE(RtcpParseCommonHeader(buffer, RtcpCommonHeader::kHeaderSizeBytes,
153 &header));
154 EXPECT_EQ(kCountOrFormat, header.count_or_format);
155 EXPECT_EQ(kPacketType, header.packet_type);
156 }
157
158 } // namespace rtcp
159 } // namespace webrtc
160
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_utility.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698