Add the equals method to IceServer.
Bug: None Change-Id: I4bac54489a44a4577cc221ba51351e4a3a92e69b Reviewed-on: https://webrtc-review.googlesource.com/c/116081 Commit-Queue: Qingsi Wang <qingsi@webrtc.org> Reviewed-by: Honghai Zhang <honghaiz@webrtc.org> Reviewed-by: Alex Glaznev <glaznev@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26271}
This commit is contained in:
parent
5586d7fb57
commit
a0d4580936
@ -12,6 +12,7 @@ package org.webrtc;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.webrtc.DataChannel;
|
||||
@ -222,6 +223,31 @@ public class PeerConnection {
|
||||
+ "] [" + tlsAlpnProtocols + "] [" + tlsEllipticCurves + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof IceServer)) {
|
||||
return false;
|
||||
}
|
||||
IceServer other = (IceServer) obj;
|
||||
return (uri.equals(other.uri) && urls.equals(other.urls) && username.equals(other.username)
|
||||
&& password.equals(other.password) && tlsCertPolicy.equals(other.tlsCertPolicy)
|
||||
&& hostname.equals(other.hostname) && tlsAlpnProtocols.equals(other.tlsAlpnProtocols)
|
||||
&& tlsEllipticCurves.equals(other.tlsEllipticCurves));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
Object[] values = {uri, urls, username, password, tlsCertPolicy, hostname, tlsAlpnProtocols,
|
||||
tlsEllipticCurves};
|
||||
return Arrays.hashCode(values);
|
||||
}
|
||||
|
||||
public static Builder builder(String uri) {
|
||||
return new Builder(Collections.singletonList(uri));
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
@ -47,6 +48,7 @@ import org.webrtc.PeerConnection.IceConnectionState;
|
||||
import org.webrtc.PeerConnection.IceGatheringState;
|
||||
import org.webrtc.PeerConnection.PeerConnectionState;
|
||||
import org.webrtc.PeerConnection.SignalingState;
|
||||
import org.webrtc.PeerConnection.TlsCertPolicy;
|
||||
|
||||
/** End-to-end tests for PeerConnection.java. */
|
||||
@RunWith(BaseJUnit4ClassRunner.class)
|
||||
@ -651,6 +653,109 @@ public class PeerConnectionTest {
|
||||
// Thread.sleep(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testIceServerChanged() throws Exception {
|
||||
PeerConnection.IceServer iceServer1 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_SECURE)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Same as iceServer1.
|
||||
PeerConnection.IceServer iceServer2 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_SECURE)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Differs from iceServer1 by the url.
|
||||
PeerConnection.IceServer iceServer3 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example2.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_SECURE)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Differs from iceServer1 by the username.
|
||||
PeerConnection.IceServer iceServer4 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername2")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_SECURE)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Differs from iceServer1 by the password.
|
||||
PeerConnection.IceServer iceServer5 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword2")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_SECURE)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Differs from iceServer1 by the TLS certificate policy.
|
||||
PeerConnection.IceServer iceServer6 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Differs from iceServer1 by the hostname.
|
||||
PeerConnection.IceServer iceServer7 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK)
|
||||
.setHostname("fakeHostname2")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Differs from iceServer1 by the TLS ALPN.
|
||||
PeerConnection.IceServer iceServer8 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol2"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve"))
|
||||
.createIceServer();
|
||||
// Differs from iceServer1 by the TLS elliptic curve.
|
||||
PeerConnection.IceServer iceServer9 =
|
||||
PeerConnection.IceServer.builder("turn:fake.example.com")
|
||||
.setUsername("fakeUsername")
|
||||
.setPassword("fakePassword")
|
||||
.setTlsCertPolicy(TlsCertPolicy.TLS_CERT_POLICY_INSECURE_NO_CHECK)
|
||||
.setHostname("fakeHostname")
|
||||
.setTlsAlpnProtocols(singletonList("fakeTlsAlpnProtocol"))
|
||||
.setTlsEllipticCurves(singletonList("fakeTlsEllipticCurve2"))
|
||||
.createIceServer();
|
||||
|
||||
assertTrue(iceServer1.equals(iceServer2));
|
||||
assertFalse(iceServer1.equals(iceServer3));
|
||||
assertFalse(iceServer1.equals(iceServer4));
|
||||
assertFalse(iceServer1.equals(iceServer5));
|
||||
assertFalse(iceServer1.equals(iceServer6));
|
||||
assertFalse(iceServer1.equals(iceServer7));
|
||||
assertFalse(iceServer1.equals(iceServer8));
|
||||
assertFalse(iceServer1.equals(iceServer9));
|
||||
}
|
||||
|
||||
// TODO(fischman) MOAR test ideas:
|
||||
// - Test that PC.removeStream() works; requires a second
|
||||
// createOffer/createAnswer dance.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user