hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 1 | /* |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 2 | * libjingle |
| 3 | * Copyright 2015 Google Inc. |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 4 | * |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 5 | * 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. |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 26 | */ |
| 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" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 36 | #import "webrtc/base/objc/NSString+StdString.h" |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 37 | |
| 38 | @interface RTCIceServerTest : NSObject |
| 39 | - (void)testOneURLServer; |
| 40 | - (void)testTwoURLServer; |
| 41 | - (void)testPasswordCredential; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 42 | - (void)testInitFromNativeServer; |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 43 | @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; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 52 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 53 | 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; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 63 | EXPECT_EQ(2u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 64 | 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; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 76 | EXPECT_EQ(1u, iceStruct.urls.size()); |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 77 | EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front()); |
| 78 | EXPECT_EQ("username", iceStruct.username); |
| 79 | EXPECT_EQ("credential", iceStruct.password); |
| 80 | } |
| 81 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 82 | - (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 | |
hjon | aa32c3e | 2015-12-13 19:58:11 -0800 | [diff] [blame] | 97 | @end |
| 98 | |
| 99 | TEST(RTCIceServerTest, OneURLTest) { |
| 100 | @autoreleasepool { |
| 101 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 102 | [test testOneURLServer]; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | TEST(RTCIceServerTest, TwoURLTest) { |
| 107 | @autoreleasepool { |
| 108 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 109 | [test testTwoURLServer]; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | TEST(RTCIceServerTest, PasswordCredentialTest) { |
| 114 | @autoreleasepool { |
| 115 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 116 | [test testPasswordCredential]; |
| 117 | } |
| 118 | } |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 119 | |
| 120 | TEST(RTCIceServerTest, InitFromNativeServerTest) { |
| 121 | @autoreleasepool { |
| 122 | RTCIceServerTest *test = [[RTCIceServerTest alloc] init]; |
| 123 | [test testInitFromNativeServer]; |
| 124 | } |
| 125 | } |