| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 package org.appspot.apprtc; | 11 package org.appspot.apprtc; |
| 12 | 12 |
| 13 import org.junit.Before; | 13 import org.junit.Before; |
| 14 import org.junit.Test; | 14 import org.junit.Test; |
| 15 import org.junit.runner.RunWith; | 15 import org.junit.runner.RunWith; |
| 16 import org.robolectric.RobolectricTestRunner; | 16 import org.robolectric.RobolectricTestRunner; |
| 17 import org.robolectric.annotation.Config; | 17 import org.robolectric.annotation.Config; |
| 18 import org.webrtc.IceCandidate; | 18 import org.webrtc.IceCandidate; |
| 19 import org.webrtc.SessionDescription; | 19 import org.webrtc.SessionDescription; |
| 20 | 20 |
| 21 import java.util.regex.Matcher; |
| 22 |
| 23 import static org.junit.Assert.assertFalse; |
| 24 import static org.junit.Assert.assertTrue; |
| 21 import static org.junit.Assert.fail; | 25 import static org.junit.Assert.fail; |
| 22 import static org.mockito.Matchers.any; | 26 import static org.mockito.Matchers.any; |
| 23 import static org.mockito.Matchers.isNotNull; | 27 import static org.mockito.Matchers.isNotNull; |
| 24 import static org.mockito.Mockito.mock; | 28 import static org.mockito.Mockito.mock; |
| 25 import static org.mockito.Mockito.timeout; | 29 import static org.mockito.Mockito.timeout; |
| 26 import static org.mockito.Mockito.verify; | 30 import static org.mockito.Mockito.verify; |
| 27 import static org.mockito.Mockito.verifyNoMoreInteractions; | 31 import static org.mockito.Mockito.verifyNoMoreInteractions; |
| 28 | 32 |
| 29 /** | 33 /** |
| 30 * Test for DirectRTCClient. Test is very simple and only tests the overall sani
ty of the class | 34 * Test for DirectRTCClient. Test is very simple and only tests the overall sani
ty of the class |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 @Before | 55 @Before |
| 52 public void setUp() { | 56 public void setUp() { |
| 53 clientEvents = mock(AppRTCClient.SignalingEvents.class); | 57 clientEvents = mock(AppRTCClient.SignalingEvents.class); |
| 54 serverEvents = mock(AppRTCClient.SignalingEvents.class); | 58 serverEvents = mock(AppRTCClient.SignalingEvents.class); |
| 55 | 59 |
| 56 client = new DirectRTCClient(clientEvents); | 60 client = new DirectRTCClient(clientEvents); |
| 57 server = new DirectRTCClient(serverEvents); | 61 server = new DirectRTCClient(serverEvents); |
| 58 } | 62 } |
| 59 | 63 |
| 60 @Test | 64 @Test |
| 65 public void testValidIpPattern() { |
| 66 // Strings that should match the pattern. |
| 67 final String[] ipAddresses = new String[] { |
| 68 "0.0.0.0", |
| 69 "127.0.0.1", |
| 70 "192.168.0.1", |
| 71 "0.0.0.0:8888", |
| 72 "127.0.0.1:8888", |
| 73 "192.168.0.1:8888", |
| 74 "::", |
| 75 "::1", |
| 76 "2001:0db8:85a3:0000:0000:8a2e:0370:7946", |
| 77 "[::]", |
| 78 "[::1]", |
| 79 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]", |
| 80 "[::]:8888", |
| 81 "[::1]:8888", |
| 82 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]:8888" |
| 83 }; |
| 84 |
| 85 for (String ip : ipAddresses) { |
| 86 assertTrue(ip + " didn't match IP_PATTERN even though it should.", |
| 87 DirectRTCClient.IP_PATTERN.matcher(ip).matches()); |
| 88 } |
| 89 } |
| 90 |
| 91 @Test |
| 92 public void testInvalidIpPattern() { |
| 93 // Strings that shouldn't match the pattern. |
| 94 final String[] invalidIpAddresses = new String[] { |
| 95 "Hello, World!", |
| 96 "aaaa", |
| 97 "1111", |
| 98 "[hello world]", |
| 99 "hello:world" |
| 100 }; |
| 101 |
| 102 for (String invalidIp : invalidIpAddresses) { |
| 103 assertFalse(invalidIp + " matched IP_PATTERN even though it shouldn't.", |
| 104 DirectRTCClient.IP_PATTERN.matcher(invalidIp).matches()); |
| 105 } |
| 106 } |
| 107 |
| 108 @Test |
| 61 public void testDirectRTCClient() { | 109 public void testDirectRTCClient() { |
| 62 server.connectToRoom(new AppRTCClient.RoomConnectionParameters(ROOM_URL, "0.
0.0.0", LOOPBACK)); | 110 server.connectToRoom(new AppRTCClient.RoomConnectionParameters(ROOM_URL, "0.
0.0.0", LOOPBACK)); |
| 63 try { | 111 try { |
| 64 Thread.sleep(SERVER_WAIT); | 112 Thread.sleep(SERVER_WAIT); |
| 65 } catch (InterruptedException e) { | 113 } catch (InterruptedException e) { |
| 66 fail(e.getMessage()); | 114 fail(e.getMessage()); |
| 67 } | 115 } |
| 68 client.connectToRoom( | 116 client.connectToRoom( |
| 69 new AppRTCClient.RoomConnectionParameters(ROOM_URL, "127.0.0.1", LOOPBAC
K)); | 117 new AppRTCClient.RoomConnectionParameters(ROOM_URL, "127.0.0.1", LOOPBAC
K)); |
| 70 verify(serverEvents, timeout(NETWORK_TIMEOUT)) | 118 verify(serverEvents, timeout(NETWORK_TIMEOUT)) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 91 .onRemoteIceCandidate(isNotNull(IceCandidate.class)); | 139 .onRemoteIceCandidate(isNotNull(IceCandidate.class)); |
| 92 | 140 |
| 93 client.disconnectFromRoom(); | 141 client.disconnectFromRoom(); |
| 94 verify(clientEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); | 142 verify(clientEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); |
| 95 verify(serverEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); | 143 verify(serverEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); |
| 96 | 144 |
| 97 verifyNoMoreInteractions(clientEvents); | 145 verifyNoMoreInteractions(clientEvents); |
| 98 verifyNoMoreInteractions(serverEvents); | 146 verifyNoMoreInteractions(serverEvents); |
| 99 } | 147 } |
| 100 } | 148 } |
| OLD | NEW |