Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -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 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | #import <OCMock/OCMock.h> |
| 16 | #ifdef __cplusplus |
| 17 | } |
| 18 | #endif |
| 19 | #import "sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory+Native.h" |
| 20 | #import "sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryBuilder+DefaultComponents.h" |
| 21 | #import "sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryBuilder.h" |
| 22 | |
| 23 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 24 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
| 25 | #include "api/video_codecs/video_decoder_factory.h" |
| 26 | #include "api/video_codecs/video_encoder_factory.h" |
| 27 | #include "modules/audio_device/include/audio_device.h" |
| 28 | #include "modules/audio_processing/include/audio_processing.h" |
| 29 | |
| 30 | #include "rtc_base/gunit.h" |
| 31 | |
| 32 | @interface RTCPeerConnectionFactoryBuilderTest : NSObject |
| 33 | - (void)testBuilder; |
| 34 | - (void)testDefaultComponentsBuilder; |
| 35 | @end |
| 36 | |
| 37 | @implementation RTCPeerConnectionFactoryBuilderTest |
| 38 | |
| 39 | - (void)testBuilder { |
| 40 | id factoryMock = OCMStrictClassMock([RTCPeerConnectionFactory class]); |
| 41 | OCMExpect([factoryMock alloc]).andReturn(factoryMock); |
| 42 | #ifdef HAVE_NO_MEDIA |
| 43 | RTC_UNUSED([[[factoryMock expect] andReturn:factoryMock] initWithNoMedia]); |
| 44 | #else |
| 45 | RTC_UNUSED([[[[factoryMock expect] andReturn:factoryMock] ignoringNonObjectArgs] |
| 46 | initWithNativeAudioEncoderFactory:nullptr |
| 47 | nativeAudioDecoderFactory:nullptr |
| 48 | nativeVideoEncoderFactory:nullptr |
| 49 | nativeVideoDecoderFactory:nullptr |
| 50 | audioDeviceModule:nullptr |
| 51 | audioProcessingModule:nullptr]); |
| 52 | #endif |
| 53 | RTCPeerConnectionFactoryBuilder* builder = [[RTCPeerConnectionFactoryBuilder alloc] init]; |
| 54 | RTCPeerConnectionFactory* peerConnectionFactory = [builder createPeerConnectionFactory]; |
| 55 | EXPECT_TRUE(peerConnectionFactory != nil); |
| 56 | OCMVerifyAll(factoryMock); |
| 57 | } |
| 58 | |
| 59 | - (void)testDefaultComponentsBuilder { |
| 60 | id factoryMock = OCMStrictClassMock([RTCPeerConnectionFactory class]); |
| 61 | OCMExpect([factoryMock alloc]).andReturn(factoryMock); |
| 62 | #ifdef HAVE_NO_MEDIA |
| 63 | RTC_UNUSED([[[factoryMock expect] andReturn:factoryMock] initWithNoMedia]); |
| 64 | #else |
| 65 | RTC_UNUSED([[[[factoryMock expect] andReturn:factoryMock] ignoringNonObjectArgs] |
| 66 | initWithNativeAudioEncoderFactory:nullptr |
| 67 | nativeAudioDecoderFactory:nullptr |
| 68 | nativeVideoEncoderFactory:nullptr |
| 69 | nativeVideoDecoderFactory:nullptr |
| 70 | audioDeviceModule:nullptr |
| 71 | audioProcessingModule:nullptr]); |
| 72 | #endif |
| 73 | RTCPeerConnectionFactoryBuilder* builder = [RTCPeerConnectionFactoryBuilder defaultBuilder]; |
| 74 | RTCPeerConnectionFactory* peerConnectionFactory = [builder createPeerConnectionFactory]; |
| 75 | EXPECT_TRUE(peerConnectionFactory != nil); |
| 76 | OCMVerifyAll(factoryMock); |
| 77 | } |
| 78 | @end |
| 79 | |
| 80 | TEST(RTCPeerConnectionFactoryBuilderTest, BuilderTest) { |
| 81 | @autoreleasepool { |
| 82 | RTCPeerConnectionFactoryBuilderTest* test = [[RTCPeerConnectionFactoryBuilderTest alloc] init]; |
| 83 | [test testBuilder]; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | TEST(RTCPeerConnectionFactoryBuilderTest, DefaultComponentsBuilderTest) { |
| 88 | @autoreleasepool { |
| 89 | RTCPeerConnectionFactoryBuilderTest* test = [[RTCPeerConnectionFactoryBuilderTest alloc] init]; |
| 90 | [test testDefaultComponentsBuilder]; |
| 91 | } |
| 92 | } |