xref: /aosp_15_r20/external/webrtc/pc/rtp_media_utils_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2017 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #include "pc/rtp_media_utils.h"
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <tuple>
14*d9f75844SAndroid Build Coastguard Worker 
15*d9f75844SAndroid Build Coastguard Worker #include "test/gtest.h"
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
18*d9f75844SAndroid Build Coastguard Worker 
19*d9f75844SAndroid Build Coastguard Worker using ::testing::Bool;
20*d9f75844SAndroid Build Coastguard Worker using ::testing::Combine;
21*d9f75844SAndroid Build Coastguard Worker using ::testing::Values;
22*d9f75844SAndroid Build Coastguard Worker using ::testing::ValuesIn;
23*d9f75844SAndroid Build Coastguard Worker 
24*d9f75844SAndroid Build Coastguard Worker RtpTransceiverDirection kAllDirections[] = {
25*d9f75844SAndroid Build Coastguard Worker     RtpTransceiverDirection::kSendRecv, RtpTransceiverDirection::kSendOnly,
26*d9f75844SAndroid Build Coastguard Worker     RtpTransceiverDirection::kRecvOnly, RtpTransceiverDirection::kInactive};
27*d9f75844SAndroid Build Coastguard Worker 
28*d9f75844SAndroid Build Coastguard Worker class EnumerateAllDirectionsTest
29*d9f75844SAndroid Build Coastguard Worker     : public ::testing::TestWithParam<RtpTransceiverDirection> {};
30*d9f75844SAndroid Build Coastguard Worker 
31*d9f75844SAndroid Build Coastguard Worker // Test that converting the direction to send/recv and back again results in the
32*d9f75844SAndroid Build Coastguard Worker // same direction.
TEST_P(EnumerateAllDirectionsTest,TestIdentity)33*d9f75844SAndroid Build Coastguard Worker TEST_P(EnumerateAllDirectionsTest, TestIdentity) {
34*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection direction = GetParam();
35*d9f75844SAndroid Build Coastguard Worker 
36*d9f75844SAndroid Build Coastguard Worker   bool send = RtpTransceiverDirectionHasSend(direction);
37*d9f75844SAndroid Build Coastguard Worker   bool recv = RtpTransceiverDirectionHasRecv(direction);
38*d9f75844SAndroid Build Coastguard Worker 
39*d9f75844SAndroid Build Coastguard Worker   EXPECT_EQ(direction, RtpTransceiverDirectionFromSendRecv(send, recv));
40*d9f75844SAndroid Build Coastguard Worker }
41*d9f75844SAndroid Build Coastguard Worker 
42*d9f75844SAndroid Build Coastguard Worker // Test that reversing the direction is equivalent to swapping send/recv.
TEST_P(EnumerateAllDirectionsTest,TestReversedSwapped)43*d9f75844SAndroid Build Coastguard Worker TEST_P(EnumerateAllDirectionsTest, TestReversedSwapped) {
44*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection direction = GetParam();
45*d9f75844SAndroid Build Coastguard Worker 
46*d9f75844SAndroid Build Coastguard Worker   bool send = RtpTransceiverDirectionHasSend(direction);
47*d9f75844SAndroid Build Coastguard Worker   bool recv = RtpTransceiverDirectionHasRecv(direction);
48*d9f75844SAndroid Build Coastguard Worker 
49*d9f75844SAndroid Build Coastguard Worker   EXPECT_EQ(RtpTransceiverDirectionFromSendRecv(recv, send),
50*d9f75844SAndroid Build Coastguard Worker             RtpTransceiverDirectionReversed(direction));
51*d9f75844SAndroid Build Coastguard Worker }
52*d9f75844SAndroid Build Coastguard Worker 
53*d9f75844SAndroid Build Coastguard Worker // Test that reversing the direction twice results in the same direction.
TEST_P(EnumerateAllDirectionsTest,TestReversedIdentity)54*d9f75844SAndroid Build Coastguard Worker TEST_P(EnumerateAllDirectionsTest, TestReversedIdentity) {
55*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection direction = GetParam();
56*d9f75844SAndroid Build Coastguard Worker 
57*d9f75844SAndroid Build Coastguard Worker   EXPECT_EQ(direction, RtpTransceiverDirectionReversed(
58*d9f75844SAndroid Build Coastguard Worker                            RtpTransceiverDirectionReversed(direction)));
59*d9f75844SAndroid Build Coastguard Worker }
60*d9f75844SAndroid Build Coastguard Worker 
61*d9f75844SAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest,
62*d9f75844SAndroid Build Coastguard Worker                          EnumerateAllDirectionsTest,
63*d9f75844SAndroid Build Coastguard Worker                          ValuesIn(kAllDirections));
64*d9f75844SAndroid Build Coastguard Worker 
65*d9f75844SAndroid Build Coastguard Worker class EnumerateAllDirectionsAndBool
66*d9f75844SAndroid Build Coastguard Worker     : public ::testing::TestWithParam<
67*d9f75844SAndroid Build Coastguard Worker           std::tuple<RtpTransceiverDirection, bool>> {};
68*d9f75844SAndroid Build Coastguard Worker 
TEST_P(EnumerateAllDirectionsAndBool,TestWithSendSet)69*d9f75844SAndroid Build Coastguard Worker TEST_P(EnumerateAllDirectionsAndBool, TestWithSendSet) {
70*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection direction = std::get<0>(GetParam());
71*d9f75844SAndroid Build Coastguard Worker   bool send = std::get<1>(GetParam());
72*d9f75844SAndroid Build Coastguard Worker 
73*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection result =
74*d9f75844SAndroid Build Coastguard Worker       RtpTransceiverDirectionWithSendSet(direction, send);
75*d9f75844SAndroid Build Coastguard Worker 
76*d9f75844SAndroid Build Coastguard Worker   EXPECT_EQ(send, RtpTransceiverDirectionHasSend(result));
77*d9f75844SAndroid Build Coastguard Worker   EXPECT_EQ(RtpTransceiverDirectionHasRecv(direction),
78*d9f75844SAndroid Build Coastguard Worker             RtpTransceiverDirectionHasRecv(result));
79*d9f75844SAndroid Build Coastguard Worker }
80*d9f75844SAndroid Build Coastguard Worker 
TEST_P(EnumerateAllDirectionsAndBool,TestWithRecvSet)81*d9f75844SAndroid Build Coastguard Worker TEST_P(EnumerateAllDirectionsAndBool, TestWithRecvSet) {
82*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection direction = std::get<0>(GetParam());
83*d9f75844SAndroid Build Coastguard Worker   bool recv = std::get<1>(GetParam());
84*d9f75844SAndroid Build Coastguard Worker 
85*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection result =
86*d9f75844SAndroid Build Coastguard Worker       RtpTransceiverDirectionWithRecvSet(direction, recv);
87*d9f75844SAndroid Build Coastguard Worker 
88*d9f75844SAndroid Build Coastguard Worker   EXPECT_EQ(RtpTransceiverDirectionHasSend(direction),
89*d9f75844SAndroid Build Coastguard Worker             RtpTransceiverDirectionHasSend(result));
90*d9f75844SAndroid Build Coastguard Worker   EXPECT_EQ(recv, RtpTransceiverDirectionHasRecv(result));
91*d9f75844SAndroid Build Coastguard Worker }
92*d9f75844SAndroid Build Coastguard Worker 
93*d9f75844SAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest,
94*d9f75844SAndroid Build Coastguard Worker                          EnumerateAllDirectionsAndBool,
95*d9f75844SAndroid Build Coastguard Worker                          Combine(ValuesIn(kAllDirections), Bool()));
96*d9f75844SAndroid Build Coastguard Worker 
97*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
98