You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
6.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2015 The WebRTC project authors. All Rights Reserved.
  3. *
  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.
  9. */
  10. #import <Foundation/Foundation.h>
  11. #include <vector>
  12. #include "rtc_base/gunit.h"
  13. #import "api/peerconnection/RTCIceServer+Private.h"
  14. #import "api/peerconnection/RTCIceServer.h"
  15. #import "helpers/NSString+StdString.h"
  16. @interface RTCIceServerTest : NSObject
  17. - (void)testOneURLServer;
  18. - (void)testTwoURLServer;
  19. - (void)testPasswordCredential;
  20. - (void)testInitFromNativeServer;
  21. @end
  22. @implementation RTCIceServerTest
  23. - (void)testOneURLServer {
  24. RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
  25. @"stun:stun1.example.net" ]];
  26. webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
  27. EXPECT_EQ(1u, iceStruct.urls.size());
  28. EXPECT_EQ("stun:stun1.example.net", iceStruct.urls.front());
  29. EXPECT_EQ("", iceStruct.username);
  30. EXPECT_EQ("", iceStruct.password);
  31. }
  32. - (void)testTwoURLServer {
  33. RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[
  34. @"turn1:turn1.example.net", @"turn2:turn2.example.net" ]];
  35. webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
  36. EXPECT_EQ(2u, iceStruct.urls.size());
  37. EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
  38. EXPECT_EQ("turn2:turn2.example.net", iceStruct.urls.back());
  39. EXPECT_EQ("", iceStruct.username);
  40. EXPECT_EQ("", iceStruct.password);
  41. }
  42. - (void)testPasswordCredential {
  43. RTCIceServer *server = [[RTCIceServer alloc]
  44. initWithURLStrings:@[ @"turn1:turn1.example.net" ]
  45. username:@"username"
  46. credential:@"credential"];
  47. webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
  48. EXPECT_EQ(1u, iceStruct.urls.size());
  49. EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
  50. EXPECT_EQ("username", iceStruct.username);
  51. EXPECT_EQ("credential", iceStruct.password);
  52. }
  53. - (void)testHostname {
  54. RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
  55. username:@"username"
  56. credential:@"credential"
  57. tlsCertPolicy:RTCTlsCertPolicySecure
  58. hostname:@"hostname"];
  59. webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
  60. EXPECT_EQ(1u, iceStruct.urls.size());
  61. EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
  62. EXPECT_EQ("username", iceStruct.username);
  63. EXPECT_EQ("credential", iceStruct.password);
  64. EXPECT_EQ("hostname", iceStruct.hostname);
  65. }
  66. - (void)testTlsAlpnProtocols {
  67. RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
  68. username:@"username"
  69. credential:@"credential"
  70. tlsCertPolicy:RTCTlsCertPolicySecure
  71. hostname:@"hostname"
  72. tlsAlpnProtocols:@[ @"proto1", @"proto2" ]];
  73. webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
  74. EXPECT_EQ(1u, iceStruct.urls.size());
  75. EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
  76. EXPECT_EQ("username", iceStruct.username);
  77. EXPECT_EQ("credential", iceStruct.password);
  78. EXPECT_EQ("hostname", iceStruct.hostname);
  79. EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size());
  80. }
  81. - (void)testTlsEllipticCurves {
  82. RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:@[ @"turn1:turn1.example.net" ]
  83. username:@"username"
  84. credential:@"credential"
  85. tlsCertPolicy:RTCTlsCertPolicySecure
  86. hostname:@"hostname"
  87. tlsAlpnProtocols:@[ @"proto1", @"proto2" ]
  88. tlsEllipticCurves:@[ @"curve1", @"curve2" ]];
  89. webrtc::PeerConnectionInterface::IceServer iceStruct = server.nativeServer;
  90. EXPECT_EQ(1u, iceStruct.urls.size());
  91. EXPECT_EQ("turn1:turn1.example.net", iceStruct.urls.front());
  92. EXPECT_EQ("username", iceStruct.username);
  93. EXPECT_EQ("credential", iceStruct.password);
  94. EXPECT_EQ("hostname", iceStruct.hostname);
  95. EXPECT_EQ(2u, iceStruct.tls_alpn_protocols.size());
  96. EXPECT_EQ(2u, iceStruct.tls_elliptic_curves.size());
  97. }
  98. - (void)testInitFromNativeServer {
  99. webrtc::PeerConnectionInterface::IceServer nativeServer;
  100. nativeServer.username = "username";
  101. nativeServer.password = "password";
  102. nativeServer.urls.push_back("stun:stun.example.net");
  103. nativeServer.hostname = "hostname";
  104. nativeServer.tls_alpn_protocols.push_back("proto1");
  105. nativeServer.tls_alpn_protocols.push_back("proto2");
  106. nativeServer.tls_elliptic_curves.push_back("curve1");
  107. nativeServer.tls_elliptic_curves.push_back("curve2");
  108. RTCIceServer *iceServer =
  109. [[RTCIceServer alloc] initWithNativeServer:nativeServer];
  110. EXPECT_EQ(1u, iceServer.urlStrings.count);
  111. EXPECT_EQ("stun:stun.example.net",
  112. [NSString stdStringForString:iceServer.urlStrings.firstObject]);
  113. EXPECT_EQ("username", [NSString stdStringForString:iceServer.username]);
  114. EXPECT_EQ("password", [NSString stdStringForString:iceServer.credential]);
  115. EXPECT_EQ("hostname", [NSString stdStringForString:iceServer.hostname]);
  116. EXPECT_EQ(2u, iceServer.tlsAlpnProtocols.count);
  117. EXPECT_EQ(2u, iceServer.tlsEllipticCurves.count);
  118. }
  119. @end
  120. TEST(RTCIceServerTest, OneURLTest) {
  121. @autoreleasepool {
  122. RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
  123. [test testOneURLServer];
  124. }
  125. }
  126. TEST(RTCIceServerTest, TwoURLTest) {
  127. @autoreleasepool {
  128. RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
  129. [test testTwoURLServer];
  130. }
  131. }
  132. TEST(RTCIceServerTest, PasswordCredentialTest) {
  133. @autoreleasepool {
  134. RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
  135. [test testPasswordCredential];
  136. }
  137. }
  138. TEST(RTCIceServerTest, HostnameTest) {
  139. @autoreleasepool {
  140. RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
  141. [test testHostname];
  142. }
  143. }
  144. TEST(RTCIceServerTest, InitFromNativeServerTest) {
  145. @autoreleasepool {
  146. RTCIceServerTest *test = [[RTCIceServerTest alloc] init];
  147. [test testInitFromNativeServer];
  148. }
  149. }