hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 1 | /* |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 3 | * |
kjellander | 95ed4e6 | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #import <Foundation/Foundation.h> |
| 12 | |
| 13 | #include <vector> |
| 14 | |
ehmaldonado | 91b122b | 2017-07-07 10:09:51 | [diff] [blame] | 15 | #include "webrtc/rtc_base/gunit.h" |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 16 | |
tkchin | 09716bd | 2016-04-27 08:54:20 | [diff] [blame] | 17 | #import "NSString+StdString.h" |
| 18 | #import "RTCIceServer+Private.h" |
| 19 | #import "WebRTC/RTCIceServer.h" |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 20 | |
| 21 | @interface RTCIceServerTest : NSObject |
| 22 | - (void)testOneURLServer; |
| 23 | - (void)testTwoURLServer; |
| 24 | - (void)testPasswordCredential; |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 25 | - (void)testInitFromNativeServer; |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 26 | @end |
| 27 | |
| 28 | @implementation RTCIceServerTest |
| 29 | |
| 30 | - (void)testOneURLServer { |
| 31 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ |
| 32 | @"stun:stun1.example.net" ]]; |
| 33 | |
hjon | 3e6cfcd | 2016-03-04 15:09:09 | [diff] [blame] | 34 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 35 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 36 | 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 | |
hjon | 3e6cfcd | 2016-03-04 15:09:09 | [diff] [blame] | 45 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 46 | EXPECT_EQ(2u, iceStruct.urls.size()); |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 47 | 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"]; |
hjon | 3e6cfcd | 2016-03-04 15:09:09 | [diff] [blame] | 58 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 59 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 60 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 61 | EXPECT_EQ("username", iceStruct.username); |
| 62 | EXPECT_EQ("credential", iceStruct.password); |
| 63 | } |
| 64 | |
Emad Omara | 8c18d91 | 2017-06-16 22:43:11 | [diff] [blame] | 65 | - (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 | |
Diogo Real | adaf22f | 2017-08-29 19:18:32 | [diff] [blame] | 79 | - (void)testTlsAlpnProtocols { |
| 80 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ] |
| 81 | username:@"username" |
| 82 | credential:@"credential" |
| 83 | tlsCertPolicy:RTCTlsCertPolicySecure |
| 84 | hostname:@"hostname" |
| 85 | tlsAlpnProtocols:@[ @"proto1", @"proto2" ]]; |
| 86 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
| 87 | EXPECT_EQ(1u, iceStruct.urls.size()); |
| 88 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 89 | EXPECT_EQ("username", iceStruct.username); |
| 90 | EXPECT_EQ("credential", iceStruct.password); |
| 91 | EXPECT_EQ("hostname", iceStruct.hostname); |
| 92 | EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size()); |
| 93 | } |
| 94 | |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 95 | - (void)testInitFromNativeServer { |
| 96 | webrtc::PeerConnectionInterface::IceServer nativeServer; |
| 97 | nativeServer.username = "username"; |
| 98 | nativeServer.password = "password"; |
| 99 | nativeServer.urls.push_back("stun:stun.example.net"); |
Emad Omara | 8c18d91 | 2017-06-16 22:43:11 | [diff] [blame] | 100 | nativeServer.hostname = "hostname"; |
Diogo Real | adaf22f | 2017-08-29 19:18:32 | [diff] [blame] | 101 | nativeServer.tls_alpn_protocols.push_back("proto1"); |
| 102 | nativeServer.tls_alpn_protocols.push_back("proto2"); |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 103 | |
| 104 | RTCIceServer *iceServer = |
| 105 | [[RTCIceServer alloc] initWithNativeServer:nativeServer]; |
| 106 | EXPECT_EQ(1u, iceServer.urlStrings.count); |
| 107 | EXPECT_EQ("stun:stun.example.net", |
| 108 | [NSString stdStringForString:iceServer.urlStrings.firstObject]); |
| 109 | EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]); |
| 110 | EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]); |
Emad Omara | 8c18d91 | 2017-06-16 22:43:11 | [diff] [blame] | 111 | EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]); |
Diogo Real | adaf22f | 2017-08-29 19:18:32 | [diff] [blame] | 112 | EXPECT_EQ(2u, iceServer.tlsAlpnProtocols.count); |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 113 | } |
| 114 | |
hjon | da83020 | 2015-12-14 03:58:11 | [diff] [blame] | 115 | @end |
| 116 | |
| 117 | TEST(RTCIceServerTest, OneURLTest) { |
| 118 | @autoreleasepool { |
| 119 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 120 | [test testOneURLServer]; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | TEST(RTCIceServerTest, TwoURLTest) { |
| 125 | @autoreleasepool { |
| 126 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 127 | [test testTwoURLServer]; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | TEST(RTCIceServerTest, PasswordCredentialTest) { |
| 132 | @autoreleasepool { |
| 133 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 134 | [test testPasswordCredential]; |
| 135 | } |
| 136 | } |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 137 | |
Emad Omara | 8c18d91 | 2017-06-16 22:43:11 | [diff] [blame] | 138 | TEST(RTCIceServerTest, HostnameTest) { |
| 139 | @autoreleasepool { |
| 140 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 141 | [test testHostname]; |
| 142 | } |
| 143 | } |
| 144 | |
hjon | df0d2fc | 2016-01-26 21:06:42 | [diff] [blame] | 145 | TEST(RTCIceServerTest, InitFromNativeServerTest) { |
| 146 | @autoreleasepool { |
| 147 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 148 | [test testInitFromNativeServer]; |
| 149 | } |
| 150 | } |