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 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 17 | #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" |
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; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 53 | config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES |
| 54 | srtpEnableAes128Sha1_32CryptoCipher:YES |
| 55 | srtpEnableEncryptedRtpHeaderExtensions:YES |
| 56 | sframeRequireFrameEncryption:YES]; |
Jiawei Ou | b1e4775 | 2018-11-13 23:48:19 -0800 | [diff] [blame^] | 57 | config.rtcpAudioReportIntervalMs = 2500; |
| 58 | config.rtcpVideoReportIntervalMs = 3750; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 59 | |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 60 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 61 | nativeConfig([config createNativeConfiguration]); |
| 62 | EXPECT_TRUE(nativeConfig.get()); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 63 | EXPECT_EQ(1u, nativeConfig->servers.size()); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 64 | webrtc::PeerConnectionInterface::IceServer nativeServer = |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 65 | nativeConfig->servers.front(); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 66 | EXPECT_EQ(1u, nativeServer.urls.size()); |
| 67 | EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front()); |
| 68 | |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 69 | EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 70 | EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 71 | nativeConfig->bundle_policy); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 72 | EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 73 | nativeConfig->rtcp_mux_policy); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 74 | EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 75 | nativeConfig->tcp_candidate_policy); |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 76 | EXPECT_EQ(webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost, |
| 77 | nativeConfig->candidate_network_policy); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 78 | EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets); |
haysc | c9f9500 | 2016-12-05 14:24:32 -0800 | [diff] [blame] | 79 | EXPECT_EQ(true, nativeConfig->audio_jitter_buffer_fast_accelerate); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 80 | EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout); |
| 81 | EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval); |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 82 | EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY, |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 83 | nativeConfig->continual_gathering_policy); |
Honghai Zhang | e2e35ca | 2016-07-01 14:22:17 -0700 | [diff] [blame] | 84 | EXPECT_EQ(true, nativeConfig->prune_turn_ports); |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 85 | EXPECT_EQ(range.min, nativeConfig->ice_regather_interval_range->min()); |
| 86 | EXPECT_EQ(range.max, nativeConfig->ice_regather_interval_range->max()); |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 87 | EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_gcm_crypto_suites); |
| 88 | EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_aes128_sha1_32_crypto_cipher); |
| 89 | EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_encrypted_rtp_header_extensions); |
| 90 | EXPECT_EQ(true, nativeConfig->crypto_options->sframe.require_frame_encryption); |
Jiawei Ou | b1e4775 | 2018-11-13 23:48:19 -0800 | [diff] [blame^] | 91 | EXPECT_EQ(2500, nativeConfig->audio_rtcp_report_interval_ms()); |
| 92 | EXPECT_EQ(3750, nativeConfig->video_rtcp_report_interval_ms()); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 93 | } |
| 94 | |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 95 | - (void)testNativeConversionToConfiguration { |
| 96 | NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; |
| 97 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 98 | RTCIntervalRange *range = [[RTCIntervalRange alloc] initWithMin:0 max:100]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 99 | |
| 100 | RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
| 101 | config.iceServers = @[ server ]; |
| 102 | config.iceTransportPolicy = RTCIceTransportPolicyRelay; |
| 103 | config.bundlePolicy = RTCBundlePolicyMaxBundle; |
| 104 | config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; |
| 105 | config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; |
| 106 | config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost; |
| 107 | const int maxPackets = 60; |
| 108 | const int timeout = 1; |
| 109 | const int interval = 2; |
| 110 | config.audioJitterBufferMaxPackets = maxPackets; |
| 111 | config.audioJitterBufferFastAccelerate = YES; |
| 112 | config.iceConnectionReceivingTimeout = timeout; |
| 113 | config.iceBackupCandidatePairPingInterval = interval; |
| 114 | config.continualGatheringPolicy = |
| 115 | RTCContinualGatheringPolicyGatherContinually; |
| 116 | config.shouldPruneTurnPorts = YES; |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 117 | config.iceRegatherIntervalRange = range; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 118 | config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES |
| 119 | srtpEnableAes128Sha1_32CryptoCipher:NO |
| 120 | srtpEnableEncryptedRtpHeaderExtensions:NO |
| 121 | sframeRequireFrameEncryption:NO]; |
Jiawei Ou | b1e4775 | 2018-11-13 23:48:19 -0800 | [diff] [blame^] | 122 | config.rtcpAudioReportIntervalMs = 1500; |
| 123 | config.rtcpVideoReportIntervalMs = 2150; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 124 | |
| 125 | webrtc::PeerConnectionInterface::RTCConfiguration *nativeConfig = |
| 126 | [config createNativeConfiguration]; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 127 | RTCConfiguration *newConfig = [[RTCConfiguration alloc] |
| 128 | initWithNativeConfiguration:*nativeConfig]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 129 | EXPECT_EQ([config.iceServers count], newConfig.iceServers.count); |
| 130 | RTCIceServer *newServer = newConfig.iceServers[0]; |
| 131 | RTCIceServer *origServer = config.iceServers[0]; |
| 132 | EXPECT_EQ(origServer.urlStrings.count, server.urlStrings.count); |
| 133 | std::string origUrl = origServer.urlStrings.firstObject.UTF8String; |
| 134 | std::string url = newServer.urlStrings.firstObject.UTF8String; |
| 135 | EXPECT_EQ(origUrl, url); |
| 136 | |
| 137 | EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy); |
| 138 | EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy); |
| 139 | EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy); |
| 140 | EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy); |
| 141 | EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy); |
| 142 | EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets); |
| 143 | EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate); |
| 144 | EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout); |
| 145 | EXPECT_EQ(config.iceBackupCandidatePairPingInterval, |
| 146 | newConfig.iceBackupCandidatePairPingInterval); |
| 147 | EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy); |
| 148 | EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts); |
Steve Anton | d295e40 | 2017-07-14 16:06:41 -0700 | [diff] [blame] | 149 | EXPECT_EQ(config.iceRegatherIntervalRange.min, newConfig.iceRegatherIntervalRange.min); |
| 150 | EXPECT_EQ(config.iceRegatherIntervalRange.max, newConfig.iceRegatherIntervalRange.max); |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 151 | EXPECT_EQ(config.cryptoOptions.srtpEnableGcmCryptoSuites, |
| 152 | newConfig.cryptoOptions.srtpEnableGcmCryptoSuites); |
| 153 | EXPECT_EQ(config.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher, |
| 154 | newConfig.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher); |
| 155 | EXPECT_EQ(config.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions, |
| 156 | newConfig.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions); |
| 157 | EXPECT_EQ(config.cryptoOptions.sframeRequireFrameEncryption, |
| 158 | newConfig.cryptoOptions.sframeRequireFrameEncryption); |
Jiawei Ou | b1e4775 | 2018-11-13 23:48:19 -0800 | [diff] [blame^] | 159 | EXPECT_EQ(config.rtcpAudioReportIntervalMs, newConfig.rtcpAudioReportIntervalMs); |
| 160 | EXPECT_EQ(config.rtcpVideoReportIntervalMs, newConfig.rtcpVideoReportIntervalMs); |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | - (void)testDefaultValues { |
| 164 | RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
| 165 | EXPECT_EQ(config.cryptoOptions, nil); |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 166 | } |
| 167 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 168 | @end |
| 169 | |
| 170 | TEST(RTCConfigurationTest, NativeConfigurationConversionTest) { |
| 171 | @autoreleasepool { |
| 172 | RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init]; |
| 173 | [test testConversionToNativeConfiguration]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 174 | [test testNativeConversionToConfiguration]; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 175 | [test testDefaultValues]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 176 | } |
| 177 | } |