diff --git a/libguh/coap/coap.cpp b/libguh/coap/coap.cpp index b4abd3c3..819340e4 100644 --- a/libguh/coap/coap.cpp +++ b/libguh/coap/coap.cpp @@ -515,8 +515,8 @@ void Coap::processNotification(const CoapPdu &pdu, const QHostAddress &address, m_observeReplyResource.insert(m_observerReply, resource); m_observeBlockwise.insert(m_observerReply, notificationNumber); - connect(m_observerReply, &CoapReply::timeout, this, &Coap::onReplyTimeout); - connect(m_observerReply, &CoapReply::finished, this, &Coap::onReplyFinished); + connect(m_observerReply.data(), &CoapReply::timeout, this, &Coap::onReplyTimeout); + connect(m_observerReply.data(), &CoapReply::finished, this, &Coap::onReplyFinished); CoapPdu pdu; pdu.setMessageType(m_observerReply->request().messageType()); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9208234c..523016d7 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -17,5 +17,5 @@ SUBDIRS = versioning \ websocketserver \ logging \ restlogging \ - #coap \ + coap \ diff --git a/tests/auto/coap/coaptests.cpp b/tests/auto/coap/coaptests.cpp index 68bf3e10..072c1119 100644 --- a/tests/auto/coap/coaptests.cpp +++ b/tests/auto/coap/coaptests.cpp @@ -565,4 +565,60 @@ void CoapTests::coreLinkParser() 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) diff --git a/tests/auto/coap/coaptests.h b/tests/auto/coap/coaptests.h index 057b29c3..417ac0f6 100644 --- a/tests/auto/coap/coaptests.h +++ b/tests/auto/coap/coaptests.h @@ -80,6 +80,9 @@ private slots: void coreLinkParser(); + void observeResource(); + void observeLargeResource(); + }; #endif // COAPTESTS_H