blob: af7e8f671b2e8f7e1ddae171e069e9e2177be0b0 [file] [log] [blame]
Steve Anton1d03a752017-11-27 14:30:09 -08001/*
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 Anton22da89f2018-01-25 13:58:07 -080011#include <tuple>
12
Steve Anton1d03a752017-11-27 14:30:09 -080013#include "pc/rtpmediautils.h"
14#include "test/gtest.h"
15
16namespace webrtc {
17
Steve Anton22da89f2018-01-25 13:58:07 -080018using ::testing::Bool;
19using ::testing::Combine;
Steve Anton1d03a752017-11-27 14:30:09 -080020using ::testing::Values;
Steve Anton22da89f2018-01-25 13:58:07 -080021using ::testing::ValuesIn;
22
23RtpTransceiverDirection kAllDirections[] = {
24 RtpTransceiverDirection::kSendRecv, RtpTransceiverDirection::kSendOnly,
25 RtpTransceiverDirection::kRecvOnly, RtpTransceiverDirection::kInactive};
Steve Anton1d03a752017-11-27 14:30:09 -080026
27class EnumerateAllDirectionsTest
Steve Anton22da89f2018-01-25 13:58:07 -080028 : public ::testing::TestWithParam<RtpTransceiverDirection> {};
Steve Anton1d03a752017-11-27 14:30:09 -080029
30// Test that converting the direction to send/recv and back again results in the
31// same direction.
32TEST_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.
42TEST_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.
53TEST_P(EnumerateAllDirectionsTest, TestReversedIdentity) {
54 RtpTransceiverDirection direction = GetParam();
55
56 EXPECT_EQ(direction, RtpTransceiverDirectionReversed(
57 RtpTransceiverDirectionReversed(direction)));
58}
59
60INSTANTIATE_TEST_CASE_P(RtpTransceiverDirectionTest,
61 EnumerateAllDirectionsTest,
Steve Anton22da89f2018-01-25 13:58:07 -080062 ValuesIn(kAllDirections));
63
64class EnumerateAllDirectionsAndBool
65 : public ::testing::TestWithParam<
66 std::tuple<RtpTransceiverDirection, bool>> {};
67
68TEST_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
80TEST_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
92INSTANTIATE_TEST_CASE_P(RtpTransceiverDirectionTest,
93 EnumerateAllDirectionsAndBool,
94 Combine(ValuesIn(kAllDirections), Bool()));
Steve Anton1d03a752017-11-27 14:30:09 -080095
96} // namespace webrtc