diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index f40e166d9f..9b47b27f5c 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -352,33 +352,34 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths) return QStringList(); } - QFileSystemWatcherEngine *engine = 0; + const auto selectEngine = [this, d]() -> QFileSystemWatcherEngine* { +#ifdef QT_BUILD_INTERNAL + const QString on = objectName(); - const QString on = objectName(); - - if (!on.startsWith(QLatin1String("_qt_autotest_force_engine_"))) { + if (Q_UNLIKELY(on.startsWith(QLatin1String("_qt_autotest_force_engine_")))) { + // Autotest override case - use the explicitly selected engine only + const QStringRef forceName = on.midRef(26); + if (forceName == QLatin1String("poller")) { + qDebug("QFileSystemWatcher: skipping native engine, using only polling engine"); + d_func()->initPollerEngine(); + return d->poller; + } else if (forceName == QLatin1String("native")) { + qDebug("QFileSystemWatcher: skipping polling engine, using only native engine"); + return d->native; + } + return nullptr; + } +#endif // Normal runtime case - search intelligently for best engine if(d->native) { - engine = d->native; + return d->native; } else { d_func()->initPollerEngine(); - engine = d->poller; + return d->poller; } + }; - } else { - // Autotest override case - use the explicitly selected engine only - const QStringRef forceName = on.midRef(26); - if(forceName == QLatin1String("poller")) { - qDebug("QFileSystemWatcher: skipping native engine, using only polling engine"); - d_func()->initPollerEngine(); - engine = d->poller; - } else if(forceName == QLatin1String("native")) { - qDebug("QFileSystemWatcher: skipping polling engine, using only native engine"); - engine = d->native; - } - } - - if(engine) + if (auto engine = selectEngine()) p = engine->addPaths(p, &d->files, &d->directories); return p; diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 67ffa91e57..cdd1f6361e 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -46,11 +46,13 @@ public: tst_QFileSystemWatcher(); private slots: +#ifdef QT_BUILD_INTERNAL void basicTest_data(); void basicTest(); void watchDirectory_data(); void watchDirectory(); +#endif void addPath(); void removePath(); @@ -58,8 +60,10 @@ private slots: void removePaths(); void removePathsFilesInSameDirectory(); +#ifdef QT_BUILD_INTERNAL void watchFileAndItsDirectory_data() { basicTest_data(); } void watchFileAndItsDirectory(); +#endif void nonExistingFile(); @@ -67,8 +71,10 @@ private slots: void destroyAfterQCoreApplication(); +#ifdef QT_BUILD_INTERNAL void QTBUG2331(); void QTBUG2331_data() { basicTest_data(); } +#endif void signalsEmittedAfterFileMoved(); @@ -90,6 +96,7 @@ tst_QFileSystemWatcher::tst_QFileSystemWatcher() #endif } +#ifdef QT_BUILD_INTERNAL void tst_QFileSystemWatcher::basicTest_data() { QTest::addColumn("backend"); @@ -360,6 +367,7 @@ void tst_QFileSystemWatcher::watchDirectory() for (const auto &testDirName : testDirs) QVERIFY(temporaryDir.rmdir(testDirName)); } +#endif // QT_BUILD_INTERNAL void tst_QFileSystemWatcher::addPath() { @@ -502,6 +510,7 @@ void tst_QFileSystemWatcher::removePathsFilesInSameDirectory() QCOMPARE(watcher.files().size(), 0); } +#ifdef QT_BUILD_INTERNAL static QByteArray msgFileOperationFailed(const char *what, const QFile &f) { return what + QByteArrayLiteral(" failed on \"") @@ -601,6 +610,7 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() QVERIFY(temporaryDir.rmdir(testDirName)); } +#endif // QT_BUILD_INTERNAL void tst_QFileSystemWatcher::nonExistingFile() { @@ -673,6 +683,7 @@ void tst_QFileSystemWatcher::destroyAfterQCoreApplication() QTest::qWait(30); } +#ifdef QT_BUILD_INTERNAL // regression test for QTBUG2331. // essentially, on windows, directories were not unwatched after being deleted // from the disk, causing all sorts of interesting problems. @@ -696,6 +707,7 @@ void tst_QFileSystemWatcher::QTBUG2331() QTRY_COMPARE(changedSpy.count(), 1); QCOMPARE(watcher.directories(), QStringList()); } +#endif // QT_BUILD_INTERNAL class SignalReceiver : public QObject {