blob: c0e739cc230e30804e4d1cc43a4ae907b2e000e4 [file] [log] [blame]
Artem Titov0d510522022-04-19 13:01:03 +02001/*
2 * Copyright 2022 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/test/peerconnection_quality_test_fixture.h"
12
13#include <vector>
14
15#include "absl/types/optional.h"
16#include "rtc_base/gunit.h"
17#include "test/gmock.h"
18
19namespace webrtc {
20namespace webrtc_pc_e2e {
21namespace {
22
Artem Titov7017a132022-04-20 20:57:56 +020023using VideoResolution = ::webrtc::webrtc_pc_e2e::
24 PeerConnectionE2EQualityTestFixture::VideoResolution;
Artem Titov0d510522022-04-19 13:01:03 +020025using VideoConfig =
26 ::webrtc::webrtc_pc_e2e::PeerConnectionE2EQualityTestFixture::VideoConfig;
Artem Titov7017a132022-04-20 20:57:56 +020027using VideoSubscription = ::webrtc::webrtc_pc_e2e::
28 PeerConnectionE2EQualityTestFixture::VideoSubscription;
Artem Titov0d510522022-04-19 13:01:03 +020029
30TEST(PclfVideoSubscription, MaxFromSenderSpecEqualIndependentOfOtherFields) {
Artem Titov7017a132022-04-20 20:57:56 +020031 VideoResolution r1(VideoResolution::Spec::kMaxFromSender);
Artem Titov0d510522022-04-19 13:01:03 +020032 r1.set_width(1);
33 r1.set_height(2);
34 r1.set_fps(3);
Artem Titov7017a132022-04-20 20:57:56 +020035 VideoResolution r2(VideoResolution::Spec::kMaxFromSender);
Artem Titov0d510522022-04-19 13:01:03 +020036 r1.set_width(4);
37 r1.set_height(5);
38 r1.set_fps(6);
39 EXPECT_EQ(r1, r2);
40}
41
42TEST(PclfVideoSubscription, WhenSpecIsNotSetFieldsAreCompared) {
Artem Titov7017a132022-04-20 20:57:56 +020043 VideoResolution test_resolution(/*width=*/1, /*height=*/2,
44 /*fps=*/3);
45 VideoResolution equal_resolution(/*width=*/1, /*height=*/2,
46 /*fps=*/3);
47 VideoResolution different_width(/*width=*/10, /*height=*/2,
48 /*fps=*/3);
49 VideoResolution different_height(/*width=*/1, /*height=*/20,
50 /*fps=*/3);
51 VideoResolution different_fps(/*width=*/1, /*height=*/20,
52 /*fps=*/30);
Artem Titov0d510522022-04-19 13:01:03 +020053
54 EXPECT_EQ(test_resolution, equal_resolution);
55 EXPECT_NE(test_resolution, different_width);
56 EXPECT_NE(test_resolution, different_height);
57 EXPECT_NE(test_resolution, different_fps);
58}
59
60TEST(PclfVideoSubscription, GetMaxResolutionForEmptyReturnsNullopt) {
Artem Titov7017a132022-04-20 20:57:56 +020061 absl::optional<VideoResolution> resolution =
Artem Titov83962d92022-04-20 19:26:08 +020062 VideoSubscription::GetMaxResolution(std::vector<VideoConfig>{});
Artem Titov0d510522022-04-19 13:01:03 +020063 ASSERT_FALSE(resolution.has_value());
64}
65
66TEST(PclfVideoSubscription, GetMaxResolutionSelectMaxForEachDimention) {
67 VideoConfig max_width(/*width=*/1000, /*height=*/1, /*fps=*/1);
68 VideoConfig max_height(/*width=*/1, /*height=*/100, /*fps=*/1);
69 VideoConfig max_fps(/*width=*/1, /*height=*/1, /*fps=*/10);
70
Artem Titov7017a132022-04-20 20:57:56 +020071 absl::optional<VideoResolution> resolution =
Artem Titov0d510522022-04-19 13:01:03 +020072 VideoSubscription::GetMaxResolution(
73 std::vector<VideoConfig>{max_width, max_height, max_fps});
74 ASSERT_TRUE(resolution.has_value());
75 EXPECT_EQ(resolution->width(), static_cast<size_t>(1000));
76 EXPECT_EQ(resolution->height(), static_cast<size_t>(100));
77 EXPECT_EQ(resolution->fps(), 10);
78}
79
80} // namespace
81} // namespace webrtc_pc_e2e
82} // namespace webrtc