From 893404a0ad649ba12d3ada2e94cc17cf77b96127 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 May 2009 17:33:32 +1000 Subject: More tests --- src/declarative/qml/qml.h | 2 +- src/declarative/qml/qmlcompiler.cpp | 16 +- src/declarative/qml/qmlcomponent.cpp | 21 +-- src/declarative/qml/qmlparser.cpp | 1 - src/declarative/qml/qmlparser_p.h | 1 - .../declarative/qmlparser/assignBasicTypes.txt | 2 + tests/auto/declarative/qmlparser/assignSignal.txt | 3 + .../declarative/qmlparser/attachedProperties.txt | 3 + .../qmlparser/autoComponentCreation.txt | 3 + .../declarative/qmlparser/dynamicProperties.txt | 11 ++ .../qmlparser/dynamicSignalsAndSlots.txt | 6 + tests/auto/declarative/qmlparser/idProperty.txt | 7 + .../declarative/qmlparser/invalidID.3.errors.txt | 1 + tests/auto/declarative/qmlparser/invalidID.3.txt | 4 + .../declarative/qmlparser/invalidID.4.errors.txt | 1 + tests/auto/declarative/qmlparser/invalidID.4.txt | 5 + .../qmlparser/listAssignment.1.errors.txt | 1 + .../declarative/qmlparser/listAssignment.1.txt | 3 + .../qmlparser/listAssignment.2.errors.txt | 2 + .../declarative/qmlparser/listAssignment.2.txt | 3 + .../qmlparser/listAssignment.3.errors.txt | 1 + .../declarative/qmlparser/listAssignment.3.txt | 5 + .../declarative/qmlparser/propertyValueSource.txt | 3 + .../auto/declarative/qmlparser/simpleBindings.txt | 17 ++ tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 182 ++++++++++++++++++++- 25 files changed, 272 insertions(+), 32 deletions(-) create mode 100644 tests/auto/declarative/qmlparser/assignSignal.txt create mode 100644 tests/auto/declarative/qmlparser/attachedProperties.txt create mode 100644 tests/auto/declarative/qmlparser/autoComponentCreation.txt create mode 100644 tests/auto/declarative/qmlparser/dynamicProperties.txt create mode 100644 tests/auto/declarative/qmlparser/dynamicSignalsAndSlots.txt create mode 100644 tests/auto/declarative/qmlparser/idProperty.txt create mode 100644 tests/auto/declarative/qmlparser/invalidID.3.errors.txt create mode 100644 tests/auto/declarative/qmlparser/invalidID.3.txt create mode 100644 tests/auto/declarative/qmlparser/invalidID.4.errors.txt create mode 100644 tests/auto/declarative/qmlparser/invalidID.4.txt create mode 100644 tests/auto/declarative/qmlparser/listAssignment.1.errors.txt create mode 100644 tests/auto/declarative/qmlparser/listAssignment.1.txt create mode 100644 tests/auto/declarative/qmlparser/listAssignment.2.errors.txt create mode 100644 tests/auto/declarative/qmlparser/listAssignment.2.txt create mode 100644 tests/auto/declarative/qmlparser/listAssignment.3.errors.txt create mode 100644 tests/auto/declarative/qmlparser/listAssignment.3.txt create mode 100644 tests/auto/declarative/qmlparser/propertyValueSource.txt create mode 100644 tests/auto/declarative/qmlparser/simpleBindings.txt diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h index 1c662a7..b435e94 100644 --- a/src/declarative/qml/qml.h +++ b/src/declarative/qml/qml.h @@ -106,7 +106,7 @@ QObject *qmlAttachedPropertiesObject(const QObject *obj) if (idx == -1 || !obj) return 0; - return qmlAttachedPropertiesObjectById(obj, idx); + return qmlAttachedPropertiesObjectById(idx, obj); } QML_DECLARE_TYPE(QObject); diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index a703ec3..ed520c1 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -863,9 +863,9 @@ bool QmlCompiler::compileIdProperty(QmlParser::Property *prop, QmlParser::Object *obj) { if (prop->value) - COMPILE_EXCEPTION("The 'id' property cannot be fetched"); + COMPILE_EXCEPTION2(prop,"The id property cannot be fetched"); if (prop->values.count() > 1) - COMPILE_EXCEPTION("The 'id' property cannot be multiset"); + COMPILE_EXCEPTION2(prop, "The object id may only be set once"); if (prop->values.count() == 1) { if (prop->values.at(0)->object) @@ -1018,6 +1018,7 @@ bool QmlCompiler::compileListProperty(QmlParser::Property *prop, if (assignedBinding) COMPILE_EXCEPTION("Can only assign one binding to lists"); + assignedBinding = true; compileBinding(v->value.asScript(), prop, ctxt, obj->metaObject(), v->location.start.line); v->type = Value::PropertyBinding; @@ -1305,17 +1306,6 @@ bool QmlCompiler::compileDynamicMeta(QmlParser::Object *obj) p.defaultValue->isDefault = false; COMPILE_CHECK(compileProperty(p.defaultValue, obj, 0)); } - - if (!p.onValueChanged.isEmpty()) { - QmlInstruction assign; - assign.type = QmlInstruction::AssignSignal; - assign.line = obj->location.start.line; - assign.assignSignal.signal = - output->indexForByteArray(p.name + "Changed()"); - assign.assignSignal.value = - output->indexForString(p.onValueChanged); - output->bytecode << assign; - } } return true; diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index da8f26d..24b5dd2 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -482,18 +482,19 @@ QObject *QmlComponent::beginCreate(QmlContext *context) ctxt->deactivate(); + QmlEnginePrivate *ep = d->engine->d_func(); + if (ep->rootComponent == this) { + ep->rootComponent = 0; + + d->bindValues = ep->bindValues; + d->parserStatus = ep->parserStatus; + ep->bindValues.clear(); + ep->parserStatus.clear(); + d->completePending = true; + } + if (rv) { QFx_setParent_noEvent(ctxt, rv); - QmlEnginePrivate *ep = d->engine->d_func(); - if (ep->rootComponent == this) { - ep->rootComponent = 0; - - d->bindValues = ep->bindValues; - d->parserStatus = ep->parserStatus; - ep->bindValues.clear(); - ep->parserStatus.clear(); - d->completePending = true; - } } else { delete ctxt; } diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp index bafdb02..10eec61 100644 --- a/src/declarative/qml/qmlparser.cpp +++ b/src/declarative/qml/qmlparser.cpp @@ -109,7 +109,6 @@ QmlParser::Object::DynamicProperty::DynamicProperty(const DynamicProperty &o) : isDefaultProperty(o.isDefaultProperty), type(o.type), name(o.name), - onValueChanged(o.onValueChanged), defaultValue(o.defaultValue) { } diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h index f25a76b..a6894fb 100644 --- a/src/declarative/qml/qmlparser_p.h +++ b/src/declarative/qml/qmlparser_p.h @@ -133,7 +133,6 @@ namespace QmlParser bool isDefaultProperty; Type type; QByteArray name; - QString onValueChanged; QmlParser::Property *defaultValue; }; struct DynamicSignal { diff --git a/tests/auto/declarative/qmlparser/assignBasicTypes.txt b/tests/auto/declarative/qmlparser/assignBasicTypes.txt index 49de929..71e400d 100644 --- a/tests/auto/declarative/qmlparser/assignBasicTypes.txt +++ b/tests/auto/declarative/qmlparser/assignBasicTypes.txt @@ -20,4 +20,6 @@ MyTypeObject { rectFProperty: "1000.1,-10.9,400x90.99" boolProperty: true variantProperty: "Hello World!" + + objectProperty: MyTypeObject { intProperty: 8 } } diff --git a/tests/auto/declarative/qmlparser/assignSignal.txt b/tests/auto/declarative/qmlparser/assignSignal.txt new file mode 100644 index 0000000..6c0fd54 --- /dev/null +++ b/tests/auto/declarative/qmlparser/assignSignal.txt @@ -0,0 +1,3 @@ +MyQmlObject { + onBasicSignal: basicSlot() +} diff --git a/tests/auto/declarative/qmlparser/attachedProperties.txt b/tests/auto/declarative/qmlparser/attachedProperties.txt new file mode 100644 index 0000000..bfe5733 --- /dev/null +++ b/tests/auto/declarative/qmlparser/attachedProperties.txt @@ -0,0 +1,3 @@ +Object { + MyQmlObject.value: 10 +} diff --git a/tests/auto/declarative/qmlparser/autoComponentCreation.txt b/tests/auto/declarative/qmlparser/autoComponentCreation.txt new file mode 100644 index 0000000..e0dbbae --- /dev/null +++ b/tests/auto/declarative/qmlparser/autoComponentCreation.txt @@ -0,0 +1,3 @@ +MyTypeObject { + componentProperty : MyTypeObject { realProperty: 9 } +} diff --git a/tests/auto/declarative/qmlparser/dynamicProperties.txt b/tests/auto/declarative/qmlparser/dynamicProperties.txt new file mode 100644 index 0000000..14c85a7 --- /dev/null +++ b/tests/auto/declarative/qmlparser/dynamicProperties.txt @@ -0,0 +1,11 @@ +Object { + default property int intProperty : 10 + property bool boolProperty: false + property double doubleProperty: -10.1 + property real realProperty: -19.9 + property string stringProperty: "Hello World!" + property color colorProperty: "red" + property date dateProperty: "1945-09-02" + property var varProperty: "Hello World!" + property variant variantProperty: 12 +} diff --git a/tests/auto/declarative/qmlparser/dynamicSignalsAndSlots.txt b/tests/auto/declarative/qmlparser/dynamicSignalsAndSlots.txt new file mode 100644 index 0000000..7cf65ee --- /dev/null +++ b/tests/auto/declarative/qmlparser/dynamicSignalsAndSlots.txt @@ -0,0 +1,6 @@ +Object { + signal signal1 + function slot1() {} + signal signal2 + function slot2() {} +} diff --git a/tests/auto/declarative/qmlparser/idProperty.txt b/tests/auto/declarative/qmlparser/idProperty.txt new file mode 100644 index 0000000..9c7d6fb --- /dev/null +++ b/tests/auto/declarative/qmlparser/idProperty.txt @@ -0,0 +1,7 @@ +MyContainer { + property var object : MyObjectId + + MyTypeObject { + id: MyObjectId + } +} diff --git a/tests/auto/declarative/qmlparser/invalidID.3.errors.txt b/tests/auto/declarative/qmlparser/invalidID.3.errors.txt new file mode 100644 index 0000000..05937f0 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.3.errors.txt @@ -0,0 +1 @@ +2:5:The id property cannot be fetched diff --git a/tests/auto/declarative/qmlparser/invalidID.3.txt b/tests/auto/declarative/qmlparser/invalidID.3.txt new file mode 100644 index 0000000..c686914 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.3.txt @@ -0,0 +1,4 @@ +MyQmlObject { + id.other: 10 +} + diff --git a/tests/auto/declarative/qmlparser/invalidID.4.errors.txt b/tests/auto/declarative/qmlparser/invalidID.4.errors.txt new file mode 100644 index 0000000..50c8960 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.4.errors.txt @@ -0,0 +1 @@ +3:5:The object id may only be set once diff --git a/tests/auto/declarative/qmlparser/invalidID.4.txt b/tests/auto/declarative/qmlparser/invalidID.4.txt new file mode 100644 index 0000000..734ccc4 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.4.txt @@ -0,0 +1,5 @@ +MyQmlObject { + id: Hello + id: World +} + diff --git a/tests/auto/declarative/qmlparser/listAssignment.1.errors.txt b/tests/auto/declarative/qmlparser/listAssignment.1.errors.txt new file mode 100644 index 0000000..44a275b --- /dev/null +++ b/tests/auto/declarative/qmlparser/listAssignment.1.errors.txt @@ -0,0 +1 @@ +1:1:Cannot assign primitives to lists diff --git a/tests/auto/declarative/qmlparser/listAssignment.1.txt b/tests/auto/declarative/qmlparser/listAssignment.1.txt new file mode 100644 index 0000000..e2376f2 --- /dev/null +++ b/tests/auto/declarative/qmlparser/listAssignment.1.txt @@ -0,0 +1,3 @@ +MyContainer { + qmllistInterfaces: 1 +} diff --git a/tests/auto/declarative/qmlparser/listAssignment.2.errors.txt b/tests/auto/declarative/qmlparser/listAssignment.2.errors.txt new file mode 100644 index 0000000..572d662 --- /dev/null +++ b/tests/auto/declarative/qmlparser/listAssignment.2.errors.txt @@ -0,0 +1,2 @@ +1:1:Cannot assign primitives to lists + diff --git a/tests/auto/declarative/qmlparser/listAssignment.2.txt b/tests/auto/declarative/qmlparser/listAssignment.2.txt new file mode 100644 index 0000000..375e4b4 --- /dev/null +++ b/tests/auto/declarative/qmlparser/listAssignment.2.txt @@ -0,0 +1,3 @@ +MyContainer { + children: 2 +} diff --git a/tests/auto/declarative/qmlparser/listAssignment.3.errors.txt b/tests/auto/declarative/qmlparser/listAssignment.3.errors.txt new file mode 100644 index 0000000..ab6fec8 --- /dev/null +++ b/tests/auto/declarative/qmlparser/listAssignment.3.errors.txt @@ -0,0 +1 @@ +1:1:Can only assign one binding to lists diff --git a/tests/auto/declarative/qmlparser/listAssignment.3.txt b/tests/auto/declarative/qmlparser/listAssignment.3.txt new file mode 100644 index 0000000..b776bee --- /dev/null +++ b/tests/auto/declarative/qmlparser/listAssignment.3.txt @@ -0,0 +1,5 @@ +MyContainer { + children: childBinding.expression + children: childBinding2.expression +} + diff --git a/tests/auto/declarative/qmlparser/propertyValueSource.txt b/tests/auto/declarative/qmlparser/propertyValueSource.txt new file mode 100644 index 0000000..780f527 --- /dev/null +++ b/tests/auto/declarative/qmlparser/propertyValueSource.txt @@ -0,0 +1,3 @@ +MyTypeObject { + intProperty : MyPropertyValueSource {} +} diff --git a/tests/auto/declarative/qmlparser/simpleBindings.txt b/tests/auto/declarative/qmlparser/simpleBindings.txt new file mode 100644 index 0000000..78f2503 --- /dev/null +++ b/tests/auto/declarative/qmlparser/simpleBindings.txt @@ -0,0 +1,17 @@ +MyTypeObject { + id: Me + property int v1: 10 + property int v2: 11 + + property int value1 + property int value2 + property int value3 + property int value4 + + value1: v1 + value2: Me.v1 + value3: v1 + v2 + value4: Math.min(v1, v2) + + objectProperty: Me +} diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index a3b94db..81d044b 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ Q_DECLARE_INTERFACE(MyInterface, "com.trolltech.Qt.Test.MyInterface"); QML_DECLARE_INTERFACE(MyInterface); QML_DEFINE_INTERFACE(MyInterface); -class MyQmlObject : public QObject, public MyInterface +class MyQmlObject : public QObject, public MyInterface, public QmlParserStatus { Q_OBJECT Q_PROPERTY(int value READ value WRITE setValue) @@ -24,7 +25,7 @@ class MyQmlObject : public QObject, public MyInterface Q_PROPERTY(QRect rect READ rect WRITE setRect) Q_PROPERTY(QMatrix matrix READ matrix WRITE setMatrix) //assumed to be unsupported by QML Q_PROPERTY(MyInterface *interface READ interface WRITE setInterface) - Q_INTERFACES(MyInterface) + Q_INTERFACES(MyInterface QmlParserStatus) public: MyQmlObject() : m_value(-1), m_interface(0) {} @@ -45,6 +46,11 @@ public: MyInterface *interface() const { return m_interface; } void setInterface(MyInterface *iface) { m_interface = iface; } + static QObject *qmlAttachedProperties(QObject *other) { + MyQmlObject *rv = new MyQmlObject; + rv->setParent(other); + return rv; + } Q_CLASSINFO("DefaultMethod", "basicSlot()"); public slots: @@ -68,6 +74,9 @@ class MyTypeObject : public QObject Q_ENUMS(MyEnum) Q_FLAGS(MyFlags) + Q_PROPERTY(QString id READ id WRITE setId); + Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty); + Q_PROPERTY(QmlComponent *componentProperty READ componentProperty WRITE setComponentProperty); Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty); Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty); Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty); @@ -89,6 +98,33 @@ class MyTypeObject : public QObject Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); public: + MyTypeObject() + : objectPropertyValue(0), componentPropertyValue(0) {} + + QString idValue; + QString id() const { + return idValue; + } + void setId(const QString &v) { + idValue = v; + } + + QObject *objectPropertyValue; + QObject *objectProperty() const { + return objectPropertyValue; + } + void setObjectProperty(QObject *v) { + objectPropertyValue = v; + } + + QmlComponent *componentPropertyValue; + QmlComponent *componentProperty() const { + return componentPropertyValue; + } + void setComponentProperty(QmlComponent *v) { + componentPropertyValue = v; + } + enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 }; Q_DECLARE_FLAGS(MyFlags, MyFlag) MyFlags flagPropertyValue; @@ -273,6 +309,22 @@ private: QML_DECLARE_TYPE(MyContainer); QML_DEFINE_TYPE(MyContainer,MyContainer); +class MyPropertyValueSource : public QmlPropertyValueSource +{ + Q_OBJECT +public: + MyPropertyValueSource() + : QmlPropertyValueSource(0) {} + + QmlMetaProperty prop; + virtual void setTarget(const QmlMetaProperty &p) + { + prop = p; + } +}; +QML_DECLARE_TYPE(MyPropertyValueSource); +QML_DEFINE_TYPE(MyPropertyValueSource,MyPropertyValueSource); + class MyDotPropertyObject : public QObject { Q_OBJECT @@ -337,6 +389,14 @@ private slots: void customParserTypes(); void rootAsQmlComponent(); void inlineQmlComponents(); + void idProperty(); + void assignSignal(); + void dynamicProperties(); + void dynamicSignalsAndSlots(); + void simpleBindings(); + void autoComponentCreation(); + void propertyValueSource(); + void attachedProperties(); // regression tests for crashes void crash1(); @@ -400,17 +460,22 @@ void tst_qmlparser::errors_data() QTest::newRow("wrongType (string for point)") << "wrongType.11.txt" << "wrongType.11.errors.txt" << false; QTest::newRow("wrongType (color for size)") << "wrongType.12.txt" << "wrongType.12.errors.txt" << false; + QTest::newRow("readOnly.1") << "readOnly.1.txt" << "readOnly.1.errors.txt" << false; + QTest::newRow("readOnly.2") << "readOnly.2.txt" << "readOnly.2.errors.txt" << true; - QTest::newRow("nonExistantProperty.1") << "readOnly.1.txt" << "readOnly.1.errors.txt" << false; - QTest::newRow("nonExistantProperty.2") << "readOnly.2.txt" << "readOnly.2.errors.txt" << true; + QTest::newRow("listAssignment.1") << "listAssignment.1.txt" << "listAssignment.1.errors.txt" << false; + QTest::newRow("listAssignment.2") << "listAssignment.2.txt" << "listAssignment.2.errors.txt" << false; + QTest::newRow("listAssignment.3") << "listAssignment.3.txt" << "listAssignment.3.errors.txt" << false; + QTest::newRow("invalidID.1") << "invalidID.txt" << "invalidID.errors.txt" << false; + QTest::newRow("invalidID.2") << "invalidID.2.txt" << "invalidID.2.errors.txt" << false; + QTest::newRow("invalidID.3") << "invalidID.3.txt" << "invalidID.3.errors.txt" << false; + QTest::newRow("invalidID.4") << "invalidID.4.txt" << "invalidID.4.errors.txt" << false; QTest::newRow("unsupportedProperty") << "unsupportedProperty.txt" << "unsupportedProperty.errors.txt" << true; QTest::newRow("nullDotProperty") << "nullDotProperty.txt" << "nullDotProperty.errors.txt" << true; QTest::newRow("fakeDotProperty") << "fakeDotProperty.txt" << "fakeDotProperty.errors.txt" << true; QTest::newRow("duplicateIDs") << "duplicateIDs.txt" << "duplicateIDs.errors.txt" << false; - QTest::newRow("invalidID.1") << "invalidID.txt" << "invalidID.errors.txt" << false; - QTest::newRow("invalidID.2") << "invalidID.2.txt" << "invalidID.2.errors.txt" << false; QTest::newRow("unregisteredObject") << "unregisteredObject.txt" << "unregisteredObject.errors.txt" << false; QTest::newRow("empty") << "empty.txt" << "empty.errors.txt" << false; QTest::newRow("missingObject") << "missingObject.txt" << "missingObject.errors.txt" << false; @@ -524,6 +589,10 @@ void tst_qmlparser::assignBasicTypes() QCOMPARE(object->rectFProperty(), QRectF((float)1000.1, (float)-10.9, (float)400, (float)90.99)); QCOMPARE(object->boolProperty(), true); QCOMPARE(object->variantProperty(), QVariant("Hello World!")); + QVERIFY(object->objectProperty() != 0); + MyTypeObject *child = qobject_cast(object->objectProperty()); + QVERIFY(child != 0); + QCOMPARE(child->intProperty(), 8); } // Tests that custom parser tyeps can be instantiated @@ -559,6 +628,107 @@ void tst_qmlparser::inlineQmlComponents() QCOMPARE(compObject->value(), 11); } +// Tests that types that have an id property have it set +void tst_qmlparser::idProperty() +{ + QmlComponent component(&engine, TEST_FILE("idProperty.txt")); + MyContainer *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->children()->count(), 1); + MyTypeObject *child = + qobject_cast(object->children()->at(0)); + QVERIFY(child != 0); + QCOMPARE(child->id(), QString("MyObjectId")); + QCOMPARE(object->property("object"), QVariant::fromValue((QObject *)child)); +} + +// Tests that signals can be assigned to +void tst_qmlparser::assignSignal() +{ + QmlComponent component(&engine, TEST_FILE("assignSignal.txt")); + MyQmlObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QTest::ignoreMessage(QtWarningMsg, "MyQmlObject::basicSlot"); + emit object->basicSignal(); +} + +// Tests the creation and assignment of dynamic properties +void tst_qmlparser::dynamicProperties() +{ + QmlComponent component(&engine, TEST_FILE("dynamicProperties.txt")); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("intProperty"), QVariant(10)); + QCOMPARE(object->property("boolProperty"), QVariant(false)); + QCOMPARE(object->property("doubleProperty"), QVariant((float)-10.1)); + QCOMPARE(object->property("realProperty"), QVariant((float)-19.9)); + QCOMPARE(object->property("stringProperty"), QVariant("Hello World!")); + QCOMPARE(object->property("colorProperty"), QVariant(QColor("red"))); + QCOMPARE(object->property("dateProperty"), QVariant(QDate(1945, 9, 2))); + QCOMPARE(object->property("varProperty"), QVariant("Hello World!")); + QCOMPARE(object->property("variantProperty"), QVariant(12)); +} + +// Tests the declaration of dynamic signals and slots +void tst_qmlparser::dynamicSignalsAndSlots() +{ + QmlComponent component(&engine, TEST_FILE("dynamicSignalsAndSlots.txt")); + QObject *object = component.create(); + QVERIFY(object != 0); + QVERIFY(object->metaObject()->indexOfMethod("signal1()") != -1); + QVERIFY(object->metaObject()->indexOfMethod("signal2()") != -1); + QVERIFY(object->metaObject()->indexOfMethod("slot1()") != -1); + QVERIFY(object->metaObject()->indexOfMethod("slot2()") != -1); +} + +void tst_qmlparser::simpleBindings() +{ + QmlComponent component(&engine, TEST_FILE("simpleBindings.txt")); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("value1"), QVariant(10)); + QCOMPARE(object->property("value2"), QVariant(10)); + QCOMPARE(object->property("value3"), QVariant(21)); + QCOMPARE(object->property("value4"), QVariant(10)); + QCOMPARE(object->property("objectProperty"), QVariant::fromValue(object)); +} + +void tst_qmlparser::autoComponentCreation() +{ + QmlComponent component(&engine, TEST_FILE("autoComponentCreation.txt")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QVERIFY(object->componentProperty() != 0); + MyTypeObject *child = qobject_cast(object->componentProperty()->create()); + QVERIFY(child != 0); + QCOMPARE(child->realProperty(), qreal(9)); +} + +void tst_qmlparser::propertyValueSource() +{ + QmlComponent component(&engine, TEST_FILE("propertyValueSource.txt")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QList valueSources = + object->findChildren(); + QCOMPARE(valueSources.count(), 1); + MyPropertyValueSource *valueSource = + qobject_cast(valueSources.at(0)); + QVERIFY(valueSource != 0); + QCOMPARE(valueSource->prop.object(), object); + QCOMPARE(valueSource->prop.name(), QString(QLatin1String("intProperty"))); +} + +void tst_qmlparser::attachedProperties() +{ + QmlComponent component(&engine, TEST_FILE("attachedProperties.txt")); + QObject *object = component.create(); + QVERIFY(object != 0); + QObject *attached = qmlAttachedPropertiesObject(object); + QVERIFY(attached != 0); + QCOMPARE(attached->property("value"), QVariant(10)); +} + void tst_qmlparser::crash1() { QmlComponent component(&engine, "Component {}"); -- cgit v0.12 From c7e351aa2f899aed619b896c627606ea24384321 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 May 2009 17:40:30 +1000 Subject: Remove QWidget hack We no longer have any QWidget bindings, so we don't need this hack. Will have to solve the problem properly when we reintroduce QWidget support. --- src/declarative/qml/qmlvme.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 794c836..dc9ef06 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -282,11 +282,7 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in } if (!stack.isEmpty()) { QObject *parent = stack.top(); - if (o->isWidgetType()) { - qobject_cast(o)->setParent(qobject_cast(parent)); - } else { - o->setParent(parent); - } + o->setParent(parent); } stack.push(o); } -- cgit v0.12 From 12dfbdc911fcc0778f7187afef59c1c9f1cb7050 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 May 2009 18:00:00 +1000 Subject: Crash --- src/declarative/fx/qfxlayouts.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/fx/qfxlayouts.cpp b/src/declarative/fx/qfxlayouts.cpp index e95998b..53b367a 100644 --- a/src/declarative/fx/qfxlayouts.cpp +++ b/src/declarative/fx/qfxlayouts.cpp @@ -378,11 +378,11 @@ void QFxBaseLayout::preLayout() if (d->aut & Horizontal) setWidth(int(width)); - else + else if (itemParent()) setImplicitWidth(itemParent()->width()); if (d->aut & Vertical) setHeight(int(height)); - else + else if (itemParent()) setImplicitHeight(itemParent()->height()); setLayoutItem(0); } -- cgit v0.12 From 8ade63338f4a0cecf885ec4f4192436b3fdeda9a Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 May 2009 18:12:13 +1000 Subject: Remove accidentally commited CXX flags --- src/declarative/declarative.pro | 2 +- tests/auto/declarative/qmlparser/qmlparser.pro | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index fac7c08..8db22b2 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -11,7 +11,7 @@ LIBS += -lgcov unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml -QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage include(../qbase.pri) diff --git a/tests/auto/declarative/qmlparser/qmlparser.pro b/tests/auto/declarative/qmlparser/qmlparser.pro index f50cf2b..42e157f 100644 --- a/tests/auto/declarative/qmlparser/qmlparser.pro +++ b/tests/auto/declarative/qmlparser/qmlparser.pro @@ -3,5 +3,5 @@ contains(QT_CONFIG,declarative): QT += declarative SOURCES += tst_qmlparser.cpp macx:CONFIG -= app_bundle -QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +# QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage LIBS += -lgcov -- cgit v0.12 From eb60b6fdb3e7288a92d9febd097e3ab64480c518 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 May 2009 23:31:14 +1000 Subject: More tests --- tests/auto/declarative/qmlparser/FailingComponent.qml | 3 +++ tests/auto/declarative/qmlparser/MyComponent.qml | 2 +- tests/auto/declarative/qmlparser/dynamicObject.1.txt | 6 ++++++ tests/auto/declarative/qmlparser/failingComponent.errors.txt | 2 ++ tests/auto/declarative/qmlparser/failingComponent.txt | 4 ++++ tests/auto/declarative/qmlparser/missingSignal.errors.txt | 1 + tests/auto/declarative/qmlparser/missingSignal.txt | 3 +++ tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 11 +++++++++++ 8 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmlparser/FailingComponent.qml create mode 100644 tests/auto/declarative/qmlparser/dynamicObject.1.txt create mode 100644 tests/auto/declarative/qmlparser/failingComponent.errors.txt create mode 100644 tests/auto/declarative/qmlparser/failingComponent.txt create mode 100644 tests/auto/declarative/qmlparser/missingSignal.errors.txt create mode 100644 tests/auto/declarative/qmlparser/missingSignal.txt diff --git a/tests/auto/declarative/qmlparser/FailingComponent.qml b/tests/auto/declarative/qmlparser/FailingComponent.qml new file mode 100644 index 0000000..b604e0b --- /dev/null +++ b/tests/auto/declarative/qmlparser/FailingComponent.qml @@ -0,0 +1,3 @@ +Object { + a: 10 +} diff --git a/tests/auto/declarative/qmlparser/MyComponent.qml b/tests/auto/declarative/qmlparser/MyComponent.qml index 320a036..8a9f57d 100644 --- a/tests/auto/declarative/qmlparser/MyComponent.qml +++ b/tests/auto/declarative/qmlparser/MyComponent.qml @@ -1,4 +1,4 @@ -Object { +MyQmlObject { property real x; property real y; } diff --git a/tests/auto/declarative/qmlparser/dynamicObject.1.txt b/tests/auto/declarative/qmlparser/dynamicObject.1.txt new file mode 100644 index 0000000..ac892c3 --- /dev/null +++ b/tests/auto/declarative/qmlparser/dynamicObject.1.txt @@ -0,0 +1,6 @@ +SetProperties { + propa: a + 10 + propb: Math.min(a, 10) + propc: MyPropertyValueSource {} + onPropA: a +} diff --git a/tests/auto/declarative/qmlparser/failingComponent.errors.txt b/tests/auto/declarative/qmlparser/failingComponent.errors.txt new file mode 100644 index 0000000..0db1271 --- /dev/null +++ b/tests/auto/declarative/qmlparser/failingComponent.errors.txt @@ -0,0 +1,2 @@ +2:-1:Unknown property "a" +2:-1:Unable to create object of type "FailingComponent" diff --git a/tests/auto/declarative/qmlparser/failingComponent.txt b/tests/auto/declarative/qmlparser/failingComponent.txt new file mode 100644 index 0000000..8c43f84 --- /dev/null +++ b/tests/auto/declarative/qmlparser/failingComponent.txt @@ -0,0 +1,4 @@ +MyContainer { + FailingComponent {} +} + diff --git a/tests/auto/declarative/qmlparser/missingSignal.errors.txt b/tests/auto/declarative/qmlparser/missingSignal.errors.txt new file mode 100644 index 0000000..8ae1bbe4 --- /dev/null +++ b/tests/auto/declarative/qmlparser/missingSignal.errors.txt @@ -0,0 +1 @@ +2:-1:Cannot assign a signal to property "onClicked" diff --git a/tests/auto/declarative/qmlparser/missingSignal.txt b/tests/auto/declarative/qmlparser/missingSignal.txt new file mode 100644 index 0000000..07d1bfa --- /dev/null +++ b/tests/auto/declarative/qmlparser/missingSignal.txt @@ -0,0 +1,3 @@ +Object { + onClicked: print("Hello world!") +} diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index 81d044b..1a35d72 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -397,6 +397,7 @@ private slots: void autoComponentCreation(); void propertyValueSource(); void attachedProperties(); + void dynamicObjects(); // regression tests for crashes void crash1(); @@ -479,6 +480,8 @@ void tst_qmlparser::errors_data() QTest::newRow("unregisteredObject") << "unregisteredObject.txt" << "unregisteredObject.errors.txt" << false; QTest::newRow("empty") << "empty.txt" << "empty.errors.txt" << false; QTest::newRow("missingObject") << "missingObject.txt" << "missingObject.errors.txt" << false; + QTest::newRow("failingComponent") << "failingComponent.txt" << "failingComponent.errors.txt" << true; + QTest::newRow("missingSignal") << "missingSignal.txt" << "missingSignal.errors.txt" << true; } void tst_qmlparser::errors() @@ -729,6 +732,14 @@ void tst_qmlparser::attachedProperties() QCOMPARE(attached->property("value"), QVariant(10)); } +// Tests non-static object properties +void tst_qmlparser::dynamicObjects() +{ + QmlComponent component(&engine, TEST_FILE("dynamicObject.1.txt")); + QObject *object = component.create(); + QVERIFY(object != 0); +} + void tst_qmlparser::crash1() { QmlComponent component(&engine, "Component {}"); -- cgit v0.12 From f8c06c96b698392bea24f388840dec03274cb14b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 12 May 2009 23:42:35 +1000 Subject: Disable code that triggers a crash at exit. This is a hack. We should fix it properly. --- src/declarative/qml/qmlcontext.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 91bf1c0..fa36eb1 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -85,9 +85,11 @@ void QmlContextPrivate::destroyed(QObject *obj) notifies.append(ii); } } - for (int ii = 0; ii < notifies.count(); ++ii) { - QMetaObject::activate(q, notifies[ii] + notifyIndex, 0); - } + + // ### Work around bug in shutdown + // for (int ii = 0; ii < notifies.count(); ++ii) { + // QMetaObject::activate(q, notifies[ii] + notifyIndex, 0); + // } } void QmlContextPrivate::init() -- cgit v0.12 From b417ed17f15d88eeac21c46fa666af37b69d4531 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 13 May 2009 10:22:47 +1000 Subject: More tests --- tests/auto/declarative/qmlparser/assignTypeExtremes.txt | 4 ++++ tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/auto/declarative/qmlparser/assignTypeExtremes.txt diff --git a/tests/auto/declarative/qmlparser/assignTypeExtremes.txt b/tests/auto/declarative/qmlparser/assignTypeExtremes.txt new file mode 100644 index 0000000..dbd281a --- /dev/null +++ b/tests/auto/declarative/qmlparser/assignTypeExtremes.txt @@ -0,0 +1,4 @@ +MyTypeObject { + uintProperty: 4000000000 + intProperty: -2000000000 +} diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index 1a35d72..8be3311 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -386,6 +386,7 @@ private slots: void assignObjectToSignal(); void assignQmlComponent(); void assignBasicTypes(); + void assignTypeExtremes(); void customParserTypes(); void rootAsQmlComponent(); void inlineQmlComponents(); @@ -598,6 +599,16 @@ void tst_qmlparser::assignBasicTypes() QCOMPARE(child->intProperty(), 8); } +// Test edge case type assignments +void tst_qmlparser::assignTypeExtremes() +{ + QmlComponent component(&engine, TEST_FILE("assignTypeExtremes.txt")); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->uintProperty(), 0xEE6B2800); + QCOMPARE(object->intProperty(), -0x77359400); +} + // Tests that custom parser tyeps can be instantiated void tst_qmlparser::customParserTypes() { -- cgit v0.12