blob: bff7cb0b946c0b9273c6d37a795de70135e27383 [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
15#include "webrtc/base/gunit.h"
16
tkchin9eeb6242016-04-27 01:54:20 -070017#import "NSString+StdString.h"
18#import "RTCIceServer+Private.h"
19#import "WebRTC/RTCIceServer.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 {
31 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
32 @"stun:stun1.example.net" ]];
33
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 {
42 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
43 @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]];
44
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 {
54 RTCIceServer *server = [[RTCIceServer alloc]
55 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 {
66 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
67 username:@"username"
68 credential:@"credential"
69 tlsCertPolicy:RTCTlsCertPolicySecure
70 hostname:@"hostname"];
71 webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
72 EXPECT_EQ(1u, iceStruct.urls.size());
73 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
74 EXPECT_EQ("username", iceStruct.username);
75 EXPECT_EQ("credential", iceStruct.password);
76 EXPECT_EQ("hostname", iceStruct.hostname);
77}
78
hjon6d49a8e2016-01-26 13:06:42 -080079- (void)testInitFromNativeServer {
80 webrtc::PeerConnectionInterface::IceServer nativeServer;
81 nativeServer.username = "username";
82 nativeServer.password = "password";
83 nativeServer.urls.push_back("stun:stun.example.net");
Emad Omaradab1d2d2017-06-16 15:43:11 -070084 nativeServer.hostname = "hostname";
hjon6d49a8e2016-01-26 13:06:42 -080085
86 RTCIceServer *iceServer =
87 [[RTCIceServer alloc] initWithNativeServer:nativeServer];
88 EXPECT_EQ(1u, iceServer.urlStrings.count);
89 EXPECT_EQ("stun:stun.example.net",
90 [NSString stdStringForString:iceServer.urlStrings.firstObject]);
91 EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]);
92 EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]);
Emad Omaradab1d2d2017-06-16 15:43:11 -070093 EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]);
hjon6d49a8e2016-01-26 13:06:42 -080094}
95
hjonaa32c3e2015-12-13 19:58:11 -080096@end
97
98TEST(RTCIceServerTest, OneURLTest) {
99 @autoreleasepool {
100 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
101 [test testOneURLServer];
102 }
103}
104
105TEST(RTCIceServerTest, TwoURLTest) {
106 @autoreleasepool {
107 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
108 [test testTwoURLServer];
109 }
110}
111
112TEST(RTCIceServerTest, PasswordCredentialTest) {
113 @autoreleasepool {
114 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
115 [test testPasswordCredential];
116 }
117}
hjon6d49a8e2016-01-26 13:06:42 -0800118
Emad Omaradab1d2d2017-06-16 15:43:11 -0700119TEST(RTCIceServerTest, HostnameTest) {
120 @autoreleasepool {
121 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
122 [test testHostname];
123 }
124}
125
hjon6d49a8e2016-01-26 13:06:42 -0800126TEST(RTCIceServerTest, InitFromNativeServerTest) {
127 @autoreleasepool {
128 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
129 [test testInitFromNativeServer];
130 }
131}