blob: 5ee49e356dbff98550e816c20cb6c10cc926c756 [file] [log] [blame]
Steve Anton1d03a752017-11-27 22:30:091/*
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 Olssona4d87372019-07-05 17:08:3311#include "pc/rtp_media_utils.h"
12
Steve Anton22da89f2018-01-25 21:58:0713#include <tuple>
14
Steve Anton1d03a752017-11-27 22:30:0915#include "test/gtest.h"
16
17namespace webrtc {
18
Steve Anton22da89f2018-01-25 21:58:0719using ::testing::Bool;
20using ::testing::Combine;
Steve Anton1d03a752017-11-27 22:30:0921using ::testing::Values;
Steve Anton22da89f2018-01-25 21:58:0722using ::testing::ValuesIn;
23
24RtpTransceiverDirection kAllDirections[] = {
25 RtpTransceiverDirection::kSendRecv, RtpTransceiverDirection::kSendOnly,
26 RtpTransceiverDirection::kRecvOnly, RtpTransceiverDirection::kInactive};
Steve Anton1d03a752017-11-27 22:30:0927
28class EnumerateAllDirectionsTest
Steve Anton22da89f2018-01-25 21:58:0729 : public ::testing::TestWithParam<RtpTransceiverDirection> {};
Steve Anton1d03a752017-11-27 22:30:0930
31// Test that converting the direction to send/recv and back again results in the
32// same direction.
33TEST_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.
43TEST_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.
54TEST_P(EnumerateAllDirectionsTest, TestReversedIdentity) {
55 RtpTransceiverDirection direction = GetParam();
56
57 EXPECT_EQ(direction, RtpTransceiverDirectionReversed(
58 RtpTransceiverDirectionReversed(direction)));
59}
60
Mirko Bonadeic84f6612019-01-31 11:20:5761INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest,
62 EnumerateAllDirectionsTest,
63 ValuesIn(kAllDirections));
Steve Anton22da89f2018-01-25 21:58:0764
65class EnumerateAllDirectionsAndBool
66 : public ::testing::TestWithParam<
67 std::tuple<RtpTransceiverDirection, bool>> {};
68
69TEST_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
81TEST_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 Bonadeic84f6612019-01-31 11:20:5793INSTANTIATE_TEST_SUITE_P(RtpTransceiverDirectionTest,
94 EnumerateAllDirectionsAndBool,
95 Combine(ValuesIn(kAllDirections), Bool()));
Steve Anton1d03a752017-11-27 22:30:0996
97} // namespace webrtc