rtp_util_unittest.cc (3393B)
1 /* 2 * Copyright (c) 2021 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/rtp_util.h" 12 13 #include <cstdint> 14 15 #include "test/gtest.h" 16 17 namespace webrtc { 18 namespace { 19 20 TEST(RtpUtilTest, IsRtpPacket) { 21 constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0, 0, // 22 0, 0, 0, 0, // 23 0, 0, 0, 0}; 24 EXPECT_TRUE(IsRtpPacket(kMinimalisticRtpPacket)); 25 26 constexpr uint8_t kWrongRtpVersion[] = {0xc0, 97, 0, 0, // 27 0, 0, 0, 0, // 28 0, 0, 0, 0}; 29 EXPECT_FALSE(IsRtpPacket(kWrongRtpVersion)); 30 31 constexpr uint8_t kPacketWithPayloadForRtcp[] = {0x80, 200, 0, 0, // 32 0, 0, 0, 0, // 33 0, 0, 0, 0}; 34 EXPECT_FALSE(IsRtpPacket(kPacketWithPayloadForRtcp)); 35 36 constexpr uint8_t kTooSmallRtpPacket[] = {0x80, 97, 0, 0, // 37 0, 0, 0, 0, // 38 0, 0, 0}; 39 EXPECT_FALSE(IsRtpPacket(kTooSmallRtpPacket)); 40 41 EXPECT_FALSE(IsRtpPacket({})); 42 } 43 44 TEST(RtpUtilTest, IsRtcpPacket) { 45 constexpr uint8_t kMinimalisticRtcpPacket[] = {0x80, 202, 0, 0}; 46 EXPECT_TRUE(IsRtcpPacket(kMinimalisticRtcpPacket)); 47 48 constexpr uint8_t kWrongRtpVersion[] = {0xc0, 202, 0, 0}; 49 EXPECT_FALSE(IsRtcpPacket(kWrongRtpVersion)); 50 51 constexpr uint8_t kPacketWithPayloadForRtp[] = {0x80, 225, 0, 0}; 52 EXPECT_FALSE(IsRtcpPacket(kPacketWithPayloadForRtp)); 53 54 constexpr uint8_t kTooSmallRtcpPacket[] = {0x80, 202, 0}; 55 EXPECT_FALSE(IsRtcpPacket(kTooSmallRtcpPacket)); 56 57 EXPECT_FALSE(IsRtcpPacket({})); 58 } 59 60 TEST(RtpUtilTest, ParseRtpPayloadType) { 61 constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0, 0, // 62 0, 0, 0, 0, // 63 0x12, 0x34, 0x56, 0x78}; 64 EXPECT_EQ(ParseRtpPayloadType(kMinimalisticRtpPacket), 97); 65 66 constexpr uint8_t kMinimalisticRtpPacketWithMarker[] = { 67 0x80, 0x80 | 97, 0, 0, // 68 0, 0, 0, 0, // 69 0x12, 0x34, 0x56, 0x78}; 70 EXPECT_EQ(ParseRtpPayloadType(kMinimalisticRtpPacketWithMarker), 97); 71 } 72 73 TEST(RtpUtilTest, ParseRtpSequenceNumber) { 74 constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0x12, 0x34, // 75 0, 0, 0, 0, // 76 0, 0, 0, 0}; 77 EXPECT_EQ(ParseRtpSequenceNumber(kMinimalisticRtpPacket), 0x1234); 78 } 79 80 TEST(RtpUtilTest, ParseRtpSsrc) { 81 constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0, 0, // 82 0, 0, 0, 0, // 83 0x12, 0x34, 0x56, 0x78}; 84 EXPECT_EQ(ParseRtpSsrc(kMinimalisticRtpPacket), 0x12345678u); 85 } 86 87 } // namespace 88 } // namespace webrtc