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