diff options
Diffstat (limited to 'tests')
15 files changed, 653 insertions, 44 deletions
diff --git a/tests/auto/moc/tst_moc.cpp b/tests/auto/moc/tst_moc.cpp index 20fade1..bbfa91f 100644 --- a/tests/auto/moc/tst_moc.cpp +++ b/tests/auto/moc/tst_moc.cpp @@ -493,6 +493,7 @@ private slots: void QTBUG5590_dummyProperty(); void QTBUG12260_defaultTemplate(); void notifyError(); + void QTBUG17635_invokableAndProperty(); void revisions(); signals: void sigWithUnsignedArg(unsigned foo); @@ -1386,6 +1387,31 @@ void tst_Moc::notifyError() #endif } +class QTBUG_17635_InvokableAndProperty : public QObject +{ + Q_OBJECT +public: + Q_PROPERTY(int numberOfEggs READ numberOfEggs) + Q_PROPERTY(int numberOfChickens READ numberOfChickens) + Q_INVOKABLE QString getEgg(int index) { return QString::fromLatin1("Egg"); } + Q_INVOKABLE QString getChicken(int index) { return QString::fromLatin1("Chicken"); } + int numberOfEggs() { return 2; } + int numberOfChickens() { return 4; } +}; + +void tst_Moc::QTBUG17635_invokableAndProperty() +{ + //Moc used to fail parsing Q_INVOKABLE if they were dirrectly following a Q_PROPERTY; + QTBUG_17635_InvokableAndProperty mc; + QString val; + QMetaObject::invokeMethod(&mc, "getEgg", Q_RETURN_ARG(QString, val), Q_ARG(int, 10)); + QCOMPARE(val, QString::fromLatin1("Egg")); + QMetaObject::invokeMethod(&mc, "getChicken", Q_RETURN_ARG(QString, val), Q_ARG(int, 10)); + QCOMPARE(val, QString::fromLatin1("Chicken")); + QVERIFY(mc.metaObject()->indexOfProperty("numberOfEggs") != -1); + QVERIFY(mc.metaObject()->indexOfProperty("numberOfChickens") != -1); +} + // If changed, update VersionTestNotify below class VersionTest : public QObject { diff --git a/tests/auto/network.pro b/tests/auto/network.pro index 7d83054..b427f1c 100644 --- a/tests/auto/network.pro +++ b/tests/auto/network.pro @@ -35,6 +35,8 @@ SUBDIRS=\ qsslerror \ qsslkey \ qsslsocket \ + qsslsocket_onDemandCertificates_member \ + qsslsocket_onDemandCertificates_static \ # qnetworkproxyfactory \ # Uses a hardcoded proxy configuration !contains(QT_CONFIG, private_tests): SUBDIRS -= \ diff --git a/tests/auto/networkselftest/tst_networkselftest.cpp b/tests/auto/networkselftest/tst_networkselftest.cpp index cfcafc0..64de64a 100644 --- a/tests/auto/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/networkselftest/tst_networkselftest.cpp @@ -967,7 +967,7 @@ void tst_NetworkSelfTest::smbServer() QVERIFY2(f, qt_error_string().toLocal8Bit()); char buf[128]; - size_t ret = fread(buf, sizeof buf, 1, f); + size_t ret = fread(buf, 1, sizeof buf, f); fclose(f); QCOMPARE(ret, strlen(contents)); diff --git a/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp b/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp index 6331db7..db0d0a7 100644 --- a/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp +++ b/tests/auto/qabstractnetworkcache/tst_qabstractnetworkcache.cpp @@ -331,7 +331,7 @@ void tst_QAbstractNetworkCache::checkSynchronous() QNetworkRequest request(realUrl); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(QNetworkRequest::DownloadBufferAttribute + 1), + QNetworkRequest::SynchronousRequestAttribute, true); // prime the cache diff --git a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp index 10fa7c6..41da16e 100644 --- a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp +++ b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp @@ -60,8 +60,8 @@ QString tst_QNetworkProxyFactory::formatProxyName(const QNetworkProxy & proxy) c QString proxyName; if (!proxy.user().isNull()) proxyName.append("%1:%2@").arg(proxy.user(), proxy.password()); - proxyName.append("%1:%2").arg(proxy.hostName(), proxy.port()); - proxyName.append(" (type=%1, capabilities=%2)").arg(proxy.type(), proxy.capabilities()); + proxyName.append(QString("%1:%2").arg(proxy.hostName()).arg(proxy.port())); + proxyName.append(QString(" (type=%1, capabilities=%2)").arg(proxy.type()).arg(proxy.capabilities())); return proxyName; } diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 3715162..93e3051 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -84,8 +84,6 @@ Q_DECLARE_METATYPE(QList<QNetworkProxy>) Q_DECLARE_METATYPE(QNetworkReply::NetworkError) Q_DECLARE_METATYPE(QBuffer*) -const int SynchronousRequestAttribute = QNetworkRequest::DownloadBufferAttribute + 1; - class QNetworkReplyPtr: public QSharedPointer<QNetworkReply> { public: @@ -327,6 +325,7 @@ private Q_SLOTS: void ioGetFromHttpBrokenChunkedEncoding(); void qtbug12908compressedHttpReply(); + void compressedHttpReplyBrokenGzip(); void getFromUnreachableIp(); @@ -340,7 +339,9 @@ private Q_SLOTS: void synchronousRequest_data(); void synchronousRequest(); +#ifndef QT_NO_OPENSSL void synchronousRequestSslFailure(); +#endif void httpAbort(); @@ -457,6 +458,7 @@ private: { //qDebug() << "connectSocketSignals" << client; connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot())); connect(client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError))); } @@ -484,15 +486,19 @@ public slots: if (multiple) receivedData.remove(0, doubleEndlPos+4); - client->write(dataToTransmit); - while (client->bytesToWrite() > 0) - client->waitForBytesWritten(); + // we need to emulate the bytesWrittenSlot call if the data is empty. + if (dataToTransmit.size() == 0) + QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection); + else + client->write(dataToTransmit); + } + } - if (doClose) { - client->disconnectFromHost(); - disconnect(client, 0, this, 0); - client = 0; - } + void bytesWrittenSlot() { + if (doClose && client->bytesToWrite() == 0) { + client->disconnectFromHost(); + disconnect(client, 0, this, 0); + client = 0; } } }; @@ -961,7 +967,9 @@ tst_QNetworkReply::tst_QNetworkReply() qRegisterMetaType<QNetworkReply *>(); // for QSignalSpy qRegisterMetaType<QAuthenticator *>(); qRegisterMetaType<QNetworkProxy>(); +#ifndef QT_NO_OPENSSL qRegisterMetaType<QList<QSslError> >(); +#endif Q_SET_DEFAULT_IAP @@ -1057,7 +1065,7 @@ QString tst_QNetworkReply::runSimpleRequest(QNetworkAccessManager::Operation op, returnCode = Timeout; int code = Success; - if (request.attribute(static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute)).toBool()) { + if (request.attribute(QNetworkRequest::SynchronousRequestAttribute).toBool()) { if (reply->isFinished()) code = reply->error() != QNetworkReply::NoError ? Failure : Success; else @@ -1494,6 +1502,12 @@ void tst_QNetworkReply::getErrors() { QFETCH(QString, url); QNetworkRequest request(url); + +#if defined(Q_OS_WIN) || defined (Q_OS_SYMBIAN) + if (qstrcmp(QTest::currentDataTag(), "empty-scheme-host") == 0) + QTest::ignoreMessage(QtWarningMsg, "QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files"); +#endif + QNetworkReplyPtr reply = manager.get(request); reply->setParent(this); // we have expect-fails @@ -1508,6 +1522,9 @@ void tst_QNetworkReply::getErrors() //qDebug() << reply->errorString(); 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); +#endif QEXPECT_FAIL("ftp-is-dir", "QFtp cannot provide enough detail", Abort); // the line below is not necessary QEXPECT_FAIL("ftp-dir-not-readable", "QFtp cannot provide enough detail", Abort); @@ -1680,7 +1697,7 @@ void tst_QNetworkReply::putToHttpSynchronous() QFETCH(QByteArray, data); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); RUN_REQUEST(runSimpleRequest(QNetworkAccessManager::PutOperation, request, reply, data)); @@ -1740,7 +1757,7 @@ void tst_QNetworkReply::postToHttpSynchronous() QNetworkRequest request(url); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QNetworkReplyPtr reply; @@ -2255,7 +2272,7 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() // now check with synchronous calls: { request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QSignalSpy authspy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); @@ -2279,7 +2296,7 @@ void tst_QNetworkReply::ioGetFromHttpWithAuthSynchronous() QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt")); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QSignalSpy authspy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); @@ -2364,7 +2381,7 @@ void tst_QNetworkReply::ioGetFromHttpWithProxyAuth() reference.seek(0); { request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QSignalSpy authspy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); @@ -2390,7 +2407,7 @@ void tst_QNetworkReply::ioGetFromHttpWithProxyAuthSynchronous() QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); manager.setProxy(proxy); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QSignalSpy authspy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); @@ -3503,7 +3520,7 @@ void tst_QNetworkReply::ioPostToHttpFromSocketSynchronous() QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi"); QNetworkRequest request(url); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QNetworkReplyPtr reply = manager.post(request, socketpair.endPoints[1]); @@ -3695,12 +3712,12 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress() incomingSocket->setReadBufferSize(1*1024); QTestEventLoop::instance().enterLoop(2); // some progress should have been made + QVERIFY(!spy.isEmpty()); QList<QVariant> args = spy.last(); qDebug() << "tst_QNetworkReply::ioPostToHttpsUploadProgress" << args.at(0).toLongLong() << sourceFile.size() << spy.size(); - QVERIFY(!args.isEmpty()); QVERIFY(args.at(0).toLongLong() > 0); // FIXME this is where it messes up @@ -3711,16 +3728,16 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress() incomingSocket->read(16*1024); QTestEventLoop::instance().enterLoop(2); // some more progress than before + QVERIFY(!spy.isEmpty()); QList<QVariant> args2 = spy.last(); - QVERIFY(!args2.isEmpty()); QVERIFY(args2.at(0).toLongLong() > args.at(0).toLongLong()); // set the read buffer to unlimited incomingSocket->setReadBufferSize(0); QTestEventLoop::instance().enterLoop(10); // progress should be finished + QVERIFY(!spy.isEmpty()); QList<QVariant> args3 = spy.last(); - QVERIFY(!args3.isEmpty()); QVERIFY(args3.at(0).toLongLong() > args2.at(0).toLongLong()); QCOMPARE(args3.at(0).toLongLong(), args3.at(1).toLongLong()); QCOMPARE(args3.at(0).toLongLong(), sourceFile.size()); @@ -3810,6 +3827,8 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() if (reader.data.size() < testData.size()) { // oops? QCOMPARE(reader.data, testData.mid(0, reader.data.size())); qDebug() << "The data is incomplete, the last" << testData.size() - reader.data.size() << "bytes are missing"; + QEXPECT_FAIL("http+limited", "Limiting is broken right now, check QTBUG-15065", Abort); + QEXPECT_FAIL("https+limited", "Limiting is broken right now, check QTBUG-15065", Abort); } QCOMPARE(reader.data.size(), testData.size()); QCOMPARE(reader.data, testData); @@ -3822,8 +3841,8 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() 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", Continue); - QEXPECT_FAIL("https+limited", "Limiting is broken right now", Continue); + 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); } } @@ -4274,7 +4293,7 @@ void tst_QNetworkReply::receiveCookiesFromHttpSynchronous() QNetworkRequest request(url); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QNetworkReplyPtr reply; @@ -4366,7 +4385,7 @@ void tst_QNetworkReply::sendCookiesSynchronous() QNetworkRequest request(url); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QNetworkReplyPtr reply; @@ -4508,7 +4527,7 @@ void tst_QNetworkReply::httpProxyCommandsSynchronous() // send synchronous request request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QNetworkReplyPtr reply = manager.get(request); @@ -5234,6 +5253,7 @@ void tst_QNetworkReply::qtbug12908compressedHttpReply() // dd if=/dev/zero of=qtbug-12908 bs=16384 count=1 && gzip qtbug-12908 && base64 -w 0 qtbug-12908.gz QString encodedFile("H4sICDdDaUwAA3F0YnVnLTEyOTA4AO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAIC3AYbSVKsAQAAA"); QByteArray decodedFile = QByteArray::fromBase64(encodedFile.toAscii()); + QCOMPARE(decodedFile.size(), 63); MiniHttpServer server(header.toAscii() + decodedFile); server.doClose = true; @@ -5246,6 +5266,31 @@ void tst_QNetworkReply::qtbug12908compressedHttpReply() QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(reply->error(), QNetworkReply::NoError); + QCOMPARE(reply->size(), qint64(16384)); + QCOMPARE(reply->readAll(), QByteArray(16384, '\0')); +} + +void tst_QNetworkReply::compressedHttpReplyBrokenGzip() +{ + QString header("HTTP/1.0 200 OK\r\nContent-Encoding: gzip\r\nContent-Length: 63\r\n\r\n"); + + // dd if=/dev/zero of=qtbug-12908 bs=16384 count=1 && gzip qtbug-12908 && base64 -w 0 qtbug-12908.gz + // Then change "BMQ" to "BMX" + QString encodedFile("H4sICDdDaUwAA3F0YnVnLTEyOTA4AO3BMXEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAIC3AYbSVKsAQAAA"); + QByteArray decodedFile = QByteArray::fromBase64(encodedFile.toAscii()); + QCOMPARE(decodedFile.size(), 63); + + MiniHttpServer server(header.toAscii() + decodedFile); + server.doClose = true; + + QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); + QNetworkReplyPtr reply = manager.get(request); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(reply->error(), QNetworkReply::ProtocolFailure); } // TODO add similar test for FTP @@ -5454,7 +5499,7 @@ void tst_QNetworkReply::synchronousRequest() #endif request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QNetworkReplyPtr reply; @@ -5485,6 +5530,7 @@ void tst_QNetworkReply::synchronousRequest() reply->deleteLater(); } +#ifndef QT_NO_OPENSSL void tst_QNetworkReply::synchronousRequestSslFailure() { // test that SSL won't be accepted with self-signed certificate, @@ -5494,7 +5540,7 @@ void tst_QNetworkReply::synchronousRequestSslFailure() QUrl url("https://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"); QNetworkRequest request(url); request.setAttribute( - static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), + QNetworkRequest::SynchronousRequestAttribute, true); QNetworkReplyPtr reply; QSignalSpy sslErrorsSpy(&manager, SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &))); @@ -5503,6 +5549,7 @@ void tst_QNetworkReply::synchronousRequestSslFailure() QCOMPARE(reply->error(), QNetworkReply::SslHandshakeFailedError); QCOMPARE(sslErrorsSpy.count(), 0); } +#endif void tst_QNetworkReply::httpAbort() { diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp index 8177d29..739f902 100644 --- a/tests/auto/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp @@ -390,6 +390,9 @@ void tst_QSslSocket::constructing() QSslConfiguration savedDefault = QSslConfiguration::defaultConfiguration(); // verify that changing the default config doesn't affect this socket + // (on Unix, the ca certs might be empty, depending on whether we load + // them on demand or not, so set them explicitly) + socket.setCaCertificates(QSslSocket::systemCaCertificates()); QSslSocket::setDefaultCaCertificates(QList<QSslCertificate>()); QSslSocket::setDefaultCiphers(QList<QSslCipher>()); QVERIFY(!socket.caCertificates().isEmpty()); @@ -518,11 +521,6 @@ void tst_QSslSocket::sslErrors_data() << 993 << (SslErrorList() << QSslError::HostNameMismatch << QSslError::SelfSignedCertificate); - - QTest::newRow("imap.trolltech.com") - << "imap.trolltech.com" - << 993 - << (SslErrorList() << QSslError::SelfSignedCertificateInChain); } void tst_QSslSocket::sslErrors() diff --git a/tests/auto/qsslsocket_onDemandCertificates_member/qsslsocket_onDemandCertificates_member.pro b/tests/auto/qsslsocket_onDemandCertificates_member/qsslsocket_onDemandCertificates_member.pro new file mode 100644 index 0000000..ea62865 --- /dev/null +++ b/tests/auto/qsslsocket_onDemandCertificates_member/qsslsocket_onDemandCertificates_member.pro @@ -0,0 +1,36 @@ +load(qttest_p4) + +SOURCES += tst_qsslsocket_onDemandCertificates_member.cpp +!wince*:win32:LIBS += -lws2_32 +QT += network +QT -= gui + +TARGET = tst_qsslsocket_onDemandCertificates_member + +win32 { + CONFIG(debug, debug|release) { + DESTDIR = debug +} else { + DESTDIR = release + } +} + +wince* { + DEFINES += SRCDIR=\\\"./\\\" + + certFiles.files = certs ssl.tar.gz + certFiles.path = . + DEPLOYMENT += certFiles +} else:symbian { + TARGET.EPOCHEAPSIZE="0x100 0x1000000" + TARGET.CAPABILITY=NetworkServices + + certFiles.files = certs ssl.tar.gz + certFiles.path = . + DEPLOYMENT += certFiles + INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE # Needed for e32svr.h in S^3 envs +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + +requires(contains(QT_CONFIG,private_tests)) diff --git a/tests/auto/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp b/tests/auto/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp new file mode 100644 index 0000000..2a1358d --- /dev/null +++ b/tests/auto/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtNetwork> +#include <QtTest/QtTest> + +#include <QNetworkProxy> +#include <QAuthenticator> + +#include "private/qhostinfo_p.h" + +#include "../network-settings.h" + +#ifdef Q_OS_SYMBIAN +#define SRCDIR "" +#endif + +#ifndef QT_NO_OPENSSL +class QSslSocketPtr: public QSharedPointer<QSslSocket> +{ +public: + inline QSslSocketPtr(QSslSocket *ptr = 0) + : QSharedPointer<QSslSocket>(ptr) + { } + + inline operator QSslSocket *() const { return data(); } +}; +#endif + +class tst_QSslSocket_onDemandCertificates_member : public QObject +{ + Q_OBJECT + + int proxyAuthCalled; + +public: + tst_QSslSocket_onDemandCertificates_member(); + virtual ~tst_QSslSocket_onDemandCertificates_member(); + +#ifndef QT_NO_OPENSSL + QSslSocketPtr newSocket(); +#endif + +public slots: + void initTestCase_data(); + void init(); + void cleanup(); + void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth); + +#ifndef QT_NO_OPENSSL +private slots: + void onDemandRootCertLoadingMemberMethods(); + +private: + QSslSocket *socket; +#endif // QT_NO_OPENSSL +}; + +tst_QSslSocket_onDemandCertificates_member::tst_QSslSocket_onDemandCertificates_member() +{ + Q_SET_DEFAULT_IAP +} + +tst_QSslSocket_onDemandCertificates_member::~tst_QSslSocket_onDemandCertificates_member() +{ +} + +enum ProxyTests { + NoProxy = 0x00, + Socks5Proxy = 0x01, + HttpProxy = 0x02, + TypeMask = 0x0f, + + NoAuth = 0x00, + AuthBasic = 0x10, + AuthNtlm = 0x20, + AuthMask = 0xf0 +}; + +void tst_QSslSocket_onDemandCertificates_member::initTestCase_data() +{ + QTest::addColumn<bool>("setProxy"); + QTest::addColumn<int>("proxyType"); + + QTest::newRow("WithoutProxy") << false << 0; + QTest::newRow("WithSocks5Proxy") << true << int(Socks5Proxy); + QTest::newRow("WithSocks5ProxyAuth") << true << int(Socks5Proxy | AuthBasic); + + QTest::newRow("WithHttpProxy") << true << int(HttpProxy); + QTest::newRow("WithHttpProxyBasicAuth") << true << int(HttpProxy | AuthBasic); + // uncomment the line below when NTLM works +// QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm); +} + +void tst_QSslSocket_onDemandCertificates_member::init() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) { + QFETCH_GLOBAL(int, proxyType); + QString testServer = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString(); + QNetworkProxy proxy; + + switch (proxyType) { + case Socks5Proxy: + proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy, testServer, 1080); + break; + + case Socks5Proxy | AuthBasic: + proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy, testServer, 1081); + break; + + case HttpProxy | NoAuth: + proxy = QNetworkProxy(QNetworkProxy::HttpProxy, testServer, 3128); + break; + + case HttpProxy | AuthBasic: + proxy = QNetworkProxy(QNetworkProxy::HttpProxy, testServer, 3129); + break; + + case HttpProxy | AuthNtlm: + proxy = QNetworkProxy(QNetworkProxy::HttpProxy, testServer, 3130); + break; + } + QNetworkProxy::setApplicationProxy(proxy); + } + + qt_qhostinfo_clear_cache(); +} + +void tst_QSslSocket_onDemandCertificates_member::cleanup() +{ + QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); +} + +#ifndef QT_NO_OPENSSL +QSslSocketPtr tst_QSslSocket_onDemandCertificates_member::newSocket() +{ + QSslSocket *socket = new QSslSocket; + + proxyAuthCalled = 0; + connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + Qt::DirectConnection); + + return QSslSocketPtr(socket); +} +#endif + +void tst_QSslSocket_onDemandCertificates_member::proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth) +{ + ++proxyAuthCalled; + auth->setUser("qsockstest"); + auth->setPassword("password"); +} + +#ifndef QT_NO_OPENSSL + +void tst_QSslSocket_onDemandCertificates_member::onDemandRootCertLoadingMemberMethods() +{ + QString host("qt.nokia.com"); + + // not using any root certs -> should not work + QSslSocketPtr socket2 = newSocket(); + this->socket = socket2; + socket2->setCaCertificates(QList<QSslCertificate>()); + socket2->connectToHostEncrypted(host, 443); + QVERIFY(!socket2->waitForEncrypted()); + + // default: using on demand loading -> should work + QSslSocketPtr socket = newSocket(); + this->socket = socket; + socket->connectToHostEncrypted(host, 443); + QVERIFY(socket->waitForEncrypted()); + + // not using any root certs again -> should not work + QSslSocketPtr socket3 = newSocket(); + this->socket = socket3; + socket3->setCaCertificates(QList<QSslCertificate>()); + socket3->connectToHostEncrypted(host, 443); + QVERIFY(!socket3->waitForEncrypted()); +} + +#endif // QT_NO_OPENSSL + +QTEST_MAIN(tst_QSslSocket_onDemandCertificates_member) +#include "tst_qsslsocket_onDemandCertificates_member.moc" diff --git a/tests/auto/qsslsocket_onDemandCertificates_static/qsslsocket_onDemandCertificates_static.pro b/tests/auto/qsslsocket_onDemandCertificates_static/qsslsocket_onDemandCertificates_static.pro new file mode 100644 index 0000000..13990cb --- /dev/null +++ b/tests/auto/qsslsocket_onDemandCertificates_static/qsslsocket_onDemandCertificates_static.pro @@ -0,0 +1,36 @@ +load(qttest_p4) + +SOURCES += tst_qsslsocket_onDemandCertificates_static.cpp +!wince*:win32:LIBS += -lws2_32 +QT += network +QT -= gui + +TARGET = tst_qsslsocket_onDemandCertificates_static + +win32 { + CONFIG(debug, debug|release) { + DESTDIR = debug +} else { + DESTDIR = release + } +} + +wince* { + DEFINES += SRCDIR=\\\"./\\\" + + certFiles.files = certs ssl.tar.gz + certFiles.path = . + DEPLOYMENT += certFiles +} else:symbian { + TARGET.EPOCHEAPSIZE="0x100 0x1000000" + TARGET.CAPABILITY=NetworkServices + + certFiles.files = certs ssl.tar.gz + certFiles.path = . + DEPLOYMENT += certFiles + INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE # Needed for e32svr.h in S^3 envs +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + +requires(contains(QT_CONFIG,private_tests)) diff --git a/tests/auto/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp b/tests/auto/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp new file mode 100644 index 0000000..8259977 --- /dev/null +++ b/tests/auto/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtNetwork> +#include <QtTest/QtTest> + +#include <QNetworkProxy> +#include <QAuthenticator> + +#include "private/qhostinfo_p.h" + +#include "../network-settings.h" + +#ifdef Q_OS_SYMBIAN +#define SRCDIR "" +#endif + +#ifndef QT_NO_OPENSSL +class QSslSocketPtr: public QSharedPointer<QSslSocket> +{ +public: + inline QSslSocketPtr(QSslSocket *ptr = 0) + : QSharedPointer<QSslSocket>(ptr) + { } + + inline operator QSslSocket *() const { return data(); } +}; +#endif + +class tst_QSslSocket_onDemandCertificates_static : public QObject +{ + Q_OBJECT + + int proxyAuthCalled; + +public: + tst_QSslSocket_onDemandCertificates_static(); + virtual ~tst_QSslSocket_onDemandCertificates_static(); + +#ifndef QT_NO_OPENSSL + QSslSocketPtr newSocket(); +#endif + +public slots: + void initTestCase_data(); + void init(); + void cleanup(); + void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth); + +#ifndef QT_NO_OPENSSL +private slots: + void onDemandRootCertLoadingStaticMethods(); + +private: + QSslSocket *socket; +#endif // QT_NO_OPENSSL +}; + +tst_QSslSocket_onDemandCertificates_static::tst_QSslSocket_onDemandCertificates_static() +{ + Q_SET_DEFAULT_IAP +} + +tst_QSslSocket_onDemandCertificates_static::~tst_QSslSocket_onDemandCertificates_static() +{ +} + +enum ProxyTests { + NoProxy = 0x00, + Socks5Proxy = 0x01, + HttpProxy = 0x02, + TypeMask = 0x0f, + + NoAuth = 0x00, + AuthBasic = 0x10, + AuthNtlm = 0x20, + AuthMask = 0xf0 +}; + +void tst_QSslSocket_onDemandCertificates_static::initTestCase_data() +{ + QTest::addColumn<bool>("setProxy"); + QTest::addColumn<int>("proxyType"); + + QTest::newRow("WithoutProxy") << false << 0; + QTest::newRow("WithSocks5Proxy") << true << int(Socks5Proxy); + QTest::newRow("WithSocks5ProxyAuth") << true << int(Socks5Proxy | AuthBasic); + + QTest::newRow("WithHttpProxy") << true << int(HttpProxy); + QTest::newRow("WithHttpProxyBasicAuth") << true << int(HttpProxy | AuthBasic); + // uncomment the line below when NTLM works +// QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm); +} + +void tst_QSslSocket_onDemandCertificates_static::init() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) { + QFETCH_GLOBAL(int, proxyType); + QString testServer = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString(); + QNetworkProxy proxy; + + switch (proxyType) { + case Socks5Proxy: + proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy, testServer, 1080); + break; + + case Socks5Proxy | AuthBasic: + proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy, testServer, 1081); + break; + + case HttpProxy | NoAuth: + proxy = QNetworkProxy(QNetworkProxy::HttpProxy, testServer, 3128); + break; + + case HttpProxy | AuthBasic: + proxy = QNetworkProxy(QNetworkProxy::HttpProxy, testServer, 3129); + break; + + case HttpProxy | AuthNtlm: + proxy = QNetworkProxy(QNetworkProxy::HttpProxy, testServer, 3130); + break; + } + QNetworkProxy::setApplicationProxy(proxy); + } + + qt_qhostinfo_clear_cache(); +} + +void tst_QSslSocket_onDemandCertificates_static::cleanup() +{ + QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); +} + +#ifndef QT_NO_OPENSSL +QSslSocketPtr tst_QSslSocket_onDemandCertificates_static::newSocket() +{ + QSslSocket *socket = new QSslSocket; + + proxyAuthCalled = 0; + connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + Qt::DirectConnection); + + return QSslSocketPtr(socket); +} +#endif + +void tst_QSslSocket_onDemandCertificates_static::proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth) +{ + ++proxyAuthCalled; + auth->setUser("qsockstest"); + auth->setPassword("password"); +} + +#ifndef QT_NO_OPENSSL + +void tst_QSslSocket_onDemandCertificates_static::onDemandRootCertLoadingStaticMethods() +{ + QString host("qt.nokia.com"); + + // not using any root certs -> should not work + QSslSocket::setDefaultCaCertificates(QList<QSslCertificate>()); + QSslSocketPtr socket = newSocket(); + this->socket = socket; + socket->connectToHostEncrypted(host, 443); + QVERIFY(!socket->waitForEncrypted()); + + // using system root certs -> should work + QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates()); + QSslSocketPtr socket2 = newSocket(); + this->socket = socket2; + socket2->connectToHostEncrypted(host, 443); + QVERIFY(socket2->waitForEncrypted()); + + // not using any root certs again -> should not work + QSslSocket::setDefaultCaCertificates(QList<QSslCertificate>()); + QSslSocketPtr socket3 = newSocket(); + this->socket = socket3; + socket3->connectToHostEncrypted(host, 443); + QVERIFY(!socket3->waitForEncrypted()); +} + +#endif // QT_NO_OPENSSL + +QTEST_MAIN(tst_QSslSocket_onDemandCertificates_static) +#include "tst_qsslsocket_onDemandCertificates_static.moc" diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp index 6cff7c53..c2acc18 100644 --- a/tests/auto/qtimer/tst_qtimer.cpp +++ b/tests/auto/qtimer/tst_qtimer.cpp @@ -50,6 +50,8 @@ #include <unistd.h> #endif +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES= @@ -272,9 +274,9 @@ void tst_QTimer::livelock() QFETCH(int, interval); LiveLockTester tester(interval); QTest::qWait(180); // we have to use wait here, since we're testing timers with a non-zero timeout - QCOMPARE(tester.timeoutsForFirst, 1); + QTRY_COMPARE(tester.timeoutsForFirst, 1); QCOMPARE(tester.timeoutsForExtra, 0); - QCOMPARE(tester.timeoutsForSecond, 1); + QTRY_COMPARE(tester.timeoutsForSecond, 1); #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) if (QSysInfo::WindowsVersion < QSysInfo::WV_XP) QEXPECT_FAIL("non-zero timer", "Multimedia timers are not available on Windows 2000", Continue); @@ -724,7 +726,7 @@ void tst_QTimer::QTBUG13633_dontBlockEvents() { DontBlockEvents t; QTest::qWait(60); - QVERIFY(t.total > 2); + QTRY_VERIFY(t.total > 2); } class SlotRepeater : public QObject { diff --git a/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp index 6cb62d0..041b61a 100644 --- a/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -46,7 +46,7 @@ #include <qsslsocket.h> -// #include "../../../../auto/network-settings.h" +#include "../../../../auto/network-settings.h" //TESTED_CLASS= //TESTED_FILES= @@ -65,6 +65,7 @@ public slots: void init(); void cleanup(); private slots: + void rootCertLoading(); void systemCaCertificates(); }; @@ -89,6 +90,16 @@ void tst_QSslSocket::cleanup() } //---------------------------------------------------------------------------------- + +void tst_QSslSocket::rootCertLoading() +{ + QBENCHMARK_ONCE { + QSslSocket socket; + socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); + socket.waitForEncrypted(); + } +} + void tst_QSslSocket::systemCaCertificates() { // The results of this test change if the benchmarking system changes too much. diff --git a/tests/benchmarks/script/sunspider/tst_sunspider.cpp b/tests/benchmarks/script/sunspider/tst_sunspider.cpp index 0df19b6..9e2bb6f 100644 --- a/tests/benchmarks/script/sunspider/tst_sunspider.cpp +++ b/tests/benchmarks/script/sunspider/tst_sunspider.cpp @@ -110,7 +110,7 @@ void tst_SunSpider::benchmark_data() void tst_SunSpider::benchmark() { QFETCH(QString, testName); - QString testContents = readFile(testsDir.absoluteFilePath(testName + ".js")); + QString testContents = readFile(testsDir.filePath(testName + ".js")); QVERIFY(!testContents.isEmpty()); QScriptEngine engine; diff --git a/tests/benchmarks/script/v8/tst_v8.cpp b/tests/benchmarks/script/v8/tst_v8.cpp index 841e2f3..b9cb859 100644 --- a/tests/benchmarks/script/v8/tst_v8.cpp +++ b/tests/benchmarks/script/v8/tst_v8.cpp @@ -115,10 +115,10 @@ void tst_V8::benchmark() { QFETCH(QString, testName); - QString baseDotJsContents = readFile(testsDir.absoluteFilePath("base.js")); + QString baseDotJsContents = readFile(testsDir.filePath("base.js")); QVERIFY(!baseDotJsContents.isEmpty()); - QString testContents = readFile(testsDir.absoluteFilePath(testName + ".js")); + QString testContents = readFile(testsDir.filePath(testName + ".js")); QVERIFY(!testContents.isEmpty()); QScriptEngine engine; |