From 80d094f07272663d759ec4bd8e8a8c233753dd46 Mon Sep 17 00:00:00 2001 From: shiroki Date: Fri, 20 May 2011 10:38:12 +0200 Subject: add test case for ipv6 url parsing Reviewed-by: Thiago (cherry picked from commit fd043eb78212de5935bc101624818070e1b4fb1b) --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 57 ++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 85bf0a8524..258be2d1d7 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -219,6 +219,8 @@ private Q_SLOTS: void putGetDeleteGetFromHttp(); void sendCustomRequestToHttp_data(); void sendCustomRequestToHttp(); + void connectToIPv6Address_data(); + void connectToIPv6Address(); void ioGetFromData_data(); void ioGetFromData(); @@ -447,14 +449,19 @@ public: QSemaphore ready; bool doClose; bool doSsl; + bool ipv6; bool multiple; int totalConnections; - MiniHttpServer(const QByteArray &data, bool ssl = false, QThread *thread = 0) - : client(0), dataToTransmit(data), doClose(true), doSsl(ssl), + MiniHttpServer(const QByteArray &data, bool ssl = false, QThread *thread = 0, bool useipv6 = false) + : client(0), dataToTransmit(data), doClose(true), doSsl(ssl), ipv6(useipv6), multiple(false), totalConnections(0) { - listen(); + if( useipv6 ){ + listen(QHostAddress::AnyIPv6); + }else{ + listen(); + } if (thread) { connect(thread, SIGNAL(started()), this, SLOT(threadStartedSlot())); moveToThread(thread); @@ -466,7 +473,7 @@ public: protected: void incomingConnection(int socketDescriptor) { - //qDebug() << "incomingConnection" << socketDescriptor; + //qDebug() << "incomingConnection" << socketDescriptor << "doSsl:" << doSsl << "ipv6:" << ipv6; if (!doSsl) { client = new QTcpSocket; client->setSocketDescriptor(socketDescriptor); @@ -2326,6 +2333,48 @@ void tst_QNetworkReply::putGetDeleteGetFromHttp() } +void tst_QNetworkReply::connectToIPv6Address_data() +{ + QTest::addColumn("url"); + QTest::addColumn("error"); + QTest::addColumn("dataToSend"); + QTest::addColumn("serverVerifyData"); + QTest::newRow("localhost") << QUrl(QByteArray("http://[::1]")) << QNetworkReply::NoError<< QByteArray("localhost") << QByteArray("\r\nHost: [::1]\r\n"); + //to add more test data here +} + +void tst_QNetworkReply::connectToIPv6Address() +{ + QFETCH(QUrl, url); + QFETCH(QNetworkReply::NetworkError, error); + QFETCH(QByteArray, dataToSend); + QFETCH(QByteArray, serverVerifyData); + + QByteArray httpResponse = QByteArray("HTTP/1.0 200 OK\r\nContent-Length: "); + httpResponse += QByteArray::number(dataToSend.size()); + httpResponse += "\r\n\r\n"; + httpResponse += dataToSend; + + MiniHttpServer server(httpResponse, false, NULL/*thread*/, true/*useipv6*/); + server.doClose = true; + + url.setPort(server.serverPort()); + QNetworkRequest request(url); + + QNetworkReplyPtr reply = manager.get(request); + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QByteArray content = reply->readAll(); + if( !serverVerifyData.isEmpty()){ + //qDebug() << server.receivedData; + //QVERIFY(server.receivedData.contains(serverVerifyData)); //got a bug here + } + QVERIFY(content == dataToSend); + QCOMPARE(reply->url(), request.url()); + QVERIFY(reply->error() == error); +} + void tst_QNetworkReply::sendCustomRequestToHttp_data() { QTest::addColumn("url"); -- cgit v1.2.3