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 |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 19 | #import "api/peerconnection/RTCPeerConnectionFactory+Native.h" |
| 20 | #import "api/peerconnection/RTCPeerConnectionFactoryBuilder+DefaultComponents.h" |
| 21 | #import "api/peerconnection/RTCPeerConnectionFactoryBuilder.h" |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 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" |
Niels Möller | a12c42a | 2018-07-25 16:05:48 +0200 | [diff] [blame] | 31 | #include "rtc_base/system/unused.h" |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 32 | |
| 33 | @interface RTCPeerConnectionFactoryBuilderTest : NSObject |
| 34 | - (void)testBuilder; |
| 35 | - (void)testDefaultComponentsBuilder; |
| 36 | @end |
| 37 | |
| 38 | @implementation RTCPeerConnectionFactoryBuilderTest |
| 39 | |
| 40 | - (void)testBuilder { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 41 | id factoryMock = OCMStrictClassMock([RTC_OBJC_TYPE(RTCPeerConnectionFactory) class]); |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 42 | OCMExpect([factoryMock alloc]).andReturn(factoryMock); |
| 43 | #ifdef HAVE_NO_MEDIA |
| 44 | RTC_UNUSED([[[factoryMock expect] andReturn:factoryMock] initWithNoMedia]); |
| 45 | #else |
| 46 | RTC_UNUSED([[[[factoryMock expect] andReturn:factoryMock] ignoringNonObjectArgs] |
| 47 | initWithNativeAudioEncoderFactory:nullptr |
| 48 | nativeAudioDecoderFactory:nullptr |
| 49 | nativeVideoEncoderFactory:nullptr |
| 50 | nativeVideoDecoderFactory:nullptr |
| 51 | audioDeviceModule:nullptr |
Niels Möller | 938bc33 | 2020-06-10 17:36:17 +0200 | [diff] [blame^] | 52 | audioProcessingModule:nullptr]); |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 53 | #endif |
| 54 | RTCPeerConnectionFactoryBuilder* builder = [[RTCPeerConnectionFactoryBuilder alloc] init]; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 55 | RTC_OBJC_TYPE(RTCPeerConnectionFactory)* peerConnectionFactory = |
| 56 | [builder createPeerConnectionFactory]; |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 57 | EXPECT_TRUE(peerConnectionFactory != nil); |
| 58 | OCMVerifyAll(factoryMock); |
| 59 | } |
| 60 | |
| 61 | - (void)testDefaultComponentsBuilder { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 62 | id factoryMock = OCMStrictClassMock([RTC_OBJC_TYPE(RTCPeerConnectionFactory) class]); |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 63 | OCMExpect([factoryMock alloc]).andReturn(factoryMock); |
| 64 | #ifdef HAVE_NO_MEDIA |
| 65 | RTC_UNUSED([[[factoryMock expect] andReturn:factoryMock] initWithNoMedia]); |
| 66 | #else |
| 67 | RTC_UNUSED([[[[factoryMock expect] andReturn:factoryMock] ignoringNonObjectArgs] |
| 68 | initWithNativeAudioEncoderFactory:nullptr |
| 69 | nativeAudioDecoderFactory:nullptr |
| 70 | nativeVideoEncoderFactory:nullptr |
| 71 | nativeVideoDecoderFactory:nullptr |
| 72 | audioDeviceModule:nullptr |
Niels Möller | 938bc33 | 2020-06-10 17:36:17 +0200 | [diff] [blame^] | 73 | audioProcessingModule:nullptr]); |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 74 | #endif |
| 75 | RTCPeerConnectionFactoryBuilder* builder = [RTCPeerConnectionFactoryBuilder defaultBuilder]; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 76 | RTC_OBJC_TYPE(RTCPeerConnectionFactory)* peerConnectionFactory = |
| 77 | [builder createPeerConnectionFactory]; |
Jiawei Ou | ae810c1 | 2018-06-20 16:18:59 -0700 | [diff] [blame] | 78 | EXPECT_TRUE(peerConnectionFactory != nil); |
| 79 | OCMVerifyAll(factoryMock); |
| 80 | } |
| 81 | @end |
| 82 | |
| 83 | TEST(RTCPeerConnectionFactoryBuilderTest, BuilderTest) { |
| 84 | @autoreleasepool { |
| 85 | RTCPeerConnectionFactoryBuilderTest* test = [[RTCPeerConnectionFactoryBuilderTest alloc] init]; |
| 86 | [test testBuilder]; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | TEST(RTCPeerConnectionFactoryBuilderTest, DefaultComponentsBuilderTest) { |
| 91 | @autoreleasepool { |
| 92 | RTCPeerConnectionFactoryBuilderTest* test = [[RTCPeerConnectionFactoryBuilderTest alloc] init]; |
| 93 | [test testDefaultComponentsBuilder]; |
| 94 | } |
| 95 | } |