blob: 14131dc38d3fcb765cfa229547e4231489859f4c [file] [log] [blame]
Jiawei Ouae810c12018-06-20 16:18:59 -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#ifdef __cplusplus
13extern "C" {
14#endif
15#import <OCMock/OCMock.h>
16#ifdef __cplusplus
17}
18#endif
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020019#import "api/peerconnection/RTCPeerConnectionFactory+Native.h"
20#import "api/peerconnection/RTCPeerConnectionFactoryBuilder+DefaultComponents.h"
21#import "api/peerconnection/RTCPeerConnectionFactoryBuilder.h"
Jiawei Ouae810c12018-06-20 16:18:59 -070022
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öllera12c42a2018-07-25 16:05:48 +020031#include "rtc_base/system/unused.h"
Jiawei Ouae810c12018-06-20 16:18:59 -070032
33@interface RTCPeerConnectionFactoryBuilderTest : NSObject
34- (void)testBuilder;
35- (void)testDefaultComponentsBuilder;
36@end
37
38@implementation RTCPeerConnectionFactoryBuilderTest
39
40- (void)testBuilder {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020041 id factoryMock = OCMStrictClassMock([RTC_OBJC_TYPE(RTCPeerConnectionFactory) class]);
Jiawei Ouae810c12018-06-20 16:18:59 -070042 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öller938bc332020-06-10 17:36:17 +020052 audioProcessingModule:nullptr]);
Jiawei Ouae810c12018-06-20 16:18:59 -070053#endif
54 RTCPeerConnectionFactoryBuilder* builder = [[RTCPeerConnectionFactoryBuilder alloc] init];
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020055 RTC_OBJC_TYPE(RTCPeerConnectionFactory)* peerConnectionFactory =
56 [builder createPeerConnectionFactory];
Jiawei Ouae810c12018-06-20 16:18:59 -070057 EXPECT_TRUE(peerConnectionFactory != nil);
58 OCMVerifyAll(factoryMock);
59}
60
61- (void)testDefaultComponentsBuilder {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020062 id factoryMock = OCMStrictClassMock([RTC_OBJC_TYPE(RTCPeerConnectionFactory) class]);
Jiawei Ouae810c12018-06-20 16:18:59 -070063 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öller938bc332020-06-10 17:36:17 +020073 audioProcessingModule:nullptr]);
Jiawei Ouae810c12018-06-20 16:18:59 -070074#endif
75 RTCPeerConnectionFactoryBuilder* builder = [RTCPeerConnectionFactoryBuilder defaultBuilder];
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020076 RTC_OBJC_TYPE(RTCPeerConnectionFactory)* peerConnectionFactory =
77 [builder createPeerConnectionFactory];
Jiawei Ouae810c12018-06-20 16:18:59 -070078 EXPECT_TRUE(peerConnectionFactory != nil);
79 OCMVerifyAll(factoryMock);
80}
81@end
82
83TEST(RTCPeerConnectionFactoryBuilderTest, BuilderTest) {
84 @autoreleasepool {
85 RTCPeerConnectionFactoryBuilderTest* test = [[RTCPeerConnectionFactoryBuilderTest alloc] init];
86 [test testBuilder];
87 }
88}
89
90TEST(RTCPeerConnectionFactoryBuilderTest, DefaultComponentsBuilderTest) {
91 @autoreleasepool {
92 RTCPeerConnectionFactoryBuilderTest* test = [[RTCPeerConnectionFactoryBuilderTest alloc] init];
93 [test testDefaultComponentsBuilder];
94 }
95}