mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-14 14:20:45 +01:00

In https://webrtc-review.googlesource.com/c/src/+/1560 we moved WebRTC from src/webrtc to src/ (in order to preserve an healthy git history). This CL takes care of fixing header guards, #include paths, etc... NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true TBR=tommi@webrtc.org Bug: chromium:611808 Change-Id: Iea91618212bee0af16aa3f05071eab8f93706578 Reviewed-on: https://webrtc-review.googlesource.com/1561 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Henrik Kjellander <kjellander@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#19846}
110 lines
3.3 KiB
C++
110 lines
3.3 KiB
C++
/*
|
|
* 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 "modules/rtp_rtcp/source/rtcp_packet/app.h"
|
|
|
|
#include "test/gmock.h"
|
|
#include "test/gtest.h"
|
|
#include "test/rtcp_packet_parser.h"
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
|
|
using ::testing::ElementsAreArray;
|
|
using ::testing::make_tuple;
|
|
using ::webrtc::rtcp::App;
|
|
|
|
constexpr uint32_t kName = ((uint32_t)'n' << 24) | ((uint32_t)'a' << 16) |
|
|
((uint32_t)'m' << 8) | (uint32_t)'e';
|
|
constexpr uint8_t kSubtype = 0x1e;
|
|
constexpr uint32_t kSenderSsrc = 0x12345678;
|
|
constexpr uint8_t kData[] = {'t', 'e', 's', 't', 'd', 'a', 't', 'a'};
|
|
constexpr uint8_t kVersionBits = 2 << 6;
|
|
constexpr uint8_t kPaddingBit = 1 << 5;
|
|
// clang-format off
|
|
constexpr uint8_t kPacketWithoutData[] = {
|
|
kVersionBits | kSubtype, App::kPacketType, 0x00, 0x02,
|
|
0x12, 0x34, 0x56, 0x78,
|
|
'n', 'a', 'm', 'e'};
|
|
constexpr uint8_t kPacketWithData[] = {
|
|
kVersionBits | kSubtype, App::kPacketType, 0x00, 0x04,
|
|
0x12, 0x34, 0x56, 0x78,
|
|
'n', 'a', 'm', 'e',
|
|
't', 'e', 's', 't',
|
|
'd', 'a', 't', 'a'};
|
|
constexpr uint8_t kTooSmallPacket[] = {
|
|
kVersionBits | kSubtype, App::kPacketType, 0x00, 0x01,
|
|
0x12, 0x34, 0x56, 0x78};
|
|
constexpr uint8_t kPaddingSize = 1;
|
|
constexpr uint8_t kPacketWithUnalignedPayload[] = {
|
|
kVersionBits | kPaddingBit | kSubtype, App::kPacketType, 0x00, 0x03,
|
|
0x12, 0x34, 0x56, 0x78,
|
|
'n', 'a', 'm', 'e',
|
|
'd', 'a', 't', kPaddingSize};
|
|
// clang-format on
|
|
} // namespace
|
|
|
|
TEST(RtcpPacketAppTest, CreateWithoutData) {
|
|
App app;
|
|
app.SetSsrc(kSenderSsrc);
|
|
app.SetSubType(kSubtype);
|
|
app.SetName(kName);
|
|
|
|
rtc::Buffer raw = app.Build();
|
|
|
|
EXPECT_THAT(make_tuple(raw.data(), raw.size()),
|
|
ElementsAreArray(kPacketWithoutData));
|
|
}
|
|
|
|
TEST(RtcpPacketAppTest, ParseWithoutData) {
|
|
App parsed;
|
|
EXPECT_TRUE(test::ParseSinglePacket(kPacketWithoutData, &parsed));
|
|
|
|
EXPECT_EQ(kSenderSsrc, parsed.ssrc());
|
|
EXPECT_EQ(kSubtype, parsed.sub_type());
|
|
EXPECT_EQ(kName, parsed.name());
|
|
EXPECT_EQ(0u, parsed.data_size());
|
|
}
|
|
|
|
TEST(RtcpPacketAppTest, CreateWithData) {
|
|
App app;
|
|
app.SetSsrc(kSenderSsrc);
|
|
app.SetSubType(kSubtype);
|
|
app.SetName(kName);
|
|
app.SetData(kData, sizeof(kData));
|
|
|
|
rtc::Buffer raw = app.Build();
|
|
|
|
EXPECT_THAT(make_tuple(raw.data(), raw.size()),
|
|
ElementsAreArray(kPacketWithData));
|
|
}
|
|
|
|
TEST(RtcpPacketAppTest, ParseWithData) {
|
|
App parsed;
|
|
EXPECT_TRUE(test::ParseSinglePacket(kPacketWithData, &parsed));
|
|
|
|
EXPECT_EQ(kSenderSsrc, parsed.ssrc());
|
|
EXPECT_EQ(kSubtype, parsed.sub_type());
|
|
EXPECT_EQ(kName, parsed.name());
|
|
EXPECT_THAT(make_tuple(parsed.data(), parsed.data_size()),
|
|
ElementsAreArray(kData));
|
|
}
|
|
|
|
TEST(RtcpPacketAppTest, ParseFailsOnTooSmallPacket) {
|
|
App parsed;
|
|
EXPECT_FALSE(test::ParseSinglePacket(kTooSmallPacket, &parsed));
|
|
}
|
|
|
|
TEST(RtcpPacketAppTest, ParseFailsOnUnalignedPayload) {
|
|
App parsed;
|
|
EXPECT_FALSE(test::ParseSinglePacket(kPacketWithUnalignedPayload, &parsed));
|
|
}
|
|
|
|
} // namespace webrtc
|