Remove usages of deprecated APIs of corelib

- Replaced the usages of deprecated APIs of corelib by corresponding
  alternatives in the library code and documentation.

- Modified the tests to make them build when deprecated APIs disabled:
    * Made the the parts of the tests testing the deprecated APIs to
      be compiled conditionally, only when the corresponding methods are
      enabled.
    * If the test-case tests only the deprecated API, but not the
      corresponding replacement, added tests for the replacement.

Task-number: QTBUG-76491
Task-number: QTBUG-76539
Task-number: QTBUG-76541
Change-Id: I62ed4a5b530a965ec3f6502c6480808f938921aa
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Sona Kurazyan 2019-06-27 15:48:30 +02:00
parent 6061e6820b
commit 9b3e8b32f2
20 changed files with 499 additions and 72 deletions

View File

@ -269,7 +269,7 @@
\codeline \codeline
\snippet itemviews/stardelegate/main.cpp 4 \snippet itemviews/stardelegate/main.cpp 4
Notice the call to qVariantFromValue to convert a \c Notice the call to QVariant::fromValue to convert a \c
StarRating to a QVariant. StarRating to a QVariant.
\section1 Possible Extensions and Suggestions \section1 Possible Extensions and Suggestions

View File

@ -2048,8 +2048,8 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile,
QPixmap, which are part of Qt GUI. In other words, there is no QPixmap, which are part of Qt GUI. In other words, there is no
\c toColor(), \c toImage(), or \c toPixmap() functions in QVariant. \c toColor(), \c toImage(), or \c toPixmap() functions in QVariant.
Instead, you can use the QVariant::value() or the qVariantValue() Instead, you can use the QVariant::value() template function.
template function. For example: For example:
\snippet code/src_corelib_io_qsettings.cpp 0 \snippet code/src_corelib_io_qsettings.cpp 0

View File

