| Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc
|
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..db016d73a8825c8d8b9be5c83a6fb44df96c3905
|
| --- /dev/null
|
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc
|
| @@ -0,0 +1,105 @@
|
| +/*
|
| + * Copyright (c) 2015 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/app.h"
|
| +
|
| +#include <limits>
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
|
| +
|
| +using webrtc::rtcp::RawPacket;
|
| +using webrtc::rtcp::App;
|
| +using webrtc::RTCPUtility::RtcpCommonHeader;
|
| +using webrtc::RTCPUtility::RtcpParseCommonHeader;
|
| +
|
| +namespace webrtc {
|
| +namespace {
|
| +
|
| +const uint32_t kName = ((uint32_t)'n' << 24) | ((uint32_t)'a' << 16) |
|
| + ((uint32_t)'m' << 8) | (uint32_t)'e';
|
| +const uint32_t kSenderSsrc = 0x12345678;
|
| +
|
| +class RtcpPacketAppTest : public ::testing::Test {
|
| + protected:
|
| + void BuildPacket() { packet = app.Build().Pass(); }
|
| + void ParsePacket() {
|
| + RtcpCommonHeader header;
|
| + EXPECT_TRUE(
|
| + RtcpParseCommonHeader(packet->Buffer(), packet->Length(), &header));
|
| + // Check there is exactly one RTCP packet in the buffer.
|
| + EXPECT_EQ(header.BlockSize(), packet->Length());
|
| + EXPECT_TRUE(parsed_.Parse(
|
| + header, packet->Buffer() + RtcpCommonHeader::kHeaderSizeBytes));
|
| + }
|
| +
|
| + App app;
|
| + rtc::scoped_ptr<RawPacket> packet;
|
| + const App& parsed() { return parsed_; }
|
| +
|
| + private:
|
| + App parsed_;
|
| +};
|
| +
|
| +TEST_F(RtcpPacketAppTest, WithNoData) {
|
| + EXPECT_TRUE(app.WithSubType(30));
|
| + app.WithName(kName);
|
| +
|
| + BuildPacket();
|
| + ParsePacket();
|
| +
|
| + EXPECT_EQ(30U, parsed().sub_type());
|
| + EXPECT_EQ(kName, parsed().name());
|
| + EXPECT_EQ(0u, parsed().data_size());
|
| +}
|
| +
|
| +TEST_F(RtcpPacketAppTest, WithData) {
|
| + app.From(kSenderSsrc);
|
| + EXPECT_TRUE(app.WithSubType(30));
|
| + app.WithName(kName);
|
| + const char kData[] = {'t', 'e', 's', 't', 'd', 'a', 't', 'a'};
|
| + const size_t kDataLength = sizeof(kData) / sizeof(kData[0]);
|
| + EXPECT_TRUE(app.WithData((const uint8_t*)kData, kDataLength));
|
| +
|
| + BuildPacket();
|
| + ParsePacket();
|
| +
|
| + EXPECT_EQ(30U, parsed().sub_type());
|
| + EXPECT_EQ(kName, parsed().name());
|
| + EXPECT_EQ(kDataLength, parsed().data_size());
|
| + EXPECT_EQ(0, strncmp(kData, (const char*)parsed().data(), kDataLength));
|
| +}
|
| +
|
| +TEST_F(RtcpPacketAppTest, FailUnalignedData) {
|
| + const char kCharData[] = {'u', 'n', 'a', 'l', 'i', 'g', 'n', 'e', 'd'};
|
| + const size_t kDataLength = sizeof(kCharData); // 9
|
| + const uint8_t* const kData = reinterpret_cast<const uint8_t*>(kCharData);
|
| + static_assert(0 != (kDataLength % 4),
|
| + "Data should NOT be 32bit aligned for this test");
|
| +
|
| + EXPECT_FALSE(app.WithData(kData, kDataLength));
|
| + EXPECT_TRUE(app.WithData(kData, kDataLength - (kDataLength % 4)));
|
| +}
|
| +
|
| +TEST_F(RtcpPacketAppTest, FailOverSizedData) {
|
| + const size_t kMaxLength = App::kMaxDataSize;
|
| + uint8_t kData[kMaxLength + 1];
|
| + EXPECT_FALSE(app.WithData(kData, kMaxLength + 1));
|
| + EXPECT_TRUE(app.WithData(kData, kMaxLength));
|
| +}
|
| +
|
| +TEST_F(RtcpPacketAppTest, FailUnboundSubType) {
|
| + const uint8_t kMaxSubType = 0x1f;
|
| + EXPECT_FALSE(app.WithSubType(kMaxSubType + 1));
|
| + EXPECT_TRUE(app.WithSubType(kMaxSubType));
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace webrtc
|
|
|