From 0defa2782ff94420da546ff36502cfea7fd64511 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 6 Mar 2012 11:46:02 +0100 Subject: tst_qsslsocket*: don't inherit from QSharedPointer QSharedPointer is about to become final. Instead of inheriting from it to add implicit conversions to and from QSslSocket*, make QSslSocketPtr a typedef, and make the conversions explicit. Change-Id: I4eebb262ab5aef348f4d676f9e839325d4ed13da Reviewed-by: Thiago Macieira --- .../auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 72 ++++++++++------------ .../tst_qsslsocket_onDemandCertificates_member.cpp | 18 ++---- .../tst_qsslsocket_onDemandCertificates_static.cpp | 18 ++---- 3 files changed, 42 insertions(+), 66 deletions(-) diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 2f9ed0d089..23e87b7f3b 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -81,15 +81,7 @@ Q_DECLARE_METATYPE(QSslConfiguration) #endif #ifndef QT_NO_SSL -class QSslSocketPtr: public QSharedPointer -{ -public: - inline QSslSocketPtr(QSslSocket *ptr = 0) - : QSharedPointer(ptr) - { } - - inline operator QSslSocket *() const { return data(); } -}; +typedef QSharedPointer QSslSocketPtr; #endif class tst_QSslSocket : public QObject @@ -605,10 +597,10 @@ void tst_QSslSocket::connectToHostEncrypted() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); QVERIFY(socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem"))); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND - connect(socket, SIGNAL(sslErrors(QList)), + connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(untrustedWorkaroundSlot(QList))); #endif @@ -636,11 +628,11 @@ void tst_QSslSocket::connectToHostEncryptedWithVerificationPeerName() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND - connect(socket, SIGNAL(sslErrors(QList)), + connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(untrustedWorkaroundSlot(QList))); #endif @@ -662,8 +654,8 @@ void tst_QSslSocket::sessionCipher() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; - connect(socket, SIGNAL(sslErrors(QList)), this, SLOT(ignoreErrorSlot())); + this->socket = socket.data(); + connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(ignoreErrorSlot())); QVERIFY(socket->sessionCipher().isNull()); socket->connectToHost(QtNetworkSettings::serverName(), 443 /* https */); QVERIFY(socket->waitForConnected(10000)); @@ -717,13 +709,13 @@ void tst_QSslSocket::peerCertificateChain() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); QList caCertificates = QSslCertificate::fromPath(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")); QVERIFY(caCertificates.count() == 1); socket->addCaCertificates(caCertificates); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND - connect(socket, SIGNAL(sslErrors(QList)), + connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(untrustedWorkaroundSlot(QList))); #endif @@ -806,7 +798,7 @@ void tst_QSslSocket::protocol() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); QList certs = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"); socket->setCaCertificates(certs); @@ -1032,14 +1024,14 @@ void tst_QSslSocket::protocolServerSide() QEventLoop loop; QTimer::singleShot(5000, &loop, SLOT(quit())); - QSslSocketPtr client = new QSslSocket; - socket = client; + QSslSocketPtr client(new QSslSocket); + socket = client.data(); QFETCH(QSsl::SslProtocol, clientProtocol); socket->setProtocol(clientProtocol); // upon SSL wrong version error, error will be triggered, not sslErrors connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), &loop, SLOT(quit())); connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); - connect(client, SIGNAL(encrypted()), &loop, SLOT(quit())); + connect(socket, SIGNAL(encrypted()), &loop, SLOT(quit())); client->connectToHostEncrypted(QHostAddress(QHostAddress::LocalHost).toString(), server.serverPort()); @@ -1091,10 +1083,10 @@ void tst_QSslSocket::setSocketDescriptor() QEventLoop loop; QTimer::singleShot(5000, &loop, SLOT(quit())); - QSslSocketPtr client = new QSslSocket; - socket = client; + QSslSocketPtr client(new QSslSocket); + socket = client.data();; connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); - connect(client, SIGNAL(encrypted()), &loop, SLOT(quit())); + connect(socket, SIGNAL(encrypted()), &loop, SLOT(quit())); client->connectToHostEncrypted(QHostAddress(QHostAddress::LocalHost).toString(), server.serverPort()); @@ -1131,7 +1123,7 @@ void tst_QSslSocket::setSslConfiguration() QSslSocketPtr socket = newSocket(); QFETCH(QSslConfiguration, configuration); socket->setSslConfiguration(configuration); - this->socket = socket; + this->socket = socket.data(); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); QFETCH(bool, works); QCOMPARE(socket->waitForEncrypted(10000), works); @@ -1147,9 +1139,9 @@ void tst_QSslSocket::waitForEncrypted() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); - connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); + connect(this->socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); QVERIFY(socket->waitForEncrypted(10000)); @@ -1164,9 +1156,9 @@ void tst_QSslSocket::waitForEncryptedMinusOne() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); - connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); + connect(this->socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); QVERIFY(socket->waitForEncrypted(-1)); @@ -1178,9 +1170,9 @@ void tst_QSslSocket::waitForConnectedEncryptedReadyRead() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); - connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); + connect(this->socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 993); QVERIFY(socket->waitForConnected(10000)); @@ -1315,7 +1307,7 @@ void tst_QSslSocket::wildcard() // valid connection. This was broken in 4.3.0. QSslSocketPtr socket = newSocket(); socket->addCaCertificates(QLatin1String("certs/aspiriniks.ca.crt")); - this->socket = socket; + this->socket = socket.data(); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND connect(socket, SIGNAL(sslErrors(QList)), this, SLOT(untrustedWorkaroundSlot(QList))); @@ -1520,7 +1512,7 @@ void tst_QSslSocket::setReadBufferSize_task_250027() // exit the event loop as soon as we receive a readyRead() SetReadBufferSize_task_250027_handler setReadBufferSize_task_250027_handler; - connect(socket, SIGNAL(readyRead()), &setReadBufferSize_task_250027_handler, SLOT(readyReadSlot())); + connect(socket.data(), SIGNAL(readyRead()), &setReadBufferSize_task_250027_handler, SLOT(readyReadSlot())); // provoke a response by sending a request socket->write("GET /qtest/fluke.gif HTTP/1.0\n"); // this file is 27 KB @@ -1532,13 +1524,13 @@ void tst_QSslSocket::setReadBufferSize_task_250027() socket->flush(); QTestEventLoop::instance().enterLoop(10); - setReadBufferSize_task_250027_handler.waitSomeMore(socket); + setReadBufferSize_task_250027_handler.waitSomeMore(socket.data()); QByteArray firstRead = socket->readAll(); // First read should be some data, but not the whole file QVERIFY(firstRead.size() > 0 && firstRead.size() < 20*1024); QTestEventLoop::instance().enterLoop(10); - setReadBufferSize_task_250027_handler.waitSomeMore(socket); + setReadBufferSize_task_250027_handler.waitSomeMore(socket.data()); QByteArray secondRead = socket->readAll(); // second read should be some more data QVERIFY(secondRead.size() > 0); @@ -1792,8 +1784,8 @@ void tst_QSslSocket::verifyDepth() void tst_QSslSocket::peerVerifyError() { QSslSocketPtr socket = newSocket(); - QSignalSpy sslErrorsSpy(socket, SIGNAL(sslErrors(QList))); - QSignalSpy peerVerifyErrorSpy(socket, SIGNAL(peerVerifyError(QSslError))); + QSignalSpy sslErrorsSpy(socket.data(), SIGNAL(sslErrors(QList))); + QSignalSpy peerVerifyErrorSpy(socket.data(), SIGNAL(peerVerifyError(QSslError))); socket->connectToHostEncrypted(QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString(), 443); QVERIFY(!socket->waitForEncrypted(10000)); @@ -1996,9 +1988,9 @@ void tst_QSslSocket::writeBigChunk() return; QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); - connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); + connect(this->socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); QByteArray data; @@ -2217,7 +2209,7 @@ void tst_QSslSocket::setEmptyDefaultConfiguration() // this test should be last, QSslConfiguration::setDefaultConfiguration(emptyConf); QSslSocketPtr socket = newSocket(); - connect(socket, SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); + connect(socket.data(), SIGNAL(sslErrors(const QList &)), this, SLOT(ignoreErrorSlot())); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); QVERIFY2(!socket->waitForEncrypted(4000), qPrintable(socket->errorString())); } diff --git a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp index bc0e04a1f2..ed9ee3be3f 100644 --- a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp +++ b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp @@ -51,15 +51,7 @@ #include "../../../network-settings.h" #ifndef QT_NO_OPENSSL -class QSslSocketPtr: public QSharedPointer -{ -public: - inline QSslSocketPtr(QSslSocket *ptr = 0) - : QSharedPointer(ptr) - { } - - inline operator QSslSocket *() const { return data(); } -}; +typedef QSharedPointer QSslSocketPtr; #endif class tst_QSslSocket_onDemandCertificates_member : public QObject @@ -201,28 +193,28 @@ void tst_QSslSocket_onDemandCertificates_member::onDemandRootCertLoadingMemberMe // not using any root certs -> should not work QSslSocketPtr socket2 = newSocket(); - this->socket = socket2; + this->socket = socket2.data(); socket2->setCaCertificates(QList()); socket2->connectToHostEncrypted(host, 443); QVERIFY(!socket2->waitForEncrypted()); // default: using on demand loading -> should work QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); socket->connectToHostEncrypted(host, 443); QEXPECT_FAIL("", "QTBUG-20983 fails", Abort); QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString())); // not using any root certs again -> should not work QSslSocketPtr socket3 = newSocket(); - this->socket = socket3; + this->socket = socket3.data(); socket3->setCaCertificates(QList()); socket3->connectToHostEncrypted(host, 443); QVERIFY(!socket3->waitForEncrypted()); // setting empty SSL configuration explicitly -> should not work QSslSocketPtr socket4 = newSocket(); - this->socket = socket4; + this->socket = socket4.data(); socket4->setSslConfiguration(QSslConfiguration()); socket4->connectToHostEncrypted(host, 443); QVERIFY(!socket4->waitForEncrypted()); diff --git a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp index dd01733fbe..ee038aa086 100644 --- a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp +++ b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp @@ -51,15 +51,7 @@ #include "../../../network-settings.h" #ifndef QT_NO_OPENSSL -class QSslSocketPtr: public QSharedPointer -{ -public: - inline QSslSocketPtr(QSslSocket *ptr = 0) - : QSharedPointer(ptr) - { } - - inline operator QSslSocket *() const { return data(); } -}; +typedef QSharedPointer QSslSocketPtr; #endif class tst_QSslSocket_onDemandCertificates_static : public QObject @@ -202,14 +194,14 @@ void tst_QSslSocket_onDemandCertificates_static::onDemandRootCertLoadingStaticMe // not using any root certs -> should not work QSslSocket::setDefaultCaCertificates(QList()); QSslSocketPtr socket = newSocket(); - this->socket = socket; + this->socket = socket.data(); socket->connectToHostEncrypted(host, 443); QVERIFY(!socket->waitForEncrypted()); // using system root certs -> should work QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates()); QSslSocketPtr socket2 = newSocket(); - this->socket = socket2; + this->socket = socket2.data(); socket2->connectToHostEncrypted(host, 443); QEXPECT_FAIL("", "QTBUG-20983 fails", Abort); QVERIFY2(socket2->waitForEncrypted(), qPrintable(socket2->errorString())); @@ -217,7 +209,7 @@ void tst_QSslSocket_onDemandCertificates_static::onDemandRootCertLoadingStaticMe // not using any root certs again -> should not work QSslSocket::setDefaultCaCertificates(QList()); QSslSocketPtr socket3 = newSocket(); - this->socket = socket3; + this->socket = socket3.data(); socket3->connectToHostEncrypted(host, 443); QVERIFY(!socket3->waitForEncrypted()); @@ -228,7 +220,7 @@ void tst_QSslSocket_onDemandCertificates_static::onDemandRootCertLoadingStaticMe QSslConfiguration originalDefaultConf = QSslConfiguration::defaultConfiguration(); QSslConfiguration::setDefaultConfiguration(conf); QSslSocketPtr socket4 = newSocket(); - this->socket = socket4; + this->socket = socket4.data(); socket4->connectToHostEncrypted(host, 443); QVERIFY(!socket4->waitForEncrypted(4000)); QSslConfiguration::setDefaultConfiguration(originalDefaultConf); // restore old behaviour for run with proxies etc. -- cgit v1.2.3