From ce78e4124d57a3c517e6de88696a09ad399c703f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 11:08:37 +1000 Subject: Add documentation on QMLs memory management assumptions --- doc/src/declarative/extending.qdoc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/doc/src/declarative/extending.qdoc b/doc/src/declarative/extending.qdoc index 0456f3f..d3e6c14 100644 --- a/doc/src/declarative/extending.qdoc +++ b/doc/src/declarative/extending.qdoc @@ -375,6 +375,37 @@ object will only be returned if it has previously been created. \l {Extending QML - Attached Properties Example} shows the complete code used to implement the rsvp attached property. +\section1 Memory Management and QVariant types + +It is an elements responsibility to ensure that it does not access or return +pointers to invalid objects. QML makes the following guarentees: + +\list +\o An object assigned to an QObject (or QObject-derived) pointer property will be +valid at the time of assignment. + +Following assignment, it is the responsibility of the class to subsequently guard +this pointer, either through a class specific method or the generic QPointer class. + +\o An object assigned to a QVariant will be valid at the time of assignment. + +When assigning an object to a QVariant property, QML will always use a QMetaType::QObjectStar +typed QVariant. It is the responsibility of the class to guard the pointer. A +general rule when writing a class that uses QVariant properties is to check the +type of the QVariant when it is set and if the type is not handled by your class, +reset it to an invalid variant. + +\o An object assigned to a QObject (or QObject-derived) list property will be +valid at the time of assignment. + +Following assignment, it is the responsibility of the class to subsequently guard +this pointer, either through a class specific method or the generic QPointer class. +\endlist + +Elements should assume that any QML assigned object can be deleted at any time, and +respond accordingly. If documented as such an element need not continue to work in +this situation, but it must not crash. + \section1 Signal Support \snippet examples/declarative/extending/signal/example.qml 0 -- cgit v0.12 From c41f7c7a4dbb2ac0c76e20628aaedeabec6f4497 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 22 Feb 2010 17:26:20 +1000 Subject: Better support modelData for object list models. modelData will now correctly return the actual object. --- src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index b96f399..9216793 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -415,7 +415,7 @@ int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, c if (model->m_listAccessor->type() == QmlListAccessor::ListProperty) { model->ensureRoles(); QObject *object = model->m_listAccessor->at(data->m_index).value(); - if (object && object->property(name).isValid()) + if (object && (object->property(name).isValid() || qstrcmp(name,"modelData")==0)) return QmlOpenMetaObject::createProperty(name, type); } } -- cgit v0.12 From 5955a7bd3bcef20558238e2de0c66fac9eccdf57 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 12:41:24 +1000 Subject: Small QmlMetaProperty code cleanup --- src/declarative/qml/qmlmetaproperty.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 7c273dc..332d126 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -811,22 +811,22 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data return writeEnumProperty(prop, coreIdx, object, v, flags); } - int t = property.propType; - int vt = value.userType(); + int propertyType = property.propType; + int variantType = value.userType(); QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(context); - if (t == QVariant::Url) { + if (propertyType == QVariant::Url) { QUrl u; bool found = false; - if (vt == QVariant::Url) { + if (variantType == QVariant::Url) { u = value.toUrl(); found = true; - } else if (vt == QVariant::ByteArray) { + } else if (variantType == QVariant::ByteArray) { u = QUrl(QString::fromUtf8(value.toByteArray())); found = true; - } else if (vt == QVariant::String) { + } else if (variantType == QVariant::String) { u = QUrl(value.toString()); found = true; } @@ -840,12 +840,12 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data void *argv[] = { &u, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv); - } else if (vt == t) { + } else if (variantType == propertyType) { void *a[] = { (void *)value.constData(), 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - } else if (qMetaTypeId() == t) { + } else if (qMetaTypeId() == propertyType) { void *a[] = { (void *)&value, 0, &status, &flags }; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); @@ -858,7 +858,7 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data return false; QObject *o = *(QObject **)value.constData(); - const QMetaObject *propMo = rawMetaObjectForType(enginePriv, t); + const QMetaObject *propMo = rawMetaObjectForType(enginePriv, propertyType); if (o) valMo = o->metaObject(); @@ -914,25 +914,25 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data } } else { - Q_ASSERT(vt != t); + Q_ASSERT(variantType != propertyType); QVariant v = value; - if (v.convert((QVariant::Type)t)) { + if (v.convert((QVariant::Type)propertyType)) { void *a[] = { (void *)v.constData(), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); - } else if ((uint)t >= QVariant::UserType && vt == QVariant::String) { - QmlMetaType::StringConverter con = QmlMetaType::customStringConverter(t); + } else if ((uint)propertyType >= QVariant::UserType && variantType == QVariant::String) { + QmlMetaType::StringConverter con = QmlMetaType::customStringConverter(propertyType); if (!con) return false; QVariant v = con(value.toString()); - if (v.userType() == t) { + if (v.userType() == propertyType) { void *a[] = { (void *)v.constData(), 0, &status, &flags}; QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); } - } else if (vt == QVariant::String) { + } else if (variantType == QVariant::String) { bool ok = false; - QVariant v = QmlStringConverters::variantFromString(value.toString(), t, &ok); + QVariant v = QmlStringConverters::variantFromString(value.toString(), propertyType, &ok); if (!ok) return false; -- cgit v0.12 From 0bc70bc54e1e67468db1dd11ec4fad3a178768c3 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 12:45:21 +1000 Subject: Rename qmllist autotest to qmllistreference --- tests/auto/declarative/declarative.pro | 2 +- tests/auto/declarative/qmllist/data/MyType.qml | 5 - .../auto/declarative/qmllist/data/engineTypes.qml | 9 - .../declarative/qmllist/data/variantToList.qml | 10 - tests/auto/declarative/qmllist/qmllist.pro | 5 - tests/auto/declarative/qmllist/tst_qmllist.cpp | 574 --------------------- .../declarative/qmllistreference/data/MyType.qml | 5 + .../qmllistreference/data/engineTypes.qml | 9 + .../qmllistreference/data/variantToList.qml | 10 + .../qmllistreference/qmllistreference.pro | 5 + .../qmllistreference/tst_qmllistreference.cpp | 574 +++++++++++++++++++++ 11 files changed, 604 insertions(+), 604 deletions(-) delete mode 100644 tests/auto/declarative/qmllist/data/MyType.qml delete mode 100644 tests/auto/declarative/qmllist/data/engineTypes.qml delete mode 100644 tests/auto/declarative/qmllist/data/variantToList.qml delete mode 100644 tests/auto/declarative/qmllist/qmllist.pro delete mode 100644 tests/auto/declarative/qmllist/tst_qmllist.cpp create mode 100644 tests/auto/declarative/qmllistreference/data/MyType.qml create mode 100644 tests/auto/declarative/qmllistreference/data/engineTypes.qml create mode 100644 tests/auto/declarative/qmllistreference/data/variantToList.qml create mode 100644 tests/auto/declarative/qmllistreference/qmllistreference.pro create mode 100644 tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 645f794..870c92b 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -39,7 +39,7 @@ SUBDIRS += \ qmlinfo \ # Cover qmlinstruction \ # Cover qmllanguage \ # Cover - qmllist \ # Cover + qmllistreference \ # Cover qmllistmodel \ # Cover qmlmetaproperty \ # Cover qmlmetatype \ # Cover diff --git a/tests/auto/declarative/qmllist/data/MyType.qml b/tests/auto/declarative/qmllist/data/MyType.qml deleted file mode 100644 index d08f35b..0000000 --- a/tests/auto/declarative/qmllist/data/MyType.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt 4.6 - -QtObject { - property int a -} diff --git a/tests/auto/declarative/qmllist/data/engineTypes.qml b/tests/auto/declarative/qmllist/data/engineTypes.qml deleted file mode 100644 index 670aee4..0000000 --- a/tests/auto/declarative/qmllist/data/engineTypes.qml +++ /dev/null @@ -1,9 +0,0 @@ -import Qt 4.6 - -QtObject { - property list myList - - myList: [ MyType { a: 1 }, - MyType { a: 9 } ] - -} diff --git a/tests/auto/declarative/qmllist/data/variantToList.qml b/tests/auto/declarative/qmllist/data/variantToList.qml deleted file mode 100644 index 0c2d0aa..0000000 --- a/tests/auto/declarative/qmllist/data/variantToList.qml +++ /dev/null @@ -1,10 +0,0 @@ -import Qt 4.6 - -QtObject { - property list myList; - myList: QtObject {} - - property var value: myList - property int test: value.length -} - diff --git a/tests/auto/declarative/qmllist/qmllist.pro b/tests/auto/declarative/qmllist/qmllist.pro deleted file mode 100644 index b2145ed..0000000 --- a/tests/auto/declarative/qmllist/qmllist.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative -macx:CONFIG -= app_bundle - -SOURCES += tst_qmllist.cpp diff --git a/tests/auto/declarative/qmllist/tst_qmllist.cpp b/tests/auto/declarative/qmllist/tst_qmllist.cpp deleted file mode 100644 index 76def1c..0000000 --- a/tests/auto/declarative/qmllist/tst_qmllist.cpp +++ /dev/null @@ -1,574 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -inline QUrl TEST_FILE(const QString &filename) -{ - QFileInfo fileInfo(__FILE__); - return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename)); -} - -inline QUrl TEST_FILE(const char *filename) -{ - return TEST_FILE(QLatin1String(filename)); -} - -class tst_QmlList : public QObject -{ - Q_OBJECT -public: - tst_QmlList() {} - -private slots: - void qmllistreference(); - void qmllistreference_invalid(); - void isValid(); - void object(); - void listElementType(); - void canAppend(); - void canAt(); - void canClear(); - void canCount(); - void append(); - void at(); - void clear(); - void count(); - void copy(); - void qmlmetaproperty(); - void engineTypes(); - void variantToList(); -}; - -class TestType : public QObject -{ - Q_OBJECT - Q_PROPERTY(QmlListProperty data READ dataProperty); - Q_PROPERTY(int intProperty READ intProperty); - -public: - TestType() : property(this, data) {} - QmlListProperty dataProperty() { return property; } - int intProperty() const { return 10; } - - QList data; - QmlListProperty property; -}; -QML_DECLARE_TYPE(TestType); -QML_DEFINE_NOCREATE_TYPE(TestType); - -void tst_QmlList::qmllistreference() -{ - TestType tt; - - QmlListReference r(&tt, "data"); - QVERIFY(r.isValid() == true); - QCOMPARE(r.count(), 0); - - tt.data.append(&tt); - QCOMPARE(r.count(), 1); -} - -void tst_QmlList::qmllistreference_invalid() -{ - TestType tt; - - // Invalid - { - QmlListReference r; - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - } - - // Non-property - { - QmlListReference r(&tt, "blah"); - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - } - - // Non-list property - { - QmlListReference r(&tt, "intProperty"); - QVERIFY(r.isValid() == false); - QVERIFY(r.object() == 0); - QVERIFY(r.listElementType() == 0); - QVERIFY(r.canAt() == false); - QVERIFY(r.canClear() == false); - QVERIFY(r.canCount() == false); - QVERIFY(r.append(0) == false); - QVERIFY(r.at(10) == 0); - QVERIFY(r.clear() == false); - QVERIFY(r.count() == 0); - } -} - -void tst_QmlList::isValid() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.isValid() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.isValid() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.isValid() == true); - delete tt; - QVERIFY(ref.isValid() == false); - } -} - -void tst_QmlList::object() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.object() == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.object() == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.object() == tt); - delete tt; - QVERIFY(ref.object() == 0); - } -} - -void tst_QmlList::listElementType() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.listElementType() == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.listElementType() == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.listElementType() == &TestType::staticMetaObject); - delete tt; - QVERIFY(ref.listElementType() == 0); - } -} - -void tst_QmlList::canAppend() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canAppend() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canAppend() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canAppend() == true); - delete tt; - QVERIFY(ref.canAppend() == false); - } - - { - TestType tt; - tt.property.append = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canAppend() == false); - } -} - -void tst_QmlList::canAt() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canAt() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canAt() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canAt() == true); - delete tt; - QVERIFY(ref.canAt() == false); - } - - { - TestType tt; - tt.property.at = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canAt() == false); - } -} - -void tst_QmlList::canClear() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canClear() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canClear() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canClear() == true); - delete tt; - QVERIFY(ref.canClear() == false); - } - - { - TestType tt; - tt.property.clear = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canClear() == false); - } -} - -void tst_QmlList::canCount() -{ - TestType *tt = new TestType; - - { - QmlListReference ref; - QVERIFY(ref.canCount() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.canCount() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.canCount() == true); - delete tt; - QVERIFY(ref.canCount() == false); - } - - { - TestType tt; - tt.property.count = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.canCount() == false); - } -} - -void tst_QmlList::append() -{ - TestType *tt = new TestType; - QObject object; - - { - QmlListReference ref; - QVERIFY(ref.append(tt) == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.append(tt) == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.append(tt) == true); - QVERIFY(tt->data.count() == 1); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(ref.append(&object) == false); - QVERIFY(tt->data.count() == 1); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(ref.append(0) == true); - QVERIFY(tt->data.count() == 2); - QVERIFY(tt->data.at(0) == tt); - QVERIFY(tt->data.at(1) == 0); - delete tt; - QVERIFY(ref.append(0) == false); - } - - { - TestType tt; - tt.property.append = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.append(&tt) == false); - } -} - -void tst_QmlList::at() -{ - TestType *tt = new TestType; - tt->data.append(tt); - tt->data.append(0); - tt->data.append(tt); - - { - QmlListReference ref; - QVERIFY(ref.at(0) == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.at(0) == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.at(0) == tt); - QVERIFY(ref.at(1) == 0); - QVERIFY(ref.at(2) == tt); - delete tt; - QVERIFY(ref.at(0) == 0); - } - - { - TestType tt; - tt.data.append(&tt); - tt.property.at = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.at(0) == 0); - } -} - -void tst_QmlList::clear() -{ - TestType *tt = new TestType; - tt->data.append(tt); - tt->data.append(0); - tt->data.append(tt); - - { - QmlListReference ref; - QVERIFY(ref.clear() == false); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.clear() == false); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.clear() == true); - QVERIFY(tt->data.count() == 0); - delete tt; - QVERIFY(ref.clear() == false); - } - - { - TestType tt; - tt.property.clear = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.clear() == false); - } -} - -void tst_QmlList::count() -{ - TestType *tt = new TestType; - tt->data.append(tt); - tt->data.append(0); - tt->data.append(tt); - - { - QmlListReference ref; - QVERIFY(ref.count() == 0); - } - - { - QmlListReference ref(tt, "blah"); - QVERIFY(ref.count() == 0); - } - - { - QmlListReference ref(tt, "data"); - QVERIFY(ref.count() == 3); - tt->data.removeAt(1); - QVERIFY(ref.count() == 2); - delete tt; - QVERIFY(ref.count() == 0); - } - - { - TestType tt; - tt.data.append(&tt); - tt.property.count = 0; - QmlListReference ref(&tt, "data"); - QVERIFY(ref.count() == 0); - } -} - -void tst_QmlList::copy() -{ - TestType tt; - tt.data.append(&tt); - tt.data.append(0); - tt.data.append(&tt); - - QmlListReference *r1 = new QmlListReference(&tt, "data"); - QVERIFY(r1->count() == 3); - - QmlListReference r2(*r1); - QmlListReference r3; - r3 = *r1; - - QVERIFY(r2.count() == 3); - QVERIFY(r3.count() == 3); - - delete r1; - - QVERIFY(r2.count() == 3); - QVERIFY(r3.count() == 3); - - tt.data.removeAt(2); - - QVERIFY(r2.count() == 2); - QVERIFY(r3.count() == 2); -} - -void tst_QmlList::qmlmetaproperty() -{ - TestType tt; - tt.data.append(&tt); - tt.data.append(0); - tt.data.append(&tt); - - QmlMetaProperty prop(&tt, QLatin1String("data")); - QVariant v = prop.read(); - QVERIFY(v.userType() == qMetaTypeId()); - QmlListReference ref = qvariant_cast(v); - QVERIFY(ref.count() == 3); - QVERIFY(ref.listElementType() == &TestType::staticMetaObject); -} - -void tst_QmlList::engineTypes() -{ - QmlEngine engine; - QmlComponent component(&engine, TEST_FILE("engineTypes.qml")); - - QObject *o = component.create(); - QVERIFY(o); - - QmlMetaProperty p1(o, QLatin1String("myList")); - QVERIFY(p1.propertyCategory() == QmlMetaProperty::Normal); - - QmlMetaProperty p2(o, QLatin1String("myList"), engine.rootContext()); - QVERIFY(p2.propertyCategory() == QmlMetaProperty::List); - QVariant v = p2.read(); - QVERIFY(v.userType() == qMetaTypeId()); - QmlListReference ref = qvariant_cast(v); - QVERIFY(ref.count() == 2); - QVERIFY(ref.listElementType()); - QVERIFY(ref.listElementType() != &QObject::staticMetaObject); - - delete o; -} - -void tst_QmlList::variantToList() -{ - QmlEngine engine; - QmlComponent component(&engine, TEST_FILE("variantToList.qml")); - - QObject *o = component.create(); - QVERIFY(o); - - QVERIFY(o->property("value").userType() == qMetaTypeId()); - QCOMPARE(o->property("test").toInt(), 1); - - delete o; -} - -QTEST_MAIN(tst_QmlList) - -#include "tst_qmllist.moc" diff --git a/tests/auto/declarative/qmllistreference/data/MyType.qml b/tests/auto/declarative/qmllistreference/data/MyType.qml new file mode 100644 index 0000000..d08f35b --- /dev/null +++ b/tests/auto/declarative/qmllistreference/data/MyType.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +QtObject { + property int a +} diff --git a/tests/auto/declarative/qmllistreference/data/engineTypes.qml b/tests/auto/declarative/qmllistreference/data/engineTypes.qml new file mode 100644 index 0000000..670aee4 --- /dev/null +++ b/tests/auto/declarative/qmllistreference/data/engineTypes.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property list myList + + myList: [ MyType { a: 1 }, + MyType { a: 9 } ] + +} diff --git a/tests/auto/declarative/qmllistreference/data/variantToList.qml b/tests/auto/declarative/qmllistreference/data/variantToList.qml new file mode 100644 index 0000000..0c2d0aa --- /dev/null +++ b/tests/auto/declarative/qmllistreference/data/variantToList.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +QtObject { + property list myList; + myList: QtObject {} + + property var value: myList + property int test: value.length +} + diff --git a/tests/auto/declarative/qmllistreference/qmllistreference.pro b/tests/auto/declarative/qmllistreference/qmllistreference.pro new file mode 100644 index 0000000..fa49d5a --- /dev/null +++ b/tests/auto/declarative/qmllistreference/qmllistreference.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += tst_qmllistreference.cpp diff --git a/tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp b/tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp new file mode 100644 index 0000000..6122f1e --- /dev/null +++ b/tests/auto/declarative/qmllistreference/tst_qmllistreference.cpp @@ -0,0 +1,574 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath("data/" + filename)); +} + +inline QUrl TEST_FILE(const char *filename) +{ + return TEST_FILE(QLatin1String(filename)); +} + +class tst_qmllistreference : public QObject +{ + Q_OBJECT +public: + tst_qmllistreference() {} + +private slots: + void qmllistreference(); + void qmllistreference_invalid(); + void isValid(); + void object(); + void listElementType(); + void canAppend(); + void canAt(); + void canClear(); + void canCount(); + void append(); + void at(); + void clear(); + void count(); + void copy(); + void qmlmetaproperty(); + void engineTypes(); + void variantToList(); +}; + +class TestType : public QObject +{ + Q_OBJECT + Q_PROPERTY(QmlListProperty data READ dataProperty); + Q_PROPERTY(int intProperty READ intProperty); + +public: + TestType() : property(this, data) {} + QmlListProperty dataProperty() { return property; } + int intProperty() const { return 10; } + + QList data; + QmlListProperty property; +}; +QML_DECLARE_TYPE(TestType); +QML_DEFINE_NOCREATE_TYPE(TestType); + +void tst_qmllistreference::qmllistreference() +{ + TestType tt; + + QmlListReference r(&tt, "data"); + QVERIFY(r.isValid() == true); + QCOMPARE(r.count(), 0); + + tt.data.append(&tt); + QCOMPARE(r.count(), 1); +} + +void tst_qmllistreference::qmllistreference_invalid() +{ + TestType tt; + + // Invalid + { + QmlListReference r; + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } + + // Non-property + { + QmlListReference r(&tt, "blah"); + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } + + // Non-list property + { + QmlListReference r(&tt, "intProperty"); + QVERIFY(r.isValid() == false); + QVERIFY(r.object() == 0); + QVERIFY(r.listElementType() == 0); + QVERIFY(r.canAt() == false); + QVERIFY(r.canClear() == false); + QVERIFY(r.canCount() == false); + QVERIFY(r.append(0) == false); + QVERIFY(r.at(10) == 0); + QVERIFY(r.clear() == false); + QVERIFY(r.count() == 0); + } +} + +void tst_qmllistreference::isValid() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.isValid() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.isValid() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.isValid() == true); + delete tt; + QVERIFY(ref.isValid() == false); + } +} + +void tst_qmllistreference::object() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.object() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.object() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.object() == tt); + delete tt; + QVERIFY(ref.object() == 0); + } +} + +void tst_qmllistreference::listElementType() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.listElementType() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.listElementType() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.listElementType() == &TestType::staticMetaObject); + delete tt; + QVERIFY(ref.listElementType() == 0); + } +} + +void tst_qmllistreference::canAppend() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canAppend() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canAppend() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canAppend() == true); + delete tt; + QVERIFY(ref.canAppend() == false); + } + + { + TestType tt; + tt.property.append = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canAppend() == false); + } +} + +void tst_qmllistreference::canAt() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canAt() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canAt() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canAt() == true); + delete tt; + QVERIFY(ref.canAt() == false); + } + + { + TestType tt; + tt.property.at = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canAt() == false); + } +} + +void tst_qmllistreference::canClear() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canClear() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canClear() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canClear() == true); + delete tt; + QVERIFY(ref.canClear() == false); + } + + { + TestType tt; + tt.property.clear = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canClear() == false); + } +} + +void tst_qmllistreference::canCount() +{ + TestType *tt = new TestType; + + { + QmlListReference ref; + QVERIFY(ref.canCount() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.canCount() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.canCount() == true); + delete tt; + QVERIFY(ref.canCount() == false); + } + + { + TestType tt; + tt.property.count = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.canCount() == false); + } +} + +void tst_qmllistreference::append() +{ + TestType *tt = new TestType; + QObject object; + + { + QmlListReference ref; + QVERIFY(ref.append(tt) == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.append(tt) == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.append(tt) == true); + QVERIFY(tt->data.count() == 1); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(ref.append(&object) == false); + QVERIFY(tt->data.count() == 1); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(ref.append(0) == true); + QVERIFY(tt->data.count() == 2); + QVERIFY(tt->data.at(0) == tt); + QVERIFY(tt->data.at(1) == 0); + delete tt; + QVERIFY(ref.append(0) == false); + } + + { + TestType tt; + tt.property.append = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.append(&tt) == false); + } +} + +void tst_qmllistreference::at() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.at(0) == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.at(0) == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.at(0) == tt); + QVERIFY(ref.at(1) == 0); + QVERIFY(ref.at(2) == tt); + delete tt; + QVERIFY(ref.at(0) == 0); + } + + { + TestType tt; + tt.data.append(&tt); + tt.property.at = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.at(0) == 0); + } +} + +void tst_qmllistreference::clear() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.clear() == false); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.clear() == false); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.clear() == true); + QVERIFY(tt->data.count() == 0); + delete tt; + QVERIFY(ref.clear() == false); + } + + { + TestType tt; + tt.property.clear = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.clear() == false); + } +} + +void tst_qmllistreference::count() +{ + TestType *tt = new TestType; + tt->data.append(tt); + tt->data.append(0); + tt->data.append(tt); + + { + QmlListReference ref; + QVERIFY(ref.count() == 0); + } + + { + QmlListReference ref(tt, "blah"); + QVERIFY(ref.count() == 0); + } + + { + QmlListReference ref(tt, "data"); + QVERIFY(ref.count() == 3); + tt->data.removeAt(1); + QVERIFY(ref.count() == 2); + delete tt; + QVERIFY(ref.count() == 0); + } + + { + TestType tt; + tt.data.append(&tt); + tt.property.count = 0; + QmlListReference ref(&tt, "data"); + QVERIFY(ref.count() == 0); + } +} + +void tst_qmllistreference::copy() +{ + TestType tt; + tt.data.append(&tt); + tt.data.append(0); + tt.data.append(&tt); + + QmlListReference *r1 = new QmlListReference(&tt, "data"); + QVERIFY(r1->count() == 3); + + QmlListReference r2(*r1); + QmlListReference r3; + r3 = *r1; + + QVERIFY(r2.count() == 3); + QVERIFY(r3.count() == 3); + + delete r1; + + QVERIFY(r2.count() == 3); + QVERIFY(r3.count() == 3); + + tt.data.removeAt(2); + + QVERIFY(r2.count() == 2); + QVERIFY(r3.count() == 2); +} + +void tst_qmllistreference::qmlmetaproperty() +{ + TestType tt; + tt.data.append(&tt); + tt.data.append(0); + tt.data.append(&tt); + + QmlMetaProperty prop(&tt, QLatin1String("data")); + QVariant v = prop.read(); + QVERIFY(v.userType() == qMetaTypeId()); + QmlListReference ref = qvariant_cast(v); + QVERIFY(ref.count() == 3); + QVERIFY(ref.listElementType() == &TestType::staticMetaObject); +} + +void tst_qmllistreference::engineTypes() +{ + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("engineTypes.qml")); + + QObject *o = component.create(); + QVERIFY(o); + + QmlMetaProperty p1(o, QLatin1String("myList")); + QVERIFY(p1.propertyCategory() == QmlMetaProperty::Normal); + + QmlMetaProperty p2(o, QLatin1String("myList"), engine.rootContext()); + QVERIFY(p2.propertyCategory() == QmlMetaProperty::List); + QVariant v = p2.read(); + QVERIFY(v.userType() == qMetaTypeId()); + QmlListReference ref = qvariant_cast(v); + QVERIFY(ref.count() == 2); + QVERIFY(ref.listElementType()); + QVERIFY(ref.listElementType() != &QObject::staticMetaObject); + + delete o; +} + +void tst_qmllistreference::variantToList() +{ + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("variantToList.qml")); + + QObject *o = component.create(); + QVERIFY(o); + + QVERIFY(o->property("value").userType() == qMetaTypeId()); + QCOMPARE(o->property("test").toInt(), 1); + + delete o; +} + +QTEST_MAIN(tst_qmllistreference) + +#include "tst_qmllistreference.moc" -- cgit v0.12 From c151647c01dd8034ee77a00520430cfb516a6a38 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 12:56:39 +1000 Subject: Cleanup warnings in qmlmetaproperty test --- .../qmlmetaproperty/tst_qmlmetaproperty.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index 050cd3f..b763b6e 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -129,7 +129,7 @@ void tst_qmlmetaproperty::qmlmetaproperty() { QmlMetaProperty prop; - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -218,7 +218,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() { QmlMetaProperty prop(&object); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -264,7 +264,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object() { QmlMetaProperty prop(&dobject); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -319,7 +319,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() { QmlMetaProperty prop(&object, QString("defaultProperty")); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -365,7 +365,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() { QmlMetaProperty prop(&dobject, QString("defaultProperty")); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -414,7 +414,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string() { QmlMetaProperty prop(&dobject, QString("onClicked")); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -468,7 +468,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() { QmlMetaProperty prop(&object, engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -514,7 +514,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_context() { QmlMetaProperty prop(&dobject, engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -569,7 +569,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() { QmlMetaProperty prop(&object, QString("defaultProperty"), engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); QVERIFY(expression != 0); @@ -615,7 +615,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() { QmlMetaProperty prop(&dobject, QString("defaultProperty"), engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); @@ -664,7 +664,7 @@ void tst_qmlmetaproperty::qmlmetaproperty_object_string_context() { QmlMetaProperty prop(&dobject, QString("onClicked"), engine.rootContext()); - QGuard binding(new QmlBinding(QString(), 0, 0)); + QGuard binding(new QmlBinding(QLatin1String("null"), 0, engine.rootContext())); binding->setTarget(prop); QVERIFY(binding != 0); QGuard expression(new QmlExpression()); -- cgit v0.12 From 23316b14f28eb1b135b6e8e90fa6fdb34dc39b59 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 23 Feb 2010 13:06:22 +1000 Subject: Fix but in QmlMetaProperty assignment operator QTBUG-8166 --- src/declarative/qml/qmlmetaproperty.cpp | 2 + .../qmlmetaproperty/tst_qmlmetaproperty.cpp | 43 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 332d126..1742c43 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -378,7 +378,9 @@ QmlMetaProperty &QmlMetaProperty::operator=(const QmlMetaProperty &other) d->object = other.d->object; d->isDefaultProperty = other.d->isDefaultProperty; + d->isNameCached = other.d->isNameCached; d->core = other.d->core; + d->nameCache = other.d->nameCache; d->valueType = other.d->valueType; diff --git a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp index b763b6e..c289641 100644 --- a/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp +++ b/tests/auto/declarative/qmlmetaproperty/tst_qmlmetaproperty.cpp @@ -121,6 +121,7 @@ private slots: // Bugs void crashOnValueProperty(); + void copy(); private: QmlEngine engine; }; @@ -1131,6 +1132,48 @@ void tst_qmlmetaproperty::crashOnValueProperty() QCOMPARE(p.read(), QVariant(20)); } +void tst_qmlmetaproperty::copy() +{ + PropertyObject object; + + QmlMetaProperty *property = new QmlMetaProperty(&object, QLatin1String("defaultProperty")); + QCOMPARE(property->name(), QString("defaultProperty")); + QCOMPARE(property->read(), QVariant(10)); + QCOMPARE(property->type(), QmlMetaProperty::Property); + QCOMPARE(property->propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(property->propertyType(), (int)QVariant::Int); + + QmlMetaProperty p1(*property); + QCOMPARE(p1.name(), QString("defaultProperty")); + QCOMPARE(p1.read(), QVariant(10)); + QCOMPARE(p1.type(), QmlMetaProperty::Property); + QCOMPARE(p1.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p1.propertyType(), (int)QVariant::Int); + + QmlMetaProperty p2(&object, QLatin1String("url")); + QCOMPARE(p2.name(), QString("url")); + p2 = *property; + QCOMPARE(p2.name(), QString("defaultProperty")); + QCOMPARE(p2.read(), QVariant(10)); + QCOMPARE(p2.type(), QmlMetaProperty::Property); + QCOMPARE(p2.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p2.propertyType(), (int)QVariant::Int); + + delete property; property = 0; + + QCOMPARE(p1.name(), QString("defaultProperty")); + QCOMPARE(p1.read(), QVariant(10)); + QCOMPARE(p1.type(), QmlMetaProperty::Property); + QCOMPARE(p1.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p1.propertyType(), (int)QVariant::Int); + + QCOMPARE(p2.name(), QString("defaultProperty")); + QCOMPARE(p2.read(), QVariant(10)); + QCOMPARE(p2.type(), QmlMetaProperty::Property); + QCOMPARE(p2.propertyCategory(), QmlMetaProperty::Normal); + QCOMPARE(p2.propertyType(), (int)QVariant::Int); +} + QTEST_MAIN(tst_qmlmetaproperty) #include "tst_qmlmetaproperty.moc" -- cgit v0.12