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

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

Issue 1307663004: Add a ParseHeader method to RtcpPacket, for parsing common RTCP header. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merged RtcpPacket header parsing with RTCPUtility Created 5 years, 3 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/base/checks.h"
17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" 18 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
17 #include "webrtc/test/rtcp_packet_parser.h" 19 #include "webrtc/test/rtcp_packet_parser.h"
18 20
19 using ::testing::ElementsAre; 21 using ::testing::ElementsAre;
20 22
21 using webrtc::rtcp::App; 23 using webrtc::rtcp::App;
22 using webrtc::rtcp::Bye; 24 using webrtc::rtcp::Bye;
23 using webrtc::rtcp::Dlrr; 25 using webrtc::rtcp::Dlrr;
24 using webrtc::rtcp::Empty; 26 using webrtc::rtcp::Empty;
25 using webrtc::rtcp::Fir; 27 using webrtc::rtcp::Fir;
(...skipping 10 matching lines...) Expand all
36 using webrtc::rtcp::Rpsi; 38 using webrtc::rtcp::Rpsi;
37 using webrtc::rtcp::Rrtr; 39 using webrtc::rtcp::Rrtr;
38 using webrtc::rtcp::SenderReport; 40 using webrtc::rtcp::SenderReport;
39 using webrtc::rtcp::Tmmbn; 41 using webrtc::rtcp::Tmmbn;
40 using webrtc::rtcp::Tmmbr; 42 using webrtc::rtcp::Tmmbr;
41 using webrtc::rtcp::VoipMetric; 43 using webrtc::rtcp::VoipMetric;
42 using webrtc::rtcp::Xr; 44 using webrtc::rtcp::Xr;
43 using webrtc::test::RtcpPacketParser; 45 using webrtc::test::RtcpPacketParser;
44 46
45 namespace webrtc { 47 namespace webrtc {
48 namespace rtcp {
46 49
47 const uint32_t kSenderSsrc = 0x12345678; 50 const uint32_t kSenderSsrc = 0x12345678;
48 const uint32_t kRemoteSsrc = 0x23456789; 51 const uint32_t kRemoteSsrc = 0x23456789;
49 52
53 // Override RtcpPacket so we can test protected methods.
54 class RtcpPacketHeaderTest : public ::testing::Test, protected RtcpPacket {
55 public:
56 RtcpPacketHeaderTest() { memset(buffer, 0, kBufferCapacity); }
57
58 virtual ~RtcpPacketHeaderTest() {}
59
60 bool Create(uint8_t* packet,
61 size_t* index,
62 size_t max_length,
63 PacketReadyCallback* callback) const override {
64 RTC_NOTREACHED();
65 return false;
66 }
67
68 size_t BlockLength() const { return 0; }
69
70 protected:
71 static const size_t kHeaderSize = 4;
72 static const size_t kBufferCapacity = 40;
åsapersson 2015/09/08 10:20:41 kHeaderSize -> kHeaderSizeInBytes kBufferCapacity
sprang_webrtc 2015/09/09 09:18:53 Done.
73 uint8_t buffer[kBufferCapacity];
74 RTCPUtility::RtcpCommonHeader header;
75 };
76
åsapersson 2015/09/08 10:20:41 I think these parsing tests should be where the pa
sprang_webrtc 2015/09/09 09:18:53 Fair enough. My long (long) term hope is to rewrit
77 TEST_F(RtcpPacketHeaderTest, HeaderSize) {
åsapersson 2015/09/08 10:20:41 Maybe rename to something like TooShortHeaderSize.
sprang_webrtc 2015/09/09 09:18:54 Renamed to TooSmallBuffer.
78 // Buffer needs to be able to hold the header.
79 for (size_t i = 0; i < kHeaderSize; ++i)
80 EXPECT_FALSE(RtcpParseCommonHeader(buffer, 0, i, &header));
81 }
82
83 TEST_F(RtcpPacketHeaderTest, Version) {
84 // Version 2 is the only allowed for now.
85 for (int v = 0; v < 4; ++v) {
86 buffer[0] = v << 6;
87 EXPECT_EQ(v == 2, RtcpParseCommonHeader(buffer, 0, kHeaderSize, &header));
88 }
89 }
90
91 TEST_F(RtcpPacketHeaderTest, PacketSize) {
92 // Set v = 2, leave p, fmt, pt as 0.
93 buffer[0] = 2 << 6;
94
95 const size_t kBlockSize = 3;
96 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize);
97 const size_t kSizeInBytes = (kBlockSize + 1) * 4;
98
99 EXPECT_FALSE(RtcpParseCommonHeader(buffer, 0, kSizeInBytes - 1, &header));
100 EXPECT_TRUE(RtcpParseCommonHeader(buffer, 0, kSizeInBytes, &header));
101 }
102
103 TEST_F(RtcpPacketHeaderTest, PayloadSize) {
104 // Set v = 2, p = 1, but leave fmt, pt as 0.
105 buffer[0] = (2 << 6) | (1 << 5);
106
107 const size_t kBlockSize = 3;
108 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize);
109 const size_t kSizeInBytes = (kBlockSize + 1) * 4;
110 const size_t kPayloadSize = kSizeInBytes - kHeaderSize;
åsapersson 2015/09/08 10:20:41 kPayloadSize -> kPayloadSizeInBytes
sprang_webrtc 2015/09/09 09:18:53 Done.
111
112 // Padding one byte larger than possible.
113 buffer[kSizeInBytes - 1] = kPayloadSize + 1;
114 EXPECT_FALSE(RtcpParseCommonHeader(buffer, 0, kSizeInBytes, &header));
115
116 // Pure padding packet?
117 buffer[kSizeInBytes - 1] = kPayloadSize;
118 EXPECT_TRUE(RtcpParseCommonHeader(buffer, 0, kSizeInBytes, &header));
119 EXPECT_EQ(0u, header.payload_size_bytes);
120
121 // Single byte of actual data.
122 buffer[kSizeInBytes - 1] = kPayloadSize - 1;
123 EXPECT_TRUE(RtcpParseCommonHeader(buffer, 0, kSizeInBytes, &header));
124 EXPECT_EQ(1u, header.payload_size_bytes);
125 }
126
127 TEST_F(RtcpPacketHeaderTest, FormatAndPayloadType) {}
åsapersson 2015/09/08 10:20:41 remove
sprang_webrtc 2015/09/09 09:18:53 Or implement :)
128
50 TEST(RtcpPacketTest, Rr) { 129 TEST(RtcpPacketTest, Rr) {
51 ReceiverReport rr; 130 ReceiverReport rr;
52 rr.From(kSenderSsrc); 131 rr.From(kSenderSsrc);
53 132
54 rtc::scoped_ptr<RawPacket> packet(rr.Build()); 133 rtc::scoped_ptr<RawPacket> packet(rr.Build());
55 RtcpPacketParser parser; 134 RtcpPacketParser parser;
56 parser.Parse(packet->Buffer(), packet->Length()); 135 parser.Parse(packet->Buffer(), packet->Length());
57 EXPECT_EQ(1, parser.receiver_report()->num_packets()); 136 EXPECT_EQ(1, parser.receiver_report()->num_packets());
58 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc()); 137 EXPECT_EQ(kSenderSsrc, parser.receiver_report()->Ssrc());
59 EXPECT_EQ(0, parser.report_block()->num_packets()); 138 EXPECT_EQ(0, parser.report_block()->num_packets());
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 for (int i = 0; i < kMaxBlocks; ++i) 1157 for (int i = 0; i < kMaxBlocks; ++i)
1079 EXPECT_TRUE(xr.WithDlrr(&dlrr)); 1158 EXPECT_TRUE(xr.WithDlrr(&dlrr));
1080 EXPECT_FALSE(xr.WithDlrr(&dlrr)); 1159 EXPECT_FALSE(xr.WithDlrr(&dlrr));
1081 1160
1082 VoipMetric voip_metric; 1161 VoipMetric voip_metric;
1083 for (int i = 0; i < kMaxBlocks; ++i) 1162 for (int i = 0; i < kMaxBlocks; ++i)
1084 EXPECT_TRUE(xr.WithVoipMetric(&voip_metric)); 1163 EXPECT_TRUE(xr.WithVoipMetric(&voip_metric));
1085 EXPECT_FALSE(xr.WithVoipMetric(&voip_metric)); 1164 EXPECT_FALSE(xr.WithVoipMetric(&voip_metric));
1086 } 1165 }
1087 1166
1167 } // namespace rtcp
1088 } // namespace webrtc 1168 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698