blob: e45ca93a6c94d07635f87ab1d2a16812b3f87e8f [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" ];
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020037 RTC_OBJC_TYPE(RTCIceServer) *server =
38 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:urlStrings];
jtteh4eeb5372017-04-03 15:06:37 -070039
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020040 RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init];
jtteh4eeb5372017-04-03 15:06:37 -070041 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;
Qingsi Wangdea68892018-03-27 10:55:21 -070048 const int timeout = 1500;
49 const int interval = 2000;
jtteh4eeb5372017-04-03 15:06:37 -070050 config.audioJitterBufferMaxPackets = maxPackets;
51 config.audioJitterBufferFastAccelerate = YES;
52 config.iceConnectionReceivingTimeout = timeout;
53 config.iceBackupCandidatePairPingInterval = interval;
54 config.continualGatheringPolicy =
55 RTCContinualGatheringPolicyGatherContinually;
56 config.shouldPruneTurnPorts = YES;
Zhi Huangb57e1692018-06-12 11:41:11 -070057 config.activeResetSrtpParams = YES;
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020058 config.cryptoOptions =
59 [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc] initWithSrtpEnableGcmCryptoSuites:YES
60 srtpEnableAes128Sha1_32CryptoCipher:YES
61 srtpEnableEncryptedRtpHeaderExtensions:NO
62 sframeRequireFrameEncryption:NO];
jtteh4eeb5372017-04-03 15:06:37 -070063
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020064 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];
jtteh4eeb5372017-04-03 15:06:37 -070069
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020070 RTC_OBJC_TYPE(RTCConfiguration) * newConfig;
kthelgasonc0977102017-04-24 00:57:16 -070071 @autoreleasepool {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020072 RTC_OBJC_TYPE(RTCPeerConnection) *peerConnection =
kthelgasonc0977102017-04-24 00:57:16 -070073 [factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil];
74 newConfig = peerConnection.configuration;
zstein03adb7c2017-08-09 14:29:42 -070075
zstein8b476172017-09-05 14:43:03 -070076 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]);
kthelgasonc0977102017-04-24 00:57:16 -070082 }
zstein03adb7c2017-08-09 14:29:42 -070083
jtteh4eeb5372017-04-03 15:06:37 -070084 EXPECT_EQ([config.iceServers count], [newConfig.iceServers count]);
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020085 RTC_OBJC_TYPE(RTCIceServer) *newServer = newConfig.iceServers[0];
86 RTC_OBJC_TYPE(RTCIceServer) *origServer = config.iceServers[0];
jtteh4eeb5372017-04-03 15:06:37 -070087 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);
Zhi Huangb57e1692018-06-12 11:41:11 -0700103 EXPECT_EQ(config.activeResetSrtpParams, newConfig.activeResetSrtpParams);
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700104 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);
jtteh4eeb5372017-04-03 15:06:37 -0700112}
113
Jonas Oreland285f83d2020-02-07 10:30:08 +0100114- (void)testWithDependencies {
115 NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200116 RTC_OBJC_TYPE(RTCIceServer) *server =
117 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:urlStrings];
Jonas Oreland285f83d2020-02-07 10:30:08 +0100118
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200119 RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init];
Jonas Oreland285f83d2020-02-07 10:30:08 +0100120 config.iceServers = @[ server ];
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200121 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];
Jonas Oreland285f83d2020-02-07 10:30:08 +0100126
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200127 RTC_OBJC_TYPE(RTCConfiguration) * newConfig;
Jonas Oreland285f83d2020-02-07 10:30:08 +0100128 std::unique_ptr<webrtc::PeerConnectionDependencies> pc_dependencies =
129 std::make_unique<webrtc::PeerConnectionDependencies>(nullptr);
130 @autoreleasepool {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200131 RTC_OBJC_TYPE(RTCPeerConnection) *peerConnection =
Jonas Oreland285f83d2020-02-07 10:30:08 +0100132 [factory peerConnectionWithDependencies:config
133 constraints:contraints
134 dependencies:std::move(pc_dependencies)
135 delegate:nil];
136 newConfig = peerConnection.configuration;
137 }
138}
139
jtteh4eeb5372017-04-03 15:06:37 -0700140@end
141
142TEST(RTCPeerConnectionTest, ConfigurationGetterTest) {
143 @autoreleasepool {
144 RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init];
145 [test testConfigurationGetter];
146 }
147}
Jonas Oreland285f83d2020-02-07 10:30:08 +0100148
149TEST(RTCPeerConnectionTest, TestWithDependencies) {
150 @autoreleasepool {
151 RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init];
152 [test testWithDependencies];
153 }
154}