From eaee35df12f3586ccafeeb84d9c478849d88eb33 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Wed, 4 Jun 2014 10:24:45 -0400 Subject: [PATCH] add a test for a default exchange to tst_QAMQPQueue --- src/amqp_exchange.cpp | 10 ++--- src/amqp_exchange.h | 6 +-- tests/auto/auto.pro | 3 +- tests/auto/channels/tst_channels.cpp | 17 -------- .../auto/qamqpexchange/tst_qamqpexchange.cpp | 34 ---------------- .../qamqpqueue.pro} | 4 +- tests/auto/qamqpqueue/tst_qamqpqueue.cpp | 39 +++++++++++++++++++ tests/auto/queues/queues.pro | 6 --- tests/auto/queues/tst_queues.cpp | 22 ----------- 9 files changed, 50 insertions(+), 91 deletions(-) delete mode 100644 tests/auto/channels/tst_channels.cpp rename tests/auto/{channels/channels.pro => qamqpqueue/qamqpqueue.pro} (58%) create mode 100644 tests/auto/qamqpqueue/tst_qamqpqueue.cpp delete mode 100644 tests/auto/queues/queues.pro delete mode 100644 tests/auto/queues/tst_queues.cpp diff --git a/src/amqp_exchange.cpp b/src/amqp_exchange.cpp index 58659e9..d801f42 100644 --- a/src/amqp_exchange.cpp +++ b/src/amqp_exchange.cpp @@ -200,19 +200,19 @@ void Exchange::bind(const QString &queueName, const QString &key) qWarning("Not implemented"); } -void Exchange::publish(const QString &message, const QString &key, +void Exchange::publish(const QString &key, const QString &message, const MessageProperties &properties) { - publish(message.toUtf8(), key, QLatin1String("text.plain"), QVariantHash(), properties); + publish(key, message.toUtf8(), QLatin1String("text.plain"), QVariantHash(), properties); } -void Exchange::publish(const QByteArray &message, const QString &key, +void Exchange::publish(const QString &key, const QByteArray &message, const QString &mimeType, const MessageProperties &properties) { - publish(message, key, mimeType, QVariantHash(), properties); + publish(key, message, mimeType, QVariantHash(), properties); } -void Exchange::publish(const QByteArray &message, const QString &key, +void Exchange::publish(const QString &key, const QByteArray &message, const QString &mimeType, const QVariantHash &headers, const Exchange::MessageProperties &properties) { diff --git a/src/amqp_exchange.h b/src/amqp_exchange.h index 1b67e9e..79fe964 100644 --- a/src/amqp_exchange.h +++ b/src/amqp_exchange.h @@ -52,11 +52,11 @@ public: void bind(const QString &queueName); void bind(const QString &queueName, const QString &key); - void publish(const QString &message, const QString &key, + void publish(const QString &key, const QString &message, const MessageProperties &properties = MessageProperties()); - void publish(const QByteArray &message, const QString &key, + void publish(const QString &key, const QByteArray &message, const QString &mimeType, const MessageProperties &properties = MessageProperties()); - void publish(const QByteArray &message, const QString &key, + void publish(const QString &key, const QByteArray &message, const QString &mimeType, const QVariantHash &headers, const Exchange::MessageProperties &properties = Exchange::MessageProperties()); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 823fc77..9b5bae5 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -2,5 +2,4 @@ TEMPLATE = subdirs SUBDIRS = \ qamqpclient \ qamqpexchange \ - queues \ - channels + qamqpqueue diff --git a/tests/auto/channels/tst_channels.cpp b/tests/auto/channels/tst_channels.cpp deleted file mode 100644 index a864ff0..0000000 --- a/tests/auto/channels/tst_channels.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -class tst_Channels : public QObject -{ - Q_OBJECT -private Q_SLOTS: - void dummy(); - -}; - -void tst_Channels::dummy() -{ - QVERIFY(true); -} - -QTEST_MAIN(tst_Channels) -#include "tst_channels.moc" diff --git a/tests/auto/qamqpexchange/tst_qamqpexchange.cpp b/tests/auto/qamqpexchange/tst_qamqpexchange.cpp index 15c1807..a27273a 100644 --- a/tests/auto/qamqpexchange/tst_qamqpexchange.cpp +++ b/tests/auto/qamqpexchange/tst_qamqpexchange.cpp @@ -12,45 +12,11 @@ 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("type"); diff --git a/tests/auto/channels/channels.pro b/tests/auto/qamqpqueue/qamqpqueue.pro similarity index 58% rename from tests/auto/channels/channels.pro rename to tests/auto/qamqpqueue/qamqpqueue.pro index 986fa32..38dedd1 100644 --- a/tests/auto/channels/channels.pro +++ b/tests/auto/qamqpqueue/qamqpqueue.pro @@ -2,5 +2,5 @@ DEPTH = ../../.. include($${DEPTH}/qamqp.pri) include($${DEPTH}/tests/tests.pri) -TARGET = tst_channels -SOURCES = tst_channels.cpp +TARGET = tst_qamqpqueue +SOURCES = tst_qamqpqueue.cpp diff --git a/tests/auto/qamqpqueue/tst_qamqpqueue.cpp b/tests/auto/qamqpqueue/tst_qamqpqueue.cpp new file mode 100644 index 0000000..2bd8eb8 --- /dev/null +++ b/tests/auto/qamqpqueue/tst_qamqpqueue.cpp @@ -0,0 +1,39 @@ +#include +#include "amqp_testcase.h" + +#include "amqp_client.h" +#include "amqp_queue.h" +#include "amqp_exchange.h" + +using namespace QAMQP; +class tst_QAMQPQueue : public TestCase +{ + Q_OBJECT +private Q_SLOTS: + void defaultExchange(); + +}; + +void tst_QAMQPQueue::defaultExchange() +{ + Client client; + client.connectToHost(); + QVERIFY(waitForSignal(&client, SIGNAL(connected()))); + + Queue *queue = client.createQueue("test-default-exchange"); + queue->declare(); + QVERIFY(waitForSignal(queue, SIGNAL(declared()))); + queue->consume(); + + Exchange *defaultExchange = client.createExchange(); + defaultExchange->publish("test-default-exchange", "first message"); + QVERIFY(waitForSignal(queue, SIGNAL(messageReceived(Queue*)))); + MessagePtr message = queue->getMessage(); + QCOMPARE(message->payload, QByteArray("first message")); + + client.disconnectFromHost(); + QVERIFY(waitForSignal(&client, SIGNAL(disconnected()))); +} + +QTEST_MAIN(tst_QAMQPQueue) +#include "tst_qamqpqueue.moc" diff --git a/tests/auto/queues/queues.pro b/tests/auto/queues/queues.pro deleted file mode 100644 index 8a7c97e..0000000 --- a/tests/auto/queues/queues.pro +++ /dev/null @@ -1,6 +0,0 @@ -DEPTH = ../../.. -include($${DEPTH}/qamqp.pri) -include($${DEPTH}/tests/tests.pri) - -TARGET = tst_queues -SOURCES = tst_queues.cpp diff --git a/tests/auto/queues/tst_queues.cpp b/tests/auto/queues/tst_queues.cpp deleted file mode 100644 index 53a9448..0000000 --- a/tests/auto/queues/tst_queues.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -#include "amqp_client.h" -#include "amqp_queue.h" - -class tst_Queues : public QObject -{ - Q_OBJECT -private Q_SLOTS: - void declare(); - -}; - -void tst_Queues::declare() -{ - - - -} - -QTEST_MAIN(tst_Queues) -#include "tst_queues.moc"