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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h"
12 12
13 #include <limits> 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/test/rtcp_packet_parser.h"
14 16
15 #include "testing/gtest/include/gtest/gtest.h" 17 using testing::ElementsAreArray;
16 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" 18 using testing::make_tuple;
17
18 using webrtc::rtcp::App; 19 using webrtc::rtcp::App;
19 using webrtc::RTCPUtility::RtcpCommonHeader;
20 using webrtc::RTCPUtility::RtcpParseCommonHeader;
21 20
22 namespace webrtc { 21 namespace webrtc {
23 namespace { 22 namespace {
23 constexpr uint32_t kName = ((uint32_t)'n' << 24) | ((uint32_t)'a' << 16) |
24 ((uint32_t)'m' << 8) | (uint32_t)'e';
25 constexpr uint8_t kSubtype = 0x1e;
26 constexpr uint32_t kSenderSsrc = 0x12345678;
27 constexpr uint8_t kData[] = {'t', 'e', 's', 't', 'd', 'a', 't', 'a'};
28 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.
29 0x12, 0x34, 0x56, 0x78,
30 'n', 'a', 'm', 'e'};
31 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.
32 0x12, 0x34, 0x56, 0x78,
33 'n', 'a', 'm', 'e',
34 't', 'e', 's', 't',
35 'd', 'a', 't', 'a'};
36 } // namespace
24 37
25 const uint32_t kName = ((uint32_t)'n' << 24) | ((uint32_t)'a' << 16) | 38 TEST(RtcpPacketAppTest, CreateWithoutData) {
26 ((uint32_t)'m' << 8) | (uint32_t)'e';
27 const uint32_t kSenderSsrc = 0x12345678;
28
29 class RtcpPacketAppTest : public ::testing::Test {
30 protected:
31 void BuildPacket() { packet = app.Build(); }
32 void ParsePacket() {
33 RtcpCommonHeader header;
34 EXPECT_TRUE(RtcpParseCommonHeader(packet.data(), packet.size(), &header));
35 // Check there is exactly one RTCP packet in the buffer.
36 EXPECT_EQ(header.BlockSize(), packet.size());
37 EXPECT_TRUE(parsed_.Parse(
38 header, packet.data() + RtcpCommonHeader::kHeaderSizeBytes));
39 }
40
41 App app; 39 App app;
42 rtc::Buffer packet; 40 app.From(kSenderSsrc);
43 const App& parsed() { return parsed_; } 41 app.WithSubType(kSubtype);
44
45 private:
46 App parsed_;
47 };
48
49 TEST_F(RtcpPacketAppTest, WithNoData) {
50 app.WithSubType(30);
51 app.WithName(kName); 42 app.WithName(kName);
52 43
53 BuildPacket(); 44 rtc::Buffer raw = app.Build();
54 ParsePacket();
55 45
56 EXPECT_EQ(30U, parsed().sub_type()); 46 EXPECT_THAT(make_tuple(raw.data(), raw.size()),
57 EXPECT_EQ(kName, parsed().name()); 47 ElementsAreArray(kPacketWithoutData));
58 EXPECT_EQ(0u, parsed().data_size());
59 } 48 }
60 49
61 TEST_F(RtcpPacketAppTest, WithData) { 50 TEST(RtcpPacketAppTest, ParseWithoutData) {
62 app.From(kSenderSsrc); 51 App parsed;
63 app.WithSubType(30); 52 EXPECT_TRUE(test::ParseSinglePacket(kPacketWithoutData, &parsed));
64 app.WithName(kName);
65 const uint8_t kData[] = {'t', 'e', 's', 't', 'd', 'a', 't', 'a'};
66 const size_t kDataLength = sizeof(kData) / sizeof(kData[0]);
67 app.WithData(kData, kDataLength);
68 53
69 BuildPacket(); 54 EXPECT_EQ(kSenderSsrc, parsed.ssrc());
70 ParsePacket(); 55 EXPECT_EQ(kSubtype, parsed.sub_type());
71 56 EXPECT_EQ(kName, parsed.name());
72 EXPECT_EQ(30U, parsed().sub_type()); 57 EXPECT_EQ(0u, parsed.data_size());
73 EXPECT_EQ(kName, parsed().name());
74 EXPECT_EQ(kDataLength, parsed().data_size());
75 EXPECT_EQ(0, memcmp(kData, parsed().data(), kDataLength));
76 } 58 }
77 59
78 } // namespace 60 TEST(RtcpPacketAppTest, CreateWithData) {
61 App app;
62 app.From(kSenderSsrc);
63 app.WithSubType(kSubtype);
64 app.WithName(kName);
65 app.WithData(kData, sizeof(kData));
66
67 rtc::Buffer raw = app.Build();
68
69 EXPECT_THAT(make_tuple(raw.data(), raw.size()),
70 ElementsAreArray(kPacketWithData));
71 }
72
73 TEST(RtcpPacketAppTest, ParseWithData) {
74 App parsed;
75 EXPECT_TRUE(test::ParseSinglePacket(kPacketWithData, &parsed));
76
åsapersson 2016/07/26 09:58:15 maybe check kSenderSsrc
danilchap 2016/07/26 11:37:02 Done.
77 EXPECT_EQ(kSubtype, parsed.sub_type());
78 EXPECT_EQ(kName, parsed.name());
79 EXPECT_THAT(make_tuple(parsed.data(), parsed.data_size()),
80 ElementsAreArray(kData));
81 }
82
83 TEST(RtcpPacketAppTest, ParseFailsOnTooSmallPacket) {
84 const uint8_t kTooSmallPacket[] = {
85 0x9e, App::kPacketType, 0x00, 0x01, 0x12, 0x34, 0x56, 0x78};
86 App parsed;
87 EXPECT_FALSE(test::ParseSinglePacket(kTooSmallPacket, &parsed));
88 }
89
79 } // namespace webrtc 90 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698