diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-07-02 15:40:35 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-08 12:08:01 +0000 |
commit | 4030fb42924d1e328d733e4a5ee975ffe3fd5aa1 (patch) | |
tree | cacd8a8d4cfb228043618861165af65a8a12da21 /tests | |
parent | dc70e511a8da8427444a7f0e5204744628849fdc (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.)
Task-number: QTBUG-91713
Change-Id: I1bd5561971239bb838bcf6c24bcdf1d07c81a657
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 74e9b77f4f3bd823d836a2a1a557b294582bac5e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/benchmarks/corelib/io/qdiriterator/main.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp index 367913338f..8c180f8757 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. @@ -64,24 +64,22 @@ private slots: void stdRecursiveDirectoryIterator_data() { 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"; + QByteArray dir(QT_TESTCASE_SOURCEDIR); + // qDebug("Source dir: %s", dir.constData()); + dir.chop(sizeof(hereRelative)); // Counts the '\0', making up for the omitted leading '/' + // 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 |