diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2015-08-25 14:54:59 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2015-08-25 14:54:59 +0200 |
| commit | 5dcc37f03182cbedc400f1d421f44b41892ba9b4 (patch) | |
| tree | 99f0d48f815537ab0da32c4b8869d0604af233d3 /tests | |
| parent | d9e5ad14e06871cfa18318f5a897626bc3f3bb24 (diff) | |
| download | qxmpp-5dcc37f03182cbedc400f1d421f44b41892ba9b4.tar.gz | |
add unit test for QXmppCallManager
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/qxmppcallmanager/qxmppcallmanager.pro | 3 | ||||
| -rw-r--r-- | tests/qxmppcallmanager/tst_qxmppcallmanager.cpp | 150 | ||||
| -rw-r--r-- | tests/tests.pro | 1 |
3 files changed, 154 insertions, 0 deletions
diff --git a/tests/qxmppcallmanager/qxmppcallmanager.pro b/tests/qxmppcallmanager/qxmppcallmanager.pro new file mode 100644 index 00000000..27465093 --- /dev/null +++ b/tests/qxmppcallmanager/qxmppcallmanager.pro @@ -0,0 +1,3 @@ +include(../tests.pri) +TARGET = tst_qxmppcallmanager +SOURCES += tst_qxmppcallmanager.cpp diff --git a/tests/qxmppcallmanager/tst_qxmppcallmanager.cpp b/tests/qxmppcallmanager/tst_qxmppcallmanager.cpp new file mode 100644 index 00000000..be84349f --- /dev/null +++ b/tests/qxmppcallmanager/tst_qxmppcallmanager.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2008-2014 The QXmpp developers + * + * Authors: + * Jeremy Lainé + * + * Source: + * https://github.com/qxmpp-project/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include <QBuffer> +#include <QObject> + +#include "QXmppCallManager.h" +#include "QXmppClient.h" +#include "QXmppServer.h" +#include "util.h" + +//Q_DECLARE_METATYPE(QXmppTransferJob::Method) + +class tst_QXmppCallManager : public QObject +{ + Q_OBJECT + +private slots: + void init(); + void testCall(); + + void acceptCall(QXmppCall *call); + +private: + QXmppCall *receiverCall; +}; + +void tst_QXmppCallManager::init() +{ + receiverCall = 0; +} + +void tst_QXmppCallManager::acceptCall(QXmppCall *call) +{ + receiverCall = call; + call->accept(); +} + +void tst_QXmppCallManager::testCall() +{ + const QString testDomain("localhost"); + const QHostAddress testHost(QHostAddress::LocalHost); + const quint16 testPort = 12345; + + QXmppLogger logger; + logger.setLoggingType(QXmppLogger::StdoutLogging); + + // prepare server + TestPasswordChecker passwordChecker; + passwordChecker.addCredentials("sender", "testpwd"); + passwordChecker.addCredentials("receiver", "testpwd"); + + QXmppServer server; + server.setDomain(testDomain); + server.setPasswordChecker(&passwordChecker); + server.listenForClients(testHost, testPort); + + // prepare sender + QXmppClient sender; + QXmppCallManager *senderManager = new QXmppCallManager; + sender.addExtension(senderManager); + sender.setLogger(&logger); + + QEventLoop senderLoop; + connect(&sender, SIGNAL(connected()), &senderLoop, SLOT(quit())); + connect(&sender, SIGNAL(disconnected()), &senderLoop, SLOT(quit())); + + QXmppConfiguration config; + config.setDomain(testDomain); + config.setHost(testHost.toString()); + config.setPort(testPort); + config.setUser("sender"); + config.setPassword("testpwd"); + sender.connectToServer(config); + senderLoop.exec(); + QCOMPARE(sender.isConnected(), true); + + // prepare receiver + QXmppClient receiver; + QXmppCallManager *receiverManager = new QXmppCallManager; + connect(receiverManager, SIGNAL(callReceived(QXmppCall*)), + this, SLOT(acceptCall(QXmppCall*))); + receiver.addExtension(receiverManager); + receiver.setLogger(&logger); + + QEventLoop receiverLoop; + connect(&receiver, SIGNAL(connected()), &receiverLoop, SLOT(quit())); + connect(&receiver, SIGNAL(disconnected()), &receiverLoop, SLOT(quit())); + + config.setUser("receiver"); + config.setPassword("testpwd"); + receiver.connectToServer(config); + receiverLoop.exec(); + QCOMPARE(receiver.isConnected(), true); + + // connect call + qDebug() << "======== CONNECT ========"; + QEventLoop loop; + QXmppCall *senderCall = senderManager->call("receiver@localhost/QXmpp"); + QVERIFY(senderCall); + connect(senderCall, SIGNAL(connected()), &loop, SLOT(quit())); + loop.exec(); + QVERIFY(receiverCall); + + QCOMPARE(senderCall->direction(), QXmppCall::OutgoingDirection); + QCOMPARE(senderCall->state(), QXmppCall::ActiveState); + + QCOMPARE(receiverCall->direction(), QXmppCall::IncomingDirection); + QCOMPARE(receiverCall->state(), QXmppCall::ActiveState); + + // exchange some media + qDebug() << "======== TALK ========"; + QTimer::singleShot(2000, &loop, SLOT(quit())); + loop.exec(); + + // hangup call + qDebug() << "======== HANGUP ========"; + connect(senderCall, SIGNAL(finished()), &loop, SLOT(quit())); + senderCall->hangup(); + loop.exec(); + + QCOMPARE(senderCall->direction(), QXmppCall::OutgoingDirection); + QCOMPARE(senderCall->state(), QXmppCall::FinishedState); + + QCOMPARE(receiverCall->direction(), QXmppCall::IncomingDirection); + QCOMPARE(receiverCall->state(), QXmppCall::FinishedState); +} + +QTEST_MAIN(tst_QXmppCallManager) +#include "tst_qxmppcallmanager.moc" diff --git a/tests/tests.pro b/tests/tests.pro index 552d4811..bbc59899 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs SUBDIRS = \ qxmpparchiveiq \ qxmppbindiq \ + qxmppcallmanager \ qxmppdataform \ qxmppdiscoveryiq \ qxmppentitytimeiq \ |
