xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2016 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/rapid_resync_request.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::RapidResyncRequest;
20 
21 namespace webrtc {
22 namespace {
23 const uint32_t kSenderSsrc = 0x12345678;
24 const uint32_t kRemoteSsrc = 0x23456789;
25 // Manually created packet matching constants above.
26 const uint8_t kPacket[] = {0x85, 205,  0x00, 0x02, 0x12, 0x34,
27                            0x56, 0x78, 0x23, 0x45, 0x67, 0x89};
28 }  // namespace
29 
TEST(RtcpPacketRapidResyncRequestTest,Parse)30 TEST(RtcpPacketRapidResyncRequestTest, Parse) {
31   RapidResyncRequest mutable_parsed;
32   EXPECT_TRUE(test::ParseSinglePacket(kPacket, &mutable_parsed));
33   const RapidResyncRequest& parsed = mutable_parsed;
34 
35   EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
36   EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc());
37 }
38 
TEST(RtcpPacketRapidResyncRequestTest,Create)39 TEST(RtcpPacketRapidResyncRequestTest, Create) {
40   RapidResyncRequest rrr;
41   rrr.SetSenderSsrc(kSenderSsrc);
42   rrr.SetMediaSsrc(kRemoteSsrc);
43 
44   rtc::Buffer packet = rrr.Build();
45 
46   EXPECT_THAT(make_tuple(packet.data(), packet.size()),
47               ElementsAreArray(kPacket));
48 }
49 
TEST(RtcpPacketRapidResyncRequestTest,ParseFailsOnTooSmallPacket)50 TEST(RtcpPacketRapidResyncRequestTest, ParseFailsOnTooSmallPacket) {
51   const uint8_t kTooSmallPacket[] = {0x85, 205,  0x00, 0x01,
52                                      0x12, 0x34, 0x56, 0x78};
53   RapidResyncRequest parsed;
54   EXPECT_FALSE(test::ParseSinglePacket(kTooSmallPacket, &parsed));
55 }
56 
TEST(RtcpPacketRapidResyncRequestTest,ParseFailsOnTooLargePacket)57 TEST(RtcpPacketRapidResyncRequestTest, ParseFailsOnTooLargePacket) {
58   const uint8_t kTooLargePacket[] = {0x85, 205,  0x00, 0x03, 0x12, 0x34,
59                                      0x56, 0x78, 0x32, 0x21, 0x65, 0x87,
60                                      0x23, 0x45, 0x67, 0x89};
61   RapidResyncRequest parsed;
62   EXPECT_FALSE(test::ParseSinglePacket(kTooLargePacket, &parsed));
63 }
64 }  // namespace webrtc
65