aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSami Shalayel <[email protected]>2025-04-10 15:33:13 +0200
committerSami Shalayel <[email protected]>2025-08-22 08:12:40 +0200
commit6e29d65f0b0c41263901341873d809309ba102c1 (patch)
treebd319c75dab203ac93d2f254c190f15a997fccba /tests
parent2547e8be4d507361527d422184d3cae205aa76ff (diff)
qmlcontextpropertydump: add tool for context property searchHEADdev
Add a tool that runs the heuristic for context properties and dumps the .ini generated by the heuristic search, for future calls of qmllint. Add a test. Task-number: QTBUG-128232 Change-Id: I5d03db45f41ef90c6f5d931837aaa466abc33303 Reviewed-by: Ulf Hermann <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/CMakeLists.txt3
-rw-r--r--tests/auto/qml/qmlcontextpropertydump/CMakeLists.txt40
-rw-r--r--tests/auto/qml/qmlcontextpropertydump/data/ContextProperties/src/someFile.cpp24
-rw-r--r--tests/auto/qml/qmlcontextpropertydump/tst_qmlcontextpropertydump.cpp81
4 files changed, 148 insertions, 0 deletions
diff --git a/tests/auto/qml/CMakeLists.txt b/tests/auto/qml/CMakeLists.txt
index ad2416a17a..548a06c4cc 100644
--- a/tests/auto/qml/CMakeLists.txt
+++ b/tests/auto/qml/CMakeLists.txt
@@ -93,6 +93,9 @@ if(QT_FEATURE_process AND NOT CMAKE_CROSSCOMPILING)
add_subdirectory(qmlformat)
add_subdirectory(qmlimportscanner)
add_subdirectory(qmllint)
+ if(QT_FEATURE_qmlcontextpropertydump)
+ add_subdirectory(qmlcontextpropertydump)
+ endif()
add_subdirectory(qmltc_qprocess)
add_subdirectory(qmltyperegistrar)
add_subdirectory(qmlplugindump)
diff --git a/tests/auto/qml/qmlcontextpropertydump/CMakeLists.txt b/tests/auto/qml/qmlcontextpropertydump/CMakeLists.txt
new file mode 100644
index 0000000000..6918399a21
--- /dev/null
+++ b/tests/auto/qml/qmlcontextpropertydump/CMakeLists.txt
@@ -0,0 +1,40 @@
+# Copyright (C) 2025 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmlcontextpropertydump LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+# Collect test data
+file(GLOB_RECURSE test_data_glob
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ data/*)
+list(APPEND test_data ${test_data_glob})
+
+qt_internal_add_test(tst_qmlcontextpropertydump
+ SOURCES
+ tst_qmlcontextpropertydump.cpp
+ LIBRARIES
+ Qt::Gui
+ Qt::QuickTestUtilsPrivate
+ Qt::QmlCompilerPrivate
+ Qt::QmlTypeRegistrarPrivate
+ LintPlugin
+ TESTDATA ${test_data}
+)
+
+qt_internal_extend_target(tst_qmlcontextpropertydump CONDITION ANDROID OR IOS
+ DEFINES
+ QT_QMLTEST_DATADIR=":/data"
+)
+
+qt_internal_extend_target(tst_qmlcontextpropertydump CONDITION NOT ANDROID AND NOT IOS
+ DEFINES
+ QT_QMLTEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data"
+)
+
+if (TARGET qmlcontextpropertydump)
+ add_dependencies(tst_qmlcontextpropertydump Qt::qmlcontextpropertydump)
+endif()
diff --git a/tests/auto/qml/qmlcontextpropertydump/data/ContextProperties/src/someFile.cpp b/tests/auto/qml/qmlcontextpropertydump/data/ContextProperties/src/someFile.cpp
new file mode 100644
index 0000000000..b50f50112c
--- /dev/null
+++ b/tests/auto/qml/qmlcontextpropertydump/data/ContextProperties/src/someFile.cpp
@@ -0,0 +1,24 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QGuiApplication>
+#include <QQmlContext>
+#include <QQuickView>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QQuickView view;
+
+ view.rootContext()->setContextProperty("myContextProperty1", QDateTime::currentDateTime());
+ view.rootContext()->setContextProperty(
+ u"myContextProperty2"_s,
+ QDateTime::currentDateTime());
+ registerContentProperties(view);
+
+ view.loadFromModule("ContextProperty", "Main");
+ view.show();
+
+ return app.exec();
+}
diff --git a/tests/auto/qml/qmlcontextpropertydump/tst_qmlcontextpropertydump.cpp b/tests/auto/qml/qmlcontextpropertydump/tst_qmlcontextpropertydump.cpp
new file mode 100644
index 0000000000..d34f9ae20a
--- /dev/null
+++ b/tests/auto/qml/qmlcontextpropertydump/tst_qmlcontextpropertydump.cpp
@@ -0,0 +1,81 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtQuickTestUtils/private/qmlutils_p.h>
+#include <QtCore/qstring.h>
+#include <QtCore/qprocess.h>
+#include <QtCore/qlibraryinfo.h>
+
+using namespace Qt::StringLiterals;
+
+class tst_qmlcontextpropertydump : public QQmlDataTest
+{
+ Q_OBJECT
+
+public:
+ tst_qmlcontextpropertydump();
+
+private slots:
+ void dump();
+
+private:
+ QString m_executablePath;
+};
+
+tst_qmlcontextpropertydump::tst_qmlcontextpropertydump() : QQmlDataTest(QT_QMLTEST_DATADIR)
+{
+ m_executablePath =
+ QLibraryInfo::path(QLibraryInfo::BinariesPath).append("/qmlcontextpropertydump"_L1);
+
+#ifdef Q_OS_WIN
+ m_executablePath.append(".exe"_L1);
+#endif
+ if (!QFileInfo::exists(m_executablePath))
+ qWarning() << "executable not found (looked for %0)"_L1.arg(m_executablePath);
+}
+
+void tst_qmlcontextpropertydump::dump()
+{
+ QProcess process;
+ process.setProgram(m_executablePath);
+ QTemporaryDir output;
+ QVERIFY(output.isValid());
+ process.setArguments({ "-s"_L1, testFile("ContextProperties"_L1), "-b"_L1, output.path() });
+
+ process.start();
+ QVERIFY(process.waitForFinished());
+ QCOMPARE(process.exitStatus(), QProcess::NormalExit);
+ QCOMPARE(process.exitCode(), 0);
+
+ QFile outputFile(output.filePath(".qt/contextPropertyDump.ini"));
+ QVERIFY(outputFile.open(QFile::ReadOnly | QFile::Text));
+
+ const QString outputFileContent = outputFile.readAll();
+ const QString expectedOutput =
+ R"([cachedHeuristicList]
+1\name=myContextProperty1
+2\name=myContextProperty2
+size=2
+
+[property_myContextProperty1]
+1\fileName=%1/src/someFile.cpp
+1\sourceLocation="324,18,14,45"
+size=1
+
+[property_myContextProperty2]
+1\fileName=%1/src/someFile.cpp
+1\sourceLocation="438,18,16,19"
+size=1
+)"_L1.arg(testFile("ContextProperties"_L1));
+
+ {
+ QFile expectedOutputFile(output.filePath("expected.ini"));
+ QVERIFY(expectedOutputFile.open(QFile::WriteOnly | QFile::Text));
+ expectedOutputFile.write(expectedOutput.toUtf8());
+ }
+
+ QCOMPARE(outputFileContent, expectedOutput);
+}
+
+QTEST_GUILESS_MAIN(tst_qmlcontextpropertydump)
+#include "tst_qmlcontextpropertydump.moc"