summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp40
-rw-r--r--tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp13
-rw-r--r--tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp5
-rw-r--r--tests/benchmarks/corelib/CMakeLists.txt1
-rw-r--r--tests/benchmarks/corelib/platform/CMakeLists.txt6
-rw-r--r--tests/benchmarks/corelib/platform/androiditemmodel/CMakeLists.txt24
-rw-r--r--tests/benchmarks/corelib/platform/androiditemmodel/testdata/src/org/qtproject/qt/android/benchmark/BenchQtAbstractItemModel.java56
-rw-r--r--tests/benchmarks/corelib/platform/androiditemmodel/tst_bench_androiditemmodel.cpp144
8 files changed, 258 insertions, 31 deletions
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index e57cc732ee2..170c38d57c1 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -15,6 +15,8 @@
#include <QtTest/private/qtesthelpers_p.h>
+#include <QtCore/qscopeguard.h>
+
#if defined(Q_OS_WIN)
# include <shlwapi.h>
# include <qt_windows.h>
@@ -552,6 +554,12 @@ void tst_QTemporaryFile::stressTest()
const int iterations = 1000;
QSet<QString> names;
+
+ const auto remover = qScopeGuard([&] {
+ for (const QString &s : std::as_const(names))
+ QFile::remove(s);
+ });
+
for (int i = 0; i < iterations; ++i) {
QTemporaryFile file;
file.setAutoRemove(false);
@@ -559,9 +567,6 @@ void tst_QTemporaryFile::stressTest()
QVERIFY(!names.contains(file.fileName()));
names.insert(file.fileName());
}
- for (QSet<QString>::const_iterator it = names.constBegin(); it != names.constEnd(); ++it) {
- QFile::remove(*it);
- }
}
void tst_QTemporaryFile::rename()
@@ -821,37 +826,26 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename()
#if defined(Q_OS_VXWORKS)
QSKIP("QTBUG-130066");
#endif
- struct CleanOnReturn
- {
- ~CleanOnReturn()
- {
+
+ QString tempName;
+ auto cleaner = qScopeGuard([&] {
if (!tempName.isEmpty())
QFile::remove(tempName);
- }
-
- void reset()
- {
- tempName.clear();
- }
-
- QString tempName;
- };
-
- CleanOnReturn cleaner;
+ });
{
QTemporaryFile file;
QVERIFY( file.open() );
- cleaner.tempName = file.fileName();
+ tempName = file.fileName();
- QVERIFY( QFile::exists(cleaner.tempName) );
+ QVERIFY(QFile::exists(tempName));
QVERIFY( !QFileInfo("i-do-not-exist").isDir() );
QVERIFY( !file.rename("i-do-not-exist/file.txt") );
- QVERIFY( QFile::exists(cleaner.tempName) );
+ QVERIFY(QFile::exists(tempName));
}
- QVERIFY( !QFile::exists(cleaner.tempName) );
- cleaner.reset();
+ QVERIFY(!QFile::exists(tempName));
+ cleaner.dismiss(); // would fail: file is known to no longer exist
}
void tst_QTemporaryFile::createNativeFile_data()
diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp
index 6dd8a6d07f9..0254cbd1360 100644
--- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp
+++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp
@@ -1379,17 +1379,14 @@ void tst_QTextStream::pos2()
// ------------------------------------------------------------------------------
void tst_QTextStream::pos3LargeFile()
{
- if (QTestPrivate::isRunningArmOnX86())
- QSKIP("Running QTextStream::pos() in tight loop is too slow on emulator");
-
{
QFile file(testFileName);
QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text));
QTextStream out( &file );
// NOTE: The unusual spacing is to ensure non-1-character whitespace.
QString lineString = " 0 1 2\t3 4\t \t5 6 7 8 9 \n";
- // Approximate 50kb text file
- const int NbLines = (50*1024) / lineString.size() + 1;
+ // Approximately 5kb text file (more is too slow (QTBUG-138435))
+ const int NbLines = (5 * 1024) / lineString.size() + 1;
for (int line = 0; line < NbLines; ++line)
QVERIFY(out << lineString);
// File is automatically flushed and closed on destruction.
@@ -1397,11 +1394,11 @@ void tst_QTextStream::pos3LargeFile()
QFile file(testFileName);
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
QTextStream in( &file );
- const int testValues[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- int value;
+ constexpr int testValues[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
while (true) {
in.pos();
- for ( int i = 0; i < 10; ++i ) {
+ for (size_t i = 0; i < std::size(testValues); ++i) {
+ int value = -42;
if (!(in >> value)) {
// End case, i == 0 && eof reached.
QCOMPARE(i, 0);
diff --git a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
index eecc8b52d28..bd95174c932 100644
--- a/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
+++ b/tests/auto/corelib/tools/qduplicatetracker/tst_qduplicatetracker.cpp
@@ -120,6 +120,11 @@ void tst_QDuplicateTracker::appendTo()
QList<int> b;
tracker.appendTo(b);
+ // iteration order is append order:
+ QVERIFY(std::equal(b.cbegin(), b.cend(),
+ tracker.cbegin(), tracker.cend()));
+ QVERIFY(std::equal(b.cbegin(), b.cend(),
+ tracker.begin(), tracker.end()));
std::sort(b.begin(), b.end());
QCOMPARE(b, QList<int>({ 0, 1 }));
diff --git a/tests/benchmarks/corelib/CMakeLists.txt b/tests/benchmarks/corelib/CMakeLists.txt
index 890cbcfc6b8..42e1d2cb96d 100644
--- a/tests/benchmarks/corelib/CMakeLists.txt
+++ b/tests/benchmarks/corelib/CMakeLists.txt
@@ -14,3 +14,4 @@ add_subdirectory(time)
add_subdirectory(tools)
add_subdirectory(plugin)
add_subdirectory(serialization)
+add_subdirectory(platform)
diff --git a/tests/benchmarks/corelib/platform/CMakeLists.txt b/tests/benchmarks/corelib/platform/CMakeLists.txt
new file mode 100644
index 00000000000..68844c1c8f7
--- /dev/null
+++ b/tests/benchmarks/corelib/platform/CMakeLists.txt
@@ -0,0 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(ANDROID)
+ add_subdirectory(androiditemmodel)
+endif()
diff --git a/tests/benchmarks/corelib/platform/androiditemmodel/CMakeLists.txt b/tests/benchmarks/corelib/platform/androiditemmodel/CMakeLists.txt
new file mode 100644
index 00000000000..b72d0564c1a
--- /dev/null
+++ b/tests/benchmarks/corelib/platform/androiditemmodel/CMakeLists.txt
@@ -0,0 +1,24 @@
+# Copyright (C) 2025 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_androiditemmodel Test:
+#####################################################################
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_bench_androiditemmodel LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_bench_androiditemmodel
+ SOURCES
+ tst_bench_androiditemmodel.cpp
+ LIBRARIES
+ Qt::Gui
+ Qt::CorePrivate
+)
+
+set_property(TARGET tst_androiditemmodel PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
+ ${CMAKE_CURRENT_SOURCE_DIR}/testdata
+)
diff --git a/tests/benchmarks/corelib/platform/androiditemmodel/testdata/src/org/qtproject/qt/android/benchmark/BenchQtAbstractItemModel.java b/tests/benchmarks/corelib/platform/androiditemmodel/testdata/src/org/qtproject/qt/android/benchmark/BenchQtAbstractItemModel.java
new file mode 100644
index 00000000000..79b07b3fd04
--- /dev/null
+++ b/tests/benchmarks/corelib/platform/androiditemmodel/testdata/src/org/qtproject/qt/android/benchmark/BenchQtAbstractItemModel.java
@@ -0,0 +1,56 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+package org.qtproject.qt.android.benchmark;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.qtproject.qt.android.QtAbstractItemModel;
+import org.qtproject.qt.android.QtModelIndex;
+
+public class BenchQtAbstractItemModel
+ extends QtAbstractItemModel
+{
+ int m_rows = 1;
+ int m_cols = 1;
+
+ @Override
+ public int columnCount(QtModelIndex parent)
+ {
+ return m_cols;
+ }
+
+ @Override
+ public Object data(QtModelIndex index, int role)
+ {
+ return null;
+ }
+
+ @Override
+ public QtModelIndex index(int row, int column, QtModelIndex parent)
+ {
+ return createIndex(row, column, 0);
+ }
+
+ @Override
+ public QtModelIndex parent(QtModelIndex qtModelIndex)
+ {
+ return new QtModelIndex();
+ }
+
+ @Override
+ public int rowCount(QtModelIndex parent)
+ {
+ return m_rows;
+ }
+
+ @Override
+ public HashMap<Integer, String> roleNames()
+ {
+ final HashMap<Integer, String> roles = new HashMap<Integer, String>();
+ roles.put(0, "integerRole");
+ return roles;
+ }
+}
diff --git a/tests/benchmarks/corelib/platform/androiditemmodel/tst_bench_androiditemmodel.cpp b/tests/benchmarks/corelib/platform/androiditemmodel/tst_bench_androiditemmodel.cpp
new file mode 100644
index 00000000000..c7079e147a7
--- /dev/null
+++ b/tests/benchmarks/corelib/platform/androiditemmodel/tst_bench_androiditemmodel.cpp
@@ -0,0 +1,144 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtTest/QTest>
+
+#include <QtCore/private/qandroiditemmodelproxy_p.h>
+#include <QtCore/private/qandroidmodelindexproxy_p.h>
+#include <QtCore/private/qandroidtypes_p.h>
+
+#include <QGuiApplication>
+#include <QtCore/qabstractitemmodel.h>
+#include <QtCore/qjniobject.h>
+#include <QtCore/qjnitypes.h>
+#include <QtCore/qstring.h>
+#include <QSignalSpy>
+#include <memory>
+
+using namespace Qt::Literals;
+
+Q_DECLARE_JNI_CLASS(BenchQtAbstractItemModel,
+ "org/qtproject/qt/android/benchmark/BenchQtAbstractItemModel")
+
+class BenchNativeAbstractItemModel : public QAbstractItemModel {
+ Q_OBJECT
+ int m_rows = 1;
+ int m_cols = 1;
+
+ public:
+
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override {
+ return m_cols;
+ }
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override {
+ return m_rows;
+ }
+
+ QVariant data(const QModelIndex &index, int role) const override {
+ return QVariant();
+ }
+
+ QModelIndex index(int row, int column, const QModelIndex &parent) const override {
+ return createIndex(row, column, quintptr(0));
+ }
+
+ QModelIndex parent(const QModelIndex &index) const override
+ {
+ return QModelIndex();
+ }
+
+ QHash<int, QByteArray> roleNames() const override {
+ static QHash<int, QByteArray> roles = {
+ {0, "integerRole"}
+ };
+ return roles;
+ }
+
+};
+
+class tst_BenchAndroidItemModel : public QObject
+{
+ Q_OBJECT
+ QtJniTypes::BenchQtAbstractItemModel m_jModel;
+ std::unique_ptr<QAbstractItemModel> qProxy;
+ std::unique_ptr<QAbstractItemModel> nativeModel;
+
+private slots:
+ void init();
+
+ void proxiedData();
+ void nativeData();
+
+ void proxiedRowCount();
+ void nativeRowCount();
+
+ void proxiedColumnCount();
+ void nativeColumnCount();
+
+ void proxiedIndex();
+ void nativeIndex();
+};
+
+void tst_BenchAndroidItemModel::init()
+{
+ m_jModel = QJniObject::construct<QtJniTypes::BenchQtAbstractItemModel>();
+ QVERIFY(m_jModel.isValid());
+ qProxy = std::unique_ptr<QAbstractItemModel>(QAndroidItemModelProxy::createNativeProxy(jModel));
+ nativeModel = std::make_unique<BenchNativeAbstractItemModel>();
+ QVERIFY(qProxy);
+}
+
+void tst_BenchAndroidItemModel::proxiedData()
+{
+ QCOMPARE(qProxy->rowCount(), 1);
+ QCOMPARE(qProxy->columnCount(), 1);
+
+ QModelIndex idx = qProxy->index(0, 0, QModelIndex());
+
+ QBENCHMARK { qProxy->data(idx, 0); }
+}
+
+void tst_BenchAndroidItemModel::nativeData()
+{
+ QCOMPARE(nativeModel->rowCount(), 1);
+ QCOMPARE(nativeModel->columnCount(), 1);
+
+ QModelIndex idx = nativeModel->index(0, 0, QModelIndex());
+
+ QBENCHMARK { nativeModel->data(idx, 0); }
+}
+
+void tst_BenchAndroidItemModel::proxiedRowCount()
+{
+ QBENCHMARK { qProxy->rowCount(QModelIndex()); }
+}
+
+void tst_BenchAndroidItemModel::nativeRowCount()
+{
+ QBENCHMARK { nativeModel->rowCount(QModelIndex()); }
+}
+
+void tst_BenchAndroidItemModel::proxiedColumnCount()
+{
+ QBENCHMARK { qProxy->columnCount(QModelIndex()); }
+}
+
+void tst_BenchAndroidItemModel::nativeColumnCount()
+{
+ QBENCHMARK { nativeModel->columnCount(QModelIndex()); }
+}
+
+void tst_BenchAndroidItemModel::proxiedIndex()
+{
+ QBENCHMARK { qProxy->index(0, 0, QModelIndex()); }
+}
+
+void tst_BenchAndroidItemModel::nativeIndex()
+{
+ QBENCHMARK { nativeModel->index(0, 0, QModelIndex()); }
+}
+
+#include "tst_bench_androiditemmodel.moc"
+
+QTEST_MAIN(tst_BenchAndroidItemModel)