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 <memory> 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/RTCCryptoOptions.h" 21#import "api/peerconnection/RTCIceServer.h" 22#import "api/peerconnection/RTCMediaConstraints.h" 23#import "api/peerconnection/RTCPeerConnection.h" 24#import "api/peerconnection/RTCPeerConnectionFactory+Native.h" 25#import "api/peerconnection/RTCPeerConnectionFactory.h" 26#import "helpers/NSString+StdString.h" 27 28@interface RTCPeerConnectionTest : NSObject 29- (void)testConfigurationGetter; 30- (void)testWithDependencies; 31@end 32 33@implementation RTCPeerConnectionTest 34 35- (void)testConfigurationGetter { 36 NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; 37 RTC_OBJC_TYPE(RTCIceServer) *server = 38 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:urlStrings]; 39 40 RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; 41 config.iceServers = @[ server ]; 42 config.iceTransportPolicy = RTCIceTransportPolicyRelay; 43 config.bundlePolicy = RTCBundlePolicyMaxBundle; 44 config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; 45 config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; 46 config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost; 47 const int maxPackets = 60; 48 const int timeout = 1500; 49 const int interval = 2000; 50 config.audioJitterBufferMaxPackets = maxPackets; 51 config.audioJitterBufferFastAccelerate = YES; 52 config.iceConnectionReceivingTimeout = timeout; 53 config.iceBackupCandidatePairPingInterval = interval; 54 config.continualGatheringPolicy = 55 RTCContinualGatheringPolicyGatherContinually; 56 config.shouldPruneTurnPorts = YES; 57 config.activeResetSrtpParams = YES; 58 config.cryptoOptions = 59 [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc] initWithSrtpEnableGcmCryptoSuites:YES 60 srtpEnableAes128Sha1_32CryptoCipher:YES 61 srtpEnableEncryptedRtpHeaderExtensions:NO 62 sframeRequireFrameEncryption:NO]; 63 64 RTC_OBJC_TYPE(RTCMediaConstraints) *contraints = 65 [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} 66 optionalConstraints:nil]; 67 RTC_OBJC_TYPE(RTCPeerConnectionFactory) *factory = 68 [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; 69 70 RTC_OBJC_TYPE(RTCConfiguration) * newConfig; 71 @autoreleasepool { 72 RTC_OBJC_TYPE(RTCPeerConnection) *peerConnection = 73 [factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil]; 74 newConfig = peerConnection.configuration; 75 76 EXPECT_TRUE([peerConnection setBweMinBitrateBps:[NSNumber numberWithInt:100000] 77 currentBitrateBps:[NSNumber numberWithInt:5000000] 78 maxBitrateBps:[NSNumber numberWithInt:500000000]]); 79 EXPECT_FALSE([peerConnection setBweMinBitrateBps:[NSNumber numberWithInt:2] 80 currentBitrateBps:[NSNumber numberWithInt:1] 81 maxBitrateBps:nil]); 82 } 83 84 EXPECT_EQ([config.iceServers count], [newConfig.iceServers count]); 85 RTC_OBJC_TYPE(RTCIceServer) *newServer = newConfig.iceServers[0]; 86 RTC_OBJC_TYPE(RTCIceServer) *origServer = config.iceServers[0]; 87 std::string origUrl = origServer.urlStrings.firstObject.UTF8String; 88 std::string url = newServer.urlStrings.firstObject.UTF8String; 89 EXPECT_EQ(origUrl, url); 90 91 EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy); 92 EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy); 93 EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy); 94 EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy); 95 EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy); 96 EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets); 97 EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate); 98 EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout); 99 EXPECT_EQ(config.iceBackupCandidatePairPingInterval, 100 newConfig.iceBackupCandidatePairPingInterval); 101 EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy); 102 EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts); 103 EXPECT_EQ(config.activeResetSrtpParams, newConfig.activeResetSrtpParams); 104 EXPECT_EQ(config.cryptoOptions.srtpEnableGcmCryptoSuites, 105 newConfig.cryptoOptions.srtpEnableGcmCryptoSuites); 106 EXPECT_EQ(config.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher, 107 newConfig.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher); 108 EXPECT_EQ(config.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions, 109 newConfig.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions); 110 EXPECT_EQ(config.cryptoOptions.sframeRequireFrameEncryption, 111 newConfig.cryptoOptions.sframeRequireFrameEncryption); 112} 113 114- (void)testWithDependencies { 115 NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; 116 RTC_OBJC_TYPE(RTCIceServer) *server = 117 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:urlStrings]; 118 119 RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; 120 config.iceServers = @[ server ]; 121 RTC_OBJC_TYPE(RTCMediaConstraints) *contraints = 122 [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} 123 optionalConstraints:nil]; 124 RTC_OBJC_TYPE(RTCPeerConnectionFactory) *factory = 125 [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; 126 127 RTC_OBJC_TYPE(RTCConfiguration) * newConfig; 128 std::unique_ptr<webrtc::PeerConnectionDependencies> pc_dependencies = 129 std::make_unique<webrtc::PeerConnectionDependencies>(nullptr); 130 @autoreleasepool { 131 RTC_OBJC_TYPE(RTCPeerConnection) *peerConnection = 132 [factory peerConnectionWithDependencies:config 133 constraints:contraints 134 dependencies:std::move(pc_dependencies) 135 delegate:nil]; 136 newConfig = peerConnection.configuration; 137 } 138} 139 140@end 141 142TEST(RTCPeerConnectionTest, ConfigurationGetterTest) { 143 @autoreleasepool { 144 RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init]; 145 [test testConfigurationGetter]; 146 } 147} 148 149TEST(RTCPeerConnectionTest, TestWithDependencies) { 150 @autoreleasepool { 151 RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init]; 152 [test testWithDependencies]; 153 } 154} 155