fix coap lib and add observing tests
This commit is contained in:
parent
2ddf19b6da
commit
444a113c33
@ -515,8 +515,8 @@ void Coap::processNotification(const CoapPdu &pdu, const QHostAddress &address,
|
|||||||
m_observeReplyResource.insert(m_observerReply, resource);
|
m_observeReplyResource.insert(m_observerReply, resource);
|
||||||
m_observeBlockwise.insert(m_observerReply, notificationNumber);
|
m_observeBlockwise.insert(m_observerReply, notificationNumber);
|
||||||
|
|
||||||
connect(m_observerReply, &CoapReply::timeout, this, &Coap::onReplyTimeout);
|
connect(m_observerReply.data(), &CoapReply::timeout, this, &Coap::onReplyTimeout);
|
||||||
connect(m_observerReply, &CoapReply::finished, this, &Coap::onReplyFinished);
|
connect(m_observerReply.data(), &CoapReply::finished, this, &Coap::onReplyFinished);
|
||||||
|
|
||||||
CoapPdu pdu;
|
CoapPdu pdu;
|
||||||
pdu.setMessageType(m_observerReply->request().messageType());
|
pdu.setMessageType(m_observerReply->request().messageType());
|
||||||
|
|||||||
@ -17,5 +17,5 @@ SUBDIRS = versioning \
|
|||||||
websocketserver \
|
websocketserver \
|
||||||
logging \
|
logging \
|
||||||
restlogging \
|
restlogging \
|
||||||
#coap \
|
coap \
|
||||||
|
|
||||||
|
|||||||
@ -565,4 +565,60 @@ void CoapTests::coreLinkParser()
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoapTests::observeResource()
|
||||||
|
{
|
||||||
|
CoapRequest request(QUrl("coap://vs0.inf.ethz.ch/obs"));
|
||||||
|
qDebug() << request.url().toString();
|
||||||
|
|
||||||
|
QSignalSpy spy(m_coap, SIGNAL(replyFinished(CoapReply*)));
|
||||||
|
QSignalSpy notificationSpy(m_coap, SIGNAL(notificationReceived(CoapObserveResource,int,QByteArray)));
|
||||||
|
|
||||||
|
CoapReply *reply = m_coap->enableResourceNotifications(request);
|
||||||
|
spy.wait();
|
||||||
|
|
||||||
|
qDebug() << "====================================";
|
||||||
|
qDebug() << reply;
|
||||||
|
|
||||||
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
||||||
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
||||||
|
QCOMPARE(reply->statusCode(), CoapPdu::Content);
|
||||||
|
QCOMPARE(reply->error(), CoapReply::NoError);
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
notificationSpy.wait(6000);
|
||||||
|
QVERIFY2(notificationSpy.count() > 0, "Did not get a notification.");
|
||||||
|
qDebug() << notificationSpy.first();
|
||||||
|
m_coap->disableNotifications(request);
|
||||||
|
QTest::qWait(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoapTests::observeLargeResource()
|
||||||
|
{
|
||||||
|
CoapRequest request(QUrl("coap://vs0.inf.ethz.ch/obs-large"));
|
||||||
|
qDebug() << request.url().toString();
|
||||||
|
|
||||||
|
QSignalSpy spy(m_coap, SIGNAL(replyFinished(CoapReply*)));
|
||||||
|
QSignalSpy notificationSpy(m_coap, SIGNAL(notificationReceived(CoapObserveResource,int,QByteArray)));
|
||||||
|
|
||||||
|
CoapReply *reply = m_coap->enableResourceNotifications(request);
|
||||||
|
spy.wait();
|
||||||
|
|
||||||
|
qDebug() << "====================================";
|
||||||
|
qDebug() << reply;
|
||||||
|
|
||||||
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
||||||
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
||||||
|
QCOMPARE(reply->statusCode(), CoapPdu::Content);
|
||||||
|
QCOMPARE(reply->error(), CoapReply::NoError);
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
notificationSpy.wait(6000);
|
||||||
|
QVERIFY2(notificationSpy.count() > 0, "Did not get a notification.");
|
||||||
|
qDebug() << notificationSpy.first();
|
||||||
|
m_coap->disableNotifications(request);
|
||||||
|
QTest::qWait(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(CoapTests)
|
QTEST_MAIN(CoapTests)
|
||||||
|
|||||||
@ -80,6 +80,9 @@ private slots:
|
|||||||
|
|
||||||
void coreLinkParser();
|
void coreLinkParser();
|
||||||
|
|
||||||
|
void observeResource();
|
||||||
|
void observeLargeResource();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COAPTESTS_H
|
#endif // COAPTESTS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user