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