Commit c3a251e1189478306453d11d61c35fc06626be1e

Authored by Wiebe Cazemier
1 parent 0759ed08

Remove QMQTT from the test project

FlashMQTests/FlashMQTests.pro
1 QT += testlib 1 QT += testlib
2 QT -= gui 2 QT -= gui
3 QT += network 3 QT += network
4 -QT += qmqtt  
5 4
6 DEFINES += TESTING \ 5 DEFINES += TESTING \
7 "FLASHMQ_VERSION=\\\"0.0.0\\\"" 6 "FLASHMQ_VERSION=\\\"0.0.0\\\""
@@ -56,8 +55,7 @@ SOURCES += tst_maintests.cpp \ @@ -56,8 +55,7 @@ SOURCES += tst_maintests.cpp \
56 ../derivablecounter.cpp \ 55 ../derivablecounter.cpp \
57 ../packetdatatypes.cpp \ 56 ../packetdatatypes.cpp \
58 ../flashmqtestclient.cpp \ 57 ../flashmqtestclient.cpp \
59 - mainappthread.cpp \  
60 - twoclienttestcontext.cpp 58 + mainappthread.cpp
61 59
62 60
63 HEADERS += \ 61 HEADERS += \
@@ -104,8 +102,7 @@ HEADERS += \ @@ -104,8 +102,7 @@ HEADERS += \
104 ../derivablecounter.h \ 102 ../derivablecounter.h \
105 ../packetdatatypes.h \ 103 ../packetdatatypes.h \
106 ../flashmqtestclient.h \ 104 ../flashmqtestclient.h \
107 - mainappthread.h \  
108 - twoclienttestcontext.h 105 + mainappthread.h
109 106
110 LIBS += -ldl -lssl -lcrypto 107 LIBS += -ldl -lssl -lcrypto
111 108
FlashMQTests/tst_maintests.cpp
@@ -18,7 +18,6 @@ License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>. @@ -18,7 +18,6 @@ License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>.
18 #include <QtTest> 18 #include <QtTest>
19 19
20 20
21 -#include <QtQmqtt/qmqtt.h>  
22 #include <QScopedPointer> 21 #include <QScopedPointer>
23 #include <QHostInfo> 22 #include <QHostInfo>
24 #include <list> 23 #include <list>
@@ -27,7 +26,6 @@ License along with FlashMQ. If not, see &lt;https://www.gnu.org/licenses/&gt;. @@ -27,7 +26,6 @@ License along with FlashMQ. If not, see &lt;https://www.gnu.org/licenses/&gt;.
27 #include "cirbuf.h" 26 #include "cirbuf.h"
28 #include "mainapp.h" 27 #include "mainapp.h"
29 #include "mainappthread.h" 28 #include "mainappthread.h"
30 -#include "twoclienttestcontext.h"  
31 #include "threadlocalutils.h" 29 #include "threadlocalutils.h"
32 #include "retainedmessagesdb.h" 30 #include "retainedmessagesdb.h"
33 #include "sessionsandsubscriptionsdb.h" 31 #include "sessionsandsubscriptionsdb.h"
FlashMQTests/twoclienttestcontext.cpp deleted
1 -/*  
2 -This file is part of FlashMQ (https://www.flashmq.org)  
3 -Copyright (C) 2021 Wiebe Cazemier  
4 -  
5 -FlashMQ is free software: you can redistribute it and/or modify  
6 -it under the terms of the GNU Affero General Public License as  
7 -published by the Free Software Foundation, version 3.  
8 -  
9 -FlashMQ is distributed in the hope that it will be useful,  
10 -but WITHOUT ANY WARRANTY; without even the implied warranty of  
11 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
12 -GNU Affero General Public License for more details.  
13 -  
14 -You should have received a copy of the GNU Affero General Public  
15 -License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>.  
16 -*/  
17 -  
18 -#include "twoclienttestcontext.h"  
19 -  
20 -#include <QEventLoop>  
21 -#include <QTimer>  
22 -  
23 -// TODO: port to QMqttClient that newer Qts now have?  
24 -  
25 -TwoClientTestContext::TwoClientTestContext(int clientNr, QObject *parent) : QObject(parent)  
26 -{  
27 - QHostInfo targetHostInfo = QHostInfo::fromName("localhost");  
28 - QHostAddress targetHost(targetHostInfo.addresses().first());  
29 - sender.reset(new QMQTT::Client(targetHost, 21883));  
30 - sender->setClientId(QString("Sender%1").arg(clientNr));  
31 - receiver.reset(new QMQTT::Client(targetHost, 21883));  
32 - receiver->setClientId(QString("Receiver%1").arg(clientNr));  
33 -  
34 - connect(sender.data(), &QMQTT::Client::error, this, &TwoClientTestContext::onClientError);  
35 - connect(receiver.data(), &QMQTT::Client::error, this, &TwoClientTestContext::onClientError);  
36 -}  
37 -  
38 -void TwoClientTestContext::publish(const QString &topic, const QByteArray &payload)  
39 -{  
40 - publish(topic, payload, 0, false);  
41 -}  
42 -  
43 -void TwoClientTestContext::publish(const QString &topic, const QByteArray &payload, bool retain)  
44 -{  
45 - publish(topic, payload, 0, retain);  
46 -}  
47 -  
48 -void TwoClientTestContext::publish(const QString &topic, const QByteArray &payload, const quint8 qos, bool retain)  
49 -{  
50 - QMQTT::Message msg;  
51 - msg.setTopic(topic);  
52 - msg.setRetain(retain);  
53 - msg.setQos(qos);  
54 - msg.setPayload(payload);  
55 - sender->publish(msg);  
56 -}  
57 -  
58 -void TwoClientTestContext::connectSender()  
59 -{  
60 - sender->connectToHost();  
61 - QEventLoop waiter;  
62 - connect(sender.data(), &QMQTT::Client::connected, &waiter, &QEventLoop::quit);  
63 - waiter.exec();  
64 -}  
65 -  
66 -void TwoClientTestContext::connectReceiver()  
67 -{  
68 - connect(receiver.data(), &QMQTT::Client::received, this, &TwoClientTestContext::onReceiverReceived);  
69 -  
70 - receiver->connectToHost();  
71 - QEventLoop waiter;  
72 - connect(receiver.data(), &QMQTT::Client::connected, &waiter, &QEventLoop::quit);  
73 - waiter.exec();  
74 -}  
75 -  
76 -void TwoClientTestContext::disconnectReceiver()  
77 -{  
78 - receiver->disconnectFromHost();  
79 - QEventLoop waiter;  
80 - connect(sender.data(), &QMQTT::Client::disconnected, &waiter, &QEventLoop::quit);  
81 - waiter.exec();  
82 -}  
83 -  
84 -void TwoClientTestContext::subscribeReceiver(const QString &topic, const quint8 qos)  
85 -{  
86 - receiver->subscribe(topic, qos);  
87 -  
88 - QEventLoop waiter;  
89 - QTimer timeout;  
90 - timeout.setSingleShot(true);  
91 - timeout.setInterval(1000);  
92 - connect(&timeout, &QTimer::timeout, &waiter, &QEventLoop::quit);  
93 - connect(receiver.data(), &QMQTT::Client::subscribed, &waiter, &QEventLoop::quit);  
94 - timeout.start();  
95 - waiter.exec();  
96 -}  
97 -  
98 -void TwoClientTestContext::unsubscribeReceiver(const QString &topic)  
99 -{  
100 - receiver->unsubscribe(topic);  
101 -  
102 - QEventLoop waiter;  
103 - QTimer timeout;  
104 - timeout.setSingleShot(true);  
105 - timeout.setInterval(1000);  
106 - connect(&timeout, &QTimer::timeout, &waiter, &QEventLoop::quit);  
107 - connect(receiver.data(), &QMQTT::Client::unsubscribed, &waiter, &QEventLoop::quit);  
108 - timeout.start();  
109 - waiter.exec();  
110 -}  
111 -  
112 -void TwoClientTestContext::waitReceiverReceived(const int count)  
113 -{  
114 - if (count > 0 && receivedMessages.count() == count)  
115 - return;  
116 -  
117 - int attempt = 0;  
118 - while(receivedMessages.count() != count && attempt++ < count)  
119 - {  
120 - QEventLoop waiter;  
121 - QTimer timeout;  
122 - timeout.setSingleShot(true);  
123 - timeout.setInterval(3000);  
124 - connect(&timeout, &QTimer::timeout, &waiter, &QEventLoop::quit);  
125 - connect(receiver.data(), &QMQTT::Client::received, &waiter, &QEventLoop::quit);  
126 - timeout.start();  
127 - waiter.exec();  
128 - }  
129 -}  
130 -  
131 -void TwoClientTestContext::onClientError(const QMQTT::ClientError error)  
132 -{  
133 - const QMQTT::Client *_sender = sender.data();  
134 -  
135 - // TODO: arg, doesn't qmqtt have a better way for this?  
136 - QString errStr = QString("unknown error");  
137 - if (error == QMQTT::SocketConnectionRefusedError)  
138 - errStr = "Connection refused";  
139 - if (error == QMQTT::SocketRemoteHostClosedError)  
140 - errStr = "Remote host closed";  
141 - if (error == QMQTT::SocketHostNotFoundError)  
142 - errStr = "Remote host not found";  
143 - if (error == QMQTT::MqttBadUserNameOrPasswordError)  
144 - errStr = "MQTT bad user or password";  
145 - if (error == QMQTT::MqttNotAuthorizedError)  
146 - errStr = "MQTT not authorized";  
147 - if (error == QMQTT::SocketResourceError)  
148 - errStr = "Socket resource error. Is your OS limiting you? Ulimit, etc?";  
149 - if (error == QMQTT::SocketSslInternalError)  
150 - errStr = "Socket SSL internal error.";  
151 - if (error == QMQTT::SocketTimeoutError)  
152 - errStr = "Socket timeout";  
153 -  
154 - QString msg = QString("Client %1 error code: %2 (%3). Initiated delayed reconnect.\n").arg(_sender->clientId()).arg(error).arg(errStr);  
155 - throw std::runtime_error(msg.toStdString());  
156 -}  
157 -  
158 -void TwoClientTestContext::onReceiverReceived(const QMQTT::Message &message)  
159 -{  
160 - receivedMessages.append(message);  
161 -}  
FlashMQTests/twoclienttestcontext.h deleted
1 -/*  
2 -This file is part of FlashMQ (https://www.flashmq.org)  
3 -Copyright (C) 2021 Wiebe Cazemier  
4 -  
5 -FlashMQ is free software: you can redistribute it and/or modify  
6 -it under the terms of the GNU Affero General Public License as  
7 -published by the Free Software Foundation, version 3.  
8 -  
9 -FlashMQ is distributed in the hope that it will be useful,  
10 -but WITHOUT ANY WARRANTY; without even the implied warranty of  
11 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
12 -GNU Affero General Public License for more details.  
13 -  
14 -You should have received a copy of the GNU Affero General Public  
15 -License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>.  
16 -*/  
17 -  
18 -#ifndef RETAINTESTCONTEXT_H  
19 -#define RETAINTESTCONTEXT_H  
20 -  
21 -#include <QObject>  
22 -#include <QtQmqtt/qmqtt.h>  
23 -#include <QHostInfo>  
24 -  
25 -class TwoClientTestContext : public QObject  
26 -{  
27 - Q_OBJECT  
28 -  
29 - QScopedPointer<QMQTT::Client> sender;  
30 - QScopedPointer<QMQTT::Client> receiver;  
31 -  
32 -private slots:  
33 - void onReceiverReceived(const QMQTT::Message& message);  
34 -  
35 -public:  
36 - explicit TwoClientTestContext(int clientNr = 0, QObject *parent = nullptr);  
37 - void publish(const QString &topic, const QByteArray &payload);  
38 - void publish(const QString &topic, const QByteArray &payload, bool retain);  
39 - void publish(const QString &topic, const QByteArray &payload, const quint8 qos, bool retain);  
40 - void connectSender();  
41 - void connectReceiver();  
42 - void disconnectReceiver();  
43 - void subscribeReceiver(const QString &topic, const quint8 qos = 0);  
44 - void unsubscribeReceiver(const QString &topic);  
45 - void waitReceiverReceived(const int count);  
46 - void onClientError(const QMQTT::ClientError error);  
47 -  
48 - QList<QMQTT::Message> receivedMessages;  
49 -  
50 -signals:  
51 -  
52 -};  
53 -  
54 -#endif // RETAINTESTCONTEXT_H