From ed19fc05313d338059a34304522d8e3a1932dc03 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 19 May 2019 09:59:24 +0200 Subject: QFileSystemWatcher: lock autotest code away into a cold section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code contained a sizeable chunk of string parsing along with qDebug()s in the normal path of execution. That code, however, was only used for Qt's own autotests. The idea of this patch is, then, to not only move the autotest case into the cold text section (using Q_UNLIKELY), but also to completely exclude it, when QT_BUILD_INTERNAL is not set. Unfortunately, the structure of the function did not really lend itself to #ifdefing that part of the code out (production code was in the middle of non-production code), so I transformed the engine selection code into a lambda, replacing assignment with returns, and swapping the branches of the central if around to yield a single block of code that can be excluded from compilation with just one #ifdef. As a consequence, the runtime code is almost unaffected, and the function is much easier to read now. Since the test-specific code is only compiled into Qt now in developer builds, guard the tests that rely on this behavior with the same macro. Change-Id: I9fd1c57020a13cef4cd1b1674ed2d3ab9424d7cd Reviewed-by: Mårten Nordheim --- .../corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/auto/corelib/io') 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 { -- cgit v1.2.3 From bd55a9d91227d1ac38f51b21ca23dec7fa5e82af Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 11 Mar 2015 14:38:59 +0100 Subject: Fix canonicalFilePath() for files with trailing slashes Such files do not exist (as per QFileInfo::exists), but on some platforms that rely on realpath(), QFileInfo::canonicalFilePath did not return the empty string. Use the same logic on macOS as we already did on Android, and include a test case. Remove the unnecessary dynamic memory allocation and use a stack-allocated array instead, unless we use modern POSIX in which case realpath() will alloc the memory for the result for us. Change-Id: Ide987c68ebf00cbb7b1a66c2e9245a12c7807128 Fixes: QTBUG-44242 Reviewed-by: Lars Knoll --- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index a92b4bd1cb..646fb2078a 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -655,6 +655,8 @@ void tst_QFileInfo::canonicalFilePath() QVERIFY(tempFile.open(QFile::WriteOnly)); QFileInfo fi(tempFile.fileName()); QCOMPARE(fi.canonicalFilePath(), QDir::currentPath() + "/" + fileName); + fi = QFileInfo(tempFile.fileName() + QString::fromLatin1("/")); + QCOMPARE(fi.canonicalFilePath(), QString::fromLatin1("")); tempFile.remove(); // This used to crash on Mac, verify that it doesn't anymore. -- cgit v1.2.3 From c9b7cc349a13b722ecd636ec4eb8e21f9f712add Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 23 May 2019 13:51:05 +0200 Subject: Remove usages of Q_OS_WINCE This platform is history. Change-Id: Iddfab008a509f4828c321730414c8204055cf7af Reviewed-by: Maurice Kalinowski --- tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 1379c788d1..155f5b953d 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -33,7 +33,7 @@ #include #include #include -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) # include #endif @@ -131,7 +131,7 @@ static const char * const enumNames[MaxStandardLocation + 1 - int(QStandardPaths void tst_qstandardpaths::initTestCase() { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // Disable WOW64 redirection, see testFindExecutable() if (QSysInfo::buildCpuArchitecture() != QSysInfo::currentCpuArchitecture()) { void *oldMode; @@ -140,7 +140,7 @@ void tst_qstandardpaths::initTestCase() qErrnoWarning("Wow64DisableWow64FsRedirection() failed"); QVERIFY(disabledDisableWow64FsRedirection); } -#endif // Q_OS_WIN && !Q_OS_WINRT && !Q_OS_WINCE +#endif // Q_OS_WIN && !Q_OS_WINRT QVERIFY2(m_localConfigTempDir.isValid(), qPrintable(m_localConfigTempDir.errorString())); QVERIFY2(m_globalConfigTempDir.isValid(), qPrintable(m_globalConfigTempDir.errorString())); QVERIFY2(m_localAppTempDir.isValid(), qPrintable(m_localAppTempDir.errorString())); -- cgit v1.2.3 From bf207acb3440da36ef972992dc105691c8c4cb79 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 May 2019 13:55:23 +0200 Subject: Tests: Fix some warnings about deprecated functions not under test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix warnings like: baselineserver/shared/baselineprotocol.cpp:295:72: warning: ‘int QImage::byteCount() const’ is deprecated: Use sizeInBytes [-Wdeprecated-declarations] tst_qnetworkreply.cpp:1560:17: warning: ‘static QList QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations] tst_qnetworkreply.cpp:1560:39: warning: ‘static QList QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations] tst_qnetworkreply.cpp:8153:60: warning: ‘T* QWeakPointer::data() const [with T = const QNetworkSession]’ is deprecated: Use toStrongRef() instead, and data() on the returned QSharedPointer [-Wdeprecated-declarations]. ... st_qprinter.cpp:1318:74: warning: ‘QList QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations] tst_qprinter.cpp:1362:74: warning: ‘QList QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations] tst_largefile.cpp:492:85: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations] tst_largefile.cpp:498:91: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations] tst_qabstractitemmodel.cpp:312:25: warning: ‘void QAbstractItemModel::reset()’ is deprecated [-Wdeprecated-declarations] ... tst_qabstractitemmodel.cpp:1793:28: warning: ‘void QAbstractItemModel::setRoleNames(const QHash&)’ is deprecated [-Wdeprecated-declarations] ... tst_qcolor.cpp:1425:33: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations] tst_qcolor.cpp:1432:31: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations] tst_qprinterinfo.cpp:303:61: warning: 'QList QPrinterInfo::supportedPaperSizes() const' is deprecated [-Wdeprecated-declarations] tst_qprinterinfo.cpp:304:65: warning: 'QList > QPrinterInfo::supportedSizesWithNames() const' is deprecated [-Wdeprecated-declarations] tst_qtextdocumentfragment.cpp:947:52: warning: ‘QString QTextCharFormat::anchorName() const’ is deprecated: Use anchorNames() instead [-Wdeprecated-declarations] tst_qtextlayout.cpp:2261:61: warning: ‘void QTextLayout::setAdditionalFormats(const QList&)’ is deprecated: Use setFormats() [-Wdeprecated-declarations] tst_qtextlayout.cpp:2330:42: warning: ‘int QFontMetrics::width(const QString&, int) const’ is deprecated: Use QFontMetrics::horizontalAdvance [-Wdeprecated-declarations] tst_qitemselectionmodel.cpp:2214:37: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations] ... tst_qtextlist.cpp:317:68: warning: 'bool QTextList::isEmpty() const' is deprecated: Use count() instead [-Wdeprecated-declarations] tst_qpainter.cpp:373:32: warning: ‘void QPainter::setMatrixEnabled(bool)’ is deprecated: Use setWorldMatrixEnabled() instead [-Wdeprecated-declarations] tst_qpainter.cpp:374:40: warning: ‘bool QPainter::matrixEnabled() const’ is deprecated: Use worldMatrixEnabled() instead [-Wdeprecated-declarations] tst_qpainter.cpp:702:45: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations] tst_qpainter.cpp:1573:29: warning: ‘void QPainter::drawRoundRect(const QRect&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:76:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:81:41: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:105:30: warning: ‘virtual void QPdfWriter::setMargins(const QPagedPaintDevice::Margins&)’ is deprecated: Use setPageMargins(QMarginsF(l, t, r, b), QPageLayout::Millimeter) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:172:37: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations] tst_qpdfwriter.cpp:258:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations] qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp:3980:54: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations] tst_qlocale.cpp:434:26: warning: 'QString::null' is deprecated: use QString() [-Wdeprecated-declarations] ... Change-Id: I77c1a934b27119eedeb26a77c913686314a2a5c7 Reviewed-by: David Faure --- tests/auto/corelib/io/largefile/tst_largefile.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index dca7672b8e..f459f62c91 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -36,6 +36,7 @@ #include +#include #include #include @@ -489,13 +490,13 @@ void tst_LargeFile::mapFile() // Keep full block mapped to facilitate OS and/or internal reuse by Qt. uchar *baseAddress = largeFile.map(position, blockSize); QVERIFY( baseAddress ); - QVERIFY( qEqual(block.begin(), block.end(), reinterpret_cast(baseAddress)) ); + QVERIFY( std::equal(block.begin(), block.end(), reinterpret_cast(baseAddress)) ); for (int offset = 1; offset < blockSize; ++offset) { uchar *address = largeFile.map(position + offset, blockSize - offset); QVERIFY( address ); - if ( !qEqual(block.begin() + offset, block.end(), reinterpret_cast(address)) ) { + if ( !std::equal(block.begin() + offset, block.end(), reinterpret_cast(address)) ) { qDebug() << "Expected:" << block.toHex(); qDebug() << "Actual :" << QByteArray(reinterpret_cast(address), blockSize).toHex(); QVERIFY(false); -- cgit v1.2.3