summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@trolltech.com>2009-03-10 16:35:17 (GMT)
committerPeter Hartmann <peter.hartmann@trolltech.com>2009-06-05 14:32:02 (GMT)
commit100b55e4ddc9e4846ab877ea670473e2a9ed641e (patch)
tree237760daafc0f9bf6af1030fa8ab7f1c5c57c600 /tests
parent1ad2cba32bc34786cdfd92ad16e3212b8830be3d (diff)
downloadQt-100b55e4ddc9e4846ab877ea670473e2a9ed641e.zip
Qt-100b55e4ddc9e4846ab877ea670473e2a9ed641e.tar.gz
Qt-100b55e4ddc9e4846ab877ea670473e2a9ed641e.tar.bz2
add HTTP DELETE support to Network Access API
added new method QNetworkAccessManager::deleteResource (naming the method "delete" was not possible since it is a reserverd word in C++) and adjusted all the internals necessary. Task-number: 242916 Reviewed-by: Thiago
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index b76a4e6..43b4ea9 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -161,6 +161,10 @@ private Q_SLOTS:
void putToHttp();
void postToHttp_data();
void postToHttp();
+ void deleteFromHttp_data();
+ void deleteFromHttp();
+ void putGetDeleteGetFromHttp_data();
+ void putGetDeleteGetFromHttp();
void ioGetFromData_data();
void ioGetFromData();
@@ -903,6 +907,10 @@ QString tst_QNetworkReply::runSimpleRequest(QNetworkAccessManager::Operation op,
reply = manager.post(request, data);
break;
+ case QNetworkAccessManager::DeleteOperation:
+ reply = manager.deleteResource(request);
+ break;
+
default:
Q_ASSERT_X(false, "tst_QNetworkReply", "Invalid/unknown operation requested");
}
@@ -1478,6 +1486,97 @@ void tst_QNetworkReply::postToHttp()
QCOMPARE(uploadedData, md5sum.toHex());
}
+void tst_QNetworkReply::deleteFromHttp_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<int>("resultCode");
+ QTest::addColumn<QNetworkReply::NetworkError>("error");
+
+ // for status codes to expect, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
+
+ QTest::newRow("405-method-not-allowed") << QUrl("http://" + QtNetworkSettings::serverName() + "/index.html") << 405 << QNetworkReply::ContentOperationNotPermittedError;
+ QTest::newRow("200-ok") << QUrl("http://" + QtNetworkSettings::serverName() + "/cgi-bin/http-delete.cgi?200-ok") << 200 << QNetworkReply::NoError;
+ QTest::newRow("202-accepted") << QUrl("http://" + QtNetworkSettings::serverName() + "/cgi-bin/http-delete.cgi?202-accepted") << 202 << QNetworkReply::NoError;
+ QTest::newRow("204-no-content") << QUrl("http://" + QtNetworkSettings::serverName() + "/cgi-bin/http-delete.cgi?204-no-content") << 204 << QNetworkReply::NoError;
+ QTest::newRow("404-not-found") << QUrl("http://" + QtNetworkSettings::serverName() + "/cgi-bin/http-delete.cgi?404-not-found") << 404 << QNetworkReply::ContentNotFoundError;
+}
+
+void tst_QNetworkReply::deleteFromHttp()
+{
+ QFETCH(QUrl, url);
+ QFETCH(int, resultCode);
+ QFETCH(QNetworkReply::NetworkError, error);
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply;
+ runSimpleRequest(QNetworkAccessManager::DeleteOperation, request, reply, 0);
+ QCOMPARE(reply->url(), url);
+ QCOMPARE(reply->error(), error);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), resultCode);
+}
+
+void tst_QNetworkReply::putGetDeleteGetFromHttp_data()
+{
+ QTest::addColumn<QUrl>("putUrl");
+ QTest::addColumn<int>("putResultCode");
+ QTest::addColumn<QNetworkReply::NetworkError>("putError");
+ QTest::addColumn<QUrl>("deleteUrl");
+ QTest::addColumn<int>("deleteResultCode");
+ QTest::addColumn<QNetworkReply::NetworkError>("deleteError");
+ QTest::addColumn<QUrl>("get2Url");
+ QTest::addColumn<int>("get2ResultCode");
+ QTest::addColumn<QNetworkReply::NetworkError>("get2Error");
+
+ QUrl url("http://" + QtNetworkSettings::serverName());
+ url.setPath(QString("/dav/qnetworkaccess-putToHttp-%1-%2")
+ .arg(QTest::currentDataTag())
+ .arg(uniqueExtension));
+
+ // first use case: put, get (to check it is there), delete, get (to check it is not there anymore)
+ QTest::newRow("success") << url << 201 << QNetworkReply::NoError << url << 204 << QNetworkReply::NoError << url << 404 << QNetworkReply::ContentNotFoundError;
+
+ QUrl wrongUrl("http://" + QtNetworkSettings::serverName());
+ wrongUrl.setPath(QString("/dav/qnetworkaccess-thisURLisNotAvailable"));
+
+ // second use case: put, get (to check it is there), delete wrong URL, get (to check it is still there)
+ QTest::newRow("delete-error") << url << 201 << QNetworkReply::NoError << wrongUrl << 404 << QNetworkReply::ContentNotFoundError << url << 200 << QNetworkReply::NoError;
+
+}
+
+void tst_QNetworkReply::putGetDeleteGetFromHttp()
+{
+ QFETCH(QUrl, putUrl);
+ QFETCH(int, putResultCode);
+ QFETCH(QNetworkReply::NetworkError, putError);
+ QFETCH(QUrl, deleteUrl);
+ QFETCH(int, deleteResultCode);
+ QFETCH(QNetworkReply::NetworkError, deleteError);
+ QFETCH(QUrl, get2Url);
+ QFETCH(int, get2ResultCode);
+ QFETCH(QNetworkReply::NetworkError, get2Error);
+
+ QNetworkRequest putRequest(putUrl);
+ QNetworkRequest deleteRequest(deleteUrl);
+ QNetworkRequest get2Request(get2Url);
+ QNetworkReplyPtr reply;
+
+ RUN_REQUEST(runSimpleRequest(QNetworkAccessManager::PutOperation, putRequest, reply, 0));
+ QCOMPARE(reply->error(), putError);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), putResultCode);
+
+ runSimpleRequest(QNetworkAccessManager::GetOperation, putRequest, reply, 0);
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
+
+ runSimpleRequest(QNetworkAccessManager::DeleteOperation, deleteRequest, reply, 0);
+ QCOMPARE(reply->error(), deleteError);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), deleteResultCode);
+
+ runSimpleRequest(QNetworkAccessManager::GetOperation, get2Request, reply, 0);
+ QCOMPARE(reply->error(), get2Error);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), get2ResultCode);
+
+}
+
void tst_QNetworkReply::ioGetFromData_data()
{
QTest::addColumn<QString>("urlStr");