aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp')
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 1311319266..582b4e0126 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -338,6 +338,7 @@ private slots:
void checkUncreatableNoReason();
void checkURLtoURLObject();
+ void registerValueTypes();
private:
QQmlEngine engine;
@@ -5923,6 +5924,83 @@ void tst_qqmllanguage::checkURLtoURLObject()
QCOMPARE(c.errors().count(), 0);
}
+struct TestValueType
+{
+ Q_GADGET
+ Q_PROPERTY(int foo MEMBER foo)
+public:
+ int foo = 12;
+
+ friend bool operator==(const TestValueType &a, const TestValueType &b)
+ {
+ return a.foo == b.foo;
+ }
+
+ friend bool operator!=(const TestValueType &a, const TestValueType &b)
+ {
+ return a.foo != b.foo;
+ }
+};
+
+struct TestExtendedValueType
+{
+ Q_GADGET
+ Q_PROPERTY(int bar READ bar WRITE setBar)
+public:
+ TestValueType wrapped;
+
+ int bar() const { return wrapped.foo; }
+ void setBar(int bar) { wrapped.foo = bar; }
+};
+
+class TestObjectType : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(TestValueType test MEMBER test)
+public:
+ TestValueType test;
+};
+
+void tst_qqmllanguage::registerValueTypes()
+{
+ QTest::ignoreMessage(QtWarningMsg, "Invalid QML element name \"UpperCase\"; value type names must begin with a lowercase letter");
+ QCOMPARE(qmlRegisterType<TestValueType>("DoesNotWork", 1, 0, "UpperCase"), -1);
+ QVERIFY(qmlRegisterType<TestObjectType>("DoesWork", 1, 0, "TestObject") >= 0);
+
+ {
+ QQmlEngine engine;
+ QQmlComponent c(&engine);
+ c.setData("import QtQml\nimport DoesWork\nTestObject { Component.onCompleted: test.foo = 14 }", QUrl());
+ QVERIFY(c.isReady());
+ QScopedPointer<QObject> obj(c.create());
+ QCOMPARE(obj->property("test").value<TestValueType>().foo, 14);
+
+ QQmlComponent c2(&engine);
+ c2.setData("import QtQml\nimport DoesWork\n TestObject { Component.onCompleted: test.bar = 14 }", QUrl());
+ QVERIFY(c2.isReady());
+ QScopedPointer<QObject> obj2(c2.create());
+ QCOMPARE(obj2->property("test").value<TestValueType>().foo, 12);
+ }
+
+ QVERIFY((qmlRegisterExtendedType<TestValueType, TestExtendedValueType>("DoesWork", 1, 0, "lowerCase")) >= 0);
+
+ {
+ QQmlEngine engine;
+ QQmlComponent c(&engine);
+ c.setData("import QtQml\nimport DoesWork\nTestObject { Component.onCompleted: test.foo = 14 }", QUrl());
+ QVERIFY(c.isReady());
+ QScopedPointer<QObject> obj(c.create());
+ // The foo property is hidden now.
+ QCOMPARE(obj->property("test").value<TestValueType>().foo, 12);
+
+ QQmlComponent c2(&engine);
+ c2.setData("import QtQml\nimport DoesWork\n TestObject { Component.onCompleted: test.bar = 14 }", QUrl());
+ QVERIFY(c2.isReady());
+ QScopedPointer<QObject> obj2(c2.create());
+ QCOMPARE(obj2->property("test").value<TestValueType>().foo, 14);
+ }
+}
+
void tst_qqmllanguage::accessNullPointerPropertyCache()
{
QQmlEngine engine;