From 233dbd11bb769d6ac2353eb28f58bc66f5ec0aa9 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Tue, 25 Aug 2015 13:12:28 +0200 Subject: ICE: test server-reflexive candidate gathering --- .../qxmppiceconnection/tst_qxmppiceconnection.cpp | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'tests') diff --git a/tests/qxmppiceconnection/tst_qxmppiceconnection.cpp b/tests/qxmppiceconnection/tst_qxmppiceconnection.cpp index 6851bb58..4bdb9d13 100644 --- a/tests/qxmppiceconnection/tst_qxmppiceconnection.cpp +++ b/tests/qxmppiceconnection/tst_qxmppiceconnection.cpp @@ -21,6 +21,7 @@ * */ +#include #include "QXmppStun.h" #include "util.h" @@ -29,9 +30,75 @@ class tst_QXmppIceConnection : public QObject Q_OBJECT private slots: + void testBind(); + void testBindStun(); void testConnect(); }; +void tst_QXmppIceConnection::testBind() +{ + const int componentId = 1024; + + QXmppLogger logger; + logger.setLoggingType(QXmppLogger::StdoutLogging); + + QXmppIceConnection client; + connect(&client, SIGNAL(logMessage(QXmppLogger::MessageType,QString)), + &logger, SLOT(log(QXmppLogger::MessageType,QString))); + client.setIceControlling(true); + client.addComponent(componentId); + + QXmppIceComponent *component = client.component(componentId); + QVERIFY(component); + + client.bind(QXmppIceComponent::discoverAddresses()); + QCOMPARE(client.localCandidates().size(), component->localCandidates().size()); + QVERIFY(!client.localCandidates().isEmpty()); + foreach (const QXmppJingleCandidate &c, client.localCandidates()) { + QCOMPARE(c.component(), componentId); + QCOMPARE(c.type(), QXmppJingleCandidate::HostType); + } +} + +void tst_QXmppIceConnection::testBindStun() +{ + const int componentId = 1024; + + QXmppLogger logger; + logger.setLoggingType(QXmppLogger::StdoutLogging); + + QHostInfo stunInfo = QHostInfo::fromName("stun.l.google.com"); + QVERIFY(!stunInfo.addresses().isEmpty()); + + QXmppIceConnection client; + connect(&client, SIGNAL(logMessage(QXmppLogger::MessageType,QString)), + &logger, SLOT(log(QXmppLogger::MessageType,QString))); + client.setIceControlling(true); + client.setStunServer(stunInfo.addresses().first(), 19302); + client.addComponent(componentId); + + QXmppIceComponent *component = client.component(componentId); + QVERIFY(component); + + QEventLoop loop; + connect(&client, SIGNAL(localCandidatesChanged()), + &loop, SLOT(quit())); + client.bind(QXmppIceComponent::discoverAddresses()); + loop.exec(); + + bool foundReflexive = false; + QCOMPARE(client.localCandidates().size(), component->localCandidates().size()); + QVERIFY(!client.localCandidates().isEmpty()); + foreach (const QXmppJingleCandidate &c, client.localCandidates()) { + QCOMPARE(c.component(), componentId); + if (c.type() == QXmppJingleCandidate::ServerReflexiveType) + foundReflexive = true; + else + QCOMPARE(c.type(), QXmppJingleCandidate::HostType); + } + QVERIFY(foundReflexive); +} + void tst_QXmppIceConnection::testConnect() { const int component = 1024; -- cgit v1.2.3