tor-browser

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

codec_list_unittest.cc (2552B)


      1 /*
      2 *  Copyright (c) 2025 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 "media/base/codec_list.h"
     12 
     13 #include <vector>
     14 
     15 #include "api/rtc_error.h"
     16 #include "api/rtp_parameters.h"
     17 #include "api/video_codecs/sdp_video_format.h"
     18 #include "media/base/codec.h"
     19 #include "rtc_base/checks.h"
     20 #include "test/gtest.h"
     21 
     22 namespace webrtc {
     23 namespace {
     24 
     25 
     26 TEST(CodecList, StoreAndRecall) {
     27  CodecList empty_list = CodecList::CreateFromTrustedData(std::vector<Codec>{});
     28  EXPECT_TRUE(empty_list.empty());
     29  EXPECT_TRUE(empty_list.codecs().empty());
     30  Codec video_codec = CreateVideoCodec({SdpVideoFormat{"VP8"}});
     31  CodecList one_codec = CodecList::CreateFromTrustedData({{video_codec}});
     32  EXPECT_EQ(one_codec.size(), 1U);
     33  EXPECT_EQ(one_codec.codecs()[0], video_codec);
     34 }
     35 
     36 TEST(CodecList, RejectIllegalConstructorArguments) {
     37  std::vector<Codec> apt_without_number{CreateVideoCodec(
     38      {SdpVideoFormat{"rtx", CodecParameterMap{{"apt", "not-a-number"}}}})};
     39  apt_without_number[0].id = 96;
     40  RTCErrorOr<CodecList> checked_codec_list =
     41      CodecList::Create(apt_without_number);
     42  EXPECT_FALSE(checked_codec_list.ok());
     43  EXPECT_EQ(checked_codec_list.error().type(), RTCErrorType::INVALID_PARAMETER);
     44 }
     45 
     46 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
     47 TEST(CodecList, CrashOnIllegalConstructorArguments) {
     48  // This tests initializing a CodecList with a sequence that doesn't
     49  // satisfy its expected invariants.
     50  // Those invariants are only checked in debug mode.
     51  // See CodecList::CheckInputConsistency for what checks are enabled.
     52  // Checks that can't be enabled log things instead.
     53  // Note: DCHECK is on in some release builds, so we can't use
     54  // EXPECT_DEBUG_DEATH here.
     55  std::vector<Codec> apt_without_number{CreateVideoCodec(
     56      {SdpVideoFormat{"rtx", CodecParameterMap{{"apt", "not-a-number"}}}})};
     57  apt_without_number[0].id = 96;
     58 #if RTC_DCHECK_IS_ON
     59  EXPECT_DEATH(
     60      CodecList bad = CodecList::CreateFromTrustedData(apt_without_number),
     61      "CheckInputConsistency");
     62 #else
     63  // Expect initialization to succeed.
     64  CodecList bad = CodecList::CreateFromTrustedData(apt_without_number);
     65  EXPECT_EQ(bad.size(), 1U);
     66 #endif
     67 }
     68 #endif
     69 
     70 }  // namespace
     71 }  // namespace webrtc