From 5b00bb39f2f079e4745a0ca6f3a8c56e18bd2775 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 21 Mar 2014 10:35:09 +0100 Subject: [PATCH] Polish tst_qsslsocket a bit. Output the SSL library version, output socket error string on connection failure consistently, silence numerous warnings about QIODevice not being open in tst_QSslSocket::constructing. Change-Id: Ia23d42de5b2daca55b2f6f50af025d61e99c52a0 Reviewed-by: Peter Hartmann --- .../network/ssl/qsslsocket/tst_qsslsocket.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 6eb20dd1f5..ded3966992 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -271,6 +271,9 @@ void tst_QSslSocket::initTestCase_data() void tst_QSslSocket::initTestCase() { + qDebug("Using SSL library %s (%ld)", + qPrintable(QSslSocket::sslLibraryVersionString()), + QSslSocket::sslLibraryVersionNumber()); QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); } @@ -347,6 +350,9 @@ void tst_QSslSocket::proxyAuthenticationRequired(const QNetworkProxy &, QAuthent void tst_QSslSocket::constructing() { + const char readNotOpenMessage[] = "QIODevice::read: device not open"; + const char writeNotOpenMessage[] = "QIODevice::write: device not open"; + if (!QSslSocket::supportsSsl()) return; @@ -363,6 +369,7 @@ void tst_QSslSocket::constructing() QCOMPARE(socket.sslConfiguration(), QSslConfiguration::defaultConfiguration()); QCOMPARE(socket.errorString(), QString("Unknown error")); char c = '\0'; + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(!socket.getChar(&c)); QCOMPARE(c, '\0'); QVERIFY(!socket.isOpen()); @@ -371,11 +378,16 @@ void tst_QSslSocket::constructing() QVERIFY(!socket.isTextModeEnabled()); QVERIFY(!socket.isWritable()); QCOMPARE(socket.openMode(), QIODevice::NotOpen); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(socket.peek(2).isEmpty()); QCOMPARE(socket.pos(), qint64(0)); + QTest::ignoreMessage(QtWarningMsg, writeNotOpenMessage); QVERIFY(!socket.putChar('c')); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(socket.read(2).isEmpty()); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QCOMPARE(socket.read(0, 0), qint64(-1)); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(socket.readAll().isEmpty()); QTest::ignoreMessage(QtWarningMsg, "QIODevice::readLine: Called with maxSize < 2"); QCOMPARE(socket.readLine(0, 0), qint64(-1)); @@ -388,7 +400,9 @@ void tst_QSslSocket::constructing() QCOMPARE(socket.size(), qint64(0)); QVERIFY(!socket.waitForBytesWritten(10)); QVERIFY(!socket.waitForReadyRead(10)); + QTest::ignoreMessage(QtWarningMsg, writeNotOpenMessage); QCOMPARE(socket.write(0, 0), qint64(-1)); + QTest::ignoreMessage(QtWarningMsg, writeNotOpenMessage); QCOMPARE(socket.write(QByteArray()), qint64(-1)); QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); QVERIFY(!socket.flush()); @@ -672,7 +686,7 @@ void tst_QSslSocket::sessionCipher() connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(ignoreErrorSlot())); QVERIFY(socket->sessionCipher().isNull()); socket->connectToHost(QtNetworkSettings::serverName(), 443 /* https */); - QVERIFY(socket->waitForConnected(10000)); + QVERIFY2(socket->waitForConnected(10000), qPrintable(socket->errorString())); QVERIFY(socket->sessionCipher().isNull()); socket->startClientEncryption(); if (!socket->waitForEncrypted(5000)) @@ -775,7 +789,7 @@ void tst_QSslSocket::peerCertificateChain() socket->connectToHost(QtNetworkSettings::serverName(), 443); QCOMPARE(socket->mode(), QSslSocket::UnencryptedMode); QVERIFY(socket->peerCertificateChain().isEmpty()); - QVERIFY2(socket->waitForConnected(10000), "Network timeout"); + QVERIFY2(socket->waitForConnected(10000), qPrintable(socket->errorString())); socket->startClientEncryption(); if (setProxy && !socket->waitForEncrypted(10000)) @@ -1334,7 +1348,7 @@ void tst_QSslSocket::waitForConnectedEncryptedReadyRead() connect(this->socket, SIGNAL(sslErrors(QList)), this, SLOT(ignoreErrorSlot())); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 993); - QVERIFY(socket->waitForConnected(10000)); + QVERIFY2(socket->waitForConnected(10000), qPrintable(socket->errorString())); QFETCH_GLOBAL(bool, setProxy); if (setProxy && !socket->waitForEncrypted(10000)) QSKIP("Skipping flaky test - See QTBUG-29941"); @@ -1679,7 +1693,7 @@ void tst_QSslSocket::setReadBufferSize_task_250027() socket->ignoreSslErrors(); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); socket->ignoreSslErrors(); - QVERIFY(socket->waitForConnected(10*1000)); + QVERIFY2(socket->waitForConnected(10*1000), qPrintable(socket->errorString())); if (setProxy && !socket->waitForEncrypted(10*1000)) QSKIP("Skipping flaky test - See QTBUG-29941");