jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [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 | |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 13 | #include <memory> |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "rtc_base/gunit.h" |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 17 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 18 | #import "api/peerconnection/RTCConfiguration+Private.h" |
| 19 | #import "api/peerconnection/RTCConfiguration.h" |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 20 | #import "api/peerconnection/RTCCryptoOptions.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 21 | #import "api/peerconnection/RTCIceServer.h" |
| 22 | #import "api/peerconnection/RTCMediaConstraints.h" |
| 23 | #import "api/peerconnection/RTCPeerConnection.h" |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 24 | #import "api/peerconnection/RTCPeerConnectionFactory+Native.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 25 | #import "api/peerconnection/RTCPeerConnectionFactory.h" |
| 26 | #import "helpers/NSString+StdString.h" |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 27 | |
| 28 | @interface RTCPeerConnectionTest : NSObject |
| 29 | - (void)testConfigurationGetter; |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 30 | - (void)testWithDependencies; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 31 | @end |
| 32 | |
| 33 | @implementation RTCPeerConnectionTest |
| 34 | |
| 35 | - (void)testConfigurationGetter { |
| 36 | NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; |
| 37 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; |
| 38 | |
| 39 | RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
| 40 | config.iceServers = @[ server ]; |
| 41 | config.iceTransportPolicy = RTCIceTransportPolicyRelay; |
| 42 | config.bundlePolicy = RTCBundlePolicyMaxBundle; |
| 43 | config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; |
| 44 | config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; |
| 45 | config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost; |
| 46 | const int maxPackets = 60; |
Qingsi Wang | dea6889 | 2018-03-27 10:55:21 -0700 | [diff] [blame] | 47 | const int timeout = 1500; |
| 48 | const int interval = 2000; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 49 | config.audioJitterBufferMaxPackets = maxPackets; |
| 50 | config.audioJitterBufferFastAccelerate = YES; |
| 51 | config.iceConnectionReceivingTimeout = timeout; |
| 52 | config.iceBackupCandidatePairPingInterval = interval; |
| 53 | config.continualGatheringPolicy = |
| 54 | RTCContinualGatheringPolicyGatherContinually; |
| 55 | config.shouldPruneTurnPorts = YES; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 56 | config.activeResetSrtpParams = YES; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 57 | config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES |
| 58 | srtpEnableAes128Sha1_32CryptoCipher:YES |
| 59 | srtpEnableEncryptedRtpHeaderExtensions:NO |
| 60 | sframeRequireFrameEncryption:NO]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 61 | |
| 62 | RTCMediaConstraints *contraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@{} |
| 63 | optionalConstraints:nil]; |
| 64 | RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 65 | |
kthelgason | c097710 | 2017-04-24 00:57:16 -0700 | [diff] [blame] | 66 | RTCConfiguration *newConfig; |
| 67 | @autoreleasepool { |
| 68 | RTCPeerConnection *peerConnection = |
| 69 | [factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil]; |
| 70 | newConfig = peerConnection.configuration; |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 71 | |
zstein | 8b47617 | 2017-09-05 14:43:03 -0700 | [diff] [blame] | 72 | EXPECT_TRUE([peerConnection setBweMinBitrateBps:[NSNumber numberWithInt:100000] |
| 73 | currentBitrateBps:[NSNumber numberWithInt:5000000] |
| 74 | maxBitrateBps:[NSNumber numberWithInt:500000000]]); |
| 75 | EXPECT_FALSE([peerConnection setBweMinBitrateBps:[NSNumber numberWithInt:2] |
| 76 | currentBitrateBps:[NSNumber numberWithInt:1] |
| 77 | maxBitrateBps:nil]); |
kthelgason | c097710 | 2017-04-24 00:57:16 -0700 | [diff] [blame] | 78 | } |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 79 | |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 80 | EXPECT_EQ([config.iceServers count], [newConfig.iceServers count]); |
| 81 | RTCIceServer *newServer = newConfig.iceServers[0]; |
| 82 | RTCIceServer *origServer = config.iceServers[0]; |
| 83 | std::string origUrl = origServer.urlStrings.firstObject.UTF8String; |
| 84 | std::string url = newServer.urlStrings.firstObject.UTF8String; |
| 85 | EXPECT_EQ(origUrl, url); |
| 86 | |
| 87 | EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy); |
| 88 | EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy); |
| 89 | EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy); |
| 90 | EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy); |
| 91 | EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy); |
| 92 | EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets); |
| 93 | EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate); |
| 94 | EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout); |
| 95 | EXPECT_EQ(config.iceBackupCandidatePairPingInterval, |
| 96 | newConfig.iceBackupCandidatePairPingInterval); |
| 97 | EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy); |
| 98 | EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts); |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 99 | EXPECT_EQ(config.activeResetSrtpParams, newConfig.activeResetSrtpParams); |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 100 | EXPECT_EQ(config.cryptoOptions.srtpEnableGcmCryptoSuites, |
| 101 | newConfig.cryptoOptions.srtpEnableGcmCryptoSuites); |
| 102 | EXPECT_EQ(config.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher, |
| 103 | newConfig.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher); |
| 104 | EXPECT_EQ(config.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions, |
| 105 | newConfig.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions); |
| 106 | EXPECT_EQ(config.cryptoOptions.sframeRequireFrameEncryption, |
| 107 | newConfig.cryptoOptions.sframeRequireFrameEncryption); |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 110 | - (void)testWithDependencies { |
| 111 | NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; |
| 112 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; |
| 113 | |
| 114 | RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
| 115 | config.iceServers = @[ server ]; |
| 116 | RTCMediaConstraints *contraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@{} |
| 117 | optionalConstraints:nil]; |
| 118 | RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init]; |
| 119 | |
| 120 | RTCConfiguration *newConfig; |
| 121 | std::unique_ptr<webrtc::PeerConnectionDependencies> pc_dependencies = |
| 122 | std::make_unique<webrtc::PeerConnectionDependencies>(nullptr); |
| 123 | @autoreleasepool { |
| 124 | RTCPeerConnection *peerConnection = |
| 125 | [factory peerConnectionWithDependencies:config |
| 126 | constraints:contraints |
| 127 | dependencies:std::move(pc_dependencies) |
| 128 | delegate:nil]; |
| 129 | newConfig = peerConnection.configuration; |
| 130 | } |
| 131 | } |
| 132 | |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 133 | @end |
| 134 | |
| 135 | TEST(RTCPeerConnectionTest, ConfigurationGetterTest) { |
| 136 | @autoreleasepool { |
| 137 | RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init]; |
| 138 | [test testConfigurationGetter]; |
| 139 | } |
| 140 | } |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 141 | |
| 142 | TEST(RTCPeerConnectionTest, TestWithDependencies) { |
| 143 | @autoreleasepool { |
| 144 | RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init]; |
| 145 | [test testWithDependencies]; |
| 146 | } |
| 147 | } |