aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-02-03 14:43:47 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-02-11 09:36:59 +0100
commitd2737bdedb6a53f83bab1c1c5606bcfc1df91687 (patch)
treef9cd94276d5a422675f7bbce3005aa56c31e269a /tests/auto/qml/qjsengine
parent1e8206f7e6bd7a37138921520e0ae43d9ec68eb6 (diff)
QML: Clean up sequence registrations for value types
We want to be able to construct a meaningful list type by surrounding the internal name of the type with QList<>. Usually this works because of the way we auto-register sequential containers for types. Only for the builtins we need to do some special casing. That special casing should happen in the builtins, not in QtQml, though. The generic QList<foo> sequence type is implicitly given for any value type foo these days. There is no need to mention it in .qmltypes. QtQml retains some extra container declarations that are not straight QList<foo> for a value type foo. Everything that's registered by the value type registration anyway is dropped. We keep the aliases QStringList and QVariantList in the builtins because they are really common. Since we now register QVariantList the way it's mandated by the builtins, we also have to handle it correctly in qv4sequenceobject.cpp. In particular, we need to append variants as-is rather than poking into them. As QStringList is an additional builtin now, we need to teach the type resolver about it. Change-Id: I0dfb5b780b27250f36f6886bc4e0926a03c114b4 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qjsengine')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index a92141a1e5..e96cb835e0 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -69,6 +69,8 @@ private slots:
void newArray_HooliganTask233836();
void toScriptValueBuiltin_data();
void toScriptValueBuiltin();
+ void toScriptValueQmlBuiltin_data();
+ void toScriptValueQmlBuiltin();
void toScriptValueQtQml_data();
void toScriptValueQtQml();
void toScriptValuenotroundtripped_data();
@@ -580,6 +582,36 @@ void tst_QJSEngine::toScriptValueBuiltin()
QCOMPARE(input, output);
}
+void tst_QJSEngine::toScriptValueQmlBuiltin_data()
+{
+ QTest::addColumn<QVariant>("input");
+
+ QTest::newRow("QList<QVariant>") << QVariant(QList<QVariant>{true, 5, 13.2f, 42.24, QString("world"), QUrl("htt://a.com"), QDateTime::currentDateTime(), QRegularExpression("a*b*c"), QByteArray("hello")});
+ QTest::newRow("QList<bool>") << QVariant::fromValue(QList<bool>{true, false, true, false});
+ QTest::newRow("QList<int>") << QVariant::fromValue(QList<int>{1, 2, 3, 4});
+ QTest::newRow("QList<float>") << QVariant::fromValue(QList<float>{1.1f, 2.2f, 3.3f, 4.4f});
+ QTest::newRow("QList<double>") << QVariant::fromValue(QList<double>{1.1, 2.2, 3.3, 4.4});
+ QTest::newRow("QList<QString>") << QVariant::fromValue(QList<QString>{"a", "b", "c", "d"});
+ QTest::newRow("QList<QUrl>") << QVariant::fromValue(QList<QUrl>{QUrl("htt://a.com"), QUrl("file:///tmp/b/"), QUrl("c.foo"), QUrl("/some/d")});
+ QTest::newRow("QList<QDateTime>") << QVariant::fromValue(QList<QDateTime>{QDateTime::currentDateTime(), QDateTime::fromMSecsSinceEpoch(300), QDateTime()});
+ QTest::newRow("QList<QRegularExpression>") << QVariant::fromValue(QList<QRegularExpression>{QRegularExpression("abcd"), QRegularExpression("a[b|c]d$"), QRegularExpression("a*b*d")});
+ QTest::newRow("QList<QByteArray>") << QVariant::fromValue(QList<QByteArray>{QByteArray("aaa"), QByteArray("bbb"), QByteArray("ccc")});
+}
+
+void tst_QJSEngine::toScriptValueQmlBuiltin()
+{
+ QFETCH(QVariant, input);
+
+ // We need the type registrations in QQmlEngine::init() for this.
+ QQmlEngine engine;
+
+ QJSValue outputJS = engine.toScriptValue(input);
+ QVariant output = engine.fromScriptValue<QVariant>(outputJS);
+
+ QVERIFY(output.convert(input.metaType()));
+ QCOMPARE(input, output);
+}
+
void tst_QJSEngine::toScriptValueQtQml_data()
{
QTest::addColumn<QVariant>("input");
@@ -592,10 +624,6 @@ void tst_QJSEngine::toScriptValueQtQml_data()
QTest::newRow("std::vector<QString>") << QVariant::fromValue(std::vector<QString>{"a", "b", "c", "d"});
QTest::newRow("std::vector<QUrl>") << QVariant::fromValue(std::vector<QUrl>{QUrl("htt://a.com"), QUrl("file:///tmp/b/"), QUrl("c.foo"), QUrl("/some/d")});
- QTest::newRow("QList<int>") << QVariant::fromValue(QList<int>{1, 2, 3, 4});
- QTest::newRow("QList<bool>") << QVariant::fromValue(QList<bool>{true, false, true, false});
- QTest::newRow("QStringList") << QVariant::fromValue(QStringList{"a", "b", "c", "d"});
- QTest::newRow("QList<QUrl>") << QVariant::fromValue(QList<QUrl>{QUrl("htt://a.com"), QUrl("file:///tmp/b/"), QUrl("c.foo"), QUrl("/some/d")});
QTest::newRow("QList<QPoint>") << QVariant::fromValue(QList<QPointF>() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42));
static const QStandardItemModel model(4, 4);