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

Unified Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc

Issue 1998633002: [rtcp] App::Parse updated not to use RTCPUtility, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/app.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 2aa4d94e78e7c47d9e52a8bfc36634089618f074..abc8f04f00959f5999af9033720d473291ffeb1a 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc
@@ -10,70 +10,101 @@
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h"
-#include <limits>
-
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
-
-using webrtc::rtcp::App;
-using webrtc::RTCPUtility::RtcpCommonHeader;
-using webrtc::RTCPUtility::RtcpParseCommonHeader;
+#include "webrtc/test/rtcp_packet_parser.h"
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(); }
- void ParsePacket() {
- RtcpCommonHeader header;
- EXPECT_TRUE(RtcpParseCommonHeader(packet.data(), packet.size(), &header));
- // Check there is exactly one RTCP packet in the buffer.
- EXPECT_EQ(header.BlockSize(), packet.size());
- EXPECT_TRUE(parsed_.Parse(
- header, packet.data() + RtcpCommonHeader::kHeaderSizeBytes));
- }
+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;
- rtc::Buffer packet;
- const App& parsed() { return parsed_; }
+ app.From(kSenderSsrc);
+ app.WithSubType(kSubtype);
+ app.WithName(kName);
- private:
- App parsed_;
-};
+ rtc::Buffer raw = app.Build();
-TEST_F(RtcpPacketAppTest, WithNoData) {
- app.WithSubType(30);
- app.WithName(kName);
+ EXPECT_THAT(make_tuple(raw.data(), raw.size()),
+ ElementsAreArray(kPacketWithoutData));
+}
- BuildPacket();
- ParsePacket();
+TEST(RtcpPacketAppTest, ParseWithoutData) {
+ App parsed;
+ EXPECT_TRUE(test::ParseSinglePacket(kPacketWithoutData, &parsed));
- EXPECT_EQ(30U, parsed().sub_type());
- EXPECT_EQ(kName, parsed().name());
- EXPECT_EQ(0u, parsed().data_size());
+ EXPECT_EQ(kSenderSsrc, parsed.ssrc());
+ EXPECT_EQ(kSubtype, parsed.sub_type());
+ EXPECT_EQ(kName, parsed.name());
+ EXPECT_EQ(0u, parsed.data_size());
}
-TEST_F(RtcpPacketAppTest, WithData) {
+TEST(RtcpPacketAppTest, CreateWithData) {
+ App app;
app.From(kSenderSsrc);
- app.WithSubType(30);
+ app.WithSubType(kSubtype);
app.WithName(kName);
- const uint8_t kData[] = {'t', 'e', 's', 't', 'd', 'a', 't', 'a'};
- const size_t kDataLength = sizeof(kData) / sizeof(kData[0]);
- app.WithData(kData, kDataLength);
+ app.WithData(kData, sizeof(kData));
- BuildPacket();
- ParsePacket();
+ rtc::Buffer raw = app.Build();
- EXPECT_EQ(30U, parsed().sub_type());
- EXPECT_EQ(kName, parsed().name());
- EXPECT_EQ(kDataLength, parsed().data_size());
- EXPECT_EQ(0, memcmp(kData, parsed().data(), kDataLength));
+ 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
} // namespace webrtc
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/app.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698