1 /*
2 * Copyright 2017 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 "pc/rtp_media_utils.h"
12
13 #include <tuple>
14
15 #include "test/gtest.h"
16
17 namespace webrtc {
18
19 using ::testing::Bool;
20 using ::testing::Combine;
21 using ::testing::Values;
22 using ::testing::ValuesIn;
23
24 RtpTransceiverDirection kAllDirections[] = {
25 RtpTransceiverDirection::kSendRecv, RtpTransceiverDirection::kSendOnly,
26 RtpTransceiverDirection::kRecvOnly, RtpTransceiverDirection::kInactive};
27
28 class EnumerateAllDirectionsTest
29 : public ::testing::TestWithParam<RtpTransceiverDirection> {};
30
31 // Test that converting the direction to send/recv and back again results in the
32 // same direction.
TEST_P(EnumerateAllDirectionsTest,TestIdentity)33 TEST_P(EnumerateAllDirectionsTest, TestIdentity) {
34 RtpTransceiverDirection direction = GetParam();
35
36 bool send = RtpTransceiverDirectionHasSend(direction);
37 bool recv = RtpTransceiverDirectionHasRecv(direction);
38
39 EXPECT_EQ(direction, RtpTransceiverDirectionFromSendRecv(send, recv));
40 }
41
42 // Test that reversing the direction is equivalent to swapping send/recv.
TEST_P(EnumerateAllDirectionsTest,TestReversedSwapped)43 TEST_P(EnumerateAllDirectionsTest, TestReversedSwapped) {
44 RtpTransceiverDirection direction = GetParam();
45
46 bool send = RtpTransceiverDirectionHasSend(direction);
47 bool recv = RtpTransceiverDirectionHasRecv(direction);
48
49 EXPECT_EQ(RtpTransceiverDirectionFromSendRecv(recv, send),
50 RtpTransceiverDirectionReversed(direction));
51 }
52
53 // Test that reversing the direction twice results in the same direction.
TEST_P(EnumerateAllDirectionsTest,TestReversedIdentity)54 TEST_P(EnumerateAllDirectionsTest, TestReversedIdentity) {
55 RtpTransceiverDirection direction = GetParam();
56
57 EXPECT_EQ(direction, RtpTransceiverDirectionReversed(
58 RtpTransceiverDirectionReversed(direction)));
59 }
60
61 INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest,
62 EnumerateAllDirectionsTest,
63 ValuesIn(kAllDirections));
64
65 class EnumerateAllDirectionsAndBool
66 : public ::testing::TestWithParam<
67 std::tuple<RtpTransceiverDirection, bool>> {};
68
TEST_P(EnumerateAllDirectionsAndBool,TestWithSendSet)69 TEST_P(EnumerateAllDirectionsAndBool, TestWithSendSet) {
70 RtpTransceiverDirection direction = std::get<0>(GetParam());
71 bool send = std::get<1>(GetParam());
72
73 RtpTransceiverDirection result =
74 RtpTransceiverDirectionWithSendSet(direction, send);
75
76 EXPECT_EQ(send, RtpTransceiverDirectionHasSend(result));
77 EXPECT_EQ(RtpTransceiverDirectionHasRecv(direction),
78 RtpTransceiverDirectionHasRecv(result));
79 }
80
TEST_P(EnumerateAllDirectionsAndBool,TestWithRecvSet)81 TEST_P(EnumerateAllDirectionsAndBool, TestWithRecvSet) {
82 RtpTransceiverDirection direction = std::get<0>(GetParam());
83 bool recv = std::get<1>(GetParam());
84
85 RtpTransceiverDirection result =
86 RtpTransceiverDirectionWithRecvSet(direction, recv);
87
88 EXPECT_EQ(RtpTransceiverDirectionHasSend(direction),
89 RtpTransceiverDirectionHasSend(result));
90 EXPECT_EQ(recv, RtpTransceiverDirectionHasRecv(result));
91 }
92
93 INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest,
94 EnumerateAllDirectionsAndBool,
95 Combine(ValuesIn(kAllDirections), Bool()));
96
97 } // namespace webrtc
98