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