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/Categorizer.qml60
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml20
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp48
4 files changed, 130 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index d80783078f..c78acadd58 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -37,6 +37,7 @@ set(qml_files
BadType.qml
BaseMember.qml
BindingExpression.qml
+ Categorizer.qml
Cycle1.qml
Cycle2.qml
Cycle3.qml
@@ -161,6 +162,7 @@ set(qml_files
listlength.qml
math.qml
mathOperations.qml
+ mergeSideEffects.qml
methods.qml
modulePrefix.qml
moveRegVoid.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/Categorizer.qml b/tests/auto/qml/qmlcppcodegen/data/Categorizer.qml
new file mode 100644
index 0000000000..83117f5d01
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/Categorizer.qml
@@ -0,0 +1,60 @@
+pragma Strict
+import QtQml
+
+QtObject {
+ id: root
+
+ enum Parameters {
+ Length = 32,
+ Iterations = 2,
+
+ Category0 = 0xf0f,
+ Category1 = 0xf0f0,
+ Category2 = 0xf0f0f,
+ Maximum = 0xf0f0f0,
+ Mask = 0xabcdef
+ }
+
+ function randomNumber() : int {
+ return (Math.random() * Categorizer.Maximum);
+ }
+
+ property list<double> numbers: {
+ // Can't StoreElement on non-list-properties in 6.5.
+ // To keep the pragma Strict, slightly adjust the original code here.
+ return [
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ randomNumber(), randomNumber(), randomNumber(), randomNumber(),
+ ];
+ }
+
+ function sum() : list<double> {
+ var numbers = root.numbers;
+
+ var cat1Sum = 0;
+ var cat2Sum = 0;
+ var cat3Sum = 0;
+ var huge = 0;
+ for (var i = 0; i < Categorizer.Iterations; ++i) {
+ for (var j = 0; j < Categorizer.Length; ++j) {
+ var num = numbers[j] & Categorizer.Mask;
+ if (num < Categorizer.Category0)
+ cat1Sum += num;
+ else if (num < Categorizer.Category1)
+ cat2Sum += num;
+ else if (num < Categorizer.Category2)
+ cat3Sum += num;
+ else
+ huge += num;
+ }
+ }
+
+ return [cat1Sum, cat2Sum, cat3Sum, huge];
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml b/tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml
new file mode 100644
index 0000000000..d4a8fec42e
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/mergeSideEffects.qml
@@ -0,0 +1,20 @@
+import QtQml
+
+QtObject {
+ property bool no: false
+ property list<int> a: [1]
+ property list<int> b: [2]
+
+ property int c: {
+ let numbers = a;
+ a = [3]; // create side effect affecting "numbers"
+
+ if (no) {
+ // Force two branches to be merged on "numbers"
+ numbers = b
+ }
+
+ // Side effect is still in effect
+ return numbers[0];
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index dae83e2c86..07d1d99f00 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -36,6 +36,7 @@ private slots:
void signalHandler();
void idAccess();
void globals();
+ void mergeSideEffects();
void multiLookup();
void enums();
void funcWithParams();
@@ -196,6 +197,7 @@ private slots:
void equalityTestsWithNullOrUndefined();
void basicBlocksWithBackJump();
void listOfInvisible();
+ void writeAndReturnTempArray();
};
void tst_QmlCppCodegen::initTestCase()
@@ -3110,6 +3112,16 @@ void tst_QmlCppCodegen::inaccessibleProperty()
QCOMPARE(o->property("c").toInt(), 5);
}
+void tst_QmlCppCodegen::mergeSideEffects()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/mergeSideEffects.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ QCOMPARE(o->property("c").toInt(), 3);
+}
+
void tst_QmlCppCodegen::typePropagationLoop()
{
QQmlEngine engine;
@@ -3772,6 +3784,42 @@ void tst_QmlCppCodegen::basicBlocksWithBackJump()
QVERIFY(!expectingMessage);
}
+void tst_QmlCppCodegen::writeAndReturnTempArray()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/Categorizer.qml"_s));
+
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ const QVariant numbers = object->property("numbers");
+ QCOMPARE(numbers.metaType(), QMetaType::fromType<QList<double>>());
+ const QList<double> numbersContent = numbers.value<QList<double>>();
+ QCOMPARE(numbersContent.length(), 32);
+ for (double number: std::as_const(numbersContent))
+ QVERIFY(number >= 0 && number < double(0xf0f0f0));
+
+ QList<double> expected { 0, 0, 0, 0};
+ for (int i = 0; i < 2; ++i) {
+ for (double number : std::as_const(numbersContent)) {
+ const int num = QJSNumberCoercion::toInteger((number)) & 0xabcdef;
+ if (num < 0xf0f)
+ expected[0] += num;
+ else if (num < 0xf0f0)
+ expected[1] += num;
+ else if (num < 0xf0f0f)
+ expected[2] += num;
+ else
+ expected[3] += num;
+ }
+ }
+
+ QList<double> sum;
+ QMetaObject::invokeMethod(object.data(), "sum", Q_RETURN_ARG(QList<double>, sum));
+ QCOMPARE(sum, expected);
+}
+
QTEST_MAIN(tst_QmlCppCodegen)
#include "tst_qmlcppcodegen.moc"