Add some simple tests to CodecList
Bug: webrtc:360058654
Change-Id: I56de5f0bd2fd949440178f1a102640da13d92f23
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/379200
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#44005}
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 0195607..56d5e80 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -930,6 +930,7 @@
defines = []
deps = [
":codec",
+ ":codec_list",
":media_channel",
":media_constants",
":media_engine",
@@ -1066,6 +1067,7 @@
sources = [
"base/codec_comparators_unittest.cc",
+ "base/codec_list_unittest.cc",
"base/codec_unittest.cc",
"base/media_engine_unittest.cc",
"base/rtp_utils_unittest.cc",
diff --git a/media/base/codec_list_unittest.cc b/media/base/codec_list_unittest.cc
new file mode 100644
index 0000000..b59e3e4
--- /dev/null
+++ b/media/base/codec_list_unittest.cc
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2025 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "media/base/codec_list.h"
+
+#include "api/video_codecs/sdp_video_format.h"
+#include "test/gtest.h"
+
+namespace cricket {
+namespace {
+
+TEST(CodecList, StoreAndRecall) {
+ CodecList empty_list(std::vector<Codec>{});
+ EXPECT_TRUE(empty_list.empty());
+ EXPECT_TRUE(empty_list.codecs().empty());
+ Codec video_codec = CreateVideoCodec({webrtc::SdpVideoFormat{"VP8"}});
+ CodecList one_codec{{video_codec}};
+ EXPECT_EQ(one_codec.size(), 1U);
+ EXPECT_EQ(one_codec.codecs()[0], video_codec);
+}
+
+#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
+TEST(CodecList, CrashOnIllegalConstructorArguments) {
+ // This tests initializing a CodecList with a sequence that doesn't
+ // satisfy its expected invariants. Those invariants are only checked
+ // in debug mode.
+ // See CodecList::CheckConsistency for what checks are enabled.
+ // Checks that can't be enabled log things instead.
+ // Note: DCHECK is on in some release builds, so we can't use
+ // EXPECT_DEBUG_DEATH here.
+ std::vector<Codec> apt_without_number{
+ CreateVideoCodec({webrtc::SdpVideoFormat{
+ "rtx", webrtc::CodecParameterMap{{"apt", "not-a-number"}}}})};
+#if RTC_DCHECK_IS_ON
+ EXPECT_DEATH(CodecList bad(apt_without_number), "FromString");
+#else
+ // Expect initialization to succeed.
+ CodecList bad{apt_without_number};
+ EXPECT_EQ(bad.size(), 1U);
+#endif
+}
+#endif
+
+} // namespace
+} // namespace cricket