aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-12-18 14:22:38 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-12-19 12:39:38 +0100
commit3d12a83170fe3e9fcf61605bbb6ee717a9c983b5 (patch)
treecaaebc2657c2a6faedfcdb216d7a0b0095222380 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parentf90bdf9d7ab6e289e891b18b3902df24123803a8 (diff)
QmlCompiler: Coerce values when calling methods
The type of the register may not be the one to be passed to the method. We cannot rely on the run time internals to coerce the value anymore since we've moved the type determination out of the generated code. To make this happen, we need to adjust the storage types of read registers in the storage generalizer. Pick-to: 6.9 Fixes: QTBUG-132329 Change-Id: I642027f349f7c05f714ec36ef4e23f9d59b4a8df Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 8c11487793..3e96ad1558 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -9,10 +9,11 @@
#include <data/getOptionalLookup.h>
#include <data/listprovider.h>
#include <data/objectwithmethod.h>
+#include <data/qmlusing.h>
#include <data/resettable.h>
+#include <data/takenumber.h>
#include <data/weathermoduleurl.h>
#include <data/withlength.h>
-#include <data/qmlusing.h>
#include <QtQml/private/qqmlengine_p.h>
#include <QtQml/private/qqmlpropertycachecreator_p.h>
@@ -239,6 +240,7 @@ private slots:
void stringLength();
void stringToByteArray();
void structuredValueType();
+ void takeNumbers();
void testIsnan();
void thisObject();
void throwObjectName();
@@ -4909,6 +4911,51 @@ void tst_QmlCppCodegen::structuredValueType()
QCOMPARE(o->property("w2").value<WeatherModelUrl>(), w2);
}
+void tst_QmlCppCodegen::takeNumbers()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/takenumber.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ TakeNumber *takeNumber = qobject_cast<TakeNumber *>(o.data());
+ QVERIFY(takeNumber != nullptr);
+
+ QCOMPARE(takeNumber->takenInt, 0);
+ QCOMPARE(takeNumber->takenNegativeInt, 0);
+ QCOMPARE(takeNumber->takenQSizeType, 0);
+ QCOMPARE(takeNumber->takenQLongLong, 0);
+
+ o->metaObject()->invokeMethod(o.data(), "literal56");
+
+ QCOMPARE(takeNumber->takenInt, 56);
+ QCOMPARE(takeNumber->takenNegativeInt, -56);
+ QCOMPARE(takeNumber->takenQSizeType, 56);
+ QCOMPARE(takeNumber->takenQLongLong, 56);
+
+ o->metaObject()->invokeMethod(o.data(), "variable0");
+
+ QCOMPARE(takeNumber->takenInt, 0);
+ QCOMPARE(takeNumber->takenNegativeInt, 0);
+ QCOMPARE(takeNumber->takenQSizeType, 0);
+ QCOMPARE(takeNumber->takenQLongLong, 0);
+
+ o->metaObject()->invokeMethod(o.data(), "variable484");
+
+ QCOMPARE(takeNumber->takenInt, 484);
+ QCOMPARE(takeNumber->takenNegativeInt, -484);
+ QCOMPARE(takeNumber->takenQSizeType, 484);
+ QCOMPARE(takeNumber->takenQLongLong, 484);
+
+ o->metaObject()->invokeMethod(o.data(), "literal0");
+
+ QCOMPARE(takeNumber->takenInt, 0);
+ QCOMPARE(takeNumber->takenNegativeInt, 0);
+ QCOMPARE(takeNumber->takenQSizeType, 0);
+ QCOMPARE(takeNumber->takenQLongLong, 0);
+}
+
void tst_QmlCppCodegen::testIsnan()
{
QQmlEngine engine;