diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-06-24 11:37:38 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-07-06 14:19:03 +0200 |
commit | 9545f40b819dd415a781cbfdc73d713c41e5919f (patch) | |
tree | 2d21416d599706c59152e9c748a20640b12ddb5c /tests | |
parent | cecbfb90c68a0f7d101e6626b9a2250d5222fefd (diff) |
Add test for conversion/decrement
This proves that we don't have this problem in 6.3.
Task-number: QTBUG-104512
Change-Id: I1fca1973f3aa0bc0e63d45fe60c024837a128709
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/conversionDecrement.qml | 18 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 21 |
3 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 0acfb97338..a2b514b3dc 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -52,6 +52,7 @@ set(qml_files compositesingleton.qml construct.qml contextParam.qml + conversionDecrement.qml conversions.qml conversions2.qml curlygrouped.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/conversionDecrement.qml b/tests/auto/qml/qmlcppcodegen/data/conversionDecrement.qml new file mode 100644 index 0000000000..fdce0fe65c --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/conversionDecrement.qml @@ -0,0 +1,18 @@ +pragma Strict +import QtQml + +QtObject { + id: panelGrid + property var pages: 4 + property int currentPageIndex: 0 + + onPagesChanged: { + if (panelGrid.currentPageIndex === 0) { + panelGrid.currentPageIndex = panelGrid.pages - 2 + } else if (panelGrid.currentPageIndex === panelGrid.pages - 1) { + panelGrid.currentPageIndex = 0 + } else { + panelGrid.currentPageIndex -= 1 + } + } +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 88ab3c5743..64bfcd0673 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -132,6 +132,7 @@ private slots: void functionTakingVar(); void javaScriptArgument(); void throwObjectName(); + void conversionDecrement(); }; void tst_QmlCppCodegen::simpleBinding() @@ -2031,6 +2032,26 @@ void tst_QmlCppCodegen::throwObjectName() QVERIFY(o->objectName().isEmpty()); } +void tst_QmlCppCodegen::conversionDecrement() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/conversionDecrement.qml"_qs)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + + QCOMPARE(o->property("currentPageIndex").toInt(), 0); + o->setProperty("pages", 5); + QCOMPARE(o->property("currentPageIndex").toInt(), 3); + o->setProperty("pages", 4); + QCOMPARE(o->property("currentPageIndex").toInt(), 0); + o->setProperty("pages", 6); + QCOMPARE(o->property("currentPageIndex").toInt(), 4); + o->setProperty("pages", 60); + QCOMPARE(o->property("currentPageIndex").toInt(), 3); +} + void tst_QmlCppCodegen::runInterpreted() { #ifdef Q_OS_ANDROID |