Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/remb_unittest.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e53138913652495f8f2a57129fbdf1edec87e700 |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/remb_unittest.cc |
@@ -0,0 +1,134 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h" |
+ |
åsapersson
2016/01/13 14:11:32
Should this file be part of this CL?
danilchap
2016/01/13 15:54:44
oops, removed.
|
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using ::testing::ElementsAreArray; |
+using ::testing::Eq; |
+using ::testing::make_tuple; |
+ |
+using webrtc::rtcp::RawPacket; |
+using webrtc::rtcp::Remb; |
+ |
+namespace webrtc { |
+namespace { |
+ |
+const uint32_t kSenderSsrc = 0x12345678; |
+ |
+const uint32_t kRemoteSsrc[] = {0x23456789, 0x2345678a, 0x2345678b}; |
+const uint32_t kBitrate = 0x3fb93 * 2; // 522022; |
+ |
+const uint8_t kPacket[] = {0x8f, 206, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, |
+ 0x00, 0x00, 0x00, 0x00, 'R', 'E', 'M', 'B', |
+ 0x03, 0x07, 0xfb, 0x93, 0x23, 0x45, 0x67, 0x89, |
+ 0x23, 0x45, 0x67, 0x8a, 0x23, 0x45, 0x67, 0x8b}; |
+const size_t kPacketLength = sizeof(kPacket); |
+ |
+bool ParseRemb(const uint8_t* buffer, size_t length, Remb* remb) { |
+ using RTCPUtility::RtcpCommonHeader; |
+ using RTCPUtility::RtcpParseCommonHeader; |
+ RtcpCommonHeader header; |
+ EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header)); |
+ EXPECT_THAT(header.BlockSize(), Eq(length)); |
+ return remb->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes); |
+} |
+ |
+TEST(RtcpPacketRembTest, Create) { |
+ Remb remb; |
+ remb.From(kSenderSsrc); |
+ remb.AppliesTo(kRemoteSsrc[0]); |
+ remb.AppliesTo(kRemoteSsrc[1]); |
+ remb.AppliesTo(kRemoteSsrc[2]); |
+ remb.WithBitrateBps(kBitrate); |
+ |
+ rtc::scoped_ptr<RawPacket> packet = remb.Build(); |
+ |
+ EXPECT_THAT(make_tuple(packet->Buffer(), packet->Length()), |
+ ElementsAreArray(kPacket)); |
+} |
+ |
+TEST(RtcpPacketRembTest, Parse) { |
+ Remb remb; |
+ EXPECT_TRUE(ParseRemb(kPacket, kPacketLength, &remb)); |
+ const Remb& parsed = remb; |
+ |
+ EXPECT_THAT(parsed.sender_ssrc(), Eq(kSenderSsrc)); |
+ EXPECT_THAT(parsed.bitrate_bps(), Eq(kBitrate)); |
+ EXPECT_THAT(parsed.ssrcs(), ElementsAreArray(kRemoteSsrc)); |
+} |
+ |
+TEST(RtcpPacketRembTest, CreateAndParseEmpty) { |
+ const uint32_t kBitrate = 500000; |
+ Remb remb; |
+ remb.From(kSenderSsrc); |
+ remb.WithBitrateBps(kBitrate); |
+ rtc::scoped_ptr<RawPacket> packet = remb.Build(); |
+ |
+ Remb parsed; |
+ EXPECT_TRUE(ParseRemb(packet->Buffer(), packet->Length(), &parsed)); |
+ EXPECT_THAT(parsed.sender_ssrc(), Eq(kSenderSsrc)); |
+ EXPECT_THAT(parsed.bitrate_bps(), Eq(kBitrate)); |
+} |
+ |
+TEST(RtcpPacketRembTest, ParseFailsOnNonRembTooSmall) { |
+ uint8_t packet[kPacketLength]; |
+ memcpy(packet, kPacket, kPacketLength); |
+ packet[3] = 3; // Make it too small. |
+ |
+ Remb remb; |
+ EXPECT_FALSE(ParseRemb(packet, (1 + 3) * 4, &remb)); |
+} |
+ |
+TEST(RtcpPacketRembTest, ParseFailsOnNonRembSignature) { |
+ uint8_t packet[kPacketLength]; |
+ memcpy(packet, kPacket, kPacketLength); |
+ packet[12] = 'N'; // Swap 'R' -> 'N' in the 'REMB' signature. |
+ |
+ Remb remb; |
+ EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb)); |
+} |
+ |
+TEST(RtcpPacketRembTest, ParseFailsWhenSsrcCountMismatchLength) { |
+ uint8_t packet[kPacketLength]; |
+ memcpy(packet, kPacket, kPacketLength); |
+ packet[16]++; // Swap 3 -> 4 in the ssrcs count. |
+ |
+ Remb remb; |
+ EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb)); |
+} |
+ |
+TEST(RtcpPacketRembTest, TooManySsrcs) { |
+ const size_t kMax = 0xff; |
+ Remb remb; |
+ for (size_t i = 1; i <= kMax; ++i) |
+ EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc[0] + i)); |
+ EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc[0])); |
+} |
+ |
+TEST(RtcpPacketRembTest, TooManyForBatchAssign) { |
+ const size_t kMax = 0xff; |
+ Remb remb; |
+ |
+ std::vector<uint32_t> AlmostAll(kMax - 1, kRemoteSsrc[0]); |
+ EXPECT_TRUE(remb.AppliesToMany(AlmostAll)); |
+ // Should be no place for 2 more. |
+ std::vector<uint32_t> TwoMoreSsrcs(2, kRemoteSsrc[1]); |
+ EXPECT_FALSE(remb.AppliesToMany(TwoMoreSsrcs)); |
+ // But enough place for 1 more. |
+ EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc[2])); |
+ // But not for another one. |
+ EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc[2] + 1)); |
+} |
+ |
+} // namespace |
+} // namespace webrtc |