diff options
Diffstat (limited to 'tests/benchmarks/corelib/text')
19 files changed, 850 insertions, 244 deletions
diff --git a/tests/benchmarks/corelib/text/CMakeLists.txt b/tests/benchmarks/corelib/text/CMakeLists.txt index d0a2373822..303aa51def 100644 --- a/tests/benchmarks/corelib/text/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from text.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qbytearray) add_subdirectory(qchar) @@ -8,3 +9,4 @@ add_subdirectory(qstringlist) add_subdirectory(qstringtokenizer) add_subdirectory(qregularexpression) add_subdirectory(qstring) +add_subdirectory(qutf8stringview) diff --git a/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt b/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt index 18b811501b..1ea3660680 100644 --- a/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qbytearray Binary: ##################################################################### @@ -5,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qbytearray SOURCES tst_bench_qbytearray.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp b/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp index a98503210c..a97cba7c50 100644 --- a/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp +++ b/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp @@ -1,31 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** 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) 2021 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QIODevice> #include <QFile> @@ -56,6 +31,9 @@ private slots: void toPercentEncoding_data(); void toPercentEncoding(); + + void operator_assign_char(); + void operator_assign_char_data(); }; void tst_QByteArray::initTestCase() @@ -378,6 +356,38 @@ void tst_QByteArray::toPercentEncoding() QTEST(encoded, "expected"); } +void tst_QByteArray::operator_assign_char() +{ + QFETCH(QByteArray, data); + QString str(data.size(), Qt::Uninitialized); + + const char *tdata = data.constData(); + QBENCHMARK { + str.operator=(tdata); + } +} + +void tst_QByteArray::operator_assign_char_data() +{ + QTest::addColumn<QByteArray>("data"); + + QByteArray data; + data.fill('a', 5); + QTest::newRow("length: 5") << data; + data.fill('b', 10); + QTest::newRow("length: 10") << data; + data.fill('c', 20); + QTest::newRow("length: 20") << data; + data.fill('d', 50); + QTest::newRow("length: 50") << data; + data.fill('e', 100); + QTest::newRow("length: 100") << data; + data.fill('f', 500); + QTest::newRow("length: 500") << data; + data.fill('g', 1'000); + QTest::newRow("length: 1'000") << data; +} + QTEST_MAIN(tst_QByteArray) #include "tst_bench_qbytearray.moc" diff --git a/tests/benchmarks/corelib/text/qchar/CMakeLists.txt b/tests/benchmarks/corelib/text/qchar/CMakeLists.txt index ef7f553f2e..136d3ef6fa 100644 --- a/tests/benchmarks/corelib/text/qchar/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qchar/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qchar Binary: ##################################################################### @@ -5,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qchar SOURCES tst_bench_qchar.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp b/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp index b1adfdca4e..194dd27d36 100644 --- a/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp +++ b/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.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 <QTest> #include <QChar> diff --git a/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt b/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt index f319c0b5bd..04c2f69b9f 100644 --- a/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qlocale Binary: ##################################################################### @@ -5,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qlocale SOURCES tst_bench_qlocale.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp b/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp index 23a64526eb..3d13174c9c 100644 --- a/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp +++ b/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp @@ -1,34 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QLocale> #include <QTest> +using namespace Qt::StringLiterals; + class tst_QLocale : public QObject { Q_OBJECT @@ -54,6 +31,12 @@ private Q_SLOTS: void toUpper_QLocale_2(); void toUpper_QString(); void number_QString(); + void toLongLong_data(); + void toLongLong(); + void toULongLong_data(); + void toULongLong(); + void toDouble_data(); + void toDouble(); }; static QString data() @@ -392,6 +375,219 @@ void tst_QLocale::number_QString() } } +template <typename Integer> +void toWholeCommon_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("locale"); + QTest::addColumn<bool>("good"); + QTest::addColumn<Integer>("expected"); + + QTest::newRow("C: empty") << u""_s << u"C"_s << false << Integer(0ull); + QTest::newRow("C: 0") << u"0"_s << u"C"_s << true << Integer(0ull); + QTest::newRow("C: 1234") << u"1234"_s << u"C"_s << true << Integer(1234ull); + // C locale omits grouping, but doesn't reject it. + QTest::newRow("C: 1,234") << u"1,234"_s << u"C"_s << true << Integer(1234ull); + QTest::newRow("C: 123456789") + << u"123456789"_s << u"C"_s << true << Integer(123456789ull); + QTest::newRow("C: 123,456,789") + << u"123,456,789"_s << u"C"_s << true << Integer(123456789ull); + + QTest::newRow("en: empty") << u""_s << u"en"_s << false << Integer(0ull); + QTest::newRow("en: 0") << u"0"_s << u"en"_s << true << Integer(0ull); + QTest::newRow("en: 1234") << u"1234"_s << u"en"_s << true << Integer(1234ull); + QTest::newRow("en: 1,234") << u"1,234"_s << u"en"_s << true << Integer(1234ull); + QTest::newRow("en: 123,456,789") + << u"123,456,789"_s << u"en"_s << true << Integer(123456789ull); + QTest::newRow("en: 123456789") + << u"123456789"_s << u"en"_s << true << Integer(123456789ull); + + QTest::newRow("de: empty") << u""_s << u"de"_s << false << Integer(0ull); + QTest::newRow("de: 0") << u"0"_s << u"de"_s << true << Integer(0ull); + QTest::newRow("de: 1234") << u"1234"_s << u"de"_s << true << Integer(1234ull); + QTest::newRow("de: 1.234") << u"1.234"_s << u"de"_s << true << Integer(1234ull); + QTest::newRow("de: 123.456.789") + << u"123.456.789"_s << u"de"_s << true << Integer(123456789ull); + QTest::newRow("de: 123456789") + << u"123456789"_s << u"de"_s << true << Integer(123456789ull); + + // Locales with non-single-character signs: + QTest::newRow("ar_EG: +403") // Arabic, Egypt + << u"\u061c+\u0664\u0660\u0663"_s << u"ar_EG"_s << true << Integer(403ull); + QTest::newRow("ar_EG: !403") // Only first character of the sign + << u"\u061c\u0664\u0660\u0663"_s << u"ar_EG"_s << false << Integer(0ull); + QTest::newRow("fa_IR: +403") // Farsi, Iran + << u"\u200e+\u06f4\u06f0\u06f3"_s << u"fa_IR"_s << true << Integer(403ull); + QTest::newRow("fa_IR: !403") // Only first character of sign + << u"\u200e\u06f4\u06f0\u06f3"_s << u"fa_IR"_s << false << Integer(0ull); +} + +void tst_QLocale::toLongLong_data() +{ + toWholeCommon_data<qlonglong>(); + + QTest::newRow("C: -1234") << u"-1234"_s << u"C"_s << true << -1234ll; + QTest::newRow("C: -123456789") << u"-123456789"_s << u"C"_s << true << -123456789ll; + QTest::newRow("C: qlonglong-max") + << u"9223372036854775807"_s << u"C"_s << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("C: qlonglong-min") + << u"-9223372036854775808"_s << u"C"_s << true + << std::numeric_limits<qlonglong>::min(); + + // Locales with multi-character signs: + QTest::newRow("ar_EG: -403") // Arabic, Egypt + << u"\u061c-\u0664\u0660\u0663"_s << u"ar_EG"_s << true << -403ll; + QTest::newRow("fa_IR: -403") // Farsi, Iran + << u"\u200e\u2212\u06f4\u06f0\u06f3"_s << u"fa_IR"_s << true << -403ll; +} + +void tst_QLocale::toLongLong() +{ + QFETCH(QString, text); + QFETCH(QString, locale); + QFETCH(bool, good); + QFETCH(qlonglong, expected); + + const QLocale loc(locale); + qlonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = loc.toLongLong(text, &ok); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QLocale::toULongLong_data() +{ + toWholeCommon_data<qulonglong>(); + + QTest::newRow("C: qlonglong-max + 1") + << u"9223372036854775808"_s << u"C"_s << true + << (qulonglong(std::numeric_limits<qlonglong>::max()) + 1); + QTest::newRow("C: qulonglong-max") + << u"18446744073709551615"_s << u"C"_s << true + << std::numeric_limits<qulonglong>::max(); +} + +void tst_QLocale::toULongLong() +{ + QFETCH(QString, text); + QFETCH(QString, locale); + QFETCH(bool, good); + QFETCH(qulonglong, expected); + + const QLocale loc(locale); + qulonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = loc.toULongLong(text, &ok); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + + +void tst_QLocale::toDouble_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("locale"); + QTest::addColumn<bool>("good"); + QTest::addColumn<double>("expected"); + + QTest::newRow("C: empty") << u""_s << u"C"_s << false << 0.0; + QTest::newRow("C: 0") << u"0"_s << u"C"_s << true << 0.0; + QTest::newRow("C: 0.12340") << u"0.12340"_s << u"C"_s << true << 0.12340; + QTest::newRow("C: -0.12340") << u"-0.12340"_s << u"C"_s << true << -0.12340; + QTest::newRow("C: −0.12340") << u"\u2212" "0.12340"_s << u"C"_s << true << -0.12340; + QTest::newRow("C: 1.0e-4") << u"1.0e-4"_s << u"C"_s << true << 1.0e-4; + QTest::newRow("C: 1.0e−4") << u"1.0e\u2212" "4"_s << u"C"_s << true << 1.0e-4; + QTest::newRow("C: 1.0e+4") << u"1.0e+4"_s << u"C"_s << true << 1.0e+4; + QTest::newRow("C: 10.e+3") << u"10.e+3"_s << u"C"_s << true << 1.0e+4; + QTest::newRow("C: 10e+3.") << u"10e+3."_s << u"C"_s << false << 0.0; // exp...dot + QTest::newRow("C: 1e4") << u"1e4"_s << u"C"_s << true << 1.0e+4; + + // NaN and infinity: + QTest::newRow("C: nan") << u"nan"_s << u"C"_s << true << qQNaN(); + QTest::newRow("C: NaN") << u"NaN"_s << u"C"_s << true << qQNaN(); + QTest::newRow("C: -nan") << u"-nan"_s << u"C"_s << false << 0.0; + QTest::newRow("C: +nan") << u"+nan"_s << u"C"_s << false << 0.0; + QTest::newRow("C: inf") << u"inf"_s << u"C"_s << true << qInf(); + QTest::newRow("C: Inf") << u"Inf"_s << u"C"_s << true << qInf(); + QTest::newRow("C: +inf") << u"+inf"_s << u"C"_s << true << qInf(); + QTest::newRow("C: -inf") << u"-inf"_s << u"C"_s << true << -qInf(); + + // Wantonly long-form representations, with trailing and leading zeros: + QTest::newRow("C: 1e-64 long-form") + << (u"0."_s + QString(63, u'0') + u'1' + QString(962, u'0')) << u"C"_s << true << 1e-64; + QTest::newRow("C: 1e+64 long-form") + << (QString(961, u'0') + u'1' + QString(64, u'0') + u".0"_s) << u"C"_s << true << 1e+64; + QTest::newRow("C: long-form 1 via e+64") + << (u"0."_s + QString(63, u'0') + u'1' + QString(962, u'0') + u"e+64"_s) + << u"C"_s << true << 1.0; + QTest::newRow("C: long-form 1 via e-64") + << (QString(961, u'0') + u'1' + QString(64, u'0') + u".0e-64"_s) + << u"C"_s << true << 1.0; + QTest::newRow("C: 12345678.9") << u"12345678.9"_s << u"C"_s << true << 12345678.9; + + // With and without grouping, en vs de for flipped separators: + QTest::newRow("en: 12345678.9") << u"12345678.9"_s << u"en"_s << true << 12345678.9; + QTest::newRow("en: 12,345,678.9") << u"12,345,678.9"_s << u"en"_s << true << 12'345'678.9; + QTest::newRow("de: 12345678,9") << u"12345678,9"_s << u"de"_s << true << 12345678.9; + QTest::newRow("de: 12.345.678,9") << u"12.345.678,9"_s << u"de"_s << true << 12'345'678.9; + + // NaN and infinity are locale-independent (for now - QTBUG-95460) + QTest::newRow("cy: nan") << u"nan"_s << u"cy"_s << true << qQNaN(); + QTest::newRow("cy: NaN") << u"NaN"_s << u"cy"_s << true << qQNaN(); + QTest::newRow("cy: -nan") << u"-nan"_s << u"cy"_s << false << 0.0; + QTest::newRow("cy: +nan") << u"+nan"_s << u"cy"_s << false << 0.0; + QTest::newRow("cy: inf") << u"inf"_s << u"cy"_s << true << qInf(); + QTest::newRow("cy: Inf") << u"Inf"_s << u"cy"_s << true << qInf(); + QTest::newRow("cy: +inf") << u"+inf"_s << u"cy"_s << true << qInf(); + QTest::newRow("cy: -inf") << u"-inf"_s << u"cy"_s << true << -qInf(); + // Samples ready for QTBUG-95460: + QTest::newRow("en: ∞") << u"\u221e"_s << u"en"_s << true << qInf(); + QTest::newRow("ga: Nuimh") << u"Nuimh"_s << u"ga"_s << true << qQNaN(); + + // Locales with multi-character exponents: + QTest::newRow("sv_SE: 4e-3") // Swedish, Sweden + << u"4\u00d7" "10^\u2212" "03"_s << u"sv_SE"_s << true << 4e-3; + QTest::newRow("sv_SE: 4x-3") // Only first character of exponent + << u"4\u00d7\u2212" "03"_s << u"sv_SE"_s << false << 0.0; + QTest::newRow("se_NO: 4e-3") // Northern Sami, Norway + << u"4\u00b7" "10^\u2212" "03"_s << u"se_NO"_s << true << 4e-3; + QTest::newRow("se_NO: 4x-3") // Only first character of exponent + << u"4\u00b7\u2212" "03"_s << u"se_NO"_s << false << 0.0; + QTest::newRow("ar_EG: 4e-3") // Arabic, Egypt + << u"\u0664\u0627\u0633\u061c-\u0660\u0663"_s << u"ar_EG"_s << true << 4e-3; + QTest::newRow("ar_EG: 4x-3") // Only first character of exponent + << u"\u0664\u0627\u061c-\u0660\u0663"_s << u"ar_EG"_s << false << 0.0; + QTest::newRow("ar_EG: 4e!3") // Only first character of sign + << u"\u0664\u0627\u0633\u061c\u0660\u0663"_s << u"ar_EG"_s << false << 0.0; + QTest::newRow("ar_EG: 4x!3") // Only first character of sign and exponent + << u"\u0664\u0627\u061c\u0660\u0663"_s << u"ar_EG"_s << false << 0.0; +} + +void tst_QLocale::toDouble() +{ + QFETCH(QString, text); + QFETCH(QString, locale); + QFETCH(bool, good); + QFETCH(double, expected); + + const QLocale loc(locale); + double actual = expected; + bool ok = false; + QBENCHMARK { + actual = loc.toDouble(text, &ok); + } + QEXPECT_FAIL("en: ∞", "Localized infinity support missing: QTBUG-95460", Abort); + QEXPECT_FAIL("ga: Nuimh", "Localized NaN support missing: QTBUG-95460", Abort); + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + QTEST_MAIN(tst_QLocale) #include "tst_bench_qlocale.moc" diff --git a/tests/benchmarks/corelib/text/qregularexpression/CMakeLists.txt b/tests/benchmarks/corelib/text/qregularexpression/CMakeLists.txt index 1e1f40a2e4..5d029439d0 100644 --- a/tests/benchmarks/corelib/text/qregularexpression/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qregularexpression/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qregularexpression.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qregularexpression Binary: @@ -7,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qregularexpression SOURCES tst_bench_qregularexpression.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qregularexpression/tst_bench_qregularexpression.cpp b/tests/benchmarks/corelib/text/qregularexpression/tst_bench_qregularexpression.cpp index 6c9c2ddaf5..83c87be0b1 100644 --- a/tests/benchmarks/corelib/text/qregularexpression/tst_bench_qregularexpression.cpp +++ b/tests/benchmarks/corelib/text/qregularexpression/tst_bench_qregularexpression.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QRegularExpression> #include <QTest> diff --git a/tests/benchmarks/corelib/text/qstring/CMakeLists.txt b/tests/benchmarks/corelib/text/qstring/CMakeLists.txt index c2ce102780..f17088d2be 100644 --- a/tests/benchmarks/corelib/text/qstring/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstring/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qstring.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qstring Binary: @@ -7,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qstring SOURCES tst_bench_qstring.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp b/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp index ada0e25d71..da5c0ff359 100644 --- a/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp +++ b/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp @@ -1,35 +1,14 @@ -/**************************************************************************** -** -** 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 <QByteArray> +#include <QLatin1StringView> #include <QFile> #include <QTest> #include <limits> +using namespace Qt::StringLiterals; + class tst_QString: public QObject { Q_OBJECT @@ -49,6 +28,7 @@ private slots: void toCaseFolded_data(); void toCaseFolded(); + // Serializing: void number_qlonglong_data(); void number_qlonglong() { number_impl<qlonglong>(); } void number_qulonglong_data(); @@ -57,10 +37,30 @@ private slots: void number_double_data(); void number_double(); + // Parsing: + void toLongLong_data(); + void toLongLong(); + void toULongLong_data(); + void toULongLong(); + void toDouble_data(); + void toDouble(); + + // operator=(~) +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) + void operator_assign_BA() { operator_assign<QByteArray>(); } + void operator_assign_BA_data() { operator_assign_data(); } + void operator_assign_char() { operator_assign<const char*>(); }; + void operator_assign_char_data() { operator_assign_data();} +#endif + void operator_assign_L1SV() { operator_assign<QLatin1StringView>(); } + void operator_assign_L1SV_data() { operator_assign_data(); } + private: void section_data_impl(bool includeRegExOnly = true); template <typename RX> void section_impl(); template <typename Integer> void number_impl(); + template <typename T> void operator_assign(); + void operator_assign_data(); }; tst_QString::tst_QString() @@ -214,6 +214,10 @@ void tst_QString::number_impl() template <typename Integer> void number_integer_common() { + QTest::addColumn<Integer>("number"); + QTest::addColumn<int>("base"); + QTest::addColumn<QString>("expected"); + QTest::newRow("0") << Integer(0ull) << 10 << QStringLiteral("0"); QTest::newRow("1234") << Integer(1234ull) << 10 << QStringLiteral("1234"); QTest::newRow("123456789") << Integer(123456789ull) << 10 << QStringLiteral("123456789"); @@ -225,10 +229,6 @@ void number_integer_common() void tst_QString::number_qlonglong_data() { - QTest::addColumn<qlonglong>("number"); - QTest::addColumn<int>("base"); - QTest::addColumn<QString>("expected"); - number_integer_common<qlonglong>(); QTest::newRow("-1234") << -1234ll << 10 << QStringLiteral("-1234"); @@ -255,10 +255,6 @@ void tst_QString::number_qlonglong_data() void tst_QString::number_qulonglong_data() { - QTest::addColumn<qulonglong>("number"); - QTest::addColumn<int>("base"); - QTest::addColumn<QString>("expected"); - number_integer_common<qulonglong>(); QTest::newRow("qlonglong-max + 1") @@ -319,6 +315,196 @@ void tst_QString::number_double() QCOMPARE(actual, expected); } +template <typename Integer> +void toWholeCommon_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<int>("base"); + QTest::addColumn<bool>("good"); + QTest::addColumn<Integer>("expected"); + + QTest::newRow("empty") << u""_s << 10 << false << Integer(0ull); + QTest::newRow("0") << u"0"_s << 10 << true << Integer(0ull); + QTest::newRow("1234") << u"1234"_s << 10 << true << Integer(1234ull); + QTest::newRow("1,234") << u"1,234"_s << 10 << false << Integer(0ull); + QTest::newRow("123456789") + << u"123456789"_s << 10 << true << Integer(123456789ull); + QTest::newRow("bad1dea, base 16") + << u"bad1dea"_s << 16 << true << Integer(0xBAD1DEAull); + QTest::newRow("bad1dea, base 10") << u"bad1dea"_s << 10 << false << Integer(0ull); + QTest::newRow("42, base 13") << u"42"_s << 13 << true << Integer(6ull * 9ull); + QTest::newRow("242, base 8") << u"242"_s << 8 << true << Integer(0242ull); + QTest::newRow("495, base 8") << u"495"_s << 8 << false << Integer(0ull); + QTest::newRow("101101, base 2") + << u"101101"_s << 2 << true << Integer(0b101101ull); + QTest::newRow("ad, base 30") << u"ad"_s << 30 << true << Integer(313ull); +} + +void tst_QString::toLongLong_data() +{ + toWholeCommon_data<qlonglong>(); + + QTest::newRow("-1234") << u"-1234"_s << 10 << true << -1234ll; + QTest::newRow("-123456789") << u"-123456789"_s << 10 << true << -123456789ll; + QTest::newRow("-bad1dea, base 16") << u"-bad1dea"_s << 16 << true << -0xBAD1DEAll; + QTest::newRow("-242, base 8") << u"-242"_s << 8 << true << -0242ll; + QTest::newRow("-101101, base 2") << u"-101101"_s << 2 << true << -0b101101ll; + QTest::newRow("-ad, base 30") << u"-ad"_s << 30 << true << -313ll; + + QTest::newRow("qlonglong-max") + << u"9223372036854775807"_s << 10 << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min") + << u"-9223372036854775808"_s << 10 << true + << std::numeric_limits<qlonglong>::min(); + QTest::newRow("qlonglong-max, base 2") + << QString(63, u'1') << 2 << true << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min, base 2") + << (u"-1"_s + QString(63, u'0')) << 2 << true + << std::numeric_limits<qlonglong>::min(); + QTest::newRow("qlonglong-max, base 16") + << (QChar(u'7') + QString(15, u'f')) << 16 << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min, base 16") + << (u"-8"_s + QString(15, u'0')) << 16 << true + << std::numeric_limits<qlonglong>::min(); +} + +void tst_QString::toLongLong() +{ + QFETCH(QString, text); + QFETCH(int, base); + QFETCH(bool, good); + QFETCH(qlonglong, expected); + + qlonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toLongLong(&ok, base); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QString::toULongLong_data() +{ + toWholeCommon_data<qulonglong>(); + + QTest::newRow("qlonglong-max + 1") + << u"9223372036854775808"_s << 10 << true + << (qulonglong(std::numeric_limits<qlonglong>::max()) + 1); + QTest::newRow("qulonglong-max") + << u"18446744073709551615"_s << 10 << true + << std::numeric_limits<qulonglong>::max(); + QTest::newRow("qulonglong-max, base 2") + << QString(64, u'1') << 2 << true << std::numeric_limits<qulonglong>::max(); + QTest::newRow("qulonglong-max, base 16") + << QString(16, u'f') << 16 << true << std::numeric_limits<qulonglong>::max(); +} + +void tst_QString::toULongLong() +{ + QFETCH(QString, text); + QFETCH(int, base); + QFETCH(bool, good); + QFETCH(qulonglong, expected); + + qulonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toULongLong(&ok, base); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QString::toDouble_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<bool>("good"); + QTest::addColumn<double>("expected"); + + QTest::newRow("empty") << u""_s << false << 0.0; + QTest::newRow("0") << u"0"_s << true << 0.0; + QTest::newRow("0.12340") << u"0.12340"_s << true << 0.12340; + QTest::newRow("-0.12340") << u"-0.12340"_s << true << -0.12340; + QTest::newRow("epsilon") + << u"2.220446049e-16"_s << true << std::numeric_limits<double>::epsilon(); + QTest::newRow("1.0e-4") << u"1.0e-4"_s << true << 1.0e-4; + QTest::newRow("1.0e+4") << u"1.0e+4"_s << true << 1.0e+4; + QTest::newRow("10.e+3") << u"10.e+3"_s << true << 1.0e+4; + QTest::newRow("10e+3.") << u"10e+3."_s << false << 0.0; + QTest::newRow("1e4") << u"1e4"_s << true << 1.0e+4; + QTest::newRow("1.0e-8") << u"1.0e-8"_s << true << 1.0e-8; + QTest::newRow("1.0e+8") << u"1.0e+8"_s << true << 1.0e+8; + + // NaN and infinity: + QTest::newRow("nan") << u"nan"_s << true << qQNaN(); + QTest::newRow("NaN") << u"NaN"_s << true << qQNaN(); + QTest::newRow("-nan") << u"-nan"_s << false << 0.0; + QTest::newRow("+nan") << u"+nan"_s << false << 0.0; + QTest::newRow("inf") << u"inf"_s << true << qInf(); + QTest::newRow("Inf") << u"Inf"_s << true << qInf(); + QTest::newRow("+inf") << u"+inf"_s << true << qInf(); + QTest::newRow("-inf") << u"-inf"_s << true << -qInf(); +} + +void tst_QString::toDouble() +{ + QFETCH(QString, text); + QFETCH(bool, good); + QFETCH(double, expected); + + double actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toDouble(&ok); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +template <typename T> void tst_QString::operator_assign() +{ + QFETCH(QByteArray, data); + QString str(data.size(), Qt::Uninitialized); + + T tdata; + if constexpr (std::is_same_v<T, const char*>) { + tdata = data.constData(); + } else if constexpr (std::is_same_v<T, QLatin1String>) { + tdata = T(data.constData(), data.size()); + } else { + tdata = T(data.constData(), data.size()); + tdata.detach(); + } + + QBENCHMARK { + str.operator=(tdata); + } +} + +void tst_QString::operator_assign_data() +{ + QTest::addColumn<QByteArray>("data"); + + QByteArray data; + data.fill('a', 5); + QTest::newRow("length: 5") << data; + data.fill('b', 10); + QTest::newRow("length: 10") << data; + data.fill('c', 20); + QTest::newRow("length: 20") << data; + data.fill('d', 50); + QTest::newRow("length: 50") << data; + data.fill('e', 100); + QTest::newRow("length: 100") << data; + data.fill('f', 500); + QTest::newRow("length: 500") << data; + data.fill('g', 1'000); + QTest::newRow("length: 1'000") << data; +} + QTEST_APPLESS_MAIN(tst_QString) #include "tst_bench_qstring.moc" diff --git a/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt index b450aa50a0..c3c95e233c 100644 --- a/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qstringbuilder Binary: ##################################################################### @@ -5,7 +8,7 @@ qt_internal_add_benchmark(tst_bench_qstringbuilder SOURCES tst_bench_qstringbuilder.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test COMPILE_OPTIONS -g diff --git a/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp b/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp index acb7c14169..496abdaf3b 100644 --- a/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp +++ b/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.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 module 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 // Select one of the scenarios below #define SCENARIO 1 diff --git a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt index 58af3c9dd3..da2f84d6e9 100644 --- a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qstringlist Binary: ##################################################################### @@ -5,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qstringlist SOURCES tst_bench_qstringlist.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) 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"); diff --git a/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt index 92dd6cec98..11720e5204 100644 --- a/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qstringtokenizer Binary: ##################################################################### @@ -5,7 +8,7 @@ qt_internal_add_benchmark(tst_bench_qstringtokenizer SOURCES tst_bench_qstringtokenizer.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp b/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp index 291b314a7f..eccfad91da 100644 --- a/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp +++ b/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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. -** -** $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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QTest> diff --git a/tests/benchmarks/corelib/text/qutf8stringview/CMakeLists.txt b/tests/benchmarks/corelib/text/qutf8stringview/CMakeLists.txt new file mode 100644 index 0000000000..14613afe56 --- /dev/null +++ b/tests/benchmarks/corelib/text/qutf8stringview/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_qutf8stringview Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_qutf8stringview + SOURCES + tst_bench_qutf8stringview.cpp + LIBRARIES + Qt::Test + Qt::CorePrivate +) diff --git a/tests/benchmarks/corelib/text/qutf8stringview/tst_bench_qutf8stringview.cpp b/tests/benchmarks/corelib/text/qutf8stringview/tst_bench_qutf8stringview.cpp new file mode 100644 index 0000000000..ec633ff67d --- /dev/null +++ b/tests/benchmarks/corelib/text/qutf8stringview/tst_bench_qutf8stringview.cpp @@ -0,0 +1,263 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <qbytearray.h> +#include <qdebug.h> +#include <qstring.h> +#include <qtest.h> +#include <qutf8stringview.h> + +class tst_QUtf8StringView : public QObject +{ + Q_OBJECT + +private slots: + void equalStringsLatin1_data() { equalStrings_data(); } + void equalStringsLatin1(); + void equalStringsUtf16_data() { equalStrings_data(); } + void equalStringsUtf16(); + void equalStringsUtf8_data() { equalStrings_data(); } + void equalStringsUtf8(); + + void compareStringsCaseSensitiveLatin1_data() { compareStringsCaseSensitive_data(); } + void compareStringsCaseSensitiveLatin1() { compareStringsLatin1(true); } + void compareStringsCaseSensitiveUtf16_data() { compareStringsCaseSensitive_data(); } + void compareStringsCaseSensitiveUtf16() { compareStringsUtf16(true); } + void compareStringsCaseSensitiveUtf8_data() { compareStringsCaseSensitive_data(); } + void compareStringsCaseSensitiveUtf8() { compareStringsUtf8(true); } + + void compareStringsCaseInsensitiveLatin1_data() { compareStringsCaseInsensitive_data(); } + void compareStringsCaseInsensitiveLatin1() { compareStringsLatin1(false); } + void compareStringsCaseInsensitiveUtf16_data() { compareStringsCaseInsensitive_data(); } + void compareStringsCaseInsensitiveUtf16() { compareStringsUtf16(false); } + void compareStringsCaseInsensitiveUtf8_data() { compareStringsCaseInsensitive_data(); } + void compareStringsCaseInsensitiveUtf8() { compareStringsUtf8(false); } + + void compareStringsWithErrors_data(); + void compareStringsWithErrors(); + +private: + void equalStrings_data(); + void compareStringsCaseSensitive_data(); + void compareStringsCaseInsensitive_data(); + void compareStringsLatin1(bool caseSensitive); + void compareStringsUtf16(bool caseSensitive); + void compareStringsUtf8(bool caseSensitive); +}; + +void tst_QUtf8StringView::equalStrings_data() +{ + QTest::addColumn<QString>("lhs"); + QTest::addColumn<QString>("rhs"); + QTest::addColumn<bool>("isEqual"); + + QTest::newRow("EqualStrings") << "Test" + << "Test" << true; + QTest::newRow("EqualStringsLong") + << "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + << "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" << true; + QTest::newRow("DifferentCase") << "test" + << "Test" << false; + QTest::newRow("DifferentCaseLong") + << "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + << "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" << false; + QTest::newRow("ReverseStrings") << "Test" + << "tseT" << false; + QTest::newRow("Latin1RangeCharacter") << u8"B\u00d8" << u8"B\u00d8" << true; + QTest::newRow("Latin1RangeCharacterDifferentCase") << u8"B\u00d8" << u8"B\u00f8" << false; +} + +void tst_QUtf8StringView::equalStringsLatin1() +{ + QFETCH(QString, lhs); + QFETCH(QString, rhs); + QFETCH(bool, isEqual); + QByteArray left = lhs.toUtf8(); + QByteArray right = rhs.toLatin1(); + QBasicUtf8StringView<false> lhv(left); + QLatin1StringView rhv(right); + bool result; + + QBENCHMARK { + result = QtPrivate::equalStrings(lhv, rhv); + }; + QCOMPARE(result, isEqual); +} + +void tst_QUtf8StringView::equalStringsUtf16() +{ + QFETCH(QString, lhs); + QFETCH(QString, rhs); + QFETCH(bool, isEqual); + + QByteArray left = lhs.toUtf8(); + QBasicUtf8StringView<false> lhv(left); + QStringView rhv(rhs); + bool result; + + QBENCHMARK { + result = QtPrivate::equalStrings(lhv, rhv); + }; + QCOMPARE(result, isEqual); +} + +void tst_QUtf8StringView::equalStringsUtf8() +{ + QFETCH(QString, lhs); + QFETCH(QString, rhs); + QFETCH(bool, isEqual); + + QByteArray left = lhs.toUtf8(); + QByteArray right = rhs.toUtf8(); + QBasicUtf8StringView<false> lhv(left); + QBasicUtf8StringView<false> rhv(right); + bool result; + + QBENCHMARK { + result = QtPrivate::equalStrings(lhv, rhv); + }; + QCOMPARE(result, isEqual); +} + +void tst_QUtf8StringView::compareStringsCaseSensitive_data() +{ + QTest::addColumn<QString>("lhs"); + QTest::addColumn<QString>("rhs"); + QTest::addColumn<int>("compareValue"); + + QTest::newRow("EqualStrings") << "Test" + << "Test" << 0; + QTest::newRow("EqualStringsLong") << "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ" + << "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ" << 0; + QTest::newRow("DifferentCase") << "test" + << "Test" << 32; + QTest::newRow("DifferentCaseLong") + << "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ" + << "abcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvxyz" << -32; + QTest::newRow("ReverseStrings") << "Test" + << "tseT" << -32; + QTest::newRow("Different Strings") << "Testing and testing" + << "Testing and resting" << 2; + QTest::newRow("Latin1RangeCharacter") << u8"B\u00d8" << u8"B\u00d8" << 0; + QTest::newRow("Latin1RangeCharacterDifferentCase") << u8"B\u00d8" << u8"B\u00f8" << -32; +} + +void tst_QUtf8StringView::compareStringsCaseInsensitive_data() +{ + QTest::addColumn<QString>("lhs"); + QTest::addColumn<QString>("rhs"); + QTest::addColumn<int>("compareValue"); + + QTest::newRow("EqualStrings") << "Test" + << "Test" << 0; + QTest::newRow("EqualStringsLong") << "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ" + << "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ" << 0; + QTest::newRow("DifferentCase") << "test" + << "Test" << 0; + QTest::newRow("DifferentCaseLong") << "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ" + << "abcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvxyz" << 0; + QTest::newRow("ReverseStrings") << "Test" + << "tseT" << -14; + QTest::newRow("Different Strings") << "Testing and testing" + << "Testing and resting" << 2; + QTest::newRow("Latin1RangeCharacter") << u8"B\u00d8" << u8"B\u00d8" << 0; + QTest::newRow("Latin1RangeCharacterDifferentCase") << u8"B\u00d8" << u8"B\u00f8" << 0; +} + +void tst_QUtf8StringView::compareStringsLatin1(bool caseSensitive) +{ + QFETCH(QString, lhs); + QFETCH(QString, rhs); + QFETCH(int, compareValue); + QByteArray left = lhs.toUtf8(); + QByteArray right = rhs.toLatin1(); + QBasicUtf8StringView<false> lhv(left); + QLatin1StringView rhv(right); + Qt::CaseSensitivity cs = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; + int result; + + QBENCHMARK { + result = lhv.compare(rhv, cs); + }; + QCOMPARE(result, compareValue); +} + +void tst_QUtf8StringView::compareStringsUtf16(bool caseSensitive) +{ + QFETCH(QString, lhs); + QFETCH(QString, rhs); + QFETCH(int, compareValue); + + QByteArray left = lhs.toUtf8(); + QBasicUtf8StringView<false> lhv(left); + QStringView rhv(rhs); + Qt::CaseSensitivity cs = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; + int result; + + QBENCHMARK { + result = lhv.compare(rhv, cs); + }; + QCOMPARE(result, compareValue); +} + +void tst_QUtf8StringView::compareStringsUtf8(bool caseSensitive) +{ + QFETCH(QString, lhs); + QFETCH(QString, rhs); + QFETCH(int, compareValue); + + QByteArray left = lhs.toUtf8(); + QByteArray right = rhs.toUtf8(); + QBasicUtf8StringView<false> lhv(left); + QBasicUtf8StringView<false> rhv(right); + Qt::CaseSensitivity cs = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; + int result; + + QBENCHMARK { + result = lhv.compare(rhv, cs); + }; + QCOMPARE(result, compareValue); +} + +void tst_QUtf8StringView::compareStringsWithErrors_data() +{ + QTest::addColumn<QByteArray>("lhs"); + QTest::addColumn<QByteArray>("rhs"); + QTest::addColumn<int>("compare"); + QTest::addColumn<bool>("caseSensitive"); + + QTest::newRow("Compare errors 0xfe vs 0xff case-insensitive") + << QByteArray("\xfe") << QByteArray("\xff") << 0 << false; + QTest::newRow("Compare errors 0xff vs 0xff case-insensitive") + << QByteArray("\xff") << QByteArray("\xff") << 0 << false; + QTest::newRow("Compare 'a' with error 0xff case-insensitive") + << QByteArray("a") << QByteArray("\xff") << -65436 << false; + QTest::newRow("Compare errors 0xfe vs 0xff case-sensitive") + << QByteArray("\xfe") << QByteArray("\xff") << -1 << true; + QTest::newRow("Compare errors 0xff vs 0xff case-sensitive") + << QByteArray("\xff") << QByteArray("\xff") << 0 << true; + QTest::newRow("Compare 'a' with error 0xff case-sensitive") + << QByteArray("a") << QByteArray("\xff") << -158 << true; +} + +void tst_QUtf8StringView::compareStringsWithErrors() +{ + QFETCH(QByteArray, lhs); + QFETCH(QByteArray, rhs); + QFETCH(int, compare); + QFETCH(bool, caseSensitive); + QBasicUtf8StringView<false> lhv(lhs); + QBasicUtf8StringView<false> rhv(rhs); + Qt::CaseSensitivity cs = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; + int result; + + QBENCHMARK { + result = lhv.compare(rhv, cs); + }; + QCOMPARE(result, compare); + QCOMPARE(-result, rhv.compare(lhv, cs)); +} + +QTEST_MAIN(tst_QUtf8StringView) + +#include "tst_bench_qutf8stringview.moc" |