|
|
|
|
@ -74,9 +74,6 @@ void CoapTests::invalidUrl()
|
|
|
|
|
CoapReply *reply = m_coap->get(request);
|
|
|
|
|
spy.wait();
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(reply->isFinished(), "Reply not finished.");
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->error(), CoapReply::HostNotFoundError);
|
|
|
|
|
@ -85,14 +82,50 @@ void CoapTests::invalidUrl()
|
|
|
|
|
void CoapTests::invalidScheme()
|
|
|
|
|
{
|
|
|
|
|
CoapRequest request(QUrl("http://coap.me"));
|
|
|
|
|
qDebug() << request.url().toString();
|
|
|
|
|
|
|
|
|
|
QSignalSpy spy(m_coap, SIGNAL(replyFinished(CoapReply*)));
|
|
|
|
|
|
|
|
|
|
// Get
|
|
|
|
|
CoapReply *reply = m_coap->get(request);
|
|
|
|
|
spy.wait(1000);
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
QVERIFY2(reply->isFinished(), "Reply not finished.");
|
|
|
|
|
QVERIFY2(spy.count() == 0, "Got a response.");
|
|
|
|
|
QCOMPARE(reply->error(), CoapReply::InvalidUrlSchemeError);
|
|
|
|
|
|
|
|
|
|
reply->deleteLater();
|
|
|
|
|
|
|
|
|
|
// Post
|
|
|
|
|
spy.clear();
|
|
|
|
|
reply = m_coap->post(request);
|
|
|
|
|
spy.wait(1000);
|
|
|
|
|
|
|
|
|
|
QVERIFY2(reply->isFinished(), "Reply not finished.");
|
|
|
|
|
QVERIFY2(spy.count() == 0, "Got a response.");
|
|
|
|
|
QCOMPARE(reply->error(), CoapReply::InvalidUrlSchemeError);
|
|
|
|
|
|
|
|
|
|
// Put
|
|
|
|
|
spy.clear();
|
|
|
|
|
reply = m_coap->put(request);
|
|
|
|
|
spy.wait(1000);
|
|
|
|
|
|
|
|
|
|
QVERIFY2(reply->isFinished(), "Reply not finished.");
|
|
|
|
|
QVERIFY2(spy.count() == 0, "Got a response.");
|
|
|
|
|
QCOMPARE(reply->error(), CoapReply::InvalidUrlSchemeError);
|
|
|
|
|
|
|
|
|
|
// Delete
|
|
|
|
|
spy.clear();
|
|
|
|
|
reply = m_coap->deleteResource(request);
|
|
|
|
|
spy.wait(1000);
|
|
|
|
|
|
|
|
|
|
QVERIFY2(reply->isFinished(), "Reply not finished.");
|
|
|
|
|
QVERIFY2(spy.count() == 0, "Got a response.");
|
|
|
|
|
QCOMPARE(reply->error(), CoapReply::InvalidUrlSchemeError);
|
|
|
|
|
|
|
|
|
|
// Ping
|
|
|
|
|
spy.clear();
|
|
|
|
|
reply = m_coap->ping(request);
|
|
|
|
|
spy.wait(1000);
|
|
|
|
|
|
|
|
|
|
QVERIFY2(reply->isFinished(), "Reply not finished.");
|
|
|
|
|
QVERIFY2(spy.count() == 0, "Got a response.");
|
|
|
|
|
@ -101,16 +134,14 @@ void CoapTests::invalidScheme()
|
|
|
|
|
|
|
|
|
|
void CoapTests::ping()
|
|
|
|
|
{
|
|
|
|
|
CoapRequest request(QUrl("coap://coap.me/"));
|
|
|
|
|
CoapRequest request;
|
|
|
|
|
request.setUrl(QUrl("coap://coap.me/"));
|
|
|
|
|
qDebug() << request.url().toString();
|
|
|
|
|
|
|
|
|
|
QSignalSpy spy(m_coap, SIGNAL(replyFinished(CoapReply*)));
|
|
|
|
|
CoapReply *reply = m_coap->ping(request);
|
|
|
|
|
spy.wait();
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(reply->isFinished(), "Reply not finished.");
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Empty);
|
|
|
|
|
@ -122,15 +153,14 @@ void CoapTests::ping()
|
|
|
|
|
void CoapTests::hello()
|
|
|
|
|
{
|
|
|
|
|
CoapRequest request(QUrl("coap://coap.me/hello"));
|
|
|
|
|
request.setMessageType(CoapPdu::Confirmable);
|
|
|
|
|
|
|
|
|
|
qDebug() << request.url().toString();
|
|
|
|
|
|
|
|
|
|
QSignalSpy spy(m_coap, SIGNAL(replyFinished(CoapReply*)));
|
|
|
|
|
CoapReply *reply = m_coap->get(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);
|
|
|
|
|
@ -149,9 +179,6 @@ void CoapTests::broken()
|
|
|
|
|
CoapReply *reply = m_coap->get(request);
|
|
|
|
|
spy.wait();
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::InternalServerError);
|
|
|
|
|
@ -170,9 +197,6 @@ void CoapTests::query()
|
|
|
|
|
CoapReply *reply = m_coap->get(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);
|
|
|
|
|
@ -191,9 +215,6 @@ void CoapTests::subPath()
|
|
|
|
|
CoapReply *reply = m_coap->get(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);
|
|
|
|
|
@ -212,9 +233,6 @@ void CoapTests::extendedOptionLength()
|
|
|
|
|
CoapReply *reply = m_coap->get(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);
|
|
|
|
|
@ -233,9 +251,6 @@ void CoapTests::specialCharacters()
|
|
|
|
|
CoapReply *reply = m_coap->get(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);
|
|
|
|
|
@ -268,9 +283,6 @@ void CoapTests::extendedDelta()
|
|
|
|
|
CoapReply *reply = m_coap->get(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);
|
|
|
|
|
@ -289,9 +301,6 @@ void CoapTests::secret()
|
|
|
|
|
CoapReply *reply = m_coap->get(request);
|
|
|
|
|
spy.wait();
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Unauthorized);
|
|
|
|
|
@ -310,9 +319,6 @@ void CoapTests::separated()
|
|
|
|
|
CoapReply *reply = m_coap->get(request);
|
|
|
|
|
spy.wait(10000);
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Content);
|
|
|
|
|
@ -331,9 +337,6 @@ void CoapTests::deleteResource()
|
|
|
|
|
CoapReply *reply = m_coap->deleteResource(request);
|
|
|
|
|
spy.wait();
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Deleted);
|
|
|
|
|
@ -346,15 +349,13 @@ void CoapTests::deleteResource()
|
|
|
|
|
void CoapTests::post()
|
|
|
|
|
{
|
|
|
|
|
CoapRequest request(QUrl("coap://coap.me:5683/validate"));
|
|
|
|
|
request.setContentType();
|
|
|
|
|
qDebug() << request.url().toString();
|
|
|
|
|
|
|
|
|
|
QSignalSpy spy(m_coap, SIGNAL(replyFinished(CoapReply*)));
|
|
|
|
|
CoapReply *reply = m_coap->post(request, "guh is awesome");
|
|
|
|
|
spy.wait();
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Created);
|
|
|
|
|
@ -373,9 +374,6 @@ void CoapTests::put()
|
|
|
|
|
CoapReply *reply = m_coap->put(request, "guh is awesome");
|
|
|
|
|
spy.wait();
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Changed);
|
|
|
|
|
@ -419,9 +417,6 @@ void CoapTests::largeDownload()
|
|
|
|
|
CoapReply *reply = m_coap->get(request);
|
|
|
|
|
spy.wait(20000);
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Content);
|
|
|
|
|
@ -442,9 +437,6 @@ void CoapTests::largeCreate()
|
|
|
|
|
CoapReply *reply = m_coap->post(request, m_uploadData);
|
|
|
|
|
spy.wait(20000);
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Created);
|
|
|
|
|
@ -459,9 +451,6 @@ void CoapTests::largeCreate()
|
|
|
|
|
reply = m_coap->get(request);
|
|
|
|
|
spy.wait(20000);
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Content);
|
|
|
|
|
@ -482,9 +471,6 @@ void CoapTests::largeUpdate()
|
|
|
|
|
CoapReply *reply = m_coap->put(request, m_uploadData);
|
|
|
|
|
spy.wait(20000);
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Changed);
|
|
|
|
|
@ -499,9 +485,6 @@ void CoapTests::largeUpdate()
|
|
|
|
|
reply = m_coap->get(request);
|
|
|
|
|
spy.wait(20000);
|
|
|
|
|
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
|
|
|
|
|
QVERIFY2(spy.count() > 0, "Did not get a response.");
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->statusCode(), CoapPdu::Content);
|
|
|
|
|
@ -531,8 +514,6 @@ void CoapTests::multipleCalls()
|
|
|
|
|
spy.clear();
|
|
|
|
|
|
|
|
|
|
foreach (CoapReply *reply, replies) {
|
|
|
|
|
qDebug() << "====================================";
|
|
|
|
|
qDebug() << reply;
|
|
|
|
|
QCOMPARE(reply->messageType(), CoapPdu::Acknowledgement);
|
|
|
|
|
QCOMPARE(reply->error(), CoapReply::NoError);
|
|
|
|
|
reply->deleteLater();
|
|
|
|
|
@ -550,9 +531,6 @@ void CoapTests::coreLinkParser()
|
|
|
|
|
CoapReply *reply = m_coap->get(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);
|
|
|
|
|
@ -562,6 +540,10 @@ void CoapTests::coreLinkParser()
|
|
|
|
|
CoreLinkParser parser(reply->payload());
|
|
|
|
|
QCOMPARE(parser.links().count(), 28);
|
|
|
|
|
|
|
|
|
|
foreach (const CoreLink &link, parser.links()) {
|
|
|
|
|
qDebug() << link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -576,9 +558,6 @@ void CoapTests::observeResource()
|
|
|
|
|
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);
|
|
|
|
|
@ -603,9 +582,6 @@ void CoapTests::observeLargeResource()
|
|
|
|
|
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);
|
|
|
|
|
@ -619,6 +595,4 @@ void CoapTests::observeLargeResource()
|
|
|
|
|
QTest::qWait(5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTEST_MAIN(CoapTests)
|
|
|
|
|
|