diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index fb7a37cdbc..822c3c214c 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -820,6 +820,7 @@ if (is_ios || is_mac) { "objc/Framework/UnitTests/RTCDoNotPutCPlusPlusInFrameworkHeaders_xctest.m", "objc/Framework/UnitTests/RTCFileVideoCapturer_xctest.mm", "objc/Framework/UnitTests/RTCH264ProfileLevelId_xctest.m", + "objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m", "objc/Framework/UnitTests/frame_buffer_helpers.h", "objc/Framework/UnitTests/frame_buffer_helpers.mm", ] @@ -900,6 +901,7 @@ if (is_ios || is_mac) { _bundle_id_suffix = ios_generic_test_bundle_id_suffix extra_substitutions = [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ] deps = [ + ":peerconnectionfactory_base_objc", ":sdk_unittests_bundle_data", ":sdk_unittests_sources", ] diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm index 9b2462e277..c16942246c 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm @@ -240,6 +240,7 @@ void PeerConnectionDelegateAdapter::OnAddTrack( @implementation RTCPeerConnection { + RTCPeerConnectionFactory *_factory; NSMutableArray *_localStreams; std::unique_ptr _observer; rtc::scoped_refptr _peerConnection; @@ -272,6 +273,7 @@ void PeerConnectionDelegateAdapter::OnAddTrack( if (!_peerConnection) { return nil; } + _factory = factory; _localStreams = [[NSMutableArray alloc] init]; _delegate = delegate; } diff --git a/sdk/objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m b/sdk/objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m new file mode 100644 index 0000000000..1c678d64a2 --- /dev/null +++ b/sdk/objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m @@ -0,0 +1,45 @@ +/* + * Copyright 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import +#import +#import +#import + +#import + +@interface RTCPeerConnectionFactoryTests : XCTestCase +- (void)testPeerConnectionLifetime; +@end + +@implementation RTCPeerConnectionFactoryTests + +- (void)testPeerConnectionLifetime { + @autoreleasepool { + RTCConfiguration *config = [[RTCConfiguration alloc] init]; + + RTCMediaConstraints *contraints = + [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@{} optionalConstraints:nil]; + + RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init]; + + RTCPeerConnection *peerConnection = + [factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil]; + + [peerConnection close]; + + factory = nil; + peerConnection = nil; + } + + XCTAssertTrue(true, @"Expect test does not crash"); +} + +@end