@ -48,7 +48,9 @@ private slots:
void defaultHandler(); void defaultHandler();
void installMessageHandler(); void installMessageHandler();
#if QT_DEPRECATED_SINCE(5, 0)
void installMsgHandler(); void installMsgHandler();
#endif
void installBothHandler(); void installBothHandler();
#ifdef QT_BUILD_INTERNAL #ifdef QT_BUILD_INTERNAL
@ -112,7 +114,9 @@ void tst_qmessagehandler::initTestCase()
void tst_qmessagehandler::cleanup() void tst_qmessagehandler::cleanup()
{ {
#if QT_DEPRECATED_SINCE(5, 0)
qInstallMsgHandler(0); qInstallMsgHandler(0);
#endif
qInstallMessageHandler((QtMessageHandler)0); qInstallMessageHandler((QtMessageHandler)0);
s_type = QtFatalMsg; s_type = QtFatalMsg;
s_file = 0; s_file = 0;
@ -143,6 +147,7 @@ void tst_qmessagehandler::installMessageHandler()
QCOMPARE((void*)myHandler, (void*)customMessageHandler); QCOMPARE((void*)myHandler, (void*)customMessageHandler);
} }
#if QT_DEPRECATED_SINCE(5, 0)
void tst_qmessagehandler::installMsgHandler() void tst_qmessagehandler::installMsgHandler()
{ {
QtMsgHandler oldHandler = qInstallMsgHandler(customMsgHandler); QtMsgHandler oldHandler = qInstallMsgHandler(customMsgHandler);
@ -158,6 +163,7 @@ void tst_qmessagehandler::installMsgHandler()
QtMsgHandler myHandler = qInstallMsgHandler(oldHandler); QtMsgHandler myHandler = qInstallMsgHandler(oldHandler);
QCOMPARE((void*)myHandler, (void*)customMsgHandler); QCOMPARE((void*)myHandler, (void*)customMsgHandler);
} }
#endif
void tst_qmessagehandler::installBothHandler() void tst_qmessagehandler::installBothHandler()
{ {

View File

@ -1036,7 +1036,9 @@ void tst_QFileInfo::systemFiles()
QCOMPARE(fi.metadataChangeTime(), fi.lastModified()); // On Windows, they're the same QCOMPARE(fi.metadataChangeTime(), fi.lastModified()); // On Windows, they're the same
QVERIFY(fi.birthTime().isValid()); QVERIFY(fi.birthTime().isValid());
QVERIFY(fi.birthTime() <= fi.lastModified()); QVERIFY(fi.birthTime() <= fi.lastModified());
#if QT_DEPRECATED_SINCE(5, 10)
QCOMPARE(fi.created(), fi.birthTime()); // On Windows, they're the same QCOMPARE(fi.created(), fi.birthTime()); // On Windows, they're the same
#endif
} }
void tst_QFileInfo::compare_data() void tst_QFileInfo::compare_data()
@ -2042,7 +2044,9 @@ static void stateCheck(const QFileInfo &info, const QString &dirname, const QStr
QCOMPARE(info.permissions(), QFile::Permissions()); QCOMPARE(info.permissions(), QFile::Permissions());
#if QT_DEPRECATED_SINCE(5, 10)
QVERIFY(!info.created().isValid()); QVERIFY(!info.created().isValid());
#endif
QVERIFY(!info.birthTime().isValid()); QVERIFY(!info.birthTime().isValid());
QVERIFY(!info.metadataChangeTime().isValid()); QVERIFY(!info.metadataChangeTime().isValid());
QVERIFY(!info.lastRead().isValid()); QVERIFY(!info.lastRead().isValid());

View File

@ -151,6 +151,13 @@ private slots:
void failToStartEmptyArgs_data(); void failToStartEmptyArgs_data();
void failToStartEmptyArgs(); void failToStartEmptyArgs();
#if QT_DEPRECATED_SINCE(5, 13)
void crashTest2_deprecated();
void restartProcessDeadlock_deprecated();
void waitForReadyReadInAReadyReadSlot_deprecated();
void finishProcessBeforeReadingDone_deprecated();
#endif
protected slots: protected slots:
void readFromProcess(); void readFromProcess();
void exitLoopSlot(); void exitLoopSlot();
@ -187,12 +194,20 @@ void tst_QProcess::getSetCheck()
QProcess obj1; QProcess obj1;
// ProcessChannelMode QProcess::readChannelMode() // ProcessChannelMode QProcess::readChannelMode()
// void QProcess::setProcessChannelMode(ProcessChannelMode) // void QProcess::setProcessChannelMode(ProcessChannelMode)
#if QT_DEPRECATED_SINCE(5, 13)
obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels)); obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels));
QCOMPARE(QProcess::ProcessChannelMode(QProcess::SeparateChannels), obj1.readChannelMode()); QCOMPARE(QProcess::ProcessChannelMode(QProcess::SeparateChannels), obj1.readChannelMode());
obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels)); obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels));
QCOMPARE(QProcess::ProcessChannelMode(QProcess::MergedChannels), obj1.readChannelMode()); QCOMPARE(QProcess::ProcessChannelMode(QProcess::MergedChannels), obj1.readChannelMode());
obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels)); obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels));
QCOMPARE(QProcess::ProcessChannelMode(QProcess::ForwardedChannels), obj1.readChannelMode()); 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() // ProcessChannel QProcess::readChannel()
// void QProcess::setReadChannel(ProcessChannel) // void QProcess::setReadChannel(ProcessChannel)
@ -335,12 +350,14 @@ void tst_QProcess::crashTest()
qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
QSignalSpy spy(process.data(), &QProcess::errorOccurred); QSignalSpy spy(process.data(), &QProcess::errorOccurred);
QSignalSpy spy2(process.data(), static_cast<QProcessErrorSignal>(&QProcess::error)); QSignalSpy spy2(process.data(), static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QSignalSpy spy3(process.data(), static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
#if QT_DEPRECATED_SINCE(5, 6)
QSignalSpy spy3(process.data(), static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(spy3.isValid()); QVERIFY(spy3.isValid());
#endif
QVERIFY(process->waitForFinished(30000)); 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(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed);
QCOMPARE(spy2.count(), 1); 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(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); QCOMPARE(process->exitStatus(), QProcess::CrashExit);
@ -379,7 +398,7 @@ void tst_QProcess::crashTest2()
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
QObject::connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), QObject::connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished),
this, &tst_QProcess::exitLoopSlot); this, &tst_QProcess::exitLoopSlot);
QTestEventLoop::instance().enterLoop(30); QTestEventLoop::instance().enterLoop(30);
@ -645,9 +664,11 @@ void tst_QProcess::readTimeoutAndThenCrash()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
QSignalSpy spy(&process, &QProcess::errorOccurred); QSignalSpy spy(&process, &QProcess::errorOccurred);
QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
#if QT_DEPRECATED_SINCE(5, 6)
QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
#endif
process.kill(); process.kill();
@ -656,8 +677,10 @@ void tst_QProcess::readTimeoutAndThenCrash()
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); 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(spy2.count(), 1);
QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed);
#endif
} }
void tst_QProcess::waitForFinished() void tst_QProcess::waitForFinished()
@ -697,12 +720,11 @@ void tst_QProcess::deadWhileReading()
void tst_QProcess::restartProcessDeadlock() void tst_QProcess::restartProcessDeadlock()
{ {
// The purpose of this test is to detect whether restarting a // The purpose of this test is to detect whether restarting a
// process in the finished() connected slot causes a deadlock // process in the finished() connected slot causes a deadlock
// because of the way QProcessManager uses its locks. // because of the way QProcessManager uses its locks.
QProcess process; QProcess process;
connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished),
this, &tst_QProcess::restartProcess); this, &tst_QProcess::restartProcess);
process.start("testProcessEcho/testProcessEcho"); process.start("testProcessEcho/testProcessEcho");
@ -710,7 +732,7 @@ void tst_QProcess::restartProcessDeadlock()
QCOMPARE(process.write("", 1), qlonglong(1)); QCOMPARE(process.write("", 1), qlonglong(1));
QVERIFY(process.waitForFinished(5000)); 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)); QCOMPARE(process.write("", 1), qlonglong(1));
QVERIFY(process.waitForFinished(5000)); QVERIFY(process.waitForFinished(5000));
@ -1027,7 +1049,7 @@ void tst_QProcess::mergedChannels()
{ {
QProcess process; QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels); process.setProcessChannelMode(QProcess::MergedChannels);
QCOMPARE(process.readChannelMode(), QProcess::MergedChannels); QCOMPARE(process.processChannelMode(), QProcess::MergedChannels);
process.start("testProcessEcho2/testProcessEcho2"); process.start("testProcessEcho2/testProcessEcho2");
@ -1155,7 +1177,7 @@ protected:
exitCode = 90210; exitCode = 90210;
QProcess process; QProcess process;
connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished),
this, &TestThread::catchExitCode, Qt::DirectConnection); this, &TestThread::catchExitCode, Qt::DirectConnection);
process.start("testProcessEcho/testProcessEcho"); process.start("testProcessEcho/testProcessEcho");
@ -1229,7 +1251,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot()
{ {
QProcess process; QProcess process;
connect(&process, &QIODevice::readyRead, this, &tst_QProcess::waitForReadyReadInAReadyReadSlotSlot); 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); this, &tst_QProcess::exitLoopSlot);
bytesAvailable = 0; bytesAvailable = 0;
@ -1468,15 +1490,19 @@ void tst_QProcess::failToStart()
QProcess process; QProcess process;
QSignalSpy stateSpy(&process, &QProcess::stateChanged); QSignalSpy stateSpy(&process, &QProcess::stateChanged);
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(stateSpy.isValid()); QVERIFY(stateSpy.isValid());
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
QVERIFY(errorSpy2.isValid());
QVERIFY(finishedSpy.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()); QVERIFY(finishedSpy2.isValid());
#endif
// OS X and HP-UX have a really low default process limit (~100), so spawning // 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. // 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 j = 0; j < 8; ++j) {
for (int i = 0; i < attempts; ++i) { for (int i = 0; i < attempts; ++i) {
QCOMPARE(errorSpy.count(), j * attempts + i); QCOMPARE(errorSpy.count(), j * attempts + i);
#if QT_DEPRECATED_SINCE(5, 6)
QCOMPARE(errorSpy2.count(), j * attempts + i); QCOMPARE(errorSpy2.count(), j * attempts + i);
#endif
process.start("/blurp"); process.start("/blurp");
switch (j) { switch (j) {
@ -1516,9 +1544,13 @@ void tst_QProcess::failToStart()
QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(errorSpy.count(), j * attempts + i + 1); QCOMPARE(errorSpy.count(), j * attempts + i + 1);
QCOMPARE(errorSpy2.count(), j * attempts + i + 1);
QCOMPARE(finishedSpy.count(), 0); 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); QCOMPARE(finishedSpy2.count(), 0);
#endif
int it = j * attempts + i + 1; int it = j * attempts + i + 1;
@ -1537,14 +1569,18 @@ void tst_QProcess::failToStartWithWait()
QProcess process; QProcess process;
QEventLoop loop; QEventLoop loop;
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
QVERIFY(errorSpy2.isValid());
QVERIFY(finishedSpy.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()); QVERIFY(finishedSpy2.isValid());
#endif
for (int i = 0; i < 50; ++i) { for (int i = 0; i < 50; ++i) {
process.start("/blurp", QStringList() << "-v" << "-debug"); process.start("/blurp", QStringList() << "-v" << "-debug");
@ -1552,9 +1588,14 @@ void tst_QProcess::failToStartWithWait()
QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(errorSpy.count(), i + 1); QCOMPARE(errorSpy.count(), i + 1);
QCOMPARE(errorSpy2.count(), i + 1);
QCOMPARE(finishedSpy.count(), 0); 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); QCOMPARE(finishedSpy2.count(), 0);
#endif
} }
} }
@ -1566,14 +1607,18 @@ void tst_QProcess::failToStartWithEventLoop()
QProcess process; QProcess process;
QEventLoop loop; QEventLoop loop;
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
QVERIFY(errorSpy2.isValid());
QVERIFY(finishedSpy.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()); QVERIFY(finishedSpy2.isValid());
#endif
// The error signal may be emitted before start() returns // The error signal may be emitted before start() returns
connect(&process, &QProcess::errorOccurred, &loop, &QEventLoop::quit, Qt::QueuedConnection); connect(&process, &QProcess::errorOccurred, &loop, &QEventLoop::quit, Qt::QueuedConnection);
@ -1586,9 +1631,13 @@ void tst_QProcess::failToStartWithEventLoop()
QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(errorSpy.count(), i + 1); QCOMPARE(errorSpy.count(), i + 1);
QCOMPARE(errorSpy2.count(), i + 1);
QCOMPARE(finishedSpy.count(), 0); 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); QCOMPARE(finishedSpy2.count(), 0);
#endif
} }
} }
@ -1606,8 +1655,12 @@ void tst_QProcess::failToStartEmptyArgs()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
QProcess process; QProcess process;
QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::errorOccurred));
QVERIFY(errorSpy.isValid()); QVERIFY(errorSpy.isValid());
#if QT_DEPRECATED_SINCE(5, 6)
QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(errorSpy2.isValid());
#endif
switch (startOverload) { switch (startOverload) {
case 0: case 0:
@ -1625,6 +1678,9 @@ void tst_QProcess::failToStartEmptyArgs()
QVERIFY(!process.waitForStarted()); QVERIFY(!process.waitForStarted());
QCOMPARE(errorSpy.count(), 1); QCOMPARE(errorSpy.count(), 1);
#if QT_DEPRECATED_SINCE(5, 6)
QCOMPARE(errorSpy2.count(), 1);
#endif
QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(process.error(), QProcess::FailedToStart);
} }
@ -1856,24 +1912,32 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess()
QProcess process; QProcess process;
QSignalSpy errorSpy(&process, &QProcess::errorOccurred); QSignalSpy errorSpy(&process, &QProcess::errorOccurred);
QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QSignalSpy finishedSpy1(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished));
QVERIFY(errorSpy.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 finishedSpy1(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished));
QVERIFY(finishedSpy1.isValid()); QVERIFY(finishedSpy1.isValid());
QVERIFY(finishedSpy2.isValid()); #endif
QVERIFY(!process.waitForReadyRead()); // used to crash QVERIFY(!process.waitForReadyRead()); // used to crash
process.start("doesntexist"); process.start("doesntexist");
QVERIFY(!process.waitForReadyRead()); QVERIFY(!process.waitForReadyRead());
QCOMPARE(errorSpy.count(), 1); QCOMPARE(errorSpy.count(), 1);
QCOMPARE(errorSpy.at(0).at(0).toInt(), 0); QCOMPARE(errorSpy.at(0).at(0).toInt(), 0);
QCOMPARE(finishedSpy.count(), 0);
#if QT_DEPRECATED_SINCE(5, 6)
QCOMPARE(errorSpy2.count(), 1); QCOMPARE(errorSpy2.count(), 1);
QCOMPARE(errorSpy2.at(0).at(0).toInt(), 0); QCOMPARE(errorSpy2.at(0).at(0).toInt(), 0);
#endif
#if QT_DEPRECATED_SINCE(5, 13)
QCOMPARE(finishedSpy1.count(), 0); QCOMPARE(finishedSpy1.count(), 0);
QCOMPARE(finishedSpy2.count(), 0); #endif
} }
void tst_QProcess::setStandardInputFile() void tst_QProcess::setStandardInputFile()
@ -2304,14 +2368,18 @@ void tst_QProcess::invalidProgramString()
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
QSignalSpy spy(&process, &QProcess::errorOccurred); QSignalSpy spy(&process, &QProcess::errorOccurred);
QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(spy.isValid()); QVERIFY(spy.isValid());
#if QT_DEPRECATED_SINCE(5, 6)
QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error));
QVERIFY(spy2.isValid()); QVERIFY(spy2.isValid());
#endif
process.start(programString); process.start(programString);
QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(process.error(), QProcess::FailedToStart);
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
#if QT_DEPRECATED_SINCE(5, 6)
QCOMPARE(spy2.count(), 1); QCOMPARE(spy2.count(), 1);
#endif
QVERIFY(!QProcess::startDetached(programString)); QVERIFY(!QProcess::startDetached(programString));
} }
@ -2365,7 +2433,7 @@ void tst_QProcess::finishProcessBeforeReadingDone()
QProcess process; QProcess process;
BlockOnReadStdOut blocker(&process); BlockOnReadStdOut blocker(&process);
QEventLoop loop; QEventLoop loop;
connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished),
&loop, &QEventLoop::quit); &loop, &QEventLoop::quit);
process.start("testProcessOutput/testProcessOutput"); process.start("testProcessOutput/testProcessOutput");
QVERIFY(process.waitForStarted()); QVERIFY(process.waitForStarted());
@ -2511,5 +2579,106 @@ void tst_QProcess::processEventsInAReadyReadSlot()
QVERIFY(process.waitForFinished()); 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) QTEST_MAIN(tst_QProcess)
#include "tst_qprocess.moc" #include "tst_qprocess.moc"

