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/sender_report_unittest.cc

Issue 1806073002: rtcp::SenderReport updated to use rtcp::CommonHeader for parsing (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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
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 10
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
12 12
13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
16 #include "webrtc/test/rtcp_packet_parser.h"
17
18 using testing::ElementsAreArray;
19 using testing::make_tuple;
15 using webrtc::rtcp::ReportBlock; 20 using webrtc::rtcp::ReportBlock;
16 using webrtc::rtcp::SenderReport; 21 using webrtc::rtcp::SenderReport;
17 using webrtc::RTCPUtility::RtcpCommonHeader;
18 using webrtc::RTCPUtility::RtcpParseCommonHeader;
19 22
20 namespace webrtc { 23 namespace webrtc {
24 namespace {
25 const uint32_t kSenderSsrc = 0x12345678;
26 const uint32_t kRemoteSsrc = 0x23456789;
27 const NtpTime kNtp(0x11121418, 0x22242628);
28 const uint32_t kRtpTimestamp = 0x33343536;
29 const uint32_t kPacketCount = 0x44454647;
30 const uint32_t kOctetCount = 0x55565758;
31 const uint8_t kPacket[] = {0x80, 200, 0x00, 0x06,
32 0x12, 0x34, 0x56, 0x78,
33 0x11, 0x12, 0x14, 0x18,
34 0x22, 0x24, 0x26, 0x28,
35 0x33, 0x34, 0x35, 0x36,
36 0x44, 0x45, 0x46, 0x47,
37 0x55, 0x56, 0x57, 0x58};
38 } // namespace
21 39
22 class RtcpPacketSenderReportTest : public ::testing::Test { 40 TEST(RtcpPacketSenderReportTest, CreateWithoutReportBlocks) {
23 protected:
24 const uint32_t kSenderSsrc = 0x12345678;
25 const uint32_t kRemoteSsrc = 0x23456789;
26
27 void ParsePacket(const rtc::Buffer& packet) {
28 RtcpCommonHeader header;
29 EXPECT_TRUE(RtcpParseCommonHeader(packet.data(), packet.size(), &header));
30 EXPECT_EQ(packet.size(), header.BlockSize());
31 EXPECT_TRUE(parsed_.Parse(
32 header, packet.data() + RtcpCommonHeader::kHeaderSizeBytes));
33 }
34
35 // Only ParsePacket can change parsed, tests should use it in readonly mode.
36 const SenderReport& parsed() { return parsed_; }
37
38 private:
39 SenderReport parsed_;
40 };
41
42 TEST_F(RtcpPacketSenderReportTest, WithoutReportBlocks) {
43 const NtpTime kNtp(0x11121418, 0x22242628);
44 const uint32_t kRtpTimestamp = 0x33343536;
45 const uint32_t kPacketCount = 0x44454647;
46 const uint32_t kOctetCount = 0x55565758;
47
48 SenderReport sr; 41 SenderReport sr;
49 sr.From(kSenderSsrc); 42 sr.From(kSenderSsrc);
50 sr.WithNtp(kNtp); 43 sr.WithNtp(kNtp);
51 sr.WithRtpTimestamp(kRtpTimestamp); 44 sr.WithRtpTimestamp(kRtpTimestamp);
52 sr.WithPacketCount(kPacketCount); 45 sr.WithPacketCount(kPacketCount);
53 sr.WithOctetCount(kOctetCount); 46 sr.WithOctetCount(kOctetCount);
54 47
55 rtc::Buffer packet = sr.Build(); 48 rtc::Buffer raw = sr.Build();
56 ParsePacket(packet); 49 EXPECT_THAT(make_tuple(raw.data(), raw.size()), ElementsAreArray(kPacket));
57
58 EXPECT_EQ(kSenderSsrc, parsed().sender_ssrc());
59 EXPECT_EQ(kNtp, parsed().ntp());
60 EXPECT_EQ(kRtpTimestamp, parsed().rtp_timestamp());
61 EXPECT_EQ(kPacketCount, parsed().sender_packet_count());
62 EXPECT_EQ(kOctetCount, parsed().sender_octet_count());
63 EXPECT_TRUE(parsed().report_blocks().empty());
64 } 50 }
65 51
66 TEST_F(RtcpPacketSenderReportTest, WithOneReportBlock) { 52 TEST(RtcpPacketSenderReportTest, ParseWithoutReportBlocks) {
53 SenderReport parsed;
54 EXPECT_TRUE(test::ParseSinglePacket(kPacket, &parsed));
55
56 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
57 EXPECT_EQ(kNtp, parsed.ntp());
58 EXPECT_EQ(kRtpTimestamp, parsed.rtp_timestamp());
59 EXPECT_EQ(kPacketCount, parsed.sender_packet_count());
60 EXPECT_EQ(kOctetCount, parsed.sender_octet_count());
61 EXPECT_TRUE(parsed.report_blocks().empty());
62 }
63
64 TEST(RtcpPacketSenderReportTest, WithOneReportBlock) {
67 ReportBlock rb; 65 ReportBlock rb;
68 rb.To(kRemoteSsrc); 66 rb.To(kRemoteSsrc);
69 67
70 SenderReport sr; 68 SenderReport sr;
71 sr.From(kSenderSsrc); 69 sr.From(kSenderSsrc);
72 EXPECT_TRUE(sr.WithReportBlock(rb)); 70 EXPECT_TRUE(sr.WithReportBlock(rb));
73 71
74 rtc::Buffer packet = sr.Build(); 72 rtc::Buffer raw = sr.Build();
75 ParsePacket(packet); 73 SenderReport parsed;
74 EXPECT_TRUE(test::ParseSinglePacket(raw, &parsed));
76 75
77 EXPECT_EQ(kSenderSsrc, parsed().sender_ssrc()); 76 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
78 EXPECT_EQ(1u, parsed().report_blocks().size()); 77 EXPECT_EQ(1u, parsed.report_blocks().size());
79 EXPECT_EQ(kRemoteSsrc, parsed().report_blocks()[0].source_ssrc()); 78 EXPECT_EQ(kRemoteSsrc, parsed.report_blocks()[0].source_ssrc());
80 } 79 }
81 80
82 TEST_F(RtcpPacketSenderReportTest, WithTwoReportBlocks) { 81 TEST(RtcpPacketSenderReportTest, WithTwoReportBlocks) {
83 ReportBlock rb1; 82 ReportBlock rb1;
84 rb1.To(kRemoteSsrc); 83 rb1.To(kRemoteSsrc);
85 ReportBlock rb2; 84 ReportBlock rb2;
86 rb2.To(kRemoteSsrc + 1); 85 rb2.To(kRemoteSsrc + 1);
87 86
88 SenderReport sr; 87 SenderReport sr;
89 sr.From(kSenderSsrc); 88 sr.From(kSenderSsrc);
90 EXPECT_TRUE(sr.WithReportBlock(rb1)); 89 EXPECT_TRUE(sr.WithReportBlock(rb1));
91 EXPECT_TRUE(sr.WithReportBlock(rb2)); 90 EXPECT_TRUE(sr.WithReportBlock(rb2));
92 91
93 rtc::Buffer packet = sr.Build(); 92 rtc::Buffer raw = sr.Build();
94 ParsePacket(packet); 93 SenderReport parsed;
94 EXPECT_TRUE(test::ParseSinglePacket(raw, &parsed));
95 95
96 EXPECT_EQ(kSenderSsrc, parsed().sender_ssrc()); 96 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
97 EXPECT_EQ(2u, parsed().report_blocks().size()); 97 EXPECT_EQ(2u, parsed.report_blocks().size());
98 EXPECT_EQ(kRemoteSsrc, parsed().report_blocks()[0].source_ssrc()); 98 EXPECT_EQ(kRemoteSsrc, parsed.report_blocks()[0].source_ssrc());
99 EXPECT_EQ(kRemoteSsrc + 1, parsed().report_blocks()[1].source_ssrc()); 99 EXPECT_EQ(kRemoteSsrc + 1, parsed.report_blocks()[1].source_ssrc());
100 } 100 }
101 101
102 TEST_F(RtcpPacketSenderReportTest, WithTooManyReportBlocks) { 102 TEST(RtcpPacketSenderReportTest, WithTooManyReportBlocks) {
103 SenderReport sr; 103 SenderReport sr;
104 sr.From(kSenderSsrc); 104 sr.From(kSenderSsrc);
105 const size_t kMaxReportBlocks = (1 << 5) - 1; 105 const size_t kMaxReportBlocks = (1 << 5) - 1;
106 ReportBlock rb; 106 ReportBlock rb;
107 for (size_t i = 0; i < kMaxReportBlocks; ++i) { 107 for (size_t i = 0; i < kMaxReportBlocks; ++i) {
108 rb.To(kRemoteSsrc + i); 108 rb.To(kRemoteSsrc + i);
109 EXPECT_TRUE(sr.WithReportBlock(rb)); 109 EXPECT_TRUE(sr.WithReportBlock(rb));
110 } 110 }
111 rb.To(kRemoteSsrc + kMaxReportBlocks); 111 rb.To(kRemoteSsrc + kMaxReportBlocks);
112 EXPECT_FALSE(sr.WithReportBlock(rb)); 112 EXPECT_FALSE(sr.WithReportBlock(rb));
113 } 113 }
114 114
115 } // namespace webrtc 115 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.cc ('k') | webrtc/test/rtcp_packet_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698