diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-05-04 03:02:23 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-05-04 03:02:23 +0200 |
commit | bad7ee3d4f329ad258b4ceacdb3818084208cf5f (patch) | |
tree | b2b2e5dfe98143f357eca7b05a0406c41ef33fa6 | |
parent | 2050395003076fea84a8bdcc3948e8b50262a39c (diff) | |
parent | 18289e7c1d2778460dccb1135fe283bd234954ad (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: I92c022cdbcba00b16d33bcbe6bcddbf525a796b0
34 files changed, 247 insertions, 234 deletions
diff --git a/examples/coap/consolecoapclient/coaphandler.cpp b/examples/coap/consolecoapclient/coaphandler.cpp index 04ef6f3..650cf5c 100644 --- a/examples/coap/consolecoapclient/coaphandler.cpp +++ b/examples/coap/consolecoapclient/coaphandler.cpp @@ -88,7 +88,7 @@ bool CoapHandler::runDiscover(const QUrl &url) void CoapHandler::onFinished(QCoapReply *reply) { - if (reply->errorReceived() == QtCoap::NoError) + if (reply->errorReceived() == QtCoap::Error::Ok) qCInfo(lcCoapClient) << "Request finished with payload:" << reply->readAll(); else qCWarning(lcCoapClient, "Request failed"); @@ -116,7 +116,7 @@ void CoapHandler::onDiscovered(QCoapDiscoveryReply *reply, QVector<QCoapResource void CoapHandler::onResponseToMulticast(QCoapReply *reply, const QCoapMessage& message, const QHostAddress &sender) { - if (reply->errorReceived() == QtCoap::NoError) + if (reply->errorReceived() == QtCoap::Error::Ok) qCInfo(lcCoapClient) << "Got a response for multicast request from:" << sender.toString() << "with payload:" << message.payload(); else diff --git a/examples/coap/quickmulticastclient/main.qml b/examples/coap/quickmulticastclient/main.qml index da28624..85fc8dc 100644 --- a/examples/coap/quickmulticastclient/main.qml +++ b/examples/coap/quickmulticastclient/main.qml @@ -102,17 +102,17 @@ Window { ListElement { group: qsTr("IPv4 CoAP Nodes") address: "224.0.1.187" - value: QtCoap.AllCoapNodesIPv4 + value: QtCoap.MulticastGroup.AllCoapNodesIPv4 } ListElement { group: qsTr("IPv6 Link Local CoAP Nodes") address: "ff02::fd" - value: QtCoap.AllCoapNodesIPv6LinkLocal + value: QtCoap.MulticastGroup.AllCoapNodesIPv6LinkLocal } ListElement { group: qsTr("IPv6 Site Local CoAP Nodes") address: "ff05::fd" - value: QtCoap.AllCoapNodesIPv6SiteLocal + value: QtCoap.MulticastGroup.AllCoapNodesIPv6SiteLocal } ListElement { group: qsTr("Other") diff --git a/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp b/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp index 6d0a1fd..4c3592b 100644 --- a/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp +++ b/examples/coap/quickmulticastclient/qmlcoapmulticastclient.cpp @@ -56,7 +56,7 @@ Q_LOGGING_CATEGORY(lcCoapClient, "qt.coap.client") QmlCoapMulticastClient::QmlCoapMulticastClient(QObject *parent) - : QCoapClient(QtCoap::NoSec, parent) + : QCoapClient(QtCoap::SecurityMode::NoSec, parent) { connect(this, &QCoapClient::finished, this, [this](QCoapReply *reply) { diff --git a/examples/coap/quicksecureclient/main.qml b/examples/coap/quicksecureclient/main.qml index 13eb478..34803a3 100644 --- a/examples/coap/quicksecureclient/main.qml +++ b/examples/coap/quicksecureclient/main.qml @@ -114,9 +114,9 @@ Window { id: securityModeGroup onClicked: { if (securityModeGroup.checkedButton === preSharedMode) - client.setSecurityMode(QtCoap.PreSharedKey); + client.setSecurityMode(QtCoap.SecurityMode.PreSharedKey); else - client.setSecurityMode(QtCoap.Certificate); + client.setSecurityMode(QtCoap.SecurityMode.Certificate); } } RowLayout { diff --git a/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp b/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp index 3dda7b0..608ed0c 100644 --- a/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp +++ b/examples/coap/quicksecureclient/qmlcoapsecureclient.cpp @@ -61,7 +61,7 @@ Q_LOGGING_CATEGORY(lcCoapClient, "qt.coap.client") QmlCoapSecureClient::QmlCoapSecureClient(QObject *parent) : QObject(parent) , m_coapClient(nullptr) - , m_securityMode(QtCoap::NoSec) + , m_securityMode(QtCoap::SecurityMode::NoSec) { } @@ -75,7 +75,7 @@ QmlCoapSecureClient::~QmlCoapSecureClient() static QString errorMessage(QtCoap::Error errorCode) { - const auto error = QMetaEnum::fromType<QtCoap::Error>().valueToKey(errorCode); + const auto error = QMetaEnum::fromType<QtCoap::Error>().valueToKey(static_cast<int>(errorCode)); return QString("Request failed with error: %1\n").arg(error); } @@ -95,7 +95,7 @@ void QmlCoapSecureClient::setSecurityMode(QtCoap::SecurityMode mode) [this](QCoapReply *reply) { if (!reply) emit finished("Something went wrong, received a null reply"); - else if (reply->errorReceived() != QtCoap::NoError) + else if (reply->errorReceived() != QtCoap::Error::Ok) emit finished(errorMessage(reply->errorReceived())); else emit finished(reply->message().payload()); diff --git a/examples/coap/simplecoapclient/mainwindow.cpp b/examples/coap/simplecoapclient/mainwindow.cpp index 193e3e2..e5cda55 100644 --- a/examples/coap/simplecoapclient/mainwindow.cpp +++ b/examples/coap/simplecoapclient/mainwindow.cpp @@ -65,16 +65,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { - m_client = new QCoapClient(QtCoap::NoSec, this); + m_client = new QCoapClient(QtCoap::SecurityMode::NoSec, this); connect(m_client, &QCoapClient::finished, this, &MainWindow::onFinished); connect(m_client, &QCoapClient::error, this, &MainWindow::onError); ui->setupUi(this); - ui->methodComboBox->addItem("Get", QtCoap::Method::Get); - ui->methodComboBox->addItem("Put", QtCoap::Method::Put); - ui->methodComboBox->addItem("Post", QtCoap::Method::Post); - ui->methodComboBox->addItem("Delete", QtCoap::Method::Delete); + ui->methodComboBox->addItem("Get", QVariant::fromValue(QtCoap::Method::Get)); + ui->methodComboBox->addItem("Put", QVariant::fromValue(QtCoap::Method::Put)); + ui->methodComboBox->addItem("Post", QVariant::fromValue(QtCoap::Method::Post)); + ui->methodComboBox->addItem("Delete", QVariant::fromValue(QtCoap::Method::Delete)); fillHostSelector(); ui->hostComboBox->setFocus(); @@ -106,13 +106,13 @@ void MainWindow::addMessage(const QString &message, bool isError) void MainWindow::onFinished(QCoapReply *reply) { - if (reply->errorReceived() == QtCoap::NoError) + if (reply->errorReceived() == QtCoap::Error::Ok) addMessage(reply->message().payload()); } static QString errorMessage(QtCoap::Error errorCode) { - const auto error = QMetaEnum::fromType<QtCoap::Error>().valueToKey(errorCode); + const auto error = QMetaEnum::fromType<QtCoap::Error>().valueToKey(static_cast<int>(errorCode)); return QString("Request failed with error: %1\n").arg(error); } @@ -124,7 +124,7 @@ void MainWindow::onError(QCoapReply *reply, QtCoap::Error error) void MainWindow::onDiscovered(QCoapDiscoveryReply *reply, QVector<QCoapResource> resources) { - if (reply->errorReceived() != QtCoap::NoError) + if (reply->errorReceived() != QtCoap::Error::Ok) return; QString message; @@ -138,7 +138,7 @@ void MainWindow::onDiscovered(QCoapDiscoveryReply *reply, QVector<QCoapResource> void MainWindow::onNotified(QCoapReply *reply, const QCoapMessage &message) { - if (reply->errorReceived() == QtCoap::NoError) + if (reply->errorReceived() == QtCoap::Error::Ok) addMessage("Received observe notification with payload: " + message.payload()); } @@ -154,8 +154,8 @@ static QString tryToResolveHostName(const QString hostName) void MainWindow::on_runButton_clicked() { - const auto msgType = ui->msgTypeCheckBox->isChecked() ? QCoapMessage::Confirmable - : QCoapMessage::NonConfirmable; + const auto msgType = ui->msgTypeCheckBox->isChecked() ? QCoapMessage::MessageType::Confirmable + : QCoapMessage::MessageType::NonConfirmable; QUrl url; url.setHost(tryToResolveHostName(ui->hostComboBox->currentText())); url.setPort(ui->portSpinBox->value()); @@ -168,16 +168,16 @@ void MainWindow::on_runButton_clicked() const auto method = ui->methodComboBox->currentData(Qt::UserRole).value<QtCoap::Method>(); switch (method) { - case QtCoap::Get: + case QtCoap::Method::Get: m_client->get(request); break; - case QtCoap::Put: + case QtCoap::Method::Put: m_client->put(request, m_currentData); break; - case QtCoap::Post: + case QtCoap::Method::Post: m_client->post(request, m_currentData); break; - case QtCoap::Delete: + case QtCoap::Method::Delete: m_client->deleteResource(request); break; default: @@ -255,5 +255,5 @@ void MainWindow::on_methodComboBox_currentIndexChanged(int index) Q_UNUSED(index); const auto method = ui->methodComboBox->currentData(Qt::UserRole).value<QtCoap::Method>(); - ui->contentButton->setEnabled(method == QtCoap::Put || method == QtCoap::Post); + ui->contentButton->setEnabled(method == QtCoap::Method::Put || method == QtCoap::Method::Post); } diff --git a/src/coap/qcoapclient.cpp b/src/coap/qcoapclient.cpp index dced30e..767f7f0 100644 --- a/src/coap/qcoapclient.cpp +++ b/src/coap/qcoapclient.cpp @@ -236,7 +236,7 @@ QCoapReply *QCoapClient::get(const QCoapRequest &request) { Q_D(QCoapClient); - QCoapRequest copyRequest(request, QtCoap::Get); + QCoapRequest copyRequest(request, QtCoap::Method::Get); copyRequest.adjustUrl(d->connection->isSecure()); return d->sendRequest(copyRequest); @@ -265,7 +265,7 @@ QCoapReply *QCoapClient::put(const QCoapRequest &request, const QByteArray &data { Q_D(QCoapClient); - QCoapRequest copyRequest(request, QtCoap::Put); + QCoapRequest copyRequest(request, QtCoap::Method::Put); copyRequest.setPayload(data); copyRequest.adjustUrl(d->connection->isSecure()); @@ -311,7 +311,7 @@ QCoapReply *QCoapClient::post(const QCoapRequest &request, const QByteArray &dat { Q_D(QCoapClient); - QCoapRequest copyRequest(request, QtCoap::Post); + QCoapRequest copyRequest(request, QtCoap::Method::Post); copyRequest.setPayload(data); copyRequest.adjustUrl(d->connection->isSecure()); @@ -360,7 +360,7 @@ QCoapReply *QCoapClient::deleteResource(const QCoapRequest &request) { Q_D(QCoapClient); - QCoapRequest copyRequest(request, QtCoap::Delete); + QCoapRequest copyRequest(request, QtCoap::Method::Delete); copyRequest.adjustUrl(d->connection->isSecure()); return d->sendRequest(copyRequest); @@ -400,13 +400,13 @@ QCoapDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group, int por QString base; switch (group) { - case QtCoap::AllCoapNodesIPv4: + case QtCoap::MulticastGroup::AllCoapNodesIPv4: base = QStringLiteral("224.0.1.187"); break; - case QtCoap::AllCoapNodesIPv6LinkLocal: + case QtCoap::MulticastGroup::AllCoapNodesIPv6LinkLocal: base = QStringLiteral("ff02::fd"); break; - case QtCoap::AllCoapNodesIPv6SiteLocal: + case QtCoap::MulticastGroup::AllCoapNodesIPv6SiteLocal: base = QStringLiteral("ff05::fd"); break; } @@ -417,7 +417,7 @@ QCoapDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group, int por discoveryUrl.setPort(port); QCoapRequest request(discoveryUrl); - request.setMethod(QtCoap::Get); + request.setMethod(QtCoap::Method::Get); request.adjustUrl(d->connection->isSecure()); return d->sendDiscovery(request); @@ -443,7 +443,7 @@ QCoapDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &disco discoveryUrl.setPath(url.path() + discoveryPath); QCoapRequest request(discoveryUrl); - request.setMethod(QtCoap::Get); + request.setMethod(QtCoap::Method::Get); request.adjustUrl(d->connection->isSecure()); return d->sendDiscovery(request); @@ -458,7 +458,7 @@ QCoapDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &disco */ QCoapReply *QCoapClient::observe(const QCoapRequest &request) { - QCoapRequest copyRequest(request, QtCoap::Get); + QCoapRequest copyRequest(request, QtCoap::Method::Get); copyRequest.enableObserve(); return get(copyRequest); @@ -579,7 +579,7 @@ bool QCoapClientPrivate::send(QCoapReply *reply) // According to https://tools.ietf.org/html/rfc7252#section-8.1, // multicast requests MUST be Non-confirmable. if (QHostAddress(reply->url().host()).isMulticast() - && reply->request().type() == QCoapMessage::Confirmable) { + && reply->request().type() == QCoapMessage::MessageType::Confirmable) { qCWarning(lcCoapClient, "Failed to send request, " "multicast requests must be non-confirmable."); return false; diff --git a/src/coap/qcoapclient.h b/src/coap/qcoapclient.h index 4645c4c..fb06903 100644 --- a/src/coap/qcoapclient.h +++ b/src/coap/qcoapclient.h @@ -53,7 +53,7 @@ class Q_COAP_EXPORT QCoapClient : public QObject { Q_OBJECT public: - explicit QCoapClient(QtCoap::SecurityMode securityMode = QtCoap::NoSec, + explicit QCoapClient(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSec, QObject *parent = nullptr); explicit QCoapClient(QCoapConnection *connection, QObject *parent = nullptr); ~QCoapClient(); @@ -74,7 +74,7 @@ public: void cancelObserve(const QUrl &url); void disconnect(); - QCoapDiscoveryReply *discover(QtCoap::MulticastGroup group = QtCoap::AllCoapNodesIPv4, + QCoapDiscoveryReply *discover(QtCoap::MulticastGroup group = QtCoap::MulticastGroup::AllCoapNodesIPv4, int port = QtCoap::DefaultPort, const QString &discoveryPath = QLatin1String("/.well-known/core")); QCoapDiscoveryReply *discover(const QUrl &baseUrl, diff --git a/src/coap/qcoapconnection.cpp b/src/coap/qcoapconnection.cpp index 7ee529a..96e98fa 100644 --- a/src/coap/qcoapconnection.cpp +++ b/src/coap/qcoapconnection.cpp @@ -120,7 +120,7 @@ Q_LOGGING_CATEGORY(lcCoapConnection, "qt.coap.connection") QCoapConnectionPrivate::QCoapConnectionPrivate(QtCoap::SecurityMode security) : securityMode(security) - , state(QCoapConnection::Unconnected) + , state(QCoapConnection::ConnectionState::Unconnected) {} /*! @@ -145,7 +145,7 @@ QCoapConnection::QCoapConnection(QObjectPrivate &dd, QObject *parent) connect(this, &QCoapConnection::bound, this, [this]() { Q_D(QCoapConnection); - d->state = QCoapConnection::Bound; + d->state = ConnectionState::Bound; startToSendRequest(); }); } @@ -187,7 +187,7 @@ QCoapConnectionPrivate::sendRequest(const QByteArray &request, const QString &ho bool QCoapConnection::isSecure() const { Q_D(const QCoapConnection); - return d->securityMode != QtCoap::NoSec; + return d->securityMode != QtCoap::SecurityMode::NoSec; } /*! @@ -262,7 +262,7 @@ void QCoapConnection::disconnect() close(); d->framesToSend.clear(); - d->state = QCoapConnection::Unconnected; + d->state = ConnectionState::Unconnected; } QT_END_NAMESPACE diff --git a/src/coap/qcoapconnection.h b/src/coap/qcoapconnection.h index 017053b..6f2931f 100644 --- a/src/coap/qcoapconnection.h +++ b/src/coap/qcoapconnection.h @@ -43,18 +43,18 @@ class Q_COAP_EXPORT QCoapConnection : public QObject { Q_OBJECT public: - enum ConnectionState { + enum class ConnectionState : quint8 { Unconnected, Bound }; - explicit QCoapConnection(QtCoap::SecurityMode securityMode = QtCoap::NoSec, + explicit QCoapConnection(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSec, QObject *parent = nullptr); virtual ~QCoapConnection(); bool isSecure() const; QtCoap::SecurityMode securityMode() const; - QCoapConnection::ConnectionState state() const; + ConnectionState state() const; QCoapSecurityConfiguration securityConfiguration() const; Q_INVOKABLE void setSecurityConfiguration(const QCoapSecurityConfiguration &configuration); diff --git a/src/coap/qcoapconnection_p.h b/src/coap/qcoapconnection_p.h index 90535ca..d75c794 100644 --- a/src/coap/qcoapconnection_p.h +++ b/src/coap/qcoapconnection_p.h @@ -60,7 +60,7 @@ struct CoapFrame { class Q_AUTOTEST_EXPORT QCoapConnectionPrivate : public QObjectPrivate { public: - QCoapConnectionPrivate(QtCoap::SecurityMode security = QtCoap::NoSec); + QCoapConnectionPrivate(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSec); ~QCoapConnectionPrivate() override = default; diff --git a/src/coap/qcoapinternalreply_p.h b/src/coap/qcoapinternalreply_p.h index db9a052..f144b47 100644 --- a/src/coap/qcoapinternalreply_p.h +++ b/src/coap/qcoapinternalreply_p.h @@ -78,7 +78,7 @@ class Q_AUTOTEST_EXPORT QCoapInternalReplyPrivate : public QCoapInternalMessageP public: QCoapInternalReplyPrivate() = default; - QtCoap::ResponseCode responseCode = QtCoap::InvalidCode; + QtCoap::ResponseCode responseCode = QtCoap::ResponseCode::InvalidCode; QHostAddress senderAddress; }; diff --git a/src/coap/qcoapinternalrequest.cpp b/src/coap/qcoapinternalrequest.cpp index b8eb51e..2e10432 100644 --- a/src/coap/qcoapinternalrequest.cpp +++ b/src/coap/qcoapinternalrequest.cpp @@ -97,7 +97,7 @@ QCoapInternalRequest::QCoapInternalRequest(const QCoapRequest &request, QObject bool QCoapInternalRequest::isValid() const { Q_D(const QCoapInternalRequest); - return isUrlValid(d->targetUri) && d->method != QtCoap::Invalid; + return isUrlValid(d->targetUri) && d->method != QtCoap::Method::Invalid; } /*! @@ -110,8 +110,8 @@ void QCoapInternalRequest::initForAcknowledgment(quint16 messageId, const QByteA { Q_D(QCoapInternalRequest); - setMethod(QtCoap::Invalid); - d->message.setType(QCoapMessage::Acknowledgment); + setMethod(QtCoap::Method::Invalid); + d->message.setType(QCoapMessage::MessageType::Acknowledgment); d->message.setMessageId(messageId); d->message.setToken(token); d->message.setPayload(QByteArray()); @@ -129,8 +129,8 @@ void QCoapInternalRequest::initForReset(quint16 messageId) { Q_D(QCoapInternalRequest); - setMethod(QtCoap::Invalid); - d->message.setType(QCoapMessage::Reset); + setMethod(QtCoap::Method::Invalid); + d->message.setType(QCoapMessage::MessageType::Reset); d->message.setMessageId(messageId); d->message.setToken(QByteArray()); d->message.setPayload(QByteArray()); @@ -171,12 +171,12 @@ QByteArray QCoapInternalRequest::toQByteArray() const QByteArray pdu; // Insert header - appendByte(&pdu, (d->message.version() << 6) // CoAP version - | (d->message.type() << 4) // Message type - | d->message.token().length()); // Token Length - appendByte(&pdu, d->method & 0xFF); // Method code - appendByte(&pdu, (d->message.messageId() >> 8) & 0xFF); // Message ID - appendByte(&pdu, d->message.messageId() & 0xFF); + appendByte(&pdu, (d->message.version() << 6) // CoAP version + | (static_cast<quint8>(d->message.type()) << 4) // Message type + | d->message.token().length()); // Token Length + appendByte(&pdu, static_cast<quint8>(d->method) & 0xFF); // Method code + appendByte(&pdu, (d->message.messageId() >> 8) & 0xFF); // Message ID + appendByte(&pdu, d->message.messageId() & 0xFF); // Insert Token pdu.append(d->message.token()); diff --git a/src/coap/qcoapinternalrequest_p.h b/src/coap/qcoapinternalrequest_p.h index 1b50aae..549f5f0 100644 --- a/src/coap/qcoapinternalrequest_p.h +++ b/src/coap/qcoapinternalrequest_p.h @@ -118,7 +118,7 @@ public: QCoapInternalRequestPrivate() = default; QUrl targetUri; - QtCoap::Method method = QtCoap::Invalid; + QtCoap::Method method = QtCoap::Method::Invalid; QCoapConnection *connection = nullptr; QByteArray fullPayload; diff --git a/src/coap/qcoapmessage.h b/src/coap/qcoapmessage.h index 550ff88..36288a7 100644 --- a/src/coap/qcoapmessage.h +++ b/src/coap/qcoapmessage.h @@ -44,7 +44,7 @@ class QCoapMessagePrivate; class Q_COAP_EXPORT QCoapMessage { public: - enum MessageType { + enum class MessageType : quint8 { Confirmable, NonConfirmable, Acknowledgment, diff --git a/src/coap/qcoapmessage_p.h b/src/coap/qcoapmessage_p.h index 9cfd282..b16ba2b 100644 --- a/src/coap/qcoapmessage_p.h +++ b/src/coap/qcoapmessage_p.h @@ -51,12 +51,12 @@ QT_BEGIN_NAMESPACE class Q_AUTOTEST_EXPORT QCoapMessagePrivate : public QSharedData { public: - QCoapMessagePrivate(QCoapMessage::MessageType type = QCoapMessage::NonConfirmable); + QCoapMessagePrivate(QCoapMessage::MessageType type = QCoapMessage::MessageType::NonConfirmable); QCoapMessagePrivate(const QCoapMessagePrivate &other); ~QCoapMessagePrivate(); quint8 version = 1; - QCoapMessage::MessageType type = QCoapMessage::NonConfirmable; + QCoapMessage::MessageType type = QCoapMessage::MessageType::NonConfirmable; quint16 messageId = 0; QByteArray token; QVector<QCoapOption> options; diff --git a/src/coap/qcoapnamespace.cpp b/src/coap/qcoapnamespace.cpp index df44ce2..b1e5fc4 100644 --- a/src/coap/qcoapnamespace.cpp +++ b/src/coap/qcoapnamespace.cpp @@ -140,74 +140,74 @@ QT_BEGIN_NAMESPACE Indicates the error condition found during processing of the request. - \value NoError No error condition. + \value Ok No error condition. - \value HostNotFoundError The remote host name was not found. + \value HostNotFound The remote host name was not found. - \value AddressInUseError The address is already in use. + \value AddressInUse The address is already in use. - \value TimeOutError The response did not arrive in time. + \value TimeOut The response did not arrive in time. - \value BadRequestError The request was not recognized. + \value BadRequest The request was not recognized. - \value UnauthorizedError The client is not authorized to perform + \value Unauthorized The client is not authorized to perform the requested action. - \value BadOptionError The request could not be understood by + \value BadOption The request could not be understood by the server due to one or more unrecognized or malformed options. - \value ForbiddenError Access to this resource is forbidden. + \value Forbidden Access to this resource is forbidden. - \value NotFoundError The resource requested was not found. + \value NotFound The resource requested was not found. - \value MethodNotAllowedError The server does not allow the method used + \value MethodNotAllowed The server does not allow the method used for the URL requested. - \value NotAcceptableError No resource satisfying the request's acceptance + \value NotAcceptable No resource satisfying the request's acceptance criteria was found. - \value RequestEntityIncompleteError The server has not received the blocks of + \value RequestEntityIncomplete The server has not received the blocks of the request body that it needs to proceed. The client has not sent all blocks, has not sent them in the order required by the server, or sent them long enough ago that the server has already discarded them. - \value PreconditionFailedError One or more conditions given in the request + \value PreconditionFailed One or more conditions given in the request header fields evaluated to false when tested on the server. - \value RequestEntityTooLargeError The request payload is larger than the + \value RequestEntityTooLarge The request payload is larger than the server is willing or able to process. - \value UnsupportedContentFormatError The payload is in a format not supported + \value UnsupportedContentFormat The payload is in a format not supported by this method on the target resource. - \value InternalServerFaultError The server encountered an unexpected + \value InternalServerFault The server encountered an unexpected condition that prevented it from fulfilling the request. - \value NotImplementedError The server does not support the + \value NotImplemented The server does not support the functionality required to fulfill the request. - \value BadGatewayError An error occurred with an upstream + \value BadGateway An error occurred with an upstream server. - \value ServiceUnavailableError The service is currently unavailable. + \value ServiceUnavailable The service is currently unavailable. - \value GatewayTimeoutError The server, while acting as a gateway + \value GatewayTimeout The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request. - \value ProxyingNotSupportedError The server is unable or unwilling to act + \value ProxyingNotSupported The server is unable or unwilling to act as a forward-proxy for the URI specified in the Proxy-Uri Option or using the scheme specified in Proxy-Scheme. - \value UnknownError An unknown error occurred. + \value Unknown An unknown error occurred. */ /*! @@ -283,14 +283,14 @@ bool QtCoap::isError(QtCoap::ResponseCode code) QtCoap::Error QtCoap::responseCodeError(QtCoap::ResponseCode code) { if (!isError(code)) - return QtCoap::NoError; + return QtCoap::Error::Ok; switch (code) { -#define SINGLE_CASE(name, ignored) case name: return name ## Error; +#define SINGLE_CASE(name, ignored) case ResponseCode::name: return Error::name; FOR_EACH_COAP_ERROR(SINGLE_CASE) #undef SINGLE_CASE default: - return UnknownError; + return Error::Unknown; } } diff --git a/src/coap/qcoapnamespace.h b/src/coap/qcoapnamespace.h index 72b91cd..353a046 100644 --- a/src/coap/qcoapnamespace.h +++ b/src/coap/qcoapnamespace.h @@ -49,7 +49,7 @@ namespace QtCoap { Q_COAP_EXPORT Q_NAMESPACE - enum ResponseCode { + enum class ResponseCode : quint8 { EmptyMessage = 0x00, Created = 0x41, // 2.01 Deleted = 0x42, // 2.02 @@ -66,21 +66,21 @@ namespace QtCoap }; Q_ENUM_NS(ResponseCode) - enum Error { - NoError, - HostNotFoundError, - AddressInUseError, - TimeOutError, + enum class Error : quint8 { + Ok, + HostNotFound, + AddressInUse, + TimeOut, -#define SINGLE_ERROR(name, ignored) name ## Error, +#define SINGLE_ERROR(name, ignored) name, FOR_EACH_COAP_ERROR(SINGLE_ERROR) #undef SINGLE_ERROR - UnknownError + Unknown }; Q_ENUM_NS(Error) - enum Method { + enum class Method : quint8 { Invalid, Get, Post, @@ -103,7 +103,7 @@ namespace QtCoap }; Q_ENUM_NS(Port) - enum SecurityMode { + enum class SecurityMode : quint8 { NoSec = 0, PreSharedKey, RawPublicKey, @@ -111,7 +111,7 @@ namespace QtCoap }; Q_ENUM_NS(SecurityMode) - enum MulticastGroup { + enum class MulticastGroup : quint8 { AllCoapNodesIPv4, AllCoapNodesIPv6LinkLocal, AllCoapNodesIPv6SiteLocal @@ -121,6 +121,8 @@ namespace QtCoap Q_COAP_EXPORT bool isError(ResponseCode code); Q_COAP_EXPORT Error responseCodeError(ResponseCode code); Q_COAP_EXPORT QRandomGenerator &randomGenerator(); + + Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") } QT_END_NAMESPACE diff --git a/src/coap/qcoapprotocol.cpp b/src/coap/qcoapprotocol.cpp index 971c70b..dd5f25d 100644 --- a/src/coap/qcoapprotocol.cpp +++ b/src/coap/qcoapprotocol.cpp @@ -168,7 +168,7 @@ void QCoapProtocol::sendRequest(QPointer<QCoapReply> reply, QCoapConnection *con internalRequest->setToSendBlock(0, d->blockSize); } - if (requestMessage->type() == QCoapMessage::Confirmable) + if (requestMessage->type() == QCoapMessage::MessageType::Confirmable) internalRequest->setTimeout(QtCoap::randomGenerator().bounded(minTimeout(), maxTimeout())); else internalRequest->setTimeout(maxTimeout()); @@ -229,11 +229,11 @@ void QCoapProtocolPrivate::onRequestTimeout(QCoapInternalRequest *request) if (!isRequestRegistered(request)) return; - if (request->message()->type() == QCoapMessage::Confirmable + if (request->message()->type() == QCoapMessage::MessageType::Confirmable && request->retransmissionCounter() < maxRetransmit) { sendRequest(request); } else { - onRequestError(request, QtCoap::TimeOutError); + onRequestError(request, QtCoap::Error::TimeOut); } } @@ -249,7 +249,7 @@ void QCoapProtocolPrivate::onRequestMaxTransmissionSpanReached(QCoapInternalRequ Q_ASSERT(QThread::currentThread() == q->thread()); if (isRequestRegistered(request)) - onRequestError(request, QtCoap::TimeOutError); + onRequestError(request, QtCoap::Error::TimeOut); } /*! @@ -267,7 +267,7 @@ void QCoapProtocolPrivate::onMulticastRequestExpired(QCoapInternalRequest *reque QPointer<QCoapReply> userReply = userReplyForToken(request->token()); if (userReply) { QMetaObject::invokeMethod(userReply, "_q_setFinished", Qt::QueuedConnection, - Q_ARG(QtCoap::Error, QtCoap::NoError)); + Q_ARG(QtCoap::Error, QtCoap::Error::Ok)); } else { qCWarning(lcCoapProtocol).nospace() << "Reply for token '" << request->token() << "' is not registered, reply is null."; @@ -312,7 +312,7 @@ void QCoapProtocolPrivate::onRequestError(QCoapInternalRequest *request, QtCoap: } QMetaObject::invokeMethod(userReply.data(), "_q_setFinished", Qt::QueuedConnection, - Q_ARG(QtCoap::Error, QtCoap::NoError)); + Q_ARG(QtCoap::Error, QtCoap::Error::Ok)); } forgetExchange(request); @@ -366,7 +366,7 @@ void QCoapProtocolPrivate::onFrameReceived(const QByteArray &data, const QHostAd // Remove option to ensure that it will stop request->removeOption(QCoapOption::Observe); sendReset(request); - } else if (messageReceived->type() == QCoapMessage::Confirmable) { + } else if (messageReceived->type() == QCoapMessage::MessageType::Confirmable) { sendAcknowledgment(request); } @@ -505,8 +505,8 @@ void QCoapProtocolPrivate::onLastMessageReceived(QCoapInternalRequest *request, auto lastReply = replies.last(); // Ignore empty ACK messages - if (lastReply->message()->type() == QCoapMessage::Acknowledgment - && lastReply->responseCode() == QtCoap::EmptyMessage) { + if (lastReply->message()->type() == QCoapMessage::MessageType::Acknowledgment + && lastReply->responseCode() == QtCoap::ResponseCode::EmptyMessage) { exchangeMap[request->token()].replies.takeLast(); return; } @@ -557,7 +557,7 @@ void QCoapProtocolPrivate::onLastMessageReceived(QCoapInternalRequest *request, emit q->responseToMulticastReceived(userReply, *lastReply->message(), sender); } else { QMetaObject::invokeMethod(userReply, "_q_setFinished", Qt::QueuedConnection, - Q_ARG(QtCoap::Error, QtCoap::NoError)); + Q_ARG(QtCoap::Error, QtCoap::Error::Ok)); forgetExchange(request); } } @@ -733,13 +733,13 @@ void QCoapProtocolPrivate::onConnectionError(QAbstractSocket::SocketError socket QtCoap::Error coapError; switch (socketError) { case QAbstractSocket::HostNotFoundError : - coapError = QtCoap::HostNotFoundError; + coapError = QtCoap::Error::HostNotFound; break; case QAbstractSocket::AddressInUseError : - coapError = QtCoap::AddressInUseError; + coapError = QtCoap::Error::AddressInUse; break; default: - coapError = QtCoap::UnknownError; + coapError = QtCoap::Error::Unknown; break; } diff --git a/src/coap/qcoapqudpconnection.cpp b/src/coap/qcoapqudpconnection.cpp index 831b23d..e38fe5b 100644 --- a/src/coap/qcoapqudpconnection.cpp +++ b/src/coap/qcoapqudpconnection.cpp @@ -101,12 +101,12 @@ QCoapQUdpConnection::QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject auto configuration = QSslConfiguration::defaultDtlsConfiguration(); switch (d->securityMode) { - case QtCoap::RawPublicKey: + case QtCoap::SecurityMode::RawPublicKey: qCWarning(lcCoapConnection, "RawPublicKey security is not supported yet," "disabling security"); - d->securityMode = QtCoap::NoSec; + d->securityMode = QtCoap::SecurityMode::NoSec; break; - case QtCoap::PreSharedKey: + case QtCoap::SecurityMode::PreSharedKey: d->dtls = new QDtls(QSslSocket::SslClientMode, this); configuration.setPeerVerifyMode(QSslSocket::VerifyNone); d->dtls->setDtlsConfiguration(configuration); @@ -114,7 +114,7 @@ QCoapQUdpConnection::QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject connect(d->dtls, &QDtls::pskRequired, this, &QCoapQUdpConnection::pskRequired); connect(d->dtls, &QDtls::handshakeTimeout, this, &QCoapQUdpConnection::handshakeTimeout); break; - case QtCoap::Certificate: + case QtCoap::SecurityMode::Certificate: d->dtls = new QDtls(QSslSocket::SslClientMode, this); configuration.setPeerVerifyMode(QSslSocket::VerifyPeer); d->dtls->setDtlsConfiguration(configuration); @@ -126,7 +126,7 @@ QCoapQUdpConnection::QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject } #else qCWarning(lcCoapConnection, "DTLS is disabled, falling back to QtCoap::NoSec mode."); - d->securityMode = QtCoap::NoSec; + d->securityMode = QtCoap::SecurityMode::NoSec; #endif } } @@ -194,7 +194,7 @@ void QCoapQUdpConnectionPrivate::bindSocket() { Q_Q(QCoapQUdpConnection); - if (state != QCoapQUdpConnection::Bound && bind()) + if (state != QCoapQUdpConnection::ConnectionState::Bound && bind()) emit q->bound(); } diff --git a/src/coap/qcoapqudpconnection.h b/src/coap/qcoapqudpconnection.h index 76c5abf..f9ca356 100644 --- a/src/coap/qcoapqudpconnection.h +++ b/src/coap/qcoapqudpconnection.h @@ -48,7 +48,7 @@ class Q_COAP_EXPORT QCoapQUdpConnection : public QCoapConnection Q_OBJECT public: - explicit QCoapQUdpConnection(QtCoap::SecurityMode security = QtCoap::NoSec, + explicit QCoapQUdpConnection(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSec, QObject *parent = nullptr); ~QCoapQUdpConnection() override = default; diff --git a/src/coap/qcoapqudpconnection_p.h b/src/coap/qcoapqudpconnection_p.h index 587f5a2..3901af8 100644 --- a/src/coap/qcoapqudpconnection_p.h +++ b/src/coap/qcoapqudpconnection_p.h @@ -56,7 +56,7 @@ class QSslPreSharedKeyAuthenticator; class Q_AUTOTEST_EXPORT QCoapQUdpConnectionPrivate : public QCoapConnectionPrivate { public: - QCoapQUdpConnectionPrivate(QtCoap::SecurityMode security = QtCoap::NoSec); + QCoapQUdpConnectionPrivate(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSec); ~QCoapQUdpConnectionPrivate() override; virtual bool bind(); diff --git a/src/coap/qcoapreply.cpp b/src/coap/qcoapreply.cpp index 1770deb..9122551 100644 --- a/src/coap/qcoapreply.cpp +++ b/src/coap/qcoapreply.cpp @@ -131,7 +131,7 @@ void QCoapReplyPrivate::_q_setFinished(QtCoap::Error newError) isFinished = true; isRunning = false; - if (newError != QtCoap::NoError) + if (newError != QtCoap::Error::Ok) _q_setError(newError); emit q->finished(q); @@ -376,7 +376,7 @@ bool QCoapReply::isSuccessful() const { Q_D(const QCoapReply); return d->isFinished && !QtCoap::isError(d->responseCode) - && d->error == QtCoap::NoError; + && d->error == QtCoap::Error::Ok; } /*! diff --git a/src/coap/qcoapreply_p.h b/src/coap/qcoapreply_p.h index b786ce2..68e9062 100644 --- a/src/coap/qcoapreply_p.h +++ b/src/coap/qcoapreply_p.h @@ -58,14 +58,14 @@ public: virtual void _q_setContent(const QHostAddress &sender, const QCoapMessage &, QtCoap::ResponseCode); void _q_setNotified(); void _q_setObserveCancelled(); - void _q_setFinished(QtCoap::Error = QtCoap::NoError); + void _q_setFinished(QtCoap::Error = QtCoap::Error::Ok); void _q_setError(QtCoap::ResponseCode code); void _q_setError(QtCoap::Error); QCoapRequest request; QCoapMessage message; - QtCoap::ResponseCode responseCode = QtCoap::InvalidCode; - QtCoap::Error error = QtCoap::NoError; + QtCoap::ResponseCode responseCode = QtCoap::ResponseCode::InvalidCode; + QtCoap::Error error = QtCoap::Error::Ok; bool isRunning = false; bool isFinished = false; bool isAborted = false; diff --git a/src/coap/qcoaprequest.cpp b/src/coap/qcoaprequest.cpp index 58420ac..1d9a441 100644 --- a/src/coap/qcoaprequest.cpp +++ b/src/coap/qcoaprequest.cpp @@ -146,7 +146,7 @@ QCoapRequest::QCoapRequest(const QCoapRequest &other) : QCoapRequest::QCoapRequest(const QCoapRequest &other, QtCoap::Method method) : QCoapRequest(other) { - if (method != QtCoap::Invalid) + if (method != QtCoap::Method::Invalid) setMethod(method); } @@ -278,7 +278,7 @@ QCoapRequest &QCoapRequest::operator=(const QCoapRequest &other) */ bool QCoapRequest::isValid() const { - return isUrlValid(url()) && method() != QtCoap::Invalid; + return isUrlValid(url()) && method() != QtCoap::Method::Invalid; } /*! diff --git a/src/coap/qcoaprequest.h b/src/coap/qcoaprequest.h index 600a635..c833334 100644 --- a/src/coap/qcoaprequest.h +++ b/src/coap/qcoaprequest.h @@ -46,10 +46,10 @@ class Q_COAP_EXPORT QCoapRequest : public QCoapMessage { public: explicit QCoapRequest(const QUrl &url = QUrl(), - MessageType type = NonConfirmable, + MessageType type = MessageType::NonConfirmable, const QUrl &proxyUrl = QUrl()); explicit QCoapRequest(const char* url, - MessageType type = NonConfirmable); + MessageType type = MessageType::NonConfirmable); QCoapRequest(const QCoapRequest &other); ~QCoapRequest(); diff --git a/src/coap/qcoaprequest_p.h b/src/coap/qcoaprequest_p.h index 35d4c70..67c26c6 100644 --- a/src/coap/qcoaprequest_p.h +++ b/src/coap/qcoaprequest_p.h @@ -52,7 +52,7 @@ class Q_AUTOTEST_EXPORT QCoapRequestPrivate : public QCoapMessagePrivate { public: QCoapRequestPrivate(const QUrl &url = QUrl(), - QCoapMessage::MessageType type = QCoapMessage::NonConfirmable, + QCoapMessage::MessageType type = QCoapMessage::MessageType::NonConfirmable, const QUrl &proxyUrl = QUrl()); QCoapRequestPrivate(const QCoapRequestPrivate &other) = default; ~QCoapRequestPrivate(); @@ -61,7 +61,7 @@ public: QUrl uri; QUrl proxyUri; - QtCoap::Method method = QtCoap::Invalid; + QtCoap::Method method = QtCoap::Method::Invalid; }; QT_END_NAMESPACE diff --git a/tests/auto/qcoapclient/tst_qcoapclient.cpp b/tests/auto/qcoapclient/tst_qcoapclient.cpp index 04db9f4..3e5eac0 100644 --- a/tests/auto/qcoapclient/tst_qcoapclient.cpp +++ b/tests/auto/qcoapclient/tst_qcoapclient.cpp @@ -228,16 +228,23 @@ void tst_QCoapClient::methods_data() QTest::addColumn<QUrl>("url"); QTest::addColumn<QtCoap::Method>("method"); - QTest::newRow("get") << QUrl(testServerResource()) << QtCoap::Get; - QTest::newRow("get_no_port") - << QUrl("coap://" + testServerHost() + "/test") << QtCoap::Get; - QTest::newRow("get_no_scheme_no_port") << QUrl(testServerHost() + "/test") << QtCoap::Get; - QTest::newRow("post") << QUrl(testServerResource()) << QtCoap::Post; - QTest::newRow("post_no_scheme_no_port") << QUrl(testServerHost() + "/test") << QtCoap::Post; - QTest::newRow("put") << QUrl(testServerResource()) << QtCoap::Put; - QTest::newRow("put_no_scheme_no_port") << QUrl(testServerHost() + "/test") << QtCoap::Put; - QTest::newRow("delete") << QUrl(testServerResource()) << QtCoap::Delete; - QTest::newRow("delete_no_scheme_no_port") << QUrl(testServerHost() + "/test") << QtCoap::Delete; + QTest::newRow("get") << QUrl(testServerResource()) << QtCoap::Method::Get; + QTest::newRow("get_no_port") << QUrl("coap://" + testServerHost() + "/test") + << QtCoap::Method::Get; + QTest::newRow("get_no_scheme_no_port") << QUrl(testServerHost() + "/test") + << QtCoap::Method::Get; + QTest::newRow("post") << QUrl(testServerResource()) + << QtCoap::Method::Post; + QTest::newRow("post_no_scheme_no_port") << QUrl(testServerHost() + "/test") + << QtCoap::Method::Post; + QTest::newRow("put") << QUrl(testServerResource()) + << QtCoap::Method::Put; + QTest::newRow("put_no_scheme_no_port") << QUrl(testServerHost() + "/test") + << QtCoap::Method::Put; + QTest::newRow("delete") << QUrl(testServerResource()) + << QtCoap::Method::Delete; + QTest::newRow("delete_no_scheme_no_port") << QUrl(testServerHost() + "/test") + << QtCoap::Method::Delete; } void tst_QCoapClient::methods() @@ -275,16 +282,16 @@ void tst_QCoapClient::methods() replyData = reply->readAll(); if (qstrncmp(QTest::currentDataTag(), "get", 3) == 0) { QVERIFY(!replyData.isEmpty()); - QCOMPARE(reply->responseCode(), QtCoap::Content); + QCOMPARE(reply->responseCode(), QtCoap::ResponseCode::Content); } else if (qstrncmp(QTest::currentDataTag(), "post", 4) == 0) { QVERIFY(replyData.isEmpty()); - QCOMPARE(reply->responseCode(), QtCoap::Created); + QCOMPARE(reply->responseCode(), QtCoap::ResponseCode::Created); } else if (qstrncmp(QTest::currentDataTag(), "put", 3) == 0) { QVERIFY(replyData.isEmpty()); - QCOMPARE(reply->responseCode(), QtCoap::Changed); + QCOMPARE(reply->responseCode(), QtCoap::ResponseCode::Changed); } else if (qstrncmp(QTest::currentDataTag(), "delete", 6) == 0) { QVERIFY(replyData.isEmpty()); - QCOMPARE(reply->responseCode(), QtCoap::Deleted); + QCOMPARE(reply->responseCode(), QtCoap::ResponseCode::Deleted); } else { QString error = QLatin1Literal("Unrecognized method '") + QTest::currentDataTag() + "'"; QFAIL(qPrintable(error)); @@ -305,7 +312,7 @@ void tst_QCoapClient::separateMethod() QByteArray replyData = reply->readAll(); QVERIFY(!replyData.isEmpty()); - QCOMPARE(reply->responseCode(), QtCoap::Content); + QCOMPARE(reply->responseCode(), QtCoap::ResponseCode::Content); } void tst_QCoapClient::removeReply() @@ -386,10 +393,10 @@ void tst_QCoapClient::requestWithQIODevice() if (qstrcmp(QTest::currentDataTag(), "post") == 0) { QVERIFY(replyData.isEmpty()); - QCOMPARE(reply->responseCode(), QtCoap::Created); + QCOMPARE(reply->responseCode(), QtCoap::ResponseCode::Created); } else if (qstrcmp(QTest::currentDataTag(), "put") == 0) { QVERIFY(replyData.isEmpty()); - QCOMPARE(reply->responseCode(), QtCoap::Changed); + QCOMPARE(reply->responseCode(), QtCoap::ResponseCode::Changed); } } @@ -425,10 +432,10 @@ void tst_QCoapClient::multipleRequests() QByteArray replyData3 = replyGet3->readAll(); QByteArray replyData4 = replyGet4->readAll(); - QCOMPARE(replyGet1->responseCode(), QtCoap::Content); - QCOMPARE(replyGet2->responseCode(), QtCoap::Content); - QCOMPARE(replyGet3->responseCode(), QtCoap::Content); - QCOMPARE(replyGet4->responseCode(), QtCoap::Content); + QCOMPARE(replyGet1->responseCode(), QtCoap::ResponseCode::Content); + QCOMPARE(replyGet2->responseCode(), QtCoap::ResponseCode::Content); + QCOMPARE(replyGet3->responseCode(), QtCoap::ResponseCode::Content); + QCOMPARE(replyGet4->responseCode(), QtCoap::ResponseCode::Content); QVERIFY(replyData1 != replyData2); QVERIFY(replyData1 != replyData3); @@ -454,7 +461,8 @@ void tst_QCoapClient::socketError() QTRY_COMPARE_WITH_TIMEOUT(spySocketError.count(), 1, 10000); QTRY_COMPARE_WITH_TIMEOUT(spyClientError.count(), 1, 1000); - QCOMPARE(spyClientError.first().at(1), QtCoap::AddressInUseError); + QCOMPARE(qvariant_cast<QtCoap::Error>(spyClientError.first().at(1)), + QtCoap::Error::AddressInUse); #else QSKIP("Not an internal build, skipping this test"); #endif @@ -483,7 +491,8 @@ void tst_QCoapClient::timeout() QElapsedTimer timeoutTimer; timeoutTimer.start(); - QScopedPointer<QCoapReply> reply(client.get(QCoapRequest(url, QCoapMessage::Confirmable))); + QScopedPointer<QCoapReply> reply( + client.get(QCoapRequest(url, QCoapMessage::MessageType::Confirmable))); QSignalSpy spyClientError(&client, &QCoapClient::error); QSignalSpy spyReplyError(reply.data(), &QCoapReply::error); QSignalSpy spyReplyAborted(reply.data(), &QCoapReply::aborted); @@ -506,7 +515,8 @@ void tst_QCoapClient::timeout() QVERIFY2(elapsedTime > 0.9 * client.protocol()->maxTransmitWait() - 20 * transmissions, qPrintable(errorMessage)); - QCOMPARE(spyReplyError.first().at(1), QtCoap::TimeOutError); + QCOMPARE(qvariant_cast<QtCoap::Error>(spyReplyError.first().at(1)), + QtCoap::Error::TimeOut); QCOMPARE(spyReplyFinished.count(), 1); QCOMPARE(spyReplyAborted.count(), 0); QCOMPARE(spyClientError.count(), 1); @@ -563,27 +573,27 @@ void tst_QCoapClient::blockwiseReply_data() QTest::newRow("get_large") << QUrl(testServerUrl() + "/large") - << QCoapMessage::NonConfirmable + << QCoapMessage::MessageType::NonConfirmable << data; QTest::newRow("get_large_separate") << QUrl(testServerUrl() + "/large-separate") - << QCoapMessage::NonConfirmable + << QCoapMessage::MessageType::NonConfirmable << data; QTest::newRow("get_large_confirmable") << QUrl(testServerUrl() + "/large") - << QCoapMessage::Confirmable + << QCoapMessage::MessageType::Confirmable << data; QTest::newRow("get_large_separate_confirmable") << QUrl(testServerUrl() + "/large-separate") - << QCoapMessage::Confirmable + << QCoapMessage::MessageType::Confirmable << data; QTest::newRow("get_large_16bits") << QUrl(testServerUrl() + "/large") - << QCoapMessage::NonConfirmable + << QCoapMessage::MessageType::NonConfirmable << data; QTest::newRow("get_large_16bits_confirmable") << QUrl(testServerUrl() + "/large") - << QCoapMessage::Confirmable + << QCoapMessage::MessageType::Confirmable << data; } @@ -625,14 +635,14 @@ void tst_QCoapClient::blockwiseRequest_data() data.append(alphabet); QTest::newRow("large_post_empty_reply") << QUrl(testServerUrl() + "/query") - << QCoapMessage::NonConfirmable + << QCoapMessage::MessageType::NonConfirmable << data - << QtCoap::MethodNotAllowed + << QtCoap::ResponseCode::MethodNotAllowed << QByteArray(); QTest::newRow("large_post_large_reply") << QUrl(testServerUrl() + "/large-post") - << QCoapMessage::NonConfirmable + << QCoapMessage::MessageType::NonConfirmable << data - << QtCoap::Changed + << QtCoap::ResponseCode::Changed << data.toUpper(); } @@ -688,7 +698,7 @@ void tst_QCoapClient::discover() const auto discoverUrl = QUrl(url.toString() + "/.well-known/core"); QCOMPARE(resourcesReply->url(), QCoapRequest::adjustedUrl(discoverUrl, false)); QCOMPARE(resourcesReply->resources().length(), resourceNumber); - QCOMPARE(resourcesReply->request().method(), QtCoap::Get); + QCOMPARE(resourcesReply->request().method(), QtCoap::Method::Get); //! TODO Test discovery content too } @@ -701,39 +711,39 @@ void tst_QCoapClient::observe_data() QTest::newRow("observe") << QUrl(testServerUrl() + "/obs") - << QCoapMessage::NonConfirmable; + << QCoapMessage::MessageType::NonConfirmable; QTest::newRow("observe_no_scheme_no_port") << QUrl(testServerHost() + "/obs") - << QCoapMessage::NonConfirmable; + << QCoapMessage::MessageType::NonConfirmable; QTest::newRow("observe_confirmable") << QUrl(testServerUrl() + "/obs") - << QCoapMessage::Confirmable; + << QCoapMessage::MessageType::Confirmable; QTest::newRow("observe_receive") << QUrl(testServerUrl() + "/obs-non") - << QCoapMessage::NonConfirmable; + << QCoapMessage::MessageType::NonConfirmable; QTest::newRow("observe_receive_confirmable") << QUrl(testServerUrl() + "/obs-non") - << QCoapMessage::Confirmable; + << QCoapMessage::MessageType::Confirmable; QTest::newRow("observe_large") << QUrl(testServerUrl() + "/obs-large") - << QCoapMessage::NonConfirmable; + << QCoapMessage::MessageType::NonConfirmable; QTest::newRow("observe_large_confirmable") << QUrl(testServerUrl() + "/obs-large") - << QCoapMessage::Confirmable; + << QCoapMessage::MessageType::Confirmable; QTest::newRow("observe_pumping") << QUrl(testServerUrl() + "/obs-pumping") - << QCoapMessage::NonConfirmable; + << QCoapMessage::MessageType::NonConfirmable; QTest::newRow("observe_pumping_confirmable") << QUrl(testServerUrl() + "/obs-pumping") - << QCoapMessage::Confirmable; + << QCoapMessage::MessageType::Confirmable; } void tst_QCoapClient::observe() @@ -753,7 +763,7 @@ void tst_QCoapClient::observe() QTRY_COMPARE_WITH_TIMEOUT(spyReplyNotified.count(), 3, 30000); client.cancelObserve(reply.data()); QCOMPARE(reply->url(), QCoapRequest::adjustedUrl(url, false)); - QCOMPARE(reply->request().method(), QtCoap::Get); + QCOMPARE(reply->request().method(), QtCoap::Method::Get); QVERIFY2(!spyReplyNotified.wait(7000), "'Notify' signal received after cancelling observe"); QCOMPARE(spyReplyFinished.count(), 1); @@ -769,7 +779,8 @@ void tst_QCoapClient::observe() void tst_QCoapClient::confirmableMulticast() { QCoapClient client; - const auto reply = client.get(QCoapRequest("224.0.1.187", QCoapMessage::Confirmable)); + const auto reply = client.get(QCoapRequest("224.0.1.187", + QCoapMessage::MessageType::Confirmable)); QVERIFY2(!reply, "Confirmable multicast request didn't fail as expected."); } diff --git a/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp b/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp index 58bd51b..da2531b 100644 --- a/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp +++ b/tests/auto/qcoapinternalreply/tst_qcoapinternalreply.cpp @@ -72,8 +72,8 @@ void tst_QCoapInternalReply::parseReplyPdu_data() QList<QByteArray> bigOptionValueReply({QByteArray("abcdefghijklmnopqrstuvwxyz")}); QTest::newRow("reply_with_options_and_payload") - << QtCoap::Content - << QCoapMessage::NonConfirmable + << QtCoap::ResponseCode::Content + << QCoapMessage::MessageType::NonConfirmable << quint16(64463) << QByteArray("4647f09b") << quint8(4) @@ -86,8 +86,8 @@ void tst_QCoapInternalReply::parseReplyPdu_data() "3962"; QTest::newRow("reply_with_payload") - << QtCoap::Content - << QCoapMessage::NonConfirmable + << QtCoap::ResponseCode::Content + << QCoapMessage::MessageType::NonConfirmable << quint16(64463) << QByteArray("4647f09b") << quint8(4) @@ -99,8 +99,8 @@ void tst_QCoapInternalReply::parseReplyPdu_data() "474554290a4d49443a2035363430300a546f6b656e3a203436343766303962"; QTest::newRow("reply_with_options") - << QtCoap::Content - << QCoapMessage::NonConfirmable + << QtCoap::ResponseCode::Content + << QCoapMessage::MessageType::NonConfirmable << quint16(64463) << QByteArray("4647f09b") << quint8(4) @@ -111,8 +111,8 @@ void tst_QCoapInternalReply::parseReplyPdu_data() << "5445fbcf4647f09bc0211e"; QTest::newRow("reply_only") - << QtCoap::Content - << QCoapMessage::NonConfirmable + << QtCoap::ResponseCode::Content + << QCoapMessage::MessageType::NonConfirmable << quint16(64463) << QByteArray("4647f09b") << quint8(4) @@ -123,8 +123,8 @@ void tst_QCoapInternalReply::parseReplyPdu_data() << "5445fbcf4647f09b"; QTest::newRow("reply_with_big_option") - << QtCoap::Content - << QCoapMessage::NonConfirmable + << QtCoap::ResponseCode::Content + << QCoapMessage::MessageType::NonConfirmable << quint16(64463) << QByteArray("4647f09b") << quint8(4) diff --git a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp index f6d4160..6a61eb1 100644 --- a/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp +++ b/tests/auto/qcoapinternalrequest/tst_qcoapinternalrequest.cpp @@ -71,8 +71,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_with_option_and_payload") << QUrl("coap://10.20.30.40:5683/test") - << QtCoap::Get - << QCoapRequest::NonConfirmable + << QtCoap::Method::Get + << QCoapRequest::MessageType::NonConfirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "5401dc504647f09bb474657374ff" @@ -80,8 +80,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_domain") << QUrl("coap://domain.com:5683/test") - << QtCoap::Get - << QCoapRequest::NonConfirmable + << QtCoap::Method::Get + << QCoapRequest::MessageType::NonConfirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "5401dc504647f09b3a646f6d61696e2e636f6d8474657374ff" @@ -89,8 +89,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_ipv6") << QUrl("coap://[::ffff:ac11:3]:5683/test") - << QtCoap::Get - << QCoapRequest::NonConfirmable + << QtCoap::Method::Get + << QCoapRequest::MessageType::NonConfirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "5401dc504647f09bb474657374ff" @@ -98,8 +98,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_without_payload") << QUrl("coap://10.20.30.40:5683/test") - << QtCoap::Get - << QCoapRequest::NonConfirmable + << QtCoap::Method::Get + << QCoapRequest::MessageType::NonConfirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "5401dc504647f09bb474657374" @@ -107,8 +107,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_without_option") << QUrl("coap://10.20.30.40:5683/") - << QtCoap::Put - << QCoapRequest::Confirmable + << QtCoap::Method::Put + << QCoapRequest::MessageType::Confirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "4403dc504647f09bff" @@ -116,8 +116,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_only") << QUrl("coap://10.20.30.40:5683/") - << QtCoap::Get - << QCoapRequest::NonConfirmable + << QtCoap::Method::Get + << QCoapRequest::MessageType::NonConfirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "5401dc504647f09b" @@ -125,8 +125,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_with_multiple_options") << QUrl("coap://10.20.30.40:5683/test/oui") - << QtCoap::Get - << QCoapRequest::NonConfirmable + << QtCoap::Method::Get + << QCoapRequest::MessageType::NonConfirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "5401dc504647f09bb474657374036f7569" @@ -134,8 +134,8 @@ void tst_QCoapInternalRequest::requestToFrame_data() QTest::newRow("request_with_big_option_number") << QUrl("coap://10.20.30.40:5683/test") - << QtCoap::Get - << QCoapRequest::NonConfirmable + << QtCoap::Method::Get + << QCoapRequest::MessageType::NonConfirmable << quint16(56400) << QByteArray::fromHex("4647f09b") << "5401dc504647f09bb474657374dd240d6162636465666768696a6b6c6d6e6f70" @@ -218,7 +218,7 @@ void tst_QCoapInternalRequest::parseUri() QFETCH(QUrl, proxyUri); QFETCH(QVector<QCoapOption>, options); - QCoapRequest request(uri, QCoapMessage::NonConfirmable, proxyUri); + QCoapRequest request(uri, QCoapMessage::MessageType::NonConfirmable, proxyUri); QCoapInternalRequest internalRequest(request); for (QCoapOption opt : options) diff --git a/tests/auto/qcoapmessage/tst_qcoapmessage.cpp b/tests/auto/qcoapmessage/tst_qcoapmessage.cpp index b071645..8801ed0 100644 --- a/tests/auto/qcoapmessage/tst_qcoapmessage.cpp +++ b/tests/auto/qcoapmessage/tst_qcoapmessage.cpp @@ -59,7 +59,7 @@ void tst_QCoapMessage::copyAndDetach() a.setMessageId(3); a.setPayload("payload"); a.setToken("token"); - a.setType(QCoapMessage::Acknowledgment); + a.setType(QCoapMessage::MessageType::Acknowledgment); a.setVersion(5); // Test the copy @@ -67,7 +67,7 @@ void tst_QCoapMessage::copyAndDetach() QVERIFY2(b.messageId() == 3, "Message not copied correctly"); QVERIFY2(b.payload() == "payload", "Message not copied correctly"); QVERIFY2(b.token() == "token", "Message not copied correctly"); - QVERIFY2(b.type() == QCoapMessage::Acknowledgment, "Message not copied correctly"); + QVERIFY2(b.type() == QCoapMessage::MessageType::Acknowledgment, "Message not copied correctly"); QVERIFY2(b.version() == 5, "Message not copied correctly"); // Detach @@ -80,10 +80,10 @@ void tst_QCoapMessage::setMessageType_data() { QTest::addColumn<QCoapMessage::MessageType>("type"); - QTest::newRow("acknowledgment") << QCoapMessage::Acknowledgment; - QTest::newRow("confirmable") << QCoapMessage::Confirmable; - QTest::newRow("non-confirmable") << QCoapMessage::NonConfirmable; - QTest::newRow("reset") << QCoapMessage::Reset; + QTest::newRow("acknowledgment") << QCoapMessage::MessageType::Acknowledgment; + QTest::newRow("confirmable") << QCoapMessage::MessageType::Confirmable; + QTest::newRow("non-confirmable") << QCoapMessage::MessageType::NonConfirmable; + QTest::newRow("reset") << QCoapMessage::MessageType::Reset; } void tst_QCoapMessage::setMessageType() diff --git a/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp b/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp index 898466d..6ce5a87 100644 --- a/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp +++ b/tests/auto/qcoapqudpconnection/tst_qcoapqudpconnection.cpp @@ -68,7 +68,7 @@ class QCoapQUdpConnectionForTest : public QCoapQUdpConnection Q_OBJECT public: QCoapQUdpConnectionForTest(QObject *parent = nullptr) : - QCoapQUdpConnection(QtCoap::NoSec, parent) + QCoapQUdpConnection(QtCoap::SecurityMode::NoSec, parent) {} void bindSocketForTest() { d_func()->bindSocket(); } @@ -93,14 +93,14 @@ void tst_QCoapQUdpConnection::connectToHost() QSignalSpy spyConnectionBound(&connection, SIGNAL(bound())); QSignalSpy spySocketStateChanged(socket , SIGNAL(stateChanged(QAbstractSocket::SocketState))); - QCOMPARE(connection.state(), QCoapQUdpConnection::Unconnected); + QCOMPARE(connection.state(), QCoapQUdpConnection::ConnectionState::Unconnected); // This will trigger connection.bind() connection.sendRequest(QByteArray(), QString(), 0); QTRY_COMPARE(spySocketStateChanged.count(), 1); QTRY_COMPARE(spyConnectionBound.count(), 1); - QCOMPARE(connection.state(), QCoapQUdpConnection::Bound); + QCOMPARE(connection.state(), QCoapQUdpConnection::ConnectionState::Bound); #else QSKIP("Not an internal build, skipping this test"); #endif @@ -115,15 +115,15 @@ void tst_QCoapQUdpConnection::reconnect() QSignalSpy connectionBoundSpy(&connection, SIGNAL(bound())); connection.sendRequest(QByteArray(), QString(), 0); QTRY_COMPARE(connectionBoundSpy.count(), 1); - QCOMPARE(connection.state(), QCoapQUdpConnection::Bound); + QCOMPARE(connection.state(), QCoapQUdpConnection::ConnectionState::Bound); connection.disconnect(); - QCOMPARE(connection.state(), QCoapQUdpConnection::Unconnected); + QCOMPARE(connection.state(), QCoapQUdpConnection::ConnectionState::Unconnected); // Make sure that we are able to connect again connection.sendRequest(QByteArray(), QString(), 0); QTRY_COMPARE(connectionBoundSpy.count(), 2); - QCOMPARE(connection.state(), QCoapQUdpConnection::Bound); + QCOMPARE(connection.state(), QCoapQUdpConnection::ConnectionState::Bound); #else QSKIP("Not an internal build, skipping this test"); #endif @@ -144,7 +144,7 @@ void tst_QCoapQUdpConnection::sendRequest_data() << testServerHost() << "/test" << quint16(QtCoap::DefaultPort) - << QtCoap::Get + << QtCoap::Method::Get << "5445" << "61626364c0211eff547970653a203120284e4f4e290a436f64653a2031202847" "4554290a4d49443a2032343830360a546f6b656e3a203631363236333634"; @@ -154,7 +154,7 @@ void tst_QCoapQUdpConnection::sendRequest_data() << testServerHost() << "/test" << quint16(QtCoap::DefaultPort) - << QtCoap::Put + << QtCoap::Method::Put << "5444" << "61626364"; @@ -163,7 +163,7 @@ void tst_QCoapQUdpConnection::sendRequest_data() << testServerHost() << "/test" << quint16(QtCoap::DefaultPort) - << QtCoap::Post + << QtCoap::Method::Post << "5441" << "61626364896c6f636174696f6e31096c6f636174696f6e32096c6f636174696f" "6e33"; @@ -173,7 +173,7 @@ void tst_QCoapQUdpConnection::sendRequest_data() << testServerHost() << "/test" << quint16(QtCoap::DefaultPort) - << QtCoap::Delete + << QtCoap::Method::Delete << "5442" << "61626364"; } diff --git a/tests/auto/qcoapreply/tst_qcoapreply.cpp b/tests/auto/qcoapreply/tst_qcoapreply.cpp index 05b5889..d9a7562 100644 --- a/tests/auto/qcoapreply/tst_qcoapreply.cpp +++ b/tests/auto/qcoapreply/tst_qcoapreply.cpp @@ -65,20 +65,20 @@ void tst_QCoapReply::updateReply_data() QTest::newRow("success") << QByteArray("Some data") - << QtCoap::Content - << QtCoap::NoError; + << QtCoap::ResponseCode::Content + << QtCoap::Error::Ok; QTest::newRow("content error") << QByteArray("Error") - << QtCoap::BadRequest - << QtCoap::NoError; + << QtCoap::ResponseCode::BadRequest + << QtCoap::Error::Ok; QTest::newRow("finished error") << QByteArray("Error") - << QtCoap::Content - << QtCoap::BadRequestError; + << QtCoap::ResponseCode::Content + << QtCoap::Error::BadRequest; QTest::newRow("content & finished errors") << QByteArray("2Errors") - << QtCoap::BadGateway - << QtCoap::BadRequestError; + << QtCoap::ResponseCode::BadGateway + << QtCoap::Error::BadRequest; } void tst_QCoapReply::updateReply() @@ -111,7 +111,7 @@ void tst_QCoapReply::updateReply() QCOMPARE(spyReplyFinished.count(), 1); QCOMPARE(spyReplyNotified.count(), 0); QCOMPARE(spyReplyAborted.count(), 0); - if (error != QtCoap::NoError || QtCoap::isError(responseCode)) { + if (error != QtCoap::Error::Ok || QtCoap::isError(responseCode)) { QVERIFY(spyReplyError.count() > 0); QCOMPARE(reply.isSuccessful(), false); } else { diff --git a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp index 4513bb9..9f66b98 100644 --- a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp +++ b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp @@ -160,9 +160,9 @@ void tst_QCoapRequest::copyAndDetach() a.setMessageId(3); a.setPayload("payload"); a.setToken("token"); - a.setType(QCoapMessage::Acknowledgment); + a.setType(QCoapMessage::MessageType::Acknowledgment); a.setVersion(5); - a.setMethod(QtCoap::Delete); + a.setMethod(QtCoap::Method::Delete); QUrl testUrl("coap://url:500/resource"); a.setUrl(testUrl); QUrl testProxyUrl("test://proxyurl"); @@ -173,12 +173,12 @@ void tst_QCoapRequest::copyAndDetach() QVERIFY2(b.messageId() == 3, "Message not copied correctly"); QVERIFY2(b.payload() == "payload", "Message not copied correctly"); QVERIFY2(b.token() == "token", "Message not copied correctly"); - QVERIFY2(b.type() == QCoapMessage::Acknowledgment, "Message not copied correctly"); + QVERIFY2(b.type() == QCoapMessage::MessageType::Acknowledgment, "Message not copied correctly"); QVERIFY2(b.version() == 5, "Message not copied correctly"); // Test the QCoapRequest copy QCoapRequest c(a); - QVERIFY2(c.method() == QtCoap::Delete, "Request not copied correctly"); + QVERIFY2(c.method() == QtCoap::Method::Delete, "Request not copied correctly"); QVERIFY2(c.url() == testUrl, "Request not copied correctly"); QVERIFY2(c.proxyUrl() == testProxyUrl, "Request not copied correctly"); |