blob: 1ddb13c20e2fad230b0e655bc9e0f614049ae1c6 [file] [log] [blame]
hjonaa32c3e2015-12-13 19:58:11 -08001/*
Henrik Kjellander15583c12016-02-10 10:53:12 +01002 * libjingle
3 * Copyright 2015 Google Inc.
hjonaa32c3e2015-12-13 19:58:11 -08004 *
Henrik Kjellander15583c12016-02-10 10:53:12 +01005 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
hjonaa32c3e2015-12-13 19:58:11 -080026 */
27
28#import <Foundation/Foundation.h>
29
30#include <vector>
31
32#include "webrtc/base/gunit.h"
33
34#import "webrtc/api/objc/RTCIceServer.h"
35#import "webrtc/api/objc/RTCIceServer+Private.h"
hjon6d49a8e2016-01-26 13:06:42 -080036#import "webrtc/base/objc/NSString+StdString.h"
hjonaa32c3e2015-12-13 19:58:11 -080037
38@interface RTCIceServerTest : NSObject
39- (void)testOneURLServer;
40- (void)testTwoURLServer;
41- (void)testPasswordCredential;
hjon6d49a8e2016-01-26 13:06:42 -080042- (void)testInitFromNativeServer;
hjonaa32c3e2015-12-13 19:58:11 -080043@end
44
45@implementation RTCIceServerTest
46
47- (void)testOneURLServer {
48 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
49 @"stun:stun1.example.net" ]];
50
51 webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
hjon6d49a8e2016-01-26 13:06:42 -080052 EXPECT_EQ(1u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080053 EXPECT_EQ("stun:stun1.example.net", iceStruct.urls.front());
54 EXPECT_EQ("", iceStruct.username);
55 EXPECT_EQ("", iceStruct.password);
56}
57
58- (void)testTwoURLServer {
59 RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
60 @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]];
61
62 webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
hjon6d49a8e2016-01-26 13:06:42 -080063 EXPECT_EQ(2u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080064 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
65 EXPECT_EQ("turn2:turn2.example.net", iceStruct.urls.back());
66 EXPECT_EQ("", iceStruct.username);
67 EXPECT_EQ("", iceStruct.password);
68}
69
70- (void)testPasswordCredential {
71 RTCIceServer *server = [[RTCIceServer alloc]
72 initWithURLStrings:@[ @"turn1:turn1.example.net" ]
73 username:@"username"
74 credential:@"credential"];
75 webrtc::PeerConnectionInterface::IceServer iceStruct = server.iceServer;
hjon6d49a8e2016-01-26 13:06:42 -080076 EXPECT_EQ(1u, iceStruct.urls.size());
hjonaa32c3e2015-12-13 19:58:11 -080077 EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
78 EXPECT_EQ("username", iceStruct.username);
79 EXPECT_EQ("credential", iceStruct.password);
80}
81
hjon6d49a8e2016-01-26 13:06:42 -080082- (void)testInitFromNativeServer {
83 webrtc::PeerConnectionInterface::IceServer nativeServer;
84 nativeServer.username = "username";
85 nativeServer.password = "password";
86 nativeServer.urls.push_back("stun:stun.example.net");
87
88 RTCIceServer *iceServer =
89 [[RTCIceServer alloc] initWithNativeServer:nativeServer];
90 EXPECT_EQ(1u, iceServer.urlStrings.count);
91 EXPECT_EQ("stun:stun.example.net",
92 [NSString stdStringForString:iceServer.urlStrings.firstObject]);
93 EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]);
94 EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]);
95}
96
hjonaa32c3e2015-12-13 19:58:11 -080097@end
98
99TEST(RTCIceServerTest, OneURLTest) {
100 @autoreleasepool {
101 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
102 [test testOneURLServer];
103 }
104}
105
106TEST(RTCIceServerTest, TwoURLTest) {
107 @autoreleasepool {
108 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
109 [test testTwoURLServer];
110 }
111}
112
113TEST(RTCIceServerTest, PasswordCredentialTest) {
114 @autoreleasepool {
115 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
116 [test testPasswordCredential];
117 }
118}
hjon6d49a8e2016-01-26 13:06:42 -0800119
120TEST(RTCIceServerTest, InitFromNativeServerTest) {
121 @autoreleasepool {
122 RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
123 [test testInitFromNativeServer];
124 }
125}