OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import <Foundation/Foundation.h> | 11 #import <Foundation/Foundation.h> |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
16 | 16 |
17 #import "webrtc/api/objc/RTCConfiguration.h" | 17 #import "webrtc/api/objc/RTCConfiguration.h" |
18 #import "webrtc/api/objc/RTCConfiguration+Private.h" | 18 #import "webrtc/api/objc/RTCConfiguration+Private.h" |
19 #import "webrtc/api/objc/RTCIceServer.h" | 19 #import "webrtc/api/objc/RTCIceServer.h" |
20 #import "webrtc/base/objc/NSString+StdString.h" | 20 #import "webrtc/base/objc/NSString+StdString.h" |
21 | 21 |
22 @interface RTCConfigurationTest : NSObject | 22 @interface RTCConfigurationTest : NSObject |
23 - (void)testConversionToNativeConfiguration; | 23 - (void)testConversionToNativeConfiguration; |
24 - (void)testInitFromNativeConfiguration; | |
25 @end | 24 @end |
26 | 25 |
27 @implementation RTCConfigurationTest | 26 @implementation RTCConfigurationTest |
28 | 27 |
29 - (void)testConversionToNativeConfiguration { | 28 - (void)testConversionToNativeConfiguration { |
30 NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; | 29 NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; |
31 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; | 30 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings]; |
32 | 31 |
33 RTCConfiguration *config = | 32 RTCConfiguration *config = [[RTCConfiguration alloc] init]; |
34 [[RTCConfiguration alloc] initWithIceServers:@[ server ] | 33 config.iceServers = @[ server ]; |
35 iceTransportPolicy:RTCIceTransportPolicyRelay | 34 config.iceTransportPolicy = RTCIceTransportPolicyRelay; |
36 bundlePolicy:RTCBundlePolicyMaxBundle | 35 config.bundlePolicy = RTCBundlePolicyMaxBundle; |
37 rtcpMuxPolicy:RTCRtcpMuxPolicyNegotiate | 36 config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate; |
38 tcpCandidatePolicy:RTCTcpCandidatePolicyDisabled | 37 config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled; |
39 audioJitterBufferMaxPackets:60 | 38 const int maxPackets = 60; |
40 iceConnectionReceivingTimeout:1 | 39 const int timeout = 1; |
41 iceBackupCandidatePairPingInterval:2]; | 40 const int interval = 2; |
| 41 config.audioJitterBufferMaxPackets = maxPackets; |
| 42 config.iceConnectionReceivingTimeout = timeout; |
| 43 config.iceBackupCandidatePairPingInterval = interval; |
42 | 44 |
43 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig = | 45 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig = |
44 config.nativeConfiguration; | 46 config.nativeConfiguration; |
45 EXPECT_EQ(1u, nativeConfig.servers.size()); | 47 EXPECT_EQ(1u, nativeConfig.servers.size()); |
46 webrtc::PeerConnectionInterface::IceServer nativeServer = | 48 webrtc::PeerConnectionInterface::IceServer nativeServer = |
47 nativeConfig.servers.front(); | 49 nativeConfig.servers.front(); |
48 EXPECT_EQ(1u, nativeServer.urls.size()); | 50 EXPECT_EQ(1u, nativeServer.urls.size()); |
49 EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front()); | 51 EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front()); |
50 | 52 |
51 EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig.type); | 53 EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig.type); |
52 EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle, | 54 EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle, |
53 nativeConfig.bundle_policy); | 55 nativeConfig.bundle_policy); |
54 EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate, | 56 EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
55 nativeConfig.rtcp_mux_policy); | 57 nativeConfig.rtcp_mux_policy); |
56 EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled, | 58 EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled, |
57 nativeConfig.tcp_candidate_policy); | 59 nativeConfig.tcp_candidate_policy); |
58 EXPECT_EQ(60, nativeConfig.audio_jitter_buffer_max_packets); | 60 EXPECT_EQ(maxPackets, nativeConfig.audio_jitter_buffer_max_packets); |
59 EXPECT_EQ(1, nativeConfig.ice_connection_receiving_timeout); | 61 EXPECT_EQ(timeout, nativeConfig.ice_connection_receiving_timeout); |
60 EXPECT_EQ(2, nativeConfig.ice_backup_candidate_pair_ping_interval); | 62 EXPECT_EQ(interval, nativeConfig.ice_backup_candidate_pair_ping_interval); |
61 } | |
62 | |
63 - (void)testInitFromNativeConfiguration { | |
64 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig; | |
65 | |
66 webrtc::PeerConnectionInterface::IceServer nativeServer; | |
67 nativeServer.username = "username"; | |
68 nativeServer.password = "password"; | |
69 nativeServer.urls.push_back("stun:stun.example.net"); | |
70 webrtc::PeerConnectionInterface::IceServers servers { nativeServer }; | |
71 | |
72 nativeConfig.servers = servers; | |
73 nativeConfig.type = webrtc::PeerConnectionInterface::kNoHost; | |
74 nativeConfig.bundle_policy = | |
75 webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; | |
76 nativeConfig.rtcp_mux_policy = | |
77 webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; | |
78 nativeConfig.tcp_candidate_policy = | |
79 webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled; | |
80 nativeConfig.audio_jitter_buffer_max_packets = 40; | |
81 nativeConfig.ice_connection_receiving_timeout = | |
82 webrtc::PeerConnectionInterface::RTCConfiguration::kUndefined; | |
83 nativeConfig.ice_backup_candidate_pair_ping_interval = | |
84 webrtc::PeerConnectionInterface::RTCConfiguration::kUndefined; | |
85 | |
86 RTCConfiguration *config = | |
87 [[RTCConfiguration alloc] initWithNativeConfiguration:nativeConfig]; | |
88 | |
89 EXPECT_EQ(1u, config.iceServers.count); | |
90 RTCIceServer *server = config.iceServers.firstObject; | |
91 EXPECT_EQ(1u, server.urlStrings.count); | |
92 EXPECT_TRUE([@"stun:stun.example.net" isEqualToString: | |
93 server.urlStrings.firstObject]); | |
94 | |
95 EXPECT_EQ(RTCIceTransportPolicyNoHost, config.iceTransportPolicy); | |
96 EXPECT_EQ(RTCBundlePolicyMaxCompat, config.bundlePolicy); | |
97 EXPECT_EQ(RTCRtcpMuxPolicyRequire, config.rtcpMuxPolicy); | |
98 EXPECT_EQ(RTCTcpCandidatePolicyEnabled, config.tcpCandidatePolicy); | |
99 EXPECT_EQ(40, config.audioJitterBufferMaxPackets); | |
100 EXPECT_EQ(-1, config.iceConnectionReceivingTimeout); | |
101 EXPECT_EQ(-1, config.iceBackupCandidatePairPingInterval); | |
102 } | 63 } |
103 | 64 |
104 @end | 65 @end |
105 | 66 |
106 TEST(RTCConfigurationTest, NativeConfigurationConversionTest) { | 67 TEST(RTCConfigurationTest, NativeConfigurationConversionTest) { |
107 @autoreleasepool { | 68 @autoreleasepool { |
108 RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init]; | 69 RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init]; |
109 [test testConversionToNativeConfiguration]; | 70 [test testConversionToNativeConfiguration]; |
110 } | 71 } |
111 } | 72 } |
112 | 73 |
113 TEST(RTCConfigurationTest, InitFromConfigurationTest) { | |
114 @autoreleasepool { | |
115 RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init]; | |
116 [test testInitFromNativeConfiguration]; | |
117 } | |
118 } | |
OLD | NEW |