overhauled tests, added TestCase class, made a few skeleton auto tests
This commit is contained in:
parent
1198db2857
commit
fde4bcf39a
|
|
@ -81,6 +81,7 @@ void ClientPrivate::disconnect()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connection_->close();
|
||||||
network_->disconnect();
|
network_->disconnect();
|
||||||
|
|
||||||
// NOTE: this should be handled by signals, no need for dptr
|
// NOTE: this should be handled by signals, no need for dptr
|
||||||
|
|
|
||||||
|
|
@ -152,8 +152,9 @@ void Connection::closeOk(const Frame::Method &frame)
|
||||||
Q_UNUSED(frame)
|
Q_UNUSED(frame)
|
||||||
Q_D(Connection);
|
Q_D(Connection);
|
||||||
|
|
||||||
|
qDebug() << Q_FUNC_INFO << "received";
|
||||||
|
|
||||||
d->connected = false;
|
d->connected = false;
|
||||||
Q_EMIT disconnected();
|
|
||||||
if (d->heartbeatTimer)
|
if (d->heartbeatTimer)
|
||||||
d->heartbeatTimer->stop();
|
d->heartbeatTimer->stop();
|
||||||
Q_EMIT disconnected();
|
Q_EMIT disconnected();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
basic \
|
qamqpclient \
|
||||||
|
qamqpconnection \
|
||||||
qamqpexchange \
|
qamqpexchange \
|
||||||
queues \
|
queues \
|
||||||
channels
|
channels
|
||||||
|
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
#include <QtTest/QtTest>
|
|
||||||
|
|
||||||
#include "amqp_client.h"
|
|
||||||
#include "signalspy.h"
|
|
||||||
|
|
||||||
class tst_Basic : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
private Q_SLOTS:
|
|
||||||
void connect();
|
|
||||||
void connectDisconnect();
|
|
||||||
void reconnect();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void tst_Basic::connect()
|
|
||||||
{
|
|
||||||
QAMQP::Client client;
|
|
||||||
SignalSpy spy(&client, SIGNAL(connected()));
|
|
||||||
client.connectToHost();
|
|
||||||
QVERIFY(spy.wait());
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Basic::connectDisconnect()
|
|
||||||
{
|
|
||||||
QAMQP::Client client;
|
|
||||||
SignalSpy connectSpy(&client, SIGNAL(connected()));
|
|
||||||
client.connectToHost();
|
|
||||||
QVERIFY(connectSpy.wait());
|
|
||||||
|
|
||||||
SignalSpy disconnectSpy(&client, SIGNAL(disconnected()));
|
|
||||||
client.disconnectFromHost();
|
|
||||||
QVERIFY(disconnectSpy.wait());
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_Basic::reconnect()
|
|
||||||
{
|
|
||||||
QVERIFY(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_Basic)
|
|
||||||
#include "tst_basic.moc"
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
DEPTH = ../../..
|
DEPTH = ../../..
|
||||||
include($${DEPTH}/qamqp.pri)
|
include($${DEPTH}/qamqp.pri)
|
||||||
include($${DEPTH}/tests/tests.pri)
|
include($${DEPTH}/tests/tests.pri)
|
||||||
|
|
||||||
TARGET = tst_basic
|
TARGET = tst_qamqpclient
|
||||||
SOURCES = tst_basic.cpp
|
SOURCES = tst_qamqpclient.cpp
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
#include "amqp_testcase.h"
|
||||||
|
|
||||||
|
#include "amqp_client.h"
|
||||||
|
|
||||||
|
using namespace QAMQP;
|
||||||
|
class tst_QAMQPClient : public TestCase
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private Q_SLOTS:
|
||||||
|
void connect();
|
||||||
|
void connectDisconnect();
|
||||||
|
void reconnect();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_QAMQPClient::connect()
|
||||||
|
{
|
||||||
|
Client client;
|
||||||
|
client.connectToHost();
|
||||||
|
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QAMQPClient::connectDisconnect()
|
||||||
|
{
|
||||||
|
Client client;
|
||||||
|
client.connectToHost();
|
||||||
|
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||||
|
client.disconnectFromHost();
|
||||||
|
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QAMQPClient::reconnect()
|
||||||
|
{
|
||||||
|
QVERIFY(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(tst_QAMQPClient)
|
||||||
|
#include "tst_qamqpclient.moc"
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
DEPTH = ../../..
|
||||||
|
include($${DEPTH}/qamqp.pri)
|
||||||
|
include($${DEPTH}/tests/tests.pri)
|
||||||
|
|
||||||
|
TARGET = tst_qamqpconnection
|
||||||
|
SOURCES = tst_qamqpconnection.cpp
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
DEPTH = ../../..
|
||||||
|
include($${DEPTH}/qamqp.pri)
|
||||||
|
include($${DEPTH}/tests/tests.pri)
|
||||||
|
|
||||||
|
TARGET = tst_qamqpexchange
|
||||||
|
SOURCES = tst_qamqpexchange.cpp
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
#include "signalspy.h"
|
||||||
|
|
||||||
|
class tst_QAMQPConnection : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private Q_SLOTS:
|
||||||
|
void dummy();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool waitForSignal(QObject *obj, const char *signal, int delay = 1);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
bool tst_QAMQPConnection::waitForSignal(QObject *obj, const char *signal, int delay)
|
||||||
|
{
|
||||||
|
QObject::connect(obj, signal, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||||
|
QPointer<QObject> safe = obj;
|
||||||
|
|
||||||
|
QTestEventLoop::instance().enterLoop(delay);
|
||||||
|
if (!safe.isNull())
|
||||||
|
QObject::disconnect(safe, signal, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||||
|
return !QTestEventLoop::instance().timeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QAMQPConnection::dummy()
|
||||||
|
{
|
||||||
|
QVERIFY(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(tst_QAMQPConnection)
|
||||||
|
#include "tst_qamqpconnection.moc"
|
||||||
|
|
@ -1,19 +1,56 @@
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
#include "signalspy.h"
|
#include "signalspy.h"
|
||||||
|
#include "amqp_testcase.h"
|
||||||
|
|
||||||
#include "amqp_client.h"
|
#include "amqp_client.h"
|
||||||
#include "amqp_exchange.h"
|
#include "amqp_exchange.h"
|
||||||
|
#include "amqp_queue.h"
|
||||||
|
|
||||||
using namespace QAMQP;
|
using namespace QAMQP;
|
||||||
class tst_QAMQPExchange : public QObject
|
class tst_QAMQPExchange : public TestCase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
void defaultExchange();
|
||||||
void standardTypes_data();
|
void standardTypes_data();
|
||||||
void standardTypes();
|
void standardTypes();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void tst_QAMQPExchange::defaultExchange()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Client checks that the default exchange is active by specifying a queue
|
||||||
|
* binding with no exchange name, and publishing a message with a suitable
|
||||||
|
* routing key but without specifying the exchange name, then ensuring that
|
||||||
|
* the message arrives in the queue correctly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Client client;
|
||||||
|
client.connectToHost();
|
||||||
|
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||||
|
|
||||||
|
Exchange *defaultExchange = client.createExchange();
|
||||||
|
Queue *queue = client.createQueue("testDefaultExchange");
|
||||||
|
queue->bind("", "testRoutingKey"); // bind to default exchange
|
||||||
|
qDebug() << "HUZZAH1";
|
||||||
|
QVERIFY(waitForSignal(queue, SIGNAL(bound())));
|
||||||
|
qDebug() << "HUZZAH2";
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
defaultExchange->publish("boop", "testRoutingKey");
|
||||||
|
QVERIFY(waitForSignal(queue, SIGNAL(messageReceived(Queue*))));
|
||||||
|
MessagePtr message = queue->getMessage();
|
||||||
|
qDebug() << message.data()->payload;
|
||||||
|
QVERIFY(true);
|
||||||
|
*/
|
||||||
|
|
||||||
|
QVERIFY(true);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QAMQPExchange::standardTypes_data()
|
void tst_QAMQPExchange::standardTypes_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<Exchange::ExchangeType>("type");
|
QTest::addColumn<Exchange::ExchangeType>("type");
|
||||||
|
|
@ -28,18 +65,17 @@ void tst_QAMQPExchange::standardTypes()
|
||||||
QFETCH(Exchange::ExchangeType, type);
|
QFETCH(Exchange::ExchangeType, type);
|
||||||
|
|
||||||
Client client;
|
Client client;
|
||||||
SignalSpy connectSpy(&client, SIGNAL(connected()));
|
|
||||||
client.connectToHost();
|
client.connectToHost();
|
||||||
QVERIFY(connectSpy.wait());
|
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
|
||||||
|
|
||||||
Exchange *exchange = client.createExchange("test");
|
Exchange *exchange = client.createExchange("test");
|
||||||
SignalSpy declareSpy(exchange, SIGNAL(declared()));
|
|
||||||
exchange->declare(type);
|
exchange->declare(type);
|
||||||
QVERIFY(declareSpy.wait());
|
QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
|
||||||
|
|
||||||
SignalSpy removeSpy(exchange, SIGNAL(removed()));
|
|
||||||
exchange->remove(false, false);
|
exchange->remove(false, false);
|
||||||
QVERIFY(removeSpy.wait());
|
QVERIFY(waitForSignal(exchange, SIGNAL(removed())));
|
||||||
|
|
||||||
|
client.disconnectFromHost();
|
||||||
|
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QAMQPExchange)
|
QTEST_MAIN(tst_QAMQPExchange)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef amqp_testcase_h__
|
||||||
|
#define amqp_testcase_h__
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTestEventLoop>
|
||||||
|
|
||||||
|
namespace QAMQP {
|
||||||
|
|
||||||
|
class TestCase : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestCase() {}
|
||||||
|
virtual ~TestCase() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool waitForSignal(QObject *obj, const char *signal, int delay = 1)
|
||||||
|
{
|
||||||
|
QObject::connect(obj, signal, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||||
|
QPointer<QObject> safe = obj;
|
||||||
|
|
||||||
|
QTestEventLoop::instance().enterLoop(delay);
|
||||||
|
if (!safe.isNull())
|
||||||
|
QObject::disconnect(safe, signal, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||||
|
return !QTestEventLoop::instance().timeout();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QAMQP
|
||||||
|
|
||||||
|
#endif // amqp_testcase_h__
|
||||||
|
|
@ -1,6 +1,25 @@
|
||||||
#ifndef SIGNALSPY_H
|
#ifndef SIGNALSPY_H
|
||||||
#define SIGNALSPY_H
|
#define SIGNALSPY_H
|
||||||
|
|
||||||
|
namespace QAMQP {
|
||||||
|
namespace Test {
|
||||||
|
|
||||||
|
bool waitForSignal(QObject *obj, const char *signal, int delay)
|
||||||
|
{
|
||||||
|
QObject::connect(obj, signal, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||||
|
QPointer<QObject> safe = obj;
|
||||||
|
|
||||||
|
QTestEventLoop::instance().enterLoop(delay);
|
||||||
|
if (!safe.isNull())
|
||||||
|
QObject::disconnect(safe, signal, &QTestEventLoop::instance(), SLOT(exitLoop()));
|
||||||
|
return !QTestEventLoop::instance().timeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Test
|
||||||
|
} // namespace QAMQP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if QT_VERSION >= 0x050000
|
#if QT_VERSION >= 0x050000
|
||||||
typedef QSignalSpy SignalSpy;
|
typedef QSignalSpy SignalSpy;
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,7 @@ QT -= gui
|
||||||
CONFIG -= app_bundle
|
CONFIG -= app_bundle
|
||||||
CONFIG += testcase
|
CONFIG += testcase
|
||||||
|
|
||||||
HEADERS += $${PWD}/common/signalspy.h
|
HEADERS += \
|
||||||
|
$${PWD}/common/signalspy.h \
|
||||||
|
$${PWD}/common/amqp_testcase.h
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue