tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rtp_packet_infos_unittest.cc (3873B)


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