diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-05-13 15:49:02 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-05-14 15:15:34 +0000 |
commit | e04667b55c2055200da93382dee44299293735a6 (patch) | |
tree | fcfcfcc8c6da4252584b50ad1a70f20d1be940a0 /tests | |
parent | 3d10238a8be9cecdf6850791d0520d17e33297a6 (diff) |
Improve the API of QCoapRequest
- Moved internally used methods to the private class.
- Replaced the internally used protected constructor with a static
method in the private class.
- Removed the internally used setMethod(), no need for it anymore.
- Removed the isValid() method, no point in keeping it.
This change is based on the feedback from API review.
Change-Id: I177efdb1d436266549dea3e8d2b01160648fce90
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qcoapclient/tst_qcoapclient.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp | 11 | ||||
-rw-r--r-- | tests/auto/qcoaprequest/tst_qcoaprequest.cpp | 22 |
4 files changed, 28 insertions, 28 deletions
diff --git a/tests/auto/qcoapclient/tst_qcoapclient.cpp b/tests/auto/qcoapclient/tst_qcoapclient.cpp index c7fce74..2b914ab 100644 --- a/tests/auto/qcoapclient/tst_qcoapclient.cpp +++ b/tests/auto/qcoapclient/tst_qcoapclient.cpp @@ -40,6 +40,7 @@ #include <private/qcoapclient_p.h> #include <private/qcoapqudpconnection_p.h> #include <private/qcoapprotocol_p.h> +#include <private/qcoaprequest_p.h> #include "../coapnetworksettings.h" @@ -273,7 +274,9 @@ void tst_QCoapClient::methods() } QVERIFY2(!reply.isNull(), "Request failed unexpectedly"); - QCOMPARE(reply->url(), QCoapRequest::adjustedUrl(url, false)); +#ifdef QT_BUILD_INTERNAL + QCOMPARE(reply->url(), QCoapRequestPrivate::adjustedUrl(url, false)); +#endif QSignalSpy spyReplyFinished(reply.data(), SIGNAL(finished(QCoapReply *))); QTRY_COMPARE(spyReplyFinished.count(), 1); QTRY_COMPARE(spyClientFinished.count(), 1); @@ -705,7 +708,9 @@ void tst_QCoapClient::discover() QTRY_COMPARE_WITH_TIMEOUT(spyReplyFinished.count(), 1, 30000); const auto discoverUrl = QUrl(url.toString() + "/.well-known/core"); - QCOMPARE(resourcesReply->url(), QCoapRequest::adjustedUrl(discoverUrl, false)); +#ifdef QT_BUILD_INTERNAL + QCOMPARE(resourcesReply->url(), QCoapRequestPrivate::adjustedUrl(discoverUrl, false)); +#endif QCOMPARE(resourcesReply->resources().length(), resourceNumber); QCOMPARE(resourcesReply->request().method(), QtCoap::Method::Get); @@ -771,7 +776,9 @@ void tst_QCoapClient::observe() QTRY_COMPARE_WITH_TIMEOUT(spyReplyNotified.count(), 3, 30000); client.cancelObserve(reply.data()); - QCOMPARE(reply->url(), QCoapRequest::adjustedUrl(url, false)); +#ifdef QT_BUILD_INTERNAL + QCOMPARE(reply->url(), QCoapRequestPrivate::adjustedUrl(url, false)); +#endif QCOMPARE(reply->request().method(), QtCoap::Method::Get); QVERIFY2(!spyReplyNotified.wait(7000), "'Notify' signal received after cancelling observe"); diff --git a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp index 1e5c732..1a1a293 100644 --- a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp +++ b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp @@ -33,6 +33,7 @@ #include <QtCoap/qcoaprequest.h> #include <private/qcoapinternalrequest_p.h> +#include <private/qcoaprequest_p.h> #ifdef QT_BUILD_INTERNAL @@ -53,12 +54,6 @@ private Q_SLOTS: void isMulticast(); }; -struct QCoapRequestForTest : public QCoapRequest -{ - QCoapRequestForTest(const QUrl& url) : QCoapRequest(url) {} - using QCoapRequest::setMethod; -}; - void tst_QCoapInternalRequest::requestToFrame_data() { QTest::addColumn<QUrl>("url"); @@ -153,9 +148,8 @@ void tst_QCoapInternalRequest::requestToFrame() QFETCH(QString, pduHeader); QFETCH(QString, pduPayload); - QCoapRequestForTest request(url); + QCoapRequest request = QCoapRequestPrivate::createRequest(QCoapRequest(url), method); request.setType(type); - request.setMethod(method); request.setPayload(pduPayload.toUtf8()); request.setMessageId(messageId); request.setToken(token); diff --git a/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp b/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp index 947cb5d..ee8c295 100644 --- a/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp +++ b/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp @@ -40,18 +40,13 @@ #include <QtCoap/qcoaprequest.h> #include <private/qcoapqudpconnection_p.h> #include <private/qcoapinternalrequest_p.h> +#include <private/qcoaprequest_p.h> #include "../coapnetworksettings.h" #ifdef QT_BUILD_INTERNAL using namespace QtCoapNetworkSettings; -struct QCoapRequestForTest : public QCoapRequest -{ - QCoapRequestForTest(const QUrl &url) : QCoapRequest(url) {} - using QCoapRequest::setMethod; -}; - class tst_QCoapQUdpConnection : public QObject { Q_OBJECT @@ -186,10 +181,10 @@ void tst_QCoapQUdpConnection::sendRequest() QSignalSpy spySocketReadyRead(connection.socket(), &QUdpSocket::readyRead); QSignalSpy spyConnectionReadyRead(&connection, &QCoapQUdpConnection::readyRead); - QCoapRequestForTest request(protocol + host + path); + QCoapRequest request = + QCoapRequestPrivate::createRequest(QCoapRequest(protocol + host + path), method); request.setMessageId(24806); request.setToken(QByteArray("abcd")); - request.setMethod(method); QVERIFY(connection.socket() != nullptr); QCoapInternalRequest internalRequest(request); connection.sendRequest(internalRequest.toQByteArray(), host, port); diff --git a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp index 592d4eb..2b042b5 100644 --- a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp +++ b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp @@ -34,6 +34,7 @@ #include <QtCoap/qcoapglobal.h> #include <QtCoap/qcoapnamespace.h> #include <QtCoap/qcoaprequest.h> +#include <private/qcoaprequest_p.h> class tst_QCoapRequest : public QObject { @@ -50,11 +51,6 @@ private Q_SLOTS: void copyAndDetach(); }; -struct QCoapRequestForTest : public QCoapRequest -{ - using QCoapRequest::setMethod; -}; - void tst_QCoapRequest::ctor_data() { QTest::addColumn<QUrl>("url"); @@ -103,13 +99,18 @@ void tst_QCoapRequest::adjustUrl_data() void tst_QCoapRequest::adjustUrl() { +#ifdef QT_BUILD_INTERNAL QFETCH(QUrl, inputUrl); QFETCH(QUrl, expectedUrl); QFETCH(bool, secure); - QCoapRequest request(inputUrl); - request.adjustUrl(secure); + // createRequest() will adjust the url + QCoapRequest request = QCoapRequestPrivate::createRequest(QCoapRequest(inputUrl), + QtCoap::Method::Get, secure); QCOMPARE(request.url(), expectedUrl); +#else + QSKIP("Not an internal build, skipping this test"); +#endif } void tst_QCoapRequest::setUrl_data() @@ -156,13 +157,13 @@ void tst_QCoapRequest::enableObserve() void tst_QCoapRequest::copyAndDetach() { - QCoapRequestForTest a; +#ifdef QT_BUILD_INTERNAL + QCoapRequest a = QCoapRequestPrivate::createRequest(QCoapRequest(), QtCoap::Method::Delete); a.setMessageId(3); a.setPayload("payload"); a.setToken("token"); a.setType(QCoapMessage::Type::Acknowledgment); a.setVersion(5); - a.setMethod(QtCoap::Method::Delete); QUrl testUrl("coap://url:500/resource"); a.setUrl(testUrl); QUrl testProxyUrl("test://proxyurl"); @@ -186,6 +187,9 @@ void tst_QCoapRequest::copyAndDetach() c.setMessageId(9); QCOMPARE(c.messageId(), 9); QCOMPARE(a.messageId(), 3); +#else + QSKIP("Not an internal build, skipping this test"); +#endif } QTEST_APPLESS_MAIN(tst_QCoapRequest) |