summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/text
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/text')
-rw-r--r--tests/benchmarks/corelib/text/CMakeLists.txt8
-rw-r--r--tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt11
-rw-r--r--tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp (renamed from tests/benchmarks/corelib/text/qbytearray/main.cpp)211
-rw-r--r--tests/benchmarks/corelib/text/qchar/CMakeLists.txt7
-rw-r--r--tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp (renamed from tests/benchmarks/corelib/text/qchar/main.cpp)31
-rw-r--r--tests/benchmarks/corelib/text/qlocale/CMakeLists.txt7
-rw-r--r--tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp (renamed from tests/benchmarks/corelib/text/qlocale/main.cpp)252
-rw-r--r--tests/benchmarks/corelib/text/qregularexpression/CMakeLists.txt5
-rw-r--r--tests/benchmarks/corelib/text/qregularexpression/tst_bench_qregularexpression.cpp29
-rw-r--r--tests/benchmarks/corelib/text/qstring/CMakeLists.txt7
-rw-r--r--tests/benchmarks/corelib/text/qstring/main.cpp192
-rw-r--r--tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp510
-rw-r--r--tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt11
-rw-r--r--tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp (renamed from tests/benchmarks/corelib/text/qstringbuilder/main.cpp)39
-rw-r--r--tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt7
-rw-r--r--tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp (renamed from tests/benchmarks/corelib/text/qstringlist/main.cpp)93
-rw-r--r--tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt7
-rw-r--r--tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp (renamed from tests/benchmarks/corelib/text/qstringtokenizer/main.cpp)31
-rw-r--r--tests/benchmarks/corelib/text/qutf8stringview/CMakeLists.txt14
-rw-r--r--tests/benchmarks/corelib/text/qutf8stringview/tst_bench_qutf8stringview.cpp263
20 files changed, 1286 insertions, 449 deletions
diff --git a/tests/benchmarks/corelib/text/CMakeLists.txt b/tests/benchmarks/corelib/text/CMakeLists.txt
index 8942b898d0..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)
@@ -7,6 +8,5 @@ add_subdirectory(qstringbuilder)
add_subdirectory(qstringlist)
add_subdirectory(qstringtokenizer)
add_subdirectory(qregularexpression)
-if(GCC)
- add_subdirectory(qstring)
-endif()
+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 50574aa221..1ea3660680 100644
--- a/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt
+++ b/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qbytearray.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qbytearray Binary:
@@ -6,11 +7,7 @@
qt_internal_add_benchmark(tst_bench_qbytearray
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qbytearray.cpp
+ LIBRARIES
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qbytearray.pro:<TRUE>:
-# TEMPLATE = "app"
-# TESTDATA = "main.cpp"
diff --git a/tests/benchmarks/corelib/text/qbytearray/main.cpp b/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp
index e421e7436b..a97cba7c50 100644
--- a/tests/benchmarks/corelib/text/qbytearray/main.cpp
+++ b/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp
@@ -1,40 +1,15 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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>
#include <QString>
#include <qtest.h>
+#include <limits>
-
-class tst_qbytearray : public QObject
+class tst_QByteArray : public QObject
{
Q_OBJECT
QByteArray sourcecode;
@@ -43,21 +18,32 @@ private slots:
void append();
void append_data();
+ void toLongLong_data();
+ void toLongLong();
+ void toULongLong_data();
+ void toULongLong();
+
void latin1Uppercasing_qt54();
void latin1Uppercasing_xlate();
void latin1Uppercasing_xlate_checked();
void latin1Uppercasing_category();
void latin1Uppercasing_bitcheck();
+
+ void toPercentEncoding_data();
+ void toPercentEncoding();
+
+ void operator_assign_char();
+ void operator_assign_char_data();
};
-void tst_qbytearray::initTestCase()
+void tst_QByteArray::initTestCase()
{
- QFile self(QFINDTESTDATA("main.cpp"));
+ QFile self(QFINDTESTDATA("tst_bench_qbytearray.cpp"));
QVERIFY(self.open(QIODevice::ReadOnly));
sourcecode = self.readAll();
}
-void tst_qbytearray::append_data()
+void tst_QByteArray::append_data()
{
QTest::addColumn<int>("size");
QTest::newRow("1") << int(1);
@@ -71,7 +57,7 @@ void tst_qbytearray::append_data()
QTest::newRow("100000000") << int(100000000);
}
-void tst_qbytearray::append()
+void tst_QByteArray::append()
{
QFETCH(int, size);
@@ -83,7 +69,90 @@ void tst_qbytearray::append()
}
}
-void tst_qbytearray::latin1Uppercasing_qt54()
+static QByteArray decNext(QByteArray big)
+{
+ // Increments a decimal digit-string (ignoring sign, so decrements if
+ // negative); only intended for taking a boundary value just out of range,
+ // so big is never a string of only 9s (that'd be one less than a power of
+ // ten, which cannot be a power of two, as odd, or one less than one, as the
+ // power of ten isn't a power of two).
+ int i = big.size() - 1;
+ while (big.at(i) == '9')
+ big[i--] = '0';
+ big[i] += 1;
+ return big;
+}
+
+void tst_QByteArray::toLongLong_data()
+{
+ QTest::addColumn<QByteArray>("text");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<qlonglong>("number");
+#define ROW(n) QTest::newRow(#n) << QByteArray(#n) << true << n ## LL
+ ROW(0);
+ ROW(1);
+ ROW(-1);
+ ROW(17);
+ ROW(-17);
+ ROW(1234567890);
+ ROW(-1234567890);
+#undef ROW
+ using LL = std::numeric_limits<qlonglong>;
+ QTest::newRow("min") << QByteArray::number(LL::min()) << true << LL::min();
+ QTest::newRow("min-1") << decNext(QByteArray::number(LL::min())) << false << 0LL;
+ QTest::newRow("max") << QByteArray::number(LL::max()) << true << LL::max();
+ QTest::newRow("max+1") << decNext(QByteArray::number(LL::max())) << false << 0LL;
+}
+
+void tst_QByteArray::toLongLong()
+{
+ QFETCH(QByteArray, text);
+ QFETCH(bool, good);
+ QFETCH(qlonglong, number);
+
+ qlonglong actual = 0;
+ bool ok;
+ QBENCHMARK {
+ actual = text.toLongLong(&ok);
+ }
+ QCOMPARE(actual, number);
+ QCOMPARE(ok, good);
+}
+
+void tst_QByteArray::toULongLong_data()
+{
+ QTest::addColumn<QByteArray>("text");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<qulonglong>("number");
+#define ROW(n) \
+ QTest::newRow(#n) << QByteArray(#n) << true << n ## ULL; \
+ QTest::newRow("-" #n) << QByteArray("-" #n) << false << 0ULL
+ ROW(0);
+ ROW(1);
+ ROW(17);
+ ROW(1234567890);
+#undef ROW
+ using ULL = std::numeric_limits<qulonglong>;
+ QTest::newRow("max") << QByteArray::number(ULL::max()) << true << ULL::max();
+ QTest::newRow("max+1") << decNext(QByteArray::number(ULL::max())) << false << 0ULL;
+}
+
+void tst_QByteArray::toULongLong()
+{
+ QFETCH(QByteArray, text);
+ QFETCH(bool, good);
+ QFETCH(qulonglong, number);
+
+ qulonglong actual = 0;
+ bool ok;
+ QBENCHMARK {
+ actual = text.toULongLong(&ok);
+ }
+ QCOMPARE(actual, number);
+ QCOMPARE(ok, good);
+}
+
+void tst_QByteArray::latin1Uppercasing_qt54()
{
QByteArray s = sourcecode;
s.detach();
@@ -132,7 +201,7 @@ static const uchar uppercased[256] = {
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xf7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xff
};
-void tst_qbytearray::latin1Uppercasing_xlate()
+void tst_QByteArray::latin1Uppercasing_xlate()
{
QByteArray output = sourcecode;
output.detach();
@@ -146,7 +215,7 @@ void tst_qbytearray::latin1Uppercasing_xlate()
}
}
-void tst_qbytearray::latin1Uppercasing_xlate_checked()
+void tst_QByteArray::latin1Uppercasing_xlate_checked()
{
QByteArray output = sourcecode;
output.detach();
@@ -199,7 +268,7 @@ static const char categories[256] = {
2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,0
};
-void tst_qbytearray::latin1Uppercasing_category()
+void tst_QByteArray::latin1Uppercasing_category()
{
QByteArray output = sourcecode;
output.detach();
@@ -244,7 +313,7 @@ static bool bittest(const quint32 *data, uchar bit)
return data[bit / bitsperelem] & (1 << (bit & (bitsperelem - 1)));
}
-void tst_qbytearray::latin1Uppercasing_bitcheck()
+void tst_QByteArray::latin1Uppercasing_bitcheck()
{
QByteArray output = sourcecode;
output.detach();
@@ -258,7 +327,67 @@ void tst_qbytearray::latin1Uppercasing_bitcheck()
}
}
+void tst_QByteArray::toPercentEncoding_data()
+{
+ QTest::addColumn<QByteArray>("plaintext");
+ QTest::addColumn<QByteArray>("expected");
+
+ QTest::newRow("empty") << QByteArray("") << QByteArray("");
+ QTest::newRow("plain")
+ << QByteArray("the quick brown fox jumped over the lazy dogs")
+ << QByteArray("the%20quick%20brown%20fox%20jumped%20over%20the%20lazy%20dogs");
+ QTest::newRow("specials")
+ << QByteArray(
+ "\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15"
+ "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,/:;<=>?@[\\]^`{|}\x7f")
+ << QByteArray(
+ "%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18"
+ "%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3C"
+ "%3D%3E%3F%40%5B%5C%5D%5E%60%7B%7C%7D%7F");
+}
+
+void tst_QByteArray::toPercentEncoding()
+{
+ QFETCH(QByteArray, plaintext);
+ QByteArray encoded;
+ QBENCHMARK {
+ encoded = plaintext.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)
+QTEST_MAIN(tst_QByteArray)
-#include "main.moc"
+#include "tst_bench_qbytearray.moc"
diff --git a/tests/benchmarks/corelib/text/qchar/CMakeLists.txt b/tests/benchmarks/corelib/text/qchar/CMakeLists.txt
index afdf96e9d4..136d3ef6fa 100644
--- a/tests/benchmarks/corelib/text/qchar/CMakeLists.txt
+++ b/tests/benchmarks/corelib/text/qchar/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qchar.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qchar Binary:
@@ -6,7 +7,7 @@
qt_internal_add_benchmark(tst_bench_qchar
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qchar.cpp
+ LIBRARIES
Qt::Test
)
diff --git a/tests/benchmarks/corelib/text/qchar/main.cpp b/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp
index 746f9730f7..194dd27d36 100644
--- a/tests/benchmarks/corelib/text/qchar/main.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>
@@ -133,4 +108,4 @@ void tst_QChar::isSpace()
QTEST_MAIN(tst_QChar)
-#include "main.moc"
+#include "tst_bench_qchar.moc"
diff --git a/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt b/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt
index 1c692af6c8..04c2f69b9f 100644
--- a/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt
+++ b/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qlocale.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qlocale Binary:
@@ -6,7 +7,7 @@
qt_internal_add_benchmark(tst_bench_qlocale
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qlocale.cpp
+ LIBRARIES
Qt::Test
)
diff --git a/tests/benchmarks/corelib/text/qlocale/main.cpp b/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp
index 887053ae4a..3d13174c9c 100644
--- a/tests/benchmarks/corelib/text/qlocale/main.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: &minus;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&minus;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: &infin;") << 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: &infin;", "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 "main.moc"
+#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 4b443cd4aa..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:
@@ -6,7 +7,7 @@
qt_internal_add_benchmark(tst_bench_qstring
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qstring.cpp
+ LIBRARIES
Qt::Test
)
diff --git a/tests/benchmarks/corelib/text/qstring/main.cpp b/tests/benchmarks/corelib/text/qstring/main.cpp
deleted file mode 100644
index 0214931b71..0000000000
--- a/tests/benchmarks/corelib/text/qstring/main.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-#include <QStringList>
-#include <QFile>
-#include <QTest>
-
-class tst_QString: public QObject
-{
- Q_OBJECT
-public:
- tst_QString();
-private slots:
- void section_regexp_data() { section_data_impl(); }
- void section_regularexpression_data() { section_data_impl(); }
- void section_regularexpression() { section_impl<QRegularExpression>(); }
- void section_string_data() { section_data_impl(false); }
- void section_string() { section_impl<QString>(); }
-
- void toUpper_data();
- void toUpper();
- void toLower_data();
- void toLower();
- void toCaseFolded_data();
- void toCaseFolded();
-
-private:
- void section_data_impl(bool includeRegExOnly = true);
- template <typename RX> void section_impl();
-};
-
-tst_QString::tst_QString()
-{
-}
-
-void tst_QString::section_data_impl(bool includeRegExOnly)
-{
- QTest::addColumn<QString>("s");
- QTest::addColumn<QString>("sep");
- QTest::addColumn<bool>("isRegExp");
-
- QTest::newRow("IPv4") << QStringLiteral("192.168.0.1") << QStringLiteral(".") << false;
- QTest::newRow("IPv6") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral(":") << false;
- if (includeRegExOnly) {
- QTest::newRow("IPv6-reversed-roles") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral("\\d+") << true;
- QTest::newRow("IPv6-complex") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral("(\\d+):\\1") << true;
- }
-}
-
-template <typename RX>
-inline QString escape(const QString &s)
-{ return RX::escape(s); }
-
-template <>
-inline QString escape<QString>(const QString &s)
-{ return s; }
-
-template <typename RX>
-inline void optimize(RX &) {}
-
-template <>
-inline void optimize(QRegularExpression &rx)
-{ rx.optimize(); }
-
-template <typename RX>
-void tst_QString::section_impl()
-{
- QFETCH(QString, s);
- QFETCH(QString, sep);
- QFETCH(bool, isRegExp);
-
- RX rx(isRegExp ? sep : escape<RX>(sep));
- optimize(rx);
- for (int i = 0; i < 20; ++i)
- (void) s.count(rx); // make (s, rx) hot
-
- QBENCHMARK {
- const QString result = s.section(rx, 0, 16);
- Q_UNUSED(result);
- }
-}
-
-void tst_QString::toUpper_data()
-{
- QTest::addColumn<QString>("s");
-
- QString lowerLatin1(300, QChar('a'));
- QString upperLatin1(300, QChar('A'));
-
- QString lowerDeseret;
- {
- QString pattern;
- pattern += QChar(QChar::highSurrogate(0x10428));
- pattern += QChar(QChar::lowSurrogate(0x10428));
- for (int i = 0; i < 300 / pattern.size(); ++i)
- lowerDeseret += pattern;
- }
- QString upperDeseret;
- {
- QString pattern;
- pattern += QChar(QChar::highSurrogate(0x10400));
- pattern += QChar(QChar::lowSurrogate(0x10400));
- for (int i = 0; i < 300 / pattern.size(); ++i)
- upperDeseret += pattern;
- }
-
- QString lowerLigature(600, QChar(0xFB03));
-
- QTest::newRow("600<a>") << (lowerLatin1 + lowerLatin1);
- QTest::newRow("600<A>") << (upperLatin1 + upperLatin1);
-
- QTest::newRow("300<a>+300<A>") << (lowerLatin1 + upperLatin1);
- QTest::newRow("300<A>+300<a>") << (upperLatin1 + lowerLatin1);
-
- QTest::newRow("300<10428>") << (lowerDeseret + lowerDeseret);
- QTest::newRow("300<10400>") << (upperDeseret + upperDeseret);
-
- QTest::newRow("150<10428>+150<10400>") << (lowerDeseret + upperDeseret);
- QTest::newRow("150<10400>+150<10428>") << (upperDeseret + lowerDeseret);
-
- QTest::newRow("300a+150<10400>") << (lowerLatin1 + upperDeseret);
- QTest::newRow("300a+150<10428>") << (lowerLatin1 + lowerDeseret);
- QTest::newRow("300A+150<10400>") << (upperLatin1 + upperDeseret);
- QTest::newRow("300A+150<10428>") << (upperLatin1 + lowerDeseret);
-
- QTest::newRow("600<FB03> (ligature)") << lowerLigature;
-}
-
-void tst_QString::toUpper()
-{
- QFETCH(QString, s);
-
- QBENCHMARK {
- s.toUpper();
- }
-}
-
-void tst_QString::toLower_data()
-{
- toUpper_data();
-}
-
-void tst_QString::toLower()
-{
- QFETCH(QString, s);
-
- QBENCHMARK {
- s.toLower();
- }
-}
-
-void tst_QString::toCaseFolded_data()
-{
- toUpper_data();
-}
-
-void tst_QString::toCaseFolded()
-{
- QFETCH(QString, s);
-
- QBENCHMARK {
- s.toCaseFolded();
- }
-}
-
-QTEST_APPLESS_MAIN(tst_QString)
-
-#include "main.moc"
diff --git a/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp b/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp
new file mode 100644
index 0000000000..da5c0ff359
--- /dev/null
+++ b/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp
@@ -0,0 +1,510 @@
+// 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
+public:
+ tst_QString();
+private slots:
+ void section_regexp_data() { section_data_impl(); }
+ void section_regularexpression_data() { section_data_impl(); }
+ void section_regularexpression() { section_impl<QRegularExpression>(); }
+ void section_string_data() { section_data_impl(false); }
+ void section_string() { section_impl<QString>(); }
+
+ void toUpper_data();
+ void toUpper();
+ void toLower_data();
+ void toLower();
+ void toCaseFolded_data();
+ void toCaseFolded();
+
+ // Serializing:
+ void number_qlonglong_data();
+ void number_qlonglong() { number_impl<qlonglong>(); }
+ void number_qulonglong_data();
+ void number_qulonglong() { number_impl<qulonglong>(); }
+
+ 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()
+{
+}
+
+void tst_QString::section_data_impl(bool includeRegExOnly)
+{
+ QTest::addColumn<QString>("s");
+ QTest::addColumn<QString>("sep");
+ QTest::addColumn<bool>("isRegExp");
+
+ QTest::newRow("IPv4") << QStringLiteral("192.168.0.1") << QStringLiteral(".") << false;
+ QTest::newRow("IPv6") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral(":") << false;
+ if (includeRegExOnly) {
+ QTest::newRow("IPv6-reversed-roles") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral("\\d+") << true;
+ QTest::newRow("IPv6-complex") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral("(\\d+):\\1") << true;
+ }
+}
+
+template <typename RX>
+inline QString escape(const QString &s)
+{ return RX::escape(s); }
+
+template <>
+inline QString escape<QString>(const QString &s)
+{ return s; }
+
+template <typename RX>
+inline void optimize(RX &) {}
+
+template <>
+inline void optimize(QRegularExpression &rx)
+{ rx.optimize(); }
+
+template <typename RX>
+void tst_QString::section_impl()
+{
+ QFETCH(QString, s);
+ QFETCH(QString, sep);
+ QFETCH(bool, isRegExp);
+
+ RX rx(isRegExp ? sep : escape<RX>(sep));
+ optimize(rx);
+ for (int i = 0; i < 20; ++i)
+ (void) s.count(rx); // make (s, rx) hot
+
+ QBENCHMARK {
+ const QString result = s.section(rx, 0, 16);
+ Q_UNUSED(result);
+ }
+}
+
+void tst_QString::toUpper_data()
+{
+ QTest::addColumn<QString>("s");
+
+ QString lowerLatin1(300, QChar('a'));
+ QString upperLatin1(300, QChar('A'));
+
+ QString lowerDeseret;
+ {
+ QString pattern;
+ pattern += QChar(QChar::highSurrogate(0x10428));
+ pattern += QChar(QChar::lowSurrogate(0x10428));
+ for (int i = 0; i < 300 / pattern.size(); ++i)
+ lowerDeseret += pattern;
+ }
+ QString upperDeseret;
+ {
+ QString pattern;
+ pattern += QChar(QChar::highSurrogate(0x10400));
+ pattern += QChar(QChar::lowSurrogate(0x10400));
+ for (int i = 0; i < 300 / pattern.size(); ++i)
+ upperDeseret += pattern;
+ }
+
+ QString lowerLigature(600, QChar(0xFB03));
+
+ QTest::newRow("600<a>") << (lowerLatin1 + lowerLatin1);
+ QTest::newRow("600<A>") << (upperLatin1 + upperLatin1);
+
+ QTest::newRow("300<a>+300<A>") << (lowerLatin1 + upperLatin1);
+ QTest::newRow("300<A>+300<a>") << (upperLatin1 + lowerLatin1);
+
+ QTest::newRow("300<10428>") << (lowerDeseret + lowerDeseret);
+ QTest::newRow("300<10400>") << (upperDeseret + upperDeseret);
+
+ QTest::newRow("150<10428>+150<10400>") << (lowerDeseret + upperDeseret);
+ QTest::newRow("150<10400>+150<10428>") << (upperDeseret + lowerDeseret);
+
+ QTest::newRow("300a+150<10400>") << (lowerLatin1 + upperDeseret);
+ QTest::newRow("300a+150<10428>") << (lowerLatin1 + lowerDeseret);
+ QTest::newRow("300A+150<10400>") << (upperLatin1 + upperDeseret);
+ QTest::newRow("300A+150<10428>") << (upperLatin1 + lowerDeseret);
+
+ QTest::newRow("600<FB03> (ligature)") << lowerLigature;
+}
+
+void tst_QString::toUpper()
+{
+ QFETCH(QString, s);
+
+ QBENCHMARK {
+ [[maybe_unused]] auto r = s.toUpper();
+ }
+}
+
+void tst_QString::toLower_data()
+{
+ toUpper_data();
+}
+
+void tst_QString::toLower()
+{
+ QFETCH(QString, s);
+
+ QBENCHMARK {
+ [[maybe_unused]] auto r = s.toLower();
+ }
+}
+
+void tst_QString::toCaseFolded_data()
+{
+ toUpper_data();
+}
+
+void tst_QString::toCaseFolded()
+{
+ QFETCH(QString, s);
+
+ QBENCHMARK {
+ [[maybe_unused]] auto r = s.toCaseFolded();
+ }
+}
+
+template <typename Integer>
+void tst_QString::number_impl()
+{
+ QFETCH(Integer, number);
+ QFETCH(int, base);
+ QFETCH(QString, expected);
+
+ QString actual;
+ QBENCHMARK {
+ actual = QString::number(number, base);
+ }
+ QCOMPARE(actual, expected);
+}
+
+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");
+ QTest::newRow("bad1dea, base 16") << Integer(0xBAD1DEAull) << 16 << QStringLiteral("bad1dea");
+ QTest::newRow("242, base 8") << Integer(0242ull) << 8 << QStringLiteral("242");
+ QTest::newRow("101101, base 2") << Integer(0b101101ull) << 2 << QStringLiteral("101101");
+ QTest::newRow("ad, base 30") << Integer(313ull) << 30 << QStringLiteral("ad");
+}
+
+void tst_QString::number_qlonglong_data()
+{
+ number_integer_common<qlonglong>();
+
+ QTest::newRow("-1234") << -1234ll << 10 << QStringLiteral("-1234");
+ QTest::newRow("-123456789") << -123456789ll << 10 << QStringLiteral("-123456789");
+ QTest::newRow("-bad1dea, base 16") << -0xBAD1DEAll << 16 << QStringLiteral("-bad1dea");
+ QTest::newRow("-242, base 8") << -0242ll << 8 << QStringLiteral("-242");
+ QTest::newRow("-101101, base 2") << -0b101101ll << 2 << QStringLiteral("-101101");
+ QTest::newRow("-ad, base 30") << -313ll << 30 << QStringLiteral("-ad");
+
+ QTest::newRow("qlonglong-max")
+ << std::numeric_limits<qlonglong>::max() << 10 << QStringLiteral("9223372036854775807");
+ QTest::newRow("qlonglong-min")
+ << std::numeric_limits<qlonglong>::min() << 10
+ << QStringLiteral("-9223372036854775808");
+ QTest::newRow("qlonglong-max, base 2")
+ << std::numeric_limits<qlonglong>::max() << 2 << QString(63, u'1');
+ QTest::newRow("qlonglong-min, base 2") << std::numeric_limits<qlonglong>::min() << 2
+ << (QStringLiteral("-1") + QString(63, u'0'));
+ QTest::newRow("qlonglong-max, base 16")
+ << std::numeric_limits<qlonglong>::max() << 16 << (QChar(u'7') + QString(15, u'f'));
+ QTest::newRow("qlonglong-min, base 16") << std::numeric_limits<qlonglong>::min() << 16
+ << (QStringLiteral("-8") + QString(15, u'0'));
+}
+
+void tst_QString::number_qulonglong_data()
+{
+ number_integer_common<qulonglong>();
+
+ QTest::newRow("qlonglong-max + 1")
+ << (qulonglong(std::numeric_limits<qlonglong>::max()) + 1) << 10
+ << QStringLiteral("9223372036854775808");
+ QTest::newRow("qulonglong-max")
+ << std::numeric_limits<qulonglong>::max() << 10
+ << QStringLiteral("18446744073709551615");
+ QTest::newRow("qulonglong-max, base 2")
+ << std::numeric_limits<qulonglong>::max() << 2 << QString(64, u'1');
+ QTest::newRow("qulonglong-max, base 16")
+ << std::numeric_limits<qulonglong>::max() << 16 << QString(16, u'f');
+}
+
+void tst_QString::number_double_data()
+{
+ QTest::addColumn<double>("number");
+ QTest::addColumn<char>("format");
+ QTest::addColumn<int>("precision");
+ QTest::addColumn<QString>("expected");
+
+ struct
+ {
+ double d;
+ char f;
+ int p;
+ QString expected;
+ } data[] = {
+ { 0.0, 'f', 0, QStringLiteral("0") },
+ { 0.0001, 'f', 0, QStringLiteral("0") },
+ { 0.1234, 'f', 5, QStringLiteral("0.12340") },
+ { -0.1234, 'f', 5, QStringLiteral("-0.12340") },
+ { 0.5 + qSqrt(1.25), 'f', 15, QStringLiteral("1.618033988749895") },
+ { std::numeric_limits<double>::epsilon(), 'g', 10, QStringLiteral("2.220446049e-16") },
+ { 0.0001, 'E', 1, QStringLiteral("1.0E-04") },
+ { 1e8, 'E', 1, QStringLiteral("1.0E+08") },
+ { -1e8, 'E', 1, QStringLiteral("-1.0E+08") },
+ };
+
+ for (auto &datum : data) {
+ QTest::addRow("%s, format '%c', precision %d", qPrintable(datum.expected), datum.f,
+ datum.p)
+ << datum.d << datum.f << datum.p << datum.expected;
+ }
+}
+
+void tst_QString::number_double()
+{
+ QFETCH(double, number);
+ QFETCH(char, format);
+ QFETCH(int, precision);
+ QFETCH(QString, expected);
+
+ QString actual;
+ QBENCHMARK {
+ actual = QString::number(number, format, precision);
+ }
+ 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 33b1b5fe5e..c3c95e233c 100644
--- a/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt
+++ b/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qstringbuilder.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qstringbuilder Binary:
@@ -6,13 +7,9 @@
qt_internal_add_benchmark(tst_bench_qstringbuilder
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qstringbuilder.cpp
+ LIBRARIES
Qt::Test
COMPILE_OPTIONS
-g
)
-
-#### Keys ignored in scope 1:.:.:qstringbuilder.pro:<TRUE>:
-# QMAKE_CFLAGS = "-g"
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/text/qstringbuilder/main.cpp b/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp
index 757e2cc683..496abdaf3b 100644
--- a/tests/benchmarks/corelib/text/qstringbuilder/main.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
@@ -96,12 +71,12 @@
#define LITERAL "some string literal"
-class tst_qstringbuilder : public QObject
+class tst_QStringBuilder : public QObject
{
Q_OBJECT
public:
- tst_qstringbuilder()
+ tst_QStringBuilder()
: l1literal(LITERAL),
l1string(LITERAL),
ba(LITERAL),
@@ -408,8 +383,8 @@ private:
std::string stdr;
};
-QTEST_MAIN(tst_qstringbuilder)
-
#undef P
-#include "main.moc"
+QTEST_MAIN(tst_QStringBuilder)
+
+#include "tst_bench_qstringbuilder.moc"
diff --git a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt
index 4649e3408a..da2f84d6e9 100644
--- a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt
+++ b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qstringlist.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qstringlist Binary:
@@ -6,7 +7,7 @@
qt_internal_add_benchmark(tst_bench_qstringlist
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qstringlist.cpp
+ LIBRARIES
Qt::Test
)
diff --git a/tests/benchmarks/corelib/text/qstringlist/main.cpp b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp
index eb507c7c64..2431446bf6 100644
--- a/tests/benchmarks/corelib/text/qstringlist/main.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;
}
@@ -93,7 +75,7 @@ void tst_QStringList::join() const
QFETCH(QString, separator);
QBENCHMARK {
- input.join(separator);
+ [[maybe_unused]] auto r = input.join(separator);
}
}
@@ -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");
@@ -173,7 +188,7 @@ void tst_QStringList::split_qlist_qbytearray() const
QByteArray ba = input.toLatin1();
QBENCHMARK {
- ba.split(splitChar);
+ [[maybe_unused]] auto r = ba.split(splitChar);
}
}
@@ -183,7 +198,7 @@ void tst_QStringList::split_qlist_qstring() const
const QChar splitChar = ':';
QBENCHMARK {
- input.split(splitChar);
+ [[maybe_unused]] auto r = input.split(splitChar);
}
}
@@ -237,4 +252,4 @@ void tst_QStringList::split_stdlist_stdstring() const
QTEST_MAIN(tst_QStringList)
-#include "main.moc"
+#include "tst_bench_qstringlist.moc"
diff --git a/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt
index c2bf848400..11720e5204 100644
--- a/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt
+++ b/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt
@@ -1,11 +1,14 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#####################################################################
## tst_bench_qstringtokenizer Binary:
#####################################################################
qt_internal_add_benchmark(tst_bench_qstringtokenizer
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qstringtokenizer.cpp
+ LIBRARIES
Qt::Test
)
diff --git a/tests/benchmarks/corelib/text/qstringtokenizer/main.cpp b/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp
index 54f48d5ea5..eccfad91da 100644
--- a/tests/benchmarks/corelib/text/qstringtokenizer/main.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>
@@ -142,4 +117,4 @@ void tst_QStringTokenizer::tokenize() const
QTEST_MAIN(tst_QStringTokenizer)
-#include "main.moc"
+#include "tst_bench_qstringtokenizer.moc"
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"