blob: 5dbb92f16d5c8ba4aed2b8aba54b5d256487cc8c [file] [log] [blame]
hjonaa32c3e2015-12-13 19:58:11 -08001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
hjonaa32c3e2015-12-13 19:58:11 -08003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
hjonaa32c3e2015-12-13 19:58:11 -08009 */
10
11#import <Foundation/Foundation.h>
12
13#include <vector>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/gunit.h"
hjonaa32c3e2015-12-13 19:58:11 -080016
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020017#import "api/peerconnection/RTCIceServer+Private.h"
18#import "api/peerconnection/RTCIceServer.h"
19#import "helpers/NSString+StdString.h"
hjonaa32c3e2015-12-13 19:58:11 -080020
21@interface RTCIceServerTest : NSObject
22- (void)testOneURLServer;
23- (void)testTwoURLServer;
24- (void)testPasswordCredential;
hjon6d49a8e2016-01-26 13:06:42 -080025- (void)testInitFromNativeServer;
hjonaa32c3e2015-12-13 19:58:11 -080026@end
27
28@implementation RTCIceServerTest
29
30- (void)testOneURLServer {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020031 RTC_OBJC_TYPE(RTCIceServer) *server =
32 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"stun:stun1.example.net" ]];
hjonaa32c3e2015-12-13 19:58:11 -080033
hjona2f77982016-03-04 07:09:09 -080034 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
hjon6d49a8e2016-01-26 13:06:42 -080035 EXPECT_EQ(1u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080036 EXPECT_EQ("stun:stun1.example.net", iceStruct.urls.front());
37 EXPECT_EQ("", iceStruct.username);
38 EXPECT_EQ("", iceStruct.password);
39}
40
41- (void)testTwoURLServer {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020042 RTC_OBJC_TYPE(RTCIceServer) *server = [[RTC_OBJC_TYPE(RTCIceServer) alloc]
43 initWithURLStrings:@[ @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]];
hjonaa32c3e2015-12-13 19:58:11 -080044
hjona2f77982016-03-04 07:09:09 -080045 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
hjon6d49a8e2016-01-26 13:06:42 -080046 EXPECT_EQ(2u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080047 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
48 EXPECT_EQ("turn2:turn2.example.net", iceStruct.urls.back());
49 EXPECT_EQ("", iceStruct.username);
50 EXPECT_EQ("", iceStruct.password);
51}
52
53- (void)testPasswordCredential {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020054 RTC_OBJC_TYPE(RTCIceServer) *server =
55 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
56 username:@"username"
57 credential:@"credential"];
hjona2f77982016-03-04 07:09:09 -080058 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
hjon6d49a8e2016-01-26 13:06:42 -080059 EXPECT_EQ(1u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080060 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
61 EXPECT_EQ("username", iceStruct.username);
62 EXPECT_EQ("credential", iceStruct.password);
63}
64
Emad Omaradab1d2d2017-06-16 15:43:11 -070065- (void)testHostname {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020066 RTC_OBJC_TYPE(RTCIceServer) *server =
67 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
68 username:@"username"
69 credential:@"credential"
70 tlsCertPolicy:RTCTlsCertPolicySecure
71 hostname:@"hostname"];
Emad Omaradab1d2d2017-06-16 15:43:11 -070072 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
73 EXPECT_EQ(1u, iceStruct.urls.size());
74 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
75 EXPECT_EQ("username", iceStruct.username);
76 EXPECT_EQ("credential", iceStruct.password);
77 EXPECT_EQ("hostname", iceStruct.hostname);
78}
79
Diogo Real1dca9d52017-08-29 12:18:32 -070080- (void)testTlsAlpnProtocols {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020081 RTC_OBJC_TYPE(RTCIceServer) *server =
82 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
83 username:@"username"
84 credential:@"credential"
85 tlsCertPolicy:RTCTlsCertPolicySecure
86 hostname:@"hostname"
87 tlsAlpnProtocols:@[ @"proto1", @"proto2" ]];
Diogo Real1dca9d52017-08-29 12:18:32 -070088 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
89 EXPECT_EQ(1u, iceStruct.urls.size());
90 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
91 EXPECT_EQ("username", iceStruct.username);
92 EXPECT_EQ("credential", iceStruct.password);
93 EXPECT_EQ("hostname", iceStruct.hostname);
Sergey Silkin9c147dd2018-09-12 10:45:38 +000094 EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size());
Diogo Real1dca9d52017-08-29 12:18:32 -070095}
96
Diogo Real7bd1f1b2017-09-08 12:50:41 -070097- (void)testTlsEllipticCurves {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020098 RTC_OBJC_TYPE(RTCIceServer) *server =
99 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
100 username:@"username"
101 credential:@"credential"
102 tlsCertPolicy:RTCTlsCertPolicySecure
103 hostname:@"hostname"
104 tlsAlpnProtocols:@[ @"proto1", @"proto2" ]
105 tlsEllipticCurves:@[ @"curve1", @"curve2" ]];
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700106 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
107 EXPECT_EQ(1u, iceStruct.urls.size());
108 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
109 EXPECT_EQ("username", iceStruct.username);
110 EXPECT_EQ("credential", iceStruct.password);
111 EXPECT_EQ("hostname", iceStruct.hostname);
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000112 EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size());
113 EXPECT_EQ(2u, iceStruct.tls_elliptic_curves.size());
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700114}
115
hjon6d49a8e2016-01-26 13:06:42 -0800116- (void)testInitFromNativeServer {
117 webrtc::PeerConnectionInterface::IceServer nativeServer;
118 nativeServer.username = "username";
119 nativeServer.password = "password";
120 nativeServer.urls.push_back("stun:stun.example.net");
Emad Omaradab1d2d2017-06-16 15:43:11 -0700121 nativeServer.hostname = "hostname";
Diogo Real1dca9d52017-08-29 12:18:32 -0700122 nativeServer.tls_alpn_protocols.push_back("proto1");
123 nativeServer.tls_alpn_protocols.push_back("proto2");
Diogo Real7bd1f1b2017-09-08 12:50:41 -0700124 nativeServer.tls_elliptic_curves.push_back("curve1");
125 nativeServer.tls_elliptic_curves.push_back("curve2");
hjon6d49a8e2016-01-26 13:06:42 -0800126
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200127 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
128 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:nativeServer];
hjon6d49a8e2016-01-26 13:06:42 -0800129 EXPECT_EQ(1u, iceServer.urlStrings.count);
130 EXPECT_EQ("stun:stun.example.net",
131 [NSString stdStringForString:iceServer.urlStrings.firstObject]);
132 EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]);
133 EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]);
Emad Omaradab1d2d2017-06-16 15:43:11 -0700134 EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]);
Sergey Silkin9c147dd2018-09-12 10:45:38 +0000135 EXPECT_EQ(2u, iceServer.tlsAlpnProtocols.count);
136 EXPECT_EQ(2u, iceServer.tlsEllipticCurves.count);
hjon6d49a8e2016-01-26 13:06:42 -0800137}
138
hjonaa32c3e2015-12-13 19:58:11 -0800139@end
140
141TEST(RTCIceServerTest, OneURLTest) {
142 @autoreleasepool {
143 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
144 [test testOneURLServer];
145 }
146}
147
148TEST(RTCIceServerTest, TwoURLTest) {
149 @autoreleasepool {
150 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
151 [test testTwoURLServer];
152 }
153}
154
155TEST(RTCIceServerTest, PasswordCredentialTest) {
156 @autoreleasepool {
157 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
158 [test testPasswordCredential];
159 }
160}
hjon6d49a8e2016-01-26 13:06:42 -0800161
Emad Omaradab1d2d2017-06-16 15:43:11 -0700162TEST(RTCIceServerTest, HostnameTest) {
163 @autoreleasepool {
164 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
165 [test testHostname];
166 }
167}
168
hjon6d49a8e2016-01-26 13:06:42 -0800169TEST(RTCIceServerTest, InitFromNativeServerTest) {
170 @autoreleasepool {
171 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
172 [test testInitFromNativeServer];
173 }
174}