overhauled tests, added TestCase class, made a few skeleton auto tests

This commit is contained in:
Matt Broadstone 2014-06-03 13:48:50 -04:00
parent 1198db2857
commit fde4bcf39a
13 changed files with 191 additions and 59 deletions

View File

@ -81,6 +81,7 @@ void ClientPrivate::disconnect()
return;
}
connection_->close();
network_->disconnect();
// NOTE: this should be handled by signals, no need for dptr

View File

@ -152,8 +152,9 @@ void Connection::closeOk(const Frame::Method &frame)
Q_UNUSED(frame)
Q_D(Connection);
qDebug() << Q_FUNC_INFO << "received";
d->connected = false;
Q_EMIT disconnected();
if (d->heartbeatTimer)
d->heartbeatTimer->stop();
Q_EMIT disconnected();

View File

@ -1,6 +1,7 @@
TEMPLATE = subdirs
SUBDIRS = \
basic \
qamqpclient \
qamqpconnection \
qamqpexchange \
queues \
channels

View File

@ -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"

View File

@ -1,6 +1,6 @@
DEPTH = ../../..
include($${DEPTH}/qamqp.pri)
include($${DEPTH}/tests/tests.pri)
TARGET = tst_basic
SOURCES = tst_basic.cpp
DEPTH = ../../..
include($${DEPTH}/qamqp.pri)
include($${DEPTH}/tests/tests.pri)
TARGET = tst_qamqpclient
SOURCES = tst_qamqpclient.cpp

View File

@ -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"

View File

@ -0,0 +1,6 @@
DEPTH = ../../..
include($${DEPTH}/qamqp.pri)
include($${DEPTH}/tests/tests.pri)
TARGET = tst_qamqpconnection
SOURCES = tst_qamqpconnection.cpp

View File

@ -0,0 +1,6 @@
DEPTH = ../../..
include($${DEPTH}/qamqp.pri)
include($${DEPTH}/tests/tests.pri)
TARGET = tst_qamqpexchange
SOURCES = tst_qamqpexchange.cpp

View File

@ -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"

View File

@ -1,19 +1,56 @@
#include <QtTest/QtTest>
#include "signalspy.h"
#include "amqp_testcase.h"
#include "amqp_client.h"
#include "amqp_exchange.h"
#include "amqp_queue.h"
using namespace QAMQP;
class tst_QAMQPExchange : public QObject
class tst_QAMQPExchange : public TestCase
{
Q_OBJECT
private Q_SLOTS:
void defaultExchange();
void standardTypes_data();
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()
{
QTest::addColumn<Exchange::ExchangeType>("type");
@ -28,18 +65,17 @@ void tst_QAMQPExchange::standardTypes()
QFETCH(Exchange::ExchangeType, type);
Client client;
SignalSpy connectSpy(&client, SIGNAL(connected()));
client.connectToHost();
QVERIFY(connectSpy.wait());
QVERIFY(waitForSignal(&client, SIGNAL(connected())));
Exchange *exchange = client.createExchange("test");
SignalSpy declareSpy(exchange, SIGNAL(declared()));
exchange->declare(type);
QVERIFY(declareSpy.wait());
SignalSpy removeSpy(exchange, SIGNAL(removed()));
QVERIFY(waitForSignal(exchange, SIGNAL(declared())));
exchange->remove(false, false);
QVERIFY(removeSpy.wait());
QVERIFY(waitForSignal(exchange, SIGNAL(removed())));
client.disconnectFromHost();
QVERIFY(waitForSignal(&client, SIGNAL(disconnected())));
}
QTEST_MAIN(tst_QAMQPExchange)

View File

@ -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__

View File

@ -1,6 +1,25 @@
#ifndef 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
typedef QSignalSpy SignalSpy;
#else

View File

@ -5,4 +5,7 @@ QT -= gui
CONFIG -= app_bundle
CONFIG += testcase
HEADERS += $${PWD}/common/signalspy.h
HEADERS += \
$${PWD}/common/signalspy.h \
$${PWD}/common/amqp_testcase.h