blob: 53fe27b93217c0c18543ff8c884ff4b322157b5e [file] [log] [blame]
jtteh4eeb5372017-04-03 15:06:37 -07001/*
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 Oreland285f83d2020-02-07 10:30:08 +010013#include <memory>
jtteh4eeb5372017-04-03 15:06:37 -070014#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/gunit.h"
jtteh4eeb5372017-04-03 15:06:37 -070017
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020018#import "api/peerconnection/RTCConfiguration+Private.h"
19#import "api/peerconnection/RTCConfiguration.h"
Benjamin Wright8c27cca2018-10-25 10:16:44 -070020#import "api/peerconnection/RTCCryptoOptions.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020021#import "api/peerconnection/RTCIceServer.h"
22#import "api/peerconnection/RTCMediaConstraints.h"
23#import "api/peerconnection/RTCPeerConnection.h"
Jonas Oreland285f83d2020-02-07 10:30:08 +010024#import "api/peerconnection/RTCPeerConnectionFactory+Native.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020025#import "api/peerconnection/RTCPeerConnectionFactory.h"
26#import "helpers/NSString+StdString.h"
jtteh4eeb5372017-04-03 15:06:37 -070027
28@interface RTCPeerConnectionTest : NSObject
29- (void)testConfigurationGetter;
Jonas Oreland285f83d2020-02-07 10:30:08 +010030- (void)testWithDependencies;
jtteh4eeb5372017-04-03 15:06:37 -070031@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 Wangdea68892018-03-27 10:55:21 -070047 const int timeout = 1500;
48 const int interval = 2000;
jtteh4eeb5372017-04-03 15:06:37 -070049 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 Huangb57e1692018-06-12 11:41:11 -070056 config.activeResetSrtpParams = YES;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070057 config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES
58 srtpEnableAes128Sha1_32CryptoCipher:YES
59 srtpEnableEncryptedRtpHeaderExtensions:NO
60 sframeRequireFrameEncryption:NO];
jtteh4eeb5372017-04-03 15:06:37 -070061
62 RTCMediaConstraints *contraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@{}
63 optionalConstraints:nil];
64 RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init];
jtteh4eeb5372017-04-03 15:06:37 -070065
kthelgasonc0977102017-04-24 00:57:16 -070066 RTCConfiguration *newConfig;
67 @autoreleasepool {
68 RTCPeerConnection *peerConnection =
69 [factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil];
70 newConfig = peerConnection.configuration;
zstein03adb7c2017-08-09 14:29:42 -070071
zstein8b476172017-09-05 14:43:03 -070072 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]);
kthelgasonc0977102017-04-24 00:57:16 -070078 }
zstein03adb7c2017-08-09 14:29:42 -070079
jtteh4eeb5372017-04-03 15:06:37 -070080 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 Huangb57e1692018-06-12 11:41:11 -070099 EXPECT_EQ(config.activeResetSrtpParams, newConfig.activeResetSrtpParams);
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700100 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);
jtteh4eeb5372017-04-03 15:06:37 -0700108}
109
Jonas Oreland285f83d2020-02-07 10:30:08 +0100110- (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
jtteh4eeb5372017-04-03 15:06:37 -0700133@end
134
135TEST(RTCPeerConnectionTest, ConfigurationGetterTest) {
136 @autoreleasepool {
137 RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init];
138 [test testConfigurationGetter];
139 }
140}
Jonas Oreland285f83d2020-02-07 10:30:08 +0100141
142TEST(RTCPeerConnectionTest, TestWithDependencies) {
143 @autoreleasepool {
144 RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init];
145 [test testWithDependencies];
146 }
147}