diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-18 16:44:07 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-23 14:39:44 +0200 |
commit | eec25c7807c85a77669c37372cfbe13e556c3bae (patch) | |
tree | bbfbf73d5632fa24e15420bd2d437af616f5f7e8 /tests | |
parent | d2670601890a188e2d083460b6e65f9df1e8f6fe (diff) |
Fix the (currently unbuilt) qdir/tree/ benchmark
It tried to find its test-data-directory locally, instead of asking
FileSystem where it was keeping its files, relative to a temporary
directory. Its expected counts didn't match the arcane results of its
data file; since this is a benchmark, not a regression test, I'm
assuming that's just because it was never right or the rules for
QDirIterator's filtering have changed.
Tidied up somewhat in the process.
Change-Id: Ib2dcd314b11cb0f1a6fc425633afd0e9c39bd036
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp b/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp index 3a7db36ea2..df16a7978a 100644 --- a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp +++ b/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite module of the Qt Toolkit. @@ -42,7 +42,7 @@ class bench_QDir_tree public: bench_QDir_tree() - : prefix("./test-tree/"), + : prefix("test-tree/"), musicprefix(QLatin1String("music")), photoprefix(QLatin1String("photos")), sourceprefix(QLatin1String("source")), @@ -60,6 +60,7 @@ private: qint64 musicsize; qint64 photosize; qint64 sourcesize; + FileSystem fs; // Uses QTemporaryDir to tidy away file tree created. private slots: void initTestCase() @@ -71,7 +72,7 @@ private slots: QStack<QByteArray> stack; QByteArray line; - Q_FOREVER { + while (true) { char ch; if (!list.getChar(&ch)) break; @@ -89,12 +90,11 @@ private slots: --pop; } - line = list.readLine(); - line.chop(1); + line = list.readLine().trimmed(); stack.push(line); line = prefix; - Q_FOREACH(const QByteArray &pathElement, stack) + for (const QByteArray &pathElement : qAsConst(stack)) line += pathElement; if (line.endsWith('/')) @@ -140,13 +140,11 @@ private slots: QTest::addColumn<int>("filter"); QTest::addColumn<int>("entryCount"); - QTest::newRow("*.cpp") << QStringList("*.cpp") - << int(QDir::Files) - << 3813; - - QTest::newRow("executables") << QStringList("*") + QTest::newRow("*.cpp") << QStringList("*.cpp") << int(QDir::Files) << 3791; + QTest::newRow("executables") + << QStringList("*") << int(QDir::Executable | QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot) - << 543; + << 536; } void fileSearch() const @@ -158,8 +156,9 @@ private slots: int count = 0; QBENCHMARK { // Recursive directory iteration - QDirIterator iterator(prefix, nameFilters, QDir::Filter(filter), - QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); + QDirIterator iterator(fs.absoluteFilePath(prefix), + nameFilters, QDir::Filter(filter), + QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); count = 0; while (iterator.hasNext()) { @@ -177,7 +176,8 @@ private slots: { int count = 0; QBENCHMARK { - QDirIterator iterator(prefix, + QDirIterator iterator( + fs.absoluteFilePath(prefix), QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); @@ -187,10 +187,10 @@ private slots: ++count; } - QCOMPARE(count, 11963); + QCOMPARE(count, 11906); } - QCOMPARE(count, 11963); + QCOMPARE(count, 11906); } void thousandFiles_data() const @@ -209,7 +209,8 @@ private slots: QBENCHMARK { qint64 totalsize = 0; int count = 0; - QDirIterator iter(dirName, QDir::Files, QDirIterator::Subdirectories); + QDirIterator iter(fs.absoluteFilePath(dirName), + QDir::Files, QDirIterator::Subdirectories); while(iter.hasNext()) { count++; totalsize += iter.nextFileInfo().size(); @@ -218,8 +219,6 @@ private slots: QCOMPARE(totalsize, expectedSize); } } -private: - FileSystem fs; }; QTEST_MAIN(bench_QDir_tree) |