diff options
Diffstat (limited to 'tests')
9 files changed, 188 insertions, 26 deletions
diff --git a/tests/auto/corelib/io/qprocess/qprocess.pri b/tests/auto/corelib/io/qprocess/qprocess.pri index d5a7532ee1..8d17090545 100644 --- a/tests/auto/corelib/io/qprocess/qprocess.pri +++ b/tests/auto/corelib/io/qprocess/qprocess.pri @@ -11,6 +11,7 @@ SUBPROGRAMS = \ testProcessEOF \ testExitCodes \ testForwarding \ + testForwardingHelper \ testGuiProcess \ testDetached \ fileWriterProcess \ diff --git a/tests/auto/corelib/io/qprocess/testForwarding/main.cpp b/tests/auto/corelib/io/qprocess/testForwarding/main.cpp index b7367ff8c6..b5d56a1138 100644 --- a/tests/auto/corelib/io/qprocess/testForwarding/main.cpp +++ b/tests/auto/corelib/io/qprocess/testForwarding/main.cpp @@ -27,15 +27,32 @@ ****************************************************************************/ #include <QtCore/QCoreApplication> +#include <QtCore/QDeadlineTimer> #include <QtCore/QProcess> +#include <QtCore/QTemporaryFile> +#include <QtCore/QThread> #include <stdlib.h> +static bool waitForDoneFileWritten(const QString &filePath, int msecs = 30000) +{ + QDeadlineTimer t(msecs); + do { + QThread::msleep(250); + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) + continue; + if (file.readAll() == "That's all folks!") + return true; + } while (!t.hasExpired()); + return false; +} + int main(int argc, char **argv) { QCoreApplication app(argc, argv); - if (argc < 3) + if (argc < 4) return 13; QProcess process; @@ -50,23 +67,37 @@ int main(int argc, char **argv) if (process.inputChannelMode() != inmode) return 11; - process.start("testProcessEcho2/testProcessEcho2"); + if (atoi(argv[3])) { + QTemporaryFile doneFile("testForwarding_XXXXXX.txt"); + if (!doneFile.open()) + return 12; + doneFile.close(); + + process.setProgram("testForwardingHelper/testForwardingHelper"); + process.setArguments(QStringList(doneFile.fileName())); + if (!process.startDetached()) + return 13; + if (!waitForDoneFileWritten(doneFile.fileName())) + return 14; + } else { + process.start("testProcessEcho2/testProcessEcho2"); - if (!process.waitForStarted(5000)) - return 2; + if (!process.waitForStarted(5000)) + return 2; - if (inmode == QProcess::ManagedInputChannel && process.write("forwarded") != 9) - return 3; + if (inmode == QProcess::ManagedInputChannel && process.write("forwarded") != 9) + return 3; - process.closeWriteChannel(); - if (!process.waitForFinished(5000)) - return 4; + process.closeWriteChannel(); + if (!process.waitForFinished(5000)) + return 4; - if ((mode == QProcess::ForwardedOutputChannel || mode == QProcess::ForwardedChannels) + if ((mode == QProcess::ForwardedOutputChannel || mode == QProcess::ForwardedChannels) && !process.readAllStandardOutput().isEmpty()) - return 5; - if ((mode == QProcess::ForwardedErrorChannel || mode == QProcess::ForwardedChannels) + return 5; + if ((mode == QProcess::ForwardedErrorChannel || mode == QProcess::ForwardedChannels) && !process.readAllStandardError().isEmpty()) - return 6; + return 6; + } return 0; } diff --git a/tests/auto/corelib/io/qprocess/testForwardingHelper/main.cpp b/tests/auto/corelib/io/qprocess/testForwardingHelper/main.cpp new file mode 100644 index 0000000000..682ca7346b --- /dev/null +++ b/tests/auto/corelib/io/qprocess/testForwardingHelper/main.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <fstream> +#include <stdio.h> + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + puts("Usage: testForwardingHelper <doneFilePath>"); + return 1; + } + fputs("out data", stdout); + fputs("err data", stderr); + fflush(stdout); + fflush(stderr); + std::ofstream out(argv[1]); + out << "That's all folks!"; + return 0; +} diff --git a/tests/auto/corelib/io/qprocess/testForwardingHelper/testForwardingHelper.pro b/tests/auto/corelib/io/qprocess/testForwardingHelper/testForwardingHelper.pro new file mode 100644 index 0000000000..e236e05c7d --- /dev/null +++ b/tests/auto/corelib/io/qprocess/testForwardingHelper/testForwardingHelper.pro @@ -0,0 +1,4 @@ +SOURCES = main.cpp +CONFIG -= qt app_bundle +CONFIG += console +DESTDIR = ./ diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index e19653abf0..e0aa577154 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1047,32 +1047,50 @@ void tst_QProcess::mergedChannels() void tst_QProcess::forwardedChannels_data() { + QTest::addColumn<bool>("detach"); QTest::addColumn<int>("mode"); QTest::addColumn<int>("inmode"); QTest::addColumn<QByteArray>("outdata"); QTest::addColumn<QByteArray>("errdata"); - QTest::newRow("separate") << int(QProcess::SeparateChannels) << int(QProcess::ManagedInputChannel) - << QByteArray() << QByteArray(); - QTest::newRow("forwarded") << int(QProcess::ForwardedChannels) << int(QProcess::ManagedInputChannel) - << QByteArray("forwarded") << QByteArray("forwarded"); - QTest::newRow("stdout") << int(QProcess::ForwardedOutputChannel) << int(QProcess::ManagedInputChannel) - << QByteArray("forwarded") << QByteArray(); - QTest::newRow("stderr") << int(QProcess::ForwardedErrorChannel) << int(QProcess::ManagedInputChannel) - << QByteArray() << QByteArray("forwarded"); - QTest::newRow("fwdinput") << int(QProcess::ForwardedErrorChannel) << int(QProcess::ForwardedInputChannel) - << QByteArray() << QByteArray("input"); + QTest::newRow("separate") + << false + << int(QProcess::SeparateChannels) << int(QProcess::ManagedInputChannel) + << QByteArray() << QByteArray(); + QTest::newRow("forwarded") + << false + << int(QProcess::ForwardedChannels) << int(QProcess::ManagedInputChannel) + << QByteArray("forwarded") << QByteArray("forwarded"); + QTest::newRow("stdout") + << false + << int(QProcess::ForwardedOutputChannel) << int(QProcess::ManagedInputChannel) + << QByteArray("forwarded") << QByteArray(); + QTest::newRow("stderr") + << false + << int(QProcess::ForwardedErrorChannel) << int(QProcess::ManagedInputChannel) + << QByteArray() << QByteArray("forwarded"); + QTest::newRow("fwdinput") + << false + << int(QProcess::ForwardedErrorChannel) << int(QProcess::ForwardedInputChannel) + << QByteArray() << QByteArray("input"); + QTest::newRow("detached-default-forwarding") + << true + << int(QProcess::SeparateChannels) << int(QProcess::ManagedInputChannel) + << QByteArray("out data") << QByteArray("err data"); } void tst_QProcess::forwardedChannels() { + QFETCH(bool, detach); QFETCH(int, mode); QFETCH(int, inmode); QFETCH(QByteArray, outdata); QFETCH(QByteArray, errdata); QProcess process; - process.start("testForwarding/testForwarding", QStringList() << QString::number(mode) << QString::number(inmode)); + process.start("testForwarding/testForwarding", + QStringList() << QString::number(mode) << QString::number(inmode) + << QString::number(bool(detach))); QVERIFY(process.waitForStarted(5000)); QCOMPARE(process.write("input"), 5); process.closeWriteChannel(); @@ -1089,7 +1107,9 @@ void tst_QProcess::forwardedChannels() case 4: err = "did not finish"; break; case 5: err = "unexpected stdout"; break; case 6: err = "unexpected stderr"; break; - case 13: err = "parameter error"; break; + case 12: err = "cannot create temp file"; break; + case 13: err = "startDetached failed"; break; + case 14: err = "waitForDoneFileWritten timed out"; break; default: err = "unknown exit code"; break; } QVERIFY2(!process.exitCode(), err); diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index fdacf83eb2..68c6ece583 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -2968,6 +2968,7 @@ void tst_QObject::dynamicProperties() QVERIFY(obj.dynamicPropertyNames().isEmpty()); + // set a non-dynamic property QVERIFY(obj.setProperty("number", 42)); QVERIFY(obj.changedDynamicProperties.isEmpty()); QCOMPARE(obj.property("number").toInt(), 42); @@ -2975,19 +2976,30 @@ void tst_QObject::dynamicProperties() QVERIFY(!obj.setProperty("number", "invalid string")); QVERIFY(obj.changedDynamicProperties.isEmpty()); + // set a dynamic property QVERIFY(!obj.setProperty("myuserproperty", "Hello")); QCOMPARE(obj.changedDynamicProperties.count(), 1); QCOMPARE(obj.changedDynamicProperties.first(), QByteArray("myuserproperty")); //check if there is no redundant DynamicPropertyChange events QVERIFY(!obj.setProperty("myuserproperty", "Hello")); QCOMPARE(obj.changedDynamicProperties.count(), 1); - obj.changedDynamicProperties.clear(); + QCOMPARE(obj.property("myuserproperty").type(), QVariant::String); QCOMPARE(obj.property("myuserproperty").toString(), QString("Hello")); QCOMPARE(obj.dynamicPropertyNames().count(), 1); QCOMPARE(obj.dynamicPropertyNames().first(), QByteArray("myuserproperty")); + // change type of the dynamic property + obj.changedDynamicProperties.clear(); + QVERIFY(!obj.setProperty("myuserproperty", QByteArray("Hello"))); + QCOMPARE(obj.changedDynamicProperties.count(), 1); + QCOMPARE(obj.changedDynamicProperties.first(), QByteArray("myuserproperty")); + QCOMPARE(obj.property("myuserproperty").type(), QVariant::ByteArray); + QCOMPARE(obj.property("myuserproperty").toString(), QByteArray("Hello")); + + // unset the property + obj.changedDynamicProperties.clear(); QVERIFY(!obj.setProperty("myuserproperty", QVariant())); QCOMPARE(obj.changedDynamicProperties.count(), 1); diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 41c8f760dc..4651258ef3 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -648,6 +648,7 @@ void tst_QtJson::testArrayNestedEmpty() object.insert("inner", inner); QJsonValue val = object.value("inner"); QJsonArray value = object.value("inner").toArray(); + QVERIFY(QJsonDocument(value).isArray()); QCOMPARE(value.size(), 0); QCOMPARE(value, inner); QCOMPARE(value.size(), 0); @@ -666,6 +667,7 @@ void tst_QtJson::testObjectNestedEmpty() object.insert("inner", inner); object.insert("inner2", inner2); QJsonObject value = object.value("inner").toObject(); + QVERIFY(QJsonDocument(value).isObject()); QCOMPARE(value.size(), 0); QCOMPARE(value, inner); QCOMPARE(value.size(), 0); diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 1f52018d7f..d32913b822 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -227,6 +227,8 @@ private slots: void hugeQImage(); + void convertColorTable(); + #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void toWinHBITMAP_data(); void toWinHBITMAP(); @@ -3496,6 +3498,19 @@ void tst_QImage::hugeQImage() #endif } +void tst_QImage::convertColorTable() +{ + QImage image(10, 10, QImage::Format_Indexed8); + image.setColor(0, 0x80ffffff); + image.fill(0); + QImage argb32 = image.convertToFormat(QImage::Format_ARGB32); + QCOMPARE(argb32.pixel(0,0), 0x80ffffff); + QImage argb32pm = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + QCOMPARE(argb32pm.pixel(0,0), 0x80808080); + QImage rgb32 = image.convertToFormat(QImage::Format_RGB32); + QCOMPARE(rgb32.pixel(0,0), 0xffffffff); +} + #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QT_BEGIN_NAMESPACE Q_GUI_EXPORT HBITMAP qt_imageToWinHBITMAP(const QImage &p, int hbitmapFormat = 0); diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 76c9dd8361..30b41da515 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -393,6 +393,7 @@ private Q_SLOTS: void ignoreSslErrorsListWithSlot_data(); void ignoreSslErrorsListWithSlot(); void encrypted(); + void abortOnEncrypted(); void sslConfiguration_data(); void sslConfiguration(); #ifdef QT_BUILD_INTERNAL @@ -6365,6 +6366,37 @@ void tst_QNetworkReply::encrypted() reply->deleteLater(); } +void tst_QNetworkReply::abortOnEncrypted() +{ + SslServer server; + server.listen(); + if (!server.isListening()) + QSKIP("Server fails to listen. Skipping since QTcpServer is covered in another test."); + + server.connect(&server, &SslServer::newEncryptedConnection, [&server]() { + connect(server.socket, &QTcpSocket::readyRead, server.socket, []() { + // This slot must not be invoked! + QVERIFY(false); + }); + }); + + QNetworkAccessManager nm; + QNetworkReply *reply = nm.get(QNetworkRequest(QUrl(QString("https://localhost:%1").arg(server.serverPort())))); + reply->ignoreSslErrors(); + + connect(reply, &QNetworkReply::encrypted, [reply, &nm]() { + reply->abort(); + nm.clearConnectionCache(); + }); + + QSignalSpy spyEncrypted(reply, &QNetworkReply::encrypted); + QTRY_COMPARE(spyEncrypted.count(), 1); + + // Wait for the socket to be closed again in order to be sure QTcpSocket::readyRead would have been emitted. + QTRY_VERIFY(server.socket != nullptr); + QTRY_COMPARE(server.socket->state(), QAbstractSocket::UnconnectedState); +} + void tst_QNetworkReply::sslConfiguration() { QNetworkRequest request(QUrl("https://" + QtNetworkSettings::httpServerName() + "/index.html")); |