summaryrefslogtreecommitdiffstats
path: root/tests/auto/qnetworkreply
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qnetworkreply')
-rw-r--r--tests/auto/qnetworkreply/test/test.pro3
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp114
2 files changed, 93 insertions, 24 deletions
diff --git a/tests/auto/qnetworkreply/test/test.pro b/tests/auto/qnetworkreply/test/test.pro
index 7efc2fb..80b879a 100644
--- a/tests/auto/qnetworkreply/test/test.pro
+++ b/tests/auto/qnetworkreply/test/test.pro
@@ -1,4 +1,5 @@
load(qttest_p4)
+QT -= gui
SOURCES += ../tst_qnetworkreply.cpp
TARGET = ../tst_qnetworkreply
@@ -33,6 +34,6 @@ symbian:{
# Symbian toolchain does not support correct include semantics
INCLUDEPATH+=..\\..\\..\\..\\include\\QtNetwork\\private
# bigfile test case requires more heap
- TARGET.EPOCHEAPSIZE="0x100 0x1000000"
+ TARGET.EPOCHEAPSIZE="0x100 0x10000000"
TARGET.CAPABILITY="ALL -TCB"
}
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 6ed8f16..4b8dc3b 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -47,6 +47,7 @@
#include <QtCore/QEventLoop>
#include <QtCore/QFile>
#include <QtCore/QSharedPointer>
+#include <QtCore/QScopedPointer>
#include <QtCore/QTemporaryFile>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>
@@ -66,6 +67,11 @@
#include <QtNetwork/qsslerror.h>
#include <QtNetwork/qsslconfiguration.h>
#endif
+#ifndef QT_NO_BEARERMANAGEMENT
+#include <QtNetwork/qnetworkconfigmanager.h>
+#include <QtNetwork/qnetworkconfiguration.h>
+#include <QtNetwork/qnetworksession.h>
+#endif
#include <time.h>
@@ -137,6 +143,11 @@ class tst_QNetworkReply: public QObject
QSslConfiguration storedSslConfiguration;
QList<QSslError> storedExpectedSslErrors;
#endif
+#ifndef QT_NO_BEARER_MANAGEMENT
+ QNetworkConfigurationManager *netConfMan;
+ QNetworkConfiguration networkConfiguration;
+ QScopedPointer<QNetworkSession> networkSession;
+#endif
public:
tst_QNetworkReply();
@@ -428,16 +439,23 @@ public:
QTcpSocket *client; // always the last one that was received
QByteArray dataToTransmit;
QByteArray receivedData;
+ QSemaphore ready;
bool doClose;
bool doSsl;
bool multiple;
int totalConnections;
- MiniHttpServer(const QByteArray &data, bool ssl = false)
+ MiniHttpServer(const QByteArray &data, bool ssl = false, QThread *thread = 0)
: client(0), dataToTransmit(data), doClose(true), doSsl(ssl),
multiple(false), totalConnections(0)
{
listen();
+ if (thread) {
+ connect(thread, SIGNAL(started()), this, SLOT(threadStartedSlot()));
+ moveToThread(thread);
+ thread->start();
+ ready.acquire();
+ }
}
protected:
@@ -514,6 +532,11 @@ public slots:
disconnect(client, 0, this, 0);
}
}
+
+ void threadStartedSlot()
+ {
+ ready.release();
+ }
};
class MyCookieJar: public QNetworkCookieJar
@@ -1241,6 +1264,18 @@ void tst_QNetworkReply::initTestCase()
#endif
QDir::setSearchPaths("srcdir", QStringList() << SRCDIR);
+#ifndef QT_NO_OPENSSL
+ QSslSocket::defaultCaCertificates(); //preload certificates
+#endif
+#ifndef QT_NO_BEARERMANAGEMENT
+ netConfMan = new QNetworkConfigurationManager(this);
+ networkConfiguration = netConfMan->defaultConfiguration();
+ networkSession.reset(new QNetworkSession(networkConfiguration));
+ if (!networkSession->isOpen()) {
+ networkSession->open();
+ QVERIFY(networkSession->waitForOpened(30000));
+ }
+#endif
}
void tst_QNetworkReply::cleanupTestCase()
@@ -1248,6 +1283,9 @@ void tst_QNetworkReply::cleanupTestCase()
#if !defined Q_OS_WIN
QFile::remove(wronlyFileName);
#endif
+ if (networkSession && networkSession->isOpen()) {
+ networkSession->close();
+ }
}
void tst_QNetworkReply::init()
@@ -1607,7 +1645,7 @@ void tst_QNetworkReply::getErrors()
QNetworkRequest request(url);
#if defined(Q_OS_WIN) || defined (Q_OS_SYMBIAN)
- if (qstrcmp(QTest::currentDataTag(), "empty-scheme-host") == 0)
+ if (qstrcmp(QTest::currentDataTag(), "empty-scheme-host") == 0 && QFileInfo(url).isAbsolute())
QTest::ignoreMessage(QtWarningMsg, "QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files");
#endif
@@ -1626,7 +1664,8 @@ void tst_QNetworkReply::getErrors()
QFETCH(int, error);
#if defined(Q_OS_WIN) || defined (Q_OS_SYMBIAN)
- QEXPECT_FAIL("empty-scheme-host", "this is expected to fail on Windows and Symbian, QTBUG-17731", Abort);
+ if (QFileInfo(url).isAbsolute())
+ QEXPECT_FAIL("empty-scheme-host", "this is expected to fail on Windows and Symbian, QTBUG-17731", Abort);
#endif
QEXPECT_FAIL("ftp-is-dir", "QFtp cannot provide enough detail", Abort);
// the line below is not necessary
@@ -1832,6 +1871,7 @@ void tst_QNetworkReply::postToHttp()
QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi");
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
QNetworkReplyPtr reply;
QFETCH(QByteArray, data);
@@ -1858,6 +1898,7 @@ void tst_QNetworkReply::postToHttpSynchronous()
QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi");
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
request.setAttribute(
QNetworkRequest::SynchronousRequestAttribute,
@@ -3617,8 +3658,7 @@ void tst_QNetworkReply::ioPutToFileFromLocalSocket()
QString socketname = "networkreplytest";
QLocalServer server;
if (!server.listen(socketname)) {
- if (QFile::exists(server.fullServerName()))
- QFile::remove(server.fullServerName());
+ QLocalServer::removeServer(socketname);
QVERIFY(server.listen(socketname));
}
QLocalSocket active;
@@ -3663,7 +3703,7 @@ void tst_QNetworkReply::ioPutToFileFromProcess()
{
#if defined(Q_OS_WINCE) || defined (Q_OS_SYMBIAN)
QSKIP("Currently no stdin/out supported for Windows CE / Symbian OS", SkipAll);
-#endif
+#else
#ifdef Q_OS_WIN
if (qstrcmp(QTest::currentDataTag(), "small") == 0)
@@ -3701,6 +3741,7 @@ void tst_QNetworkReply::ioPutToFileFromProcess()
QByteArray contents = file.readAll();
QCOMPARE(contents, data);
#endif
+#endif
}
void tst_QNetworkReply::ioPutToFtpFromFile_data()
@@ -3814,6 +3855,8 @@ void tst_QNetworkReply::ioPostToHttpFromFile()
QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi");
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
+
QNetworkReplyPtr reply = manager.post(request, &sourceFile);
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
@@ -3890,8 +3933,10 @@ void tst_QNetworkReply::ioPostToHttpFromSocket()
socketpair.endPoints[0]->write(data);
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
+
manager.setProxy(proxy);
- QNetworkReplyPtr reply = manager.post(QNetworkRequest(url), socketpair.endPoints[1]);
+ QNetworkReplyPtr reply = manager.post(request, socketpair.endPoints[1]);
socketpair.endPoints[0]->close();
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
@@ -3964,6 +4009,7 @@ void tst_QNetworkReply::ioPostToHttpFromSocketSynchronous()
QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi");
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
request.setAttribute(
QNetworkRequest::SynchronousRequestAttribute,
true);
@@ -3993,7 +4039,8 @@ void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileToEnd()
QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
QNetworkRequest request(url);
- QNetworkReplyPtr reply = manager.post(QNetworkRequest(url), &sourceFile);
+ request.setRawHeader("Content-Type", "application/octet-stream");
+ QNetworkReplyPtr reply = manager.post(request, &sourceFile);
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
@@ -4019,6 +4066,7 @@ void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileFiveBytes()
QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
// only send 5 bytes
request.setHeader(QNetworkRequest::ContentLengthHeader, 5);
QVERIFY(request.header(QNetworkRequest::ContentLengthHeader).isValid());
@@ -4079,6 +4127,7 @@ void tst_QNetworkReply::ioPostToHttpNoBufferFlag()
QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
// disallow buffering
request.setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, true);
request.setHeader(QNetworkRequest::ContentLengthHeader, data.size());
@@ -4141,6 +4190,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress()
// create the request
QUrl url = QUrl(QString("https://127.0.0.1:%1/").arg(server.serverPort()));
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
QNetworkReplyPtr reply = manager.post(request, &sourceFile);
QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64)));
connect(&server, SIGNAL(newEncryptedConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
@@ -4253,7 +4303,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp()
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
QTime loopTime;
loopTime.start();
- QTestEventLoop::instance().enterLoop(11);
+ QTestEventLoop::instance().enterLoop(30);
const int elapsedTime = loopTime.elapsed();
server.wait();
reader.wrapUp();
@@ -4285,10 +4335,9 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp()
const int minRate = rate * 1024 * (100-allowedDeviation) / 100;
const int maxRate = rate * 1024 * (100+allowedDeviation) / 100;
qDebug() << minRate << "<="<< server.transferRate << "<=" << maxRate << "?";
- QVERIFY(server.transferRate >= minRate);
QEXPECT_FAIL("http+limited", "Limiting is broken right now, check QTBUG-15065", Continue);
QEXPECT_FAIL("https+limited", "Limiting is broken right now, check QTBUG-15065", Continue);
- QVERIFY(server.transferRate <= maxRate);
+ QVERIFY(server.transferRate >= minRate && server.transferRate <= maxRate);
}
}
@@ -4363,6 +4412,7 @@ void tst_QNetworkReply::ioPostToHttpEmptyUploadProgress()
// create the request
QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort()));
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
QNetworkReplyPtr reply = manager.post(request, &buffer);
QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64)));
connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
@@ -4709,6 +4759,7 @@ void tst_QNetworkReply::receiveCookiesFromHttp()
QByteArray data = cookieString.toLatin1() + '\n';
QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/set-cookie.cgi");
QNetworkRequest request(url);
+ request.setRawHeader("Content-Type", "application/octet-stream");
QNetworkReplyPtr reply;
RUN_REQUEST(runSimpleRequest(QNetworkAccessManager::PostOperation, request, reply, data));
@@ -4736,7 +4787,7 @@ void tst_QNetworkReply::receiveCookiesFromHttpSynchronous()
QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/set-cookie.cgi");
QNetworkRequest request(url);
-
+ request.setRawHeader("Content-Type", "application/octet-stream");
request.setAttribute(
QNetworkRequest::SynchronousRequestAttribute,
true);
@@ -4952,6 +5003,26 @@ void tst_QNetworkReply::httpProxyCommandsSynchronous_data()
httpProxyCommands_data();
}
+struct QThreadCleanup
+{
+ static inline void cleanup(QThread *thread)
+ {
+ thread->quit();
+ if (thread->wait(3000))
+ delete thread;
+ else
+ qWarning("thread hung, leaking memory so test can finish");
+ }
+};
+
+struct QDeleteLaterCleanup
+{
+ static inline void cleanup(QObject *o)
+ {
+ o->deleteLater();
+ }
+};
+
void tst_QNetworkReply::httpProxyCommandsSynchronous()
{
QFETCH(QUrl, url);
@@ -4961,11 +5032,9 @@ void tst_QNetworkReply::httpProxyCommandsSynchronous()
// when using synchronous commands, we need a different event loop for
// the server thread, because the client is never returning to the
// event loop
- MiniHttpServer proxyServer(responseToSend);
- QThread serverThread;
- proxyServer.moveToThread(&serverThread);
- serverThread.start();
- QNetworkProxy proxy(QNetworkProxy::HttpProxy, "127.0.0.1", proxyServer.serverPort());
+ QScopedPointer<QThread, QThreadCleanup> serverThread(new QThread);
+ QScopedPointer<MiniHttpServer, QDeleteLaterCleanup> proxyServer(new MiniHttpServer(responseToSend, false, serverThread.data()));
+ QNetworkProxy proxy(QNetworkProxy::HttpProxy, "127.0.0.1", proxyServer->serverPort());
manager.setProxy(proxy);
QNetworkRequest request(url);
@@ -4978,8 +5047,6 @@ void tst_QNetworkReply::httpProxyCommandsSynchronous()
QNetworkReplyPtr reply = manager.get(request);
QVERIFY(reply->isFinished()); // synchronous
manager.setProxy(QNetworkProxy());
- serverThread.quit();
- serverThread.wait(3000);
//qDebug() << reply->error() << reply->errorString();
@@ -4987,7 +5054,7 @@ void tst_QNetworkReply::httpProxyCommandsSynchronous()
// especially since it won't succeed in the HTTPS case
// so just check that the command was correct
- QString receivedHeader = proxyServer.receivedData.left(expectedCommand.length());
+ QString receivedHeader = proxyServer->receivedData.left(expectedCommand.length());
QCOMPARE(receivedHeader, expectedCommand);
}
@@ -5480,7 +5547,7 @@ void tst_QNetworkReply::getFromHttpIntoBuffer()
// FIXME we really need to consolidate all those server implementations
class GetFromHttpIntoBuffer2Server : QObject {
- Q_OBJECT;
+ Q_OBJECT
qint64 dataSize;
qint64 dataSent;
QTcpServer server;
@@ -5602,6 +5669,7 @@ public:
void finishedSlot() {
// We should have already received all readyRead
+ QVERIFY(!bytesAvailableList.isEmpty());
QVERIFY(bytesAvailableList.last() == uploadSize);
}
};
@@ -5747,7 +5815,7 @@ void tst_QNetworkReply::getFromUnreachableIp()
QNetworkReplyPtr reply = manager.get(request);
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QTestEventLoop::instance().enterLoop(5);
+ QTestEventLoop::instance().enterLoop(10);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(reply->error() != QNetworkReply::NoError);
@@ -5933,7 +6001,7 @@ void tst_QNetworkReply::synchronousRequest_data()
<< QString("text/plain");
QTest::newRow("simple-file")
- << QUrl(QString::fromLatin1("file:///" SRCDIR "/rfc3252.txt"))
+ << QUrl::fromLocalFile(SRCDIR "/rfc3252.txt")
<< QString("file:" SRCDIR "/rfc3252.txt")
<< true
<< QString();