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