diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-10-14 15:45:35 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-10-14 15:45:35 +0200 |
commit | 4456984da780b14572e1ec0f079a4d349ab299bd (patch) | |
tree | f586a281a81c57c91c49e83a5d3ec6c7eece0578 /tests | |
parent | e824abd987d77efaa085fe1f9fb514d270798d55 (diff) | |
parent | 281121697340084f7d385eab530f41916789b94d (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
tests/auto/corelib/io/qfile/tst_qfile.cpp
tests/auto/corelib/io/qprocess/tst_qprocess.cpp
tests/auto/corelib/tools/qversionnumber/qversionnumber.pro
Change-Id: Ia93ce500349d96a2fbf0b4a37b73f088cc505c6e
Diffstat (limited to 'tests')
69 files changed, 1536 insertions, 554 deletions
diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index 59a536ed25..6be8ff81cf 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -225,8 +225,8 @@ void tst_QNumeric::addOverflow_data() // to QTest::toString and QTest::qCompare will remain. template <typename Int> static void addOverflow_template() { -#if defined(Q_CC_MSVC) && Q_CC_MSVC < 1900 - QSKIP("Test disabled, this test generates an Internal Compiler Error compiling"); +#if defined(Q_CC_MSVC) && Q_CC_MSVC < 2000 + QSKIP("Test disabled, this test generates an Internal Compiler Error compiling in release mode"); #else const Int max = std::numeric_limits<Int>::max(); Int r; diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 8a1777d7fd..2106a1cea8 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -68,6 +68,12 @@ QT_END_NAMESPACE #endif +static QByteArray msgDoesNotExist(const QString &name) +{ + return (QLatin1Char('"') + QDir::toNativeSeparators(name) + + QLatin1String("\" does not exist.")).toLocal8Bit(); +} + class tst_QDir : public QObject { Q_OBJECT @@ -354,7 +360,7 @@ void tst_QDir::mkdir() //make sure it really exists (ie that mkdir returns the right value) QFileInfo fi(path); - QVERIFY(fi.exists() && fi.isDir()); + QVERIFY2(fi.exists() && fi.isDir(), msgDoesNotExist(path).constData()); } void tst_QDir::makedirReturnCode() @@ -378,7 +384,7 @@ void tst_QDir::makedirReturnCode() f.open(QIODevice::WriteOnly); f.write("test"); f.close(); - QVERIFY(f.exists()); + QVERIFY2(f.exists(), msgDoesNotExist(f.fileName()).constData()); QVERIFY(!QDir::current().mkdir(dirName)); // calling mkdir on an existing file will fail. QVERIFY(!QDir::current().mkpath(dirName)); // calling mkpath on an existing file will fail. f.remove(); @@ -474,7 +480,7 @@ void tst_QDir::removeRecursivelyFailure() QVERIFY(!QDir().rmdir(path)); QDir dir(path); QVERIFY(!dir.removeRecursively()); // didn't work - QVERIFY(dir.exists()); // still exists + QVERIFY2(dir.exists(), msgDoesNotExist(dir.absolutePath()).constData()); // still exists QVERIFY(dirAsFile.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner))); QVERIFY(dir.removeRecursively()); @@ -527,14 +533,15 @@ void tst_QDir::exists_data() QTest::newRow("simple dir") << (m_dataPath + "/resources") << true; QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << true; #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) - QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; - QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true; - QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true; - QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true; - QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true; - QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true; - QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false; - QTest::newRow("unc 8") << "//" + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << false; + const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); + QTest::newRow("unc 1") << uncRoot << true; + QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; + QTest::newRow("unc 3") << uncRoot + "/testshare" << true; + QTest::newRow("unc 4") << uncRoot + "/testshare/" << true; + QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << true; + QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << true; + QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << false; + QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << false; QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false; #endif #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) @@ -566,7 +573,10 @@ void tst_QDir::exists() QFETCH(bool, expected); QDir dir(path); - QCOMPARE(dir.exists(), expected); + if (expected) + QVERIFY2(dir.exists(), msgDoesNotExist(path).constData()); + else + QVERIFY(!dir.exists()); } void tst_QDir::isRelativePath_data() @@ -802,7 +812,7 @@ void tst_QDir::entryList() #endif //Q_NO_SYMLINKS QDir dir(dirName); - QVERIFY(dir.exists()); + QVERIFY2(dir.exists(), msgDoesNotExist(dirName).constData()); QStringList actual = dir.entryList(nameFilters, (QDir::Filters)filterspec, (QDir::SortFlags)sortspec); @@ -845,8 +855,8 @@ void tst_QDir::entryListTimedSort() QTemporaryFile aFile(entrylistPath + "A-XXXXXX.qws"); QTemporaryFile bFile(entrylistPath + "B-XXXXXX.qws"); - QVERIFY(aFile.open()); - QVERIFY(bFile.open()); + QVERIFY2(aFile.open(), qPrintable(aFile.errorString())); + QVERIFY2(bFile.open(), qPrintable(bFile.errorString())); { QProcess p; p.start(touchBinary, QStringList() << "-t" << "201306021513" << aFile.fileName()); @@ -888,18 +898,25 @@ void tst_QDir::entryListSimple_data() #endif #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << 2; - QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << 2; - QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << 2; - QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << 2; - QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << 2; - QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << 2; - QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << 0; - QTest::newRow("unc 8") << "//" + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << 0; + const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); + QTest::newRow("unc 1") << uncRoot << 2; + QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 2; + QTest::newRow("unc 3") << uncRoot + "/testshare" << 2; + QTest::newRow("unc 4") << uncRoot + "/testshare/" << 2; + QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << 2; + QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << 2; + QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << 0; + QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << 0; QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << 0; #endif } +static QByteArray msgEntryListFailed(int actual, int expectedMin, const QString &name) +{ + return QByteArray::number(actual) + " < " + QByteArray::number(expectedMin) + " in \"" + + QFile::encodeName(QDir::toNativeSeparators(name)) + '"'; +} + void tst_QDir::entryListSimple() { QFETCH(QString, dirName); @@ -907,7 +924,7 @@ void tst_QDir::entryListSimple() QDir dir(dirName); QStringList actual = dir.entryList(); - QVERIFY(actual.count() >= countMin); + QVERIFY2(actual.count() >= countMin, msgEntryListFailed(actual.count(), countMin, dirName).constData()); } void tst_QDir::entryListWithSymLinks() @@ -1121,7 +1138,7 @@ void tst_QDir::setNameFilters() QFETCH(QStringList, expected); QDir dir(dirName); - QVERIFY(dir.exists()); + QVERIFY2(dir.exists(), msgDoesNotExist(dirName).constData()); dir.setNameFilters(nameFilters); QStringList actual = dir.entryList(); @@ -1504,7 +1521,7 @@ void tst_QDir::exists2() QDir dir; if (exists) - QVERIFY(dir.exists(path)); + QVERIFY2(dir.exists(path), msgDoesNotExist(path).constData()); else QVERIFY(!dir.exists(path)); diff --git a/tests/auto/corelib/io/qfile/BLACKLIST b/tests/auto/corelib/io/qfile/BLACKLIST new file mode 100644 index 0000000000..7aac313b12 --- /dev/null +++ b/tests/auto/corelib/io/qfile/BLACKLIST @@ -0,0 +1,5 @@ +# QTBUG-48455 +[readLineStdin] +msvc-2015 +[readLineStdin_lineByLine] +msvc-2015 diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index c1aed842cf..b4140e1115 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -390,9 +390,30 @@ tst_QFile::tst_QFile() : m_oldDir(QDir::currentPath()) { } +static QByteArray msgOpenFailed(QIODevice::OpenMode om, const QFile &file) +{ + QString result; + QDebug(&result).noquote().nospace() << "Could not open \"" + << QDir::toNativeSeparators(file.fileName()) << "\" using " + << om << ": " << file.errorString(); + return result.toLocal8Bit(); +} + +static QByteArray msgOpenFailed(const QFile &file) +{ + return (QLatin1String("Could not open \"") + QDir::toNativeSeparators(file.fileName()) + + QLatin1String("\": ") + file.errorString()).toLocal8Bit(); +} + +static QByteArray msgFileDoesNotExist(const QString &name) +{ + return (QLatin1Char('"') + QDir::toNativeSeparators(name) + + QLatin1String("\" does not exist.")).toLocal8Bit(); +} + void tst_QFile::initTestCase() { - QVERIFY(m_temporaryDir.isValid()); + QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString())); m_stdinProcessDir = QFINDTESTDATA("stdinprocess"); QVERIFY(!m_stdinProcessDir.isEmpty()); m_testSourceFile = QFINDTESTDATA("tst_qfile.cpp"); @@ -418,19 +439,19 @@ void tst_QFile::initTestCase() // create a file and make it read-only QFile file(QString::fromLatin1(readOnlyFile)); - QVERIFY2(file.open(QFile::WriteOnly), qPrintable(file.errorString())); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); file.write("a", 1); file.close(); QVERIFY2(file.setPermissions(QFile::ReadOwner), qPrintable(file.errorString())); // create another file and make it not readable file.setFileName(QString::fromLatin1(noReadFile)); - QVERIFY2(file.open(QFile::WriteOnly), qPrintable(file.errorString())); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); file.write("b", 1); file.close(); #ifndef Q_OS_WIN // Not supported on Windows. QVERIFY2(file.setPermissions(0), qPrintable(file.errorString())); #else - QVERIFY2(file.open(QFile::WriteOnly), qPrintable(file.errorString())); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); #endif } @@ -455,19 +476,19 @@ void tst_QFile::cleanupTestCase() void tst_QFile::exists() { QFile f( m_testFile ); - QVERIFY(f.exists()); + QVERIFY2(f.exists(), msgFileDoesNotExist(m_testFile)); QFile file("nobodyhassuchafile"); file.remove(); QVERIFY(!file.exists()); QFile file2("nobodyhassuchafile"); - QVERIFY(file2.open(QIODevice::WriteOnly)); + QVERIFY2(file2.open(QIODevice::WriteOnly), msgOpenFailed(file2).constData()); file2.close(); QVERIFY(file.exists()); - QVERIFY(file.open(QIODevice::WriteOnly)); + QVERIFY2(file.open(QIODevice::WriteOnly), msgOpenFailed(file).constData()); file.close(); QVERIFY(file.exists()); @@ -475,8 +496,9 @@ void tst_QFile::exists() QVERIFY(!file.exists()); #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) - QFile unc("//" + QtNetworkSettings::winServerName() + "/testshare/readme.txt"); - QVERIFY(unc.exists()); + const QString uncPath = "//" + QtNetworkSettings::winServerName() + "/testshare/readme.txt"; + QFile unc(uncPath); + QVERIFY2(unc.exists(), msgFileDoesNotExist(uncPath).constData()); #endif } @@ -558,7 +580,12 @@ void tst_QFile::open() if (filename.isEmpty()) QTest::ignoreMessage(QtWarningMsg, "QFSFileEngine::open: No file name specified"); - QCOMPARE(f.open( QIODevice::OpenMode(mode) ), ok); + const QIODevice::OpenMode om(mode); + const bool succeeded = f.open(om); + if (ok) + QVERIFY2(succeeded, msgOpenFailed(om, f).constData()); + else + QVERIFY(!succeeded); QTEST( f.error(), "status" ); } @@ -566,7 +593,7 @@ void tst_QFile::open() void tst_QFile::openUnbuffered() { QFile file(m_testFile); - QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)); + QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Unbuffered), msgOpenFailed(file).constData()); char c = '\0'; QVERIFY(file.seek(1)); QCOMPARE(file.pos(), qint64(1)); @@ -618,7 +645,7 @@ void tst_QFile::size() QFile f( filename ); QCOMPARE( f.size(), size ); - QVERIFY( f.open(QIODevice::ReadOnly) ); + QVERIFY2(f.open(QIODevice::ReadOnly), msgOpenFailed(f).constData()); QCOMPARE( f.size(), size ); } @@ -662,7 +689,7 @@ void tst_QFile::sizeNoExist() void tst_QFile::seek() { QFile file("newfile.txt"); - file.open(QIODevice::WriteOnly); + QVERIFY2(file.open(QIODevice::WriteOnly), msgOpenFailed(file).constData()); QCOMPARE(file.size(), qint64(0)); QCOMPARE(file.pos(), qint64(0)); QVERIFY(file.seek(10)); @@ -674,7 +701,7 @@ void tst_QFile::seek() void tst_QFile::setSize() { QFile f("createme.txt"); - QVERIFY(f.open(QIODevice::Truncate | QIODevice::ReadWrite)); + QVERIFY2(f.open(QIODevice::Truncate | QIODevice::ReadWrite), msgOpenFailed(f).constData()); f.putChar('a'); f.seek(0); @@ -712,7 +739,7 @@ void tst_QFile::setSize() void tst_QFile::setSizeSeek() { QFile f("setsizeseek.txt"); - QVERIFY(f.open(QFile::WriteOnly)); + QVERIFY2(f.open(QFile::WriteOnly), msgOpenFailed(f).constData()); f.write("ABCD"); QCOMPARE(f.pos(), qint64(4)); @@ -734,7 +761,7 @@ void tst_QFile::setSizeSeek() void tst_QFile::atEnd() { QFile f( m_testFile ); - QVERIFY(f.open( QIODevice::ReadOnly )); + QVERIFY2(f.open(QFile::ReadOnly), msgOpenFailed(f).constData()); int size = f.size(); f.seek( size ); @@ -747,7 +774,7 @@ void tst_QFile::atEnd() void tst_QFile::readLine() { QFile f( m_testFile ); - QVERIFY(f.open( QIODevice::ReadOnly )); + QVERIFY2(f.open(QFile::ReadOnly), msgOpenFailed(f).constData()); int i = 0; char p[128]; @@ -767,7 +794,8 @@ void tst_QFile::readLine() void tst_QFile::readLine2() { QFile f( m_testFile ); - f.open( QIODevice::ReadOnly ); + QVERIFY2(f.open(QFile::ReadOnly), msgOpenFailed(f).constData()); + char p[128]; QCOMPARE(f.readLine(p, 60), qlonglong(59)); @@ -785,7 +813,7 @@ void tst_QFile::readLineNullInLine() { QFile::remove("nullinline.txt"); QFile file("nullinline.txt"); - QVERIFY(file.open(QIODevice::ReadWrite)); + QVERIFY2(file.open(QFile::ReadWrite), msgOpenFailed(file).constData()); QVERIFY(file.write("linewith\0null\nanotherline\0withnull\n\0\nnull\0", 42) > 0); QVERIFY(file.flush()); file.reset(); @@ -816,10 +844,8 @@ void tst_QFile::readAll() QFETCH( QString, fileName ); QFile file(fileName); - if (textMode) - QVERIFY(file.open(QFile::Text | QFile::ReadOnly)); - else - QVERIFY(file.open(QFile::ReadOnly)); + const QIODevice::OpenMode om = textMode ? (QFile::Text | QFile::ReadOnly) : QFile::ReadOnly; + QVERIFY2(file.open(om), msgOpenFailed(om, file).constData()); QByteArray a = file.readAll(); file.reset(); @@ -848,8 +874,8 @@ void tst_QFile::readAllBuffer() QByteArray data1("This is arguably a very simple text."); QByteArray data2("This is surely not as simple a test."); - QVERIFY( writer.open(QIODevice::ReadWrite | QIODevice::Unbuffered) ); - QVERIFY( reader.open(QIODevice::ReadOnly) ); + QVERIFY2(writer.open(QIODevice::ReadWrite | QIODevice::Unbuffered), msgOpenFailed(writer).constData()); + QVERIFY2(reader.open(QIODevice::ReadOnly), msgOpenFailed(reader).constData()); QCOMPARE( writer.write(data1), qint64(data1.size()) ); QVERIFY( writer.seek(0) ); @@ -868,6 +894,32 @@ void tst_QFile::readAllBuffer() QFile::remove(fileName); } +#ifndef QT_NO_PROCESS +class StdinReaderProcessGuard { // Ensure the stdin reader process is stopped on destruction. + Q_DISABLE_COPY(StdinReaderProcessGuard) + +public: + StdinReaderProcessGuard(QProcess *p) : m_process(p) {} + ~StdinReaderProcessGuard() { stop(); } + + bool stop(int msecs = 30000) + { + if (m_process->state() != QProcess::Running) + return true; + m_process->closeWriteChannel(); + if (m_process->waitForFinished(msecs)) + return m_process->exitStatus() == QProcess::NormalExit && !m_process->exitCode(); + m_process->terminate(); + if (!m_process->waitForFinished()) + m_process->kill(); + return false; + } + +private: + QProcess *m_process; +}; +#endif // !QT_NO_PROCESS + #if !defined(Q_OS_WINCE) void tst_QFile::readAllStdin() { @@ -877,18 +929,17 @@ void tst_QFile::readAllStdin() QByteArray lotsOfData(1024, '@'); // 10 megs QProcess process; + StdinReaderProcessGuard processGuard(&process); process.start(m_stdinProcessDir + QStringLiteral("/stdinprocess"), QStringList(QStringLiteral("all"))); QVERIFY2(process.waitForStarted(), qPrintable(process.errorString())); for (int i = 0; i < 5; ++i) { QTest::qWait(1000); process.write(lotsOfData); - while (process.bytesToWrite() > 0) { + while (process.bytesToWrite() > 0) QVERIFY(process.waitForBytesWritten()); - } } - process.closeWriteChannel(); - process.waitForFinished(); + QVERIFY(processGuard.stop()); QCOMPARE(process.readAll().size(), lotsOfData.size() * 5); #endif } @@ -908,6 +959,7 @@ void tst_QFile::readLineStdin() for (int i = 0; i < 2; ++i) { QProcess process; + StdinReaderProcessGuard processGuard(&process); process.start(m_stdinProcessDir + QStringLiteral("/stdinprocess"), QStringList() << QStringLiteral("line") << QString::number(i), QIODevice::Text | QIODevice::ReadWrite); @@ -915,13 +967,11 @@ void tst_QFile::readLineStdin() for (int i = 0; i < 5; ++i) { QTest::qWait(1000); process.write(lotsOfData); - while (process.bytesToWrite() > 0) { + while (process.bytesToWrite() > 0) QVERIFY(process.waitForBytesWritten()); - } } - process.closeWriteChannel(); - QVERIFY(process.waitForFinished(5000)); + QVERIFY(processGuard.stop(5000)); QByteArray array = process.readAll(); QCOMPARE(array.size(), lotsOfData.size() * 5); @@ -942,6 +992,7 @@ void tst_QFile::readLineStdin_lineByLine() #else for (int i = 0; i < 2; ++i) { QProcess process; + StdinReaderProcessGuard processGuard(&process); process.start(m_stdinProcessDir + QStringLiteral("/stdinprocess"), QStringList() << QStringLiteral("line") << QString::number(i), QIODevice::Text | QIODevice::ReadWrite); @@ -956,8 +1007,7 @@ void tst_QFile::readLineStdin_lineByLine() QCOMPARE(process.readAll(), line); } - process.closeWriteChannel(); - QVERIFY(process.waitForFinished(5000)); + QVERIFY(processGuard.stop(5000)); } #endif } @@ -967,7 +1017,7 @@ void tst_QFile::text() { // dosfile.txt is a binary CRLF file QFile file(m_dosFile); - QVERIFY(file.open(QFile::Text | QFile::ReadOnly)); + QVERIFY2(file.open(QFile::Text | QFile::ReadOnly), msgOpenFailed(file).constData()); QCOMPARE(file.readLine(), QByteArray("/dev/system/root / reiserfs acl,user_xattr 1 1\n")); QCOMPARE(file.readLine(), @@ -980,7 +1030,7 @@ void tst_QFile::text() void tst_QFile::missingEndOfLine() { QFile file(m_noEndOfLineFile); - QVERIFY(file.open(QFile::ReadOnly)); + QVERIFY2(file.open(QFile::ReadOnly), msgOpenFailed(file).constData()); int nlines = 0; while (!file.atEnd()) { @@ -1026,7 +1076,7 @@ void tst_QFile::getch() void tst_QFile::ungetChar() { QFile f(m_testFile); - QVERIFY(f.open(QIODevice::ReadOnly)); + QVERIFY2(f.open(QFile::ReadOnly), msgOpenFailed(f).constData()); QByteArray array = f.readLine(); QCOMPARE(array.constData(), "----------------------------------------------------------\n"); @@ -1044,7 +1094,7 @@ void tst_QFile::ungetChar() QFile::remove("genfile.txt"); QFile out("genfile.txt"); - QVERIFY(out.open(QIODevice::ReadWrite)); + QVERIFY2(out.open(QIODevice::ReadWrite), msgOpenFailed(out).constData()); out.write("123"); out.seek(0); QCOMPARE(out.readAll().constData(), "123"); @@ -1127,7 +1177,7 @@ void tst_QFile::createFile() QVERIFY( !QFile::exists( "createme.txt" ) ); QFile f( "createme.txt" ); - QVERIFY( f.open( QIODevice::WriteOnly ) ); + QVERIFY2( f.open(QIODevice::WriteOnly), msgOpenFailed(f).constData()); f.close(); QVERIFY( QFile::exists( "createme.txt" ) ); } @@ -1140,11 +1190,11 @@ void tst_QFile::append() QVERIFY(!QFile::exists(name)); QFile f(name); - QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate)); + QVERIFY2(f.open(QIODevice::WriteOnly | QIODevice::Truncate), msgOpenFailed(f).constData()); f.putChar('a'); f.close(); - QVERIFY(f.open(QIODevice::Append)); + QVERIFY2(f.open(QIODevice::Append), msgOpenFailed(f).constData()); QCOMPARE(f.pos(), 1); f.putChar('a'); f.close(); @@ -1181,7 +1231,7 @@ void tst_QFile::permissions() QFETCH(bool, create); if (create) { QFile fc(file); - QVERIFY(fc.open(QFile::WriteOnly)); + QVERIFY2(fc.open(QFile::WriteOnly), msgOpenFailed(fc).constData()); QVERIFY(fc.write("hello\n")); fc.close(); } @@ -1230,7 +1280,7 @@ void tst_QFile::setPermissions() QVERIFY( !QFile::exists( "createme.txt" ) ); QFile f("createme.txt"); - QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate)); + QVERIFY2(f.open(QIODevice::WriteOnly | QIODevice::Truncate), msgOpenFailed(f).constData()); f.putChar('a'); f.close(); @@ -1247,8 +1297,8 @@ void tst_QFile::copy() QFile::remove("test2"); QVERIFY(QFile::copy(m_testSourceFile, "tst_qfile_copy.cpp")); QFile in1(m_testSourceFile), in2("tst_qfile_copy.cpp"); - QVERIFY(in1.open(QFile::ReadOnly)); - QVERIFY(in2.open(QFile::ReadOnly)); + QVERIFY2(in1.open(QFile::ReadOnly), msgOpenFailed(in1).constData()); + QVERIFY2(in2.open(QFile::ReadOnly), msgOpenFailed(in2).constData()); QByteArray data1 = in1.readAll(), data2 = in2.readAll(); QCOMPARE(data1, data2); QFile::remove( "main_copy.cpp" ); @@ -1261,8 +1311,8 @@ void tst_QFile::copyAfterFail() QFile file1("file-to-be-copied.txt"); QFile file2("existing-file.txt"); - QVERIFY(file1.open(QIODevice::ReadWrite) && "(test-precondition)"); - QVERIFY(file2.open(QIODevice::ReadWrite) && "(test-precondition)"); + QVERIFY2(file1.open(QIODevice::ReadWrite), msgOpenFailed(file1).constData()); + QVERIFY2(file2.open(QIODevice::ReadWrite), msgOpenFailed(file1).constData()); file2.close(); QVERIFY(!QFile::exists("copied-file-1.txt") && "(test-precondition)"); QVERIFY(!QFile::exists("copied-file-2.txt") && "(test-precondition)"); @@ -1331,7 +1381,7 @@ void tst_QFile::copyFallback() QVERIFY(QFile::remove("file-copy-destination.txt")); // Fallback copy of open file. - QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); QVERIFY(file.copy("file-copy-destination.txt")); QVERIFY(QFile::exists("file-copy-destination.txt")); QVERIFY(!file.isOpen()); @@ -1401,7 +1451,7 @@ void tst_QFile::link() QCOMPARE(info2.symLinkTarget(), referenceTarget); QFile link("myLink.lnk"); - QVERIFY(link.open(QIODevice::ReadOnly)); + QVERIFY2(link.open(QIODevice::ReadOnly), msgOpenFailed(link).constData()); QCOMPARE(link.symLinkTarget(), referenceTarget); link.close(); @@ -1483,15 +1533,15 @@ void tst_QFile::readTextFile() QFETCH(QByteArray, out); QFile winfile("winfile.txt"); - QVERIFY(winfile.open(QFile::WriteOnly | QFile::Truncate)); + QVERIFY2(winfile.open(QFile::WriteOnly | QFile::Truncate), msgOpenFailed(winfile).constData()); winfile.write(in); winfile.close(); - QVERIFY(winfile.open(QFile::ReadOnly)); + QVERIFY2(winfile.open(QFile::ReadOnly), msgOpenFailed(winfile).constData()); QCOMPARE(winfile.readAll(), in); winfile.close(); - QVERIFY(winfile.open(QFile::ReadOnly | QFile::Text)); + QVERIFY2(winfile.open(QFile::ReadOnly | QFile::Text), msgOpenFailed(winfile).constData()); QCOMPARE(winfile.readAll(), out); } @@ -1499,13 +1549,13 @@ void tst_QFile::readTextFile2() { { QFile file(m_testLogFile); - QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); file.read(4097); } { QFile file(m_testLogFile); - QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); + QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text), msgOpenFailed(file).constData()); file.read(4097); } } @@ -1532,7 +1582,8 @@ void tst_QFile::writeTextFile() QFETCH(QByteArray, in); QFile file("textfile.txt"); - QVERIFY(file.open(QFile::WriteOnly | QFile::Truncate | QFile::Text)); + QVERIFY2(file.open(QFile::WriteOnly | QFile::Truncate | QFile::Text), + msgOpenFailed(file).constData()); QByteArray out = in; #ifdef Q_OS_WIN out.replace('\n', "\r\n"); @@ -1555,8 +1606,10 @@ void tst_QFile::largeUncFileSupport() { // 1) Native file handling. QFile file(largeFile); + QVERIFY2(file.exists(), msgFileDoesNotExist(largeFile)); + QCOMPARE(file.size(), size); - QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); @@ -1593,13 +1646,13 @@ void tst_QFile::flush() { QFile file(fileName); - QVERIFY(file.open(QFile::WriteOnly)); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); QCOMPARE(file.write("abc", 3),qint64(3)); } { QFile file(fileName); - QVERIFY(file.open(QFile::WriteOnly | QFile::Append)); + QVERIFY2(file.open(QFile::WriteOnly | QFile::Append), msgOpenFailed(file).constData()); QCOMPARE(file.pos(), qlonglong(3)); QCOMPARE(file.write("def", 3), qlonglong(3)); QCOMPARE(file.pos(), qlonglong(6)); @@ -1607,7 +1660,7 @@ void tst_QFile::flush() { QFile file("stdfile.txt"); - QVERIFY(file.open(QFile::ReadOnly)); + QVERIFY2(file.open(QFile::ReadOnly), msgOpenFailed(file).constData()); QCOMPARE(file.readAll(), QByteArray("abcdef")); } } @@ -1617,7 +1670,7 @@ void tst_QFile::bufferedRead() QFile::remove("stdfile.txt"); QFile file("stdfile.txt"); - QVERIFY(file.open(QFile::WriteOnly)); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); file.write("abcdef"); file.close(); @@ -1634,7 +1687,7 @@ void tst_QFile::bufferedRead() { QFile file; - QVERIFY(file.open(stdFile, QFile::ReadOnly)); + QVERIFY2(file.open(stdFile, QFile::ReadOnly), msgOpenFailed(file).constData()); QCOMPARE(file.pos(), qlonglong(1)); QCOMPARE(file.read(&c, 1), qlonglong(1)); QCOMPARE(c, 'b'); @@ -1648,7 +1701,7 @@ void tst_QFile::bufferedRead() void tst_QFile::isSequential() { QFile zero("/dev/null"); - QVERIFY(zero.open(QFile::ReadOnly)); + QVERIFY2(zero.open(QFile::ReadOnly), msgOpenFailed(zero).constData()); QVERIFY(zero.isSequential()); } #endif @@ -1662,15 +1715,15 @@ void tst_QFile::truncate() { for (int i = 0; i < 2; ++i) { QFile file("truncate.txt"); - QVERIFY(file.open(QFile::WriteOnly)); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); file.write(QByteArray(200, '@')); file.close(); - QVERIFY(file.open((i ? QFile::WriteOnly : QFile::ReadWrite) | QFile::Truncate)); + QVERIFY2(file.open((i ? QFile::WriteOnly : QFile::ReadWrite) | QFile::Truncate), msgOpenFailed(file).constData()); file.write(QByteArray(100, '$')); file.close(); - QVERIFY(file.open(QFile::ReadOnly)); + QVERIFY2(file.open(QFile::ReadOnly), msgOpenFailed(file).constData()); QCOMPARE(file.readAll(), QByteArray(100, '$')); } } @@ -1679,13 +1732,13 @@ void tst_QFile::seekToPos() { { QFile file("seekToPos.txt"); - QVERIFY(file.open(QFile::WriteOnly)); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); file.write("a\r\nb\r\nc\r\n"); file.flush(); } QFile file("seekToPos.txt"); - QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); + QVERIFY2(file.open(QFile::ReadOnly | QFile::Text), msgOpenFailed(file).constData()); file.seek(1); char c; QVERIFY(file.getChar(&c)); @@ -1707,7 +1760,7 @@ void tst_QFile::seekAfterEndOfFile() QFile::remove(filename); { QFile file(filename); - QVERIFY(file.open(QFile::WriteOnly)); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); file.write("abcd"); QCOMPARE(file.size(), qint64(4)); file.seek(8); @@ -1723,7 +1776,7 @@ void tst_QFile::seekAfterEndOfFile() } QFile file(filename); - QVERIFY(file.open(QFile::ReadOnly)); + QVERIFY2(file.open(QFile::ReadOnly), msgOpenFailed(file).constData()); QByteArray contents = file.readAll(); QCOMPARE(contents.left(12), QByteArray("abcdefghijkl", 12)); //bytes 12-15 are uninitialised so we don't care what they read as. @@ -1741,7 +1794,7 @@ void tst_QFile::FILEReadWrite() // create test file { QFile f("FILEReadWrite.txt"); - QVERIFY(f.open(QFile::WriteOnly)); + QVERIFY2(f.open(QFile::WriteOnly), msgOpenFailed(f).constData()); QDataStream ds(&f); qint8 c = 0; ds << c; @@ -1777,7 +1830,7 @@ void tst_QFile::FILEReadWrite() #endif QVERIFY(fp); QFile file; - QVERIFY(file.open(fp, QFile::ReadWrite)); + QVERIFY2(file.open(fp, QFile::ReadWrite), msgOpenFailed(file).constData()); QDataStream sfile(&file) ; qint8 var1,var2,var3,var4; @@ -1814,7 +1867,7 @@ void tst_QFile::FILEReadWrite() // check modified file { QFile f("FILEReadWrite.txt"); - QVERIFY(f.open(QFile::ReadOnly)); + QVERIFY2(f.open(QFile::ReadOnly), msgOpenFailed(file).constData()); QDataStream ds(&f); qint8 c = 0; ds >> c; @@ -1928,14 +1981,14 @@ void tst_QFile::i18nFileName() } { QFile file(fileName); - QVERIFY(file.open(QFile::WriteOnly | QFile::Text)); + QVERIFY2(file.open(QFile::WriteOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); ts.setCodec("UTF-8"); ts << fileName << endl; } { QFile file(fileName); - QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); + QVERIFY2(file.open(QFile::ReadOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); ts.setCodec("UTF-8"); QString line = ts.readLine(); @@ -1983,13 +2036,13 @@ void tst_QFile::longFileName() QEXPECT_FAIL("244 chars", "Full pathname must be less than 260 chars", Abort); QEXPECT_FAIL("244 chars to absolutepath", "Full pathname must be less than 260 chars", Abort); #endif - QVERIFY(file.open(QFile::WriteOnly | QFile::Text)); + QVERIFY2(file.open(QFile::WriteOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); ts << fileName << endl; } { QFile file(fileName); - QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); + QVERIFY2(file.open(QFile::ReadOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); QString line = ts.readLine(); QCOMPARE(line, fileName); @@ -1998,7 +2051,7 @@ void tst_QFile::longFileName() { QVERIFY(QFile::copy(fileName, newName)); QFile file(newName); - QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); + QVERIFY2(file.open(QFile::ReadOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); QString line = ts.readLine(); QCOMPARE(line, fileName); @@ -2008,12 +2061,12 @@ void tst_QFile::longFileName() { QVERIFY(QFile::rename(fileName, newName)); QFile file(newName); - QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); + QVERIFY2(file.open(QFile::ReadOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); QString line = ts.readLine(); QCOMPARE(line, fileName); } - QVERIFY(QFile::exists(newName)); + QVERIFY2(QFile::exists(newName), msgFileDoesNotExist(newName).constData()); } #ifdef QT_BUILD_INTERNAL @@ -2146,7 +2199,7 @@ void tst_QFile::remove_and_exists() bool opened = f.open(QIODevice::WriteOnly); QVERIFY(opened); - f.write(QString("testing that remove/exists work...").toLatin1()); + f.write("testing that remove/exists work..."); f.close(); QVERIFY(f.exists()); @@ -2165,7 +2218,7 @@ void tst_QFile::removeOpenFile() QVERIFY(!f.exists()); bool opened = f.open(QIODevice::WriteOnly); QVERIFY(opened); - f.write(QString("testing that remove closes the file first...").toLatin1()); + f.write("testing that remove closes the file first..."); bool removed = f.remove(); // remove should both close and remove the file QVERIFY(removed); @@ -2184,7 +2237,7 @@ void tst_QFile::removeOpenFile() QVERIFY(!f.exists()); bool opened = f.open(QIODevice::WriteOnly); QVERIFY(opened); - f.write(QString("testing that remove closes the file first...").toLatin1()); + f.write("testing that remove closes the file first..."); f.close(); } @@ -2208,7 +2261,7 @@ void tst_QFile::fullDisk() if (!file.exists()) QSKIP("/dev/full doesn't exist on this system"); - QVERIFY(file.open(QIODevice::WriteOnly)); + QVERIFY2(file.open(QIODevice::WriteOnly), msgOpenFailed(file).constData()); file.write("foobar", 6); QVERIFY(!file.flush()); @@ -2235,7 +2288,7 @@ void tst_QFile::fullDisk() QCOMPARE(file.error(), QFile::NoError); // try again without flush: - QVERIFY(file.open(QIODevice::WriteOnly)); + QVERIFY2(file.open(QIODevice::WriteOnly), msgOpenFailed(file).constData()); file.write("foobar", 6); file.close(); QVERIFY(file.error() != QFile::NoError); @@ -2288,8 +2341,7 @@ void tst_QFile::writeLargeDataBlock() { QFile file(fileName); - QVERIFY2( openFile(file, QIODevice::WriteOnly, (FileType)type), - qPrintable(QString("Couldn't open file for writing: [%1]").arg(fileName)) ); + QVERIFY2(openFile(file, QIODevice::WriteOnly, (FileType)type), msgOpenFailed(file)); qint64 fileWriteOriginalData = file.write(originalData); qint64 originalDataSize = (qint64)originalData.size(); #if defined(Q_OS_WIN) @@ -2332,7 +2384,7 @@ void tst_QFile::writeLargeDataBlock() void tst_QFile::readFromWriteOnlyFile() { QFile file("writeonlyfile"); - QVERIFY(file.open(QFile::WriteOnly)); + QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); char c; QTest::ignoreMessage(QtWarningMsg, "QIODevice::read (QFile, \"writeonlyfile\"): WriteOnly device"); QCOMPARE(file.read(&c, 1), qint64(-1)); @@ -2341,7 +2393,7 @@ void tst_QFile::readFromWriteOnlyFile() void tst_QFile::writeToReadOnlyFile() { QFile file("readonlyfile"); - QVERIFY(file.open(QFile::ReadOnly)); + QVERIFY2(file.open(QFile::ReadOnly), msgOpenFailed(file).constData()); char c = 0; QTest::ignoreMessage(QtWarningMsg, "QIODevice::write (QFile, \"readonlyfile\"): ReadOnly device"); QCOMPARE(file.write(&c, 1), qint64(-1)); @@ -2363,13 +2415,13 @@ void tst_QFile::virtualFile() // consistency check QFileInfo fi(fname); - QVERIFY(fi.exists()); + QVERIFY2(fi.exists(), msgFileDoesNotExist(fname).constData()); QVERIFY(fi.isFile()); QCOMPARE(fi.size(), Q_INT64_C(0)); // open the file QFile f(fname); - QVERIFY(f.open(QIODevice::ReadOnly)); + QVERIFY2(f.open(QIODevice::ReadOnly), msgOpenFailed(f).constData()); QCOMPARE(f.size(), Q_INT64_C(0)); QVERIFY(f.atEnd()); @@ -2413,7 +2465,7 @@ void tst_QFile::textFile() ::fclose(fs); QFile file("writeabletextfile"); - QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); QByteArray data = file.readAll(); @@ -2543,8 +2595,8 @@ void tst_QFile::renameMultiple() // create the file if it doesn't exist QFile file("file-to-be-renamed.txt"); QFile file2("existing-file.txt"); - QVERIFY(file.open(QIODevice::ReadWrite) && "(test-precondition)"); - QVERIFY(file2.open(QIODevice::ReadWrite) && "(test-precondition)"); + QVERIFY2(file.open(QIODevice::ReadWrite), msgOpenFailed(file).constData()); + QVERIFY2(file2.open(QIODevice::ReadWrite), msgOpenFailed(file2).constData()); // any stale files from previous test failures? QFile::remove("file-renamed-once.txt"); @@ -2583,10 +2635,10 @@ void tst_QFile::renameMultiple() void tst_QFile::appendAndRead() { QFile writeFile(QLatin1String("appendfile.txt")); - QVERIFY(writeFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); + QVERIFY2(writeFile.open(QIODevice::WriteOnly | QIODevice::Truncate), msgOpenFailed(writeFile).constData()); QFile readFile(QLatin1String("appendfile.txt")); - QVERIFY(readFile.open(QIODevice::ReadOnly)); + QVERIFY2(readFile.open(QIODevice::ReadOnly), msgOpenFailed(readFile).constData()); // Write to the end of the file, then read that character back, and so on. for (int i = 0; i < 100; ++i) { @@ -2612,11 +2664,13 @@ void tst_QFile::miscWithUncPathAsCurrentDir() { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) QString current = QDir::currentPath(); - QVERIFY(QDir::setCurrent("//" + QtNetworkSettings::winServerName() + "/testshare")); + const QString path = QLatin1String("//") + QtNetworkSettings::winServerName() + + QLatin1String("/testshare"); + QVERIFY2(QDir::setCurrent(path), qPrintable(QDir::toNativeSeparators(path))); QFile file("test.pri"); - QVERIFY(file.exists()); + QVERIFY2(file.exists(), msgFileDoesNotExist(file.fileName()).constData()); QCOMPARE(int(file.size()), 34); - QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); QVERIFY(QDir::setCurrent(current)); #endif } @@ -2634,7 +2688,7 @@ void tst_QFile::handle() int fd; #if !defined(Q_OS_WINCE) QFile file(m_testSourceFile); - QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); fd = int(file.handle()); QVERIFY(fd > 2); QCOMPARE(int(file.handle()), fd); @@ -2648,7 +2702,7 @@ void tst_QFile::handle() // same, but read from QFile first now file.close(); - QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)); + QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Unbuffered), msgOpenFailed(file).constData()); fd = int(file.handle()); QVERIFY(fd > 2); QVERIFY(file.getChar(&c)); @@ -2690,7 +2744,7 @@ void tst_QFile::nativeHandleLeaks() { QFile file("qt_file.tmp"); - QVERIFY( file.open(QIODevice::ReadWrite) ); + QVERIFY2(file.open(QIODevice::ReadWrite), msgOpenFailed(file).constData()); fd1 = file.handle(); QVERIFY( -1 != fd1 ); @@ -2709,7 +2763,7 @@ void tst_QFile::nativeHandleLeaks() { QFile file("qt_file.tmp"); - QVERIFY( file.open(QIODevice::ReadOnly) ); + QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); fd2 = file.handle(); QVERIFY( -1 != fd2 ); @@ -2755,7 +2809,7 @@ void tst_QFile::readEof() { QFile file(filename); - QVERIFY(file.open(QIODevice::ReadOnly | mode)); + QVERIFY2(file.open(QIODevice::ReadOnly | mode), msgOpenFailed(file).constData()); bool isSequential = file.isSequential(); if (!isSequential) { QVERIFY(file.seek(245)); @@ -2777,7 +2831,7 @@ void tst_QFile::readEof() { QFile file(filename); - QVERIFY(file.open(QIODevice::ReadOnly | mode)); + QVERIFY2(file.open(QIODevice::ReadOnly | mode), msgOpenFailed(file).constData()); bool isSequential = file.isSequential(); if (!isSequential) { QVERIFY(file.seek(245)); @@ -2798,7 +2852,7 @@ void tst_QFile::readEof() { QFile file(filename); - QVERIFY(file.open(QIODevice::ReadOnly | mode)); + QVERIFY2(file.open(QIODevice::ReadOnly | mode), msgOpenFailed(file).constData()); bool isSequential = file.isSequential(); if (!isSequential) { QVERIFY(file.seek(245)); @@ -2820,7 +2874,7 @@ void tst_QFile::readEof() { QFile file(filename); - QVERIFY(file.open(QIODevice::ReadOnly | mode)); + QVERIFY2(file.open(QIODevice::ReadOnly | mode), msgOpenFailed(file).constData()); bool isSequential = file.isSequential(); if (!isSequential) { QVERIFY(file.seek(245)); @@ -2841,7 +2895,7 @@ void tst_QFile::readEof() { QFile file(filename); - QVERIFY(file.open(QIODevice::ReadOnly | mode)); + QVERIFY2(file.open(QIODevice::ReadOnly | mode), msgOpenFailed(file).constData()); bool isSequential = file.isSequential(); if (!isSequential) { QVERIFY(file.seek(245)); @@ -2867,7 +2921,7 @@ void tst_QFile::posAfterFailedStat() QFile::remove("tmp.txt"); QFile file("tmp.txt"); QVERIFY(!file.exists()); - QVERIFY(file.open(QIODevice::Append)); + QVERIFY2(file.open(QIODevice::Append), msgOpenFailed(file).constData()); QVERIFY(file.exists()); file.write("qt430", 5); QVERIFY(!file.isSequential()); @@ -2922,11 +2976,11 @@ void tst_QFile::map() QCOMPARE(file.error(), QFile::PermissionsError); // make a file - QVERIFY(file.open(QFile::ReadWrite)); + QVERIFY2(file.open(QFile::ReadWrite), msgOpenFailed(file).constData()); QVERIFY(file.resize(fileSize)); QVERIFY(file.flush()); file.close(); - QVERIFY(file.open(QFile::ReadWrite)); + QVERIFY2(file.open(QFile::ReadWrite), msgOpenFailed(file).constData()); memory = file.map(offset, size); if (error != QFile::NoError) { QVERIFY(file.error() != QFile::NoError); @@ -3061,13 +3115,14 @@ void tst_QFile::mapOpenMode() QFile file(fileName); // make a file - QVERIFY(file.open(QFile::ReadWrite)); + QVERIFY2(file.open(QFile::ReadWrite), msgOpenFailed(file).constData()); QVERIFY(file.write(pattern)); QVERIFY(file.flush()); file.close(); // open according to our mode - QVERIFY(file.open(QIODevice::OpenMode(openMode))); + const QIODevice::OpenMode om(openMode); + QVERIFY2(file.open(om), msgOpenFailed(om, file).constData()); uchar *memory = file.map(0, fileSize, QFileDevice::MemoryMapFlags(flags)); #if defined(Q_OS_WINCE) @@ -3116,7 +3171,8 @@ void tst_QFile::mapWrittenFile() QFile::remove(fileName); } QFile file(fileName); - QVERIFY(file.open(QIODevice::ReadWrite | QFile::OpenMode(mode))); + const QIODevice::OpenMode om = QIODevice::ReadWrite | QIODevice::OpenMode(mode); + QVERIFY2(file.open(om), msgOpenFailed(om, file).constData()); QCOMPARE(file.write(data, sizeof data), qint64(sizeof data)); if ((mode & QIODevice::Unbuffered) == 0) file.flush(); @@ -3328,7 +3384,7 @@ void tst_QFile::caseSensitivity() QString filename("File.txt"); { QFile f(filename); - QVERIFY(f.open(QIODevice::WriteOnly)); + QVERIFY2(f.open(QIODevice::WriteOnly), msgOpenFailed(f)); QVERIFY(f.write(testData)); f.close(); } diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 0319568229..1d49c8e3b9 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -149,6 +149,25 @@ static QString seedAndTemplate() qsrand(QDateTime::currentDateTimeUtc().toTime_t()); return QDir::tempPath() + "/tst_qfileinfo-XXXXXX"; } + +static QByteArray msgDoesNotExist(const QString &name) +{ + return (QLatin1Char('"') + QDir::toNativeSeparators(name) + + QLatin1String("\" does not exist.")).toLocal8Bit(); +} + +static QByteArray msgIsNoDirectory(const QString &name) +{ + return (QLatin1Char('"') + QDir::toNativeSeparators(name) + + QLatin1String("\" is not a directory.")).toLocal8Bit(); +} + +static QByteArray msgIsNotRoot(const QString &name) +{ + return (QLatin1Char('"') + QDir::toNativeSeparators(name) + + QLatin1String("\" is no root directory.")).toLocal8Bit(); +} + class tst_QFileInfo : public QObject { Q_OBJECT @@ -317,7 +336,7 @@ static QFileInfoPrivate* getPrivate(QFileInfo &info) void tst_QFileInfo::copy() { QTemporaryFile t; - t.open(); + QVERIFY2(t.open(), qPrintable(t.errorString())); QFileInfo info(t.fileName()); QVERIFY(info.exists()); @@ -414,13 +433,14 @@ void tst_QFileInfo::isDir_data() //QTest::newRow("drive 2") << "t:s" << false; #endif #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; - QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true; - QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true; - QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true; - QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true; - QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true; - QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false; + const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); + QTest::newRow("unc 1") << uncRoot << true; + QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; + QTest::newRow("unc 3") << uncRoot + "/testshare" << true; + QTest::newRow("unc 4") << uncRoot + "/testshare/" << true; + QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << true; + QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << true; + QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << false; #endif } @@ -429,8 +449,11 @@ void tst_QFileInfo::isDir() QFETCH(QString, path); QFETCH(bool, expected); - QFileInfo fi(path); - QCOMPARE(fi.isDir(), expected); + const bool isDir = QFileInfo(path).isDir(); + if (expected) + QVERIFY2(isDir, msgIsNoDirectory(path).constData()); + else + QVERIFY(!isDir); } void tst_QFileInfo::isRoot_data() @@ -453,10 +476,11 @@ void tst_QFileInfo::isRoot_data() #endif #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) - QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; - QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true; - QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << false; - QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << false; + const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); + QTest::newRow("unc 1") << uncRoot << true; + QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; + QTest::newRow("unc 3") << uncRoot + "/testshare" << false; + QTest::newRow("unc 4") << uncRoot + "/testshare/" << false; QTest::newRow("unc 7") << "//ahostthatshouldnotexist" << false; #endif } @@ -466,8 +490,11 @@ void tst_QFileInfo::isRoot() QFETCH(QString, path); QFETCH(bool, expected); - QFileInfo fi(path); - QCOMPARE(fi.isRoot(), expected); + const bool isRoot = QFileInfo(path).isRoot(); + if (expected) + QVERIFY2(isRoot, msgIsNotRoot(path).constData()); + else + QVERIFY(!isRoot); } void tst_QFileInfo::exists_data() @@ -493,14 +520,15 @@ void tst_QFileInfo::exists_data() QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) - QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; - QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true; - QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true; - QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true; - QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true; - QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true; - QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false; - QTest::newRow("unc 8") << "//" + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << false; + const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); + QTest::newRow("unc 1") << uncRoot << true; + QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; + QTest::newRow("unc 3") << uncRoot + "/testshare" << true; + QTest::newRow("unc 4") << uncRoot + "/testshare/" << true; + QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << true; + QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << true; + QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << false; + QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << false; QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false; #endif } @@ -511,8 +539,12 @@ void tst_QFileInfo::exists() QFETCH(bool, expected); QFileInfo fi(path); - QCOMPARE(fi.exists(), expected); - QCOMPARE(QFileInfo::exists(path), expected); + const bool exists = fi.exists(); + QCOMPARE(exists, QFileInfo::exists(path)); + if (expected) + QVERIFY2(exists, msgDoesNotExist(path).constData()); + else + QVERIFY(!exists); } void tst_QFileInfo::absolutePath_data() @@ -612,7 +644,7 @@ void tst_QFileInfo::canonicalPath() { QTemporaryFile tempFile; tempFile.setAutoRemove(true); - tempFile.open(); + QVERIFY2(tempFile.open(), qPrintable(tempFile.errorString())); QFileInfo fi(tempFile.fileName()); QCOMPARE(fi.canonicalPath(), QFileInfo(QDir::tempPath()).canonicalFilePath()); } @@ -994,7 +1026,7 @@ void tst_QFileInfo::systemFiles() QSKIP("This is a Windows only test"); #endif QFileInfo fi("c:\\pagefile.sys"); - QVERIFY(fi.exists()); + QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData()); QVERIFY(fi.size() > 0); QVERIFY(fi.lastModified().isValid()); } @@ -1479,7 +1511,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() QTest::newRow("dummy") << target.path() << false << "" << target.canonicalPath(); QSKIP("link not supported by FS or insufficient privilege"); } - QVERIFY(file.exists()); + QVERIFY2(file.exists(), msgDoesNotExist(file.fileName()).constData()); QTest::newRow("absolute dir symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath(); QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalPath(); @@ -1510,7 +1542,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() QFile file(fileInJunction.absoluteFilePath()); file.open(QIODevice::ReadWrite); file.close(); - QVERIFY(file.exists()); + QVERIFY2(file.exists(), msgDoesNotExist(file.fileName()).constData()); QTest::newRow("file in junction") << fileInJunction.absoluteFilePath() << false << "" << fileInJunction.canonicalFilePath(); target = QDir::rootPath(); @@ -1602,7 +1634,7 @@ void tst_QFileInfo::isWritable() #else QFileInfo fi("c:\\pagefile.sys"); #endif - QVERIFY(fi.exists()); + QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData()); QVERIFY(!fi.isWritable()); #endif #if defined (Q_OS_QNX) // On QNX /etc is usually on a read-only filesystem @@ -1860,7 +1892,7 @@ void tst_QFileInfo::owner() QVERIFY(testFile.write(testData) != -1); } QFileInfo fi(fileName); - QVERIFY(fi.exists()); + QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData()); QCOMPARE(fi.owner(), userName); QFile::remove(fileName); @@ -1895,7 +1927,7 @@ void tst_QFileInfo::group() QVERIFY(testFile.write(testData) != -1); testFile.close(); QFileInfo fi(fileName); - QVERIFY(fi.exists()); + QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData()); QCOMPARE(fi.group(), expected); } diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index a0434aa8ee..026743257c 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -126,7 +126,7 @@ void tst_QFileSystemWatcher::basicTest() // create test file QTemporaryDir temporaryDirectory(m_tempDirPattern); - QVERIFY(temporaryDirectory.isValid()); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); QFile testFile(temporaryDirectory.path() + QLatin1Char('/') + testFileName); QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate)); testFile.write(QByteArray("hello")); @@ -263,7 +263,7 @@ void tst_QFileSystemWatcher::watchDirectory() QFETCH(QString, backend); QTemporaryDir temporaryDirectory(m_tempDirPattern); - QVERIFY(temporaryDirectory.isValid()); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); QDir temporaryDir(temporaryDirectory.path()); const QString testDirName = QStringLiteral("testDir"); @@ -498,7 +498,7 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() QFETCH(QString, backend); QTemporaryDir temporaryDirectory(m_tempDirPattern); - QVERIFY(temporaryDirectory.isValid()); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); QDir temporaryDir(temporaryDirectory.path()); const QString testDirName = QStringLiteral("testDir"); @@ -605,7 +605,7 @@ void tst_QFileSystemWatcher::nonExistingFile() void tst_QFileSystemWatcher::removeFileAndUnWatch() { QTemporaryDir temporaryDirectory(m_tempDirPattern); - QVERIFY(temporaryDirectory.isValid()); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); const QString filename = temporaryDirectory.path() + QStringLiteral("/foo.txt"); @@ -664,7 +664,7 @@ void tst_QFileSystemWatcher::QTBUG2331() QFETCH(QString, backend); QTemporaryDir temporaryDirectory(m_tempDirPattern); - QVERIFY(temporaryDirectory.isValid()); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); QFileSystemWatcher watcher; watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend); QVERIFY(watcher.addPath(temporaryDirectory.path())); @@ -724,7 +724,8 @@ void tst_QFileSystemWatcher::signalsEmittedAfterFileMoved() { const int fileCount = 10; QTemporaryDir temporaryDirectory(m_tempDirPattern); - QVERIFY(temporaryDirectory.isValid()); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); + QDir testDir(temporaryDirectory.path()); QVERIFY(testDir.mkdir("movehere")); QString movePath = testDir.filePath("movehere"); diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index 27614e0eb8..21c5696d1d 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -80,6 +80,7 @@ void tst_QLockFile::initTestCase() #elif defined(QT_NO_PROCESS) QSKIP("This test requires QProcess support"); #else + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); // chdir to our testdata path and execute helper apps relative to that. QString testdata_dir = QFileInfo(QFINDTESTDATA("qlockfiletesthelper")).absolutePath(); QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir)); diff --git a/tests/auto/corelib/io/qprocess/BLACKLIST b/tests/auto/corelib/io/qprocess/BLACKLIST index dcd913ca49..216faa7fb4 100644 --- a/tests/auto/corelib/io/qprocess/BLACKLIST +++ b/tests/auto/corelib/io/qprocess/BLACKLIST @@ -1,2 +1,5 @@ [lockupsInStartDetached] redhatenterpriselinuxworkstation-6.6 +# QTBUG-48455 +[fileWriterProcess] +msvc-2015 diff --git a/tests/auto/corelib/io/qprocess/fileWriterProcess/main.cpp b/tests/auto/corelib/io/qprocess/fileWriterProcess/main.cpp index 411c7e334b..25cb66f9d2 100644 --- a/tests/auto/corelib/io/qprocess/fileWriterProcess/main.cpp +++ b/tests/auto/corelib/io/qprocess/fileWriterProcess/main.cpp @@ -33,20 +33,26 @@ #include <QCoreApplication> #include <QFile> +#include <stdio.h> + int main(int argc, char **argv) { QCoreApplication ca(argc, argv); QFile f; f.open(stdin, QIODevice::ReadOnly); - QString input; + QByteArray input; char buf[1024]; qint64 len; while ((len = f.read(buf, 1024)) > 0) - input += QByteArray(buf, len); + input.append(buf, len); f.close(); QFile f2("fileWriterProcess.txt"); - f2.open(QIODevice::WriteOnly | QIODevice::Truncate); - f2.write(input.toLatin1()); + if (!f2.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + fprintf(stderr, "Cannot open %s for writing: %s\n", + qPrintable(f2.fileName()), qPrintable(f2.errorString())); + return 1; + } + f2.write(input); f2.close(); return 0; } diff --git a/tests/auto/corelib/io/qprocess/testDetached/main.cpp b/tests/auto/corelib/io/qprocess/testDetached/main.cpp index bbcc7033c7..760306ea17 100644 --- a/tests/auto/corelib/io/qprocess/testDetached/main.cpp +++ b/tests/auto/corelib/io/qprocess/testDetached/main.cpp @@ -57,7 +57,8 @@ int main(int argc, char **argv) QFile f(args.at(1)); if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - fprintf(stderr, "Cannot open %s for writing", qPrintable(f.fileName())); + fprintf(stderr, "Cannot open %s for writing: %s\n", + qPrintable(f.fileName()), qPrintable(f.errorString())); return 1; } diff --git a/tests/auto/corelib/io/qprocess/testExitCodes/main.cpp b/tests/auto/corelib/io/qprocess/testExitCodes/main.cpp index c92d7f515f..c3cf9f56c7 100644 --- a/tests/auto/corelib/io/qprocess/testExitCodes/main.cpp +++ b/tests/auto/corelib/io/qprocess/testExitCodes/main.cpp @@ -33,8 +33,8 @@ #include <stdlib.h> -int main(int /* argc */, char **argv) +int main(int argc, char **argv) { - return atoi(argv[1]); + return argc >= 2 ? atoi(argv[1]) : -1; } diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 426c378967..83da28767f 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -62,6 +62,10 @@ if (ret == false) \ QVERIFY(ret); \ } +typedef void (QProcess::*QProcessFinishedSignal1)(int); +typedef void (QProcess::*QProcessFinishedSignal2)(int, QProcess::ExitStatus); +typedef void (QProcess::*QProcessErrorSignal)(QProcess::ProcessError); + class tst_QProcess : public QObject { Q_OBJECT @@ -69,6 +73,7 @@ class tst_QProcess : public QObject public slots: void initTestCase(); void cleanupTestCase(); + void init(); #ifndef QT_NO_PROCESS private slots: @@ -174,7 +179,6 @@ protected slots: #endif private: - QProcess *process; qint64 bytesAvailable; #endif //QT_NO_PROCESS }; @@ -197,6 +201,11 @@ void tst_QProcess::cleanupTestCase() #endif } +void tst_QProcess::init() +{ + bytesAvailable = 0; +} + #ifndef QT_NO_PROCESS // Testing get/set functions @@ -257,10 +266,10 @@ void tst_QProcess::simpleStart() { qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); - process = new QProcess; - QSignalSpy spy(process, &QProcess::stateChanged); + QScopedPointer<QProcess> process(new QProcess); + QSignalSpy spy(process.data(), &QProcess::stateChanged); QVERIFY(spy.isValid()); - connect(process, SIGNAL(readyRead()), this, SLOT(readFromProcess())); + connect(process.data(), &QIODevice::readyRead, this, &tst_QProcess::readFromProcess); /* valgrind dislike SUID binaries(those that have the `s'-flag set), which * makes it fail to start the process. For this reason utilities like `ping' won't @@ -272,8 +281,7 @@ void tst_QProcess::simpleStart() QCOMPARE(process->state(), QProcess::Running); QTRY_COMPARE(process->state(), QProcess::NotRunning); - delete process; - process = 0; + process.reset(); QCOMPARE(spy.count(), 3); QCOMPARE(qvariant_cast<QProcess::ProcessState>(spy.at(0).at(0)), QProcess::Starting); @@ -325,9 +333,8 @@ void tst_QProcess::execute() void tst_QProcess::startDetached() { - QProcess proc; - QVERIFY(proc.startDetached("testProcessNormal/testProcessNormal", - QStringList() << "arg1" << "arg2")); + QVERIFY(QProcess::startDetached("testProcessNormal/testProcessNormal", + QStringList() << "arg1" << "arg2")); #ifdef QPROCESS_USE_SPAWN QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue); #endif @@ -336,18 +343,20 @@ void tst_QProcess::startDetached() void tst_QProcess::readFromProcess() { + QProcess *process = qobject_cast<QProcess *>(sender()); + QVERIFY(process); int lines = 0; while (process->canReadLine()) { ++lines; - QByteArray line = process->readLine(); + process->readLine(); } } void tst_QProcess::crashTest() { qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState"); - process = new QProcess; - QSignalSpy stateSpy(process, &QProcess::stateChanged); + QScopedPointer<QProcess> process(new QProcess); + QSignalSpy stateSpy(process.data(), &QProcess::stateChanged); QVERIFY(stateSpy.isValid()); process->start("testProcessCrash/testProcessCrash"); QVERIFY(process->waitForStarted(5000)); @@ -355,9 +364,9 @@ void tst_QProcess::crashTest() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - QSignalSpy spy(process, &QProcess::errorOccurred); - QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); - QSignalSpy spy3(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy spy(process.data(), &QProcess::errorOccurred); + QSignalSpy spy2(process.data(), static_cast<QProcessErrorSignal>(&QProcess::error)); + QSignalSpy spy3(process.data(), static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); @@ -376,8 +385,8 @@ void tst_QProcess::crashTest() QCOMPARE(process->exitStatus(), QProcess::CrashExit); - delete process; - process = 0; + // delete process; + process.reset(); QCOMPARE(stateSpy.count(), 3); QCOMPARE(qvariant_cast<QProcess::ProcessState>(stateSpy.at(0).at(0)), QProcess::Starting); @@ -387,20 +396,21 @@ void tst_QProcess::crashTest() void tst_QProcess::crashTest2() { - process = new QProcess; - process->start("testProcessCrash/testProcessCrash"); - QVERIFY(process->waitForStarted(5000)); + QProcess process; + process.start("testProcessCrash/testProcessCrash"); + QVERIFY(process.waitForStarted(5000)); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); - QSignalSpy spy(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::errorOccurred)); - QSignalSpy spy2(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy spy(&process, static_cast<QProcessErrorSignal>(&QProcess::errorOccurred)); + QSignalSpy spy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); - QObject::connect(process, SIGNAL(finished(int)), this, SLOT(exitLoopSlot())); + QObject::connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::exitLoopSlot); QTestEventLoop::instance().enterLoop(30); if (QTestEventLoop::instance().timeout()) @@ -412,10 +422,7 @@ void tst_QProcess::crashTest2() QCOMPARE(spy2.count(), 1); QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit); - QCOMPARE(process->exitStatus(), QProcess::CrashExit); - - delete process; - process = 0; + QCOMPARE(process.exitStatus(), QProcess::CrashExit); } #ifndef Q_OS_WINCE @@ -438,24 +445,24 @@ void tst_QProcess::echoTest() { QFETCH(QByteArray, input); - process = new QProcess; - connect(process, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); + QProcess process; + connect(&process, &QIODevice::readyRead, this, &tst_QProcess::exitLoopSlot); - process->start("testProcessEcho/testProcessEcho"); - QVERIFY(process->waitForStarted(5000)); + process.start("testProcessEcho/testProcessEcho"); + QVERIFY(process.waitForStarted(5000)); - process->write(input); + process.write(input); QTime stopWatch; stopWatch.start(); do { - QVERIFY(process->isOpen()); + QVERIFY(process.isOpen()); QTestEventLoop::instance().enterLoop(2); - } while (stopWatch.elapsed() < 60000 && process->bytesAvailable() < input.size()); + } while (stopWatch.elapsed() < 60000 && process.bytesAvailable() < input.size()); if (stopWatch.elapsed() >= 60000) QFAIL("Timed out"); - QByteArray message = process->readAll(); + QByteArray message = process.readAll(); QCOMPARE(message.size(), input.size()); char *c1 = message.data(); @@ -468,13 +475,11 @@ void tst_QProcess::echoTest() } QCOMPARE(*c1, *c2); - process->write("", 1); - - QVERIFY(process->waitForFinished(5000)); - + process.write("", 1); - delete process; - process = 0; + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -488,17 +493,17 @@ void tst_QProcess::exitLoopSlot() void tst_QProcess::echoTest2() { - process = new QProcess; - connect(process, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); + QProcess process; + connect(&process, &QIODevice::readyRead, this, &tst_QProcess::exitLoopSlot); - process->start("testProcessEcho2/testProcessEcho2"); - QVERIFY(process->waitForStarted(5000)); - QVERIFY(!process->waitForReadyRead(250)); - QCOMPARE(process->error(), QProcess::Timedout); + process.start("testProcessEcho2/testProcessEcho2"); + QVERIFY(process.waitForStarted(5000)); + QVERIFY(!process.waitForReadyRead(250)); + QCOMPARE(process.error(), QProcess::Timedout); - process->write("Hello"); - QSignalSpy spy1(process, &QProcess::readyReadStandardOutput); - QSignalSpy spy2(process, &QProcess::readyReadStandardError); + process.write("Hello"); + QSignalSpy spy1(&process, &QProcess::readyReadStandardOutput); + QSignalSpy spy2(&process, &QProcess::readyReadStandardError); QVERIFY(spy1.isValid()); QVERIFY(spy2.isValid()); @@ -509,11 +514,11 @@ void tst_QProcess::echoTest2() QTestEventLoop::instance().enterLoop(1); if (stopWatch.elapsed() >= 30000) QFAIL("Timed out"); - process->setReadChannel(QProcess::StandardOutput); - qint64 baso = process->bytesAvailable(); + process.setReadChannel(QProcess::StandardOutput); + qint64 baso = process.bytesAvailable(); - process->setReadChannel(QProcess::StandardError); - qint64 base = process->bytesAvailable(); + process.setReadChannel(QProcess::StandardError); + qint64 base = process.bytesAvailable(); if (baso == 5 && base == 5) break; } @@ -521,14 +526,13 @@ void tst_QProcess::echoTest2() QVERIFY(spy1.count() > 0); QVERIFY(spy2.count() > 0); - QCOMPARE(process->readAllStandardOutput(), QByteArray("Hello")); - QCOMPARE(process->readAllStandardError(), QByteArray("Hello")); - - process->write("", 1); - QVERIFY(process->waitForFinished(5000)); + QCOMPARE(process.readAllStandardOutput(), QByteArray("Hello")); + QCOMPARE(process.readAllStandardError(), QByteArray("Hello")); - delete process; - process = 0; + process.write("", 1); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -545,6 +549,8 @@ void tst_QProcess::echoTestGui() process.write("q"); QVERIFY(process.waitForFinished(50000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); QCOMPARE(process.readAllStandardOutput(), QByteArray("Hello")); QCOMPARE(process.readAllStandardError(), QByteArray("Hello")); @@ -583,6 +589,8 @@ void tst_QProcess::batFiles() proc.start(batFile, QStringList()); QVERIFY(proc.waitForFinished(5000)); + QCOMPARE(proc.exitStatus(), QProcess::NormalExit); + QCOMPARE(proc.exitCode(), 0); QVERIFY(proc.bytesAvailable() > 0); @@ -616,21 +624,18 @@ void tst_QProcess::exitStatus_data() void tst_QProcess::exitStatus() { - process = new QProcess; + QProcess process; QFETCH(QStringList, processList); QFETCH(QList<QProcess::ExitStatus>, exitStatus); QCOMPARE(exitStatus.count(), processList.count()); for (int i = 0; i < processList.count(); ++i) { - process->start(processList.at(i)); - QVERIFY(process->waitForStarted(5000)); - QVERIFY(process->waitForFinished(30000)); + process.start(processList.at(i)); + QVERIFY(process.waitForStarted(5000)); + QVERIFY(process.waitForFinished(30000)); - QCOMPARE(process->exitStatus(), exitStatus.at(i)); + QCOMPARE(process.exitStatus(), exitStatus.at(i)); } - - process->deleteLater(); - process = 0; } #ifndef Q_OS_WINCE @@ -638,23 +643,22 @@ void tst_QProcess::exitStatus() void tst_QProcess::loopBackTest() { - process = new QProcess; - process->start("testProcessEcho/testProcessEcho"); - QVERIFY(process->waitForStarted(5000)); + QProcess process; + process.start("testProcessEcho/testProcessEcho"); + QVERIFY(process.waitForStarted(5000)); for (int i = 0; i < 100; ++i) { - process->write("Hello"); + process.write("Hello"); do { - QVERIFY(process->waitForReadyRead(5000)); - } while (process->bytesAvailable() < 5); - QCOMPARE(process->readAll(), QByteArray("Hello")); + QVERIFY(process.waitForReadyRead(5000)); + } while (process.bytesAvailable() < 5); + QCOMPARE(process.readAll(), QByteArray("Hello")); } - process->write("", 1); - QVERIFY(process->waitForFinished(5000)); - - delete process; - process = 0; + process.write("", 1); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -663,35 +667,32 @@ void tst_QProcess::loopBackTest() void tst_QProcess::readTimeoutAndThenCrash() { - process = new QProcess; - process->start("testProcessEcho/testProcessEcho"); - if (process->state() != QProcess::Starting) - QCOMPARE(process->state(), QProcess::Running); + QProcess process; + process.start("testProcessEcho/testProcessEcho"); + if (process.state() != QProcess::Starting) + QCOMPARE(process.state(), QProcess::Running); - QVERIFY(process->waitForStarted(5000)); - QCOMPARE(process->state(), QProcess::Running); + QVERIFY(process.waitForStarted(5000)); + QCOMPARE(process.state(), QProcess::Running); - QVERIFY(!process->waitForReadyRead(5000)); - QCOMPARE(process->error(), QProcess::Timedout); + QVERIFY(!process.waitForReadyRead(5000)); + QCOMPARE(process.error(), QProcess::Timedout); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); - QSignalSpy spy(process, &QProcess::errorOccurred); - QSignalSpy spy2(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy(&process, &QProcess::errorOccurred); + QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); - process->kill(); + process.kill(); - QVERIFY(process->waitForFinished(5000)); - QCOMPARE(process->state(), QProcess::NotRunning); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.state(), QProcess::NotRunning); QCOMPARE(spy.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); QCOMPARE(spy2.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); - - delete process; - process = 0; } #endif @@ -738,6 +739,8 @@ void tst_QProcess::deadWhileReading() QCOMPARE(output.count("\n"), 10*1024); process.waitForFinished(); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -749,23 +752,27 @@ void tst_QProcess::restartProcessDeadlock() // The purpose of this test is to detect whether restarting a // process in the finished() connected slot causes a deadlock // because of the way QProcessManager uses its locks. - QProcess proc; - process = &proc; - connect(process, SIGNAL(finished(int)), this, SLOT(restartProcess())); + QProcess process; + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::restartProcess); - process->start("testProcessEcho/testProcessEcho"); + process.start("testProcessEcho/testProcessEcho"); - QCOMPARE(process->write("", 1), qlonglong(1)); - QVERIFY(process->waitForFinished(5000)); + QCOMPARE(process.write("", 1), qlonglong(1)); + QVERIFY(process.waitForFinished(5000)); - process->disconnect(SIGNAL(finished(int))); + QObject::disconnect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), Q_NULLPTR, Q_NULLPTR); - QCOMPARE(process->write("", 1), qlonglong(1)); - QVERIFY(process->waitForFinished(5000)); + QCOMPARE(process.write("", 1), qlonglong(1)); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } void tst_QProcess::restartProcess() { + QProcess *process = qobject_cast<QProcess *>(sender()); + QVERIFY(process); process->start("testProcessEcho/testProcessEcho"); } #endif @@ -794,6 +801,8 @@ void tst_QProcess::closeWriteChannel() if (more.state() == QProcess::Running) more.write("q"); QVERIFY(more.waitForFinished(5000)); + QCOMPARE(more.exitStatus(), QProcess::NormalExit); + QCOMPARE(more.exitCode(), 0); } #endif @@ -824,6 +833,8 @@ void tst_QProcess::closeReadChannel() proc.write("", 1); QVERIFY(proc.waitForFinished(5000)); + QCOMPARE(proc.exitStatus(), QProcess::NormalExit); + QCOMPARE(proc.exitCode(), 0); } } #endif @@ -878,7 +889,7 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() { QProcess proc; - connect(&proc, SIGNAL(readyRead()), this, SLOT(exitLoopSlot())); + connect(&proc, &QIODevice::readyRead, this, &tst_QProcess::exitLoopSlot); QSignalSpy spy(&proc, &QProcess::readyRead); QVERIFY(spy.isValid()); @@ -898,12 +909,14 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() QVERIFY(QTestEventLoop::instance().timeout()); QVERIFY(!proc.waitForReadyRead(250)); - QObject::disconnect(&proc, SIGNAL(readyRead()), 0, 0); + QObject::disconnect(&proc, &QIODevice::readyRead, Q_NULLPTR, Q_NULLPTR); proc.write("B"); QVERIFY(proc.waitForReadyRead(5000)); proc.write("", 1); QVERIFY(proc.waitForFinished(5000)); + QCOMPARE(proc.exitStatus(), QProcess::NormalExit); + QCOMPARE(proc.exitCode(), 0); } #endif @@ -960,30 +973,30 @@ public: SoftExitProcess(int n) : waitedForFinished(false), n(n), killing(false) { - connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), - this, SLOT(finishedSlot(int,QProcess::ExitStatus))); + connect(this, static_cast<QProcessFinishedSignal2>(&QProcess::finished), + this, &SoftExitProcess::finishedSlot); switch (n) { case 0: setReadChannelMode(QProcess::MergedChannels); - connect(this, SIGNAL(readyRead()), this, SLOT(terminateSlot())); + connect(this, &QIODevice::readyRead, this, &SoftExitProcess::terminateSlot); break; case 1: - connect(this, SIGNAL(readyReadStandardOutput()), - this, SLOT(terminateSlot())); + connect(this, &QProcess::readyReadStandardOutput, + this, &SoftExitProcess::terminateSlot); break; case 2: - connect(this, SIGNAL(readyReadStandardError()), - this, SLOT(terminateSlot())); + connect(this, &QProcess::readyReadStandardError, + this, &SoftExitProcess::terminateSlot); break; case 3: - connect(this, SIGNAL(started()), - this, SLOT(terminateSlot())); + connect(this, &QProcess::started, + this, &SoftExitProcess::terminateSlot); break; case 4: default: - connect(this, SIGNAL(stateChanged(QProcess::ProcessState)), - this, SLOT(terminateSlot())); + connect(this, &QProcess::stateChanged, + this, &SoftExitProcess::terminateSlot); break; } } @@ -1084,6 +1097,8 @@ void tst_QProcess::mergedChannels() process.closeWriteChannel(); QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -1122,6 +1137,8 @@ void tst_QProcess::forwardedChannels() QCOMPARE(process.write("input"), 5); process.closeWriteChannel(); QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); const char *err; switch (process.exitCode()) { case 0: err = "ok"; break; @@ -1161,6 +1178,8 @@ void tst_QProcess::atEnd() process.write("", 1); QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -1179,8 +1198,8 @@ protected: exitCode = 90210; QProcess process; - connect(&process, SIGNAL(finished(int)), this, SLOT(catchExitCode(int)), - Qt::DirectConnection); + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &TestThread::catchExitCode, Qt::DirectConnection); process.start("testProcessEcho/testProcessEcho"); @@ -1239,19 +1258,16 @@ void tst_QProcess::processesInMultipleThreads() // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForFinishedWithTimeout() { - process = new QProcess(this); - - process->start("testProcessEcho/testProcessEcho"); + QProcess process; - QVERIFY(process->waitForStarted(5000)); - QVERIFY(!process->waitForFinished(1)); + process.start("testProcessEcho/testProcessEcho"); - process->write("", 1); + QVERIFY(process.waitForStarted(5000)); + QVERIFY(!process.waitForFinished(1)); - QVERIFY(process->waitForFinished()); + process.write("", 1); - delete process; - process = 0; + QVERIFY(process.waitForFinished()); } #endif @@ -1259,27 +1275,28 @@ void tst_QProcess::waitForFinishedWithTimeout() // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlot() { - process = new QProcess(this); - connect(process, SIGNAL(readyRead()), this, SLOT(waitForReadyReadInAReadyReadSlotSlot())); - connect(process, SIGNAL(finished(int)), this, SLOT(exitLoopSlot())); + QProcess process; + connect(&process, &QIODevice::readyRead, this, &tst_QProcess::waitForReadyReadInAReadyReadSlotSlot); + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::exitLoopSlot); bytesAvailable = 0; - process->start("testProcessEcho/testProcessEcho"); - QVERIFY(process->waitForStarted(5000)); + process.start("testProcessEcho/testProcessEcho"); + QVERIFY(process.waitForStarted(5000)); - QSignalSpy spy(process, &QProcess::readyRead); + QSignalSpy spy(&process, &QProcess::readyRead); QVERIFY(spy.isValid()); - process->write("foo"); + process.write("foo"); QTestEventLoop::instance().enterLoop(30); QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(spy.count(), 1); - process->disconnect(); - QVERIFY(process->waitForFinished(5000)); - QVERIFY(process->bytesAvailable() > bytesAvailable); - delete process; - process = 0; + process.disconnect(); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); + QVERIFY(process.bytesAvailable() > bytesAvailable); } #endif @@ -1287,6 +1304,8 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() { + QProcess *process = qobject_cast<QProcess *>(sender()); + QVERIFY(process); bytesAvailable = process->bytesAvailable(); process->write("bar", 4); QVERIFY(process->waitForReadyRead(5000)); @@ -1298,25 +1317,25 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() { - process = new QProcess(this); - connect(process, SIGNAL(bytesWritten(qint64)), this, SLOT(waitForBytesWrittenInABytesWrittenSlotSlot())); + QProcess process; + connect(&process, &QIODevice::bytesWritten, this, &tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot); bytesAvailable = 0; - process->start("testProcessEcho/testProcessEcho"); - QVERIFY(process->waitForStarted(5000)); + process.start("testProcessEcho/testProcessEcho"); + QVERIFY(process.waitForStarted(5000)); - QSignalSpy spy(process, &QProcess::bytesWritten); + QSignalSpy spy(&process, &QProcess::bytesWritten); QVERIFY(spy.isValid()); - process->write("f"); + process.write("f"); QTestEventLoop::instance().enterLoop(30); QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(spy.count(), 1); - process->write("", 1); - process->disconnect(); - QVERIFY(process->waitForFinished()); - delete process; - process = 0; + process.write("", 1); + process.disconnect(); + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -1324,6 +1343,8 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() { + QProcess *process = qobject_cast<QProcess *>(sender()); + QVERIFY(process); process->write("b"); QVERIFY(process->waitForBytesWritten(5000)); QTestEventLoop::instance().exitLoop(); @@ -1392,11 +1413,11 @@ void tst_QProcess::spaceArgsTest() << QString::fromLatin1("testProcessSpacesArgs/one space") << QString::fromLatin1("testProcessSpacesArgs/two space s"); - process = new QProcess(this); + QProcess process; for (int i = 0; i < programs.size(); ++i) { QString program = programs.at(i); - process->start(program, args); + process.start(program, args); #if defined(Q_OS_WINCE) const int timeOutMS = 10000; @@ -1404,14 +1425,16 @@ void tst_QProcess::spaceArgsTest() const int timeOutMS = 5000; #endif QByteArray errorMessage; - bool started = process->waitForStarted(timeOutMS); + bool started = process.waitForStarted(timeOutMS); if (!started) - errorMessage = startFailMessage(program, *process); + errorMessage = startFailMessage(program, process); QVERIFY2(started, errorMessage.constData()); - QVERIFY(process->waitForFinished(timeOutMS)); + QVERIFY(process.waitForFinished(timeOutMS)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); #if !defined(Q_OS_WINCE) - QStringList actual = QString::fromLatin1(process->readAll()).split("|"); + QStringList actual = QString::fromLatin1(process.readAll()).split("|"); #endif #if !defined(Q_OS_WINCE) QVERIFY(!actual.isEmpty()); @@ -1428,16 +1451,16 @@ void tst_QProcess::spaceArgsTest() program += QLatin1Char(' ') + stringArgs; errorMessage.clear(); - process->start(program); - started = process->waitForStarted(5000); + process.start(program); + started = process.waitForStarted(5000); if (!started) - errorMessage = startFailMessage(program, *process); + errorMessage = startFailMessage(program, process); QVERIFY2(started, errorMessage.constData()); - QVERIFY(process->waitForFinished(5000)); + QVERIFY(process.waitForFinished(5000)); #if !defined(Q_OS_WINCE) - actual = QString::fromLatin1(process->readAll()).split("|"); + actual = QString::fromLatin1(process.readAll()).split("|"); #endif #if !defined(Q_OS_WINCE) QVERIFY(!actual.isEmpty()); @@ -1447,9 +1470,6 @@ void tst_QProcess::spaceArgsTest() QCOMPARE(actual, args); #endif } - - delete process; - process = 0; } #if defined(Q_OS_WIN) @@ -1471,6 +1491,8 @@ void tst_QProcess::nativeArguments() QVERIFY(proc.waitForStarted(10000)); QVERIFY(proc.waitForFinished(10000)); #endif + QCOMPARE(proc.exitStatus(), QProcess::NormalExit); + QCOMPARE(proc.exitCode(), 0); #if defined(Q_OS_WINCE) // WinCE test outputs to a file, so check that @@ -1525,9 +1547,9 @@ void tst_QProcess::failToStart() QProcess process; QSignalSpy stateSpy(&process, &QProcess::stateChanged); QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(stateSpy.isValid()); QVERIFY(errorSpy.isValid()); @@ -1597,9 +1619,9 @@ void tst_QProcess::failToStartWithWait() QProcess process; QEventLoop loop; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy2.isValid()); @@ -1629,9 +1651,9 @@ void tst_QProcess::failToStartWithEventLoop() QProcess process; QEventLoop loop; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy2.isValid()); @@ -1669,7 +1691,7 @@ void tst_QProcess::failToStartEmptyArgs() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QProcess process; - QSignalSpy errorSpy(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(errorSpy.isValid()); switch (startOverload) { @@ -1707,6 +1729,8 @@ void tst_QProcess::removeFileWhileProcessIsRunning() process.write("", 1); QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif #ifndef Q_OS_WINCE @@ -1851,6 +1875,8 @@ void tst_QProcess::spaceInName() QVERIFY(process.waitForStarted()); process.write("", 1); QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } #endif @@ -1893,9 +1919,9 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() QProcess process; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); - QSignalSpy finishedSpy1(&process, static_cast<void (QProcess::*)(int)>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QSignalSpy finishedSpy1(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy2.isValid()); @@ -1932,6 +1958,8 @@ void tst_QProcess::setStandardInputFile() process.start("testProcessEcho/testProcessEcho"); QPROCESS_VERIFY(process, waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); QByteArray all = process.readAll(); QCOMPARE(all.size(), int(sizeof data) - 1); // testProcessEcho drops the ending \0 QVERIFY(all == data); @@ -2004,6 +2032,8 @@ void tst_QProcess::setStandardOutputFile() process.start("testProcessEcho2/testProcessEcho2"); process.write(testdata, sizeof testdata); QPROCESS_VERIFY(process,waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); // open the file again and verify the data QVERIFY(file.open(QIODevice::ReadOnly)); @@ -2033,6 +2063,8 @@ void tst_QProcess::setStandardOutputFileNullDevice() process.start("testProcessEcho2/testProcessEcho2"); process.write(testdata, sizeof testdata); QPROCESS_VERIFY(process,waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); QVERIFY(!QFileInfo(QProcess::nullDevice()).isFile()); @@ -2049,6 +2081,8 @@ void tst_QProcess::setStandardOutputFileAndWaitForBytesWritten() process.write(testdata, sizeof testdata); process.waitForBytesWritten(); QPROCESS_VERIFY(process, waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); // open the file again and verify the data QVERIFY(file.open(QIODevice::ReadOnly)); @@ -2089,7 +2123,11 @@ void tst_QProcess::setStandardOutputProcess() source.waitForBytesWritten(); source.closeWriteChannel(); QPROCESS_VERIFY(source, waitForFinished()); + QCOMPARE(source.exitStatus(), QProcess::NormalExit); + QCOMPARE(source.exitCode(), 0); QPROCESS_VERIFY(sink, waitForFinished()); + QCOMPARE(sink.exitStatus(), QProcess::NormalExit); + QCOMPARE(sink.exitCode(), 0); QByteArray all = sink.readAll(); if (!merged) @@ -2103,25 +2141,34 @@ void tst_QProcess::setStandardOutputProcess() // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::fileWriterProcess() { - QString stdinStr; - for (int i = 0; i < 5000; ++i) - stdinStr += QString::fromLatin1("%1 -- testing testing 1 2 3\n").arg(i); + const QByteArray line = QByteArrayLiteral(" -- testing testing 1 2 3\n"); + QByteArray stdinStr; + stdinStr.reserve(5000 * (4 + line.size()) + 1); + for (int i = 0; i < 5000; ++i) { + stdinStr += QByteArray::number(i); + stdinStr += line; + } QTime stopWatch; stopWatch.start(); + const QString fileName = QLatin1String("fileWriterProcess.txt"); + do { - QFile::remove("fileWriterProcess.txt"); + if (QFile::exists(fileName)) + QVERIFY(QFile::remove(fileName)); QProcess process; process.start("fileWriterProcess/fileWriterProcess", QIODevice::ReadWrite | QIODevice::Text); - process.write(stdinStr.toLatin1()); + process.write(stdinStr); process.closeWriteChannel(); while (process.bytesToWrite()) { QVERIFY(stopWatch.elapsed() < 3500); QVERIFY(process.waitForBytesWritten(2000)); } QVERIFY(process.waitForFinished()); - QCOMPARE(QFile("fileWriterProcess.txt").size(), qint64(stdinStr.size())); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); + QCOMPARE(QFile(fileName).size(), qint64(stdinStr.size())); } while (stopWatch.elapsed() < 3000); } #endif @@ -2181,6 +2228,8 @@ void tst_QProcess::switchReadChannels() process.write(data); process.closeWriteChannel(); QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); for (int i = 0; i < 4; ++i) { process.setReadChannel(QProcess::StandardOutput); @@ -2210,6 +2259,8 @@ void tst_QProcess::discardUnwantedOutput() process.write("Hello, World"); process.closeWriteChannel(); QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); process.setReadChannel(QProcess::StandardOutput); QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); @@ -2223,45 +2274,41 @@ void tst_QProcess::discardUnwantedOutput() // Windows CE does not support working directory logic void tst_QProcess::setWorkingDirectory() { - process = new QProcess; - process->setWorkingDirectory("test"); + QProcess process; + process.setWorkingDirectory("test"); // use absolute path because on Windows, the executable is relative to the parent's CWD // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). - process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + process.start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); - QVERIFY2(process->waitForFinished(), process->errorString().toLocal8Bit()); + QVERIFY2(process.waitForFinished(), process.errorString().toLocal8Bit()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); - QByteArray workingDir = process->readAllStandardOutput(); + QByteArray workingDir = process.readAllStandardOutput(); QCOMPARE(QDir("test").canonicalPath(), QDir(workingDir.constData()).canonicalPath()); - - delete process; - process = 0; } void tst_QProcess::setNonExistentWorkingDirectory() { - process = new QProcess; - process->setWorkingDirectory("this/directory/should/not/exist/for/sure"); + QProcess process; + process.setWorkingDirectory("this/directory/should/not/exist/for/sure"); // use absolute path because on Windows, the executable is relative to the parent's CWD // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). - process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); - QVERIFY(!process->waitForFinished()); + process.start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + QVERIFY(!process.waitForFinished()); #ifdef QPROCESS_USE_SPAWN QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue); #endif - QCOMPARE(int(process->error()), int(QProcess::FailedToStart)); + QCOMPARE(int(process.error()), int(QProcess::FailedToStart)); #ifdef Q_OS_UNIX # ifdef QPROCESS_USE_SPAWN QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue); # endif - QVERIFY2(process->errorString().startsWith("chdir:"), process->errorString().toLocal8Bit()); + QVERIFY2(process.errorString().startsWith("chdir:"), process.errorString().toLocal8Bit()); #endif - - delete process; - process = 0; } #endif @@ -2278,8 +2325,11 @@ void tst_QProcess::startFinishStartFinish() QCOMPARE(QString::fromLatin1(process.readLine().trimmed()), QString("0 -this is a number")); #endif - if (process.state() != QProcess::NotRunning) + if (process.state() != QProcess::NotRunning) { QVERIFY(process.waitForFinished(10000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); + } } } @@ -2298,7 +2348,7 @@ void tst_QProcess::invalidProgramString() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QSignalSpy spy(&process, &QProcess::errorOccurred); - QSignalSpy spy2(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error)); + QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); @@ -2316,7 +2366,7 @@ void tst_QProcess::onlyOneStartedSignal() QProcess process; QSignalSpy spyStarted(&process, &QProcess::started); - QSignalSpy spyFinished(&process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished)); + QSignalSpy spyFinished(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(spyStarted.isValid()); QVERIFY(spyFinished.isValid()); @@ -2332,6 +2382,8 @@ void tst_QProcess::onlyOneStartedSignal() process.start("testProcessNormal/testProcessNormal"); QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); QCOMPARE(spyStarted.count(), 1); QCOMPARE(spyFinished.count(), 1); } @@ -2342,7 +2394,7 @@ class BlockOnReadStdOut : public QObject public: BlockOnReadStdOut(QProcess *process) { - connect(process, SIGNAL(readyReadStandardOutput()), SLOT(block())); + connect(process, &QProcess::readyReadStandardOutput, this, &BlockOnReadStdOut::block); } public slots: @@ -2357,7 +2409,8 @@ void tst_QProcess::finishProcessBeforeReadingDone() QProcess process; BlockOnReadStdOut blocker(&process); QEventLoop loop; - connect(&process, SIGNAL(finished(int)), &loop, SLOT(quit())); + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + &loop, &QEventLoop::quit); process.start("testProcessOutput/testProcessOutput"); QVERIFY(process.waitForStarted()); loop.exec(); @@ -2365,6 +2418,8 @@ void tst_QProcess::finishProcessBeforeReadingDone() QRegExp(QStringLiteral("[\r\n]")), QString::SkipEmptyParts); QVERIFY(!lines.isEmpty()); QCOMPARE(lines.last(), QStringLiteral("10239 -this is a number")); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); } //----------------------------------------------------------------------------- @@ -2381,14 +2436,17 @@ void tst_QProcess::startStopStartStop() QProcess process; process.start("testProcessNormal/testProcessNormal"); QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); process.start("testExitCodes/testExitCodes", QStringList() << "1"); QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 1); process.start("testProcessNormal/testProcessNormal"); QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } @@ -2460,6 +2518,7 @@ void tst_QProcess::startStopStartStopBuffers() process.write("line3\n"); process.closeWriteChannel(); QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); if (channelMode2 == QProcess::MergedChannels) { diff --git a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp index 5796636b92..6e6dc2df95 100644 --- a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp +++ b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp @@ -99,7 +99,7 @@ static inline QByteArray msgCannotOpen(const QFileDevice &f) void tst_QSaveFile::transactionalWrite() { QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); QFile::remove(targetFile); QSaveFile file(targetFile); @@ -134,7 +134,7 @@ void tst_QSaveFile::saveTwice() // Check that we can reuse a QSaveFile object // (and test the case of an existing target file) QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); QSaveFile file(targetFile); QVERIFY2(file.open(QIODevice::WriteOnly), msgCannotOpen(file).constData()); @@ -153,7 +153,7 @@ void tst_QSaveFile::saveTwice() void tst_QSaveFile::textStreamManualFlush() { QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); QSaveFile file(targetFile); QVERIFY2(file.open(QIODevice::WriteOnly), msgCannotOpen(file).constData()); @@ -174,7 +174,7 @@ void tst_QSaveFile::textStreamManualFlush() void tst_QSaveFile::textStreamAutoFlush() { QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); QSaveFile file(targetFile); QVERIFY2(file.open(QIODevice::WriteOnly), msgCannotOpen(file).constData()); @@ -206,7 +206,7 @@ void tst_QSaveFile::transactionalWriteNoPermissionsOnDir() #endif QFETCH(bool, directWriteFallback); QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); QVERIFY(QFile(dir.path()).setPermissions(QFile::ReadOwner | QFile::ExeOwner)); PermissionRestorer permissionRestorer(dir.path()); @@ -264,7 +264,7 @@ void tst_QSaveFile::transactionalWriteNoPermissionsOnFile() #endif // Setup an existing but readonly file QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); QFile file(targetFile); PermissionRestorer permissionRestorer(targetFile); @@ -285,7 +285,7 @@ void tst_QSaveFile::transactionalWriteNoPermissionsOnFile() void tst_QSaveFile::transactionalWriteCanceled() { QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); QFile::remove(targetFile); QSaveFile file(targetFile); @@ -313,7 +313,7 @@ void tst_QSaveFile::transactionalWriteErrorRenaming() QSKIP("Test is not applicable with root privileges"); #endif QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); QSaveFile file(targetFile); QVERIFY2(file.open(QIODevice::WriteOnly), msgCannotOpen(file).constData()); @@ -347,7 +347,7 @@ void tst_QSaveFile::symlink() #ifdef Q_OS_UNIX QByteArray someData = "some data"; QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString targetFile = dir.path() + QLatin1String("/outfile"); const QString linkFile = dir.path() + QLatin1String("/linkfile"); @@ -400,7 +400,7 @@ void tst_QSaveFile::symlink() // link to a link in another directory QTemporaryDir dir2; - QVERIFY(dir2.isValid()); + QVERIFY2(dir2.isValid(), qPrintable(dir2.errorString())); const QString linkFile2 = dir2.path() + QLatin1String("/linkfile"); QVERIFY(QFile::link(linkFile, linkFile2)); @@ -458,7 +458,7 @@ void tst_QSaveFile::symlink() void tst_QSaveFile::directory() { QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); const QString subdir = dir.path() + QLatin1String("/subdir"); QVERIFY(QDir(dir.path()).mkdir(QStringLiteral("subdir"))); diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 83ccf20a6d..a520010b47 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -3378,7 +3378,7 @@ void tst_QSettings::dontReorderIniKeysNeedlessly() QString outFileName2; QTemporaryFile outFile; - outFile.open(); + QVERIFY2(outFile.open(), qPrintable(outFile.errorString())); outFile.write(contentsBefore); outFileName = outFile.fileName(); outFile.close(); diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index efb343cf85..24ff2f237f 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -56,6 +56,7 @@ class tst_qstandardpaths : public QObject Q_OBJECT private slots: + void initTestCase(); void dump(); void testDefaultLocations(); void testCustomLocations(); @@ -128,6 +129,14 @@ static const char * const enumNames[MaxStandardLocation + 1 - int(QStandardPaths "AppConfigLocation" }; +void tst_qstandardpaths::initTestCase() +{ + QVERIFY2(m_localConfigTempDir.isValid(), qPrintable(m_localConfigTempDir.errorString())); + QVERIFY2(m_globalConfigTempDir.isValid(), qPrintable(m_globalConfigTempDir.errorString())); + QVERIFY2(m_localAppTempDir.isValid(), qPrintable(m_localAppTempDir.errorString())); + QVERIFY2(m_globalAppTempDir.isValid(), qPrintable(m_globalAppTempDir.errorString())); +} + void tst_qstandardpaths::dump() { #ifdef Q_XDG_PLATFORM diff --git a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp index 57bb81be61..aaaa0d4949 100644 --- a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp +++ b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp @@ -153,7 +153,7 @@ void tst_QStorageInfo::storageList() void tst_QStorageInfo::tempFile() { QTemporaryFile file; - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QStorageInfo storage1(file.fileName()); #ifdef Q_OS_LINUX @@ -174,7 +174,7 @@ void tst_QStorageInfo::tempFile() void tst_QStorageInfo::caching() { QTemporaryFile file; - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QStorageInfo storage1(file.fileName()); #ifdef Q_OS_LINUX diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 4bcdd1b827..532a53e5d3 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -258,6 +258,7 @@ tst_QTextStream::tst_QTextStream() void tst_QTextStream::initTestCase() { + QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); QVERIFY(!m_rfc3261FilePath.isEmpty()); QVERIFY(!m_shiftJisFilePath.isEmpty()); diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 7d85377c7a..629bbad5aa 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -2808,7 +2808,7 @@ public: QModelIndex tl; QModelIndex br; public slots: - void changed(const QItemSelection &selected, const QItemSelection &deselected) + void changed(const QItemSelection &, const QItemSelection &deselected) { tl = deselected.first().topLeft(); br = deselected.first().bottomRight(); diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index a0cadc9a2f..b889d61786 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -41,12 +41,7 @@ #include <private/qeventloop_p.h> #include <private/qthread_p.h> -#ifdef QT_GUI_LIB -#include <QtGui/QGuiApplication> -typedef QGuiApplication TestApplication; -#else typedef QCoreApplication TestApplication; -#endif class EventSpy : public QObject { diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp index 4d54aa4dc8..22c78f8e48 100644 --- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp +++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com> +** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -38,15 +38,29 @@ #include <qobject.h> #include <qmetaobject.h> +struct CustomType +{ + int padding; + QString str; + CustomType(const QString &str = QString()) : str(str) {} + operator QString() const { return str; } + friend bool operator!=(const CustomType &a, const CustomType &b) + { return a.str != b.str; } +}; + +Q_DECLARE_METATYPE(CustomType) + class tst_QMetaProperty : public QObject { Q_OBJECT Q_PROPERTY(EnumType value WRITE setValue READ getValue) Q_PROPERTY(EnumType value2 WRITE set_value READ get_value) + Q_PROPERTY(QString value7 MEMBER value7 RESET resetValue7) Q_PROPERTY(int value8 READ value8) Q_PROPERTY(int value9 READ value9 CONSTANT) Q_PROPERTY(int value10 READ value10 FINAL) Q_PROPERTY(QMap<int, int> map MEMBER map) + Q_PROPERTY(CustomType custom MEMBER custom) private slots: void hasStdCppSet(); @@ -55,6 +69,7 @@ private slots: void gadget(); void readAndWriteWithLazyRegistration(); void mapProperty(); + void conversion(); public: enum EnumType { EnumType1 }; @@ -64,11 +79,14 @@ public: void set_value(EnumType) {} EnumType get_value() const { return EnumType1; } + void resetValue7() { value7 = QStringLiteral("reset"); } int value8() const { return 1; } int value9() const { return 1; } int value10() const { return 1; } + QString value7; QMap<int, int> map; + CustomType custom; }; void tst_QMetaProperty::hasStdCppSet() @@ -195,5 +213,42 @@ void tst_QMetaProperty::mapProperty() QCOMPARE(map, (v.value<QMap<int,int> >())); } +void tst_QMetaProperty::conversion() +{ + QMetaType::registerConverter<QString, CustomType>(); + QMetaType::registerConverter<CustomType, QString>(); + + QString hello = QStringLiteral("Hello"); + + // Write to a QString property using a CustomType in a QVariant + QMetaProperty value7P = metaObject()->property(metaObject()->indexOfProperty("value7")); + QVERIFY(value7P.isValid()); + QVERIFY(value7P.write(this, QVariant::fromValue(CustomType(hello)))); + QCOMPARE(value7, hello); + + // Write to a CustomType property using a QString in a QVariant + QMetaProperty customP = metaObject()->property(metaObject()->indexOfProperty("custom")); + QVERIFY(customP.isValid()); + QVERIFY(customP.write(this, hello)); + QCOMPARE(custom.str, hello); + + // Something that cannot be converted should fail + QVERIFY(!customP.write(this, 45)); + QVERIFY(!customP.write(this, QVariant::fromValue(this))); + QVERIFY(!value7P.write(this, QVariant::fromValue(this))); + QVERIFY(!value7P.write(this, QVariant::fromValue<QObject*>(this))); + + // none of this should have changed the values + QCOMPARE(value7, hello); + QCOMPARE(custom.str, hello); + + // Empty variant should be converted to default object + QVERIFY(customP.write(this, QVariant())); + QCOMPARE(custom.str, QString()); + // or reset resetable + QVERIFY(value7P.write(this, QVariant())); + QCOMPARE(value7, QLatin1Literal("reset")); +} + QTEST_MAIN(tst_QMetaProperty) #include "tst_qmetaproperty.moc" diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 3661db071b..90f7780344 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -1925,7 +1925,7 @@ void tst_QObject::property() QCOMPARE(object.property("string"), QVariant("String1")); QVERIFY(object.setProperty("string", "String2")); QCOMPARE(object.property("string"), QVariant("String2")); - QVERIFY(!object.setProperty("string", QVariant())); + QVERIFY(object.setProperty("string", QVariant())); const int idx = mo->indexOfProperty("variant"); QVERIFY(idx != -1); @@ -2027,7 +2027,7 @@ void tst_QObject::property() QCOMPARE(object.property("customString"), QVariant("String1")); QVERIFY(object.setProperty("customString", "String2")); QCOMPARE(object.property("customString"), QVariant("String2")); - QVERIFY(!object.setProperty("customString", QVariant())); + QVERIFY(object.setProperty("customString", QVariant())); } void tst_QObject::metamethod() diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp index d0eb10d3aa..30ce65849d 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp +++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp @@ -40,6 +40,7 @@ #include <QtCore/QSocketNotifier> #include <QtNetwork/QTcpServer> #include <QtNetwork/QTcpSocket> +#include <QtNetwork/QUdpSocket> #ifndef Q_OS_WINRT #include <private/qnativesocketengine_p.h> #else @@ -66,8 +67,29 @@ private slots: #ifdef Q_OS_UNIX void posixSockets(); #endif + void asyncMultipleDatagram(); + +protected slots: + void async_readDatagramSlot(); + void async_writeDatagramSlot(); + +private: + QUdpSocket *m_asyncSender; + QUdpSocket *m_asyncReceiver; }; +static QHostAddress makeNonAny(const QHostAddress &address, + QHostAddress::SpecialAddress preferForAny = QHostAddress::LocalHost) +{ + if (address == QHostAddress::Any) + return preferForAny; + if (address == QHostAddress::AnyIPv4) + return QHostAddress::LocalHost; + if (address == QHostAddress::AnyIPv6) + return QHostAddress::LocalHostIPv6; + return address; +} + class UnexpectedDisconnectTester : public QObject { Q_OBJECT @@ -299,5 +321,56 @@ void tst_QSocketNotifier::posixSockets() } #endif +void tst_QSocketNotifier::async_readDatagramSlot() +{ + char buf[1]; + QVERIFY(m_asyncReceiver->hasPendingDatagrams()); + do { + QCOMPARE(m_asyncReceiver->pendingDatagramSize(), qint64(1)); + QCOMPARE(m_asyncReceiver->readDatagram(buf, sizeof(buf)), qint64(1)); + if (buf[0] == '1') { + // wait for the second datagram message. + QTest::qSleep(100); + } + } while (m_asyncReceiver->hasPendingDatagrams()); + + if (buf[0] == '3') + QTestEventLoop::instance().exitLoop(); +} + +void tst_QSocketNotifier::async_writeDatagramSlot() +{ + m_asyncSender->writeDatagram("3", makeNonAny(m_asyncReceiver->localAddress()), + m_asyncReceiver->localPort()); +} + +void tst_QSocketNotifier::asyncMultipleDatagram() +{ + m_asyncSender = new QUdpSocket; + m_asyncReceiver = new QUdpSocket; + + QVERIFY(m_asyncReceiver->bind(QHostAddress(QHostAddress::AnyIPv4), 0)); + quint16 port = m_asyncReceiver->localPort(); + QVERIFY(port != 0); + + QSignalSpy spy(m_asyncReceiver, &QIODevice::readyRead); + connect(m_asyncReceiver, &QIODevice::readyRead, this, + &tst_QSocketNotifier::async_readDatagramSlot); + m_asyncSender->writeDatagram("1", makeNonAny(m_asyncReceiver->localAddress()), port); + m_asyncSender->writeDatagram("2", makeNonAny(m_asyncReceiver->localAddress()), port); + // wait a little to ensure that the datagrams we've just sent + // will be delivered on receiver side. + QTest::qSleep(100); + + QTimer::singleShot(500, this, &tst_QSocketNotifier::async_writeDatagramSlot); + + QTestEventLoop::instance().enterLoop(1); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(spy.count(), 2); + + delete m_asyncSender; + delete m_asyncReceiver; +} + QTEST_MAIN(tst_QSocketNotifier) #include <tst_qsocketnotifier.moc> diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 064f780546..c17d81ea9e 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -72,6 +72,7 @@ private slots: void singleShotStaticFunctionZeroTimeout(); void recurseOnTimeoutAndStopTimer(); void singleShotToFunctors(); + void crossThreadSingleShotToFunctor(); void dontBlockEvents(); void postedEventsShouldNotStarveTimers(); @@ -877,5 +878,28 @@ void tst_QTimer::postedEventsShouldNotStarveTimers() QVERIFY(timerHelper.count > 5); } +struct DummyFunctor { + void operator()() {} +}; + +void tst_QTimer::crossThreadSingleShotToFunctor() +{ + // We're testing for crashes here, so the test simply running to + // completion is considered a success + QThread t; + t.start(); + + QObject* o = new QObject(); + o->moveToThread(&t); + + for (int i = 0; i < 10000; i++) { + QTimer::singleShot(0, o, DummyFunctor()); + } + + t.quit(); + t.wait(); + delete o; +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic1.xml b/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic1.xml new file mode 100644 index 0000000000..04204d8763 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic1.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="text/invalid-magic1"> + <comment>wrong value for byte type</comment> + <magic> + <match value="foo" type="byte" offset="0"/> + </magic> + </mime-type> +</mime-info> diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic2.xml b/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic2.xml new file mode 100644 index 0000000000..f18075482e --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic2.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="text/invalid-magic2"> + <comment>mask doesn't start with 0x</comment> + <magic> + <match value="foo" type="string" mask="ffff" offset="0"/> + </magic> + </mime-type> +</mime-info> diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic3.xml b/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic3.xml new file mode 100644 index 0000000000..0e2508cc0f --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/invalid-magic3.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="text/invalid-magic3"> + <comment>mask has wrong size</comment> + <magic> + <match value="foo" type="string" mask="0xffff" offset="0"/> + </magic> + </mime-type> +</mime-info> diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc b/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc index 4654a61660..29666627a1 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc +++ b/tests/auto/corelib/mimetypes/qmimedatabase/testdata.qrc @@ -4,5 +4,8 @@ <file alias="qml-again.xml">qml-again.xml</file> <file alias="text-x-objcsrc.xml">text-x-objcsrc.xml</file> <file alias="test.qml">test.qml</file> + <file>invalid-magic1.xml</file> + <file>invalid-magic2.xml</file> + <file>invalid-magic3.xml</file> </qresource> </RCC> diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index dd04849f87..0171c4ac5a 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -46,9 +46,16 @@ #include <QtTest/QtTest> -static const char yastFileName[] ="yast2-metapackage-handler-mimetypes.xml"; -static const char qmlAgainFileName[] ="qml-again.xml"; -static const char textXObjCSrcFileName[] ="text-x-objcsrc.xml"; +static const char *const additionalMimeFiles[] = { + "yast2-metapackage-handler-mimetypes.xml", + "qml-again.xml", + "text-x-objcsrc.xml", + "invalid-magic1.xml", + "invalid-magic2.xml", + "invalid-magic3.xml", + 0 +}; + #define RESOURCE_PREFIX ":/qt-project.org/qmime/" void initializeLang() @@ -120,6 +127,7 @@ tst_QMimeDatabase::tst_QMimeDatabase() void tst_QMimeDatabase::initTestCase() { + QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString())); QStandardPaths::setTestModeEnabled(true); m_localMimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/mime"; if (QDir(m_localMimeDir).exists()) { @@ -151,12 +159,12 @@ void tst_QMimeDatabase::initTestCase() qWarning("%s", qPrintable(testSuiteWarning())); errorMessage = QString::fromLatin1("Cannot find '%1'"); - m_yastMimeTypes = QLatin1String(RESOURCE_PREFIX) + yastFileName; - QVERIFY2(QFile::exists(m_yastMimeTypes), qPrintable(errorMessage.arg(yastFileName))); - m_qmlAgainFileName = QLatin1String(RESOURCE_PREFIX) + qmlAgainFileName; - QVERIFY2(QFile::exists(m_qmlAgainFileName), qPrintable(errorMessage.arg(qmlAgainFileName))); - m_textXObjCSrcFileName = QLatin1String(RESOURCE_PREFIX) + textXObjCSrcFileName; - QVERIFY2(QFile::exists(m_textXObjCSrcFileName), qPrintable(errorMessage.arg(textXObjCSrcFileName))); + for (uint i = 0; i < sizeof additionalMimeFiles / sizeof additionalMimeFiles[0] - 1; i++) { + const QString resourceFilePath = QString::fromLatin1(RESOURCE_PREFIX) + QLatin1String(additionalMimeFiles[i]); + QVERIFY2(QFile::exists(resourceFilePath), qPrintable(errorMessage.arg(resourceFilePath))); + m_additionalMimeFileNames.append(QLatin1String(additionalMimeFiles[i])); + m_additionalMimeFilePaths.append(resourceFilePath); + } initTestCaseInternal(); m_isUsingCacheProvider = !qEnvironmentVariableIsSet("QT_NO_MIME_CACHE"); @@ -865,6 +873,14 @@ static void checkHasMimeType(const QString &mimeType) QVERIFY(found); } +static void ignoreInvalidMimetypeWarnings(const QString &mimeDir) +{ + const QByteArray basePath = QFile::encodeName(mimeDir) + "/packages/"; + QTest::ignoreMessage(QtWarningMsg, ("QMimeDatabase: Error parsing " + basePath + "invalid-magic1.xml\nInvalid magic rule value \"foo\"").constData()); + QTest::ignoreMessage(QtWarningMsg, ("QMimeDatabase: Error parsing " + basePath + "invalid-magic2.xml\nInvalid magic rule mask \"ffff\"").constData()); + QTest::ignoreMessage(QtWarningMsg, ("QMimeDatabase: Error parsing " + basePath + "invalid-magic3.xml\nInvalid magic rule mask size \"0xffff\"").constData()); +} + QT_BEGIN_NAMESPACE extern Q_CORE_EXPORT int qmime_secondsBetweenChecks; // see qmimeprovider.cpp QT_END_NAMESPACE @@ -885,23 +901,21 @@ void tst_QMimeDatabase::installNewGlobalMimeType() const QString mimeDir = m_globalXdgDir + QLatin1String("/mime"); const QString destDir = mimeDir + QLatin1String("/packages/"); - const QString destFile = destDir + QLatin1String(yastFileName); - QFile::remove(destFile); - const QString destQmlFile = destDir + QLatin1String(qmlAgainFileName); - QFile::remove(destQmlFile); - const QString destTextXObjCSrcFile = destDir + QLatin1String(textXObjCSrcFileName); - QFile::remove(destTextXObjCSrcFile); - //qDebug() << destFile; - if (!QFileInfo(destDir).isDir()) QVERIFY(QDir(m_globalXdgDir).mkpath(destDir)); + QString errorMessage; - QVERIFY2(copyResourceFile(m_yastMimeTypes, destFile, &errorMessage), qPrintable(errorMessage)); - QVERIFY2(copyResourceFile(m_qmlAgainFileName, destQmlFile, &errorMessage), qPrintable(errorMessage)); - QVERIFY2(copyResourceFile(m_textXObjCSrcFileName, destTextXObjCSrcFile, &errorMessage), qPrintable(errorMessage)); + for (int i = 0; i < m_additionalMimeFileNames.size(); ++i) { + const QString destFile = destDir + m_additionalMimeFileNames.at(i); + QFile::remove(destFile); + QVERIFY2(copyResourceFile(m_additionalMimeFilePaths.at(i), destFile, &errorMessage), qPrintable(errorMessage)); + } if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); + if (!m_isUsingCacheProvider) + ignoreInvalidMimetypeWarnings(mimeDir); + QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), QString::fromLatin1("text/x-SuSE-ymu")); QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); @@ -922,10 +936,9 @@ void tst_QMimeDatabase::installNewGlobalMimeType() qDebug() << objcsrc.globPatterns(); } - // Now test removing it again - QVERIFY(QFile::remove(destFile)); - QVERIFY(QFile::remove(destQmlFile)); - QVERIFY(QFile::remove(destTextXObjCSrcFile)); + // Now test removing the mimetype definitions again + for (int i = 0; i < m_additionalMimeFileNames.size(); ++i) + QFile::remove(destDir + m_additionalMimeFileNames.at(i)); if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), @@ -942,23 +955,35 @@ void tst_QMimeDatabase::installNewLocalMimeType() qmime_secondsBetweenChecks = 0; QMimeDatabase db; + + // Check that we're starting clean QVERIFY(!db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + QVERIFY(!db.mimeTypeForName(QLatin1String("text/invalid-magic1")).isValid()); const QString destDir = m_localMimeDir + QLatin1String("/packages/"); - QDir().mkpath(destDir); - const QString destFile = destDir + QLatin1String(yastFileName); - QFile::remove(destFile); - const QString destQmlFile = destDir + QLatin1String(qmlAgainFileName); - QFile::remove(destQmlFile); + QVERIFY(QDir().mkpath(destDir)); QString errorMessage; - QVERIFY2(copyResourceFile(m_yastMimeTypes, destFile, &errorMessage), qPrintable(errorMessage)); - QVERIFY2(copyResourceFile(m_qmlAgainFileName, destQmlFile, &errorMessage), qPrintable(errorMessage)); - if (m_isUsingCacheProvider && !runUpdateMimeDatabase(m_localMimeDir)) { + for (int i = 0; i < m_additionalMimeFileNames.size(); ++i) { + const QString destFile = destDir + m_additionalMimeFileNames.at(i); + QFile::remove(destFile); + QVERIFY2(copyResourceFile(m_additionalMimeFilePaths.at(i), destFile, &errorMessage), qPrintable(errorMessage)); + } + if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(m_localMimeDir)) { const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (") + QDir::toNativeSeparators(m_localMimeDir) + QLatin1Char(')'); QSKIP(qPrintable(skipWarning)); } + if (!m_isUsingCacheProvider) + ignoreInvalidMimetypeWarnings(m_localMimeDir); + + QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); + + // These mimetypes have invalid magic, but still do exist. + QVERIFY(db.mimeTypeForName(QLatin1String("text/invalid-magic1")).isValid()); + QVERIFY(db.mimeTypeForName(QLatin1String("text/invalid-magic2")).isValid()); + QVERIFY(db.mimeTypeForName(QLatin1String("text/invalid-magic3")).isValid()); + QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), QString::fromLatin1("text/x-SuSE-ymu")); QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); @@ -974,8 +999,8 @@ void tst_QMimeDatabase::installNewLocalMimeType() QString::fromLatin1("text/x-qml")); // Now test removing the local mimetypes again (note, this leaves a mostly-empty mime.cache file) - QVERIFY(QFile::remove(destFile)); - QVERIFY(QFile::remove(destQmlFile)); + for (int i = 0; i < m_additionalMimeFileNames.size(); ++i) + QFile::remove(destDir + m_additionalMimeFileNames.at(i)); if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(m_localMimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h index f12beafe86..2827bd2dc4 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h @@ -36,6 +36,7 @@ #include <QtCore/QObject> #include <QtCore/QTemporaryDir> +#include <QtCore/QStringList> class tst_QMimeDatabase : public QObject { @@ -92,9 +93,8 @@ private: QString m_globalXdgDir; QString m_localMimeDir; - QString m_yastMimeTypes; - QString m_qmlAgainFileName; - QString m_textXObjCSrcFileName; + QStringList m_additionalMimeFileNames; + QStringList m_additionalMimeFilePaths; QTemporaryDir m_temporaryDir; QString m_testSuite; bool m_isUsingCacheProvider; diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index 60a4d749c9..5ec32b1d02 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -68,6 +68,7 @@ private slots: void incrementalFilterResults(); void qfutureSynchronizer(); void warnRace(); + void matchFlags(); }; void sleeper() @@ -930,5 +931,17 @@ void tst_QFutureWatcher::warnRace() future.waitForFinished(); } +void tst_QFutureWatcher::matchFlags() +{ + /* Regression test: expect a default watcher to be in the same state as a + * default future. */ + QFutureWatcher<int> watcher; + QFuture<int> future; + QCOMPARE(watcher.isStarted(), future.isStarted()); + QCOMPARE(watcher.isCanceled(), future.isCanceled()); + QCOMPARE(watcher.isFinished(), future.isFinished()); +} + + QTEST_MAIN(tst_QFutureWatcher) #include "tst_qfuturewatcher.moc" diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp index 105b8b45d8..105b8b45d8 100755..100644 --- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index a9f3dc19a2..571e8deb00 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -2170,6 +2170,7 @@ void tst_QDateTime::offsetFromUtc() // Offset constructor QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, 60 * 60); QCOMPARE(dt1.offsetFromUtc(), 60 * 60); + QVERIFY(dt1.timeZone().isValid()); dt1 = QDateTime(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, -60 * 60); QCOMPARE(dt1.offsetFromUtc(), -60 * 60); diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp index 2e829bb05e..d3ace40164 100644 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp @@ -204,6 +204,7 @@ private slots: void removeOneInt() const; void removeOneMovable() const; void removeOneComplex() const; + void reverseIterators() const; void startsWithInt() const; void startsWithMovable() const; void startsWithComplex() const; @@ -754,6 +755,21 @@ void tst_QLinkedList::removeOneComplex() const QCOMPARE(liveCount, Complex::getLiveCount()); } +void tst_QLinkedList::reverseIterators() const +{ + QLinkedList<int> l; + l << 1 << 2 << 3 << 4; + QLinkedList<int> lr = l; + std::reverse(lr.begin(), lr.end()); + const QLinkedList<int> &clr = lr; + QVERIFY(std::equal(l.begin(), l.end(), lr.rbegin())); + QVERIFY(std::equal(l.begin(), l.end(), lr.crbegin())); + QVERIFY(std::equal(l.begin(), l.end(), clr.rbegin())); + QVERIFY(std::equal(lr.rbegin(), lr.rend(), l.begin())); + QVERIFY(std::equal(lr.crbegin(), lr.crend(), l.begin())); + QVERIFY(std::equal(clr.rbegin(), clr.rend(), l.begin())); +} + template<typename T> void tst_QLinkedList::startsWith() const { diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index ed9c269b00..f8f368f51c 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -65,6 +65,7 @@ private slots: void begin(); void end(); void insert(); + void reverseIterators(); void setOperations(); void stlIterator(); void stlMutableIterator(); @@ -555,6 +556,21 @@ void tst_QSet::insert() } } +void tst_QSet::reverseIterators() +{ + QSet<int> s; + s << 1 << 17 << 61 << 127 << 911; + std::vector<int> v(s.begin(), s.end()); + std::reverse(v.begin(), v.end()); + const QSet<int> &cs = s; + QVERIFY(std::equal(v.begin(), v.end(), s.rbegin())); + QVERIFY(std::equal(v.begin(), v.end(), s.crbegin())); + QVERIFY(std::equal(v.begin(), v.end(), cs.rbegin())); + QVERIFY(std::equal(s.rbegin(), s.rend(), v.begin())); + QVERIFY(std::equal(s.crbegin(), s.crend(), v.begin())); + QVERIFY(std::equal(cs.rbegin(), cs.rend(), v.begin())); +} + void tst_QSet::setOperations() { QSet<QString> set1, set2; diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp index c3a615fdff..2128eeb164 100644 --- a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp @@ -641,6 +641,7 @@ namespace QTest { make.setProcessChannelMode(channelMode); static const char makes[] = + "jom.exe\0" //preferred for visual c++ or mingw "nmake.exe\0" //for visual c++ "mingw32-make.exe\0" //for mingw "gmake\0" diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index bc55d53a60..124829a11c 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -4989,6 +4989,22 @@ void tst_QString::operator_smaller() QVERIFY(QString("b") >= "a"); QVERIFY(QString("b") > "a"); + QVERIFY(QString("a") < QByteArray("b")); + QVERIFY(QString("a") <= QByteArray("b")); + QVERIFY(QString("a") <= QByteArray("a")); + QVERIFY(QString("a") == QByteArray("a")); + QVERIFY(QString("a") >= QByteArray("a")); + QVERIFY(QString("b") >= QByteArray("a")); + QVERIFY(QString("b") > QByteArray("a")); + + QVERIFY(QByteArray("a") < QString("b")); + QVERIFY(QByteArray("a") <= QString("b")); + QVERIFY(QByteArray("a") <= QString("a")); + QVERIFY(QByteArray("a") == QString("a")); + QVERIFY(QByteArray("a") >= QString("a")); + QVERIFY(QByteArray("b") >= QString("a")); + QVERIFY(QByteArray("b") > QString("a")); + QVERIFY(QLatin1String("a") < QString("b")); QVERIFY(QLatin1String("a") <= QString("b")); QVERIFY(QLatin1String("a") <= QString("a")); diff --git a/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro b/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro index 39e40600e3..e3a231060c 100644 --- a/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro +++ b/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro @@ -1,4 +1,5 @@ CONFIG += testcase +contains(QT_CONFIG, c++11):CONFIG += c++11 c++14 TARGET = tst_qversionnumber -QT = core-private testlib +QT = core testlib SOURCES = tst_qversionnumber.cpp diff --git a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp index b681f9829a..57fd5084be 100644 --- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp @@ -150,7 +150,11 @@ int tst_QDBusMarshall::fileDescriptorForTest() { if (!tempFile.isOpen()) { tempFile.setFileTemplate(QDir::tempPath() + "/qdbusmarshalltestXXXXXX.tmp"); - tempFile.open(); + if (!tempFile.open()) { + qWarning("%s: Cannot create temporary file: %s", Q_FUNC_INFO, + qPrintable(tempFile.errorString())); + return 0; + } } return tempFile.handle(); } diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp index 3f846d25d5..fbe9669cbb 100644 --- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp @@ -194,7 +194,7 @@ void tst_QImageReader::initTestCase() prefix = QFINDTESTDATA("images/"); if (prefix.isEmpty()) QFAIL("Can't find images directory!"); - QVERIFY(m_temporaryDir.isValid()); + QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString())); } void tst_QImageReader::cleanupTestCase() diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp index fe6d7493e4..51dfe66090 100644 --- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp @@ -416,7 +416,7 @@ void tst_QImageWriter::testCanWrite() { // check if canWrite won't leave an empty file QTemporaryDir dir; - QVERIFY(dir.isValid()); + QVERIFY2(dir.isValid(), qPrintable(dir.errorString())); QString fileName(dir.path() + QLatin1String("/001.garble")); QVERIFY(!QFileInfo(fileName).exists()); QImageWriter writer(fileName); @@ -524,7 +524,7 @@ void tst_QImageWriter::saveToTemporaryFile() { // 1) Via QImageWriter's API, with a standard temp file name QTemporaryFile file; - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QImageWriter writer(&file, "PNG"); if (writer.canWrite()) QVERIFY(writer.write(image)); @@ -538,7 +538,7 @@ void tst_QImageWriter::saveToTemporaryFile() { // 2) Via QImage's API, with a standard temp file name QTemporaryFile file; - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QVERIFY(image.save(&file, "PNG")); file.reset(); QImage tmp; @@ -548,7 +548,7 @@ void tst_QImageWriter::saveToTemporaryFile() { // 3) Via QImageWriter's API, with a named temp file QTemporaryFile file("tempXXXXXX"); - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QImageWriter writer(&file, "PNG"); QVERIFY(writer.write(image)); #if defined(Q_OS_WINCE) @@ -559,7 +559,7 @@ void tst_QImageWriter::saveToTemporaryFile() { // 4) Via QImage's API, with a named temp file QTemporaryFile file("tempXXXXXX"); - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QVERIFY(image.save(&file, "PNG")); file.reset(); QImage tmp; diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 7d47a4167d..b03a117f83 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -24,6 +24,8 @@ SUBDIRS=\ qopenglwindow \ qrasterwindow +win32:!wince*:!winrt: SUBDIRS += noqteventloop + !qtHaveModule(widgets): SUBDIRS -= \ qmouseevent_modal \ qtouchevent diff --git a/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro new file mode 100644 index 0000000000..de5715e147 --- /dev/null +++ b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_noqteventloop + +QT += core-private gui-private testlib + +SOURCES += tst_noqteventloop.cpp + +contains(QT_CONFIG,dynamicgl):win32:!wince*:!winrt: LIBS += -luser32 diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp new file mode 100644 index 0000000000..d21569dcc0 --- /dev/null +++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** 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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QEvent> +#include <QtCore/qthread.h> +#include <QtGui/qguiapplication.h> + +#include <QtCore/qt_windows.h> + +class tst_NoQtEventLoop : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanup(); + void consumeMouseEvents(); + +}; + +void tst_NoQtEventLoop::initTestCase() +{ +} + +void tst_NoQtEventLoop::cleanup() +{ +} + +class Window : public QWindow +{ +public: + Window(QWindow *parentWindow = 0) : QWindow(parentWindow) + { + } + + void reset() + { + m_received.clear(); + } + + bool event(QEvent *event) + { + m_received[event->type()]++; + return QWindow::event(event); + } + + int received(QEvent::Type type) + { + return m_received.value(type, 0); + } + + + QHash<QEvent::Type, int> m_received; +}; + +bool g_exit = false; + +extern "C" LRESULT QT_WIN_CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + if (message == WM_SHOWWINDOW && wParam == 0) + g_exit = true; + return DefWindowProc(hwnd, message, wParam, lParam); +} + +class TestThread : public QThread +{ + Q_OBJECT +public: + TestThread(HWND parentWnd, Window *childWindow) : QThread(), m_hwnd(parentWnd), m_childWindow(childWindow) { + m_screenW = ::GetSystemMetrics(SM_CXSCREEN); + m_screenH = ::GetSystemMetrics(SM_CYSCREEN); + } + + enum { + MouseClick, + MouseMove + }; + + void mouseInput(int command, const QPoint &p = QPoint()) + { + INPUT mouseEvent; + mouseEvent.type = INPUT_MOUSE; + MOUSEINPUT &mi = mouseEvent.mi; + mi.mouseData = 0; + mi.time = 0; + mi.dwExtraInfo = 0; + mi.dx = 0; + mi.dy = 0; + switch (command) { + case MouseClick: + mi.dwFlags = MOUSEEVENTF_LEFTDOWN; + ::SendInput(1, &mouseEvent, sizeof(INPUT)); + ::Sleep(50); + mi.dwFlags = MOUSEEVENTF_LEFTUP; + ::SendInput(1, &mouseEvent, sizeof(INPUT)); + break; + case MouseMove: + mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; + mi.dx = p.x() * 65536 / m_screenW; + mi.dy = p.y() * 65536 / m_screenH; + ::SendInput(1, &mouseEvent, sizeof(INPUT)); + break; + } + } + + void mouseClick() + { + mouseInput(MouseClick); + } + + void mouseMove(const QPoint &pt) + { + mouseInput(MouseMove, pt); + } + + + void run() { + struct ScopedCleanup + { + /* This is in order to ensure that the window is hidden when returning from run(), + regardless of the return point (e.g. with QTRY_COMPARE) */ + ScopedCleanup(HWND hwnd) : m_hwnd(hwnd) { } + ~ScopedCleanup() { + ::ShowWindow(m_hwnd, SW_HIDE); + } + HWND m_hwnd; + } cleanup(m_hwnd); + + m_testPassed = false; + POINT pt; + pt.x = 0; + pt.y = 0; + if (!::ClientToScreen(m_hwnd, &pt)) + return; + m_windowPos = QPoint(pt.x, pt.y); + + + // First activate the parent window (which will also activate the child window) + m_windowPos += QPoint(5,5); + mouseMove(m_windowPos); + ::Sleep(150); + mouseClick(); + + + + // At this point the windows are activated, no further events will be send to the QWindow + // if we click on the native parent HWND + m_childWindow->reset(); + ::Sleep(150); + mouseClick(); + ::Sleep(150); + + QTRY_COMPARE(m_childWindow->received(QEvent::MouseButtonPress) + m_childWindow->received(QEvent::MouseButtonRelease), 0); + + // Now click in the QWindow. The QWindow should receive those events. + m_windowPos.ry() += 50; + mouseMove(m_windowPos); + ::Sleep(150); + mouseClick(); + QTRY_COMPARE(m_childWindow->received(QEvent::MouseButtonPress), 1); + QTRY_COMPARE(m_childWindow->received(QEvent::MouseButtonRelease), 1); + + m_testPassed = true; + + // ScopedCleanup will hide the window here + // Once the native window is hidden, it will exit the event loop. + } + + bool passed() const { return m_testPassed; } + +private: + int m_screenW; + int m_screenH; + bool m_testPassed; + HWND m_hwnd; + Window *m_childWindow; + QPoint m_windowPos; + +}; + + +void tst_NoQtEventLoop::consumeMouseEvents() +{ + int argc = 1; + char *argv[] = {const_cast<char*>("test")}; + QGuiApplication app(argc, argv); + QString clsName(QStringLiteral("tst_NoQtEventLoop_WINDOW")); + const HINSTANCE appInstance = (HINSTANCE)GetModuleHandle(0); + WNDCLASSEX wc; + wc.cbSize = sizeof(WNDCLASSEX); + wc.style = CS_DBLCLKS | CS_OWNDC; // CS_SAVEBITS + wc.lpfnWndProc = wndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = appInstance; + wc.hIcon = 0; + wc.hIconSm = 0; + wc.hCursor = 0; + wc.hbrBackground = ::GetSysColorBrush(COLOR_BTNFACE /*COLOR_WINDOW*/); + wc.lpszMenuName = 0; + wc.lpszClassName = (wchar_t*)clsName.utf16(); + + ATOM atom = ::RegisterClassEx(&wc); + QVERIFY2(atom, "RegisterClassEx failed"); + + DWORD dwExStyle = WS_EX_APPWINDOW; + DWORD dwStyle = WS_CAPTION | WS_HSCROLL | WS_TABSTOP | WS_VISIBLE; + + HWND mainWnd = ::CreateWindowEx(dwExStyle, (wchar_t*)clsName.utf16(), TEXT("tst_NoQtEventLoop"), dwStyle, 100, 100, 300, 300, 0, NULL, appInstance, NULL); + QVERIFY2(mainWnd, "CreateWindowEx failed"); + + ::ShowWindow(mainWnd, SW_SHOW); + + Window *childWindow = new Window; + childWindow->setParent(QWindow::fromWinId((WId)mainWnd)); + childWindow->setGeometry(0, 50, 200, 200); + childWindow->show(); + + TestThread *testThread = new TestThread(mainWnd, childWindow); + connect(testThread, SIGNAL(finished()), testThread, SLOT(deleteLater())); + testThread->start(); + + // Our own message loop... + MSG msg; + while (::GetMessage(&msg, NULL, 0, 0) > 0) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + if (g_exit) + break; + } + + QCOMPARE(testThread->passed(), true); + +} + +#include <tst_noqteventloop.moc> + +QTEST_APPLESS_MAIN(tst_NoQtEventLoop) + diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 2c363e3d69..ea8f594f9c 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -60,6 +60,7 @@ class tst_QGuiApplication: public tst_QCoreApplication Q_OBJECT private slots: + void initTestCase(); void cleanup(); void displayName(); void desktopFileName(); @@ -85,6 +86,21 @@ private slots: void settableStyleHints(); // Needs to run last as it changes style hints. }; +void tst_QGuiApplication::initTestCase() +{ +#ifdef QT_QPA_DEFAULT_PLATFORM_NAME + if ((QString::compare(QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME), + QStringLiteral("eglfs"), Qt::CaseInsensitive) == 0) || + (QString::compare(QString::fromLatin1(qgetenv("QT_QPA_PLATFORM")), + QStringLiteral("eglfs"), Qt::CaseInsensitive) == 0)) { + // Set env variables to disable input and cursor because eglfs is single fullscreen window + // and trying to initialize input and cursor will crash test. + qputenv("QT_QPA_EGLFS_DISABLE_INPUT", "1"); + qputenv("QT_QPA_EGLFS_HIDECURSOR", "1"); + } +#endif +} + void tst_QGuiApplication::cleanup() { QVERIFY(QGuiApplication::allWindows().isEmpty()); diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 210939c7f0..1e7e858bed 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -5025,6 +5025,7 @@ void tst_QPainter::drawPolyline_data() QTest::newRow("basic") << (QVector<QPointF>() << QPointF(10, 10) << QPointF(20, 10) << QPointF(20, 20) << QPointF(10, 20)); QTest::newRow("clipped") << (QVector<QPointF>() << QPoint(-10, 100) << QPoint(-1, 100) << QPoint(-1, -2) << QPoint(100, -2) << QPoint(100, 40)); // QTBUG-31579 QTest::newRow("shortsegment") << (QVector<QPointF>() << QPoint(20, 100) << QPoint(20, 99) << QPoint(21, 99) << QPoint(21, 104)); // QTBUG-42398 + QTest::newRow("edge") << (QVector<QPointF>() << QPointF(4.5, 121.6) << QPointF(9.4, 150.9) << QPointF(14.2, 184.8) << QPointF(19.1, 130.4)); } void tst_QPainter::drawPolyline() @@ -5034,7 +5035,7 @@ void tst_QPainter::drawPolyline() for (int r = 0; r < 2; r++) { images[r] = QImage(150, 150, QImage::Format_ARGB32); - images[r].fill(Qt::transparent); + images[r].fill(Qt::white); QPainter p(images + r); QPen pen(Qt::red, 0, Qt::SolidLine, Qt::FlatCap); p.setPen(pen); diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp index 4bc31baba8..5eaee1192a 100644 --- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp +++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp @@ -50,8 +50,7 @@ private slots: void tst_QPdfWriter::basics() { QTemporaryFile file; - if (!file.open()) - QSKIP("Couldn't open temp file!"); + QVERIFY2(file.open(), qPrintable(file.errorString())); QPdfWriter writer(file.fileName()); QCOMPARE(writer.title(), QString()); @@ -150,8 +149,7 @@ void tst_QPdfWriter::testPageMetrics() QSizeF sizeMMf = QSizeF(widthMMf, heightMMf); QTemporaryFile file; - if (!file.open()) - QSKIP("Couldn't open temp file!"); + QVERIFY2(file.open(), qPrintable(file.errorString())); QPdfWriter writer(file.fileName()); QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait); diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index d8e9836112..ec62bafd6c 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -65,6 +65,7 @@ private slots: void inFontUcs4(); void lineWidth(); void mnemonicTextWidth(); + void leadingBelowLine(); }; tst_QFontMetrics::tst_QFontMetrics() @@ -343,5 +344,16 @@ void tst_QFontMetrics::mnemonicTextWidth() QCOMPARE(fm.size(Qt::TextShowMnemonic, f1), fm.size(Qt::TextShowMnemonic, f2)); QCOMPARE(fm.size(Qt::TextHideMnemonic, f1), fm.size(Qt::TextHideMnemonic, f2)); } + +void tst_QFontMetrics::leadingBelowLine() +{ + QScriptLine line; + line.leading = 10; + line.leadingIncluded = true; + line.ascent = 5; + QCOMPARE(line.height(), line.ascent + line.descent + line.leading); + QCOMPARE(line.base(), line.ascent); +} + QTEST_MAIN(tst_QFontMetrics) #include "tst_qfontmetrics.moc" diff --git a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp index c8964eb02c..db4b15530c 100644 --- a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp +++ b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp @@ -35,6 +35,7 @@ #include <QtTest/QtTest> #include <qdebug.h> #include <qdesktopservices.h> +#include <qregularexpression.h> class tst_qdesktopservices : public QObject { @@ -74,7 +75,9 @@ void tst_qdesktopservices::openUrl() QCOMPARE(QDesktopServices::openUrl(QUrl()), false); #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) // this test is only valid on windows on other systems it might mean open a new document in the application handling .file - QTest::ignoreMessage(QtWarningMsg, "ShellExecute 'file://invalid.file' failed (error 3)."); + const QRegularExpression messagePattern("ShellExecute 'file://invalid\\.file' failed \\(error \\d+\\)\\."); + QVERIFY(messagePattern.isValid()); + QTest::ignoreMessage(QtWarningMsg, messagePattern); QCOMPARE(QDesktopServices::openUrl(QUrl("file://invalid.file")), false); #endif } diff --git a/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp b/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp index 4cbdef2bbe..fd48ec3253 100644 --- a/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp +++ b/tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp @@ -294,6 +294,7 @@ void tst_QAbstractNetworkCache::runTest() QNetworkAccessManager manager; NetworkDiskCache *diskCache = new NetworkDiskCache(&manager); + QVERIFY2(diskCache->tempDir.isValid(), qPrintable(diskCache->tempDir.errorString())); manager.setCache(diskCache); QCOMPARE(diskCache->gotData, false); @@ -344,6 +345,7 @@ void tst_QAbstractNetworkCache::checkSynchronous() QNetworkAccessManager manager; NetworkDiskCache *diskCache = new NetworkDiskCache(&manager); + QVERIFY2(diskCache->tempDir.isValid(), qPrintable(diskCache->tempDir.errorString())); manager.setCache(diskCache); QCOMPARE(diskCache->gotData, false); @@ -392,6 +394,7 @@ void tst_QAbstractNetworkCache::deleteCache() { QNetworkAccessManager manager; NetworkDiskCache *diskCache = new NetworkDiskCache(&manager); + QVERIFY2(diskCache->tempDir.isValid(), qPrintable(diskCache->tempDir.errorString())); manager.setCache(diskCache); QString url = "httpcachetest_cachecontrol.cgi?max-age=1000"; diff --git a/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp index 5d072af6d5..0d188a8fec 100644 --- a/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp +++ b/tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp @@ -36,6 +36,7 @@ #include "private/qhttpnetworkconnection_p.h" #include "private/qnoncontiguousbytedevice_p.h" #include <QAuthenticator> +#include <QTcpServer> #include "../../../network-settings.h" @@ -106,6 +107,8 @@ private Q_SLOTS: void getAndThenDeleteObject(); void getAndThenDeleteObject_data(); + + void overlappingCloseAndWrite(); }; tst_QHttpNetworkConnection::tst_QHttpNetworkConnection() @@ -1112,6 +1115,57 @@ void tst_QHttpNetworkConnection::getAndThenDeleteObject() } } +class TestTcpServer : public QTcpServer +{ + Q_OBJECT +public: + TestTcpServer() : errorCodeReports(0) + { + connect(this, &QTcpServer::newConnection, this, &TestTcpServer::onNewConnection); + QVERIFY(listen(QHostAddress::LocalHost)); + } + + int errorCodeReports; + +public slots: + void onNewConnection() + { + QTcpSocket *socket = nextPendingConnection(); + if (!socket) + return; + // close socket instantly! + connect(socket, &QTcpSocket::readyRead, socket, &QTcpSocket::close); + } + + void onReply(QNetworkReply::NetworkError code) + { + QCOMPARE(code, QNetworkReply::RemoteHostClosedError); + ++errorCodeReports; + } +}; + +void tst_QHttpNetworkConnection::overlappingCloseAndWrite() +{ + // server accepts connections, but closes the socket instantly + TestTcpServer server; + QNetworkAccessManager accessManager; + + // ten requests are scheduled. All should result in an RemoteHostClosed... + QUrl url; + url.setScheme(QStringLiteral("http")); + url.setHost(server.serverAddress().toString()); + url.setPort(server.serverPort()); + for (int i = 0; i < 10; ++i) { + QNetworkRequest request(url); + QNetworkReply *reply = accessManager.get(request); + // Not using Qt5 connection syntax here because of overly baroque syntax to discern between + // different error() methods. + QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), + &server, SLOT(onReply(QNetworkReply::NetworkError))); + } + + QTRY_COMPARE(server.errorCodeReports, 10); +} QTEST_MAIN(tst_QHttpNetworkConnection) diff --git a/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp b/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp index b4e4b9ce0a..8ecb57dd33 100644 --- a/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp +++ b/tests/auto/network/access/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp @@ -74,6 +74,10 @@ void tst_QNetworkAccessManager::networkAccessible() // if there is no session, we cannot know in which state we are in QNetworkAccessManager::NetworkAccessibility initialAccessibility = manager.networkAccessible(); + + if (initialAccessibility == QNetworkAccessManager::UnknownAccessibility) + QSKIP("Unknown accessibility", SkipAll); + QCOMPARE(manager.networkAccessible(), initialAccessibility); manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible); @@ -94,29 +98,28 @@ void tst_QNetworkAccessManager::networkAccessible() QCOMPARE(manager.networkAccessible(), initialAccessibility); QNetworkConfigurationManager configManager; - bool sessionRequired = (configManager.capabilities() - & QNetworkConfigurationManager::NetworkSessionRequired); QNetworkConfiguration defaultConfig = configManager.defaultConfiguration(); if (defaultConfig.isValid()) { manager.setConfiguration(defaultConfig); - // the accessibility has not changed if no session is required - if (sessionRequired) { + QCOMPARE(spy.count(), 0); + + if (defaultConfig.state().testFlag(QNetworkConfiguration::Active)) + QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible); + else + QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible); + + manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible); + + if (defaultConfig.state().testFlag(QNetworkConfiguration::Active)) { QCOMPARE(spy.count(), 1); - QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(), - QNetworkAccessManager::Accessible); + QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()), + QNetworkAccessManager::NotAccessible); } else { QCOMPARE(spy.count(), 0); } - QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible); - - manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible); - - QCOMPARE(spy.count(), 1); - QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()), - QNetworkAccessManager::NotAccessible); - QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible); } + QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible); #endif } diff --git a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp index 708e7ebca8..1685838e9e 100644 --- a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp +++ b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp @@ -563,7 +563,7 @@ void tst_QNetworkDiskCache::oldCacheVersionFile() { QTemporaryFile file(cache.cacheDirectory() + "/XXXXXX.d"); file.setAutoRemove(false); - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QDataStream out(&file); out << qint32(0xe8); out << qint32(2); diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 6c919eb3f9..55e17b142a 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -1679,7 +1679,7 @@ void tst_QNetworkReply::getFromFile() // create the file: QTemporaryFile file(QDir::currentPath() + "/temp-XXXXXX"); file.setAutoRemove(true); - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QNetworkRequest request(QUrl::fromLocalFile(file.fileName())); QNetworkReplyPtr reply; @@ -3065,7 +3065,7 @@ void tst_QNetworkReply::ioGetFromFile() { QTemporaryFile file(QDir::currentPath() + "/temp-XXXXXX"); file.setAutoRemove(true); - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); QFETCH(QByteArray, data); QCOMPARE(file.write(data), data.size()); @@ -5353,7 +5353,7 @@ void tst_QNetworkReply::chaining() { QTemporaryFile sourceFile(QDir::currentPath() + "/temp-XXXXXX"); sourceFile.setAutoRemove(true); - QVERIFY(sourceFile.open()); + QVERIFY2(sourceFile.open(), qPrintable(sourceFile.errorString())); QFETCH(QByteArray, data); QCOMPARE(sourceFile.write(data), data.size()); @@ -7194,6 +7194,7 @@ void tst_QNetworkReply::qtbug28035browserDoesNotLoadQtProjectOrgCorrectly() { QByteArray postData = "ACT=100"; QTemporaryDir tempDir(QDir::tempPath() + "/tmp_cache_28035"); + QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); tempDir.setAutoRemove(true); QNetworkDiskCache *diskCache = new QNetworkDiskCache(); diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 09d9448e10..0ee3255502 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -115,10 +115,13 @@ private slots: void linkLocalIPv4(); void readyRead(); void readyReadForEmptyDatagram(); + void asyncReadDatagram(); + void writeInHostLookupState(); protected slots: void empty_readyReadSlot(); void empty_connectedSlot(); + void async_readDatagramSlot(); private: #ifndef QT_NO_BEARERMANAGEMENT @@ -126,6 +129,8 @@ private: QNetworkConfiguration networkConfiguration; QSharedPointer<QNetworkSession> networkSession; #endif + QUdpSocket *m_asyncSender; + QUdpSocket *m_asyncReceiver; }; static QHostAddress makeNonAny(const QHostAddress &address, QHostAddress::SpecialAddress preferForAny = QHostAddress::LocalHost) @@ -1670,5 +1675,67 @@ void tst_QUdpSocket::readyReadForEmptyDatagram() QCOMPARE(receiver.readDatagram(buf, sizeof buf), qint64(0)); } +void tst_QUdpSocket::async_readDatagramSlot() +{ + char buf[1]; + QVERIFY(m_asyncReceiver->hasPendingDatagrams()); + QCOMPARE(m_asyncReceiver->pendingDatagramSize(), qint64(1)); + QCOMPARE(m_asyncReceiver->bytesAvailable(), qint64(1)); + QCOMPARE(m_asyncReceiver->readDatagram(buf, sizeof(buf)), qint64(1)); + + if (buf[0] == '2') { + QTestEventLoop::instance().exitLoop(); + return; + } + + m_asyncSender->writeDatagram("2", makeNonAny(m_asyncReceiver->localAddress()), m_asyncReceiver->localPort()); + // wait a little to ensure that the datagram we've just sent + // will be delivered on receiver side. + QTest::qSleep(100); +} + +void tst_QUdpSocket::asyncReadDatagram() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + m_asyncSender = new QUdpSocket; + m_asyncReceiver = new QUdpSocket; +#ifdef FORCE_SESSION + m_asyncSender->setProperty("_q_networksession", QVariant::fromValue(networkSession)); + m_asyncReceiver->setProperty("_q_networksession", QVariant::fromValue(networkSession)); +#endif + + QVERIFY(m_asyncReceiver->bind(QHostAddress(QHostAddress::AnyIPv4), 0)); + quint16 port = m_asyncReceiver->localPort(); + QVERIFY(port != 0); + + QSignalSpy spy(m_asyncReceiver, SIGNAL(readyRead())); + connect(m_asyncReceiver, SIGNAL(readyRead()), SLOT(async_readDatagramSlot())); + + m_asyncSender->writeDatagram("1", makeNonAny(m_asyncReceiver->localAddress()), port); + + QTestEventLoop::instance().enterLoop(1); + + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(spy.count(), 2); + + delete m_asyncSender; + delete m_asyncReceiver; +} + +void tst_QUdpSocket::writeInHostLookupState() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + QUdpSocket socket; + socket.connectToHost("nosuchserver.qt-project.org", 80); + QCOMPARE(socket.state(), QUdpSocket::HostLookupState); + QVERIFY(!socket.putChar('0')); +} + QTEST_MAIN(tst_QUdpSocket) #include "tst_qudpsocket.moc" diff --git a/tests/auto/other/languagechange/tst_languagechange.cpp b/tests/auto/other/languagechange/tst_languagechange.cpp index 7658aaa8e0..493e279e18 100644 --- a/tests/auto/other/languagechange/tst_languagechange.cpp +++ b/tests/auto/other/languagechange/tst_languagechange.cpp @@ -276,7 +276,7 @@ void tst_languageChange::retranslatability() tempDirPattern += QStringLiteral("languagechangetestdirXXXXXX"); QTemporaryDir temporaryDir(tempDirPattern); temporaryDir.setAutoRemove(true); - QVERIFY(temporaryDir.isValid()); + QVERIFY2(temporaryDir.isValid(), qPrintable(temporaryDir.errorString())); const QString finalDir = temporaryDir.path() + QStringLiteral("/finaldir"); const QString fooName = temporaryDir.path() + QStringLiteral("/foo"); QDir dir; diff --git a/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro b/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro index 2ea54ab603..10d950541a 100644 --- a/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro +++ b/tests/auto/other/qaccessibilitylinux/qaccessibilitylinux.pro @@ -1,8 +1,5 @@ CONFIG += testcase -# This is temporary to start running the test as part of normal CI. -CONFIG += insignificant_test # QTBUG-27732 - include($$QT_SOURCE_TREE/src/platformsupport/accessibility/accessibility.pri) include($$QT_SOURCE_TREE/src/platformsupport/linuxaccessibility/linuxaccessibility.pri) diff --git a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp index 5f0eed5afe..4885a5f037 100644 --- a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp +++ b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp @@ -84,7 +84,15 @@ class tst_QAccessibilityLinux : public QObject Q_OBJECT public: - tst_QAccessibilityLinux() : m_window(0), root(0), rootApplication(0), mainWindow(0) {} + tst_QAccessibilityLinux() : m_window(0), root(0), rootApplication(0), mainWindow(0) + { + qputenv("QT_LINUX_ACCESSIBILITY_ALWAYS_ON", QByteArrayLiteral("1")); + dbus = new DBusConnection(); + } + ~tst_QAccessibilityLinux() + { + delete dbus; + } private slots: void initTestCase(); @@ -112,7 +120,7 @@ private: QDBusInterface *rootApplication; QDBusInterface *mainWindow; - DBusConnection dbus; + DBusConnection *dbus; }; // helper to find children of a dbus object @@ -149,7 +157,7 @@ QString tst_QAccessibilityLinux::getParent(QDBusInterface *interface) // helper to get dbus object QDBusInterface *tst_QAccessibilityLinux::getInterface(const QString &path, const QString &interfaceName) { - return new QDBusInterface(address, path, interfaceName, dbus.connection(), this); + return new QDBusInterface(address, path, interfaceName, dbus->connection(), this); } void tst_QAccessibilityLinux::initTestCase() @@ -158,14 +166,22 @@ void tst_QAccessibilityLinux::initTestCase() qApp->setStyle("fusion"); qApp->setApplicationName("tst_QAccessibilityLinux app"); - // Pretend we are a screen reader + + // trigger launching of at-spi if it isn't running already QDBusConnection c = QDBusConnection::sessionBus(); OrgA11yStatusInterface *a11yStatus = new OrgA11yStatusInterface(QStringLiteral("org.a11y.Bus"), QStringLiteral("/org/a11y/bus"), c, this); - a11yStatus->setScreenReaderEnabled(true); + // don't care about the result, calling any function on "org.a11y.Bus" will launch the service + a11yStatus->isEnabled(); + for (int i = 0; i < 5; ++i) { + if (!dbus->isEnabled()) + QTest::qWait(100); + } - QTRY_VERIFY(dbus.isEnabled()); - QTRY_VERIFY(dbus.connection().isConnected()); - address = dbus.connection().baseService().toLatin1().data(); + if (!dbus->isEnabled()) + QSKIP("Could not connect to AT-SPI, make sure lib atspi2 is installed."); + QTRY_VERIFY(dbus->isEnabled()); + QTRY_VERIFY(dbus->connection().isConnected()); + address = dbus->connection().baseService().toLatin1().data(); QVERIFY(!address.isEmpty()); m_window = new AccessibleTestWindow(); @@ -185,7 +201,7 @@ void tst_QAccessibilityLinux::cleanupTestCase() void tst_QAccessibilityLinux::registerDbus() { - QVERIFY(dbus.connection().isConnected()); + QVERIFY(dbus->connection().isConnected()); root = getInterface("/org/a11y/atspi/accessible/root", "org.a11y.atspi.Accessible"); diff --git a/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp b/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp index 53459b13f6..b79b3aba28 100644 --- a/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp +++ b/tests/auto/other/qprocess_and_guieventloop/tst_qprocess_and_guieventloop.cpp @@ -45,9 +45,11 @@ private slots: void tst_QProcess_and_GuiEventLoop::waitForAndEventLoop() { -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) +#if defined(QT_NO_PROCESS) + QSKIP("QProcess not supported"); +#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) QSKIP("Not supported on Android"); -#endif +#else // based on testcase provided in QTBUG-39488 QByteArray msg = "Hello World"; @@ -78,6 +80,7 @@ void tst_QProcess_and_GuiEventLoop::waitForAndEventLoop() QCOMPARE(process.exitCode(), 0); QCOMPARE(spy.count(), 1); QCOMPARE(process.readAll().trimmed(), msg); +#endif } QTEST_MAIN(tst_QProcess_and_GuiEventLoop) diff --git a/tests/auto/testlib/selftests/expected_crashes_3.txt b/tests/auto/testlib/selftests/expected_crashes_3.txt index 57c3ddc2ba..0e3f60dd1b 100644 --- a/tests/auto/testlib/selftests/expected_crashes_3.txt +++ b/tests/auto/testlib/selftests/expected_crashes_3.txt @@ -2,6 +2,7 @@ Config: Using QtTest library @INSERT_QT_VERSION_HERE@, Qt @INSERT_QT_VERSION_HERE@ PASS : tst_Crashes::initTestCase() QFATAL : tst_Crashes::crash() Received signal 11 + Function time: ms Total time: ms FAIL! : tst_Crashes::crash() Received a fatal error. Loc: [Unknown file(0)] Totals: 1 passed, 1 failed, 0 skipped, 0 blacklisted diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 42d929c4a1..63c48fc809 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -316,6 +316,7 @@ tst_Selftests::tst_Selftests() void tst_Selftests::initTestCase() { + QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); //Detect the location of the sub programs QString subProgram = QLatin1String("float/float"); #if defined(Q_OS_WIN) @@ -625,13 +626,28 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge for (int n = 0; n < loggers.count(); ++n) { QString logger = loggers[n]; -#if defined(Q_OS_WIN) - if (n == 0 && subdir == QLatin1String("crashes")) { // Remove stack trace which is output to stdout. - const int exceptionLogStart = actualOutputs.first().indexOf("A crash occurred in "); + if (n == 0 && subdir == QLatin1String("crashes")) { + QByteArray &actual = actualOutputs[0]; +#ifndef Q_OS_WIN + // Remove digits of times to match the expected file. + const QLatin1String timePattern("Function time:"); + int timePos = actual.indexOf(timePattern); + if (timePos >= 0) { + timePos += timePattern.size(); + const int nextLinePos = actual.indexOf('\n', timePos); + for (int c = (nextLinePos != -1 ? nextLinePos : actual.size()) - 1; c >= timePos; --c) { + if (actual.at(c) >= '0' && actual.at(c) <= '9') + actual.remove(c, 1); + } + } +#else // !Q_OS_WIN + // Remove stack trace which is output to stdout. + const int exceptionLogStart = actual.indexOf("A crash occurred in "); if (exceptionLogStart >= 0) - actualOutputs[0].truncate(exceptionLogStart); - } + actual.truncate(exceptionLogStart); #endif // Q_OS_WIN + } + QList<QByteArray> res = splitLines(actualOutputs[n]); const QString expectedFileName = expectedFileNameFromTest(subdir, logger); QList<QByteArray> exp = expectedResult(expectedFileName); diff --git a/tests/auto/tools/uic/tst_uic.cpp b/tests/auto/tools/uic/tst_uic.cpp index eac80bed7a..42c8e3e7b9 100644 --- a/tests/auto/tools/uic/tst_uic.cpp +++ b/tests/auto/tools/uic/tst_uic.cpp @@ -86,6 +86,7 @@ static QByteArray msgProcessStartFailed(const QString &command, const QString &w void tst_uic::initTestCase() { + QVERIFY2(m_generated.isValid(), qPrintable(m_generated.errorString())); QVERIFY(m_versionRegexp.isValid()); m_baseline = QFINDTESTDATA("baseline"); QVERIFY2(!m_baseline.isEmpty(), "Could not find 'baseline'."); diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index fbd368d077..16ff118a3f 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -483,11 +483,11 @@ void tst_QFiledialog::completer() if (startPath.isEmpty()) { tempDir.reset(new QTemporaryDir); - QVERIFY(tempDir->isValid()); + QVERIFY2(tempDir->isValid(), qPrintable(tempDir->errorString())); startPath = tempDir->path(); for (int i = 0; i < 10; ++i) { TemporaryFilePtr file(new QTemporaryFile(startPath + QStringLiteral("/rXXXXXX"))); - QVERIFY(file->open()); + QVERIFY2(file->open(), qPrintable(file->errorString())); files.append(file); } } @@ -889,7 +889,7 @@ void tst_QFiledialog::selectFile() QScopedPointer<QTemporaryFile> tempFile; if (file == QLatin1String("temp")) { tempFile.reset(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/aXXXXXX"))); - QVERIFY(tempFile->open()); + QVERIFY2(tempFile->open(), qPrintable(tempFile->errorString())); file = tempFile->fileName(); } @@ -927,7 +927,7 @@ void tst_QFiledialog::selectFileWrongCaseSaveAs() void tst_QFiledialog::selectFiles() { QTemporaryDir tempDir; - QVERIFY(tempDir.isValid()); + QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); const QString tempPath = tempDir.path(); { QNonNativeFileDialog fd; diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index 1e9cbe6578..cca150eb54 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -81,6 +81,12 @@ public: } }; +static QByteArray msgDoesNotExist(const QString &name) +{ + return (QLatin1Char('"') + QDir::toNativeSeparators(name) + + QLatin1String("\" does not exist.")).toLocal8Bit(); +} + class tst_QFileDialog2 : public QObject { Q_OBJECT @@ -171,7 +177,7 @@ void tst_QFileDialog2::cleanupSettingsFile() void tst_QFileDialog2::initTestCase() { - QVERIFY(tempDir.isValid()); + QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); QStandardPaths::setTestModeEnabled(true); cleanupSettingsFile(); } @@ -243,13 +249,13 @@ void tst_QFileDialog2::deleteDirAndFiles() QTemporaryFile *t; t = new QTemporaryFile(tempPath + "/foo/aXXXXXX"); t->setAutoRemove(false); - t->open(); + QVERIFY2(t->open(), qPrintable(t->errorString())); t->close(); delete t; t = new QTemporaryFile(tempPath + "/foo/B/yXXXXXX"); t->setAutoRemove(false); - t->open(); + QVERIFY2(t->open(), qPrintable(t->errorString())); t->close(); delete t; FriendlyQFileDialog fd; @@ -307,7 +313,7 @@ void tst_QFileDialog2::unc() #else QString dir(QDir::currentPath()); #endif - QVERIFY(QFile::exists(dir)); + QVERIFY2(QFile::exists(dir), msgDoesNotExist(dir).constData()); QNonNativeFileDialog fd(0, QString(), dir); QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model"); QVERIFY(model); @@ -849,7 +855,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting() current.mkdir("f"); current.mkdir("g"); QTemporaryFile *tempFile = new QTemporaryFile(current.absolutePath() + "/rXXXXXX"); - tempFile->open(); + QVERIFY2(tempFile->open(), qPrintable(tempFile->errorString())); current.cdUp(); QNonNativeFileDialog fd; @@ -1108,6 +1114,7 @@ void tst_QFileDialog2::task254490_selectFileMultipleTimes() QString tempPath = tempDir.path(); QTemporaryFile *t; t = new QTemporaryFile; + QVERIFY2(t->open(), qPrintable(t->errorString())); t->open(); QNonNativeFileDialog fd(0, "TestFileDialog"); @@ -1209,7 +1216,7 @@ void tst_QFileDialog2::QTBUG4419_lineEditSelectAll() { QString tempPath = tempDir.path(); QTemporaryFile temporaryFile(tempPath + "/tst_qfiledialog2_lineEditSelectAll.XXXXXX"); - QVERIFY(temporaryFile.open()); + QVERIFY2(temporaryFile.open(), qPrintable(temporaryFile.errorString())); QNonNativeFileDialog fd(0, "TestFileDialog", temporaryFile.fileName()); fd.setDirectory(tempPath); diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index bbe027fbc6..a70be695ef 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -173,7 +173,7 @@ void tst_QFileSystemModel::cleanup() void tst_QFileSystemModel::initTestCase() { - QVERIFY(m_tempDir.isValid()); + QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString())); flatDirTestPath = m_tempDir.path(); } @@ -318,7 +318,7 @@ void tst_QFileSystemModel::readOnly() { QCOMPARE(model->isReadOnly(), true); QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); - file.open(); + QVERIFY2(file.open(), qPrintable(file.errorString())); QModelIndex root = model->setRootPath(flatDirTestPath); QTRY_VERIFY(model->rowCount(root) > 0); @@ -819,7 +819,7 @@ void tst_QFileSystemModel::setData() void tst_QFileSystemModel::sortPersistentIndex() { QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); - file.open(); + QVERIFY2(file.open(), qPrintable(file.errorString())); QModelIndex root = model->setRootPath(flatDirTestPath); QTRY_VERIFY(model->rowCount(root) > 0); diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index f066f526eb..b7804da4ad 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -149,6 +149,7 @@ private slots: void spacing(); void testScrollToWithHidden(); void testViewOptions(); + void taskQTBUG_39902_mutualScrollBars_data(); void taskQTBUG_39902_mutualScrollBars(); void horizontalScrollingByVerticalWheelEvents(); }; @@ -2361,8 +2362,21 @@ private: QStyle* m_oldStyle; }; +void tst_QListView::taskQTBUG_39902_mutualScrollBars_data() +{ + QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode"); + QTest::newRow("per item / per item") << QAbstractItemView::ScrollPerItem << QAbstractItemView::ScrollPerItem; + QTest::newRow("per pixel / per item") << QAbstractItemView::ScrollPerPixel << QAbstractItemView::ScrollPerItem; + QTest::newRow("per item / per pixel") << QAbstractItemView::ScrollPerItem << QAbstractItemView::ScrollPerPixel; + QTest::newRow("per pixel / per pixel") << QAbstractItemView::ScrollPerPixel << QAbstractItemView::ScrollPerPixel; +} + void tst_QListView::taskQTBUG_39902_mutualScrollBars() { + QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode); + QWidget window; window.resize(400, 300); QListView *view = new QListView(&window); @@ -2374,6 +2388,9 @@ void tst_QListView::taskQTBUG_39902_mutualScrollBars() model.setData(model.index(i, 0), itemSize, Qt::SizeHintRole); view->setModel(&model); + view->setVerticalScrollMode(verticalScrollMode); + view->setHorizontalScrollMode(horizontalScrollMode); + window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); // make sure QListView is done with layouting the items (1/10 sec, like QListView) @@ -2414,7 +2431,7 @@ void tst_QListView::taskQTBUG_39902_mutualScrollBars() QTRY_VERIFY(view->horizontalScrollBar()->isVisible()); QTRY_VERIFY(view->verticalScrollBar()->isVisible()); - // now remove just one single pixel in with -> both scroll bars will show up since they depend on each other + // now remove just one single pixel in width -> both scroll bars will show up since they depend on each other view->resize(itemSize.width() + view->frameWidth() * 2 - 1, model.rowCount() * itemSize.height() + view->frameWidth() * 2); QTRY_VERIFY(view->horizontalScrollBar()->isVisible()); QTRY_VERIFY(view->verticalScrollBar()->isVisible()); @@ -2423,6 +2440,11 @@ void tst_QListView::taskQTBUG_39902_mutualScrollBars() view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2); QTRY_VERIFY(!view->horizontalScrollBar()->isVisible()); QTRY_VERIFY(!view->verticalScrollBar()->isVisible()); + + // now remove just one single pixel in height -> both scroll bars will show up since they depend on each other + view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2 - 1); + QTRY_VERIFY(view->horizontalScrollBar()->isVisible()); + QTRY_VERIFY(view->verticalScrollBar()->isVisible()); } void tst_QListView::horizontalScrollingByVerticalWheelEvents() diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index 6d2b2ea964..ea31fd19dd 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -94,6 +94,7 @@ private slots: void task262056_sortDuplicate(); void itemWithHeaderItems(); void mimeData(); + void selectedRowAfterSorting(); private: QTableWidget *testWidget; @@ -1565,5 +1566,23 @@ void tst_QTableWidget::mimeData() delete data2; } +void tst_QTableWidget::selectedRowAfterSorting() +{ + TestTableWidget table(3,3); + table.setSelectionBehavior(QAbstractItemView::SelectRows); + for (int r = 0; r < 3; r++) + for (int c = 0; c < 3; c++) + table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0"))); + QHeaderView *localHorizontalHeader = table.horizontalHeader(); + localHorizontalHeader->setSortIndicator(1,Qt::DescendingOrder); + table.setProperty("sortingEnabled",true); + table.selectRow(1); + table.item(1,1)->setText("9"); + QCOMPARE(table.selectedItems().count(),3); + foreach (QTableWidgetItem *item, table.selectedItems()) { + QCOMPARE(item->row(),0); + } +} + QTEST_MAIN(tst_QTableWidget) #include "tst_qtablewidget.moc" diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index 4bdb299213..5188dfbcfa 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -338,30 +338,30 @@ void tst_QWidget_window::tst_windowFilePath() void tst_QWidget_window::tst_showWithoutActivating() { -#ifndef Q_DEAD_CODE_FROM_QT4_X11 - QSKIP("This test is X11-only."); -#else - QWidget w; - w.show(); - QVERIFY(QTest::qWaitForWindowExposed(&w)); - QApplication::processEvents(); + QString platformName = QGuiApplication::platformName().toLower(); + if (platformName == "cocoa") + QSKIP("Cocoa: This fails. Figure out why."); + else if (platformName != QStringLiteral("xcb") + && platformName != QStringLiteral("windows") + && platformName != QStringLiteral("ios")) + QSKIP("Qt::WA_ShowWithoutActivating is currently supported only on xcb, windows, and ios platforms."); + + QWidget w1; + w1.setAttribute(Qt::WA_ShowWithoutActivating); + w1.show(); + QVERIFY(!QTest::qWaitForWindowActive(&w1)); + + QWidget w2; + w2.show(); + QVERIFY(QTest::qWaitForWindowActive(&w2)); + + QWidget w3; + w3.setAttribute(Qt::WA_ShowWithoutActivating); + w3.show(); + QVERIFY(!QTest::qWaitForWindowActive(&w3)); - QApplication::clipboard(); - QLineEdit *lineEdit = new QLineEdit; - lineEdit->setAttribute(Qt::WA_ShowWithoutActivating, true); - lineEdit->show(); - lineEdit->setAttribute(Qt::WA_ShowWithoutActivating, false); - lineEdit->raise(); - lineEdit->activateWindow(); - - Window window; - int revertto; - QTRY_COMPARE(lineEdit->winId(), - (XGetInputFocus(QX11Info::display(), &window, &revertto), window) ); - // Note the use of the , before window because we want the XGetInputFocus to be re-executed - // in each iteration of the inside loop of the QTRY_COMPARE macro - -#endif // Q_DEAD_CODE_FROM_QT4_X11 + w3.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&w3)); } void tst_QWidget_window::tst_paintEventOnSecondShow() diff --git a/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp b/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp index f19ef391ff..781adeedad 100644 --- a/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp +++ b/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp @@ -193,9 +193,7 @@ private slots: void deleteStack(); void checkSignals(); void addStackAndDie(); -#ifndef QT_NO_PROCESS void commandTextFormat(); -#endif }; tst_QUndoGroup::tst_QUndoGroup() @@ -599,9 +597,11 @@ void tst_QUndoGroup::addStackAndDie() delete stack; } -#ifndef QT_NO_PROCESS void tst_QUndoGroup::commandTextFormat() { +#ifdef QT_NO_PROCESS + QSKIP("No QProcess available"); +#else QString binDir = QLibraryInfo::location(QLibraryInfo::BinariesPath); if (QProcess::execute(binDir + "/lrelease -version") != 0) @@ -643,8 +643,8 @@ void tst_QUndoGroup::commandTextFormat() QCOMPARE(redo_action->text(), QString("redo-prefix append redo-suffix")); qApp->removeTranslator(&translator); -} #endif +} #else class tst_QUndoGroup : public QObject diff --git a/tests/auto/widgets/util/qundostack/tst_qundostack.cpp b/tests/auto/widgets/util/qundostack/tst_qundostack.cpp index 29bc14f372..2c8a9a3ee5 100644 --- a/tests/auto/widgets/util/qundostack/tst_qundostack.cpp +++ b/tests/auto/widgets/util/qundostack/tst_qundostack.cpp @@ -239,9 +239,7 @@ private slots: void macroBeginEnd(); void compression(); void undoLimit(); -#ifndef QT_NO_PROCESS void commandTextFormat(); -#endif void separateUndoText(); }; @@ -2958,9 +2956,11 @@ void tst_QUndoStack::undoLimit() true); // redoChanged } -#ifndef QT_NO_PROCESS void tst_QUndoStack::commandTextFormat() { +#ifdef QT_NO_PROCESS + QSKIP("No QProcess available"); +#else QString binDir = QLibraryInfo::location(QLibraryInfo::BinariesPath); if (QProcess::execute(binDir + "/lrelease -version") != 0) @@ -2999,8 +2999,8 @@ void tst_QUndoStack::commandTextFormat() QCOMPARE(redo_action->text(), QString("redo-prefix append redo-suffix")); qApp->removeTranslator(&translator); -} #endif +} void tst_QUndoStack::separateUndoText() { |