tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include <qtest.h>
       
    42 #include <QtDeclarative/qdeclarativeengine.h>
       
    43 #include <QtDeclarative/qdeclarativecomponent.h>
       
    44 #include <QtDeclarative/qdeclarativeproperty.h>
       
    45 #include <QtDeclarative/private/qdeclarativeproperty_p.h>
       
    46 #include <private/qdeclarativebinding_p.h>
       
    47 #include <QtGui/QLineEdit>
       
    48 #include <QtCore/qfileinfo.h>
       
    49 #include <QtCore/qdir.h>
       
    50 
       
    51 inline QUrl TEST_FILE(const QString &filename)
       
    52 {
       
    53     QFileInfo fileInfo(__FILE__);
       
    54     return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(QLatin1String("data/") + filename));
       
    55 }
       
    56 
       
    57 class MyQmlObject : public QObject
       
    58 {
       
    59     Q_OBJECT
       
    60 public:
       
    61     MyQmlObject() {}
       
    62 };
       
    63 
       
    64 QML_DECLARE_TYPE(MyQmlObject);
       
    65 
       
    66 class MyAttached : public QObject
       
    67 {
       
    68     Q_OBJECT
       
    69     Q_PROPERTY(int foo READ foo WRITE setFoo)
       
    70 public:
       
    71     MyAttached(QObject *parent) : QObject(parent), m_foo(13) {}
       
    72 
       
    73     int foo() const { return m_foo; }
       
    74     void setFoo(int f) { m_foo = f; }
       
    75 
       
    76 private:
       
    77     int m_foo;
       
    78 };
       
    79 
       
    80 class MyContainer : public QObject
       
    81 {
       
    82     Q_OBJECT
       
    83     Q_PROPERTY(QDeclarativeListProperty<MyQmlObject> children READ children)
       
    84 public:
       
    85     MyContainer() {}
       
    86 
       
    87     QDeclarativeListProperty<MyQmlObject> children() { return QDeclarativeListProperty<MyQmlObject>(this, m_children); }
       
    88 
       
    89     static MyAttached *qmlAttachedProperties(QObject *o) {
       
    90         return new MyAttached(o);
       
    91     }
       
    92 
       
    93 private:
       
    94     QList<MyQmlObject*> m_children;
       
    95 };
       
    96 
       
    97 QML_DECLARE_TYPE(MyContainer);
       
    98 QML_DECLARE_TYPEINFO(MyContainer, QML_HAS_ATTACHED_PROPERTIES)
       
    99 
       
   100 class tst_qdeclarativeproperty : public QObject
       
   101 {
       
   102     Q_OBJECT
       
   103 public:
       
   104     tst_qdeclarativeproperty() {}
       
   105 
       
   106 private slots:
       
   107     void initTestCase();
       
   108 
       
   109     // Constructors
       
   110     void qmlmetaproperty();
       
   111     void qmlmetaproperty_object();
       
   112     void qmlmetaproperty_object_string();
       
   113     void qmlmetaproperty_object_context();
       
   114     void qmlmetaproperty_object_string_context();
       
   115 
       
   116     // Methods
       
   117     void name();
       
   118     void read();
       
   119     void write();
       
   120     void reset();
       
   121 
       
   122     // Functionality
       
   123     void writeObjectToList();
       
   124     void writeListToList();
       
   125 
       
   126     //writeToReadOnly();
       
   127 
       
   128     // Bugs
       
   129     void crashOnValueProperty();
       
   130 
       
   131     void copy();
       
   132 private:
       
   133     QDeclarativeEngine engine;
       
   134 };
       
   135 
       
   136 void tst_qdeclarativeproperty::qmlmetaproperty()
       
   137 {
       
   138     QDeclarativeProperty prop;
       
   139 
       
   140     QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   141     QVERIFY(binding != 0);
       
   142     QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   143     QVERIFY(expression != 0);
       
   144 
       
   145     QObject *obj = new QObject;
       
   146 
       
   147     QCOMPARE(prop.name(), QString());
       
   148     QCOMPARE(prop.read(), QVariant());
       
   149     QCOMPARE(prop.write(QVariant()), false);
       
   150     QCOMPARE(prop.hasNotifySignal(), false);
       
   151     QCOMPARE(prop.needsNotifySignal(), false);
       
   152     QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   153     QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   154     QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   155     QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   156     QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   157     QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   158     QVERIFY(prop.method().signature() == 0);
       
   159     QCOMPARE(prop.type(), QDeclarativeProperty::Invalid);
       
   160     QCOMPARE(prop.isProperty(), false);
       
   161     QCOMPARE(prop.isWritable(), false);
       
   162     QCOMPARE(prop.isDesignable(), false);
       
   163     QCOMPARE(prop.isResettable(), false);
       
   164     QCOMPARE(prop.isValid(), false);
       
   165     QCOMPARE(prop.object(), (QObject *)0);
       
   166     QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   167     QCOMPARE(prop.propertyType(), 0);
       
   168     QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   169     QVERIFY(prop.property().name() == 0);
       
   170     QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   171     QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   172     QVERIFY(binding == 0);
       
   173     QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   174     QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   175     QVERIFY(expression == 0);
       
   176     QCOMPARE(prop.index(), -1);
       
   177     QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   178 
       
   179     delete obj;
       
   180 }
       
   181 
       
   182 class PropertyObject : public QObject
       
   183 {
       
   184     Q_OBJECT
       
   185     Q_PROPERTY(int defaultProperty READ defaultProperty)
       
   186     Q_PROPERTY(QRect rectProperty READ rectProperty)
       
   187     Q_PROPERTY(QRect wrectProperty READ wrectProperty WRITE setWRectProperty)
       
   188     Q_PROPERTY(QUrl url READ url WRITE setUrl)
       
   189     Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty)
       
   190     Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal)
       
   191     Q_PROPERTY(MyQmlObject *qmlObject READ qmlObject)
       
   192 
       
   193     Q_CLASSINFO("DefaultProperty", "defaultProperty")
       
   194 public:
       
   195     PropertyObject() : m_resetProperty(9) {}
       
   196 
       
   197     int defaultProperty() { return 10; }
       
   198     QRect rectProperty() { return QRect(10, 10, 1, 209); }
       
   199 
       
   200     QRect wrectProperty() { return m_rect; }
       
   201     void setWRectProperty(const QRect &r) { m_rect = r; }
       
   202 
       
   203     QUrl url() { return m_url; }
       
   204     void setUrl(const QUrl &u) { m_url = u; }
       
   205 
       
   206     int resettableProperty() const { return m_resetProperty; }
       
   207     void setResettableProperty(int r) { m_resetProperty = r; }
       
   208     void resetProperty() { m_resetProperty = 9; }
       
   209 
       
   210     int propertyWithNotify() const { return m_propertyWithNotify; }
       
   211     void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); }
       
   212 
       
   213     MyQmlObject *qmlObject() { return &m_qmlObject; }
       
   214 signals:
       
   215     void clicked();
       
   216     void oddlyNamedNotifySignal();
       
   217 
       
   218 private:
       
   219     int m_resetProperty;
       
   220     QRect m_rect;
       
   221     QUrl m_url;
       
   222     int m_propertyWithNotify;
       
   223     MyQmlObject m_qmlObject;
       
   224 };
       
   225 
       
   226 QML_DECLARE_TYPE(PropertyObject);
       
   227 
       
   228 void tst_qdeclarativeproperty::qmlmetaproperty_object()
       
   229 {
       
   230     QObject object; // Has no default property
       
   231     PropertyObject dobject; // Has default property
       
   232 
       
   233     {
       
   234         QDeclarativeProperty prop(&object);
       
   235 
       
   236         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   237         QVERIFY(binding != 0);
       
   238         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   239         QVERIFY(expression != 0);
       
   240 
       
   241         QObject *obj = new QObject;
       
   242 
       
   243         QCOMPARE(prop.name(), QString());
       
   244         QCOMPARE(prop.read(), QVariant());
       
   245         QCOMPARE(prop.write(QVariant()), false);
       
   246         QCOMPARE(prop.hasNotifySignal(), false);
       
   247         QCOMPARE(prop.needsNotifySignal(), false);
       
   248         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   249         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   250         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   251         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   252         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   253         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   254         QVERIFY(prop.method().signature() == 0);
       
   255         QCOMPARE(prop.type(), QDeclarativeProperty::Invalid);
       
   256         QCOMPARE(prop.isProperty(), false);
       
   257         QCOMPARE(prop.isWritable(), false);
       
   258         QCOMPARE(prop.isDesignable(), false);
       
   259         QCOMPARE(prop.isResettable(), false);
       
   260         QCOMPARE(prop.isValid(), false);
       
   261         QCOMPARE(prop.object(), (QObject *)0);
       
   262         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   263         QCOMPARE(prop.propertyType(), 0);
       
   264         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   265         QVERIFY(prop.property().name() == 0);
       
   266         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   267         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   268         QVERIFY(binding == 0);
       
   269         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   270         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   271         QVERIFY(expression == 0);
       
   272         QCOMPARE(prop.index(), -1);
       
   273         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   274 
       
   275         delete obj;
       
   276     }
       
   277 
       
   278     {
       
   279         QDeclarativeProperty prop(&dobject);
       
   280 
       
   281         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   282         binding.data()->setTarget(prop);
       
   283         QVERIFY(binding != 0);
       
   284         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   285         QVERIFY(expression != 0);
       
   286 
       
   287         QObject *obj = new QObject;
       
   288 
       
   289         QCOMPARE(prop.name(), QString("defaultProperty"));
       
   290         QCOMPARE(prop.read(), QVariant(10));
       
   291         QCOMPARE(prop.write(QVariant()), false);
       
   292         QCOMPARE(prop.hasNotifySignal(), false);
       
   293         QCOMPARE(prop.needsNotifySignal(), true);
       
   294         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   295         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   296         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   297         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   298         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   299         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   300         QVERIFY(prop.method().signature() == 0);
       
   301         QCOMPARE(prop.type(), QDeclarativeProperty::Property);
       
   302         QCOMPARE(prop.isProperty(), true);
       
   303         QCOMPARE(prop.isWritable(), false);
       
   304         QCOMPARE(prop.isDesignable(), true);
       
   305         QCOMPARE(prop.isResettable(), false);
       
   306         QCOMPARE(prop.isValid(), true);
       
   307         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   308         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
   309         QCOMPARE(prop.propertyType(), (int)QVariant::Int);
       
   310         QCOMPARE(prop.propertyTypeName(), "int");
       
   311         QCOMPARE(QString(prop.property().name()), QString("defaultProperty"));
       
   312         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   313         QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int");
       
   314         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   315         QVERIFY(binding != 0);
       
   316         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding.data());
       
   317         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   318         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   319         QVERIFY(expression == 0);
       
   320         QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty"));
       
   321         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   322 
       
   323         delete obj;
       
   324     }
       
   325 }
       
   326 
       
   327 void tst_qdeclarativeproperty::qmlmetaproperty_object_string()
       
   328 {
       
   329     QObject object; 
       
   330     PropertyObject dobject; 
       
   331 
       
   332     {
       
   333         QDeclarativeProperty prop(&object, QString("defaultProperty"));
       
   334 
       
   335         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   336         QVERIFY(binding != 0);
       
   337         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   338         QVERIFY(expression != 0);
       
   339 
       
   340         QObject *obj = new QObject;
       
   341 
       
   342         QCOMPARE(prop.name(), QString());
       
   343         QCOMPARE(prop.read(), QVariant());
       
   344         QCOMPARE(prop.write(QVariant()), false);
       
   345         QCOMPARE(prop.hasNotifySignal(), false);
       
   346         QCOMPARE(prop.needsNotifySignal(), false);
       
   347         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   348         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   349         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   350         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   351         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   352         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   353         QVERIFY(prop.method().signature() == 0);
       
   354         QCOMPARE(prop.type(), QDeclarativeProperty::Invalid);
       
   355         QCOMPARE(prop.isProperty(), false);
       
   356         QCOMPARE(prop.isWritable(), false);
       
   357         QCOMPARE(prop.isDesignable(), false);
       
   358         QCOMPARE(prop.isResettable(), false);
       
   359         QCOMPARE(prop.isValid(), false);
       
   360         QCOMPARE(prop.object(), (QObject *)0);
       
   361         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   362         QCOMPARE(prop.propertyType(), 0);
       
   363         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   364         QVERIFY(prop.property().name() == 0);
       
   365         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   366         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   367         QVERIFY(binding == 0);
       
   368         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   369         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   370         QVERIFY(expression == 0);
       
   371         QCOMPARE(prop.index(), -1);
       
   372         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   373 
       
   374         delete obj;
       
   375     }
       
   376 
       
   377     {
       
   378         QDeclarativeProperty prop(&dobject, QString("defaultProperty"));
       
   379 
       
   380         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   381         binding.data()->setTarget(prop);
       
   382         QVERIFY(binding != 0);
       
   383         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   384         QVERIFY(expression != 0);
       
   385 
       
   386         QObject *obj = new QObject;
       
   387 
       
   388         QCOMPARE(prop.name(), QString("defaultProperty"));
       
   389         QCOMPARE(prop.read(), QVariant(10));
       
   390         QCOMPARE(prop.write(QVariant()), false);
       
   391         QCOMPARE(prop.hasNotifySignal(), false);
       
   392         QCOMPARE(prop.needsNotifySignal(), true);
       
   393         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   394         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   395         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   396         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   397         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   398         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   399         QVERIFY(prop.method().signature() == 0);
       
   400         QCOMPARE(prop.type(), QDeclarativeProperty::Property);
       
   401         QCOMPARE(prop.isProperty(), true);
       
   402         QCOMPARE(prop.isWritable(), false);
       
   403         QCOMPARE(prop.isDesignable(), true);
       
   404         QCOMPARE(prop.isResettable(), false);
       
   405         QCOMPARE(prop.isValid(), true);
       
   406         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   407         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
   408         QCOMPARE(prop.propertyType(), (int)QVariant::Int);
       
   409         QCOMPARE(prop.propertyTypeName(), "int");
       
   410         QCOMPARE(QString(prop.property().name()), QString("defaultProperty"));
       
   411         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   412         QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int");
       
   413         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   414         QVERIFY(binding != 0);
       
   415         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding.data());
       
   416         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   417         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   418         QVERIFY(expression == 0);
       
   419         QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty"));
       
   420         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   421 
       
   422         delete obj;
       
   423     }
       
   424 
       
   425     {
       
   426         QDeclarativeProperty prop(&dobject, QString("onClicked"));
       
   427 
       
   428         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   429         binding.data()->setTarget(prop);
       
   430         QVERIFY(binding != 0);
       
   431         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   432         QVERIFY(expression != 0);
       
   433 
       
   434         QObject *obj = new QObject;
       
   435 
       
   436         QCOMPARE(prop.name(), QString("onClicked"));
       
   437         QCOMPARE(prop.read(), QVariant());
       
   438         QCOMPARE(prop.write(QVariant("Hello")), false);
       
   439         QCOMPARE(prop.hasNotifySignal(), false);
       
   440         QCOMPARE(prop.needsNotifySignal(), false);
       
   441         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   442         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   443         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   444         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   445         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   446         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   447         QCOMPARE(QString(prop.method().signature()), QString("clicked()"));
       
   448         QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty);
       
   449         QCOMPARE(prop.isProperty(), false);
       
   450         QCOMPARE(prop.isWritable(), false);
       
   451         QCOMPARE(prop.isDesignable(), false);
       
   452         QCOMPARE(prop.isResettable(), false);
       
   453         QCOMPARE(prop.isValid(), true);
       
   454         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   455         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   456         QCOMPARE(prop.propertyType(), 0);
       
   457         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   458         QCOMPARE(prop.property().name(), (const char *)0);
       
   459         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   460         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   461         QVERIFY(binding == 0);
       
   462         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   463         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   464         QVERIFY(expression != 0);
       
   465         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression.data());
       
   466         QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("clicked()"));
       
   467         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   468 
       
   469         delete obj;
       
   470     }
       
   471 
       
   472     {
       
   473         QDeclarativeProperty prop(&dobject, QString("onPropertyWithNotifyChanged"));
       
   474 
       
   475         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   476         binding.data()->setTarget(prop);
       
   477         QVERIFY(binding != 0);
       
   478         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   479         QVERIFY(expression != 0);
       
   480 
       
   481         QObject *obj = new QObject;
       
   482 
       
   483         QCOMPARE(prop.name(), QString("onOddlyNamedNotifySignal"));
       
   484         QCOMPARE(prop.read(), QVariant());
       
   485         QCOMPARE(prop.write(QVariant("Hello")), false);
       
   486         QCOMPARE(prop.hasNotifySignal(), false);
       
   487         QCOMPARE(prop.needsNotifySignal(), false);
       
   488         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   489         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   490         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   491         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   492         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   493         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   494         QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()"));
       
   495         QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty);
       
   496         QCOMPARE(prop.isProperty(), false);
       
   497         QCOMPARE(prop.isWritable(), false);
       
   498         QCOMPARE(prop.isDesignable(), false);
       
   499         QCOMPARE(prop.isResettable(), false);
       
   500         QCOMPARE(prop.isValid(), true);
       
   501         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   502         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   503         QCOMPARE(prop.propertyType(), 0);
       
   504         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   505         QCOMPARE(prop.property().name(), (const char *)0);
       
   506         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   507         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   508         QVERIFY(binding == 0);
       
   509         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   510         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   511         QVERIFY(expression != 0);
       
   512         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression.data());
       
   513         QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()"));
       
   514         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   515 
       
   516         delete obj;
       
   517     }
       
   518 }
       
   519 
       
   520 void tst_qdeclarativeproperty::qmlmetaproperty_object_context()
       
   521 {
       
   522     QObject object; // Has no default property
       
   523     PropertyObject dobject; // Has default property
       
   524 
       
   525     {
       
   526         QDeclarativeProperty prop(&object, engine.rootContext());
       
   527 
       
   528         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   529         QVERIFY(binding != 0);
       
   530         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   531         QVERIFY(expression != 0);
       
   532 
       
   533         QObject *obj = new QObject;
       
   534 
       
   535         QCOMPARE(prop.name(), QString());
       
   536         QCOMPARE(prop.read(), QVariant());
       
   537         QCOMPARE(prop.write(QVariant()), false);
       
   538         QCOMPARE(prop.hasNotifySignal(), false);
       
   539         QCOMPARE(prop.needsNotifySignal(), false);
       
   540         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   541         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   542         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   543         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   544         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   545         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   546         QVERIFY(prop.method().signature() == 0);
       
   547         QCOMPARE(prop.type(), QDeclarativeProperty::Invalid);
       
   548         QCOMPARE(prop.isProperty(), false);
       
   549         QCOMPARE(prop.isWritable(), false);
       
   550         QCOMPARE(prop.isDesignable(), false);
       
   551         QCOMPARE(prop.isResettable(), false);
       
   552         QCOMPARE(prop.isValid(), false);
       
   553         QCOMPARE(prop.object(), (QObject *)0);
       
   554         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   555         QCOMPARE(prop.propertyType(), 0);
       
   556         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   557         QVERIFY(prop.property().name() == 0);
       
   558         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   559         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   560         QVERIFY(binding == 0);
       
   561         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   562         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   563         QVERIFY(expression == 0);
       
   564         QCOMPARE(prop.index(), -1);
       
   565         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   566 
       
   567         delete obj;
       
   568     }
       
   569 
       
   570     {
       
   571         QDeclarativeProperty prop(&dobject, engine.rootContext());
       
   572 
       
   573         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   574         binding.data()->setTarget(prop);
       
   575         QVERIFY(binding != 0);
       
   576         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   577         QVERIFY(expression != 0);
       
   578 
       
   579         QObject *obj = new QObject;
       
   580 
       
   581         QCOMPARE(prop.name(), QString("defaultProperty"));
       
   582         QCOMPARE(prop.read(), QVariant(10));
       
   583         QCOMPARE(prop.write(QVariant()), false);
       
   584         QCOMPARE(prop.hasNotifySignal(), false);
       
   585         QCOMPARE(prop.needsNotifySignal(), true);
       
   586         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   587         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   588         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   589         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   590         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   591         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   592         QVERIFY(prop.method().signature() == 0);
       
   593         QCOMPARE(prop.type(), QDeclarativeProperty::Property);
       
   594         QCOMPARE(prop.isProperty(), true);
       
   595         QCOMPARE(prop.isWritable(), false);
       
   596         QCOMPARE(prop.isDesignable(), true);
       
   597         QCOMPARE(prop.isResettable(), false);
       
   598         QCOMPARE(prop.isValid(), true);
       
   599         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   600         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
   601         QCOMPARE(prop.propertyType(), (int)QVariant::Int);
       
   602         QCOMPARE(prop.propertyTypeName(), "int");
       
   603         QCOMPARE(QString(prop.property().name()), QString("defaultProperty"));
       
   604         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   605         QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int");
       
   606         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   607         QVERIFY(binding != 0);
       
   608         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding.data());
       
   609         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   610         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   611         QVERIFY(expression == 0);
       
   612         QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty"));
       
   613         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   614 
       
   615         delete obj;
       
   616     }
       
   617 }
       
   618 
       
   619 void tst_qdeclarativeproperty::qmlmetaproperty_object_string_context()
       
   620 {
       
   621     QObject object; 
       
   622     PropertyObject dobject; 
       
   623 
       
   624     {
       
   625         QDeclarativeProperty prop(&object, QString("defaultProperty"), engine.rootContext());
       
   626 
       
   627         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   628         QVERIFY(binding != 0);
       
   629         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   630         QVERIFY(expression != 0);
       
   631 
       
   632         QObject *obj = new QObject;
       
   633 
       
   634         QCOMPARE(prop.name(), QString());
       
   635         QCOMPARE(prop.read(), QVariant());
       
   636         QCOMPARE(prop.write(QVariant()), false);
       
   637         QCOMPARE(prop.hasNotifySignal(), false);
       
   638         QCOMPARE(prop.needsNotifySignal(), false);
       
   639         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   640         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   641         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   642         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   643         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   644         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   645         QVERIFY(prop.method().signature() == 0);
       
   646         QCOMPARE(prop.type(), QDeclarativeProperty::Invalid);
       
   647         QCOMPARE(prop.isProperty(), false);
       
   648         QCOMPARE(prop.isWritable(), false);
       
   649         QCOMPARE(prop.isDesignable(), false);
       
   650         QCOMPARE(prop.isResettable(), false);
       
   651         QCOMPARE(prop.isValid(), false);
       
   652         QCOMPARE(prop.object(), (QObject *)0);
       
   653         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   654         QCOMPARE(prop.propertyType(), 0);
       
   655         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   656         QVERIFY(prop.property().name() == 0);
       
   657         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   658         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   659         QVERIFY(binding == 0);
       
   660         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   661         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   662         QVERIFY(expression == 0);
       
   663         QCOMPARE(prop.index(), -1);
       
   664         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   665 
       
   666         delete obj;
       
   667     }
       
   668 
       
   669     {
       
   670         QDeclarativeProperty prop(&dobject, QString("defaultProperty"), engine.rootContext());
       
   671 
       
   672         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   673         binding.data()->setTarget(prop);
       
   674         QVERIFY(binding != 0);
       
   675         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   676         QVERIFY(expression != 0);
       
   677 
       
   678         QObject *obj = new QObject;
       
   679 
       
   680         QCOMPARE(prop.name(), QString("defaultProperty"));
       
   681         QCOMPARE(prop.read(), QVariant(10));
       
   682         QCOMPARE(prop.write(QVariant()), false);
       
   683         QCOMPARE(prop.hasNotifySignal(), false);
       
   684         QCOMPARE(prop.needsNotifySignal(), true);
       
   685         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   686         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   687         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   688         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   689         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   690         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   691         QVERIFY(prop.method().signature() == 0);
       
   692         QCOMPARE(prop.type(), QDeclarativeProperty::Property);
       
   693         QCOMPARE(prop.isProperty(), true);
       
   694         QCOMPARE(prop.isWritable(), false);
       
   695         QCOMPARE(prop.isDesignable(), true);
       
   696         QCOMPARE(prop.isResettable(), false);
       
   697         QCOMPARE(prop.isValid(), true);
       
   698         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   699         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
   700         QCOMPARE(prop.propertyType(), (int)QVariant::Int);
       
   701         QCOMPARE(prop.propertyTypeName(), "int");
       
   702         QCOMPARE(QString(prop.property().name()), QString("defaultProperty"));
       
   703         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   704         QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Unable to assign null to int");
       
   705         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   706         QVERIFY(binding != 0);
       
   707         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == binding.data());
       
   708         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   709         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   710         QVERIFY(expression == 0);
       
   711         QCOMPARE(prop.index(), dobject.metaObject()->indexOfProperty("defaultProperty"));
       
   712         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   713 
       
   714         delete obj;
       
   715     }
       
   716 
       
   717     {
       
   718         QDeclarativeProperty prop(&dobject, QString("onClicked"), engine.rootContext());
       
   719 
       
   720         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   721         binding.data()->setTarget(prop);
       
   722         QVERIFY(binding != 0);
       
   723         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   724         QVERIFY(expression != 0);
       
   725 
       
   726         QObject *obj = new QObject;
       
   727 
       
   728         QCOMPARE(prop.name(), QString("onClicked"));
       
   729         QCOMPARE(prop.read(), QVariant());
       
   730         QCOMPARE(prop.write(QVariant("Hello")), false);
       
   731         QCOMPARE(prop.hasNotifySignal(), false);
       
   732         QCOMPARE(prop.needsNotifySignal(), false);
       
   733         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   734         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   735         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   736         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   737         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   738         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   739         QCOMPARE(QString(prop.method().signature()), QString("clicked()"));
       
   740         QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty);
       
   741         QCOMPARE(prop.isProperty(), false);
       
   742         QCOMPARE(prop.isWritable(), false);
       
   743         QCOMPARE(prop.isDesignable(), false);
       
   744         QCOMPARE(prop.isResettable(), false);
       
   745         QCOMPARE(prop.isValid(), true);
       
   746         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   747         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   748         QCOMPARE(prop.propertyType(), 0);
       
   749         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   750         QCOMPARE(prop.property().name(), (const char *)0);
       
   751         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   752         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   753         QVERIFY(binding == 0);
       
   754         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   755         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   756         QVERIFY(expression != 0);
       
   757         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression.data());
       
   758         QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("clicked()"));
       
   759         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   760 
       
   761         delete obj;
       
   762     }
       
   763 
       
   764     {
       
   765         QDeclarativeProperty prop(&dobject, QString("onPropertyWithNotifyChanged"), engine.rootContext());
       
   766 
       
   767         QWeakPointer<QDeclarativeBinding> binding(new QDeclarativeBinding(QLatin1String("null"), 0, engine.rootContext()));
       
   768         binding.data()->setTarget(prop);
       
   769         QVERIFY(binding != 0);
       
   770         QWeakPointer<QDeclarativeExpression> expression(new QDeclarativeExpression());
       
   771         QVERIFY(expression != 0);
       
   772 
       
   773         QObject *obj = new QObject;
       
   774 
       
   775         QCOMPARE(prop.name(), QString("onOddlyNamedNotifySignal"));
       
   776         QCOMPARE(prop.read(), QVariant());
       
   777         QCOMPARE(prop.write(QVariant("Hello")), false);
       
   778         QCOMPARE(prop.hasNotifySignal(), false);
       
   779         QCOMPARE(prop.needsNotifySignal(), false);
       
   780         QCOMPARE(prop.connectNotifySignal(0, SLOT(deleteLater())), false);
       
   781         QCOMPARE(prop.connectNotifySignal(obj, SLOT(deleteLater())), false);
       
   782         QCOMPARE(prop.connectNotifySignal(obj, 0), false);
       
   783         QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   784         QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
       
   785         QCOMPARE(prop.connectNotifySignal(obj, -1), false);
       
   786         QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()"));
       
   787         QCOMPARE(prop.type(), QDeclarativeProperty::SignalProperty);
       
   788         QCOMPARE(prop.isProperty(), false);
       
   789         QCOMPARE(prop.isWritable(), false);
       
   790         QCOMPARE(prop.isDesignable(), false);
       
   791         QCOMPARE(prop.isResettable(), false);
       
   792         QCOMPARE(prop.isValid(), true);
       
   793         QCOMPARE(prop.object(), qobject_cast<QObject*>(&dobject));
       
   794         QCOMPARE(prop.propertyTypeCategory(), QDeclarativeProperty::InvalidCategory);
       
   795         QCOMPARE(prop.propertyType(), 0);
       
   796         QCOMPARE(prop.propertyTypeName(), (const char *)0);
       
   797         QCOMPARE(prop.property().name(), (const char *)0);
       
   798         QVERIFY(QDeclarativePropertyPrivate::binding(prop) == 0);
       
   799         QVERIFY(QDeclarativePropertyPrivate::setBinding(prop, binding.data()) == 0);
       
   800         QVERIFY(binding == 0);
       
   801         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == 0);
       
   802         QVERIFY(QDeclarativePropertyPrivate::setSignalExpression(prop, expression.data()) == 0);
       
   803         QVERIFY(expression != 0);
       
   804         QVERIFY(QDeclarativePropertyPrivate::signalExpression(prop) == expression.data());
       
   805         QCOMPARE(prop.index(), dobject.metaObject()->indexOfMethod("oddlyNamedNotifySignal()"));
       
   806         QCOMPARE(QDeclarativePropertyPrivate::valueTypeCoreIndex(prop), -1);
       
   807 
       
   808         delete obj;
       
   809     }
       
   810 }
       
   811 
       
   812 void tst_qdeclarativeproperty::name()
       
   813 {
       
   814     { 
       
   815         QDeclarativeProperty p;
       
   816         QCOMPARE(p.name(), QString());
       
   817     }
       
   818 
       
   819     {
       
   820         PropertyObject o;
       
   821         QDeclarativeProperty p(&o);
       
   822         QCOMPARE(p.name(), QString("defaultProperty"));
       
   823     }
       
   824 
       
   825     {
       
   826         QObject o;
       
   827         QDeclarativeProperty p(&o, QString("objectName"));
       
   828         QCOMPARE(p.name(), QString("objectName"));
       
   829     }
       
   830 
       
   831     {
       
   832         PropertyObject o;
       
   833         QDeclarativeProperty p(&o, "onClicked");
       
   834         QCOMPARE(p.name(), QString("onClicked"));
       
   835     }
       
   836 
       
   837     {
       
   838         QObject o;
       
   839         QDeclarativeProperty p(&o, "onClicked");
       
   840         QCOMPARE(p.name(), QString());
       
   841     }
       
   842 
       
   843     {
       
   844         PropertyObject o;
       
   845         QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged");
       
   846         QCOMPARE(p.name(), QString("onOddlyNamedNotifySignal"));
       
   847     }
       
   848 
       
   849     {
       
   850         QObject o;
       
   851         QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged");
       
   852         QCOMPARE(p.name(), QString());
       
   853     }
       
   854 
       
   855     {
       
   856         QObject o;
       
   857         QDeclarativeProperty p(&o, "foo");
       
   858         QCOMPARE(p.name(), QString());
       
   859     }
       
   860 
       
   861     {
       
   862         QDeclarativeProperty p(0, "foo");
       
   863         QCOMPARE(p.name(), QString());
       
   864     }
       
   865 
       
   866     {
       
   867         PropertyObject o;
       
   868         QDeclarativeProperty p(&o, "rectProperty");
       
   869         QCOMPARE(p.name(), QString("rectProperty"));
       
   870     }
       
   871 
       
   872     {
       
   873         PropertyObject o;
       
   874         QDeclarativeProperty p(&o, "rectProperty.x");
       
   875         QCOMPARE(p.name(), QString("rectProperty.x"));
       
   876     }
       
   877 
       
   878     {
       
   879         PropertyObject o;
       
   880         QDeclarativeProperty p(&o, "rectProperty.foo");
       
   881         QCOMPARE(p.name(), QString());
       
   882     }
       
   883 }
       
   884 
       
   885 void tst_qdeclarativeproperty::read()
       
   886 {
       
   887     // Invalid 
       
   888     {
       
   889         QDeclarativeProperty p;
       
   890         QCOMPARE(p.read(), QVariant());
       
   891     }
       
   892 
       
   893     // Default prop
       
   894     {
       
   895         PropertyObject o;
       
   896         QDeclarativeProperty p(&o);
       
   897         QCOMPARE(p.read(), QVariant(10));
       
   898     }
       
   899 
       
   900     // Invalid default prop
       
   901     {
       
   902         QObject o;
       
   903         QDeclarativeProperty p(&o);
       
   904         QCOMPARE(p.read(), QVariant());
       
   905     }
       
   906 
       
   907     // Value prop by name
       
   908     {
       
   909         QObject o;
       
   910 
       
   911         QDeclarativeProperty p(&o, "objectName");
       
   912         QCOMPARE(p.read(), QVariant(QString()));
       
   913 
       
   914         o.setObjectName("myName");
       
   915 
       
   916         QCOMPARE(p.read(), QVariant("myName"));
       
   917     }
       
   918 
       
   919     // Value-type prop
       
   920     {
       
   921         PropertyObject o;
       
   922         QDeclarativeProperty p(&o, "rectProperty.x");
       
   923         QCOMPARE(p.read(), QVariant(10));
       
   924     }
       
   925 
       
   926     // Invalid value-type prop
       
   927     {
       
   928         PropertyObject o;
       
   929         QDeclarativeProperty p(&o, "rectProperty.foo");
       
   930         QCOMPARE(p.read(), QVariant());
       
   931     }
       
   932 
       
   933     // Signal property
       
   934     {
       
   935         PropertyObject o;
       
   936         QDeclarativeProperty p(&o, "onClicked");
       
   937         QCOMPARE(p.read(), QVariant());
       
   938 
       
   939         QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression()));
       
   940         QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p));
       
   941 
       
   942         QCOMPARE(p.read(), QVariant());
       
   943     }
       
   944 
       
   945     // Automatic signal property 
       
   946     {
       
   947         PropertyObject o;
       
   948         QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged");
       
   949         QCOMPARE(p.read(), QVariant());
       
   950 
       
   951         QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression()));
       
   952         QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p));
       
   953 
       
   954         QCOMPARE(p.read(), QVariant());
       
   955     }
       
   956 
       
   957     // Deleted object
       
   958     {
       
   959         PropertyObject *o = new PropertyObject;
       
   960         QDeclarativeProperty p(o, "rectProperty.x");
       
   961         QCOMPARE(p.read(), QVariant(10));
       
   962         delete o;
       
   963         QCOMPARE(p.read(), QVariant());
       
   964     }
       
   965 
       
   966     // Object property
       
   967     {
       
   968         PropertyObject o;
       
   969         QDeclarativeProperty p(&o, "qmlObject");
       
   970         QCOMPARE(p.propertyTypeCategory(), QDeclarativeProperty::Object);
       
   971         QCOMPARE(p.propertyType(), qMetaTypeId<MyQmlObject*>());
       
   972         QVariant v = p.read();
       
   973         QVERIFY(v.userType() == QMetaType::QObjectStar);
       
   974         QVERIFY(qvariant_cast<QObject *>(v) == o.qmlObject());
       
   975     }
       
   976     {
       
   977         QDeclarativeComponent component(&engine, TEST_FILE("readSynthesizedObject.qml"));
       
   978         QObject *object = component.create();
       
   979         QVERIFY(object != 0);
       
   980 
       
   981         QDeclarativeProperty p(object, "test", &engine);
       
   982 
       
   983         QCOMPARE(p.propertyTypeCategory(), QDeclarativeProperty::Object);
       
   984         QVERIFY(p.propertyType() != QMetaType::QObjectStar);
       
   985 
       
   986         QVariant v = p.read();
       
   987         QVERIFY(v.userType() == QMetaType::QObjectStar);
       
   988         QCOMPARE(qvariant_cast<QObject *>(v)->property("a").toInt(), 10);
       
   989         QCOMPARE(qvariant_cast<QObject *>(v)->property("b").toInt(), 19);
       
   990     }
       
   991 
       
   992     // Attached property
       
   993     {
       
   994         QDeclarativeComponent component(&engine);
       
   995         component.setData("import Test 1.0\nMyContainer { }", QUrl());
       
   996         QObject *object = component.create();
       
   997         QVERIFY(object != 0);
       
   998 
       
   999         QDeclarativeProperty p(object, "MyContainer.foo", qmlContext(object));
       
  1000         QCOMPARE(p.read(), QVariant(13));
       
  1001         delete object;
       
  1002     }
       
  1003     {
       
  1004         QDeclarativeComponent component(&engine);
       
  1005         component.setData("import Test 1.0\nMyContainer { MyContainer.foo: 10 }", QUrl());
       
  1006         QObject *object = component.create();
       
  1007         QVERIFY(object != 0);
       
  1008 
       
  1009         QDeclarativeProperty p(object, "MyContainer.foo", qmlContext(object));
       
  1010         QCOMPARE(p.read(), QVariant(10));
       
  1011         delete object;
       
  1012     }
       
  1013     {
       
  1014         QDeclarativeComponent component(&engine);
       
  1015         component.setData("import Test 1.0 as Foo\nFoo.MyContainer { Foo.MyContainer.foo: 10 }", QUrl());
       
  1016         QObject *object = component.create();
       
  1017         QVERIFY(object != 0);
       
  1018 
       
  1019         QDeclarativeProperty p(object, "Foo.MyContainer.foo", qmlContext(object));
       
  1020         QCOMPARE(p.read(), QVariant(10));
       
  1021         delete object;
       
  1022     }
       
  1023 }
       
  1024 
       
  1025 void tst_qdeclarativeproperty::write()
       
  1026 {
       
  1027     // Invalid
       
  1028     {
       
  1029         QDeclarativeProperty p;
       
  1030         QCOMPARE(p.write(QVariant(10)), false);
       
  1031     }
       
  1032 
       
  1033     // Read-only default prop
       
  1034     {
       
  1035         PropertyObject o;
       
  1036         QDeclarativeProperty p(&o);
       
  1037         QCOMPARE(p.write(QVariant(10)), false);
       
  1038     }
       
  1039 
       
  1040     // Invalid default prop
       
  1041     {
       
  1042         QObject o;
       
  1043         QDeclarativeProperty p(&o);
       
  1044         QCOMPARE(p.write(QVariant(10)), false);
       
  1045     }
       
  1046 
       
  1047     // Read-only prop by name
       
  1048     {
       
  1049         PropertyObject o;
       
  1050         QDeclarativeProperty p(&o, QString("defaultProperty"));
       
  1051         QCOMPARE(p.write(QVariant(10)), false);
       
  1052     }
       
  1053 
       
  1054     // Writable prop by name
       
  1055     {
       
  1056         PropertyObject o;
       
  1057         QDeclarativeProperty p(&o, QString("objectName"));
       
  1058         QCOMPARE(o.objectName(), QString());
       
  1059         QCOMPARE(p.write(QVariant(QString("myName"))), true);
       
  1060         QCOMPARE(o.objectName(), QString("myName"));
       
  1061     }
       
  1062 
       
  1063     // Deleted object
       
  1064     {
       
  1065         PropertyObject *o = new PropertyObject;
       
  1066         QDeclarativeProperty p(o, QString("objectName"));
       
  1067         QCOMPARE(p.write(QVariant(QString("myName"))), true);
       
  1068         QCOMPARE(o->objectName(), QString("myName"));
       
  1069 
       
  1070         delete o;
       
  1071 
       
  1072         QCOMPARE(p.write(QVariant(QString("myName"))), false);
       
  1073     }
       
  1074 
       
  1075     // Signal property
       
  1076     {
       
  1077         PropertyObject o;
       
  1078         QDeclarativeProperty p(&o, "onClicked");
       
  1079         QCOMPARE(p.write(QVariant("console.log(1921)")), false);
       
  1080 
       
  1081         QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression()));
       
  1082         QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p));
       
  1083 
       
  1084         QCOMPARE(p.write(QVariant("console.log(1921)")), false);
       
  1085 
       
  1086         QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p));
       
  1087     }
       
  1088 
       
  1089     // Automatic signal property
       
  1090     {
       
  1091         PropertyObject o;
       
  1092         QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged");
       
  1093         QCOMPARE(p.write(QVariant("console.log(1921)")), false);
       
  1094 
       
  1095         QVERIFY(0 == QDeclarativePropertyPrivate::setSignalExpression(p, new QDeclarativeExpression()));
       
  1096         QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p));
       
  1097 
       
  1098         QCOMPARE(p.write(QVariant("console.log(1921)")), false);
       
  1099 
       
  1100         QVERIFY(0 != QDeclarativePropertyPrivate::signalExpression(p));
       
  1101     }
       
  1102 
       
  1103     // Value-type property
       
  1104     {
       
  1105         PropertyObject o;
       
  1106         QDeclarativeProperty p(&o, "wrectProperty");
       
  1107 
       
  1108         QCOMPARE(o.wrectProperty(), QRect());
       
  1109         QCOMPARE(p.write(QRect(1, 13, 99, 8)), true);
       
  1110         QCOMPARE(o.wrectProperty(), QRect(1, 13, 99, 8));
       
  1111 
       
  1112         QDeclarativeProperty p2(&o, "wrectProperty.x");
       
  1113         QCOMPARE(p2.read(), QVariant(1));
       
  1114         QCOMPARE(p2.write(QVariant(6)), true);
       
  1115         QCOMPARE(p2.read(), QVariant(6));
       
  1116         QCOMPARE(o.wrectProperty(), QRect(6, 13, 99, 8));
       
  1117     }
       
  1118 
       
  1119     // URL-property
       
  1120     {
       
  1121         PropertyObject o;
       
  1122         QDeclarativeProperty p(&o, "url");
       
  1123 
       
  1124         QCOMPARE(p.write(QUrl("main.qml")), true);
       
  1125         QCOMPARE(o.url(), QUrl("main.qml"));
       
  1126 
       
  1127         QDeclarativeProperty p2(&o, "url", engine.rootContext());
       
  1128 
       
  1129         QUrl result = engine.baseUrl().resolved(QUrl("main.qml"));
       
  1130         QVERIFY(result != QUrl("main.qml"));
       
  1131 
       
  1132         QCOMPARE(p2.write(QUrl("main.qml")), true);
       
  1133         QCOMPARE(o.url(), result);
       
  1134     }
       
  1135 
       
  1136     // Attached property
       
  1137     {
       
  1138         QDeclarativeComponent component(&engine);
       
  1139         component.setData("import Test 1.0\nMyContainer { }", QUrl());
       
  1140         QObject *object = component.create();
       
  1141         QVERIFY(object != 0);
       
  1142 
       
  1143         QDeclarativeProperty p(object, "MyContainer.foo", qmlContext(object));
       
  1144         p.write(QVariant(99));
       
  1145         QCOMPARE(p.read(), QVariant(99));
       
  1146         delete object;
       
  1147     }
       
  1148     {
       
  1149         QDeclarativeComponent component(&engine);
       
  1150         component.setData("import Test 1.0 as Foo\nFoo.MyContainer { Foo.MyContainer.foo: 10 }", QUrl());
       
  1151         QObject *object = component.create();
       
  1152         QVERIFY(object != 0);
       
  1153 
       
  1154         QDeclarativeProperty p(object, "Foo.MyContainer.foo", qmlContext(object));
       
  1155         p.write(QVariant(99));
       
  1156         QCOMPARE(p.read(), QVariant(99));
       
  1157         delete object;
       
  1158     }
       
  1159 }
       
  1160 
       
  1161 void tst_qdeclarativeproperty::reset()
       
  1162 {
       
  1163     // Invalid
       
  1164     {
       
  1165         QDeclarativeProperty p;
       
  1166         QCOMPARE(p.isResettable(), false);
       
  1167         QCOMPARE(p.reset(), false);
       
  1168     }
       
  1169 
       
  1170     // Read-only default prop
       
  1171     {
       
  1172         PropertyObject o;
       
  1173         QDeclarativeProperty p(&o);
       
  1174         QCOMPARE(p.isResettable(), false);
       
  1175         QCOMPARE(p.reset(), false);
       
  1176     }
       
  1177 
       
  1178     // Invalid default prop
       
  1179     {
       
  1180         QObject o;
       
  1181         QDeclarativeProperty p(&o);
       
  1182         QCOMPARE(p.isResettable(), false);
       
  1183         QCOMPARE(p.reset(), false);
       
  1184     }
       
  1185 
       
  1186     // Non-resettable-only prop by name
       
  1187     {
       
  1188         PropertyObject o;
       
  1189         QDeclarativeProperty p(&o, QString("defaultProperty"));
       
  1190         QCOMPARE(p.isResettable(), false);
       
  1191         QCOMPARE(p.reset(), false);
       
  1192     }
       
  1193 
       
  1194     // Resettable prop by name
       
  1195     {
       
  1196         PropertyObject o;
       
  1197         QDeclarativeProperty p(&o, QString("resettableProperty"));
       
  1198 
       
  1199         QCOMPARE(p.read(), QVariant(9));
       
  1200         QCOMPARE(p.write(QVariant(11)), true);
       
  1201         QCOMPARE(p.read(), QVariant(11));
       
  1202 
       
  1203         QCOMPARE(p.isResettable(), true);
       
  1204         QCOMPARE(p.reset(), true);
       
  1205 
       
  1206         QCOMPARE(p.read(), QVariant(9));
       
  1207     }
       
  1208 
       
  1209     // Deleted object
       
  1210     {
       
  1211         PropertyObject *o = new PropertyObject;
       
  1212 
       
  1213         QDeclarativeProperty p(o, QString("resettableProperty"));
       
  1214 
       
  1215         QCOMPARE(p.isResettable(), true);
       
  1216         QCOMPARE(p.reset(), true);
       
  1217 
       
  1218         delete o;
       
  1219 
       
  1220         QCOMPARE(p.isResettable(), false);
       
  1221         QCOMPARE(p.reset(), false);
       
  1222     }
       
  1223 
       
  1224     // Signal property
       
  1225     {
       
  1226         PropertyObject o;
       
  1227         QDeclarativeProperty p(&o, "onClicked");
       
  1228 
       
  1229         QCOMPARE(p.isResettable(), false);
       
  1230         QCOMPARE(p.reset(), false);
       
  1231     }
       
  1232 
       
  1233     // Automatic signal property
       
  1234     {
       
  1235         PropertyObject o;
       
  1236         QDeclarativeProperty p(&o, "onPropertyWithNotifyChanged");
       
  1237 
       
  1238         QCOMPARE(p.isResettable(), false);
       
  1239         QCOMPARE(p.reset(), false);
       
  1240     }
       
  1241 }
       
  1242 
       
  1243 void tst_qdeclarativeproperty::writeObjectToList()
       
  1244 {
       
  1245     QDeclarativeComponent containerComponent(&engine);
       
  1246     containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl());
       
  1247     MyContainer *container = qobject_cast<MyContainer*>(containerComponent.create());
       
  1248     QVERIFY(container != 0);
       
  1249     QDeclarativeListReference list(container, "children");
       
  1250     QVERIFY(list.count() == 1);
       
  1251 
       
  1252     MyQmlObject *object = new MyQmlObject;
       
  1253     QDeclarativeProperty prop(container, "children");
       
  1254     prop.write(qVariantFromValue(object));
       
  1255     QCOMPARE(list.count(), 1);
       
  1256     QCOMPARE(list.at(0), qobject_cast<QObject*>(object));
       
  1257 }
       
  1258 
       
  1259 Q_DECLARE_METATYPE(QList<QObject *>);
       
  1260 void tst_qdeclarativeproperty::writeListToList()
       
  1261 {
       
  1262     QDeclarativeComponent containerComponent(&engine);
       
  1263     containerComponent.setData("import Test 1.0\nMyContainer { children: MyQmlObject {} }", QUrl());
       
  1264     MyContainer *container = qobject_cast<MyContainer*>(containerComponent.create());
       
  1265     QVERIFY(container != 0);
       
  1266     QDeclarativeListReference list(container, "children");
       
  1267     QVERIFY(list.count() == 1);
       
  1268 
       
  1269     QList<QObject*> objList;
       
  1270     objList << new MyQmlObject() << new MyQmlObject() << new MyQmlObject() << new MyQmlObject();
       
  1271     QDeclarativeProperty prop(container, "children");
       
  1272     prop.write(qVariantFromValue(objList));
       
  1273     QCOMPARE(list.count(), 4);
       
  1274 
       
  1275     //XXX need to try this with read/write prop (for read-only it correctly doesn't write)
       
  1276     /*QList<MyQmlObject*> typedObjList;
       
  1277     typedObjList << new MyQmlObject();
       
  1278     prop.write(qVariantFromValue(&typedObjList));
       
  1279     QCOMPARE(container->children()->size(), 1);*/
       
  1280 }
       
  1281 
       
  1282 void tst_qdeclarativeproperty::crashOnValueProperty()
       
  1283 {
       
  1284     QDeclarativeEngine *engine = new QDeclarativeEngine;
       
  1285     QDeclarativeComponent component(engine);
       
  1286 
       
  1287     component.setData("import Test 1.0\nPropertyObject { wrectProperty.x: 10 }", QUrl());
       
  1288     PropertyObject *obj = qobject_cast<PropertyObject*>(component.create());
       
  1289     QVERIFY(obj != 0);
       
  1290 
       
  1291     QDeclarativeProperty p(obj, "wrectProperty.x", qmlContext(obj));
       
  1292     QCOMPARE(p.name(), QString("wrectProperty.x"));
       
  1293 
       
  1294     QCOMPARE(p.read(), QVariant(10));
       
  1295 
       
  1296     //don't crash once the engine is deleted
       
  1297     delete engine;
       
  1298     engine = 0;
       
  1299 
       
  1300     QCOMPARE(p.propertyTypeName(), "int");
       
  1301     QCOMPARE(p.read(), QVariant(10));
       
  1302     p.write(QVariant(20));
       
  1303     QCOMPARE(p.read(), QVariant(20));
       
  1304 }
       
  1305 
       
  1306 void tst_qdeclarativeproperty::copy()
       
  1307 {
       
  1308     PropertyObject object;
       
  1309 
       
  1310     QDeclarativeProperty *property = new QDeclarativeProperty(&object, QLatin1String("defaultProperty"));
       
  1311     QCOMPARE(property->name(), QString("defaultProperty"));
       
  1312     QCOMPARE(property->read(), QVariant(10));
       
  1313     QCOMPARE(property->type(), QDeclarativeProperty::Property);
       
  1314     QCOMPARE(property->propertyTypeCategory(), QDeclarativeProperty::Normal);
       
  1315     QCOMPARE(property->propertyType(), (int)QVariant::Int);
       
  1316 
       
  1317     QDeclarativeProperty p1(*property);
       
  1318     QCOMPARE(p1.name(), QString("defaultProperty"));
       
  1319     QCOMPARE(p1.read(), QVariant(10));
       
  1320     QCOMPARE(p1.type(), QDeclarativeProperty::Property);
       
  1321     QCOMPARE(p1.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
  1322     QCOMPARE(p1.propertyType(), (int)QVariant::Int);
       
  1323 
       
  1324     QDeclarativeProperty p2(&object, QLatin1String("url"));
       
  1325     QCOMPARE(p2.name(), QString("url"));
       
  1326     p2 = *property;
       
  1327     QCOMPARE(p2.name(), QString("defaultProperty"));
       
  1328     QCOMPARE(p2.read(), QVariant(10));
       
  1329     QCOMPARE(p2.type(), QDeclarativeProperty::Property);
       
  1330     QCOMPARE(p2.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
  1331     QCOMPARE(p2.propertyType(), (int)QVariant::Int);
       
  1332 
       
  1333     delete property; property = 0;
       
  1334 
       
  1335     QCOMPARE(p1.name(), QString("defaultProperty"));
       
  1336     QCOMPARE(p1.read(), QVariant(10));
       
  1337     QCOMPARE(p1.type(), QDeclarativeProperty::Property);
       
  1338     QCOMPARE(p1.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
  1339     QCOMPARE(p1.propertyType(), (int)QVariant::Int);
       
  1340 
       
  1341     QCOMPARE(p2.name(), QString("defaultProperty"));
       
  1342     QCOMPARE(p2.read(), QVariant(10));
       
  1343     QCOMPARE(p2.type(), QDeclarativeProperty::Property);
       
  1344     QCOMPARE(p2.propertyTypeCategory(), QDeclarativeProperty::Normal);
       
  1345     QCOMPARE(p2.propertyType(), (int)QVariant::Int);
       
  1346 }
       
  1347 
       
  1348 void tst_qdeclarativeproperty::initTestCase()
       
  1349 {
       
  1350     qmlRegisterType<MyQmlObject>("Test",1,0,"MyQmlObject");
       
  1351     qmlRegisterType<PropertyObject>("Test",1,0,"PropertyObject");
       
  1352     qmlRegisterType<MyContainer>("Test",1,0,"MyContainer");
       
  1353 }
       
  1354 
       
  1355 
       
  1356 QTEST_MAIN(tst_qdeclarativeproperty)
       
  1357 
       
  1358 #include "tst_qdeclarativeproperty.moc"