View File

@ -55,6 +55,10 @@ private slots:
void checkStructure(); void checkStructure();
void searchPath_data(); void searchPath_data();
void searchPath(); void searchPath();
#if QT_DEPRECATED_SINCE(5, 13)
void searchPath_deprecated_data();
void searchPath_deprecated();
#endif
void doubleSlashInRoot(); void doubleSlashInRoot();
void setLocale(); void setLocale();
void lastModified(); void lastModified();
@ -419,6 +423,58 @@ void tst_QResourceEngine::checkStructure()
} }
void tst_QResourceEngine::searchPath_data() 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>("searchPath");
QTest::addColumn<QString>("file"); QTest::addColumn<QString>("file");
@ -438,7 +494,7 @@ void tst_QResourceEngine::searchPath_data()
<< QByteArray("path2\n"); << QByteArray("path2\n");
} }
void tst_QResourceEngine::searchPath() void tst_QResourceEngine::searchPath_deprecated()
{ {
QFETCH(QString, searchPath); QFETCH(QString, searchPath);
QFETCH(QString, file); QFETCH(QString, file);
@ -456,6 +512,8 @@ void tst_QResourceEngine::searchPath()
qf.close(); qf.close();
} }
#endif
void tst_QResourceEngine::checkUnregisterResource_data() void tst_QResourceEngine::checkUnregisterResource_data()
{ {
QTest::addColumn<QString>("rcc_file"); QTest::addColumn<QString>("rcc_file");

View File

@ -311,8 +311,11 @@ void tst_QSettings::initTestCase()
void tst_QSettings::cleanupTestFiles() void tst_QSettings::cleanupTestFiles()
{ {
QSettings::setSystemIniPath(settingsPath("__system__")); QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, settingsPath("__system__"));
QSettings::setUserIniPath(settingsPath("__user__")); 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()); QDir settingsDir(settingsPath());
if (settingsDir.exists()) if (settingsDir.exists())

View File

@ -520,7 +520,7 @@ public slots:
QVector<QtTestObject *> o5, QList<QtTestObject *> o6) QVector<QtTestObject *> o5, QList<QtTestObject *> o6)
{ {
slotResult = QLatin1String("slotWithRegistrableArgument:") + o1->slotResult + o2->slotResult 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()); + QString::number(o6.size());
} }

