summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-07-02 15:40:35 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-07-09 18:29:34 +0200
commitb83aa5a206d8aae68ca424791bdc7ea05d8e54f8 (patch)
treec1c68536773e3ce2f0392a10aef85c85a86e4ee9 /tests
parent8a12edd8e801bad0f91c07704265795a6ccd2004 (diff)
Fix QDirIterator benchmark to actually find its test data
The benchmark had a hard-coded path on MS and needed an environment variable set otherwise; neither sounds like a good approach, when testlib defines a variable that tells us the test's source directory, a clearly superior way to find things in our source directories. In the process, replace exit()ing on failure to get a path with a QSKIP() so that the test at least fails gracefully if it ever can't find its data. (Using QFAIL() left it with no rows but still trying to run the test, leading to an assert failure.) 5.15 backport replaces QT_TESTCASE_SOURCEDIR with a search for the source tree's qdiriterator.pro using QTest::qFindTestData(). Task-number: QTBUG-91713 Change-Id: I1bd5561971239bb838bcf6c24bcdf1d07c81a657 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 74e9b77f4f3bd823d836a2a1a557b294582bac5e)
Diffstat (limited to 'tests')
-rw-r--r--tests/benchmarks/corelib/io/qdiriterator/main.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp
index eae752d99a..0bbe755f4e 100644
--- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp
+++ b/tests/benchmarks/corelib/io/qdiriterator/main.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 of the Qt Toolkit.
@@ -57,24 +57,23 @@ private slots:
void data();
};
-
void tst_qdiriterator::data()
{
-#if defined(Q_OS_WIN)
- const char *qtdir = "C:\\depot\\qt\\main";
-#else
- const char *qtdir = ::getenv("QTDIR");
-#endif
- if (!qtdir) {
- fprintf(stderr, "QTDIR not set\n");
- exit(1);
- }
+ const char hereRelative[] = "tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro";
+ QString proname = QTest::qFindTestData(QStringLiteral("qdiriterator.pro"));
+ // qDebug("Source pro: %s", proname.toLocal8Bit().constData());
+ // Size chopped counts the '\0', making up for the omitted leading '/':
+ QByteArray dir(QStringRef(&proname).chopped(sizeof(hereRelative)).toLocal8Bit());
+ // qDebug("Root dir: %s", dir.constData());
QTest::addColumn<QByteArray>("dirpath");
- QByteArray ba = QByteArray(qtdir) + "/src/corelib";
- QByteArray ba1 = ba + "/io";
- QTest::newRow(ba) << ba;
- //QTest::newRow(ba1) << ba1;
+ const QByteArray ba = dir + "/src/corelib";
+
+ if (!QFileInfo(QString::fromLocal8Bit(ba)).isDir())
+ QSKIP("Missing Qt directory");
+
+ QTest::newRow("corelib") << ba;
+ QTest::newRow("corelib/io") << (ba + "/io");
}
#ifdef Q_OS_WIN