diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-19 16:38:55 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-24 15:44:16 +0200 |
commit | 6ff6c088c22938fc35690d385a9625f33c18a35a (patch) | |
tree | 30806408c396730e85fa4f3fe22424b49ad80d59 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
parent | a75ddda71b9a1af2fccad85aca725798eb8aa8e4 (diff) |
QmlCompiler: Add support for LoadElement on strings
In JavaScript the [] operator on strings returns a string. QString's
operator[] returns a QChar, but we can easily create a string from that.
Fixes: QTBUG-103371
Change-Id: Id5c960f00ecc7a5dfe30ccbcaac3ffb2a30308b9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index b4993d1752..84c5ad2deb 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -1955,6 +1955,20 @@ void tst_QmlCppCodegen::typedArray() QCOMPARE(o->property("inIntList").toInt(), 2); QCOMPARE(qvariant_cast<QDateTime>(o->property("inDateList")), date); QCOMPARE(o->property("inRealList").toDouble(), 30.0); + QCOMPARE(o->property("inCharList").toString(), QStringLiteral("f")); + + const QMetaObject *metaObject = o->metaObject(); + QMetaMethod method = metaObject->method(metaObject->indexOfMethod("stringAt10(QString)")); + QVERIFY(method.isValid()); + + // If LoadElement threw an exception the function would certainly return neither 10 nor 20. + int result = 0; + method.invoke( + o.data(), Q_RETURN_ARG(int, result), Q_ARG(QString, QStringLiteral("a"))); + QCOMPARE(result, 10); + method.invoke( + o.data(), Q_RETURN_ARG(int, result), Q_ARG(QString, QStringLiteral("aaaaaaaaaaa"))); + QCOMPARE(result, 20); } void tst_QmlCppCodegen::prefixedType() @@ -2126,6 +2140,10 @@ void tst_QmlCppCodegen::valueTypeLists() QCOMPARE(qvariant_cast<int>(o->property("intInBounds")), 7); QVERIFY(o->metaObject()->indexOfProperty("intOutOfBounds") > 0); QVERIFY(!o->property("intOutOfBounds").isValid()); + + QCOMPARE(qvariant_cast<QString>(o->property("charInBounds")), QStringLiteral("d")); + QVERIFY(o->metaObject()->indexOfProperty("charOutOfBounds") > 0); + QVERIFY(!o->property("charOutOfBounds").isValid()); } void tst_QmlCppCodegen::boundComponents() |