Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 11 | #import "api/peerconnection/RTCAudioSource.h" |
| 12 | #import "api/peerconnection/RTCConfiguration.h" |
| 13 | #import "api/peerconnection/RTCDataChannel.h" |
| 14 | #import "api/peerconnection/RTCDataChannelConfiguration.h" |
| 15 | #import "api/peerconnection/RTCMediaConstraints.h" |
| 16 | #import "api/peerconnection/RTCMediaStreamTrack.h" |
| 17 | #import "api/peerconnection/RTCPeerConnection.h" |
| 18 | #import "api/peerconnection/RTCPeerConnectionFactory.h" |
| 19 | #import "api/peerconnection/RTCRtpReceiver.h" |
| 20 | #import "api/peerconnection/RTCRtpSender.h" |
| 21 | #import "api/peerconnection/RTCRtpTransceiver.h" |
Philipp Hancke | daec488 | 2020-09-15 10:40:07 +0200 | [diff] [blame] | 22 | #import "api/peerconnection/RTCSessionDescription.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 23 | #import "api/peerconnection/RTCVideoSource.h" |
Byoungchan Lee | 83ceb90 | 2021-11-16 11:31:57 +0900 | [diff] [blame] | 24 | #import "rtc_base/system/unused.h" |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 25 | |
| 26 | #import <XCTest/XCTest.h> |
| 27 | |
| 28 | @interface RTCPeerConnectionFactoryTests : XCTestCase |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 29 | @end |
| 30 | |
| 31 | @implementation RTCPeerConnectionFactoryTests |
| 32 | |
| 33 | - (void)testPeerConnectionLifetime { |
| 34 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 35 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 36 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 37 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 38 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 39 | optionalConstraints:nil]; |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 40 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 41 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 42 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 43 | |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 44 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 45 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 46 | peerConnection = |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 47 | [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 48 | [peerConnection close]; |
| 49 | factory = nil; |
| 50 | } |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 51 | peerConnection = nil; |
| 52 | } |
| 53 | |
| 54 | XCTAssertTrue(true, @"Expect test does not crash"); |
| 55 | } |
| 56 | |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 57 | - (void)testMediaStreamLifetime { |
| 58 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 59 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 60 | RTC_OBJC_TYPE(RTCMediaStream) * mediaStream; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 61 | |
| 62 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 63 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 64 | mediaStream = [factory mediaStreamWithStreamId:@"mediaStream"]; |
| 65 | factory = nil; |
| 66 | } |
| 67 | mediaStream = nil; |
Byoungchan Lee | 83ceb90 | 2021-11-16 11:31:57 +0900 | [diff] [blame] | 68 | RTC_UNUSED(mediaStream); |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | XCTAssertTrue(true, "Expect test does not crash"); |
| 72 | } |
| 73 | |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 74 | - (void)testDataChannelLifetime { |
| 75 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 76 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
| 77 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 78 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 79 | optionalConstraints:nil]; |
| 80 | RTC_OBJC_TYPE(RTCDataChannelConfiguration) *dataChannelConfig = |
| 81 | [[RTC_OBJC_TYPE(RTCDataChannelConfiguration) alloc] init]; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 82 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 83 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 84 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
| 85 | RTC_OBJC_TYPE(RTCDataChannel) * dataChannel; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 86 | |
| 87 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 88 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 89 | peerConnection = |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 90 | [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 91 | dataChannel = |
| 92 | [peerConnection dataChannelForLabel:@"test_channel" configuration:dataChannelConfig]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 93 | XCTAssertNotNil(dataChannel); |
Yura Yaroshevich | c75b35a | 2018-06-27 17:09:14 +0300 | [diff] [blame] | 94 | [peerConnection close]; |
| 95 | peerConnection = nil; |
| 96 | factory = nil; |
| 97 | } |
| 98 | dataChannel = nil; |
| 99 | } |
| 100 | |
| 101 | XCTAssertTrue(true, "Expect test does not crash"); |
| 102 | } |
| 103 | |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 104 | - (void)testRTCRtpTransceiverLifetime { |
| 105 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 106 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 107 | config.sdpSemantics = RTCSdpSemanticsUnifiedPlan; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 108 | RTC_OBJC_TYPE(RTCMediaConstraints) *contraints = |
| 109 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 110 | optionalConstraints:nil]; |
| 111 | RTC_OBJC_TYPE(RTCRtpTransceiverInit) *init = |
| 112 | [[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 113 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 114 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 115 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
| 116 | RTC_OBJC_TYPE(RTCRtpTransceiver) * tranceiver; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 117 | |
| 118 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 119 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 120 | peerConnection = |
| 121 | [factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil]; |
| 122 | tranceiver = [peerConnection addTransceiverOfType:RTCRtpMediaTypeAudio init:init]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 123 | XCTAssertNotNil(tranceiver); |
Yura Yaroshevich | 08f14dd | 2018-07-09 11:56:06 +0300 | [diff] [blame] | 124 | [peerConnection close]; |
| 125 | peerConnection = nil; |
| 126 | factory = nil; |
| 127 | } |
| 128 | tranceiver = nil; |
| 129 | } |
| 130 | |
| 131 | XCTAssertTrue(true, "Expect test does not crash"); |
| 132 | } |
| 133 | |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 134 | - (void)testRTCRtpSenderLifetime { |
| 135 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 136 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
Jeremy Leconte | 99d7d6b | 2022-08-19 09:29:55 +0200 | [diff] [blame] | 137 | config.sdpSemantics = RTCSdpSemanticsPlanB; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 138 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 139 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 140 | optionalConstraints:nil]; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 141 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 142 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 143 | RTC_OBJC_TYPE(RTCPeerConnection) * peerConnection; |
| 144 | RTC_OBJC_TYPE(RTCRtpSender) * sender; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 145 | |
| 146 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 147 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 148 | peerConnection = |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 149 | [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 150 | sender = [peerConnection senderWithKind:kRTCMediaStreamTrackKindVideo streamId:@"stream"]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 151 | XCTAssertNotNil(sender); |
Yura Yaroshevich | ef43aaf | 2018-07-09 19:16:32 +0300 | [diff] [blame] | 152 | [peerConnection close]; |
| 153 | peerConnection = nil; |
| 154 | factory = nil; |
| 155 | } |
| 156 | sender = nil; |
| 157 | } |
| 158 | |
| 159 | XCTAssertTrue(true, "Expect test does not crash"); |
| 160 | } |
| 161 | |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 162 | - (void)testRTCRtpReceiverLifetime { |
| 163 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 164 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
Jeremy Leconte | 99d7d6b | 2022-08-19 09:29:55 +0200 | [diff] [blame] | 165 | config.sdpSemantics = RTCSdpSemanticsPlanB; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 166 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 167 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} |
| 168 | optionalConstraints:nil]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 169 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 170 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 171 | RTC_OBJC_TYPE(RTCPeerConnection) * pc1; |
| 172 | RTC_OBJC_TYPE(RTCPeerConnection) * pc2; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 173 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 174 | NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *receivers1; |
| 175 | NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *receivers2; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 176 | |
| 177 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 178 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 179 | pc1 = [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
| 180 | [pc1 senderWithKind:kRTCMediaStreamTrackKindAudio streamId:@"stream"]; |
| 181 | |
| 182 | pc2 = [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
| 183 | [pc2 senderWithKind:kRTCMediaStreamTrackKindAudio streamId:@"stream"]; |
| 184 | |
| 185 | NSTimeInterval negotiationTimeout = 15; |
| 186 | XCTAssertTrue([self negotiatePeerConnection:pc1 |
| 187 | withPeerConnection:pc2 |
| 188 | negotiationTimeout:negotiationTimeout]); |
| 189 | |
| 190 | XCTAssertEqual(pc1.signalingState, RTCSignalingStateStable); |
| 191 | XCTAssertEqual(pc2.signalingState, RTCSignalingStateStable); |
| 192 | |
| 193 | receivers1 = pc1.receivers; |
| 194 | receivers2 = pc2.receivers; |
| 195 | XCTAssertTrue(receivers1.count > 0); |
| 196 | XCTAssertTrue(receivers2.count > 0); |
| 197 | [pc1 close]; |
| 198 | [pc2 close]; |
| 199 | pc1 = nil; |
| 200 | pc2 = nil; |
| 201 | factory = nil; |
| 202 | } |
| 203 | receivers1 = nil; |
| 204 | receivers2 = nil; |
| 205 | } |
| 206 | |
| 207 | XCTAssertTrue(true, "Expect test does not crash"); |
| 208 | } |
| 209 | |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 210 | - (void)testAudioSourceLifetime { |
| 211 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 212 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 213 | RTC_OBJC_TYPE(RTCAudioSource) * audioSource; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 214 | |
| 215 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 216 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 217 | audioSource = [factory audioSourceWithConstraints:nil]; |
| 218 | XCTAssertNotNil(audioSource); |
| 219 | factory = nil; |
| 220 | } |
| 221 | audioSource = nil; |
| 222 | } |
| 223 | |
| 224 | XCTAssertTrue(true, "Expect test does not crash"); |
| 225 | } |
| 226 | |
| 227 | - (void)testVideoSourceLifetime { |
| 228 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 229 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 230 | RTC_OBJC_TYPE(RTCVideoSource) * videoSource; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 231 | |
| 232 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 233 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 234 | videoSource = [factory videoSource]; |
| 235 | XCTAssertNotNil(videoSource); |
| 236 | factory = nil; |
| 237 | } |
| 238 | videoSource = nil; |
| 239 | } |
| 240 | |
| 241 | XCTAssertTrue(true, "Expect test does not crash"); |
| 242 | } |
| 243 | |
| 244 | - (void)testAudioTrackLifetime { |
| 245 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 246 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 247 | RTC_OBJC_TYPE(RTCAudioTrack) * audioTrack; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 248 | |
| 249 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 250 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 251 | audioTrack = [factory audioTrackWithTrackId:@"audioTrack"]; |
| 252 | XCTAssertNotNil(audioTrack); |
| 253 | factory = nil; |
| 254 | } |
| 255 | audioTrack = nil; |
| 256 | } |
| 257 | |
| 258 | XCTAssertTrue(true, "Expect test does not crash"); |
| 259 | } |
| 260 | |
| 261 | - (void)testVideoTrackLifetime { |
| 262 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 263 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 264 | RTC_OBJC_TYPE(RTCVideoTrack) * videoTrack; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 265 | |
| 266 | @autoreleasepool { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 267 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
Yura Yaroshevich | 01cee07 | 2018-07-11 15:35:40 +0300 | [diff] [blame] | 268 | videoTrack = [factory videoTrackWithSource:[factory videoSource] trackId:@"videoTrack"]; |
| 269 | XCTAssertNotNil(videoTrack); |
| 270 | factory = nil; |
| 271 | } |
| 272 | videoTrack = nil; |
| 273 | } |
| 274 | |
| 275 | XCTAssertTrue(true, "Expect test does not crash"); |
| 276 | } |
| 277 | |
Philipp Hancke | daec488 | 2020-09-15 10:40:07 +0200 | [diff] [blame] | 278 | - (void)testRollback { |
| 279 | @autoreleasepool { |
| 280 | RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; |
| 281 | config.sdpSemantics = RTCSdpSemanticsUnifiedPlan; |
| 282 | RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = |
| 283 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{ |
| 284 | kRTCMediaConstraintsOfferToReceiveAudio : kRTCMediaConstraintsValueTrue |
| 285 | } |
| 286 | optionalConstraints:nil]; |
| 287 | |
| 288 | __block RTC_OBJC_TYPE(RTCPeerConnectionFactory) * factory; |
| 289 | __block RTC_OBJC_TYPE(RTCPeerConnection) * pc1; |
| 290 | RTCSessionDescription *rollback = [[RTCSessionDescription alloc] initWithType:RTCSdpTypeRollback |
| 291 | sdp:@""]; |
| 292 | |
| 293 | @autoreleasepool { |
| 294 | factory = [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; |
| 295 | pc1 = [factory peerConnectionWithConfiguration:config constraints:constraints delegate:nil]; |
| 296 | dispatch_semaphore_t negotiatedSem = dispatch_semaphore_create(0); |
| 297 | [pc1 offerForConstraints:constraints |
| 298 | completionHandler:^(RTC_OBJC_TYPE(RTCSessionDescription) * offer, NSError * error) { |
| 299 | XCTAssertNil(error); |
| 300 | XCTAssertNotNil(offer); |
| 301 | |
| 302 | __weak RTC_OBJC_TYPE(RTCPeerConnection) *weakPC1 = pc1; |
| 303 | [pc1 setLocalDescription:offer |
| 304 | completionHandler:^(NSError *error) { |
| 305 | XCTAssertNil(error); |
| 306 | [weakPC1 setLocalDescription:rollback |
| 307 | completionHandler:^(NSError *error) { |
| 308 | XCTAssertNil(error); |
| 309 | }]; |
| 310 | }]; |
| 311 | NSTimeInterval negotiationTimeout = 15; |
| 312 | dispatch_semaphore_wait( |
| 313 | negotiatedSem, |
| 314 | dispatch_time(DISPATCH_TIME_NOW, (int64_t)(negotiationTimeout * NSEC_PER_SEC))); |
| 315 | |
| 316 | XCTAssertEqual(pc1.signalingState, RTCSignalingStateStable); |
| 317 | |
| 318 | [pc1 close]; |
| 319 | pc1 = nil; |
| 320 | factory = nil; |
| 321 | }]; |
| 322 | } |
| 323 | |
| 324 | XCTAssertTrue(true, "Expect test does not crash"); |
| 325 | } |
| 326 | } |
| 327 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 328 | - (bool)negotiatePeerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)pc1 |
| 329 | withPeerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)pc2 |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 330 | negotiationTimeout:(NSTimeInterval)timeout { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 331 | __weak RTC_OBJC_TYPE(RTCPeerConnection) *weakPC1 = pc1; |
| 332 | __weak RTC_OBJC_TYPE(RTCPeerConnection) *weakPC2 = pc2; |
| 333 | RTC_OBJC_TYPE(RTCMediaConstraints) *sdpConstraints = |
| 334 | [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{ |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 335 | kRTCMediaConstraintsOfferToReceiveAudio : kRTCMediaConstraintsValueTrue |
| 336 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 337 | optionalConstraints:nil]; |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 338 | |
| 339 | dispatch_semaphore_t negotiatedSem = dispatch_semaphore_create(0); |
| 340 | [weakPC1 offerForConstraints:sdpConstraints |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 341 | completionHandler:^(RTC_OBJC_TYPE(RTCSessionDescription) * offer, NSError * error) { |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 342 | XCTAssertNil(error); |
| 343 | XCTAssertNotNil(offer); |
| 344 | [weakPC1 |
| 345 | setLocalDescription:offer |
| 346 | completionHandler:^(NSError *error) { |
| 347 | XCTAssertNil(error); |
| 348 | [weakPC2 |
| 349 | setRemoteDescription:offer |
| 350 | completionHandler:^(NSError *error) { |
| 351 | XCTAssertNil(error); |
| 352 | [weakPC2 |
| 353 | answerForConstraints:sdpConstraints |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 354 | completionHandler:^( |
| 355 | RTC_OBJC_TYPE(RTCSessionDescription) * answer, |
| 356 | NSError * error) { |
Yura Yaroshevich | 7a16c54 | 2018-07-11 12:55:04 +0300 | [diff] [blame] | 357 | XCTAssertNil(error); |
| 358 | XCTAssertNotNil(answer); |
| 359 | [weakPC2 |
| 360 | setLocalDescription:answer |
| 361 | completionHandler:^(NSError *error) { |
| 362 | XCTAssertNil(error); |
| 363 | [weakPC1 |
| 364 | setRemoteDescription:answer |
| 365 | completionHandler:^(NSError *error) { |
| 366 | XCTAssertNil(error); |
| 367 | dispatch_semaphore_signal(negotiatedSem); |
| 368 | }]; |
| 369 | }]; |
| 370 | }]; |
| 371 | }]; |
| 372 | }]; |
| 373 | }]; |
| 374 | |
| 375 | return 0 == |
| 376 | dispatch_semaphore_wait(negotiatedSem, |
| 377 | dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC))); |
| 378 | } |
| 379 | |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 380 | @end |