View File

@ -1807,16 +1807,36 @@ void tst_QMetaType::automaticTemplateRegistration()
QCOMPARE(extractedPtr.data()->objectName(), sp.data()->objectName()); \ QCOMPARE(extractedPtr.data()->objectName(), sp.data()->objectName()); \
} }
#if QT_DEPRECATED_SINCE(5, 0)
TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QObject, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QObject, WeakPointerToQObject, qWeakPointerFromVariant)
TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QFile, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QFile, WeakPointerToQObject, qWeakPointerFromVariant)
TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QTemporaryFile, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QTemporaryFile, WeakPointerToQObject, qWeakPointerFromVariant)
TEST_NONOWNING_SMARTPOINTER(QWeakPointer, MyObject, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, MyObject, WeakPointerToQObject, qWeakPointerFromVariant)
#endif
TEST_NONOWNING_SMARTPOINTER(QPointer, QObject, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, QObject, TrackingPointerToQObject, qPointerFromVariant)
TEST_NONOWNING_SMARTPOINTER(QPointer, QFile, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, QFile, TrackingPointerToQObject, qPointerFromVariant)
TEST_NONOWNING_SMARTPOINTER(QPointer, QTemporaryFile, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, QTemporaryFile, TrackingPointerToQObject, qPointerFromVariant)
TEST_NONOWNING_SMARTPOINTER(QPointer, MyObject, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, MyObject, TrackingPointerToQObject, qPointerFromVariant)
#undef TEST_NONOWNING_SMARTPOINTER #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> template <typename T>

View File

