summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/text/qbytearray
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/text/qbytearray')
-rw-r--r--tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt13
-rw-r--r--tests/benchmarks/corelib/text/qbytearray/qbytearray.pro7
-rw-r--r--tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp (renamed from tests/benchmarks/corelib/text/qbytearray/main.cpp)211
3 files changed, 175 insertions, 56 deletions
diff --git a/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt b/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt
index cdae659c92..1ea3660680 100644
--- a/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt
+++ b/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt
@@ -1,16 +1,13 @@
-# Generated from qbytearray.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qbytearray Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qbytearray
+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/qbytearray.pro b/tests/benchmarks/corelib/text/qbytearray/qbytearray.pro
deleted file mode 100644
index 25af9512d4..0000000000
--- a/tests/benchmarks/corelib/text/qbytearray/qbytearray.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TEMPLATE = app
-CONFIG += benchmark
-QT = core testlib
-
-TARGET = tst_bench_qbytearray
-SOURCES += main.cpp
-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"