aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/collector.h25
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/collector.qml41
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp20
4 files changed, 88 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 94368c99f7..4b5dd31c0a 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -7,6 +7,7 @@ add_subdirectory(WithSubDir)
set(cpp_sources
ambiguous.h
birthdayparty.cpp birthdayparty.h
+ collector.h
convertQJSPrimitiveValueToIntegral.h
cppbaseclass.h
detachedreferences.h
@@ -118,6 +119,7 @@ set(qml_files
callObjectLookupOnNull.qml
callWithSpread.qml
childobject.qml
+ collector.qml
colorAsVariant.qml
colorString.qml
compareOriginals.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/collector.h b/tests/auto/qml/qmlcppcodegen/data/collector.h
new file mode 100644
index 0000000000..0b892dcb82
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/collector.h
@@ -0,0 +1,25 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef COLLECTOR_H
+#define COLLECTOR_H
+
+#include <QtCore/qobject.h>
+#include <QtQmlIntegration/qqmlintegration.h>
+#include <QtQml/qjsengine.h>
+
+class Collector : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ Q_PROPERTY(int gc READ gc CONSTANT)
+
+public:
+ int gc() const
+ {
+ qjsEngine(this)->collectGarbage();
+ return 1;
+ }
+};
+
+#endif // COLLECTOR_H
diff --git a/tests/auto/qml/qmlcppcodegen/data/collector.qml b/tests/auto/qml/qmlcppcodegen/data/collector.qml
new file mode 100644
index 0000000000..161a242bcc
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/collector.qml
@@ -0,0 +1,41 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+pragma Strict
+import QtQml
+import TestTypes
+
+Collector {
+ id: self
+ property Component c: QtObject { objectName: "dynamic" }
+ property QtObject o: c.createObject()
+ property QtObject o2
+ property int gcRun: 0
+
+ // Pass the object through a property once so that we know
+ // it has a wrapper (missing wrapper will be fixed independently)
+ property QtObject hidden: c.createObject()
+ function os() : list<var> {
+ let result = [hidden]
+ hidden = null
+ return result
+ }
+
+ Component.onCompleted: {
+ var oo = o
+ o = null
+ var oso = os()
+
+ // Hide this behind a property so that the side effect
+ // can't be detected.
+ var one = self.gc
+
+ // Don't rely on QV4::Sequence to check its members, yet
+ o2 = oso[0]
+ o = oo
+
+ // Actually use the value retrieved to trigger the gc
+ // Otherwise the access is optimized out.
+ gcRun = one
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 7e116e9d6f..243b6b1296 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -72,6 +72,7 @@ private slots:
void callContextPropertyLookupResult();
void callObjectLookupOnNull();
void callWithSpread();
+ void collectGarbageDuringAotCode();
void colorAsVariant();
void colorString();
void compareOriginals();
@@ -1100,6 +1101,25 @@ void tst_QmlCppCodegen::callWithSpread()
QVERIFY(!o.isNull());
}
+void tst_QmlCppCodegen::collectGarbageDuringAotCode()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/collector.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ QObject *inner = o->property("o").value<QObject *>();
+ QVERIFY(inner);
+ QCOMPARE(inner->objectName(), u"dynamic"_s);
+
+ inner = o->property("o2").value<QObject *>();
+ QVERIFY(inner);
+ QCOMPARE(inner->objectName(), u"dynamic"_s);
+
+ QCOMPARE(o->property("gcRun").toInt(), 1);
+}
+
void tst_QmlCppCodegen::colorAsVariant()
{
QQmlEngine engine;