Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 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 | |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 11 | #include "pc/rtp_media_utils.h" |
| 12 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 13 | #include <tuple> |
| 14 | |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 15 | #include "test/gtest.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 19 | using ::testing::Bool; |
| 20 | using ::testing::Combine; |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 21 | using ::testing::Values; |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 22 | using ::testing::ValuesIn; |
| 23 | |
| 24 | RtpTransceiverDirection kAllDirections[] = { |
| 25 | RtpTransceiverDirection::kSendRecv, RtpTransceiverDirection::kSendOnly, |
| 26 | RtpTransceiverDirection::kRecvOnly, RtpTransceiverDirection::kInactive}; |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 27 | |
| 28 | class EnumerateAllDirectionsTest |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 29 | : public ::testing::TestWithParam<RtpTransceiverDirection> {}; |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 30 | |
| 31 | // Test that converting the direction to send/recv and back again results in the |
| 32 | // same direction. |
| 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. |
| 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. |
| 54 | TEST_P(EnumerateAllDirectionsTest, TestReversedIdentity) { |
| 55 | RtpTransceiverDirection direction = GetParam(); |
| 56 | |
| 57 | EXPECT_EQ(direction, RtpTransceiverDirectionReversed( |
| 58 | RtpTransceiverDirectionReversed(direction))); |
| 59 | } |
| 60 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 61 | INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest, |
| 62 | EnumerateAllDirectionsTest, |
| 63 | ValuesIn(kAllDirections)); |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 64 | |
| 65 | class EnumerateAllDirectionsAndBool |
| 66 | : public ::testing::TestWithParam< |
| 67 | std::tuple<RtpTransceiverDirection, bool>> {}; |
| 68 | |
| 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 | |
| 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 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 93 | INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest, |
| 94 | EnumerateAllDirectionsAndBool, |
| 95 | Combine(ValuesIn(kAllDirections), Bool())); |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 96 | |
| 97 | } // namespace webrtc |