summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-07-11 19:28:35 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-07-28 15:16:42 +0200
commit25fff849e8f34af6d41ff36f2891bb4099b89360 (patch)
treed34bb46cd97d25bd2abeee68c9060a1a9b40ff22 /tests/auto/corelib/io
parent8ccd5d5af295ae36440157fe1d00a176fdf1c6bf (diff)
QDirIterator: add nextFileInfo()
Before this change, next() was the only way to advance the iterator, whether the caller was ultimately interested in just the filePath() (good) or not (bad luck, had to call .fileInfo()). Add a new function, nextFileInfo(), with returns fileInfo() instead. Incidentally, the returned object has already been constructed as part of advance()ing the iterator, so the new function is faster than next() even if the result is ignored, because we're not calculating a QString result the caller may not be interested in. Use the new function around the code. Fix a couple of cases of next(); fileInfo().filePath() (just use next()'s return value) as a drive-by. [ChangeLog][QtCore][QDirIterator] Added nextFileInfo(), which is like next(), but returns fileInfo() instead of filePath(). Change-Id: I601220575961169b44139fc55b9eae6c3197afb4 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp4
-rw-r--r--tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp26
-rw-r--r--tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp4
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp4
4 files changed, 12 insertions, 26 deletions
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index a132750113..7b7a996cdd 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -242,9 +242,7 @@ tst_QDir::tst_QDir()
QString resourceSourcePath = QStringLiteral(":/android_testdata/");
QDirIterator it(resourceSourcePath, QDirIterator::Subdirectories);
while (it.hasNext()) {
- it.next();
-
- QFileInfo fileInfo = it.fileInfo();
+ QFileInfo fileInfo = it.nextFileInfo();
if (!fileInfo.isDir()) {
QString destination = m_dataPath + QLatin1Char('/') + fileInfo.filePath().mid(resourceSourcePath.length());
diff --git a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp
index b41352185d..35282ccaa3 100644
--- a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp
+++ b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp
@@ -127,9 +127,7 @@ void tst_QDirIterator::initTestCase()
QString resourceSourcePath = QStringLiteral(":/testdata");
QDirIterator it(resourceSourcePath, QDirIterator::Subdirectories);
while (it.hasNext()) {
- it.next();
-
- QFileInfo fileInfo = it.fileInfo();
+ QFileInfo fileInfo = it.nextFileInfo();
if (!fileInfo.isDir()) {
QString destination = testdata_dir + QLatin1Char('/') + fileInfo.filePath().mid(resourceSourcePath.length());
@@ -467,7 +465,7 @@ void tst_QDirIterator::stopLinkLoop()
QStringList list;
int max = 200;
while (--max && it.hasNext())
- it.next();
+ it.nextFileInfo();
QVERIFY(max);
// The goal of this test is only to ensure that the test above don't malfunction
@@ -508,10 +506,8 @@ void tst_QDirIterator::engineWithNoIterator()
void tst_QDirIterator::absoluteFilePathsFromRelativeIteratorPath()
{
QDirIterator it("entrylist/", QDir::NoDotAndDotDot);
- while (it.hasNext()) {
- it.next();
- QVERIFY(QFileInfo(it.filePath()).absoluteFilePath().contains("entrylist"));
- }
+ while (it.hasNext())
+ QVERIFY(it.nextFileInfo().absoluteFilePath().contains("entrylist"));
}
void tst_QDirIterator::recurseWithFilters() const
@@ -528,11 +524,9 @@ void tst_QDirIterator::recurseWithFilters() const
expectedEntries.insert(QString::fromLatin1("recursiveDirs/textFileA.txt"));
QVERIFY(it.hasNext());
- it.next();
- actualEntries.insert(it.fileInfo().filePath());
+ actualEntries.insert(it.next());
QVERIFY(it.hasNext());
- it.next();
- actualEntries.insert(it.fileInfo().filePath());
+ actualEntries.insert(it.next());
QCOMPARE(actualEntries, expectedEntries);
QVERIFY(!it.hasNext());
@@ -555,7 +549,7 @@ void tst_QDirIterator::longPath()
int m = 0;
while (it.hasNext()) {
++m;
- it.next();
+ it.nextFileInfo();
}
QCOMPARE(n, m);
@@ -622,8 +616,7 @@ void tst_QDirIterator::hiddenDirs_hiddenFiles()
QDirIterator di("hiddenDirs_hiddenFiles", QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (di.hasNext()) {
++matches;
- QString filename = di.next();
- if (QFileInfo(filename).isDir())
+ if (di.nextFileInfo().isDir())
++failures; // search was only supposed to find files
}
QCOMPARE(matches, 6);
@@ -636,8 +629,7 @@ void tst_QDirIterator::hiddenDirs_hiddenFiles()
QDirIterator di("hiddenDirs_hiddenFiles", QDir::Dirs | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (di.hasNext()) {
++matches;
- QString filename = di.next();
- if (!QFileInfo(filename).isDir())
+ if (!di.nextFileInfo().isDir())
++failures; // search was only supposed to find files
}
QCOMPARE(matches, 6);
diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
index b2f7aedab0..317a57a44c 100644
--- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
+++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
@@ -77,9 +77,7 @@ void tst_QResourceEngine::initTestCase()
QDirIterator it(sourcePath, QDirIterator::Subdirectories);
while (it.hasNext()) {
- it.next();
-
- QFileInfo fileInfo = it.fileInfo();
+ QFileInfo fileInfo = it.nextFileInfo();
if (!fileInfo.isDir()) {
QString destination(dataPath + QLatin1Char('/') + fileInfo.filePath().mid(sourcePath.length()));
QFileInfo destinationFileInfo(destination);
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index 5c7d69a788..dcf3486449 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -111,9 +111,7 @@ void tst_QTemporaryFile::initTestCase()
QString sourceDir(":/android_testdata/");
QDirIterator it(sourceDir, QDirIterator::Subdirectories);
while (it.hasNext()) {
- it.next();
-
- QFileInfo sourceFileInfo = it.fileInfo();
+ QFileInfo sourceFileInfo = it.nextFileInfo();
if (!sourceFileInfo.isDir()) {
QFileInfo destinationFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1Char('/') + sourceFileInfo.filePath().mid(sourceDir.length()));