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

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: Created 4 years, 7 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
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..b94f2b715c63b7aa95925c48331191c3f408ba0f 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,81 @@
#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"
+#include "webrtc/test/rtcp_packet_parser.h"
+using testing::ElementsAreArray;
+using testing::make_tuple;
using webrtc::rtcp::App;
-using webrtc::RTCPUtility::RtcpCommonHeader;
-using webrtc::RTCPUtility::RtcpParseCommonHeader;
namespace webrtc {
namespace {
+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 kPacketWithoutData[] = {0x9e, 204, 0x00, 0x02,
åsapersson 2016/07/26 09:58:15 App::kPacketType
danilchap 2016/07/26 11:37:02 Done. First byte expanded too.
+ 0x12, 0x34, 0x56, 0x78,
+ 'n', 'a', 'm', 'e'};
+constexpr uint8_t kPacketWithData[] = {0x9e, 204, 0x00, 0x04,
åsapersson 2016/07/26 09:58:15 App::kPacketType
danilchap 2016/07/26 11:37:02 Done.
+ 0x12, 0x34, 0x56, 0x78,
+ 'n', 'a', 'm', 'e',
+ 't', 'e', 's', 't',
+ 'd', 'a', 't', 'a'};
+} // 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));
- }
-
+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));
+
åsapersson 2016/07/26 09:58:15 maybe check kSenderSsrc
danilchap 2016/07/26 11:37:02 Done.
+ 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) {
+ const uint8_t kTooSmallPacket[] = {
+ 0x9e, App::kPacketType, 0x00, 0x01, 0x12, 0x34, 0x56, 0x78};
+ App parsed;
+ EXPECT_FALSE(test::ParseSinglePacket(kTooSmallPacket, &parsed));
}
-} // namespace
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698