blob: 67a303e5507e99e5908daea67d552af2a7c77c51 [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
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020017#import "api/peerconnection/RTCConfiguration+Private.h"
18#import "api/peerconnection/RTCConfiguration.h"
19#import "api/peerconnection/RTCIceServer.h"
20#import "api/peerconnection/RTCIntervalRange.h"
21#import "helpers/NSString+StdString.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;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070053 config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES
54 srtpEnableAes128Sha1_32CryptoCipher:YES
55 srtpEnableEncryptedRtpHeaderExtensions:YES
56 sframeRequireFrameEncryption:YES];
hjon6d49a8e2016-01-26 13:06:42 -080057
Henrik Boströme06c2dd2016-05-13 13:50:38 +020058 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
hbosa73ca562016-05-17 03:28:58 -070059 nativeConfig([config createNativeConfiguration]);
60 EXPECT_TRUE(nativeConfig.get());
Henrik Boströme06c2dd2016-05-13 13:50:38 +020061 EXPECT_EQ(1u, nativeConfig->servers.size());
hjon6d49a8e2016-01-26 13:06:42 -080062 webrtc::PeerConnectionInterface::IceServer nativeServer =
Henrik Boströme06c2dd2016-05-13 13:50:38 +020063 nativeConfig->servers.front();
hjon6d49a8e2016-01-26 13:06:42 -080064 EXPECT_EQ(1u, nativeServer.urls.size());
65 EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front());
66
Henrik Boströme06c2dd2016-05-13 13:50:38 +020067 EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type);
hjon6d49a8e2016-01-26 13:06:42 -080068 EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020069 nativeConfig->bundle_policy);
hjon6d49a8e2016-01-26 13:06:42 -080070 EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020071 nativeConfig->rtcp_mux_policy);
hjon6d49a8e2016-01-26 13:06:42 -080072 EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020073 nativeConfig->tcp_candidate_policy);
Honghai Zhang46007ae2016-06-03 16:31:32 -070074 EXPECT_EQ(webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost,
75 nativeConfig->candidate_network_policy);
Henrik Boströme06c2dd2016-05-13 13:50:38 +020076 EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets);
hayscc9f95002016-12-05 14:24:32 -080077 EXPECT_EQ(true, nativeConfig->audio_jitter_buffer_fast_accelerate);
Henrik Boströme06c2dd2016-05-13 13:50:38 +020078 EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout);
79 EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval);
Honghai Zhang3108fc92016-05-11 10:10:39 -070080 EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020081 nativeConfig->continual_gathering_policy);
Honghai Zhange2e35ca2016-07-01 14:22:17 -070082 EXPECT_EQ(true, nativeConfig->prune_turn_ports);
Steve Antond295e402017-07-14 16:06:41 -070083 EXPECT_EQ(range.min, nativeConfig->ice_regather_interval_range->min());
84 EXPECT_EQ(range.max, nativeConfig->ice_regather_interval_range->max());
Benjamin Wright8c27cca2018-10-25 10:16:44 -070085 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_gcm_crypto_suites);
86 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_aes128_sha1_32_crypto_cipher);
87 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_encrypted_rtp_header_extensions);
88 EXPECT_EQ(true, nativeConfig->crypto_options->sframe.require_frame_encryption);
hjon6d49a8e2016-01-26 13:06:42 -080089}
90
jtteh4eeb5372017-04-03 15:06:37 -070091- (void)testNativeConversionToConfiguration {
92 NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
93 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
Steve Antond295e402017-07-14 16:06:41 -070094 RTCIntervalRange *range = [[RTCIntervalRange alloc] initWithMin:0 max:100];
jtteh4eeb5372017-04-03 15:06:37 -070095
96 RTCConfiguration *config = [[RTCConfiguration alloc] init];
97 config.iceServers = @[ server ];
98 config.iceTransportPolicy = RTCIceTransportPolicyRelay;
99 config.bundlePolicy = RTCBundlePolicyMaxBundle;
100 config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate;
101 config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled;
102 config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost;
103 const int maxPackets = 60;
104 const int timeout = 1;
105 const int interval = 2;
106 config.audioJitterBufferMaxPackets = maxPackets;
107 config.audioJitterBufferFastAccelerate = YES;
108 config.iceConnectionReceivingTimeout = timeout;
109 config.iceBackupCandidatePairPingInterval = interval;
110 config.continualGatheringPolicy =
111 RTCContinualGatheringPolicyGatherContinually;
112 config.shouldPruneTurnPorts = YES;
Steve Antond295e402017-07-14 16:06:41 -0700113 config.iceRegatherIntervalRange = range;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700114 config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES
115 srtpEnableAes128Sha1_32CryptoCipher:NO
116 srtpEnableEncryptedRtpHeaderExtensions:NO
117 sframeRequireFrameEncryption:NO];
jtteh4eeb5372017-04-03 15:06:37 -0700118
119 webrtc::PeerConnectionInterface::RTCConfiguration *nativeConfig =
120 [config createNativeConfiguration];
jtteh465faf02017-04-04 14:00:16 -0700121 RTCConfiguration *newConfig = [[RTCConfiguration alloc]
122 initWithNativeConfiguration:*nativeConfig];
jtteh4eeb5372017-04-03 15:06:37 -0700123 EXPECT_EQ([config.iceServers count], newConfig.iceServers.count);
124 RTCIceServer *newServer = newConfig.iceServers[0];
125 RTCIceServer *origServer = config.iceServers[0];
126 EXPECT_EQ(origServer.urlStrings.count, server.urlStrings.count);
127 std::string origUrl = origServer.urlStrings.firstObject.UTF8String;
128 std::string url = newServer.urlStrings.firstObject.UTF8String;
129 EXPECT_EQ(origUrl, url);
130
131 EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy);
132 EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy);
133 EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy);
134 EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy);
135 EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy);
136 EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets);
137 EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate);
138 EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout);
139 EXPECT_EQ(config.iceBackupCandidatePairPingInterval,
140 newConfig.iceBackupCandidatePairPingInterval);
141 EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy);
142 EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts);
Steve Antond295e402017-07-14 16:06:41 -0700143 EXPECT_EQ(config.iceRegatherIntervalRange.min, newConfig.iceRegatherIntervalRange.min);
144 EXPECT_EQ(config.iceRegatherIntervalRange.max, newConfig.iceRegatherIntervalRange.max);
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700145 EXPECT_EQ(config.cryptoOptions.srtpEnableGcmCryptoSuites,
146 newConfig.cryptoOptions.srtpEnableGcmCryptoSuites);
147 EXPECT_EQ(config.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher,
148 newConfig.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher);
149 EXPECT_EQ(config.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions,
150 newConfig.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions);
151 EXPECT_EQ(config.cryptoOptions.sframeRequireFrameEncryption,
152 newConfig.cryptoOptions.sframeRequireFrameEncryption);
153}
154
155- (void)testDefaultValues {
156 RTCConfiguration *config = [[RTCConfiguration alloc] init];
157 EXPECT_EQ(config.cryptoOptions, nil);
jtteh4eeb5372017-04-03 15:06:37 -0700158}
159
hjon6d49a8e2016-01-26 13:06:42 -0800160@end
161
162TEST(RTCConfigurationTest, NativeConfigurationConversionTest) {
163 @autoreleasepool {
164 RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init];
165 [test testConversionToNativeConfiguration];
jtteh4eeb5372017-04-03 15:06:37 -0700166 [test testNativeConversionToConfiguration];
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700167 [test testDefaultValues];
hjon6d49a8e2016-01-26 13:06:42 -0800168 }
169}