blob: 90de644c097b8a3e1a390afedead2528583252fd [file] [log] [blame]
hjon6d49a8e2016-01-26 13:06:42 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/gunit.h"
hjon6d49a8e2016-01-26 13:06:42 -080016
tkchin9eeb6242016-04-27 01:54:20 -070017#import "NSString+StdString.h"
18#import "RTCConfiguration+Private.h"
19#import "WebRTC/RTCConfiguration.h"
20#import "WebRTC/RTCIceServer.h"
Steve Antond295e402017-07-14 16:06:41 -070021#import "WebRTC/RTCIntervalRange.h"
hjon6d49a8e2016-01-26 13:06:42 -080022
23@interface RTCConfigurationTest : NSObject
24- (void)testConversionToNativeConfiguration;
jtteh4eeb5372017-04-03 15:06:37 -070025- (void)testNativeConversionToConfiguration;
hjon6d49a8e2016-01-26 13:06:42 -080026@end
27
28@implementation RTCConfigurationTest
29
30- (void)testConversionToNativeConfiguration {
31 NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
32 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
Steve Antond295e402017-07-14 16:06:41 -070033 RTCIntervalRange *range = [[RTCIntervalRange alloc] initWithMin:0 max:100];
hjon6d49a8e2016-01-26 13:06:42 -080034
tkchinab8f82f2016-01-27 17:50:11 -080035 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 Zhang46007ae2016-06-03 16:31:32 -070041 config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost;
tkchinab8f82f2016-01-27 17:50:11 -080042 const int maxPackets = 60;
43 const int timeout = 1;
44 const int interval = 2;
45 config.audioJitterBufferMaxPackets = maxPackets;
hayscc9f95002016-12-05 14:24:32 -080046 config.audioJitterBufferFastAccelerate = YES;
tkchinab8f82f2016-01-27 17:50:11 -080047 config.iceConnectionReceivingTimeout = timeout;
48 config.iceBackupCandidatePairPingInterval = interval;
Honghai Zhang3108fc92016-05-11 10:10:39 -070049 config.continualGatheringPolicy =
50 RTCContinualGatheringPolicyGatherContinually;
honghaizaf6b6e02016-07-11 15:09:26 -070051 config.shouldPruneTurnPorts = YES;
Steve Antond295e402017-07-14 16:06:41 -070052 config.iceRegatherIntervalRange = range;
hjon6d49a8e2016-01-26 13:06:42 -080053
Henrik Boströme06c2dd2016-05-13 13:50:38 +020054 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
hbosa73ca562016-05-17 03:28:58 -070055 nativeConfig([config createNativeConfiguration]);
56 EXPECT_TRUE(nativeConfig.get());
Henrik Boströme06c2dd2016-05-13 13:50:38 +020057 EXPECT_EQ(1u, nativeConfig->servers.size());
hjon6d49a8e2016-01-26 13:06:42 -080058 webrtc::PeerConnectionInterface::IceServer nativeServer =
Henrik Boströme06c2dd2016-05-13 13:50:38 +020059 nativeConfig->servers.front();
hjon6d49a8e2016-01-26 13:06:42 -080060 EXPECT_EQ(1u, nativeServer.urls.size());
61 EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front());
62
Henrik Boströme06c2dd2016-05-13 13:50:38 +020063 EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type);
hjon6d49a8e2016-01-26 13:06:42 -080064 EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020065 nativeConfig->bundle_policy);
hjon6d49a8e2016-01-26 13:06:42 -080066 EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020067 nativeConfig->rtcp_mux_policy);
hjon6d49a8e2016-01-26 13:06:42 -080068 EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020069 nativeConfig->tcp_candidate_policy);
Honghai Zhang46007ae2016-06-03 16:31:32 -070070 EXPECT_EQ(webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost,
71 nativeConfig->candidate_network_policy);
Henrik Boströme06c2dd2016-05-13 13:50:38 +020072 EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets);
hayscc9f95002016-12-05 14:24:32 -080073 EXPECT_EQ(true, nativeConfig->audio_jitter_buffer_fast_accelerate);
Henrik Boströme06c2dd2016-05-13 13:50:38 +020074 EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout);
75 EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval);
Honghai Zhang3108fc92016-05-11 10:10:39 -070076 EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020077 nativeConfig->continual_gathering_policy);
Honghai Zhange2e35ca2016-07-01 14:22:17 -070078 EXPECT_EQ(true, nativeConfig->prune_turn_ports);
Steve Antond295e402017-07-14 16:06:41 -070079 EXPECT_EQ(range.min, nativeConfig->ice_regather_interval_range->min());
80 EXPECT_EQ(range.max, nativeConfig->ice_regather_interval_range->max());
hjon6d49a8e2016-01-26 13:06:42 -080081}
82
jtteh4eeb5372017-04-03 15:06:37 -070083- (void)testNativeConversionToConfiguration {
84 NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
85 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
Steve Antond295e402017-07-14 16:06:41 -070086 RTCIntervalRange *range = [[RTCIntervalRange alloc] initWithMin:0 max:100];
jtteh4eeb5372017-04-03 15:06:37 -070087
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 Antond295e402017-07-14 16:06:41 -0700105 config.iceRegatherIntervalRange = range;
jtteh4eeb5372017-04-03 15:06:37 -0700106
107 webrtc::PeerConnectionInterface::RTCConfiguration *nativeConfig =
108 [config createNativeConfiguration];
jtteh465faf02017-04-04 14:00:16 -0700109 RTCConfiguration *newConfig = [[RTCConfiguration alloc]
110 initWithNativeConfiguration:*nativeConfig];
jtteh4eeb5372017-04-03 15:06:37 -0700111 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 Antond295e402017-07-14 16:06:41 -0700131 EXPECT_EQ(config.iceRegatherIntervalRange.min, newConfig.iceRegatherIntervalRange.min);
132 EXPECT_EQ(config.iceRegatherIntervalRange.max, newConfig.iceRegatherIntervalRange.max);
jtteh4eeb5372017-04-03 15:06:37 -0700133}
134
hjon6d49a8e2016-01-26 13:06:42 -0800135@end
136
137TEST(RTCConfigurationTest, NativeConfigurationConversionTest) {
138 @autoreleasepool {
139 RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init];
140 [test testConversionToNativeConfiguration];
jtteh4eeb5372017-04-03 15:06:37 -0700141 [test testNativeConversionToConfiguration];
hjon6d49a8e2016-01-26 13:06:42 -0800142 }
143}
144