diff options
Diffstat (limited to 'tests/auto/corelib')
40 files changed, 651 insertions, 136 deletions
diff --git a/tests/auto/corelib/global/qglobal/qglobal.pro b/tests/auto/corelib/global/qglobal/qglobal.pro index b105769430..e4453affa5 100644 --- a/tests/auto/corelib/global/qglobal/qglobal.pro +++ b/tests/auto/corelib/global/qglobal/qglobal.pro @@ -2,4 +2,6 @@ CONFIG += testcase TARGET = tst_qglobal QT = core testlib SOURCES = tst_qglobal.cpp qglobal.c -contains(QT_CONFIG, c++1z): CONFIG += c++1z +qtConfig(c++11): CONFIG += c++11 +qtConfig(c++14): CONFIG += c++14 +qtConfig(c++1z): CONFIG += c++1z diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 5e5492de59..b33dec8a61 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -464,7 +464,7 @@ typedef int (Empty::*memFun) (); QCOMPARE(Q_ALIGNOF(type), size_t(alignment)); \ /* Compare to native operator for compilers that support it, otherwise... erm... check consistency! :-) */ \ - QCOMPARE(QT_EMULATED_ALIGNOF(type), Q_ALIGNOF(type)); \ + QCOMPARE(alignof(type), Q_ALIGNOF(type)); \ } while (false) /**/ @@ -517,7 +517,7 @@ void tst_QGlobal::qAlignOf() TEST_AlignOf_impl(AlignmentInStruct<double>, Q_ALIGNOF(AlignmentInStruct<qint64>)); // 32-bit x86 ABI, Clang disagrees with gcc -#if !defined(Q_PROCESSOR_X86_32) || !defined(Q_CC_CLANG) +#if !defined(Q_PROCESSOR_X86_32) || !defined(Q_CC_CLANG) || defined(Q_OS_ANDROID) TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(qint64)); #else TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(AlignmentInStruct<qint64>)); diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index 23507ec2e6..7dd2a46807 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -48,7 +48,9 @@ private slots: void defaultHandler(); void installMessageHandler(); +#if QT_DEPRECATED_SINCE(5, 0) void installMsgHandler(); +#endif void installBothHandler(); #ifdef QT_BUILD_INTERNAL @@ -112,7 +114,9 @@ void tst_qmessagehandler::initTestCase() void tst_qmessagehandler::cleanup() { +#if QT_DEPRECATED_SINCE(5, 0) qInstallMsgHandler(0); +#endif qInstallMessageHandler((QtMessageHandler)0); s_type = QtFatalMsg; s_file = 0; @@ -143,6 +147,7 @@ void tst_qmessagehandler::installMessageHandler() QCOMPARE((void*)myHandler, (void*)customMessageHandler); } +#if QT_DEPRECATED_SINCE(5, 0) void tst_qmessagehandler::installMsgHandler() { QtMsgHandler oldHandler = qInstallMsgHandler(customMsgHandler); @@ -158,6 +163,7 @@ void tst_qmessagehandler::installMsgHandler() QtMsgHandler myHandler = qInstallMsgHandler(oldHandler); QCOMPARE((void*)myHandler, (void*)customMsgHandler); } +#endif void tst_qmessagehandler::installBothHandler() { diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index f459f62c91..e6d2f10c16 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -28,7 +28,6 @@ #include <QTest> -#include <QtAlgorithms> #include <QFile> #include <QFileInfo> #include <QRandomGenerator> diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 4428be08d4..734694abeb 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1036,7 +1036,9 @@ void tst_QFileInfo::systemFiles() QCOMPARE(fi.metadataChangeTime(), fi.lastModified()); // On Windows, they're the same QVERIFY(fi.birthTime().isValid()); QVERIFY(fi.birthTime() <= fi.lastModified()); +#if QT_DEPRECATED_SINCE(5, 10) QCOMPARE(fi.created(), fi.birthTime()); // On Windows, they're the same +#endif } void tst_QFileInfo::compare_data() @@ -1261,7 +1263,7 @@ void tst_QFileInfo::fakeFileTimes_data() QTest::newRow("early") << QDateTime(QDate(1901, 12, 14), QTime(12, 0)); // QTBUG-12006 claims XP handled this (2010-Mar-26 8:46:10) wrong due to an MS API bug: - QTest::newRow("XP-bug") << QDateTime::fromTime_t(1269593170); + QTest::newRow("XP-bug") << QDateTime::fromSecsSinceEpoch(1269593170); } void tst_QFileInfo::fakeFileTimes() @@ -1915,7 +1917,8 @@ void tst_QFileInfo::owner() DWORD bufSize = 1024; if (GetUserNameW(usernameBuf, &bufSize)) { userName = QString::fromWCharArray(usernameBuf); - if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && IsUserAdmin()) { + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista + && IsUserAdmin()) { // Special case : If the user is a member of Administrators group, all files // created by the current user are owned by the Administrators group. LPLOCALGROUP_USERS_INFO_0 pBuf = NULL; @@ -2042,7 +2045,9 @@ static void stateCheck(const QFileInfo &info, const QString &dirname, const QStr QCOMPARE(info.permissions(), QFile::Permissions()); +#if QT_DEPRECATED_SINCE(5, 10) QVERIFY(!info.created().isValid()); +#endif QVERIFY(!info.birthTime().isValid()); QVERIFY(!info.metadataChangeTime().isValid()); QVERIFY(!info.lastRead().isValid()); diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index eeeb3bc6e2..8703b15dda 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -496,7 +496,7 @@ void tst_QLockFile::noPermissionsWindows() QSKIP("This test is for desktop Windows only"); #endif #ifdef Q_OS_WIN - if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS7) + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows7) QSKIP("This test requires at least Windows 7"); #endif if (const int p = processProperties()) { diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index e4ff3c2a08..e799369c8a 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -151,6 +151,13 @@ private slots: void failToStartEmptyArgs_data(); void failToStartEmptyArgs(); +#if QT_DEPRECATED_SINCE(5, 13) + void crashTest2_deprecated(); + void restartProcessDeadlock_deprecated(); + void waitForReadyReadInAReadyReadSlot_deprecated(); + void finishProcessBeforeReadingDone_deprecated(); +#endif + protected slots: void readFromProcess(); void exitLoopSlot(); @@ -187,12 +194,20 @@ void tst_QProcess::getSetCheck() QProcess obj1; // ProcessChannelMode QProcess::readChannelMode() // void QProcess::setProcessChannelMode(ProcessChannelMode) +#if QT_DEPRECATED_SINCE(5, 13) obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::SeparateChannels), obj1.readChannelMode()); obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::MergedChannels), obj1.readChannelMode()); obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::ForwardedChannels), obj1.readChannelMode()); +#endif + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels)); + QCOMPARE(QProcess::ProcessChannelMode(QProcess::SeparateChannels), obj1.processChannelMode()); + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels)); + QCOMPARE(QProcess::ProcessChannelMode(QProcess::MergedChannels), obj1.processChannelMode()); + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels)); + QCOMPARE(QProcess::ProcessChannelMode(QProcess::ForwardedChannels), obj1.processChannelMode()); // ProcessChannel QProcess::readChannel() // void QProcess::setReadChannel(ProcessChannel) @@ -335,12 +350,14 @@ void tst_QProcess::crashTest() qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); QSignalSpy spy(process.data(), &QProcess::errorOccurred); - QSignalSpy spy2(process.data(), static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy spy3(process.data(), static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy spy2(process.data(), static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy spy3(process.data(), static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy3.isValid()); +#endif QVERIFY(process->waitForFinished(30000)); @@ -348,10 +365,12 @@ void tst_QProcess::crashTest() 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); + QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(spy3.count(), 1); - QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy3.at(0).at(1).constData()), QProcess::CrashExit); + QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy3.at(0).at(0).constData()), QProcess::Crashed); +#endif QCOMPARE(process->exitStatus(), QProcess::CrashExit); @@ -379,7 +398,7 @@ void tst_QProcess::crashTest2() QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); - QObject::connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + QObject::connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &tst_QProcess::exitLoopSlot); QTestEventLoop::instance().enterLoop(30); @@ -645,9 +664,11 @@ void tst_QProcess::readTimeoutAndThenCrash() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QSignalSpy spy(&process, &QProcess::errorOccurred); - QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy.isValid()); +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy2.isValid()); +#endif process.kill(); @@ -656,8 +677,10 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(spy.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(spy2.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); +#endif } void tst_QProcess::waitForFinished() @@ -697,12 +720,11 @@ void tst_QProcess::deadWhileReading() 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 process; - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &tst_QProcess::restartProcess); process.start("testProcessEcho/testProcessEcho"); @@ -710,7 +732,7 @@ void tst_QProcess::restartProcessDeadlock() QCOMPARE(process.write("", 1), qlonglong(1)); QVERIFY(process.waitForFinished(5000)); - QObject::disconnect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), nullptr, nullptr); + QObject::disconnect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), nullptr, nullptr); QCOMPARE(process.write("", 1), qlonglong(1)); QVERIFY(process.waitForFinished(5000)); @@ -1027,7 +1049,7 @@ void tst_QProcess::mergedChannels() { QProcess process; process.setProcessChannelMode(QProcess::MergedChannels); - QCOMPARE(process.readChannelMode(), QProcess::MergedChannels); + QCOMPARE(process.processChannelMode(), QProcess::MergedChannels); process.start("testProcessEcho2/testProcessEcho2"); @@ -1155,7 +1177,7 @@ protected: exitCode = 90210; QProcess process; - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &TestThread::catchExitCode, Qt::DirectConnection); process.start("testProcessEcho/testProcessEcho"); @@ -1229,7 +1251,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() { QProcess process; connect(&process, &QIODevice::readyRead, this, &tst_QProcess::waitForReadyReadInAReadyReadSlotSlot); - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &tst_QProcess::exitLoopSlot); bytesAvailable = 0; @@ -1468,15 +1490,19 @@ void tst_QProcess::failToStart() QProcess process; QSignalSpy stateSpy(&process, &QProcess::stateChanged); QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(stateSpy.isValid()); QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); QVERIFY(finishedSpy2.isValid()); +#endif // OS X and HP-UX have a really low default process limit (~100), so spawning // to many processes here will cause test failures later on. @@ -1491,7 +1517,9 @@ void tst_QProcess::failToStart() for (int j = 0; j < 8; ++j) { for (int i = 0; i < attempts; ++i) { QCOMPARE(errorSpy.count(), j * attempts + i); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(errorSpy2.count(), j * attempts + i); +#endif process.start("/blurp"); switch (j) { @@ -1516,9 +1544,13 @@ void tst_QProcess::failToStart() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), j * attempts + i + 1); - QCOMPARE(errorSpy2.count(), j * attempts + i + 1); QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), j * attempts + i + 1); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy2.count(), 0); +#endif int it = j * attempts + i + 1; @@ -1537,14 +1569,18 @@ void tst_QProcess::failToStartWithWait() QProcess process; QEventLoop loop; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); QVERIFY(finishedSpy2.isValid()); +#endif for (int i = 0; i < 50; ++i) { process.start("/blurp", QStringList() << "-v" << "-debug"); @@ -1552,9 +1588,14 @@ void tst_QProcess::failToStartWithWait() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); - QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), i + 1); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy2.count(), 0); +#endif + } } @@ -1566,14 +1607,18 @@ void tst_QProcess::failToStartWithEventLoop() QProcess process; QEventLoop loop; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); QVERIFY(finishedSpy2.isValid()); +#endif // The error signal may be emitted before start() returns connect(&process, &QProcess::errorOccurred, &loop, &QEventLoop::quit, Qt::QueuedConnection); @@ -1586,9 +1631,13 @@ void tst_QProcess::failToStartWithEventLoop() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); - QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), i + 1); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy2.count(), 0); +#endif } } @@ -1606,8 +1655,12 @@ void tst_QProcess::failToStartEmptyArgs() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QProcess process; - QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::errorOccurred)); QVERIFY(errorSpy.isValid()); +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif switch (startOverload) { case 0: @@ -1625,6 +1678,9 @@ void tst_QProcess::failToStartEmptyArgs() QVERIFY(!process.waitForStarted()); QCOMPARE(errorSpy.count(), 1); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), 1); +#endif QCOMPARE(process.error(), QProcess::FailedToStart); } @@ -1856,24 +1912,32 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() QProcess process; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); + QVERIFY(errorSpy.isValid()); + QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QSignalSpy finishedSpy1(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - - QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy1.isValid()); - QVERIFY(finishedSpy2.isValid()); +#endif QVERIFY(!process.waitForReadyRead()); // used to crash process.start("doesntexist"); QVERIFY(!process.waitForReadyRead()); QCOMPARE(errorSpy.count(), 1); QCOMPARE(errorSpy.at(0).at(0).toInt(), 0); + QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(errorSpy2.count(), 1); QCOMPARE(errorSpy2.at(0).at(0).toInt(), 0); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy1.count(), 0); - QCOMPARE(finishedSpy2.count(), 0); +#endif } void tst_QProcess::setStandardInputFile() @@ -2304,14 +2368,18 @@ void tst_QProcess::invalidProgramString() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QSignalSpy spy(&process, &QProcess::errorOccurred); - QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy.isValid()); +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy2.isValid()); +#endif process.start(programString); QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(spy.count(), 1); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(spy2.count(), 1); +#endif QVERIFY(!QProcess::startDetached(programString)); } @@ -2365,7 +2433,7 @@ void tst_QProcess::finishProcessBeforeReadingDone() QProcess process; BlockOnReadStdOut blocker(&process); QEventLoop loop; - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), &loop, &QEventLoop::quit); process.start("testProcessOutput/testProcessOutput"); QVERIFY(process.waitForStarted()); @@ -2511,5 +2579,106 @@ void tst_QProcess::processEventsInAReadyReadSlot() QVERIFY(process.waitForFinished()); } +#if QT_DEPRECATED_SINCE(5, 13) + +void tst_QProcess::crashTest2_deprecated() +{ + 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<QProcessErrorSignal>(&QProcess::errorOccurred)); + QSignalSpy spy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); + + QVERIFY(spy.isValid()); + QVERIFY(spy2.isValid()); + + QObject::connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::exitLoopSlot); + + QTestEventLoop::instance().enterLoop(30); + if (QTestEventLoop::instance().timeout()) + QFAIL("Failed to detect crash : operation timed out"); + + 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::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit); + + QCOMPARE(process.exitStatus(), QProcess::CrashExit); +} + +void tst_QProcess::restartProcessDeadlock_deprecated() +{ + // 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 process; + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::restartProcess); + + process.start("testProcessEcho/testProcessEcho"); + + QCOMPARE(process.write("", 1), qlonglong(1)); + QVERIFY(process.waitForFinished(5000)); + + QObject::disconnect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), nullptr, nullptr); + + QCOMPARE(process.write("", 1), qlonglong(1)); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); +} + +void tst_QProcess::waitForReadyReadInAReadyReadSlot_deprecated() +{ + 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)); + + QSignalSpy spy(&process, &QProcess::readyRead); + QVERIFY(spy.isValid()); + process.write("foo"); + QTestEventLoop::instance().enterLoop(30); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(spy.count(), 1); + + process.disconnect(); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); + QVERIFY(process.bytesAvailable() > bytesAvailable); +} + +void tst_QProcess::finishProcessBeforeReadingDone_deprecated() +{ + QProcess process; + BlockOnReadStdOut blocker(&process); + QEventLoop loop; + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + &loop, &QEventLoop::quit); + process.start("testProcessOutput/testProcessOutput"); + QVERIFY(process.waitForStarted()); + loop.exec(); + QStringList lines = QString::fromLocal8Bit(process.readAllStandardOutput()).split( + 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); +} + +#endif + QTEST_MAIN(tst_QProcess) #include "tst_qprocess.moc" diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 0b50c391b8..df1dbebbf2 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -55,6 +55,10 @@ private slots: void checkStructure(); void searchPath_data(); void searchPath(); +#if QT_DEPRECATED_SINCE(5, 13) + void searchPath_deprecated_data(); + void searchPath_deprecated(); +#endif void doubleSlashInRoot(); void setLocale(); void lastModified(); @@ -420,6 +424,58 @@ void tst_QResourceEngine::checkStructure() void tst_QResourceEngine::searchPath_data() { + auto searchPath = QFileInfo(QFINDTESTDATA("testqrc")).canonicalFilePath(); + + QTest::addColumn<QString>("searchPathPrefix"); + QTest::addColumn<QString>("searchPath"); + QTest::addColumn<QString>("file"); + QTest::addColumn<QByteArray>("expected"); + + QTest::newRow("no_search_path") + << QString() + << QString() + << ":search_file.txt" + << QByteArray("root\n"); + QTest::newRow("path1") + << "searchpath1" + << searchPath + << "searchpath1:searchpath1/search_file.txt" + << QByteArray("path1\n"); + QTest::newRow("no_search_path2") + << QString() + << QString() + << ":/search_file.txt" + << QByteArray("root\n"); + QTest::newRow("path2") + << "searchpath2" + << searchPath + "/searchpath2" + << "searchpath2:search_file.txt" + << QByteArray("path2\n"); +} + +void tst_QResourceEngine::searchPath() +{ + QFETCH(QString, searchPathPrefix); + QFETCH(QString, searchPath); + QFETCH(QString, file); + QFETCH(QByteArray, expected); + + if (!searchPath.isEmpty()) + QDir::addSearchPath(searchPathPrefix, searchPath); + QFile qf(file); + QVERIFY(qf.open(QFile::ReadOnly)); + QByteArray actual = qf.readAll(); + + actual.replace('\r', ""); + + QCOMPARE(actual, expected); + qf.close(); +} + +#if QT_DEPRECATED_SINCE(5, 13) + +void tst_QResourceEngine::searchPath_deprecated_data() +{ QTest::addColumn<QString>("searchPath"); QTest::addColumn<QString>("file"); QTest::addColumn<QByteArray>("expected"); @@ -438,7 +494,7 @@ void tst_QResourceEngine::searchPath_data() << QByteArray("path2\n"); } -void tst_QResourceEngine::searchPath() +void tst_QResourceEngine::searchPath_deprecated() { QFETCH(QString, searchPath); QFETCH(QString, file); @@ -456,6 +512,8 @@ void tst_QResourceEngine::searchPath() qf.close(); } +#endif + void tst_QResourceEngine::checkUnregisterResource_data() { QTest::addColumn<QString>("rcc_file"); diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 8b69518ef7..a71a68e457 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -311,8 +311,11 @@ void tst_QSettings::initTestCase() void tst_QSettings::cleanupTestFiles() { - QSettings::setSystemIniPath(settingsPath("__system__")); - QSettings::setUserIniPath(settingsPath("__user__")); + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, settingsPath("__system__")); + QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, settingsPath("__system__")); + + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, settingsPath("__user__")); + QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, settingsPath("__user__")); QDir settingsDir(settingsPath()); if (settingsDir.exists()) diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index 67d8c55b04..00417fffa0 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -569,13 +569,7 @@ void tst_QTemporaryFile::rename() void tst_QTemporaryFile::renameFdLeak() { -#ifdef Q_OS_UNIX - -# if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) - ChdirOnReturn cor(QDir::currentPath()); - QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); -# endif - +#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) const QByteArray sourceFile = QFile::encodeName(QFINDTESTDATA(__FILE__)); QVERIFY(!sourceFile.isEmpty()); // Test this on Unix only diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 89a06b358e..026c6a6324 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -520,7 +520,7 @@ public slots: QVector<QtTestObject *> o5, QList<QtTestObject *> o6) { slotResult = QLatin1String("slotWithRegistrableArgument:") + o1->slotResult + o2->slotResult - + o3->slotResult + o4.data()->slotResult + QString::number(o5.size()) + + o3->slotResult + o4.toStrongRef()->slotResult + QString::number(o5.size()) + QString::number(o6.size()); } diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 28458c43c7..12c29a6e13 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1807,16 +1807,36 @@ void tst_QMetaType::automaticTemplateRegistration() QCOMPARE(extractedPtr.data()->objectName(), sp.data()->objectName()); \ } +#if QT_DEPRECATED_SINCE(5, 0) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QObject, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QFile, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QTemporaryFile, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, MyObject, WeakPointerToQObject, qWeakPointerFromVariant) +#endif TEST_NONOWNING_SMARTPOINTER(QPointer, QObject, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, QFile, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, QTemporaryFile, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, MyObject, TrackingPointerToQObject, qPointerFromVariant) #undef TEST_NONOWNING_SMARTPOINTER + + +#define TEST_WEAK_SMARTPOINTER(ELEMENT_TYPE, FLAG_TEST) \ + { \ + ELEMENT_TYPE elem; \ + QSharedPointer < ELEMENT_TYPE > shared(new ELEMENT_TYPE); \ + QWeakPointer < ELEMENT_TYPE > sp(shared); \ + sp.toStrongRef()->setObjectName("Test name"); \ + QVariant v = QVariant::fromValue(sp); \ + QCOMPARE(v.typeName(), "QWeakPointer<" #ELEMENT_TYPE ">"); \ + QVERIFY(QMetaType::typeFlags(::qMetaTypeId<QWeakPointer < ELEMENT_TYPE > >()) & QMetaType::FLAG_TEST); \ + } + + TEST_WEAK_SMARTPOINTER(QObject, WeakPointerToQObject) + TEST_WEAK_SMARTPOINTER(QFile, WeakPointerToQObject) + TEST_WEAK_SMARTPOINTER(QTemporaryFile, WeakPointerToQObject) + TEST_WEAK_SMARTPOINTER(MyObject, WeakPointerToQObject) +#undef TEST_WEAK_SMARTPOINTER } template <typename T> diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 7c9d8a476a..1778bf24bc 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -81,7 +81,9 @@ private slots: void senderTest(); void declareInterface(); void qpointerResetBeforeDestroyedSignal(); +#ifndef QT_NO_USERDATA void testUserData(); +#endif void childDeletesItsSibling(); void dynamicProperties(); void floatProperty(); @@ -2338,6 +2340,7 @@ void tst_QObject::declareInterface() } +#ifndef QT_NO_USERDATA class CustomData : public QObjectUserData { public: @@ -2380,6 +2383,7 @@ void tst_QObject::testUserData() QCOMPARE(data->id, id); } } +#endif // QT_NO_USERDATA class DestroyedListener : public QObject { diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index c75e4ef035..5d06f6e8c8 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -402,6 +402,8 @@ QT_WARNING_POP QVERIFY( var6.isNull() ); QVariant varLL( (qlonglong)0 ); QVERIFY( !varLL.isNull() ); + +#if QT_DEPRECATED_SINCE(5, 9) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED QVariant var7(QString::null); @@ -412,6 +414,7 @@ QT_WARNING_DISABLE_DEPRECATED var7 = QVariant::fromValue<QString>(QString::null); QT_WARNING_POP QVERIFY(var7.isNull()); +#endif QVariant var8(QMetaType::Nullptr, nullptr); QVERIFY(var8.isNull()); @@ -433,6 +436,9 @@ QT_WARNING_POP QVERIFY(var11.isNull()); QVERIFY(QVariant::fromValue<int*>(nullptr).isNull()); + + QVariant var12(QVariant::fromValue<QString>(QString())); + QVERIFY(var12.isNull()); } void tst_QVariant::swap() @@ -2871,6 +2877,7 @@ void tst_QVariant::qvariant_cast_QObject_wrapper() QVERIFY(spVar.canConvert<QObject*>()); QCOMPARE(f, spVar.value<QObject*>()); } +#if QT_DEPRECATED_SINCE(5, 0) { QFile *f = new QFile(this); QT_WARNING_PUSH @@ -2881,6 +2888,15 @@ QT_WARNING_POP QVERIFY(spVar.canConvert<QObject*>()); QCOMPARE(f, spVar.value<QObject*>()); } +#endif + { + QFile *f = new QFile(this); + QSharedPointer<QObject> sp(f); + QWeakPointer<QObject> wp = sp; + QVariant wpVar = QVariant::fromValue(wp); + QVERIFY(wpVar.canConvert<QObject*>()); + QCOMPARE(f, wpVar.value<QObject*>()); + } { QFile *f = new QFile(this); QSharedPointer<QFile> sp(f); diff --git a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp index a290c012df..aa85a7c35b 100644 --- a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp +++ b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp @@ -41,7 +41,6 @@ class tst_QPlugin : public QObject Q_OBJECT QDir dir; - QString invalidPluginName; public: tst_QPlugin(); @@ -64,15 +63,14 @@ void tst_QPlugin::initTestCase() QVERIFY2(dir.exists(), qPrintable(QString::fromLatin1("Cannot find the 'plugins' directory starting from '%1'"). arg(QDir::toNativeSeparators(QDir::currentPath())))); - - const auto fileNames = dir.entryList({"*invalid*"}, QDir::Files); - if (!fileNames.isEmpty()) - invalidPluginName = dir.absoluteFilePath(fileNames.first()); } void tst_QPlugin::loadDebugPlugin() { const auto fileNames = dir.entryList(QStringList() << "*debug*", QDir::Files); + if (fileNames.isEmpty()) + QSKIP("No debug plugins found - skipping test"); + for (const QString &fileName : fileNames) { if (!QLibrary::isLibrary(fileName)) continue; @@ -100,6 +98,9 @@ void tst_QPlugin::loadDebugPlugin() void tst_QPlugin::loadReleasePlugin() { const auto fileNames = dir.entryList(QStringList() << "*release*", QDir::Files); + if (fileNames.isEmpty()) + QSKIP("No release plugins found - skipping test"); + for (const QString &fileName : fileNames) { if (!QLibrary::isLibrary(fileName)) continue; @@ -227,7 +228,13 @@ static qsizetype locateMetadata(const uchar *data, qsizetype len) void tst_QPlugin::scanInvalidPlugin() { - QVERIFY(!invalidPluginName.isEmpty()); + const auto fileNames = dir.entryList({"*invalid*"}, QDir::Files); + QString invalidPluginName; + if (fileNames.isEmpty()) + QSKIP("No invalid plugin found - skipping test"); + else + invalidPluginName = dir.absoluteFilePath(fileNames.first()); + // copy the file QFileInfo fn(invalidPluginName); diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index b06000d9c4..c4a366d7c6 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -549,7 +549,8 @@ void tst_QPluginLoader::staticPlugins() } QVERIFY(found); - QCOMPARE(metaData.value("version").toInt(), QT_VERSION); + // We don't store the patch release version anymore (since 5.13) + QCOMPARE(metaData.value("version").toInt() / 0x100, QT_VERSION / 0x100); QCOMPARE(metaData.value("IID").toString(), "SomeIID"); QCOMPARE(metaData.value("ExtraMetaData"), QJsonArray({ "StaticPlugin", "foo" })); QCOMPARE(metaData.value("URI").toString(), "qt.test.pluginloader.staticplugin"); diff --git a/tests/auto/corelib/thread/qfuture/qfuture.pro b/tests/auto/corelib/thread/qfuture/qfuture.pro index b1667760d6..1f21130af7 100644 --- a/tests/auto/corelib/thread/qfuture/qfuture.pro +++ b/tests/auto/corelib/thread/qfuture/qfuture.pro @@ -3,3 +3,4 @@ TARGET = tst_qfuture QT = core core-private testlib SOURCES = tst_qfuture.cpp DEFINES += QT_STRICT_ITERATORS +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 37c5874c02..749aa45916 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -69,7 +69,8 @@ private slots: static const int iterations = 100; QAtomicInt lockCount(0); -QMutex normalMutex, recursiveMutex(QMutex::Recursive); +QMutex normalMutex; +QRecursiveMutex recursiveMutex; QSemaphore testsTurn; QSemaphore threadsTurn; @@ -993,9 +994,9 @@ public: QMutex mutex; QWaitCondition cond; - QMutex &test_mutex; + QRecursiveMutex &test_mutex; - inline rmutex_Thread(QMutex &m) : test_mutex(m) { } + inline rmutex_Thread(QRecursiveMutex &m) : test_mutex(m) { } void run() { @@ -1024,7 +1025,7 @@ void tst_QMutex::lock_unlock_locked_tryLock() QMutex mutex; mutex_Thread thread(mutex); - QMutex rmutex(QMutex::Recursive); + QRecursiveMutex rmutex; rmutex_Thread rthread(rmutex); for (int i = 0; i < iterations; ++i) { diff --git a/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp b/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp index 67db5d1458..c83e186ca7 100644 --- a/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp +++ b/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp @@ -36,7 +36,7 @@ class tst_QMutexLockerThread : public QThread { public: - QMutex mutex; + QRecursiveMutex mutex; QSemaphore semaphore, testSemaphore; void waitForTest() @@ -45,10 +45,6 @@ public: testSemaphore.acquire(); } - tst_QMutexLockerThread() - : mutex(QMutex::Recursive) - { - } }; class tst_QMutexLocker : public QObject diff --git a/tests/auto/corelib/thread/qthread/BLACKLIST b/tests/auto/corelib/thread/qthread/BLACKLIST index d75249454f..ccf530362c 100644 --- a/tests/auto/corelib/thread/qthread/BLACKLIST +++ b/tests/auto/corelib/thread/qthread/BLACKLIST @@ -1,2 +1,4 @@ [wait3_slowDestructor] windows +[sleep] +windows ci diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index baec4a22a5..7be2f48758 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -110,6 +110,12 @@ private slots: enum { one_minute = 60 * 1000, five_minutes = 5 * one_minute }; +template <class Int> +static QString msgElapsed(Int elapsed) +{ + return QString::fromLatin1("elapsed: %1").arg(elapsed); +} + class SignalRecorder : public QObject { Q_OBJECT @@ -591,7 +597,7 @@ void tst_QThread::sleep() thread.interval = 2; thread.start(); QVERIFY(thread.wait(five_minutes)); - QVERIFY(thread.elapsed >= 2000); + QVERIFY2(thread.elapsed >= 2000, qPrintable(msgElapsed(thread.elapsed))); } void tst_QThread::msleep() @@ -602,9 +608,9 @@ void tst_QThread::msleep() thread.start(); QVERIFY(thread.wait(five_minutes)); #if defined (Q_OS_WIN) // May no longer be needed - QVERIFY(thread.elapsed >= 100); + QVERIFY2(thread.elapsed >= 100, qPrintable(msgElapsed(thread.elapsed))); #else - QVERIFY(thread.elapsed >= 120); + QVERIFY2(thread.elapsed >= 120, qPrintable(msgElapsed(thread.elapsed))); #endif } @@ -616,9 +622,9 @@ void tst_QThread::usleep() thread.start(); QVERIFY(thread.wait(five_minutes)); #if defined (Q_OS_WIN) // May no longer be needed - QVERIFY(thread.elapsed >= 100); + QVERIFY2(thread.elapsed >= 100, qPrintable(msgElapsed(thread.elapsed))); #else - QVERIFY(thread.elapsed >= 120); + QVERIFY2(thread.elapsed >= 120, qPrintable(msgElapsed(thread.elapsed))); #endif } @@ -1065,13 +1071,15 @@ void tst_QThread::wait2() timer.start(); QVERIFY(!thread.wait(Waiting_Thread::WaitTime)); qint64 elapsed = timer.elapsed(); // On Windows, we sometimes get (WaitTime - 9). - QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 10, qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); + QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 10, + qPrintable(msgElapsed(elapsed))); timer.start(); thread.cond1.wakeOne(); QVERIFY(thread.wait(/*Waiting_Thread::WaitTime * 1.4*/)); elapsed = timer.elapsed(); - QVERIFY2(elapsed - Waiting_Thread::WaitTime >= -1, qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); + QVERIFY2(elapsed - Waiting_Thread::WaitTime >= -1, + qPrintable(msgElapsed(elapsed))); } diff --git a/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp b/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp index d27884197a..3826fa148e 100644 --- a/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp +++ b/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp @@ -32,7 +32,7 @@ #include "qmutex.h" -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, onceInitializationMutex, (QMutex::Recursive)) +Q_GLOBAL_STATIC(QRecursiveMutex, onceInitializationMutex) enum QOnceExtra { MustRunCode = 0x01, diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 0ef494b229..73384c35f4 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -91,7 +91,7 @@ private slots: void negativeYear() const; void printNegativeYear() const; void roundtripGermanLocale() const; -#if QT_CONFIG(textdate) +#if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) void shortDayName() const; void standaloneShortDayName() const; void longDayName() const; @@ -1473,7 +1473,7 @@ void tst_QDate::roundtripGermanLocale() const theDateTime.fromString(theDateTime.toString(Qt::TextDate), Qt::TextDate); } -#if QT_CONFIG(textdate) +#if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) QT_WARNING_PUSH // the methods tested here are all deprecated QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 6f0aebb071..ac1b903aa1 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -61,6 +61,10 @@ private slots: void timeSpec(); void toSecsSinceEpoch_data(); void toSecsSinceEpoch(); +#if QT_DEPRECATED_SINCE(5, 8) + void toTime_t_data(); + void toTime_t(); +#endif void daylightSavingsTimeChange_data(); void daylightSavingsTimeChange(); void springForward_data(); @@ -147,6 +151,7 @@ private slots: void systemTimeZoneChange() const; void invalid() const; + void range() const; void macTypes(); @@ -1689,6 +1694,34 @@ void tst_QDateTime::toSecsSinceEpoch() QDateTime datetime = dt( dateTimeStr ); qint64 asSecsSinceEpoch = datetime.toSecsSinceEpoch(); + QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); + + QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch); + QCOMPARE(datetime, datetime2); +} + +#if QT_DEPRECATED_SINCE(5, 8) +void tst_QDateTime::toTime_t_data() +{ + QTest::addColumn<QString>("dateTimeStr"); + QTest::addColumn<bool>("res"); + + QTest::newRow( "data1" ) << str( 1800, 1, 1, 12, 0, 0 ) << false; + QTest::newRow( "data2" ) << str( 1969, 1, 1, 12, 0, 0 ) << false; + QTest::newRow( "data3" ) << str( 2002, 1, 1, 12, 0, 0 ) << true; + QTest::newRow( "data4" ) << str( 2002, 6, 1, 12, 0, 0 ) << true; + QTest::newRow( "data5" ) << QString("INVALID") << false; + QTest::newRow( "data6" ) << str( 2038, 1, 1, 12, 0, 0 ) << true; + QTest::newRow( "data7" ) << str( 2063, 4, 5, 12, 0, 0 ) << true; // the day of First Contact + QTest::newRow( "data8" ) << str( 2107, 1, 1, 12, 0, 0 ) + << bool( sizeof(uint) > 32 && sizeof(time_t) > 32 ); +} + +void tst_QDateTime::toTime_t() +{ + QFETCH( QString, dateTimeStr ); + QDateTime datetime = dt( dateTimeStr ); + uint asTime_t = datetime.toTime_t(); QFETCH( bool, res ); if (res) { @@ -1696,15 +1729,13 @@ void tst_QDateTime::toSecsSinceEpoch() } else { QVERIFY( asTime_t == (uint)-1 ); } - QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); if ( asTime_t != (uint) -1 ) { QDateTime datetime2 = QDateTime::fromTime_t( asTime_t ); QCOMPARE(datetime, datetime2); } - QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch); - QCOMPARE(datetime, datetime2); } +#endif void tst_QDateTime::daylightSavingsTimeChange_data() { @@ -2489,17 +2520,20 @@ void tst_QDateTime::fromString_LOCALE_ILDATE() void tst_QDateTime::fromStringToStringLocale_data() { + QTest::addColumn<QLocale>("locale"); QTest::addColumn<QDateTime>("dateTime"); - QTest::newRow("data0") << QDateTime(QDate(1999, 1, 18), QTime(11, 49, 00)); + QTest::newRow("frFR") << QLocale(QLocale::French, QLocale::France) << QDateTime(QDate(1999, 1, 18), QTime(11, 49, 00)); + QTest::newRow("spCO") << QLocale(QLocale::Spanish, QLocale::Colombia) << QDateTime(QDate(1999, 1, 18), QTime(11, 49, 00)); } void tst_QDateTime::fromStringToStringLocale() { + QFETCH(QLocale, locale); QFETCH(QDateTime, dateTime); QLocale def; - QLocale::setDefault(QLocale(QLocale::French, QLocale::France)); + QLocale::setDefault(locale); #define ROUNDTRIP(format) \ QCOMPARE(QDateTime::fromString(dateTime.toString(format), format), dateTime) @@ -3472,6 +3506,15 @@ void tst_QDateTime::invalid() const QCOMPARE(tzDate.timeSpec(), Qt::TimeZone); } +void tst_QDateTime::range() const +{ + using Bounds = std::numeric_limits<qint64>; + QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::min() + 1, Qt::UTC).date().year(), + int(QDateTime::YearRange::First)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::max() - 1, Qt::UTC).date().year(), + int(QDateTime::YearRange::Last)); +} + void tst_QDateTime::macTypes() { #ifndef Q_OS_MAC diff --git a/tests/auto/corelib/tools/collections/collections.pro b/tests/auto/corelib/tools/collections/collections.pro index 5c04515fa0..b074fa9338 100644 --- a/tests/auto/corelib/tools/collections/collections.pro +++ b/tests/auto/corelib/tools/collections/collections.pro @@ -5,3 +5,4 @@ QT = core testlib # This test does not work with strict iterators DEFINES -= QT_STRICT_ITERATORS +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index b911be3ffb..e79a4dba29 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -67,7 +67,6 @@ void foo() #include <algorithm> -#include "qalgorithms.h" #include "qbitarray.h" #include "qbytearray.h" #include "qcache.h" @@ -191,16 +190,6 @@ void tst_Collections::list() QVERIFY(list.size() == 6); QVERIFY(list.end() - list.begin() == list.size()); -#if !defined(Q_CC_MSVC) && !defined(Q_CC_SUN) - QVERIFY(std::binary_search(list.begin(), list.end(), 2) == true); - QVERIFY(std::binary_search(list.begin(), list.end(), 9) == false); -#endif - QVERIFY(qBinaryFind(list.begin(), list.end(), 2) == list.begin() + 1); - QVERIFY(qLowerBound(list.begin(), list.end(), 2) == list.begin() + 1); - QVERIFY(qUpperBound(list.begin(), list.end(), 2) == list.begin() + 2); - QVERIFY(qBinaryFind(list.begin(), list.end(), 9) == list.end()); - QVERIFY(qLowerBound(list.begin(), list.end(), 9) == list.end()); - QVERIFY(qUpperBound(list.begin(), list.end(), 9) == list.end()); { int sum = 0; QListIterator<int> i(list); @@ -996,16 +985,8 @@ void tst_Collections::vector() v.append(2); QVERIFY(*v.begin() == 2); v.prepend(1); - - v << 3 << 4 << 5 << 6; - QVERIFY(std::binary_search(v.begin(), v.end(), 2) == true); - QVERIFY(std::binary_search(v.begin(), v.end(), 9) == false); - QVERIFY(qBinaryFind(v.begin(), v.end(), 2) == v.begin() + 1); - QVERIFY(qLowerBound(v.begin(), v.end(), 2) == v.begin() + 1); - QVERIFY(qUpperBound(v.begin(), v.end(), 2) == v.begin() + 2); - QVERIFY(qBinaryFind(v.begin(), v.end(), 9) == v.end()); - QVERIFY(qLowerBound(v.begin(), v.end(), 9) == v.end()); - QVERIFY(qUpperBound(v.begin(), v.end(), 9) == v.end()); + QVERIFY(*v.begin() == 1); + QVERIFY(*(v.begin() + 1) == 2); v.clear(); v << 1 << 2 << 3; @@ -1370,7 +1351,7 @@ void tst_Collections::hash() { typedef QHash<QString, QString> Hash; Hash hash; - QString key; + QString key = QLatin1String(" "); for (int i = 0; i < 10; ++i) { key[0] = i + '0'; for (int j = 0; j < 10; ++j) { @@ -2013,13 +1994,17 @@ void tst_Collections::qstring() QString nonNull = ""; QVERIFY(null.left(10).isNull()); QVERIFY(null.mid(0).isNull()); + QVERIFY(null.isNull()); + QVERIFY(!nonNull.isNull()); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(null == QString::null); QVERIFY(QString::null == null); QVERIFY(nonNull != QString::null); QVERIFY(QString::null != nonNull); QVERIFY(null == nonNull); QVERIFY(QString::null == QString::null); +#endif QString fill = "123"; fill.fill('a'); diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp index 06db0e8546..18432e51a6 100644 --- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp @@ -48,6 +48,11 @@ class tst_QAlgorithms : public QObject { Q_OBJECT private slots: + void swap(); + void swap2(); + void convenienceAPI(); + +#if QT_DEPRECATED_SINCE(5, 2) void test_qLowerBound_data(); void test_qLowerBound(); void test_qUpperBound_data(); @@ -55,19 +60,23 @@ private slots: void test_qBinaryFind_data(); void test_qBinaryFind(); void qBinaryFindOneEntry(); - void swap(); - void swap2(); void sortEmptyList(); void sortedList(); void sortAPItest(); void stableSortTest(); void stableSortCorrectnessTest_data(); void stableSortCorrectnessTest(); - void convenienceAPI(); + void convenienceAPI_deprecated(); void qCountIterators() const; void qCountContainer() const; void binaryFindOnLargeContainer() const; +#if Q_TEST_PERFORMANCE + void performance(); +#endif + +#endif // QT_DEPRECATED_SINCE(5, 2) + void popCount08_data() { popCount_data_impl(sizeof(quint8 )); } void popCount16_data() { popCount_data_impl(sizeof(quint16)); } void popCount32_data() { popCount_data_impl(sizeof(quint32)); } @@ -96,9 +105,6 @@ private slots: void countLeading64() { countLeading_impl<quint64>(); } private: -#if Q_TEST_PERFORMANCE - void performance(); -#endif void popCount_data_impl(size_t sizeof_T_Int); template <typename T_Int> void popCount_impl(); @@ -112,6 +118,8 @@ private: void countLeading_impl(); }; +#if QT_DEPRECATED_SINCE(5, 2) + class TestInt { public: @@ -172,7 +180,7 @@ ResultSet testRun(ContainerType &container, Algorithm &algorithm, int millisecs) { TestInt::lessThanRefCount = 0; int count = 0; - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() < millisecs) { ++count; @@ -257,6 +265,8 @@ void testAlgorithm(Algorithm algorithm, QStringList &dataSetTypes) } #endif +#endif // QT_DEPRECATED_SINCE(5, 2) + void tst_QAlgorithms::swap() { { @@ -391,6 +401,17 @@ void tst_QAlgorithms::swap2() } } +void tst_QAlgorithms::convenienceAPI() +{ + // Compile-test for QAlgorithm convenience functions. + + QList<int *> pointerList; + qDeleteAll(pointerList); + qDeleteAll(pointerList.begin(), pointerList.end()); +} + +#if QT_DEPRECATED_SINCE(5, 2) + void tst_QAlgorithms::sortEmptyList() { // Only test if it crashes @@ -676,7 +697,7 @@ void tst_QAlgorithms::stableSortCorrectnessTest() QVERIFY(isSorted(sorted)); } -void tst_QAlgorithms::convenienceAPI() +void tst_QAlgorithms::convenienceAPI_deprecated() { // Compile-test for QAlgorithm convenience functions. QList<int> list, list2; @@ -716,10 +737,6 @@ void tst_QAlgorithms::convenienceAPI() qBinaryFind(list, 1); qBinaryFind(list.begin(), list.end(), 1); qBinaryFind(list.begin(), list.end(), 1, qLess<int>()); - - QList<int *> pointerList; - qDeleteAll(pointerList); - qDeleteAll(pointerList.begin(), pointerList.end()); } template <typename DataType> @@ -1041,6 +1058,8 @@ void tst_QAlgorithms::binaryFindOnLargeContainer() const QCOMPARE(foundIt.pos(), 1073987655); } +#endif // QT_DEPRECATED_SINCE(5, 2) + // alternative implementation of qPopulationCount for comparison: static Q_DECL_CONSTEXPR const uint bitsSetInNibble[] = { 0, 1, 1, 2, 1, 2, 2, 3, diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 7db7d71b1f..25e2f21d03 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -1625,6 +1625,18 @@ void tst_QArrayData::literals() QCOMPARE(const_(v)[i], char('A' + i)); QCOMPARE(const_(v)[10], char('\0')); } + + { + struct LiteralType { + int value; + Q_DECL_CONSTEXPR LiteralType(int v = 0) : value(v) {} + }; + + QArrayDataPointer<LiteralType> d = Q_ARRAY_LITERAL(LiteralType, LiteralType(0), LiteralType(1), LiteralType(2)); + QCOMPARE(d->size, 3); + for (int i = 0; i < 3; ++i) + QCOMPARE(d->data()[i].value, i); + } } // Variadic Q_ARRAY_LITERAL need to be available in the current configuration. diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp index b9bcecd607..513c811788 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp @@ -74,10 +74,12 @@ int main(int argc, char *argv[]) hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR")); hiddenOption.setFlags(QCommandLineOption::HiddenFromHelp); parser.addOption(hiddenOption); +#if QT_DEPRECATED_SINCE(5, 8) QCommandLineOption hiddenOption2(QStringList() << QStringLiteral("hidden2")); hiddenOption2.setDescription(QStringLiteral("NEITHER SHOULD THIS")); hiddenOption2.setHidden(true); parser.addOption(hiddenOption2); +#endif // This program supports different options depending on the "command" (first argument). // Call parse() to find out the positional arguments. diff --git a/tests/auto/corelib/tools/qhash/qhash.pro b/tests/auto/corelib/tools/qhash/qhash.pro index 79ffd4e9d1..e96c0d1bf1 100644 --- a/tests/auto/corelib/tools/qhash/qhash.pro +++ b/tests/auto/corelib/tools/qhash/qhash.pro @@ -2,3 +2,5 @@ CONFIG += testcase TARGET = tst_qhash QT = core testlib SOURCES = $$PWD/tst_qhash.cpp + +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index d70d488e96..f0aaad98bd 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -273,7 +273,7 @@ void tst_QHash::insert1() { typedef QHash<QString, QString> Hash; Hash hash; - QString key; + QString key = QLatin1String(" "); for (int i = 0; i < 10; ++i) { key[0] = i + '0'; for (int j = 0; j < 10; ++j) { diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp index 915a24a1f6..0418daf640 100644 --- a/tests/auto/corelib/tools/qline/tst_qline.cpp +++ b/tests/auto/corelib/tools/qline/tst_qline.cpp @@ -53,8 +53,10 @@ private slots: void testNormalVector(); void testNormalVector_data(); +#if QT_DEPRECATED_SINCE(5, 14) void testAngle(); void testAngle_data(); +#endif void testAngle2(); void testAngle2_data(); @@ -378,6 +380,7 @@ void tst_QLine::testNormalVector() QCOMPARE(n.dy(), qreal(nvy)); } +#if QT_DEPRECATED_SINCE(5, 14) void tst_QLine::testAngle_data() { QTest::addColumn<double>("xa1"); @@ -426,6 +429,7 @@ void tst_QLine::testAngle() double resultAngle = a.angle(b); QCOMPARE(qRound(resultAngle), qRound(angle)); } +#endif void tst_QLine::testAngle2_data() { diff --git a/tests/auto/corelib/tools/qmap/qmap.pro b/tests/auto/corelib/tools/qmap/qmap.pro index 27820a76c8..2cc772720d 100644 --- a/tests/auto/corelib/tools/qmap/qmap.pro +++ b/tests/auto/corelib/tools/qmap/qmap.pro @@ -2,3 +2,5 @@ CONFIG += testcase TARGET = tst_qmap QT = core testlib SOURCES = $$PWD/tst_qmap.cpp + +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/qset/qset.pro b/tests/auto/corelib/tools/qset/qset.pro index 10ae3307d1..d0c6337147 100644 --- a/tests/auto/corelib/tools/qset/qset.pro +++ b/tests/auto/corelib/tools/qset/qset.pro @@ -2,3 +2,5 @@ CONFIG += testcase TARGET = tst_qset QT = core testlib SOURCES = tst_qset.cpp + +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 187b73eeec..f3c647515a 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -75,8 +75,10 @@ private slots: void functionCallDownCast(); void upCast(); void qobjectWeakManagement(); +#if QT_DEPRECATED_SINCE(5, 0) void noSharedPointerFromWeakQObject(); void sharedPointerFromQObjectWithWeak(); +#endif void weakQObjectFromSharedPointer(); void objectCast(); void objectCastStdSharedPtr(); @@ -882,6 +884,78 @@ void tst_QSharedPointer::qobjectWeakManagement() QWeakPointer<QObject> weak; weak = QWeakPointer<QObject>(); QVERIFY(weak.isNull()); + QVERIFY(weak.toStrongRef().isNull()); + } + + { + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak(shared); + QVERIFY(!weak.isNull()); + QVERIFY(weak.toStrongRef() == obj); + + // now delete + shared.reset(); + QVERIFY(weak.isNull()); + } + safetyCheck(); + + { + // same, bit with operator= + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak; + weak = shared; + QVERIFY(!weak.isNull()); + QVERIFY(weak.toStrongRef() == obj); + + // now delete + shared.reset(); + QVERIFY(weak.isNull()); + } + safetyCheck(); + + { + // with two QWeakPointers + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak(shared); + + { + QWeakPointer<QObject> weak2(shared); + QVERIFY(!weak2.isNull()); + QVERIFY(weak == weak2); + } + QVERIFY(!weak.isNull()); + + shared.reset(); + QVERIFY(weak.isNull()); + } + safetyCheck(); + + { + // same, but delete the pointer while two QWeakPointers exist + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak(shared); + + { + QWeakPointer<QObject> weak2(shared); + QVERIFY(!weak2.isNull()); + + shared.reset(); + QVERIFY(weak.isNull()); + QVERIFY(weak2.isNull()); + } + QVERIFY(weak.isNull()); + } + safetyCheck(); + +#if QT_DEPRECATED_SINCE(5, 0) + { + QWeakPointer<QObject> weak; + weak = QWeakPointer<QObject>(); + QVERIFY(weak.isNull()); QVERIFY(!weak.data()); } @@ -972,8 +1046,10 @@ void tst_QSharedPointer::qobjectWeakManagement() QVERIFY(weak.isNull()); } safetyCheck(); +#endif } +#if QT_DEPRECATED_SINCE(5, 0) void tst_QSharedPointer::noSharedPointerFromWeakQObject() { // you're not allowed to create a QSharedPointer from an unmanaged QObject @@ -1007,18 +1083,32 @@ void tst_QSharedPointer::sharedPointerFromQObjectWithWeak() } QVERIFY(weak.isNull()); } +#endif void tst_QSharedPointer::weakQObjectFromSharedPointer() { - // this is the inverse of the above: you're allowed to create a QWeakPointer - // from a managed QObject - QSharedPointer<QObject> shared(new QObject); - QWeakPointer<QObject> weak = shared.data(); - QVERIFY(!weak.isNull()); +#if QT_DEPRECATED_SINCE(5, 0) + { + // this is the inverse of the above: you're allowed to create a QWeakPointer + // from a managed QObject + QSharedPointer<QObject> shared(new QObject); + QWeakPointer<QObject> weak = shared.data(); + QVERIFY(!weak.isNull()); - // delete: - shared.clear(); - QVERIFY(weak.isNull()); + // delete: + shared.clear(); + QVERIFY(weak.isNull()); + } +#endif + { + QSharedPointer<QObject> shared(new QObject); + QWeakPointer<QObject> weak = shared; + QVERIFY(!weak.isNull()); + + // delete: + shared.clear(); + QVERIFY(weak.isNull()); + } } void tst_QSharedPointer::objectCast() @@ -2376,6 +2466,7 @@ void tst_QSharedPointer::qvariantCast() // Intentionally does not compile. // QSharedPointer<int> sop = qSharedPointerFromVariant<int>(v); +#if QT_DEPRECATED_SINCE(5, 0) v = QVariant::fromValue(sp.toWeakRef()); { @@ -2419,6 +2510,7 @@ void tst_QSharedPointer::qvariantCast() QWeakPointer<QThread> other = qWeakPointerFromVariant<QThread>(v); QVERIFY(!other); } +#endif } class SomeClass : public QEnableSharedFromThis<SomeClass> diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 79f5a8c46d..e4aa00f500 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -521,7 +521,9 @@ private slots: void stringRef_local8Bit_data(); void stringRef_local8Bit(); void fromLatin1(); +#if QT_DEPRECATED_SINCE(5, 0) void fromAscii(); +#endif void fromUcs4(); void toUcs4(); void arg(); @@ -4284,9 +4286,9 @@ void tst_QString::fromLocal8Bit_data() //QTest::newRow("null5") << QByteArray() << 5 << QString(); //QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << -1 << QString(); //QTest::newRow("empty0") << QByteArray() << 0 << QString(); - //QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromAscii("\0abcd", 5); - //QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromAscii("ab"); - //QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromAscii("ab\0cd", 5); + //QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromLatin1("\0abcd", 5); + //QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromLatin1("ab"); + //QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromLatin1("ab\0cd", 5); } void tst_QString::fromLocal8Bit() @@ -4590,6 +4592,7 @@ void tst_QString::fromLatin1() QVERIFY(a.size() == 5); } +#if QT_DEPRECATED_SINCE(5, 0) void tst_QString::fromAscii() { QString a; @@ -4610,6 +4613,7 @@ void tst_QString::fromAscii() a = QString::fromAscii("\0abcd", 5); QVERIFY(a.size() == 5); } +#endif void tst_QString::fromUcs4() { diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp index 2b5aa8e98b..66d4744454 100644 --- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp @@ -259,6 +259,12 @@ void tst_QStringList::filter() list5 = list5.filter( QRegularExpression("[i]ll") ); list6 << "Bill Gates" << "Bill Clinton"; QCOMPARE( list5, list6 ); + + QStringList list7, list8; + list7 << "Bill Gates" << "Joe Blow" << "Bill Clinton"; + list7 = list7.filter( QStringView(QString("Bill")) ); + list8 << "Bill Gates" << "Bill Clinton"; + QCOMPARE( list7, list8 ); } void tst_QStringList::sort() @@ -316,6 +322,16 @@ void tst_QStringList::replaceInStrings() list10 << "Bill Clinton" << "Bill Gates"; list9.replaceInStrings( QRegularExpression("^(.*), (.*)$"), "\\2 \\1" ); QCOMPARE( list9, list10 ); + + QStringList list11, list12, list13, list14; + list11 << "alpha" << "beta" << "gamma" << "epsilon"; + list12 << "alpha" << "beta" << "gamma" << "epsilon"; + list13 << "alpha" << "beta" << "gamma" << "epsilon"; + list11.replaceInStrings( QStringView(QString("a")), QStringView(QString("o")) ); + list12.replaceInStrings( QStringView(QString("a")), QString("o") ); + list13.replaceInStrings( QString("a"), QStringView(QString("o")) ); + list14 << "olpho" << "beto" << "gommo" << "epsilon"; + QCOMPARE( list11, list12 ); } void tst_QStringList::contains() @@ -427,6 +443,7 @@ void tst_QStringList::join() const QCOMPARE(input.join(separator), expectedResult); QCOMPARE(input.join(QLatin1String(separator.toLatin1())), expectedResult); + QCOMPARE(input.join(QStringView(separator)), expectedResult); } void tst_QStringList::join_data() const diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp index 581e9152e6..6f01947131 100644 --- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp +++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp @@ -596,7 +596,10 @@ void tst_QStringRef::startsWith() QVERIFY(!ref.startsWith("C")); QVERIFY(!ref.startsWith("ABCDEF")); QVERIFY(ref.startsWith("")); + QVERIFY(ref.startsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null)); +#endif QVERIFY(ref.startsWith('A')); QVERIFY(ref.startsWith(QLatin1Char('A'))); QVERIFY(ref.startsWith(QChar('A'))); @@ -623,7 +626,10 @@ void tst_QStringRef::startsWith() QVERIFY(!ref.startsWith("c", Qt::CaseInsensitive)); QVERIFY(!ref.startsWith("abcdef", Qt::CaseInsensitive)); QVERIFY(ref.startsWith("", Qt::CaseInsensitive)); + QVERIFY(ref.startsWith(QString(), Qt::CaseInsensitive)); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null, Qt::CaseInsensitive)); +#endif QVERIFY(ref.startsWith('a', Qt::CaseInsensitive)); QVERIFY(ref.startsWith('A', Qt::CaseInsensitive)); QVERIFY(ref.startsWith(QLatin1Char('a'), Qt::CaseInsensitive)); @@ -656,7 +662,10 @@ void tst_QStringRef::startsWith() const QString a = QString::fromLatin1(""); CREATE_REF(a); QVERIFY(ref.startsWith("")); + QVERIFY(ref.startsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null)); +#endif QVERIFY(!ref.startsWith("ABC")); QVERIFY(ref.startsWith(QLatin1String(""))); @@ -670,7 +679,10 @@ void tst_QStringRef::startsWith() { const QStringRef ref; QVERIFY(!ref.startsWith("")); + QVERIFY(ref.startsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null)); +#endif QVERIFY(!ref.startsWith("ABC")); QVERIFY(!ref.startsWith(QLatin1String(""))); @@ -693,7 +705,10 @@ void tst_QStringRef::endsWith() QVERIFY(!ref.endsWith("C")); QVERIFY(!ref.endsWith("ABCDEF")); QVERIFY(ref.endsWith("")); + QVERIFY(ref.endsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null)); +#endif QVERIFY(ref.endsWith('B')); QVERIFY(ref.endsWith(QLatin1Char('B'))); QVERIFY(ref.endsWith(QChar('B'))); @@ -720,7 +735,10 @@ void tst_QStringRef::endsWith() QVERIFY(!ref.endsWith("c", Qt::CaseInsensitive)); QVERIFY(!ref.endsWith("abcdef", Qt::CaseInsensitive)); QVERIFY(ref.endsWith("", Qt::CaseInsensitive)); + QVERIFY(ref.endsWith(QString(), Qt::CaseInsensitive)); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null, Qt::CaseInsensitive)); +#endif QVERIFY(ref.endsWith('b', Qt::CaseInsensitive)); QVERIFY(ref.endsWith('B', Qt::CaseInsensitive)); QVERIFY(ref.endsWith(QLatin1Char('b'), Qt::CaseInsensitive)); @@ -754,7 +772,10 @@ void tst_QStringRef::endsWith() const QString a = QString::fromLatin1(""); CREATE_REF(a); QVERIFY(ref.endsWith("")); + QVERIFY(ref.endsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null)); +#endif QVERIFY(!ref.endsWith("ABC")); QVERIFY(!ref.endsWith(QLatin1Char(0))); QVERIFY(!ref.endsWith(QLatin1Char('x'))); @@ -768,7 +789,10 @@ void tst_QStringRef::endsWith() { QStringRef ref; QVERIFY(!ref.endsWith("")); + QVERIFY(ref.endsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null)); +#endif QVERIFY(!ref.endsWith("ABC")); QVERIFY(!ref.endsWith(QLatin1String(""))); diff --git a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp index 5467d438a3..a46011ff6c 100644 --- a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp +++ b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp @@ -192,7 +192,7 @@ static void doTestData(const QString &testString, const QList<int> &expectedBrea // test toPreviousBoundary() { QList<int> expectedBreakPositionsRev = expectedBreakPositions; - std::sort(expectedBreakPositionsRev.begin(), expectedBreakPositionsRev.end(), qGreater<int>()); + std::sort(expectedBreakPositionsRev.begin(), expectedBreakPositionsRev.end(), std::greater<int>()); QList<int> actualBreakPositions; boundaryFinder.toEnd(); @@ -539,6 +539,13 @@ void tst_QTextBoundaryFinder::sentenceBoundaries_manual_data() QTest::newRow("data3") << testString << expectedBreakPositions; } + { + QString testString(QString::fromUtf8("Doing TEST, doing another test.")); + QList<int> expectedBreakPositions; + expectedBreakPositions << 0 << 31; + + QTest::newRow("data4") << testString << expectedBreakPositions; + } } void tst_QTextBoundaryFinder::sentenceBoundaries_manual() diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index fff8c75a90..070c25368b 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -57,6 +57,7 @@ private slots: void initializeListComplex(); void insertMove(); void nonCopyable(); + void implicitDefaultCtor(); private: template<typename T> @@ -1078,5 +1079,11 @@ void tst_QVarLengthArray::nonCopyable() QVERIFY(ptr6 == vec.at(5).get()); } +void tst_QVarLengthArray::implicitDefaultCtor() +{ + QVarLengthArray<int> def = {}; + QCOMPARE(def.size(), 0); +} + QTEST_APPLESS_MAIN(tst_QVarLengthArray) #include "tst_qvarlengtharray.moc" |