1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "modules/rtp_rtcp/source/rtcp_packet/pli.h"
12
13 #include "test/gmock.h"
14 #include "test/gtest.h"
15 #include "test/rtcp_packet_parser.h"
16
17 using ::testing::ElementsAreArray;
18 using ::testing::make_tuple;
19 using webrtc::rtcp::Pli;
20
21 namespace webrtc {
22 namespace {
23 const uint32_t kSenderSsrc = 0x12345678;
24 const uint32_t kRemoteSsrc = 0x23456789;
25 // Manually created Pli packet matching constants above.
26 const uint8_t kPacket[] = {0x81, 206, 0x00, 0x02, 0x12, 0x34,
27 0x56, 0x78, 0x23, 0x45, 0x67, 0x89};
28 } // namespace
29
TEST(RtcpPacketPliTest,Parse)30 TEST(RtcpPacketPliTest, Parse) {
31 Pli mutable_parsed;
32 EXPECT_TRUE(test::ParseSinglePacket(kPacket, &mutable_parsed));
33 const Pli& parsed = mutable_parsed; // Read values from constant object.
34
35 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
36 EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc());
37 }
38
TEST(RtcpPacketPliTest,Create)39 TEST(RtcpPacketPliTest, Create) {
40 Pli pli;
41 pli.SetSenderSsrc(kSenderSsrc);
42 pli.SetMediaSsrc(kRemoteSsrc);
43
44 rtc::Buffer packet = pli.Build();
45
46 EXPECT_THAT(make_tuple(packet.data(), packet.size()),
47 ElementsAreArray(kPacket));
48 }
49
TEST(RtcpPacketPliTest,ParseFailsOnTooSmallPacket)50 TEST(RtcpPacketPliTest, ParseFailsOnTooSmallPacket) {
51 const uint8_t kTooSmallPacket[] = {0x81, 206, 0x00, 0x01,
52 0x12, 0x34, 0x56, 0x78};
53
54 Pli parsed;
55 EXPECT_FALSE(test::ParseSinglePacket(kTooSmallPacket, &parsed));
56 }
57
58 } // namespace webrtc
59