blob: 3fb4d428e4c59a5390d9cd2d87ef74c5149b0a78 [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"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020020#import "helpers/NSString+StdString.h"
hjon6d49a8e2016-01-26 13:06:42 -080021
22@interface RTCConfigurationTest : NSObject
23- (void)testConversionToNativeConfiguration;
jtteh4eeb5372017-04-03 15:06:37 -070024- (void)testNativeConversionToConfiguration;
hjon6d49a8e2016-01-26 13:06:42 -080025@end
26
27@implementation RTCConfigurationTest
28
29- (void)testConversionToNativeConfiguration {
30 NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
31 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
32
tkchinab8f82f2016-01-27 17:50:11 -080033 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 Zhang46007ae2016-06-03 16:31:32 -070039 config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost;
tkchinab8f82f2016-01-27 17:50:11 -080040 const int maxPackets = 60;
41 const int timeout = 1;
42 const int interval = 2;
43 config.audioJitterBufferMaxPackets = maxPackets;
hayscc9f95002016-12-05 14:24:32 -080044 config.audioJitterBufferFastAccelerate = YES;
tkchinab8f82f2016-01-27 17:50:11 -080045 config.iceConnectionReceivingTimeout = timeout;
46 config.iceBackupCandidatePairPingInterval = interval;
Honghai Zhang3108fc92016-05-11 10:10:39 -070047 config.continualGatheringPolicy =
48 RTCContinualGatheringPolicyGatherContinually;
honghaizaf6b6e02016-07-11 15:09:26 -070049 config.shouldPruneTurnPorts = YES;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070050 config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES
51 srtpEnableAes128Sha1_32CryptoCipher:YES
52 srtpEnableEncryptedRtpHeaderExtensions:YES
53 sframeRequireFrameEncryption:YES];
Jiawei Oub1e47752018-11-13 23:48:19 -080054 config.rtcpAudioReportIntervalMs = 2500;
55 config.rtcpVideoReportIntervalMs = 3750;
hjon6d49a8e2016-01-26 13:06:42 -080056
Henrik Boströme06c2dd2016-05-13 13:50:38 +020057 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
hbosa73ca562016-05-17 03:28:58 -070058 nativeConfig([config createNativeConfiguration]);
59 EXPECT_TRUE(nativeConfig.get());
Henrik Boströme06c2dd2016-05-13 13:50:38 +020060 EXPECT_EQ(1u, nativeConfig->servers.size());
hjon6d49a8e2016-01-26 13:06:42 -080061 webrtc::PeerConnectionInterface::IceServer nativeServer =
Henrik Boströme06c2dd2016-05-13 13:50:38 +020062 nativeConfig->servers.front();
hjon6d49a8e2016-01-26 13:06:42 -080063 EXPECT_EQ(1u, nativeServer.urls.size());
64 EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front());
65
Henrik Boströme06c2dd2016-05-13 13:50:38 +020066 EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type);
hjon6d49a8e2016-01-26 13:06:42 -080067 EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020068 nativeConfig->bundle_policy);
hjon6d49a8e2016-01-26 13:06:42 -080069 EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020070 nativeConfig->rtcp_mux_policy);
hjon6d49a8e2016-01-26 13:06:42 -080071 EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020072 nativeConfig->tcp_candidate_policy);
Honghai Zhang46007ae2016-06-03 16:31:32 -070073 EXPECT_EQ(webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost,
74 nativeConfig->candidate_network_policy);
Henrik Boströme06c2dd2016-05-13 13:50:38 +020075 EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets);
hayscc9f95002016-12-05 14:24:32 -080076 EXPECT_EQ(true, nativeConfig->audio_jitter_buffer_fast_accelerate);
Henrik Boströme06c2dd2016-05-13 13:50:38 +020077 EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout);
78 EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval);
Honghai Zhang3108fc92016-05-11 10:10:39 -070079 EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY,
Henrik Boströme06c2dd2016-05-13 13:50:38 +020080 nativeConfig->continual_gathering_policy);
Honghai Zhange2e35ca2016-07-01 14:22:17 -070081 EXPECT_EQ(true, nativeConfig->prune_turn_ports);
Benjamin Wright8c27cca2018-10-25 10:16:44 -070082 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_gcm_crypto_suites);
83 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_aes128_sha1_32_crypto_cipher);
84 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_encrypted_rtp_header_extensions);
85 EXPECT_EQ(true, nativeConfig->crypto_options->sframe.require_frame_encryption);
Jiawei Oub1e47752018-11-13 23:48:19 -080086 EXPECT_EQ(2500, nativeConfig->audio_rtcp_report_interval_ms());
87 EXPECT_EQ(3750, nativeConfig->video_rtcp_report_interval_ms());
hjon6d49a8e2016-01-26 13:06:42 -080088}
89
jtteh4eeb5372017-04-03 15:06:37 -070090- (void)testNativeConversionToConfiguration {
91 NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
92 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
93
94 RTCConfiguration *config = [[RTCConfiguration alloc] init];
95 config.iceServers = @[ server ];
96 config.iceTransportPolicy = RTCIceTransportPolicyRelay;
97 config.bundlePolicy = RTCBundlePolicyMaxBundle;
98 config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate;
99 config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled;
100 config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost;
101 const int maxPackets = 60;
102 const int timeout = 1;
103 const int interval = 2;
104 config.audioJitterBufferMaxPackets = maxPackets;
105 config.audioJitterBufferFastAccelerate = YES;
106 config.iceConnectionReceivingTimeout = timeout;
107 config.iceBackupCandidatePairPingInterval = interval;
108 config.continualGatheringPolicy =
109 RTCContinualGatheringPolicyGatherContinually;
110 config.shouldPruneTurnPorts = YES;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700111 config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES
112 srtpEnableAes128Sha1_32CryptoCipher:NO
113 srtpEnableEncryptedRtpHeaderExtensions:NO
114 sframeRequireFrameEncryption:NO];
Jiawei Oub1e47752018-11-13 23:48:19 -0800115 config.rtcpAudioReportIntervalMs = 1500;
116 config.rtcpVideoReportIntervalMs = 2150;
jtteh4eeb5372017-04-03 15:06:37 -0700117
118 webrtc::PeerConnectionInterface::RTCConfiguration *nativeConfig =
119 [config createNativeConfiguration];
jtteh465faf02017-04-04 14:00:16 -0700120 RTCConfiguration *newConfig = [[RTCConfiguration alloc]
121 initWithNativeConfiguration:*nativeConfig];
jtteh4eeb5372017-04-03 15:06:37 -0700122 EXPECT_EQ([config.iceServers count], newConfig.iceServers.count);
123 RTCIceServer *newServer = newConfig.iceServers[0];
124 RTCIceServer *origServer = config.iceServers[0];
125 EXPECT_EQ(origServer.urlStrings.count, server.urlStrings.count);
126 std::string origUrl = origServer.urlStrings.firstObject.UTF8String;
127 std::string url = newServer.urlStrings.firstObject.UTF8String;
128 EXPECT_EQ(origUrl, url);
129
130 EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy);
131 EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy);
132 EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy);
133 EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy);
134 EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy);
135 EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets);
136 EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate);
137 EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout);
138 EXPECT_EQ(config.iceBackupCandidatePairPingInterval,
139 newConfig.iceBackupCandidatePairPingInterval);
140 EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy);
141 EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts);
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700142 EXPECT_EQ(config.cryptoOptions.srtpEnableGcmCryptoSuites,
143 newConfig.cryptoOptions.srtpEnableGcmCryptoSuites);
144 EXPECT_EQ(config.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher,
145 newConfig.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher);
146 EXPECT_EQ(config.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions,
147 newConfig.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions);
148 EXPECT_EQ(config.cryptoOptions.sframeRequireFrameEncryption,
149 newConfig.cryptoOptions.sframeRequireFrameEncryption);
Jiawei Oub1e47752018-11-13 23:48:19 -0800150 EXPECT_EQ(config.rtcpAudioReportIntervalMs, newConfig.rtcpAudioReportIntervalMs);
151 EXPECT_EQ(config.rtcpVideoReportIntervalMs, newConfig.rtcpVideoReportIntervalMs);
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700152}
153
154- (void)testDefaultValues {
155 RTCConfiguration *config = [[RTCConfiguration alloc] init];
156 EXPECT_EQ(config.cryptoOptions, nil);
jtteh4eeb5372017-04-03 15:06:37 -0700157}
158
hjon6d49a8e2016-01-26 13:06:42 -0800159@end
160
161TEST(RTCConfigurationTest, NativeConfigurationConversionTest) {
162 @autoreleasepool {
163 RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init];
164 [test testConversionToNativeConfiguration];
jtteh4eeb5372017-04-03 15:06:37 -0700165 [test testNativeConversionToConfiguration];
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700166 [test testDefaultValues];
hjon6d49a8e2016-01-26 13:06:42 -0800167 }
168}