OLD | NEW |
(Empty) | |
| 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 <memory> |
| 12 |
| 13 #include "webrtc/base/fakenetwork.h" |
| 14 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/physicalsocketserver.h" |
| 16 #include "webrtc/base/thread.h" |
| 17 #include "webrtc/base/virtualsocketserver.h" |
| 18 #include "webrtc/media/base/fakemediaengine.h" |
| 19 #include "webrtc/ortc/ortcfactory.h" |
| 20 #include "webrtc/ortc/testrtpparameters.h" |
| 21 #include "webrtc/p2p/base/fakepackettransport.h" |
| 22 |
| 23 namespace { |
| 24 |
| 25 const rtc::IPAddress kIPv4LocalHostAddress = |
| 26 rtc::IPAddress(0x7F000001); // 127.0.0.1 |
| 27 |
| 28 } // namespace |
| 29 |
| 30 namespace webrtc { |
| 31 |
| 32 // This test uses a virtual network and fake media engine, in order to test the |
| 33 // OrtcFactory at only an API level. Any end-to-end test should go in |
| 34 // ortcfactory_integrationtest.cc instead. |
| 35 class OrtcFactoryTest : public testing::Test { |
| 36 public: |
| 37 OrtcFactoryTest() |
| 38 : virtual_socket_server_(&physical_socket_server_), |
| 39 socket_server_scope_(&virtual_socket_server_), |
| 40 fake_packet_transport_("fake transport") { |
| 41 ortc_factory_ = OrtcFactory::Create( |
| 42 nullptr, nullptr, &fake_network_manager_, nullptr, |
| 43 nullptr, std::unique_ptr<cricket::MediaEngineInterface>( |
| 44 new cricket::FakeMediaEngine())) |
| 45 .MoveValue(); |
| 46 } |
| 47 |
| 48 protected: |
| 49 std::unique_ptr<RtpTransportInterface> |
| 50 CreateRtpTransportWithFakePacketTransport() { |
| 51 return ortc_factory_ |
| 52 ->CreateRtpTransport(MakeRtcpMuxParameters(), &fake_packet_transport_, |
| 53 nullptr, nullptr) |
| 54 .MoveValue(); |
| 55 } |
| 56 |
| 57 std::unique_ptr<OrtcFactoryInterface> ortc_factory_; |
| 58 rtc::PhysicalSocketServer physical_socket_server_; |
| 59 rtc::VirtualSocketServer virtual_socket_server_; |
| 60 rtc::SocketServerScope socket_server_scope_; |
| 61 rtc::FakeNetworkManager fake_network_manager_; |
| 62 rtc::FakePacketTransport fake_packet_transport_; |
| 63 }; |
| 64 |
| 65 TEST_F(OrtcFactoryTest, CanCreateMultipleRtpTransportControllers) { |
| 66 auto controller_result1 = ortc_factory_->CreateRtpTransportController(); |
| 67 EXPECT_TRUE(controller_result1.ok()); |
| 68 auto controller_result2 = ortc_factory_->CreateRtpTransportController(); |
| 69 EXPECT_TRUE(controller_result1.ok()); |
| 70 } |
| 71 |
| 72 // Basic test that CreateUdpTransport works with AF_INET and AF_INET6. |
| 73 TEST_F(OrtcFactoryTest, CreateUdpTransport) { |
| 74 auto result = ortc_factory_->CreateUdpTransport(AF_INET); |
| 75 EXPECT_TRUE(result.ok()); |
| 76 result = ortc_factory_->CreateUdpTransport(AF_INET6); |
| 77 EXPECT_TRUE(result.ok()); |
| 78 } |
| 79 |
| 80 // Test CreateUdpPort with the |min_port| and |max_port| arguments. |
| 81 TEST_F(OrtcFactoryTest, CreateUdpTransportWithPortRange) { |
| 82 auto socket_result1 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002); |
| 83 ASSERT_TRUE(socket_result1.ok()); |
| 84 EXPECT_EQ(2000, socket_result1.value()->GetLocalAddress().port()); |
| 85 auto socket_result2 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002); |
| 86 ASSERT_TRUE(socket_result2.ok()); |
| 87 EXPECT_EQ(2001, socket_result2.value()->GetLocalAddress().port()); |
| 88 auto socket_result3 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002); |
| 89 ASSERT_TRUE(socket_result3.ok()); |
| 90 EXPECT_EQ(2002, socket_result3.value()->GetLocalAddress().port()); |
| 91 |
| 92 // All sockets in the range have been exhausted, so the next call should |
| 93 // fail. |
| 94 auto failed_result = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002); |
| 95 EXPECT_EQ(RTCErrorType::RESOURCE_EXHAUSTED, failed_result.error().type()); |
| 96 |
| 97 // If one socket is destroyed, that port should be freed up again. |
| 98 socket_result2.MoveValue().reset(); |
| 99 auto socket_result4 = ortc_factory_->CreateUdpTransport(AF_INET, 2000, 2002); |
| 100 ASSERT_TRUE(socket_result4.ok()); |
| 101 EXPECT_EQ(2001, socket_result4.value()->GetLocalAddress().port()); |
| 102 } |
| 103 |
| 104 // Just sanity check that each "GetCapabilities" method returns some codecs. |
| 105 TEST_F(OrtcFactoryTest, GetSenderAndReceiverCapabilities) { |
| 106 RtpCapabilities audio_send_caps = |
| 107 ortc_factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_AUDIO); |
| 108 EXPECT_GT(audio_send_caps.codecs.size(), 0u); |
| 109 RtpCapabilities video_send_caps = |
| 110 ortc_factory_->GetRtpSenderCapabilities(cricket::MEDIA_TYPE_VIDEO); |
| 111 EXPECT_GT(video_send_caps.codecs.size(), 0u); |
| 112 RtpCapabilities audio_receive_caps = |
| 113 ortc_factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_AUDIO); |
| 114 EXPECT_GT(audio_receive_caps.codecs.size(), 0u); |
| 115 RtpCapabilities video_receive_caps = |
| 116 ortc_factory_->GetRtpReceiverCapabilities(cricket::MEDIA_TYPE_VIDEO); |
| 117 EXPECT_GT(video_receive_caps.codecs.size(), 0u); |
| 118 } |
| 119 |
| 120 // Calling CreateRtpSender with a null track should fail, since that makes it |
| 121 // impossible to know whether to create an audio or video sender. The |
| 122 // application should be using the method that takes a cricket::MediaType |
| 123 // instead. |
| 124 TEST_F(OrtcFactoryTest, CreateSenderWithNullTrack) { |
| 125 auto rtp_transport = CreateRtpTransportWithFakePacketTransport(); |
| 126 auto result = ortc_factory_->CreateRtpSender(nullptr, rtp_transport.get()); |
| 127 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, result.error().type()); |
| 128 } |
| 129 |
| 130 // Calling CreateRtpSender or CreateRtpReceiver with MEDIA_TYPE_DATA should |
| 131 // fail. |
| 132 TEST_F(OrtcFactoryTest, CreateSenderOrReceieverWithInvalidKind) { |
| 133 auto rtp_transport = CreateRtpTransportWithFakePacketTransport(); |
| 134 auto sender_result = ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_DATA, |
| 135 rtp_transport.get()); |
| 136 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, sender_result.error().type()); |
| 137 auto receiver_result = ortc_factory_->CreateRtpReceiver( |
| 138 cricket::MEDIA_TYPE_DATA, rtp_transport.get()); |
| 139 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, receiver_result.error().type()); |
| 140 } |
| 141 |
| 142 TEST_F(OrtcFactoryTest, CreateSendersOrReceieversWithNullTransport) { |
| 143 auto sender_result = |
| 144 ortc_factory_->CreateRtpSender(cricket::MEDIA_TYPE_AUDIO, nullptr); |
| 145 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, sender_result.error().type()); |
| 146 auto receiver_result = |
| 147 ortc_factory_->CreateRtpReceiver(cricket::MEDIA_TYPE_AUDIO, nullptr); |
| 148 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, receiver_result.error().type()); |
| 149 } |
| 150 |
| 151 } // namespace webrtc |
OLD | NEW |