add auto tests for standard exchange types
fixed a bug with reporting the removal of an exchange added an ExchangeType enum for standard types
This commit is contained in:
parent
4aa8397f2a
commit
360e64b34b
|
|
@ -24,7 +24,7 @@ void Exchange::onOpen()
|
|||
{
|
||||
Q_D(Exchange);
|
||||
if (d->delayedDeclare)
|
||||
declare();
|
||||
declare(Exchange::Direct);
|
||||
}
|
||||
|
||||
void Exchange::onClose()
|
||||
|
|
@ -44,6 +44,11 @@ QString Exchange::type() const
|
|||
return d->type;
|
||||
}
|
||||
|
||||
void Exchange::declare(ExchangeType type, ExchangeOptions options , const Frame::TableField &args)
|
||||
{
|
||||
declare(ExchangePrivate::typeToString(type), options, args);
|
||||
}
|
||||
|
||||
void Exchange::declare(const QString &type, ExchangeOptions options , const Frame::TableField &args)
|
||||
{
|
||||
Q_D(Exchange);
|
||||
|
|
@ -176,6 +181,18 @@ void Exchange::publish(const QByteArray &message, const QString &key,
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
QString ExchangePrivate::typeToString(Exchange::ExchangeType type)
|
||||
{
|
||||
switch (type) {
|
||||
case Exchange::Direct: return QLatin1String("direct");
|
||||
case Exchange::FanOut: return QLatin1String("fanout");
|
||||
case Exchange::Topic: return QLatin1String("topic");
|
||||
case Exchange::Headers: return QLatin1String("headers");
|
||||
}
|
||||
|
||||
return QLatin1String("direct");
|
||||
}
|
||||
|
||||
ExchangePrivate::ExchangePrivate(Exchange *q)
|
||||
: ChannelPrivate(q),
|
||||
delayedDeclare(false),
|
||||
|
|
@ -195,7 +212,7 @@ bool ExchangePrivate::_q_method(const Frame::Method &frame)
|
|||
case miDeclareOk:
|
||||
declareOk(frame);
|
||||
break;
|
||||
case miDelete:
|
||||
case miDeleteOk:
|
||||
deleteOk(frame);
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -18,6 +18,14 @@ class QAMQP_EXPORT Exchange : public Channel
|
|||
Q_ENUMS(ExchangeOption)
|
||||
|
||||
public:
|
||||
enum ExchangeType {
|
||||
Direct,
|
||||
FanOut,
|
||||
Topic,
|
||||
Headers
|
||||
};
|
||||
QString type() const;
|
||||
|
||||
enum ExchangeOption {
|
||||
NoOptions = 0x0,
|
||||
Passive = 0x01,
|
||||
|
|
@ -32,9 +40,11 @@ public:
|
|||
|
||||
virtual ~Exchange();
|
||||
|
||||
QString type() const;
|
||||
ExchangeOptions option() const;
|
||||
|
||||
void declare(ExchangeType type = Direct,
|
||||
ExchangeOptions options = NoOptions,
|
||||
const Frame::TableField &args = Frame::TableField());
|
||||
void declare(const QString &type = QLatin1String("direct"),
|
||||
ExchangeOptions options = NoOptions,
|
||||
const Frame::TableField &args = Frame::TableField());
|
||||
|
|
@ -73,5 +83,6 @@ private:
|
|||
} // namespace QAMQP
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QAMQP::Exchange::ExchangeOptions)
|
||||
Q_DECLARE_METATYPE(QAMQP::Exchange::ExchangeType)
|
||||
|
||||
#endif // amqp_exchange_h__
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef amqp_exchange_p_h__
|
||||
#define amqp_exchange_p_h__
|
||||
|
||||
#include "amqp_exchange.h"
|
||||
#include "amqp_channel_p.h"
|
||||
|
||||
namespace QAMQP
|
||||
|
|
@ -15,6 +16,7 @@ public:
|
|||
};
|
||||
|
||||
ExchangePrivate(Exchange *q);
|
||||
static QString typeToString(Exchange::ExchangeType type);
|
||||
|
||||
// method handler related
|
||||
virtual void _q_disconnected();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
TEMPLATE = subdirs
|
||||
SUBDIRS = \
|
||||
basic \
|
||||
exchanges \
|
||||
qamqpexchange \
|
||||
queues \
|
||||
channels
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
#include <QtTest/QtTest>
|
||||
|
||||
class tst_Exchanges : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void dummy();
|
||||
|
||||
};
|
||||
|
||||
void tst_Exchanges::dummy()
|
||||
{
|
||||
QVERIFY(true);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_Exchanges)
|
||||
#include "tst_exchanges.moc"
|
||||
|
|
@ -2,5 +2,5 @@ DEPTH = ../../..
|
|||
include($${DEPTH}/qamqp.pri)
|
||||
include($${DEPTH}/tests/tests.pri)
|
||||
|
||||
TARGET = tst_exchanges
|
||||
SOURCES = tst_exchanges.cpp
|
||||
TARGET = tst_qamqpexchange
|
||||
SOURCES = tst_qamqpexchange.cpp
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#include <QtTest/QtTest>
|
||||
#include "signalspy.h"
|
||||
|
||||
#include "amqp_client.h"
|
||||
#include "amqp_exchange.h"
|
||||
|
||||
using namespace QAMQP;
|
||||
class tst_QAMQPExchange : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void standardTypes_data();
|
||||
void standardTypes();
|
||||
|
||||
};
|
||||
|
||||
void tst_QAMQPExchange::standardTypes_data()
|
||||
{
|
||||
QTest::addColumn<Exchange::ExchangeType>("type");
|
||||
QTest::newRow("direct") << Exchange::Direct;
|
||||
QTest::newRow("fanout") << Exchange::FanOut;
|
||||
QTest::newRow("topic") << Exchange::Topic;
|
||||
QTest::newRow("headers") << Exchange::Headers;
|
||||
}
|
||||
|
||||
void tst_QAMQPExchange::standardTypes()
|
||||
{
|
||||
QFETCH(Exchange::ExchangeType, type);
|
||||
|
||||
Client client;
|
||||
SignalSpy connectSpy(&client, SIGNAL(connected()));
|
||||
client.connectToHost();
|
||||
QVERIFY(connectSpy.wait());
|
||||
|
||||
Exchange *exchange = client.createExchange("test");
|
||||
SignalSpy declareSpy(exchange, SIGNAL(declared()));
|
||||
exchange->declare(type);
|
||||
QVERIFY(declareSpy.wait());
|
||||
|
||||
SignalSpy removeSpy(exchange, SIGNAL(removed()));
|
||||
exchange->remove(false, false);
|
||||
QVERIFY(removeSpy.wait());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QAMQPExchange)
|
||||
#include "tst_qamqpexchange.moc"
|
||||
Loading…
Reference in New Issue