@ -402,6 +402,8 @@ QT_WARNING_POP
QVERIFY( var6.isNull() ); QVERIFY( var6.isNull() );
QVariant varLL( (qlonglong)0 ); QVariant varLL( (qlonglong)0 );
QVERIFY( !varLL.isNull() ); QVERIFY( !varLL.isNull() );
#if QT_DEPRECATED_SINCE(5, 9)
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_DEPRECATED
QVariant var7(QString::null); QVariant var7(QString::null);
@ -412,6 +414,7 @@ QT_WARNING_DISABLE_DEPRECATED
var7 = QVariant::fromValue<QString>(QString::null); var7 = QVariant::fromValue<QString>(QString::null);
QT_WARNING_POP QT_WARNING_POP
QVERIFY(var7.isNull()); QVERIFY(var7.isNull());
#endif
QVariant var8(QMetaType::Nullptr, nullptr); QVariant var8(QMetaType::Nullptr, nullptr);
QVERIFY(var8.isNull()); QVERIFY(var8.isNull());
@ -433,6 +436,9 @@ QT_WARNING_POP
QVERIFY(var11.isNull()); QVERIFY(var11.isNull());
QVERIFY(QVariant::fromValue<int*>(nullptr).isNull()); QVERIFY(QVariant::fromValue<int*>(nullptr).isNull());
QVariant var12(QVariant::fromValue<QString>(QString()));
QVERIFY(var12.isNull());
} }
void tst_QVariant::swap() void tst_QVariant::swap()
@ -2871,6 +2877,7 @@ void tst_QVariant::qvariant_cast_QObject_wrapper()
QVERIFY(spVar.canConvert<QObject*>()); QVERIFY(spVar.canConvert<QObject*>());
QCOMPARE(f, spVar.value<QObject*>()); QCOMPARE(f, spVar.value<QObject*>());
} }
#if QT_DEPRECATED_SINCE(5, 0)
{ {
QFile *f = new QFile(this); QFile *f = new QFile(this);
QT_WARNING_PUSH QT_WARNING_PUSH
@ -2881,6 +2888,15 @@ QT_WARNING_POP
QVERIFY(spVar.canConvert<QObject*>()); QVERIFY(spVar.canConvert<QObject*>());
QCOMPARE(f, spVar.value<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); QFile *f = new QFile(this);
QSharedPointer<QFile> sp(f); QSharedPointer<QFile> sp(f);

View File

@ -1994,13 +1994,17 @@ void tst_Collections::qstring()
QString nonNull = ""; QString nonNull = "";
QVERIFY(null.left(10).isNull()); QVERIFY(null.left(10).isNull());
QVERIFY(null.mid(0).isNull()); QVERIFY(null.mid(0).isNull());
QVERIFY(null.isNull());
QVERIFY(!nonNull.isNull());
#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(null == QString::null); QVERIFY(null == QString::null);
QVERIFY(QString::null == null); QVERIFY(QString::null == null);
QVERIFY(nonNull != QString::null); QVERIFY(nonNull != QString::null);
QVERIFY(QString::null != nonNull); QVERIFY(QString::null != nonNull);
QVERIFY(null == nonNull); QVERIFY(null == nonNull);
QVERIFY(QString::null == QString::null); QVERIFY(QString::null == QString::null);
#endif
QString fill = "123"; QString fill = "123";
fill.fill('a'); fill.fill('a');

View File

@ -48,6 +48,11 @@ class tst_QAlgorithms : public QObject
{ {
Q_OBJECT Q_OBJECT
private slots: private slots:
void swap();
void swap2();
void convenienceAPI();
#if QT_DEPRECATED_SINCE(5, 2)
void test_qLowerBound_data(); void test_qLowerBound_data();
void test_qLowerBound(); void test_qLowerBound();
void test_qUpperBound_data(); void test_qUpperBound_data();
@ -55,19 +60,23 @@ private slots:
void test_qBinaryFind_data(); void test_qBinaryFind_data();
void test_qBinaryFind(); void test_qBinaryFind();
void qBinaryFindOneEntry(); void qBinaryFindOneEntry();
void swap();
void swap2();
void sortEmptyList(); void sortEmptyList();
void sortedList(); void sortedList();
void sortAPItest(); void sortAPItest();
void stableSortTest(); void stableSortTest();
void stableSortCorrectnessTest_data(); void stableSortCorrectnessTest_data();
void stableSortCorrectnessTest(); void stableSortCorrectnessTest();
void convenienceAPI(); void convenienceAPI_deprecated();
void qCountIterators() const; void qCountIterators() const;
void qCountContainer() const; void qCountContainer() const;
void binaryFindOnLargeContainer() 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 popCount08_data() { popCount_data_impl(sizeof(quint8 )); }
void popCount16_data() { popCount_data_impl(sizeof(quint16)); } void popCount16_data() { popCount_data_impl(sizeof(quint16)); }
void popCount32_data() { popCount_data_impl(sizeof(quint32)); } void popCount32_data() { popCount_data_impl(sizeof(quint32)); }
@ -96,9 +105,6 @@ private slots:
void countLeading64() { countLeading_impl<quint64>(); } void countLeading64() { countLeading_impl<quint64>(); }
private: private:
#if Q_TEST_PERFORMANCE
void performance();
#endif
void popCount_data_impl(size_t sizeof_T_Int); void popCount_data_impl(size_t sizeof_T_Int);
template <typename T_Int> template <typename T_Int>
void popCount_impl(); void popCount_impl();
@ -112,6 +118,8 @@ private:
void countLeading_impl(); void countLeading_impl();
}; };
#if QT_DEPRECATED_SINCE(5, 2)
class TestInt class TestInt
{ {
public: public:
@ -257,6 +265,8 @@ void testAlgorithm(Algorithm algorithm, QStringList &dataSetTypes)
} }
#endif #endif
#endif // QT_DEPRECATED_SINCE(5, 2)
void tst_QAlgorithms::swap() 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() void tst_QAlgorithms::sortEmptyList()
{ {
// Only test if it crashes // Only test if it crashes
@ -676,7 +697,7 @@ void tst_QAlgorithms::stableSortCorrectnessTest()
QVERIFY(isSorted(sorted)); QVERIFY(isSorted(sorted));
} }
void tst_QAlgorithms::convenienceAPI() void tst_QAlgorithms::convenienceAPI_deprecated()
{ {
// Compile-test for QAlgorithm convenience functions. // Compile-test for QAlgorithm convenience functions.
QList<int> list, list2; QList<int> list, list2;
@ -716,10 +737,6 @@ void tst_QAlgorithms::convenienceAPI()
qBinaryFind(list, 1); qBinaryFind(list, 1);
qBinaryFind(list.begin(), list.end(), 1); qBinaryFind(list.begin(), list.end(), 1);
qBinaryFind(list.begin(), list.end(), 1, qLess<int>()); qBinaryFind(list.begin(), list.end(), 1, qLess<int>());
QList<int *> pointerList;
qDeleteAll(pointerList);
qDeleteAll(pointerList.begin(), pointerList.end());
} }
template <typename DataType> template <typename DataType>
@ -1041,6 +1058,8 @@ void tst_QAlgorithms::binaryFindOnLargeContainer() const
QCOMPARE(foundIt.pos(), 1073987655); QCOMPARE(foundIt.pos(), 1073987655);
} }
#endif // QT_DEPRECATED_SINCE(5, 2)
// alternative implementation of qPopulationCount for comparison: // alternative implementation of qPopulationCount for comparison:
static Q_DECL_CONSTEXPR const uint bitsSetInNibble[] = { static Q_DECL_CONSTEXPR const uint bitsSetInNibble[] = {
0, 1, 1, 2, 1, 2, 2, 3, 0, 1, 1, 2, 1, 2, 2, 3,

View File

@ -74,10 +74,12 @@ int main(int argc, char *argv[])
hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR")); hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR"));
hiddenOption.setFlags(QCommandLineOption::HiddenFromHelp); hiddenOption.setFlags(QCommandLineOption::HiddenFromHelp);
parser.addOption(hiddenOption); parser.addOption(hiddenOption);
#if QT_DEPRECATED_SINCE(5, 8)
QCommandLineOption hiddenOption2(QStringList() << QStringLiteral("hidden2")); QCommandLineOption hiddenOption2(QStringList() << QStringLiteral("hidden2"));
hiddenOption2.setDescription(QStringLiteral("NEITHER SHOULD THIS")); hiddenOption2.setDescription(QStringLiteral("NEITHER SHOULD THIS"));
hiddenOption2.setHidden(true); hiddenOption2.setHidden(true);
parser.addOption(hiddenOption2); parser.addOption(hiddenOption2);
#endif
// This program supports different options depending on the "command" (first argument). // This program supports different options depending on the "command" (first argument).
// Call parse() to find out the positional arguments. // Call parse() to find out the positional arguments.

