mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
New JUnit tests and equals methods
This commit is contained in:
parent
9c71cb8aeb
commit
c4588eadc6
4 changed files with 104 additions and 2 deletions
|
@ -455,4 +455,26 @@ public class Bytestream extends IQ {
|
|||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(other instanceof Bytestream)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Bytestream o = (Bytestream) other;
|
||||
|
||||
return o.getMode() == getMode() &&
|
||||
o.getSessionID().equals(getSessionID()) &&
|
||||
o.getStreamHosts().equals(getStreamHosts());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * getStreamHosts().hashCode() + 29 * getSessionID().hashCode() + 23 * getMode().hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,9 +102,9 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
|||
* @param other transport of the other party.
|
||||
*/
|
||||
JingleS5BTransport(FullJid initiator, FullJid responder, List<JingleTransportCandidate<?>> ourCandidates, JingleS5BTransport other) {
|
||||
this.sid = other.sid;
|
||||
this.sid = other.getSid();
|
||||
this.mode = other.mode;
|
||||
this.ourDstAddr = Socks5Utils.createDigest(other.sid, responder, initiator);
|
||||
this.ourDstAddr = Socks5Utils.createDigest(sid, responder, initiator);
|
||||
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
|
||||
this.theirDstAddr = other.theirDstAddr;
|
||||
|
||||
|
@ -232,6 +232,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
|||
establishBytestreamSession(connection);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ReferenceEquality")
|
||||
void establishBytestreamSession(XMPPConnection connection)
|
||||
throws SmackException.NotConnectedException, InterruptedException {
|
||||
Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr);
|
||||
|
@ -251,6 +252,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
|||
connectIfReady();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ReferenceEquality")
|
||||
public JingleS5BTransportCandidate connectToCandidates(int timeout) {
|
||||
|
||||
if (getTheirCandidates().size() == 0) {
|
||||
|
@ -276,6 +278,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
|||
Socks5Proxy.getSocks5Proxy().removeTransfer(ourDstAddr);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ReferenceEquality")
|
||||
void connectIfReady() {
|
||||
final JingleS5BTransportManager jingleS5BTransportManager = JingleS5BTransportManager.getInstanceFor(getParent().getParent().getJingleManager().getConnection());
|
||||
final JingleSession session = getParent().getParent();
|
||||
|
|
|
@ -114,4 +114,26 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
|
|||
public Socket getSocket() {
|
||||
return socket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(other instanceof JingleS5BTransportCandidate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JingleS5BTransportCandidate o = (JingleS5BTransportCandidate) other;
|
||||
|
||||
return o.getCandidateId().equals(this.getCandidateId()) &&
|
||||
o.getType() == this.getType() &&
|
||||
o.getStreamHost().equals(this.getStreamHost());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getCandidateId().hashCode() + 3 * getType().hashCode() + 5 * getStreamHost().hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,12 @@ import static junit.framework.TestCase.assertNotNull;
|
|||
import static junit.framework.TestCase.assertNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle.component.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.component.JingleTransportCandidate;
|
||||
|
@ -249,6 +253,57 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
assertEquals(streamHost.toXML().toString(), candidate.getStreamHost().toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorsTest() throws XmppStringprepException {
|
||||
FullJid initiator = JidCreate.fullFrom("in@it.ia/tor");
|
||||
FullJid responder = JidCreate.fullFrom("re@sp.on/der");
|
||||
|
||||
List<JingleTransportCandidate<?>> c1 = new ArrayList<>();
|
||||
JingleS5BTransportCandidate c11 = new JingleS5BTransportCandidate("1234", new Bytestream.StreamHost(JidCreate.from("p.b.c"), "p.b.c", 9999), 100, JingleS5BTransportCandidateElement.Type.proxy);
|
||||
c1.add(c11);
|
||||
|
||||
List<JingleTransportCandidate<?>> c2 = new ArrayList<>();
|
||||
JingleS5BTransportCandidate c21 = new JingleS5BTransportCandidate("1337", new Bytestream.StreamHost(JidCreate.from("p.a.b"), "p.a.b", 1000), 101, JingleS5BTransportCandidateElement.Type.proxy);
|
||||
JingleS5BTransportCandidate c22 = new JingleS5BTransportCandidate("1009", new Bytestream.StreamHost(JidCreate.from("p.a.b"), "p.a.b", 2000), 10, JingleS5BTransportCandidateElement.Type.proxy);
|
||||
c2.add(c21);
|
||||
c2.add(c22);
|
||||
|
||||
|
||||
JingleS5BTransport t1 = new JingleS5BTransport(initiator, responder, "tSes", Bytestream.Mode.tcp, c1);
|
||||
|
||||
assertEquals("tSes", t1.getSid());
|
||||
assertEquals(Bytestream.Mode.tcp, t1.getMode());
|
||||
|
||||
assertEquals(Socks5Utils.createDigest("tSes", initiator, responder), t1.getOurDstAddr());
|
||||
assertNull(t1.getTheirDstAddr());
|
||||
|
||||
assertEquals(1, t1.getOurCandidates().size());
|
||||
assertEquals(c11, t1.getOurCandidates().get(0));
|
||||
assertEquals(0, t1.getTheirCandidates().size());
|
||||
|
||||
|
||||
JingleS5BTransport t1parsed = new JingleS5BTransportAdapter().transportFromElement(t1.getElement());
|
||||
|
||||
assertEquals(t1.getOurDstAddr(), t1parsed.getTheirDstAddr());
|
||||
assertNull(t1parsed.getOurDstAddr());
|
||||
assertEquals(0, t1parsed.getOurCandidates().size());
|
||||
assertEquals(t1.getSid(), t1parsed.getSid());
|
||||
assertEquals(t1.getMode(), t1parsed.getMode());
|
||||
assertEquals(t1.getOurCandidates().size(), t1parsed.getTheirCandidates().size());
|
||||
|
||||
JingleS5BTransport t2 = new JingleS5BTransport(initiator, responder, c2, t1parsed);
|
||||
|
||||
assertEquals("tSes", t2.getSid());
|
||||
assertEquals(Bytestream.Mode.tcp, t2.getMode());
|
||||
|
||||
assertEquals(Socks5Utils.createDigest("tSes", responder, initiator), t2.getOurDstAddr());
|
||||
assertEquals(t1.getOurDstAddr(), t2.getTheirDstAddr());
|
||||
|
||||
assertEquals(2, t2.getOurCandidates().size());
|
||||
assertEquals(c2, t2.getOurCandidates());
|
||||
assertEquals(t1.getOurCandidates().size(), t2.getTheirCandidates().size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void typeFromIllegalStringTest() {
|
||||
JingleS5BTransportCandidateElement.Type.fromString("illegal-type");
|
||||
|
|
Loading…
Reference in a new issue