diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-11-20 09:55:31 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-11-21 15:25:56 +0100 |
| commit | 7ed5f038fcbe95111a99c90602fbf09368892a13 (patch) | |
| tree | 8cb45de872abce5d43ca60ba62abca253b7bb205 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | 828af69f8cfc2ef66dd80478de0fc5f94053ec2f (diff) | |
QmlCompiler: Add AsVariant initializations for SetLookup
With SetLookup there is always the possibility of causing a reset by
passing undefined. That's why we need to wrap the argument into QVariant
most of the time. SetValueLookup didn't take this into account, which
resulted in invalid code.
The test also reveals that a number of cases were generating different
errors depending on whether the code was run in interpreted or compiled
mode. Align those.
Pick-to: 6.8
Task-number: QTBUG-127174
Change-Id: I88f45977dcd0eeba8aaf580663d4b85b8bb26f72
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 6b6283b854..ad7d9f39b4 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -4226,7 +4226,8 @@ void tst_QmlCppCodegen::propertyOfParent() void tst_QmlCppCodegen::qmlUsing() { QQmlEngine engine; - QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/qmlUsing.qml"_s)); + const QString url = u"qrc:/qt/qml/TestTypes/qmlUsing.qml"_s; + QQmlComponent component(&engine, QUrl(url)); QVERIFY2(component.isReady(), component.errorString().toUtf8()); QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); @@ -4244,13 +4245,24 @@ void tst_QmlCppCodegen::qmlUsing() QCOMPARE(u->property("myA2").toInt(), 7); QCOMPARE(u->property("myB2").toInt(), 5); + QCOMPARE(u->u(), 9u); + QCOMPARE(u->val().u(), 26u); + QCOMPARE(u->property("valU").toUInt(), 26u); + QCOMPARE(u->property("myU").toUInt(), 9u); + QCOMPARE(u->property("myU2").toUInt(), 9u); + QList<int> as; QList<int> bs; + QList<uint> us; QObject::connect(u, &UsingUserObject::aChanged, this, [&]() { as.append(u->a()); bs.append(u->getB()); }); + QObject::connect(u, &UsingUserObject::uChanged, this, [&]() { + us.append(u->u()); + }); + QMetaObject::invokeMethod(object.data(), "twiddle"); const QList<int> expectedA = { 57, 59 }; @@ -4259,6 +4271,9 @@ void tst_QmlCppCodegen::qmlUsing() const QList<int> expectedB = { 5, 58 }; QCOMPARE(bs, expectedB); + const QList<uint> expectedU = { 62, 63 }; + QCOMPARE(us, expectedU); + QCOMPARE(u->a(), 59); QCOMPARE(u->getB(), 60); QCOMPARE(u->val().a(), 55); @@ -4268,6 +4283,65 @@ void tst_QmlCppCodegen::qmlUsing() QCOMPARE(u->property("myB").toInt(), 5); // Remains 5, due to lack of signaling QCOMPARE(u->property("myA2").toInt(), 59); QCOMPARE(u->property("myB2").toInt(), 5); // Remains 5, due to lack of signaling + + QCOMPARE(u->u(), 63u); + QCOMPARE(u->val().u(), 61u); + QCOMPARE(u->property("valU").toUInt(), 61u); + QCOMPARE(u->property("myU").toUInt(), 63u); + QCOMPARE(u->property("myU2").toUInt(), 63u); + + + QMetaObject::invokeMethod(object.data(), "burn"); + + const uint huge = 4294967295; + + const QList<uint> expectedU2 = { 62, 63, huge, 64, huge }; + QCOMPARE(us, expectedU2); + + QCOMPARE(u->u(), huge); + QCOMPARE(u->val().u(), huge); + QCOMPARE(u->property("valU").toUInt(), huge); + QCOMPARE(u->property("myU").toUInt(), huge); + QCOMPARE(u->property("myU2").toUInt(), huge); + + QMetaObject::invokeMethod(object.data(), "twiddle"); + + const QString iError = u" Error: Cannot assign QString to TransparentWrapper<int,int_tag>"_s; + const QString uError = u" Error: Cannot assign QString to TransparentWrapper<uint,int_tag>"_s; + + QTest::ignoreMessage(QtWarningMsg, qPrintable(url + u":46:"_s + iError)); + QMetaObject::invokeMethod(object.data(), "impossibleValA"); + QCOMPARE(u->val().a(), 55); + QCOMPARE(u->property("valA").toInt(), 55); + + QTest::ignoreMessage(QtWarningMsg, qPrintable(url + u":50:"_s + iError)); + QMetaObject::invokeMethod(object.data(), "impossibleA"); + QCOMPARE(u->a(), 59); + QCOMPARE(u->property("myA").toInt(), 59); + QCOMPARE(u->property("myA2").toInt(), 59); + + QTest::ignoreMessage(QtWarningMsg, qPrintable(url + u":54:"_s + iError)); + QMetaObject::invokeMethod(object.data(), "impossibleSelfA"); + QCOMPARE(u->a(), 59); + QCOMPARE(u->property("myA").toInt(), 59); + QCOMPARE(u->property("myA2").toInt(), 59); + + QTest::ignoreMessage(QtWarningMsg, qPrintable(url + u":58:"_s + uError)); + QMetaObject::invokeMethod(object.data(), "impossibleValU"); + QCOMPARE(u->val().u(), 61u); + QCOMPARE(u->property("valU").toUInt(), 61u); + + QTest::ignoreMessage(QtWarningMsg, qPrintable(url + u":62:"_s + uError)); + QMetaObject::invokeMethod(object.data(), "impossibleU"); + QCOMPARE(u->u(), 63u); + QCOMPARE(u->property("myU").toUInt(), 63u); + QCOMPARE(u->property("myU2").toUInt(), 63u); + + QTest::ignoreMessage(QtWarningMsg, qPrintable(url + u":66:"_s + uError)); + QMetaObject::invokeMethod(object.data(), "impossibleSelfU"); + QCOMPARE(u->u(), 63u); + QCOMPARE(u->property("myU").toUInt(), 63u); + QCOMPARE(u->property("myU2").toUInt(), 63u); } void tst_QmlCppCodegen::qtfont() |
