xref: /aosp_15_r20/external/webrtc/api/rtp_packet_infos_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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 "api/rtp_packet_infos.h"
12 
13 #include "test/gmock.h"
14 #include "test/gtest.h"
15 
16 namespace webrtc {
17 namespace {
18 
19 using ::testing::ElementsAre;
20 using ::testing::SizeIs;
21 
22 template <typename Iterator>
ToVector(Iterator begin,Iterator end)23 RtpPacketInfos::vector_type ToVector(Iterator begin, Iterator end) {
24   return RtpPacketInfos::vector_type(begin, end);
25 }
26 
27 }  // namespace
28 
TEST(RtpPacketInfosTest,BasicFunctionality)29 TEST(RtpPacketInfosTest, BasicFunctionality) {
30   RtpPacketInfo p0(/*ssrc=*/123, /*csrcs=*/{1, 2}, /*rtp_timestamp=*/89,
31                    /*receive_time=*/Timestamp::Millis(7));
32   p0.set_audio_level(5);
33   p0.set_absolute_capture_time(AbsoluteCaptureTime{
34       .absolute_capture_timestamp = 45, .estimated_capture_clock_offset = 78});
35 
36   RtpPacketInfo p1(/*ssrc=*/456, /*csrcs=*/{3, 4}, /*rtp_timestamp=*/89,
37                    /*receive_time=*/Timestamp::Millis(1));
38   p1.set_audio_level(4);
39   p1.set_absolute_capture_time(AbsoluteCaptureTime{
40       .absolute_capture_timestamp = 13, .estimated_capture_clock_offset = 21});
41 
42   RtpPacketInfo p2(/*ssrc=*/789, /*csrcs=*/{5, 6}, /*rtp_timestamp=*/88,
43                    /*receive_time=*/Timestamp::Millis(7));
44   p2.set_audio_level(1);
45   p2.set_absolute_capture_time(AbsoluteCaptureTime{
46       .absolute_capture_timestamp = 99, .estimated_capture_clock_offset = 78});
47 
48   RtpPacketInfos x({p0, p1, p2});
49 
50   ASSERT_THAT(x, SizeIs(3));
51 
52   EXPECT_EQ(x[0], p0);
53   EXPECT_EQ(x[1], p1);
54   EXPECT_EQ(x[2], p2);
55 
56   EXPECT_EQ(x.front(), p0);
57   EXPECT_EQ(x.back(), p2);
58 
59   EXPECT_THAT(ToVector(x.begin(), x.end()), ElementsAre(p0, p1, p2));
60   EXPECT_THAT(ToVector(x.rbegin(), x.rend()), ElementsAre(p2, p1, p0));
61 
62   EXPECT_THAT(ToVector(x.cbegin(), x.cend()), ElementsAre(p0, p1, p2));
63   EXPECT_THAT(ToVector(x.crbegin(), x.crend()), ElementsAre(p2, p1, p0));
64 
65   EXPECT_FALSE(x.empty());
66 }
67 
TEST(RtpPacketInfosTest,CopyShareData)68 TEST(RtpPacketInfosTest, CopyShareData) {
69   RtpPacketInfo p0(/*ssrc=*/123, /*csrcs=*/{1, 2}, /*rtp_timestamp=*/89,
70                    /*receive_time=*/Timestamp::Millis(7));
71   p0.set_audio_level(5);
72   p0.set_absolute_capture_time(AbsoluteCaptureTime{
73       .absolute_capture_timestamp = 45, .estimated_capture_clock_offset = 78});
74 
75   RtpPacketInfo p1(/*ssrc=*/456, /*csrcs=*/{3, 4}, /*rtp_timestamp=*/89,
76                    /*receive_time=*/Timestamp::Millis(1));
77   p1.set_audio_level(4);
78   p1.set_absolute_capture_time(AbsoluteCaptureTime{
79       .absolute_capture_timestamp = 13, .estimated_capture_clock_offset = 21});
80 
81   RtpPacketInfo p2(/*ssrc=*/789, /*csrcs=*/{5, 6}, /*rtp_timestamp=*/88,
82                    /*receive_time=*/Timestamp::Millis(7));
83   p2.set_audio_level(1);
84   p2.set_absolute_capture_time(AbsoluteCaptureTime{
85       .absolute_capture_timestamp = 99, .estimated_capture_clock_offset = 78});
86 
87   RtpPacketInfos lhs({p0, p1, p2});
88   RtpPacketInfos rhs = lhs;
89 
90   ASSERT_THAT(lhs, SizeIs(3));
91   ASSERT_THAT(rhs, SizeIs(3));
92 
93   for (size_t i = 0; i < lhs.size(); ++i) {
94     EXPECT_EQ(lhs[i], rhs[i]);
95   }
96 
97   EXPECT_EQ(lhs.front(), rhs.front());
98   EXPECT_EQ(lhs.back(), rhs.back());
99 
100   EXPECT_EQ(lhs.begin(), rhs.begin());
101   EXPECT_EQ(lhs.end(), rhs.end());
102   EXPECT_EQ(lhs.rbegin(), rhs.rbegin());
103   EXPECT_EQ(lhs.rend(), rhs.rend());
104 
105   EXPECT_EQ(lhs.cbegin(), rhs.cbegin());
106   EXPECT_EQ(lhs.cend(), rhs.cend());
107   EXPECT_EQ(lhs.crbegin(), rhs.crbegin());
108   EXPECT_EQ(lhs.crend(), rhs.crend());
109 
110   EXPECT_EQ(lhs.empty(), rhs.empty());
111 }
112 
113 }  // namespace webrtc
114