View File

@ -53,8 +53,10 @@ private slots:
void testNormalVector(); void testNormalVector();
void testNormalVector_data(); void testNormalVector_data();
#if QT_DEPRECATED_SINCE(5, 14)
void testAngle(); void testAngle();
void testAngle_data(); void testAngle_data();
#endif
void testAngle2(); void testAngle2();
void testAngle2_data(); void testAngle2_data();
@ -378,6 +380,7 @@ void tst_QLine::testNormalVector()
QCOMPARE(n.dy(), qreal(nvy)); QCOMPARE(n.dy(), qreal(nvy));
} }
#if QT_DEPRECATED_SINCE(5, 14)
void tst_QLine::testAngle_data() void tst_QLine::testAngle_data()
{ {
QTest::addColumn<double>("xa1"); QTest::addColumn<double>("xa1");
@ -426,6 +429,7 @@ void tst_QLine::testAngle()
double resultAngle = a.angle(b); double resultAngle = a.angle(b);
QCOMPARE(qRound(resultAngle), qRound(angle)); QCOMPARE(qRound(resultAngle), qRound(angle));
} }
#endif
void tst_QLine::testAngle2_data() void tst_QLine::testAngle2_data()
{ {

View File

@ -75,8 +75,10 @@ private slots:
void functionCallDownCast(); void functionCallDownCast();
void upCast(); void upCast();
void qobjectWeakManagement(); void qobjectWeakManagement();
#if QT_DEPRECATED_SINCE(5, 0)
void noSharedPointerFromWeakQObject(); void noSharedPointerFromWeakQObject();
void sharedPointerFromQObjectWithWeak(); void sharedPointerFromQObjectWithWeak();
#endif
void weakQObjectFromSharedPointer(); void weakQObjectFromSharedPointer();
void objectCast(); void objectCast();
void objectCastStdSharedPtr(); void objectCastStdSharedPtr();
@ -878,6 +880,78 @@ class OtherObject: public QObject
void tst_QSharedPointer::qobjectWeakManagement() 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; QWeakPointer<QObject> weak;
weak = QWeakPointer<QObject>(); weak = QWeakPointer<QObject>();
@ -972,8 +1046,10 @@ void tst_QSharedPointer::qobjectWeakManagement()
QVERIFY(weak.isNull()); QVERIFY(weak.isNull());
} }
safetyCheck(); safetyCheck();
#endif
} }
#if QT_DEPRECATED_SINCE(5, 0)
void tst_QSharedPointer::noSharedPointerFromWeakQObject() void tst_QSharedPointer::noSharedPointerFromWeakQObject()
{ {
// you're not allowed to create a QSharedPointer from an unmanaged QObject // you're not allowed to create a QSharedPointer from an unmanaged QObject
@ -1007,18 +1083,32 @@ void tst_QSharedPointer::sharedPointerFromQObjectWithWeak()
} }
QVERIFY(weak.isNull()); QVERIFY(weak.isNull());
} }
#endif
void tst_QSharedPointer::weakQObjectFromSharedPointer() void tst_QSharedPointer::weakQObjectFromSharedPointer()
{ {
// this is the inverse of the above: you're allowed to create a QWeakPointer #if QT_DEPRECATED_SINCE(5, 0)
// from a managed QObject {
QSharedPointer<QObject> shared(new QObject); // this is the inverse of the above: you're allowed to create a QWeakPointer
QWeakPointer<QObject> weak = shared.data(); // from a managed QObject
QVERIFY(!weak.isNull()); QSharedPointer<QObject> shared(new QObject);
QWeakPointer<QObject> weak = shared.data();
QVERIFY(!weak.isNull());
// delete: // delete:
shared.clear(); shared.clear();
QVERIFY(weak.isNull()); 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() void tst_QSharedPointer::objectCast()
@ -2376,6 +2466,7 @@ void tst_QSharedPointer::qvariantCast()
// Intentionally does not compile. // Intentionally does not compile.
// QSharedPointer<int> sop = qSharedPointerFromVariant<int>(v); // QSharedPointer<int> sop = qSharedPointerFromVariant<int>(v);
#if QT_DEPRECATED_SINCE(5, 0)
v = QVariant::fromValue(sp.toWeakRef()); v = QVariant::fromValue(sp.toWeakRef());
{ {
@ -2419,6 +2510,7 @@ void tst_QSharedPointer::qvariantCast()
QWeakPointer<QThread> other = qWeakPointerFromVariant<QThread>(v); QWeakPointer<QThread> other = qWeakPointerFromVariant<QThread>(v);
QVERIFY(!other); QVERIFY(!other);
} }
#endif
} }
class SomeClass : public QEnableSharedFromThis<SomeClass> class SomeClass : public QEnableSharedFromThis<SomeClass>

