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#import <XCTest/XCTest.h> 13 14#include <vector> 15 16#include "rtc_base/gunit.h" 17 18#import "api/peerconnection/RTCConfiguration+Private.h" 19#import "api/peerconnection/RTCConfiguration.h" 20#import "api/peerconnection/RTCIceServer.h" 21#import "helpers/NSString+StdString.h" 22 23@interface RTCConfigurationTest : XCTestCase 24@end 25 26@implementation RTCConfigurationTest 27 28- (void)testConversionToNativeConfiguration { 29 NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; 30 RTC_OBJC_TYPE(RTCIceServer) *server = 31 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:urlStrings]; 32 33 RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; 34 config.iceServers = @[ server ]; 35 config.iceTransportPolicy = RTCIceTransportPolicyRelay; 36 config.bundlePolicy = RTCBundlePolicyMaxBundle; 37 config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; 38 config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; 39 config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost; 40 const int maxPackets = 60; 41 const int timeout = 1; 42 const int interval = 2; 43 config.audioJitterBufferMaxPackets = maxPackets; 44 config.audioJitterBufferFastAccelerate = YES; 45 config.iceConnectionReceivingTimeout = timeout; 46 config.iceBackupCandidatePairPingInterval = interval; 47 config.continualGatheringPolicy = 48 RTCContinualGatheringPolicyGatherContinually; 49 config.shouldPruneTurnPorts = YES; 50 config.cryptoOptions = 51 [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc] initWithSrtpEnableGcmCryptoSuites:YES 52 srtpEnableAes128Sha1_32CryptoCipher:YES 53 srtpEnableEncryptedRtpHeaderExtensions:YES 54 sframeRequireFrameEncryption:YES]; 55 config.rtcpAudioReportIntervalMs = 2500; 56 config.rtcpVideoReportIntervalMs = 3750; 57 58 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> 59 nativeConfig([config createNativeConfiguration]); 60 EXPECT_TRUE(nativeConfig.get()); 61 EXPECT_EQ(1u, nativeConfig->servers.size()); 62 webrtc::PeerConnectionInterface::IceServer nativeServer = 63 nativeConfig->servers.front(); 64 EXPECT_EQ(1u, nativeServer.urls.size()); 65 EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front()); 66 67 EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type); 68 EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle, 69 nativeConfig->bundle_policy); 70 EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate, 71 nativeConfig->rtcp_mux_policy); 72 EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled, 73 nativeConfig->tcp_candidate_policy); 74 EXPECT_EQ(webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost, 75 nativeConfig->candidate_network_policy); 76 EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets); 77 EXPECT_EQ(true, nativeConfig->audio_jitter_buffer_fast_accelerate); 78 EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout); 79 EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval); 80 EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY, 81 nativeConfig->continual_gathering_policy); 82 EXPECT_EQ(true, nativeConfig->prune_turn_ports); 83 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_gcm_crypto_suites); 84 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_aes128_sha1_32_crypto_cipher); 85 EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_encrypted_rtp_header_extensions); 86 EXPECT_EQ(true, nativeConfig->crypto_options->sframe.require_frame_encryption); 87 EXPECT_EQ(2500, nativeConfig->audio_rtcp_report_interval_ms()); 88 EXPECT_EQ(3750, nativeConfig->video_rtcp_report_interval_ms()); 89} 90 91- (void)testNativeConversionToConfiguration { 92 NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; 93 RTC_OBJC_TYPE(RTCIceServer) *server = 94 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:urlStrings]; 95 96 RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(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; 113 config.cryptoOptions = 114 [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc] initWithSrtpEnableGcmCryptoSuites:YES 115 srtpEnableAes128Sha1_32CryptoCipher:NO 116 srtpEnableEncryptedRtpHeaderExtensions:NO 117 sframeRequireFrameEncryption:NO]; 118 config.rtcpAudioReportIntervalMs = 1500; 119 config.rtcpVideoReportIntervalMs = 2150; 120 121 webrtc::PeerConnectionInterface::RTCConfiguration *nativeConfig = 122 [config createNativeConfiguration]; 123 RTC_OBJC_TYPE(RTCConfiguration) *newConfig = 124 [[RTC_OBJC_TYPE(RTCConfiguration) alloc] initWithNativeConfiguration:*nativeConfig]; 125 EXPECT_EQ([config.iceServers count], newConfig.iceServers.count); 126 RTC_OBJC_TYPE(RTCIceServer) *newServer = newConfig.iceServers[0]; 127 RTC_OBJC_TYPE(RTCIceServer) *origServer = config.iceServers[0]; 128 EXPECT_EQ(origServer.urlStrings.count, server.urlStrings.count); 129 std::string origUrl = origServer.urlStrings.firstObject.UTF8String; 130 std::string url = newServer.urlStrings.firstObject.UTF8String; 131 EXPECT_EQ(origUrl, url); 132 133 EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy); 134 EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy); 135 EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy); 136 EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy); 137 EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy); 138 EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets); 139 EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate); 140 EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout); 141 EXPECT_EQ(config.iceBackupCandidatePairPingInterval, 142 newConfig.iceBackupCandidatePairPingInterval); 143 EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy); 144 EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts); 145 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 EXPECT_EQ(config.rtcpAudioReportIntervalMs, newConfig.rtcpAudioReportIntervalMs); 154 EXPECT_EQ(config.rtcpVideoReportIntervalMs, newConfig.rtcpVideoReportIntervalMs); 155} 156 157- (void)testDefaultValues { 158 RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; 159 EXPECT_EQ(config.cryptoOptions, nil); 160} 161 162@end 163