diff options
Diffstat (limited to 'tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp')
-rw-r--r-- | tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp index 327f4dc1a1..2431446bf6 100644 --- a/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp +++ b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QStringList> #include <QTest> @@ -33,6 +8,8 @@ #include <string> #include <vector> +using namespace Qt::StringLiterals; + class tst_QStringList: public QObject { Q_OBJECT @@ -44,6 +21,11 @@ private slots: void removeDuplicates() const; void removeDuplicates_data() const; + void filter_data() const; + void filter() const; + void filter_stringMatcher_data() const { filter_data(); } + void filter_stringMatcher() const; + void split_qlist_qbytearray() const; void split_qlist_qbytearray_data() const { return split_data(); } @@ -68,9 +50,9 @@ private: QStringList tst_QStringList::populateList(const int count, const QString &unit) { QStringList retval; - + retval.reserve(count); for (int i = 0; i < count; ++i) - retval.append(unit); + retval.append(unit + QString::number(i)); return retval; } @@ -102,20 +84,20 @@ void tst_QStringList::join_data() const QTest::addColumn<QStringList>("input"); QTest::addColumn<QString>("separator"); - QTest::newRow("") + QTest::newRow("100") << populateList(100, QLatin1String("unit")) << QString(); - QTest::newRow("") + QTest::newRow("1000") << populateList(1000, QLatin1String("unit")) << QString(); - QTest::newRow("") - << populateList(10000, QLatin1String("unit")) + QTest::newRow("10000") + << populateList(10'000, QLatin1String("unit")) << QString(); - QTest::newRow("") - << populateList(100000, QLatin1String("unit")) + QTest::newRow("100000") + << populateList(100'000, QLatin1String("unit")) << QString(); } @@ -155,6 +137,39 @@ void tst_QStringList::removeDuplicates_data() const QTest::addRow("long-dup-0.75") << (l + l + l + l); } +void tst_QStringList::filter_data() const +{ + QTest::addColumn<QStringList>("list"); + QTest::addColumn<QStringList>("expected"); + + for (int i : {10, 20, 30, 40, 50, 70, 80, 100, 300, 500, 700, 900, 10'000}) { + QStringList list = populateList(i, u"A rather long string to test QStringMatcher"_s); + list.append(u"Horse and cart from old"_s); + QTest::addRow("list%d", i) << list << QStringList(u"Horse and cart from old"_s); + } +} + +void tst_QStringList::filter() const +{ + QFETCH(QStringList, list); + QFETCH(QStringList, expected); + + QBENCHMARK { + QCOMPARE(list.filter(u"Horse and cart from old", Qt::CaseSensitive), expected); + } +} + +void tst_QStringList::filter_stringMatcher() const +{ + QFETCH(QStringList, list); + QFETCH(QStringList, expected); + + const QStringMatcher matcher(u"Horse and cart from old", Qt::CaseSensitive); + QBENCHMARK { + QCOMPARE(list.filter(matcher), expected); + } +} + void tst_QStringList::split_data() const { QTest::addColumn<QString>("input"); |