View File

@ -521,7 +521,9 @@ private slots:
void stringRef_local8Bit_data(); void stringRef_local8Bit_data();
void stringRef_local8Bit(); void stringRef_local8Bit();
void fromLatin1(); void fromLatin1();
#if QT_DEPRECATED_SINCE(5, 0)
void fromAscii(); void fromAscii();
#endif
void fromUcs4(); void fromUcs4();
void toUcs4(); void toUcs4();
void arg(); void arg();
@ -4284,9 +4286,9 @@ void tst_QString::fromLocal8Bit_data()
//QTest::newRow("null5") << QByteArray() << 5 << QString(); //QTest::newRow("null5") << QByteArray() << 5 << QString();
//QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << -1 << QString(); //QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << -1 << QString();
//QTest::newRow("empty0") << QByteArray() << 0 << QString(); //QTest::newRow("empty0") << QByteArray() << 0 << QString();
//QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromAscii("\0abcd", 5); //QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromLatin1("\0abcd", 5);
//QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromAscii("ab"); //QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromLatin1("ab");
//QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromAscii("ab\0cd", 5); //QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromLatin1("ab\0cd", 5);
} }
void tst_QString::fromLocal8Bit() void tst_QString::fromLocal8Bit()
@ -4590,6 +4592,7 @@ void tst_QString::fromLatin1()
QVERIFY(a.size() == 5); QVERIFY(a.size() == 5);
} }
#if QT_DEPRECATED_SINCE(5, 0)
void tst_QString::fromAscii() void tst_QString::fromAscii()
{ {
QString a; QString a;
@ -4610,6 +4613,7 @@ void tst_QString::fromAscii()
a = QString::fromAscii("\0abcd", 5); a = QString::fromAscii("\0abcd", 5);
QVERIFY(a.size() == 5); QVERIFY(a.size() == 5);
} }
#endif
void tst_QString::fromUcs4() void tst_QString::fromUcs4()
{ {

View File

@ -596,7 +596,10 @@ void tst_QStringRef::startsWith()
QVERIFY(!ref.startsWith("C")); QVERIFY(!ref.startsWith("C"));
QVERIFY(!ref.startsWith("ABCDEF")); QVERIFY(!ref.startsWith("ABCDEF"));
QVERIFY(ref.startsWith("")); QVERIFY(ref.startsWith(""));
QVERIFY(ref.startsWith(QString()));
#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.startsWith(QString::null)); QVERIFY(ref.startsWith(QString::null));
#endif
QVERIFY(ref.startsWith('A')); QVERIFY(ref.startsWith('A'));
QVERIFY(ref.startsWith(QLatin1Char('A'))); QVERIFY(ref.startsWith(QLatin1Char('A')));
QVERIFY(ref.startsWith(QChar('A'))); QVERIFY(ref.startsWith(QChar('A')));
@ -623,7 +626,10 @@ void tst_QStringRef::startsWith()
QVERIFY(!ref.startsWith("c", Qt::CaseInsensitive)); QVERIFY(!ref.startsWith("c", Qt::CaseInsensitive));
QVERIFY(!ref.startsWith("abcdef", Qt::CaseInsensitive)); QVERIFY(!ref.startsWith("abcdef", Qt::CaseInsensitive));
QVERIFY(ref.startsWith("", 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)); QVERIFY(ref.startsWith(QString::null, Qt::CaseInsensitive));
#endif
QVERIFY(ref.startsWith('a', Qt::CaseInsensitive)); QVERIFY(ref.startsWith('a', Qt::CaseInsensitive));
QVERIFY(ref.startsWith('A', Qt::CaseInsensitive)); QVERIFY(ref.startsWith('A', Qt::CaseInsensitive));
QVERIFY(ref.startsWith(QLatin1Char('a'), Qt::CaseInsensitive)); QVERIFY(ref.startsWith(QLatin1Char('a'), Qt::CaseInsensitive));
@ -656,7 +662,10 @@ void tst_QStringRef::startsWith()
const QString a = QString::fromLatin1(""); const QString a = QString::fromLatin1("");
CREATE_REF(a); CREATE_REF(a);
QVERIFY(ref.startsWith("")); QVERIFY(ref.startsWith(""));
QVERIFY(ref.startsWith(QString()));
#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.startsWith(QString::null)); QVERIFY(ref.startsWith(QString::null));
#endif
QVERIFY(!ref.startsWith("ABC")); QVERIFY(!ref.startsWith("ABC"));
QVERIFY(ref.startsWith(QLatin1String(""))); QVERIFY(ref.startsWith(QLatin1String("")));
@ -670,7 +679,10 @@ void tst_QStringRef::startsWith()
{ {
const QStringRef ref; const QStringRef ref;
QVERIFY(!ref.startsWith("")); QVERIFY(!ref.startsWith(""));
QVERIFY(ref.startsWith(QString()));
#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.startsWith(QString::null)); QVERIFY(ref.startsWith(QString::null));
#endif
QVERIFY(!ref.startsWith("ABC")); QVERIFY(!ref.startsWith("ABC"));
QVERIFY(!ref.startsWith(QLatin1String(""))); QVERIFY(!ref.startsWith(QLatin1String("")));
@ -693,7 +705,10 @@ void tst_QStringRef::endsWith()
QVERIFY(!ref.endsWith("C")); QVERIFY(!ref.endsWith("C"));
QVERIFY(!ref.endsWith("ABCDEF")); QVERIFY(!ref.endsWith("ABCDEF"));
QVERIFY(ref.endsWith("")); QVERIFY(ref.endsWith(""));
QVERIFY(ref.endsWith(QString()));
#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.endsWith(QString::null)); QVERIFY(ref.endsWith(QString::null));
#endif
QVERIFY(ref.endsWith('B')); QVERIFY(ref.endsWith('B'));
QVERIFY(ref.endsWith(QLatin1Char('B'))); QVERIFY(ref.endsWith(QLatin1Char('B')));
QVERIFY(ref.endsWith(QChar('B'))); QVERIFY(ref.endsWith(QChar('B')));
@ -720,7 +735,10 @@ void tst_QStringRef::endsWith()
QVERIFY(!ref.endsWith("c", Qt::CaseInsensitive)); QVERIFY(!ref.endsWith("c", Qt::CaseInsensitive));
QVERIFY(!ref.endsWith("abcdef", Qt::CaseInsensitive)); QVERIFY(!ref.endsWith("abcdef", Qt::CaseInsensitive));
QVERIFY(ref.endsWith("", 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)); QVERIFY(ref.endsWith(QString::null, Qt::CaseInsensitive));
#endif
QVERIFY(ref.endsWith('b', Qt::CaseInsensitive)); QVERIFY(ref.endsWith('b', Qt::CaseInsensitive));
QVERIFY(ref.endsWith('B', Qt::CaseInsensitive)); QVERIFY(ref.endsWith('B', Qt::CaseInsensitive));
QVERIFY(ref.endsWith(QLatin1Char('b'), Qt::CaseInsensitive)); QVERIFY(ref.endsWith(QLatin1Char('b'), Qt::CaseInsensitive));
@ -754,7 +772,10 @@ void tst_QStringRef::endsWith()
const QString a = QString::fromLatin1(""); const QString a = QString::fromLatin1("");
CREATE_REF(a); CREATE_REF(a);
QVERIFY(ref.endsWith("")); QVERIFY(ref.endsWith(""));
QVERIFY(ref.endsWith(QString()));
#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.endsWith(QString::null)); QVERIFY(ref.endsWith(QString::null));
#endif
QVERIFY(!ref.endsWith("ABC")); QVERIFY(!ref.endsWith("ABC"));
QVERIFY(!ref.endsWith(QLatin1Char(0))); QVERIFY(!ref.endsWith(QLatin1Char(0)));
QVERIFY(!ref.endsWith(QLatin1Char('x'))); QVERIFY(!ref.endsWith(QLatin1Char('x')));
@ -768,7 +789,10 @@ void tst_QStringRef::endsWith()
{ {
QStringRef ref; QStringRef ref;
QVERIFY(!ref.endsWith("")); QVERIFY(!ref.endsWith(""));
QVERIFY(ref.endsWith(QString()));
#if QT_DEPRECATED_SINCE(5, 9)
QVERIFY(ref.endsWith(QString::null)); QVERIFY(ref.endsWith(QString::null));
#endif
QVERIFY(!ref.endsWith("ABC")); QVERIFY(!ref.endsWith("ABC"));
QVERIFY(!ref.endsWith(QLatin1String(""))); QVERIFY(!ref.endsWith(QLatin1String("")));

View File

@ -311,12 +311,14 @@ void tst_QStandardItem::getSetFlags()
item.setCheckable(true); item.setCheckable(true);
QCOMPARE(item.checkState(), Qt::Checked); QCOMPARE(item.checkState(), Qt::Checked);
#if QT_DEPRECATED_SINCE(5, 6)
// deprecated API // deprecated API
item.setTristate(true); item.setTristate(true);
QVERIFY(item.isTristate()); QVERIFY(item.isTristate());
QVERIFY(item.flags() & Qt::ItemIsTristate); QVERIFY(item.flags() & Qt::ItemIsTristate);
item.setTristate(false); item.setTristate(false);
QVERIFY(!(item.flags() & Qt::ItemIsTristate)); QVERIFY(!(item.flags() & Qt::ItemIsTristate));
#endif
} }
void tst_QStandardItem::getSetRowAndColumnCount() void tst_QStandardItem::getSetRowAndColumnCount()

View File

@ -422,7 +422,7 @@ void tst_qmake::prompt()
{ {
#if 0 #if 0
QProcess qmake; QProcess qmake;
qmake.setReadChannelMode(QProcess::MergedChannels); qmake.setProcessChannelMode(QProcess::MergedChannels);
qmake.setWorkingDirectory(QLatin1String("testdata/prompt")); qmake.setWorkingDirectory(QLatin1String("testdata/prompt"));
qmake.start(QLatin1String("qmake CONFIG-=debug_and_release CONFIG-=debug CONFIG+=release"), qmake.start(QLatin1String("qmake CONFIG-=debug_and_release CONFIG-=debug CONFIG+=release"),
QIODevice::Text | QIODevice::ReadWrite); QIODevice::Text | QIODevice::ReadWrite);

View File

@ -183,7 +183,7 @@ private:
void DraggableLabel::mousePressEvent(QMouseEvent *) void DraggableLabel::mousePressEvent(QMouseEvent *)
{ {
QMimeData *mimeData = new QMimeData; QMimeData *mimeData = new QMimeData;
mimeData->setImageData(qVariantFromValue(m_pixmap)); mimeData->setImageData(QVariant::fromValue(m_pixmap));
QDrag *drag = new QDrag(this); QDrag *drag = new QDrag(this);
QPixmap pixmap = m_pixmap; QPixmap pixmap = m_pixmap;
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {