From 2edaf0446788d9543ef357fc1f1d65a8c8736486 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 11 Nov 2009 16:52:18 +1000 Subject: QmlDom tests --- src/declarative/qml/qmldom.cpp | 100 +-- src/declarative/qml/qmldom.h | 4 +- src/declarative/qml/qmldom_p.h | 22 +- src/declarative/qml/qmlscriptparser.cpp | 15 +- tests/auto/declarative/qmldom/data/MyItem.qml | 4 + tests/auto/declarative/qmldom/tst_qmldom.cpp | 928 ++++++++++++++++++++++++++ 6 files changed, 989 insertions(+), 84 deletions(-) create mode 100644 tests/auto/declarative/qmldom/data/MyItem.qml diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 39d6730..f4a137c 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -57,13 +57,6 @@ QmlDomDocumentPrivate::QmlDomDocumentPrivate() { } -QmlDomDocumentPrivate::QmlDomDocumentPrivate(const QmlDomDocumentPrivate &other) -: QSharedData(other), root(0) -{ - root = other.root; - if (root) root->addref(); -} - QmlDomDocumentPrivate::~QmlDomDocumentPrivate() { if (root) root->release(); @@ -141,7 +134,7 @@ QList QmlDomDocument::imports() const /*! Loads a QmlDomDocument from \a data. \a data should be valid QML data. On success, true is returned. If the \a data is malformed, false - is returned and QmlDomDocument::loadError() contains an error description. + is returned and QmlDomDocument::errors() contains an error description. \sa QmlDomDocument::loadError() */ @@ -160,7 +153,8 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl td->release(); component->release(); return false; - } else if(td->status == QmlCompositeTypeData::Waiting) { + } else if(td->status == QmlCompositeTypeData::Waiting || + td->status == QmlCompositeTypeData::WaitingResources) { QmlError error; error.setDescription(QLatin1String("QmlDomDocument supports local types only")); d->errors << error; @@ -234,13 +228,6 @@ QmlDomPropertyPrivate::QmlDomPropertyPrivate() { } -QmlDomPropertyPrivate::QmlDomPropertyPrivate(const QmlDomPropertyPrivate &other) -: QSharedData(other), property(0) -{ - property = other.property; - if (property) property->addref(); -} - QmlDomPropertyPrivate::~QmlDomPropertyPrivate() { if (property) property->release(); @@ -251,13 +238,6 @@ QmlDomDynamicPropertyPrivate::QmlDomDynamicPropertyPrivate(): { } -QmlDomDynamicPropertyPrivate::QmlDomDynamicPropertyPrivate(const QmlDomDynamicPropertyPrivate &other) -: QSharedData(other), valid(other.valid) -{ - property = other.property; - if (valid && property.defaultValue) property.defaultValue->addref(); -} - QmlDomDynamicPropertyPrivate::~QmlDomDynamicPropertyPrivate() { if (valid && property.defaultValue) property.defaultValue->release(); @@ -307,6 +287,15 @@ QmlDomProperty &QmlDomProperty::operator=(const QmlDomProperty &other) } /*! + Returns true if this is a valid QmlDomProperty, false otherwise. +*/ +bool QmlDomProperty::isValid() const +{ + return d->property != 0; +} + + +/*! Return the name of this property. \qml @@ -482,7 +471,7 @@ int QmlDomDynamicProperty::propertyType() const return QMetaType::type("QColor"); case QmlParser::Object::DynamicProperty::Date: - return QMetaType::type("QDateTime"); + return QMetaType::type("QDate"); case QmlParser::Object::DynamicProperty::Int: return QMetaType::type("int"); @@ -507,6 +496,14 @@ int QmlDomDynamicProperty::propertyType() const return -1; } +QByteArray QmlDomDynamicProperty::propertyTypeName() const +{ + if (isValid()) + return d->property.customType; + + return QByteArray(); +} + /*! Return true if this property is used as a default property in the QML document. @@ -539,6 +536,7 @@ QmlDomProperty QmlDomDynamicProperty::defaultValue() const if (isValid() && d->property.defaultValue) { rp.d->property = d->property.defaultValue; + rp.d->propertyName = propertyName(); rp.d->property->addref(); } @@ -570,18 +568,10 @@ int QmlDomDynamicProperty::length() const } QmlDomObjectPrivate::QmlDomObjectPrivate() -: object(0), isVirtualComponent(false) +: object(0) { } -QmlDomObjectPrivate::QmlDomObjectPrivate(const QmlDomObjectPrivate &other) -: QSharedData(other), object(0), isVirtualComponent(false) -{ - object = other.object; - if (object) object->addref(); - isVirtualComponent = other.isVirtualComponent; -} - QmlDomObjectPrivate::~QmlDomObjectPrivate() { if (object) object->release(); @@ -665,16 +655,6 @@ QmlDomObject::QmlDomObject() } /*! - Construct a new QmlDomObject with the specified \a objectType. -*/ -QmlDomObject::QmlDomObject(const QByteArray &objectType) -: d(new QmlDomObjectPrivate) -{ - Q_UNUSED(objectType); - qWarning("QmlDomObject::QmlDomObject(const QByteArray &): Not implemented"); -} - -/*! Create a copy of \a other QmlDomObject. */ QmlDomObject::QmlDomObject(const QmlDomObject &other) @@ -785,7 +765,7 @@ QList QmlDomObject::properties() const { QList rv; - if (!d->object) + if (!d->object || isComponent()) return rv; QmlDomObjectPrivate::Properties properties = d->properties(); @@ -853,6 +833,9 @@ QmlDomDynamicProperty QmlDomObject::dynamicProperty(const QByteArray &name) cons { QmlDomDynamicProperty p; + if (!isValid()) + return p; + for (int i = 0; i < d->object->dynamicProperties.size(); ++i) { if (d->object->dynamicProperties.at(i).name == name) { p.d = new QmlDomDynamicPropertyPrivate; @@ -900,8 +883,7 @@ QByteArray QmlDomObject::customTypeData() const */ bool QmlDomObject::isComponent() const { - return d->isVirtualComponent || - (d->object && d->object->typeName == "Qt/Component"); + return (d->object && d->object->typeName == "Qt/Component"); } /*! @@ -958,13 +940,6 @@ QmlDomBasicValuePrivate::QmlDomBasicValuePrivate() { } -QmlDomBasicValuePrivate::QmlDomBasicValuePrivate(const QmlDomBasicValuePrivate &other) -: QSharedData(other), value(0) -{ - value = other.value; - if (value) value->addref(); -} - QmlDomBasicValuePrivate::~QmlDomBasicValuePrivate() { if (value) value->release(); @@ -1250,15 +1225,6 @@ QmlDomValuePrivate::QmlDomValuePrivate() { } -QmlDomValuePrivate::QmlDomValuePrivate(const QmlDomValuePrivate &other) -: QSharedData(other), property(0), value(0) -{ - property = other.property; - value = other.value; - if (property) property->addref(); - if (value) value->addref(); -} - QmlDomValuePrivate::~QmlDomValuePrivate() { if (property) property->release(); @@ -1754,10 +1720,7 @@ Item { QmlDomObject QmlDomComponent::componentRoot() const { QmlDomObject rv; - if (d->isVirtualComponent) { - rv.d->object = d->object; - rv.d->object->addref(); - } else if (d->object) { + if (d->object) { QmlParser::Object *obj = 0; if (d->object->defaultProperty && d->object->defaultProperty->values.count() == 1 && @@ -1778,11 +1741,6 @@ QmlDomImportPrivate::QmlDomImportPrivate() { } -QmlDomImportPrivate::QmlDomImportPrivate(const QmlDomImportPrivate &other) -: QSharedData(other) -{ -} - QmlDomImportPrivate::~QmlDomImportPrivate() { } diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h index 8c43c4a..250307f 100644 --- a/src/declarative/qml/qmldom.h +++ b/src/declarative/qml/qmldom.h @@ -92,6 +92,8 @@ public: ~QmlDomProperty(); QmlDomProperty &operator=(const QmlDomProperty &); + bool isValid() const; + QByteArray propertyName() const; QList propertyNameParts() const; @@ -121,6 +123,7 @@ public: QByteArray propertyName() const; int propertyType() const; + QByteArray propertyTypeName() const; bool isDefaultProperty() const; @@ -139,7 +142,6 @@ class Q_DECLARATIVE_EXPORT QmlDomObject { public: QmlDomObject(); - QmlDomObject(const QByteArray &); QmlDomObject(const QmlDomObject &); ~QmlDomObject(); QmlDomObject &operator=(const QmlDomObject &); diff --git a/src/declarative/qml/qmldom_p.h b/src/declarative/qml/qmldom_p.h index 4b4de80..cb0d884 100644 --- a/src/declarative/qml/qmldom_p.h +++ b/src/declarative/qml/qmldom_p.h @@ -62,7 +62,8 @@ class QmlDomDocumentPrivate : public QSharedData { public: QmlDomDocumentPrivate(); - QmlDomDocumentPrivate(const QmlDomDocumentPrivate &); + QmlDomDocumentPrivate(const QmlDomDocumentPrivate &o) + : QSharedData(o) { qFatal("Not impl"); } ~QmlDomDocumentPrivate(); QList errors; @@ -75,7 +76,8 @@ class QmlDomObjectPrivate : public QSharedData { public: QmlDomObjectPrivate(); - QmlDomObjectPrivate(const QmlDomObjectPrivate &); + QmlDomObjectPrivate(const QmlDomObjectPrivate &o) + : QSharedData(o) { qFatal("Not impl"); } ~QmlDomObjectPrivate(); typedef QList > Properties; @@ -83,14 +85,14 @@ public: Properties properties(QmlParser::Property *) const; QmlParser::Object *object; - bool isVirtualComponent; }; class QmlDomPropertyPrivate : public QSharedData { public: QmlDomPropertyPrivate(); - QmlDomPropertyPrivate(const QmlDomPropertyPrivate &); + QmlDomPropertyPrivate(const QmlDomPropertyPrivate &o) + : QSharedData(o) { qFatal("Not impl"); } ~QmlDomPropertyPrivate(); QByteArray propertyName; @@ -101,7 +103,8 @@ class QmlDomDynamicPropertyPrivate : public QSharedData { public: QmlDomDynamicPropertyPrivate(); - QmlDomDynamicPropertyPrivate(const QmlDomDynamicPropertyPrivate &); + QmlDomDynamicPropertyPrivate(const QmlDomDynamicPropertyPrivate &o) + : QSharedData(o) { qFatal("Not impl"); } ~QmlDomDynamicPropertyPrivate(); bool valid; @@ -112,7 +115,8 @@ class QmlDomValuePrivate : public QSharedData { public: QmlDomValuePrivate(); - QmlDomValuePrivate(const QmlDomValuePrivate &); + QmlDomValuePrivate(const QmlDomValuePrivate &o) + : QSharedData(o) { qFatal("Not impl"); } ~QmlDomValuePrivate(); QmlParser::Property *property; @@ -123,7 +127,8 @@ class QmlDomBasicValuePrivate : public QSharedData { public: QmlDomBasicValuePrivate(); - QmlDomBasicValuePrivate(const QmlDomBasicValuePrivate &); + QmlDomBasicValuePrivate(const QmlDomBasicValuePrivate &o) + : QSharedData(o) { qFatal("Not impl"); } ~QmlDomBasicValuePrivate(); QmlParser::Value *value; @@ -133,7 +138,8 @@ class QmlDomImportPrivate : public QSharedData { public: QmlDomImportPrivate(); - QmlDomImportPrivate(const QmlDomImportPrivate &); + QmlDomImportPrivate(const QmlDomImportPrivate &o) + : QSharedData(o) { qFatal("Not impl"); } ~QmlDomImportPrivate(); enum Type { Library, File }; diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 526894e..b622c24 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -342,10 +342,17 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, Value *v = new Value; v->object = obj; v->location = obj->location; - if (state.property) + if (state.property) { state.property->addValue(v); - else - state.object->getDefaultProperty()->addValue(v); + } else { + Property *defaultProp = state.object->getDefaultProperty(); + if (defaultProp->location.start.line == -1) { + defaultProp->location = v->location; + defaultProp->location.end = defaultProp->location.start; + defaultProp->location.range.length = 0; + } + defaultProp->addValue(v); + } } } @@ -583,8 +590,8 @@ bool ProcessAST::visit(AST::UiPublicMember *node) QmlScriptParser::TypeReference *typeRef = _parser->findOrCreateType(memberType); typeRef->refObjects.append(_stateStack.top().object); - property.customType = memberType.toUtf8(); } + property.customType = memberType.toUtf8(); property.name = name.toUtf8(); property.location = location(node->firstSourceLocation(), node->lastSourceLocation()); diff --git a/tests/auto/declarative/qmldom/data/MyItem.qml b/tests/auto/declarative/qmldom/data/MyItem.qml new file mode 100644 index 0000000..1472f01 --- /dev/null +++ b/tests/auto/declarative/qmldom/data/MyItem.qml @@ -0,0 +1,4 @@ +import Qt 4.6 + +Item { +} diff --git a/tests/auto/declarative/qmldom/tst_qmldom.cpp b/tests/auto/declarative/qmldom/tst_qmldom.cpp index 350e985..f219581 100644 --- a/tests/auto/declarative/qmldom/tst_qmldom.cpp +++ b/tests/auto/declarative/qmldom/tst_qmldom.cpp @@ -55,13 +55,24 @@ public: private slots: void loadSimple(); void loadProperties(); + void loadGroupedProperties(); void loadChildObject(); void loadComposite(); void loadImports(); + void loadErrors(); + void loadSyntaxErrors(); + void loadRemoteErrors(); + void loadDynamicProperty(); + void loadComponent(); void testValueSource(); void testValueInterceptor(); + void object_dynamicProperty(); + void object_property(); + void object_url(); + + void copy(); private: QmlEngine engine; }; @@ -85,6 +96,7 @@ void tst_qmldom::loadSimple() QVERIFY(rootObject.objectTypeMinorVersion() == 6); } +// Test regular properties void tst_qmldom::loadProperties() { QByteArray qml = "import Qt 4.6\n" @@ -100,15 +112,119 @@ void tst_qmldom::loadProperties() QmlDomProperty xProperty = rootObject.property("x"); QVERIFY(xProperty.propertyName() == "x"); + QCOMPARE(xProperty.propertyNameParts().count(), 1); + QVERIFY(xProperty.propertyNameParts().at(0) == "x"); + QCOMPARE(xProperty.position(), 32); + QCOMPARE(xProperty.length(), 1); QVERIFY(xProperty.value().isLiteral()); QVERIFY(xProperty.value().toLiteral().literal() == "300"); QmlDomProperty visibleProperty = rootObject.property("visible"); QVERIFY(visibleProperty.propertyName() == "visible"); + QCOMPARE(visibleProperty.propertyNameParts().count(), 1); + QVERIFY(visibleProperty.propertyNameParts().at(0) == "visible"); + QCOMPARE(visibleProperty.position(), 41); + QCOMPARE(visibleProperty.length(), 7); QVERIFY(visibleProperty.value().isLiteral()); QVERIFY(visibleProperty.value().toLiteral().literal() == "true"); } +// Test grouped properties +void tst_qmldom::loadGroupedProperties() +{ + { + QByteArray qml = "import Qt 4.6\n" + "Item { anchors.left: parent.left; anchors.right: parent.right }"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootItem = document.rootObject(); + QVERIFY(rootItem.isValid()); + QVERIFY(rootItem.properties().size() == 2); + + // Order is not deterministic + QmlDomProperty p0 = rootItem.properties().at(0); + QmlDomProperty p1 = rootItem.properties().at(1); + QmlDomProperty leftProperty; + QmlDomProperty rightProperty; + if (p0.propertyName() == "anchors.left") { + leftProperty = p0; + rightProperty = p1; + } else { + leftProperty = p1; + rightProperty = p0; + } + + QVERIFY(leftProperty.propertyName() == "anchors.left"); + QCOMPARE(leftProperty.propertyNameParts().count(), 2); + QVERIFY(leftProperty.propertyNameParts().at(0) == "anchors"); + QVERIFY(leftProperty.propertyNameParts().at(1) == "left"); + QCOMPARE(leftProperty.position(), 21); + QCOMPARE(leftProperty.length(), 12); + QVERIFY(leftProperty.value().isBinding()); + QVERIFY(leftProperty.value().toBinding().binding() == "parent.left"); + + QVERIFY(rightProperty.propertyName() == "anchors.right"); + QCOMPARE(rightProperty.propertyNameParts().count(), 2); + QVERIFY(rightProperty.propertyNameParts().at(0) == "anchors"); + QVERIFY(rightProperty.propertyNameParts().at(1) == "right"); + QCOMPARE(rightProperty.position(), 48); + QCOMPARE(rightProperty.length(), 13); + QVERIFY(rightProperty.value().isBinding()); + QVERIFY(rightProperty.value().toBinding().binding() == "parent.right"); + } + + { + QByteArray qml = "import Qt 4.6\n" + "Item { \n" + " anchors {\n" + " left: parent.left\n" + " right: parent.right\n" + " }\n" + "}"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootItem = document.rootObject(); + QVERIFY(rootItem.isValid()); + QVERIFY(rootItem.properties().size() == 2); + + // Order is not deterministic + QmlDomProperty p0 = rootItem.properties().at(0); + QmlDomProperty p1 = rootItem.properties().at(1); + QmlDomProperty leftProperty; + QmlDomProperty rightProperty; + if (p0.propertyName() == "anchors.left") { + leftProperty = p0; + rightProperty = p1; + } else { + leftProperty = p1; + rightProperty = p0; + } + + QVERIFY(leftProperty.propertyName() == "anchors.left"); + QCOMPARE(leftProperty.propertyNameParts().count(), 2); + QVERIFY(leftProperty.propertyNameParts().at(0) == "anchors"); + QVERIFY(leftProperty.propertyNameParts().at(1) == "left"); + QCOMPARE(leftProperty.position(), 44); + QCOMPARE(leftProperty.length(), 4); + QVERIFY(leftProperty.value().isBinding()); + QVERIFY(leftProperty.value().toBinding().binding() == "parent.left"); + + QVERIFY(rightProperty.propertyName() == "anchors.right"); + QCOMPARE(rightProperty.propertyNameParts().count(), 2); + QVERIFY(rightProperty.propertyNameParts().at(0) == "anchors"); + QVERIFY(rightProperty.propertyNameParts().at(1) == "right"); + QCOMPARE(rightProperty.position(), 70); + QCOMPARE(rightProperty.length(), 5); + QVERIFY(rightProperty.value().isBinding()); + QVERIFY(rightProperty.value().toBinding().binding() == "parent.right"); + } + +} + void tst_qmldom::loadChildObject() { QByteArray qml = "import Qt 4.6\n" @@ -212,6 +328,7 @@ void tst_qmldom::testValueInterceptor() QVERIFY(animationValue.isObject()); } +// Test QmlDomDocument::imports() void tst_qmldom::loadImports() { QByteArray qml = "import Qt 4.6\n" @@ -259,6 +376,817 @@ void tst_qmldom::loadImports() QCOMPARE(import.version(), QLatin1String("")); } +// Test loading a file with errors +void tst_qmldom::loadErrors() +{ + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " foo: 12\n" + "}"; + + QmlDomDocument document; + QVERIFY(false == document.load(&engine, qml)); + + QCOMPARE(document.errors().count(), 1); + QmlError error = document.errors().first(); + + QCOMPARE(error.url(), QUrl()); + QCOMPARE(error.line(), 3); + QCOMPARE(error.column(), 3); + QCOMPARE(error.description(), QString("Cannot assign to non-existant property \"foo\"")); +} + +// Test loading a file with syntax errors +void tst_qmldom::loadSyntaxErrors() +{ + QByteArray qml = "import Qt 4.6\n" + "asdf"; + + QmlDomDocument document; + QVERIFY(false == document.load(&engine, qml)); + + QCOMPARE(document.errors().count(), 1); + QmlError error = document.errors().first(); + + QCOMPARE(error.url(), QUrl()); + QCOMPARE(error.line(), 2); + QCOMPARE(error.column(), 1); + QCOMPARE(error.description(), QString("Syntax error")); +} + +// Test attempting to load a file with remote references +void tst_qmldom::loadRemoteErrors() +{ + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " Script {\n" + " source: \"http://localhost/exampleQmlScript.js\"" + " }\n" + "}"; + QmlDomDocument document; + QVERIFY(false == document.load(&engine, qml)); + + QCOMPARE(document.errors().count(), 1); + QmlError error = document.errors().first(); + + QCOMPARE(error.url(), QUrl()); + QCOMPARE(error.line(), -1); + QCOMPARE(error.column(), -1); + QCOMPARE(error.description(), QString("QmlDomDocument supports local types only")); +} + +// Test dynamic property declarations +void tst_qmldom::loadDynamicProperty() +{ + { + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " property int a\n" + " property bool b\n" + " property double c\n" + " property real d\n" + " property string e\n" + " property url f\n" + " property color g\n" + " property date h\n" + " property var i\n" + " property variant j\n" + " property Object k\n" + "}"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + + QCOMPARE(rootObject.dynamicProperties().count(), 11); + +#define DP_TEST(index, name, type, test_position, test_length, propTypeName) \ + { \ + QmlDomDynamicProperty d = rootObject.dynamicProperties().at(index); \ + QVERIFY(d.isValid()); \ + QVERIFY(d.propertyName() == # name ); \ + QVERIFY(d.propertyType() == type); \ + QVERIFY(d.propertyTypeName() == propTypeName); \ + QVERIFY(d.isDefaultProperty() == false); \ + QVERIFY(d.defaultValue().isValid() == false); \ + QCOMPARE(d.position(), test_position); \ + QCOMPARE(d.length(), test_length); \ + } \ + + DP_TEST(0, a, QVariant::Int, 25, 14, "int"); + DP_TEST(1, b, QVariant::Bool, 44, 15, "bool"); + DP_TEST(2, c, QVariant::Double, 64, 17, "double"); + DP_TEST(3, d, QMetaType::QReal, 86, 15, "real"); + DP_TEST(4, e, QVariant::String, 106, 17, "string"); + DP_TEST(5, f, QVariant::Url, 128, 14, "url"); + DP_TEST(6, g, QVariant::Color, 147, 16, "color"); + DP_TEST(7, h, QVariant::Date, 168, 15, "date"); + DP_TEST(8, i, qMetaTypeId(), 188, 14, "var"); + DP_TEST(9, j, qMetaTypeId(), 207, 18, "variant"); + DP_TEST(10, k, -1, 230, 17, "Object"); + } + + { + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " property int a: 12\n" + " property int b: a + 6\n" + " default property Object c\n" + "}\n"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + + QCOMPARE(rootObject.dynamicProperties().count(), 3); + + { + QmlDomDynamicProperty d = rootObject.dynamicProperties().at(0); + QVERIFY(d.isDefaultProperty() == false); + QVERIFY(d.defaultValue().isValid()); + QVERIFY(d.defaultValue().propertyName() == "a"); + QVERIFY(d.defaultValue().value().isLiteral()); + } + + { + QmlDomDynamicProperty d = rootObject.dynamicProperties().at(1); + QVERIFY(d.isDefaultProperty() == false); + QVERIFY(d.defaultValue().isValid()); + QVERIFY(d.defaultValue().propertyName() == "b"); + QVERIFY(d.defaultValue().value().isBinding()); + } + + { + QmlDomDynamicProperty d = rootObject.dynamicProperties().at(2); + QVERIFY(d.isDefaultProperty() == true); + QVERIFY(d.defaultValue().isValid() == false); + } + } +} + +// Test inline components +void tst_qmldom::loadComponent() +{ + // Explicit component + { + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " Component {\n" + " id: myComponent\n" + " Item {}\n" + " }\n" + "}"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootItem = document.rootObject(); + QVERIFY(rootItem.isValid()); + QVERIFY(rootItem.properties().size() == 1); + + QmlDomProperty listProperty = rootItem.properties().at(0); + QVERIFY(listProperty.isDefaultProperty()); + QVERIFY(listProperty.value().isList()); + + QmlDomList list = listProperty.value().toList(); + QVERIFY(list.values().size() == 1); + + QmlDomObject componentObject = list.values().first().toObject(); + QVERIFY(componentObject.isValid()); + QVERIFY(componentObject.objectClassName() == "Component"); + QVERIFY(componentObject.isComponent()); + + QmlDomComponent component = componentObject.toComponent(); + QVERIFY(component.isValid()); + QVERIFY(component.objectType() == "Qt/Component"); + QVERIFY(component.objectTypeMajorVersion() == 4); + QVERIFY(component.objectTypeMinorVersion() == 6); + QVERIFY(component.objectClassName() == "Component"); + QVERIFY(component.objectId() == "myComponent"); + QVERIFY(component.properties().isEmpty()); + QVERIFY(component.dynamicProperties().isEmpty()); + QVERIFY(component.isCustomType() == false); + QVERIFY(component.customTypeData() == ""); + QVERIFY(component.isComponent()); + QCOMPARE(component.position(), 25); + QCOMPARE(component.length(), 57); + + QVERIFY(component.componentRoot().isValid()); + QVERIFY(component.componentRoot().objectClassName() == "Item"); + } + + // Implicit component + { + QByteArray qml = "import Qt 4.6\n" + "ListView {\n" + " delegate: Item {}\n" + "}"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootItem = document.rootObject(); + QVERIFY(rootItem.isValid()); + QVERIFY(rootItem.properties().size() == 1); + + QmlDomProperty delegate = rootItem.property("delegate"); + + QmlDomObject componentObject = delegate.value().toObject(); + QVERIFY(componentObject.isValid()); + QVERIFY(componentObject.objectClassName() == "Component"); + QVERIFY(componentObject.isComponent()); + + QmlDomComponent component = componentObject.toComponent(); + QVERIFY(component.isValid()); + QVERIFY(component.objectType() == "Qt/Component"); + QVERIFY(component.objectClassName() == "Component"); + QVERIFY(component.objectId() == ""); + QVERIFY(component.properties().isEmpty()); + QVERIFY(component.dynamicProperties().isEmpty()); + QVERIFY(component.isCustomType() == false); + QVERIFY(component.customTypeData() == ""); + QVERIFY(component.isComponent()); + QCOMPARE(component.position(), 39); + QCOMPARE(component.length(), 7); + + QVERIFY(component.componentRoot().isValid()); + QVERIFY(component.componentRoot().objectClassName() == "Item"); + } +} + +// Test QmlDomObject::dynamicProperty() method +void tst_qmldom::object_dynamicProperty() +{ + // Invalid object + { + QmlDomObject object; + QVERIFY(object.dynamicProperty("").isValid() == false); + QVERIFY(object.dynamicProperty("foo").isValid() == false); + } + + + // Valid object, no dynamic properties + { + QByteArray qml = "import Qt 4.6\n" + "Item {}"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + + QVERIFY(rootObject.dynamicProperty("").isValid() == false); + QVERIFY(rootObject.dynamicProperty("foo").isValid() == false); + } + + // Valid object, dynamic properties + { + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " property int a\n" + "}"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + + QVERIFY(rootObject.dynamicProperty("").isValid() == false); + QVERIFY(rootObject.dynamicProperty("foo").isValid() == false); + + QmlDomDynamicProperty p = rootObject.dynamicProperty("a"); + QVERIFY(p.isValid()); + QVERIFY(p.propertyName() == "a"); + QVERIFY(p.propertyType() == QVariant::Int); + QVERIFY(p.propertyTypeName() == "int"); + QVERIFY(p.isDefaultProperty() == false); + QCOMPARE(p.position(), 25); + QCOMPARE(p.length(), 14); + } + +} + +// Test QmlObject::property() method +void tst_qmldom::object_property() +{ + // Invalid object + { + QmlDomObject object; + QVERIFY(object.property("").isValid() == false); + QVERIFY(object.property("foo").isValid() == false); + } + + // Valid object - no default + { + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " x: 10\n" + " y: 12\n" + "}\n"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + + QVERIFY(rootObject.property("").isValid() == false); + QVERIFY(rootObject.property("foo").isValid() == false); + + QmlDomProperty x = rootObject.property("x"); + QVERIFY(x.isValid()); + QVERIFY(x.propertyName() == "x"); + QVERIFY(x.propertyNameParts().count() == 1); + QVERIFY(x.propertyNameParts().at(0) == "x"); + QVERIFY(x.isDefaultProperty() == false); + QVERIFY(x.value().isLiteral()); + QVERIFY(x.value().toLiteral().literal() == "10"); + QCOMPARE(x.position(), 25); + QCOMPARE(x.length(), 1); + + QmlDomProperty y = rootObject.property("y"); + QVERIFY(y.isValid()); + QVERIFY(y.propertyName() == "y"); + QVERIFY(y.propertyNameParts().count() == 1); + QVERIFY(y.propertyNameParts().at(0) == "y"); + QVERIFY(y.isDefaultProperty() == false); + QVERIFY(y.value().isLiteral()); + QVERIFY(y.value().toLiteral().literal() == "12"); + QCOMPARE(y.position(), 35); + QCOMPARE(y.length(), 1); + } + + // Valid object - with default + { + QByteArray qml = "import Qt 4.6\n" + "Item {\n" + " x: 10\n" + " y: 12\n" + " Item {}\n" + "}\n"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + + QVERIFY(rootObject.property("").isValid() == false); + QVERIFY(rootObject.property("foo").isValid() == false); + + QmlDomProperty x = rootObject.property("x"); + QVERIFY(x.isValid()); + QVERIFY(x.propertyName() == "x"); + QVERIFY(x.propertyNameParts().count() == 1); + QVERIFY(x.propertyNameParts().at(0) == "x"); + QVERIFY(x.isDefaultProperty() == false); + QVERIFY(x.value().isLiteral()); + QVERIFY(x.value().toLiteral().literal() == "10"); + QCOMPARE(x.position(), 25); + QCOMPARE(x.length(), 1); + + QmlDomProperty y = rootObject.property("y"); + QVERIFY(y.isValid()); + QVERIFY(y.propertyName() == "y"); + QVERIFY(y.propertyNameParts().count() == 1); + QVERIFY(y.propertyNameParts().at(0) == "y"); + QVERIFY(y.isDefaultProperty() == false); + QVERIFY(y.value().isLiteral()); + QVERIFY(y.value().toLiteral().literal() == "12"); + QCOMPARE(y.position(), 35); + QCOMPARE(y.length(), 1); + + QmlDomProperty data = rootObject.property("data"); + QVERIFY(data.isValid()); + QVERIFY(data.propertyName() == "data"); + QVERIFY(data.propertyNameParts().count() == 1); + QVERIFY(data.propertyNameParts().at(0) == "data"); + QVERIFY(data.isDefaultProperty() == true); + QVERIFY(data.value().isList()); + QCOMPARE(data.position(), 45); + QCOMPARE(data.length(), 0); + } +} + +// Tests the QmlDomObject::url() method +void tst_qmldom::object_url() +{ + // Invalid object + { + QmlDomObject object; + QCOMPARE(object.url(), QUrl()); + } + + // Valid builtin object + { + QByteArray qml = "import Qt 4.6\n" + "Item {}"; + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + QCOMPARE(rootObject.url(), QUrl()); + } + + // Valid composite object + { + QByteArray qml = "import Qt 4.6\n" + "MyItem {}"; + + QUrl myUrl = QUrl::fromLocalFile(SRCDIR "/data/main.qml"); + QUrl subUrl = QUrl::fromLocalFile(SRCDIR "/data/MyItem.qml"); + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml, myUrl)); + + QmlDomObject rootObject = document.rootObject(); + QVERIFY(rootObject.isValid()); + QCOMPARE(rootObject.url(), subUrl); + } +} + +// Test copy constructors and operators +void tst_qmldom::copy() +{ + QByteArray qml = "import Qt 4.6\n" + "MyItem {\n" + " id: myItem\n" + " property int a: 10\n" + " x: 10\n" + " y: x + 10\n" + " z: NumberAnimation {}\n" + " opacity: Behavior {}\n" + " Component {\n" + " Item{}\n" + " }\n" + " children: [ Item{}, Item{} ]\n" + "}\n"; + + QUrl myUrl = QUrl::fromLocalFile(SRCDIR "/data/main.qml"); + + QmlDomDocument document; + QVERIFY(document.load(&engine, qml, myUrl)); + + // QmlDomDocument + { + QmlDomDocument document2(document); + QmlDomDocument document3; + document3 = document; + + QCOMPARE(document.imports().count(), document2.imports().count()); + QCOMPARE(document.errors().count(), document2.errors().count()); + QCOMPARE(document.rootObject().objectClassName(), document2.rootObject().objectClassName()); + + QCOMPARE(document.imports().count(), document3.imports().count()); + QCOMPARE(document.errors().count(), document3.errors().count()); + QCOMPARE(document.rootObject().objectClassName(), document3.rootObject().objectClassName()); + } + + // QmlDomImport + { + QCOMPARE(document.imports().count(), 1); + QmlDomImport import = document.imports().at(0); + + QmlDomImport import2(import); + QmlDomImport import3; + import3 = import2; + + QCOMPARE(import.type(), import2.type()); + QCOMPARE(import.uri(), import2.uri()); + QCOMPARE(import.version(), import2.version()); + QCOMPARE(import.qualifier(), import2.qualifier()); + + QCOMPARE(import.type(), import3.type()); + QCOMPARE(import.uri(), import3.uri()); + QCOMPARE(import.version(), import3.version()); + QCOMPARE(import.qualifier(), import3.qualifier()); + } + + // QmlDomObject + { + QmlDomObject object = document.rootObject(); + QVERIFY(object.isValid()); + + QmlDomObject object2(object); + QmlDomObject object3; + object3 = object; + + QCOMPARE(object.isValid(), object2.isValid()); + QCOMPARE(object.objectType(), object2.objectType()); + QCOMPARE(object.objectClassName(), object2.objectClassName()); + QCOMPARE(object.objectTypeMajorVersion(), object2.objectTypeMajorVersion()); + QCOMPARE(object.objectTypeMinorVersion(), object2.objectTypeMinorVersion()); + QCOMPARE(object.objectId(), object2.objectId()); + QCOMPARE(object.properties().count(), object2.properties().count()); + QCOMPARE(object.dynamicProperties().count(), object2.dynamicProperties().count()); + QCOMPARE(object.isCustomType(), object2.isCustomType()); + QCOMPARE(object.customTypeData(), object2.customTypeData()); + QCOMPARE(object.isComponent(), object2.isComponent()); + QCOMPARE(object.position(), object2.position()); + QCOMPARE(object.length(), object2.length()); + QCOMPARE(object.url(), object2.url()); + + QCOMPARE(object.isValid(), object3.isValid()); + QCOMPARE(object.objectType(), object3.objectType()); + QCOMPARE(object.objectClassName(), object3.objectClassName()); + QCOMPARE(object.objectTypeMajorVersion(), object3.objectTypeMajorVersion()); + QCOMPARE(object.objectTypeMinorVersion(), object3.objectTypeMinorVersion()); + QCOMPARE(object.objectId(), object3.objectId()); + QCOMPARE(object.properties().count(), object3.properties().count()); + QCOMPARE(object.dynamicProperties().count(), object3.dynamicProperties().count()); + QCOMPARE(object.isCustomType(), object3.isCustomType()); + QCOMPARE(object.customTypeData(), object3.customTypeData()); + QCOMPARE(object.isComponent(), object3.isComponent()); + QCOMPARE(object.position(), object3.position()); + QCOMPARE(object.length(), object3.length()); + QCOMPARE(object.url(), object3.url()); + } + + // QmlDomDynamicProperty + { + QmlDomObject object = document.rootObject(); + QmlDomDynamicProperty property = object.dynamicProperty("a"); + + QmlDomDynamicProperty property2(property); + QmlDomDynamicProperty property3; + property3 = property; + + QCOMPARE(property.isValid(), property2.isValid()); + QCOMPARE(property.propertyName(), property2.propertyName()); + QCOMPARE(property.propertyType(), property2.propertyType()); + QCOMPARE(property.propertyTypeName(), property2.propertyTypeName()); + QCOMPARE(property.isDefaultProperty(), property2.isDefaultProperty()); + QCOMPARE(property.defaultValue().propertyName(), property2.defaultValue().propertyName()); + QCOMPARE(property.position(), property2.position()); + QCOMPARE(property.length(), property2.length()); + + QCOMPARE(property.isValid(), property3.isValid()); + QCOMPARE(property.propertyName(), property3.propertyName()); + QCOMPARE(property.propertyType(), property3.propertyType()); + QCOMPARE(property.propertyTypeName(), property3.propertyTypeName()); + QCOMPARE(property.isDefaultProperty(), property3.isDefaultProperty()); + QCOMPARE(property.defaultValue().propertyName(), property3.defaultValue().propertyName()); + QCOMPARE(property.position(), property3.position()); + QCOMPARE(property.length(), property3.length()); + } + + // QmlDomProperty + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("opacity"); + + QmlDomProperty property2(property); + QmlDomProperty property3; + property3 = property; + + QCOMPARE(property.isValid(), property2.isValid()); + QCOMPARE(property.propertyName(), property2.propertyName()); + QCOMPARE(property.propertyNameParts(), property2.propertyNameParts()); + QCOMPARE(property.isDefaultProperty(), property2.isDefaultProperty()); + QCOMPARE(property.value().type(), property2.value().type()); + QCOMPARE(property.position(), property2.position()); + QCOMPARE(property.length(), property2.length()); + + QCOMPARE(property.isValid(), property3.isValid()); + QCOMPARE(property.propertyName(), property3.propertyName()); + QCOMPARE(property.propertyNameParts(), property3.propertyNameParts()); + QCOMPARE(property.isDefaultProperty(), property3.isDefaultProperty()); + QCOMPARE(property.value().type(), property3.value().type()); + QCOMPARE(property.position(), property3.position()); + QCOMPARE(property.length(), property3.length()); + } + + // QmlDomValueLiteral + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("x"); + QmlDomValueLiteral literal = property.value().toLiteral(); + QCOMPARE(literal.literal(), QString("10")); + + QmlDomValueLiteral literal2(literal); + QmlDomValueLiteral literal3; + literal3 = literal2; + + QCOMPARE(literal2.literal(), QString("10")); + QCOMPARE(literal3.literal(), QString("10")); + } + + + // QmlDomValueBinding + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("y"); + QmlDomValueBinding binding = property.value().toBinding(); + QCOMPARE(binding.binding(), QString("x + 10")); + + QmlDomValueBinding binding2(binding); + QmlDomValueBinding binding3; + binding3 = binding2; + + QCOMPARE(binding2.binding(), QString("x + 10")); + QCOMPARE(binding3.binding(), QString("x + 10")); + } + + // QmlDomValueValueSource + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("z"); + QmlDomValueValueSource source = property.value().toValueSource(); + QCOMPARE(source.object().objectClassName(), QByteArray("NumberAnimation")); + + QmlDomValueValueSource source2(source); + QmlDomValueValueSource source3; + source3 = source; + + QCOMPARE(source2.object().objectClassName(), QByteArray("NumberAnimation")); + QCOMPARE(source3.object().objectClassName(), QByteArray("NumberAnimation")); + } + + // QmlDomValueValueInterceptor + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("opacity"); + QmlDomValueValueInterceptor interceptor = property.value().toValueInterceptor(); + QCOMPARE(interceptor.object().objectClassName(), QByteArray("Behavior")); + + QmlDomValueValueInterceptor interceptor2(interceptor); + QmlDomValueValueInterceptor interceptor3; + interceptor3 = interceptor; + + QCOMPARE(interceptor2.object().objectClassName(), QByteArray("Behavior")); + QCOMPARE(interceptor3.object().objectClassName(), QByteArray("Behavior")); + } + + // QmlDomComponent + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("data"); + QCOMPARE(property.value().toList().values().count(), 1); + QmlDomComponent component = + property.value().toList().values().at(0).toObject().toComponent(); + QCOMPARE(component.componentRoot().objectClassName(), QByteArray("Item")); + + QmlDomComponent component2(component); + QmlDomComponent component3; + component3 = component; + + QCOMPARE(component.componentRoot().objectClassName(), component2.componentRoot().objectClassName()); + QCOMPARE(component.isValid(), component2.isValid()); + QCOMPARE(component.objectType(), component2.objectType()); + QCOMPARE(component.objectClassName(), component2.objectClassName()); + QCOMPARE(component.objectTypeMajorVersion(), component2.objectTypeMajorVersion()); + QCOMPARE(component.objectTypeMinorVersion(), component2.objectTypeMinorVersion()); + QCOMPARE(component.objectId(), component2.objectId()); + QCOMPARE(component.properties().count(), component2.properties().count()); + QCOMPARE(component.dynamicProperties().count(), component2.dynamicProperties().count()); + QCOMPARE(component.isCustomType(), component2.isCustomType()); + QCOMPARE(component.customTypeData(), component2.customTypeData()); + QCOMPARE(component.isComponent(), component2.isComponent()); + QCOMPARE(component.position(), component2.position()); + QCOMPARE(component.length(), component2.length()); + QCOMPARE(component.url(), component2.url()); + + QCOMPARE(component.componentRoot().objectClassName(), component3.componentRoot().objectClassName()); + QCOMPARE(component.isValid(), component3.isValid()); + QCOMPARE(component.objectType(), component3.objectType()); + QCOMPARE(component.objectClassName(), component3.objectClassName()); + QCOMPARE(component.objectTypeMajorVersion(), component3.objectTypeMajorVersion()); + QCOMPARE(component.objectTypeMinorVersion(), component3.objectTypeMinorVersion()); + QCOMPARE(component.objectId(), component3.objectId()); + QCOMPARE(component.properties().count(), component3.properties().count()); + QCOMPARE(component.dynamicProperties().count(), component3.dynamicProperties().count()); + QCOMPARE(component.isCustomType(), component3.isCustomType()); + QCOMPARE(component.customTypeData(), component3.customTypeData()); + QCOMPARE(component.isComponent(), component3.isComponent()); + QCOMPARE(component.position(), component3.position()); + QCOMPARE(component.length(), component3.length()); + QCOMPARE(component.url(), component3.url()); + } + + // QmlDomValue + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("data"); + QmlDomValue value = property.value(); + + QmlDomValue value2(value); + QmlDomValue value3; + value3 = value; + + QCOMPARE(value.type(), value2.type()); + QCOMPARE(value.isInvalid(), value2.isInvalid()); + QCOMPARE(value.isLiteral(), value2.isLiteral()); + QCOMPARE(value.isBinding(), value2.isBinding()); + QCOMPARE(value.isValueSource(), value2.isValueSource()); + QCOMPARE(value.isValueInterceptor(), value2.isValueInterceptor()); + QCOMPARE(value.isObject(), value2.isObject()); + QCOMPARE(value.isList(), value2.isList()); + QCOMPARE(value.position(), value2.position()); + QCOMPARE(value.length(), value2.length()); + + QCOMPARE(value.type(), value3.type()); + QCOMPARE(value.isInvalid(), value3.isInvalid()); + QCOMPARE(value.isLiteral(), value3.isLiteral()); + QCOMPARE(value.isBinding(), value3.isBinding()); + QCOMPARE(value.isValueSource(), value3.isValueSource()); + QCOMPARE(value.isValueInterceptor(), value3.isValueInterceptor()); + QCOMPARE(value.isObject(), value3.isObject()); + QCOMPARE(value.isList(), value3.isList()); + QCOMPARE(value.position(), value3.position()); + QCOMPARE(value.length(), value3.length()); + } + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("x"); + QmlDomValue value = property.value(); + + QmlDomValue value2(value); + QmlDomValue value3; + value3 = value; + + QCOMPARE(value.type(), value2.type()); + QCOMPARE(value.isInvalid(), value2.isInvalid()); + QCOMPARE(value.isLiteral(), value2.isLiteral()); + QCOMPARE(value.isBinding(), value2.isBinding()); + QCOMPARE(value.isValueSource(), value2.isValueSource()); + QCOMPARE(value.isValueInterceptor(), value2.isValueInterceptor()); + QCOMPARE(value.isObject(), value2.isObject()); + QCOMPARE(value.isList(), value2.isList()); + QCOMPARE(value.position(), value2.position()); + QCOMPARE(value.length(), value2.length()); + + QCOMPARE(value.type(), value3.type()); + QCOMPARE(value.isInvalid(), value3.isInvalid()); + QCOMPARE(value.isLiteral(), value3.isLiteral()); + QCOMPARE(value.isBinding(), value3.isBinding()); + QCOMPARE(value.isValueSource(), value3.isValueSource()); + QCOMPARE(value.isValueInterceptor(), value3.isValueInterceptor()); + QCOMPARE(value.isObject(), value3.isObject()); + QCOMPARE(value.isList(), value3.isList()); + QCOMPARE(value.position(), value3.position()); + QCOMPARE(value.length(), value3.length()); + } + { + QmlDomValue value; + + QmlDomValue value2(value); + QmlDomValue value3; + value3 = value; + + QCOMPARE(value.type(), value2.type()); + QCOMPARE(value.isInvalid(), value2.isInvalid()); + QCOMPARE(value.isLiteral(), value2.isLiteral()); + QCOMPARE(value.isBinding(), value2.isBinding()); + QCOMPARE(value.isValueSource(), value2.isValueSource()); + QCOMPARE(value.isValueInterceptor(), value2.isValueInterceptor()); + QCOMPARE(value.isObject(), value2.isObject()); + QCOMPARE(value.isList(), value2.isList()); + QCOMPARE(value.position(), value2.position()); + QCOMPARE(value.length(), value2.length()); + + QCOMPARE(value.type(), value3.type()); + QCOMPARE(value.isInvalid(), value3.isInvalid()); + QCOMPARE(value.isLiteral(), value3.isLiteral()); + QCOMPARE(value.isBinding(), value3.isBinding()); + QCOMPARE(value.isValueSource(), value3.isValueSource()); + QCOMPARE(value.isValueInterceptor(), value3.isValueInterceptor()); + QCOMPARE(value.isObject(), value3.isObject()); + QCOMPARE(value.isList(), value3.isList()); + QCOMPARE(value.position(), value3.position()); + QCOMPARE(value.length(), value3.length()); + } + + // QmlDomList + { + QmlDomObject object = document.rootObject(); + QmlDomProperty property = object.property("children"); + QmlDomList list = property.value().toList(); + QCOMPARE(list.values().count(), 2); + + QmlDomList list2(list); + QmlDomList list3; + list3 = list2; + + QCOMPARE(list.values().count(), list2.values().count()); + QCOMPARE(list.position(), list2.position()); + QCOMPARE(list.length(), list2.length()); + QCOMPARE(list.commaPositions(), list2.commaPositions()); + + QCOMPARE(list.values().count(), list3.values().count()); + QCOMPARE(list.position(), list3.position()); + QCOMPARE(list.length(), list3.length()); + QCOMPARE(list.commaPositions(), list3.commaPositions()); + + } +} QTEST_MAIN(tst_qmldom) -- cgit v0.12