hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [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 | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #import <Foundation/Foundation.h> |
| 12 | |
| 13 | #include <vector> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 15 | #include "rtc_base/gunit.h" |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 16 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "NSString+StdString.h" |
| 18 | #import "RTCIceServer+Private.h" |
| 19 | #import "WebRTC/RTCIceServer.h" |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 20 | |
| 21 | @interface RTCIceServerTest : NSObject |
| 22 | - (void)testOneURLServer; |
| 23 | - (void)testTwoURLServer; |
| 24 | - (void)testPasswordCredential; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 25 | - (void)testInitFromNativeServer; |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [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 | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 34 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 35 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [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 | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 45 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 46 | EXPECT_EQ(2u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [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 | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 58 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 59 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [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 | dab1d2d | 2017-06-16 15:43:11 -0700 | [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 | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [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 | |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 95 | - (void)testTlsEllipticCurves { |
| 96 | RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ] |
| 97 | username:@"username" |
| 98 | credential:@"credential" |
| 99 | tlsCertPolicy:RTCTlsCertPolicySecure |
| 100 | hostname:@"hostname" |
| 101 | tlsAlpnProtocols:@[ @"proto1", @"proto2" ] |
| 102 | tlsEllipticCurves:@[ @"curve1", @"curve2" ]]; |
| 103 | webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer; |
| 104 | EXPECT_EQ(1u, iceStruct.urls.size()); |
| 105 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 106 | EXPECT_EQ("username", iceStruct.username); |
| 107 | EXPECT_EQ("credential", iceStruct.password); |
| 108 | EXPECT_EQ("hostname", iceStruct.hostname); |
| 109 | EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size()); |
| 110 | EXPECT_EQ(2u, iceStruct.tls_elliptic_curves.size()); |
| 111 | } |
| 112 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 113 | - (void)testInitFromNativeServer { |
| 114 | webrtc::PeerConnectionInterface::IceServer nativeServer; |
| 115 | nativeServer.username = "username"; |
| 116 | nativeServer.password = "password"; |
| 117 | nativeServer.urls.push_back("stun:stun.example.net"); |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 118 | nativeServer.hostname = "hostname"; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 119 | nativeServer.tls_alpn_protocols.push_back("proto1"); |
| 120 | nativeServer.tls_alpn_protocols.push_back("proto2"); |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 121 | nativeServer.tls_elliptic_curves.push_back("curve1"); |
| 122 | nativeServer.tls_elliptic_curves.push_back("curve2"); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 123 | |
| 124 | RTCIceServer *iceServer = |
| 125 | [[RTCIceServer alloc] initWithNativeServer:nativeServer]; |
| 126 | EXPECT_EQ(1u, iceServer.urlStrings.count); |
| 127 | EXPECT_EQ("stun:stun.example.net", |
| 128 | [NSString stdStringForString:iceServer.urlStrings.firstObject]); |
| 129 | EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]); |
| 130 | EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]); |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 131 | EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 132 | EXPECT_EQ(2u, iceServer.tlsAlpnProtocols.count); |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 133 | EXPECT_EQ(2u, iceServer.tlsEllipticCurves.count); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 134 | } |
| 135 | |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 136 | @end |
| 137 | |
| 138 | TEST(RTCIceServerTest, OneURLTest) { |
| 139 | @autoreleasepool { |
| 140 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 141 | [test testOneURLServer]; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | TEST(RTCIceServerTest, TwoURLTest) { |
| 146 | @autoreleasepool { |
| 147 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 148 | [test testTwoURLServer]; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | TEST(RTCIceServerTest, PasswordCredentialTest) { |
| 153 | @autoreleasepool { |
| 154 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 155 | [test testPasswordCredential]; |
| 156 | } |
| 157 | } |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 158 | |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 159 | TEST(RTCIceServerTest, HostnameTest) { |
| 160 | @autoreleasepool { |
| 161 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 162 | [test testHostname]; |
| 163 | } |
| 164 | } |
| 165 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 166 | TEST(RTCIceServerTest, InitFromNativeServerTest) { |
| 167 | @autoreleasepool { |
| 168 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 169 | [test testInitFromNativeServer]; |
| 170 | } |
| 171 | } |