hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | #import <Foundation/Foundation.h> |
| 12 | |
| 13 | #include <vector> |
| 14 | |
ehmaldonado | eaaae9e | 2017-07-07 03:09:51 -0700 | [diff] [blame] | 15 | #include "webrtc/rtc_base/gunit.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 16 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "NSString+StdString.h" |
| 18 | #import "RTCConfiguration+Private.h" |
| 19 | #import "WebRTC/RTCConfiguration.h" |
| 20 | #import "WebRTC/RTCIceServer.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 21 | |
| 22 | @interface RTCConfigurationTest : NSObject |
| 23 | - (void)testConversionToNativeConfiguration; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 24 | - (void)testNativeConversionToConfiguration; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 25 | @end |
| 26 | |
| 27 | @implementation RTCConfigurationTest |
| 28 | |
| 29 | - (void)testConversionToNativeConfiguration { |
| 30 | NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; |
| 31 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; |
| 32 | |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 33 | RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
| 34 | config.iceServers = @[ server ]; |
| 35 | config.iceTransportPolicy = RTCIceTransportPolicyRelay; |
| 36 | config.bundlePolicy = RTCBundlePolicyMaxBundle; |
| 37 | config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; |
| 38 | config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 39 | config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 40 | const int maxPackets = 60; |
| 41 | const int timeout = 1; |
| 42 | const int interval = 2; |
| 43 | config.audioJitterBufferMaxPackets = maxPackets; |
haysc | c9f9500 | 2016-12-05 14:24:32 -0800 | [diff] [blame] | 44 | config.audioJitterBufferFastAccelerate = YES; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 45 | config.iceConnectionReceivingTimeout = timeout; |
| 46 | config.iceBackupCandidatePairPingInterval = interval; |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 47 | config.continualGatheringPolicy = |
| 48 | RTCContinualGatheringPolicyGatherContinually; |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 49 | config.shouldPruneTurnPorts = YES; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 50 | |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 51 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 52 | nativeConfig([config createNativeConfiguration]); |
| 53 | EXPECT_TRUE(nativeConfig.get()); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 54 | EXPECT_EQ(1u, nativeConfig->servers.size()); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 55 | webrtc::PeerConnectionInterface::IceServer nativeServer = |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 56 | nativeConfig->servers.front(); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 57 | EXPECT_EQ(1u, nativeServer.urls.size()); |
| 58 | EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front()); |
| 59 | |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 60 | EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 61 | EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 62 | nativeConfig->bundle_policy); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 63 | EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 64 | nativeConfig->rtcp_mux_policy); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 65 | EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 66 | nativeConfig->tcp_candidate_policy); |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 67 | EXPECT_EQ(webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost, |
| 68 | nativeConfig->candidate_network_policy); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 69 | EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets); |
haysc | c9f9500 | 2016-12-05 14:24:32 -0800 | [diff] [blame] | 70 | EXPECT_EQ(true, nativeConfig->audio_jitter_buffer_fast_accelerate); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 71 | EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout); |
| 72 | EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval); |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 73 | EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 74 | nativeConfig->continual_gathering_policy); |
Honghai Zhang | e2e35ca | 2016-07-01 14:22:17 -0700 | [diff] [blame] | 75 | EXPECT_EQ(true, nativeConfig->prune_turn_ports); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 76 | } |
| 77 | |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 78 | - (void)testNativeConversionToConfiguration { |
| 79 | NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; |
| 80 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; |
| 81 | |
| 82 | RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
| 83 | config.iceServers = @[ server ]; |
| 84 | config.iceTransportPolicy = RTCIceTransportPolicyRelay; |
| 85 | config.bundlePolicy = RTCBundlePolicyMaxBundle; |
| 86 | config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; |
| 87 | config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; |
| 88 | config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost; |
| 89 | const int maxPackets = 60; |
| 90 | const int timeout = 1; |
| 91 | const int interval = 2; |
| 92 | config.audioJitterBufferMaxPackets = maxPackets; |
| 93 | config.audioJitterBufferFastAccelerate = YES; |
| 94 | config.iceConnectionReceivingTimeout = timeout; |
| 95 | config.iceBackupCandidatePairPingInterval = interval; |
| 96 | config.continualGatheringPolicy = |
| 97 | RTCContinualGatheringPolicyGatherContinually; |
| 98 | config.shouldPruneTurnPorts = YES; |
| 99 | |
| 100 | webrtc::PeerConnectionInterface::RTCConfiguration *nativeConfig = |
| 101 | [config createNativeConfiguration]; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 102 | RTCConfiguration *newConfig = [[RTCConfiguration alloc] |
| 103 | initWithNativeConfiguration:*nativeConfig]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 104 | EXPECT_EQ([config.iceServers count], newConfig.iceServers.count); |
| 105 | RTCIceServer *newServer = newConfig.iceServers[0]; |
| 106 | RTCIceServer *origServer = config.iceServers[0]; |
| 107 | EXPECT_EQ(origServer.urlStrings.count, server.urlStrings.count); |
| 108 | std::string origUrl = origServer.urlStrings.firstObject.UTF8String; |
| 109 | std::string url = newServer.urlStrings.firstObject.UTF8String; |
| 110 | EXPECT_EQ(origUrl, url); |
| 111 | |
| 112 | EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy); |
| 113 | EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy); |
| 114 | EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy); |
| 115 | EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy); |
| 116 | EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy); |
| 117 | EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets); |
| 118 | EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate); |
| 119 | EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout); |
| 120 | EXPECT_EQ(config.iceBackupCandidatePairPingInterval, |
| 121 | newConfig.iceBackupCandidatePairPingInterval); |
| 122 | EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy); |
| 123 | EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts); |
| 124 | } |
| 125 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 126 | @end |
| 127 | |
| 128 | TEST(RTCConfigurationTest, NativeConfigurationConversionTest) { |
| 129 | @autoreleasepool { |
| 130 | RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init]; |
| 131 | [test testConversionToNativeConfiguration]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 132 | [test testNativeConversionToConfiguration]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |