diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-12 05:16:49 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-12 05:16:49 (GMT) |
commit | 0d1fecac0a0a6d914aa3c00ef6e2c4aadeecc0c0 (patch) | |
tree | 7b68f32c65087a38a2c64ae955ba157c78c88504 | |
parent | 7c0960a479a250d4c6b46d6fe094ab93564e515b (diff) | |
download | Qt-0d1fecac0a0a6d914aa3c00ef6e2c4aadeecc0c0.zip Qt-0d1fecac0a0a6d914aa3c00ef6e2c4aadeecc0c0.tar.gz Qt-0d1fecac0a0a6d914aa3c00ef6e2c4aadeecc0c0.tar.bz2 |
More QML tests
36 files changed, 399 insertions, 76 deletions
diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 1e8e82b..fac7c08 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -7,8 +7,12 @@ DEFINES += QT_NO_USING_NAMESPACE win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 +LIBS += -lgcov + unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml +QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage + include(../qbase.pri) #modules diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index f17b50d..a703ec3 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -93,7 +93,7 @@ int QmlCompiledData::indexForFloat(float *data, int count) { Q_ASSERT(count > 0); - for (int ii = 0; ii < floatData.count() - count; ++ii) { + for (int ii = 0; ii <= floatData.count() - count; ++ii) { bool found = true; for (int jj = 0; jj < count; ++jj) { if (floatData.at(ii + jj) != data[jj]) { @@ -117,7 +117,7 @@ int QmlCompiledData::indexForInt(int *data, int count) { Q_ASSERT(count > 0); - for (int ii = 0; ii < floatData.count() - count; ++ii) { + for (int ii = 0; ii <= intData.count() - count; ++ii) { bool found = true; for (int jj = 0; jj < count; ++jj) { if (intData.at(ii + jj) != data[jj]) { @@ -240,13 +240,8 @@ QmlCompiler::generateStoreInstruction(QmlCompiledData &cdata, { instr.type = QmlInstruction::StoreString; instr.storeString.propertyIndex = coreIdx; - if (string->startsWith(QLatin1Char('\'')) && string->endsWith(QLatin1Char('\''))) { - QString unquotedString = string->mid(1, string->length() - 2); - primitive = cdata.indexForString(unquotedString); - } else { - if (primitive == -1) - primitive = cdata.indexForString(*string); - } + if (primitive == -1) + primitive = cdata.indexForString(*string); instr.storeString.value = primitive; } break; @@ -488,18 +483,13 @@ bool QmlCompiler::compile(QmlEngine *engine, ref.component = tref.unit->toComponent(engine); ref.ref = tref.unit; ref.ref->addref(); - } else if (tref.parser) - ref.parser = tref.parser; + } ref.className = unit->data.types().at(ii).toLatin1(); out->types << ref; } Object *root = unit->data.tree(); - if (!root) { - exceptionDescription = QLatin1String("Can't compile because of earlier errors"); - output = 0; - return false; - } + Q_ASSERT(root); compileTree(root); @@ -1498,26 +1488,25 @@ QObject *QmlCompiledData::TypeReference::createInstance(QmlContext *ctxt) const if (rv) QmlEngine::setContextForObject(rv, ctxt); return rv; - } else if (component) { + } else { + Q_ASSERT(component); QObject *rv = component->create(ctxt); QmlContext *ctxt = qmlContext(rv); if(ctxt) { static_cast<QmlContextPrivate *>(QObjectPrivate::get(ctxt))->typeName = className; } return rv; - } else { - return 0; - } + } } const QMetaObject *QmlCompiledData::TypeReference::metaObject() const { - if (type) + if (type) { return type->metaObject(); - else if (component) + } else { + Q_ASSERT(component); return &static_cast<QmlComponentPrivate *>(QObjectPrivate::get(component))->cc->root; - else - return 0; + } } QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h index 9d2f8f7..246dd70 100644 --- a/src/declarative/qml/qmlcompiler_p.h +++ b/src/declarative/qml/qmlcompiler_p.h @@ -72,12 +72,11 @@ public: struct TypeReference { TypeReference() - : type(0), component(0), parser(0), ref(0) {} + : type(0), component(0), ref(0) {} QByteArray className; QmlType *type; QmlComponent *component; - QmlCustomParser *parser; QmlRefCount *ref; QObject *createInstance(QmlContext *) const; diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index f646ca9..e1124a6 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -123,7 +123,7 @@ QmlCompositeTypeData::toCompiledComponent(QmlEngine *engine) } QmlCompositeTypeData::TypeReference::TypeReference() -: type(0), unit(0), parser(0) +: type(0), unit(0) { } @@ -309,18 +309,8 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) continue; } - QmlCustomParser *parser = - QmlMetaType::customParser(type); - - if (parser) { - ref.parser = parser; - unit->types << ref; - continue; - } - ref.type = QmlMetaType::qmlType(type); if (ref.type) { - ref.parser = parser; unit->types << ref; continue; } diff --git a/src/declarative/qml/qmlcompositetypemanager_p.h b/src/declarative/qml/qmlcompositetypemanager_p.h index c12dedc..f03b2cb 100644 --- a/src/declarative/qml/qmlcompositetypemanager_p.h +++ b/src/declarative/qml/qmlcompositetypemanager_p.h @@ -92,7 +92,6 @@ struct QmlCompositeTypeData : public QmlRefCount QmlType *type; QmlCompositeTypeData *unit; - QmlCustomParser *parser; }; QList<TypeReference> types; diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index 63e5c58..7825e5c 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -87,8 +87,6 @@ struct QmlMetaTypeData Names nameToType; typedef QHash<const QMetaObject *, QmlType *> MetaObjects; MetaObjects metaObjectToType; - typedef QHash<QByteArray, QmlCustomParser *> CustomParsers; - CustomParsers customParsers; typedef QHash<int, QmlMetaType::StringConverter> StringConverters; StringConverters stringConverters; @@ -448,30 +446,6 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun return index; } -void QmlMetaType::registerCustomParser(const char *qmlName, - QmlCustomParser *parser) -{ - QWriteLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - - Q_ASSERT(parser); - if (data->customParsers.contains(qmlName)) { - delete parser; - return; - } - - data->customParsers.insert(qmlName, parser); -} - -QmlCustomParser *QmlMetaType::customParser(const QByteArray &name) -{ - QReadLocker lock(metaTypeDataLock()); - QmlMetaTypeData *data = metaTypeData(); - - return data->customParsers.value(name); -} - - int QmlMetaType::qmlParserStatusCast(int userType) { QReadLocker lock(metaTypeDataLock()); @@ -1167,9 +1141,4 @@ bool QmlMetaType::copy(int type, void *data, const void *copy) return false; } -void qmlRegisterCustomParser(const char *qmlName, QmlCustomParser *parser) -{ - QmlMetaType::registerCustomParser(qmlName, parser); -} - QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h index 99f8e93..7ab01a5 100644 --- a/src/declarative/qml/qmlmetatype.h +++ b/src/declarative/qml/qmlmetatype.h @@ -61,9 +61,6 @@ class Q_DECLARATIVE_EXPORT QmlMetaType public: static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, const QMetaObject *, QmlAttachedPropertiesFunc, int pStatus, int object, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *); static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *); - static void registerCustomParser(const char *, QmlCustomParser *); - - static QmlCustomParser *customParser(const QByteArray &); static bool copy(int type, void *data, const void *copy = 0); @@ -269,8 +266,6 @@ int qmlRegisterCustomType(const char *qmlName, const char *typeName, QmlCustomPa 0, 0, parser); } -void qmlRegisterCustomParser(const char *qmlName, QmlCustomParser *); - QT_END_NAMESPACE QT_END_HEADER diff --git a/tests/auto/declarative/qmlparser/MyComponent.qml b/tests/auto/declarative/qmlparser/MyComponent.qml new file mode 100644 index 0000000..320a036 --- /dev/null +++ b/tests/auto/declarative/qmlparser/MyComponent.qml @@ -0,0 +1,4 @@ +Object { + property real x; + property real y; +} diff --git a/tests/auto/declarative/qmlparser/MyContainerComponent.qml b/tests/auto/declarative/qmlparser/MyContainerComponent.qml new file mode 100644 index 0000000..5746928 --- /dev/null +++ b/tests/auto/declarative/qmlparser/MyContainerComponent.qml @@ -0,0 +1,3 @@ +MyContainer { + property int x +} diff --git a/tests/auto/declarative/qmlparser/assignBasicTypes.txt b/tests/auto/declarative/qmlparser/assignBasicTypes.txt new file mode 100644 index 0000000..49de929 --- /dev/null +++ b/tests/auto/declarative/qmlparser/assignBasicTypes.txt @@ -0,0 +1,23 @@ +MyTypeObject { + flagProperty: "FlagVal1 | FlagVal3" + enumProperty: "EnumVal2" + stringProperty: "Hello World!" + uintProperty: 10 + intProperty: -19 + realProperty: 23.2 + doubleProperty: -19.7 + colorProperty: "red" + dateProperty: "1982-11-25" + timeProperty: "11:11:31" + timeProperty: "11:11:32" + timeProperty: "11:11:32" + dateTimeProperty: "2009-05-12T13:22:01" + pointProperty: "99,13" + pointFProperty: "-10.1,12.3" + sizeProperty: "99x13" + sizeFProperty: "0.1x0.2" + rectProperty: "9,7,100x200" + rectFProperty: "1000.1,-10.9,400x90.99" + boolProperty: true + variantProperty: "Hello World!" +} diff --git a/tests/auto/declarative/qmlparser/assignQmlComponent.txt b/tests/auto/declarative/qmlparser/assignQmlComponent.txt new file mode 100644 index 0000000..6b6d77f --- /dev/null +++ b/tests/auto/declarative/qmlparser/assignQmlComponent.txt @@ -0,0 +1,3 @@ +MyContainer { + MyComponent { x: 10; y: 11; } +} diff --git a/tests/auto/declarative/qmlparser/customParserTypes.txt b/tests/auto/declarative/qmlparser/customParserTypes.txt new file mode 100644 index 0000000..52848fa --- /dev/null +++ b/tests/auto/declarative/qmlparser/customParserTypes.txt @@ -0,0 +1,4 @@ +ListModel { + ListElement { a: 10 } + ListElement { a: 12 } +} diff --git a/tests/auto/declarative/qmlparser/inlineQmlComponents.txt b/tests/auto/declarative/qmlparser/inlineQmlComponents.txt new file mode 100644 index 0000000..e713a88 --- /dev/null +++ b/tests/auto/declarative/qmlparser/inlineQmlComponents.txt @@ -0,0 +1,8 @@ +MyContainer { + Component { + id: MyComponent + MyQmlObject { + value: 11 + } + } +} diff --git a/tests/auto/declarative/qmlparser/invalidID.2.errors.txt b/tests/auto/declarative/qmlparser/invalidID.2.errors.txt new file mode 100644 index 0000000..6380750 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.2.errors.txt @@ -0,0 +1,2 @@ +1:1:"" is not a valid id + diff --git a/tests/auto/declarative/qmlparser/invalidID.2.txt b/tests/auto/declarative/qmlparser/invalidID.2.txt new file mode 100644 index 0000000..a7af29e --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.2.txt @@ -0,0 +1,4 @@ +MyQmlObject { + id: "" +} + diff --git a/tests/auto/declarative/qmlparser/qmlparser.pro b/tests/auto/declarative/qmlparser/qmlparser.pro index 43e5309..f50cf2b 100644 --- a/tests/auto/declarative/qmlparser/qmlparser.pro +++ b/tests/auto/declarative/qmlparser/qmlparser.pro @@ -2,3 +2,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative SOURCES += tst_qmlparser.cpp macx:CONFIG -= app_bundle + +QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage +LIBS += -lgcov diff --git a/tests/auto/declarative/qmlparser/rootAsQmlComponent.txt b/tests/auto/declarative/qmlparser/rootAsQmlComponent.txt new file mode 100644 index 0000000..8cb57ff --- /dev/null +++ b/tests/auto/declarative/qmlparser/rootAsQmlComponent.txt @@ -0,0 +1,5 @@ +MyContainerComponent { + x: 11 + MyQmlObject {} + MyQmlObject {} +} diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index f17583a..a3b94db 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -62,6 +62,193 @@ private: QML_DECLARE_TYPE(MyQmlObject); QML_DEFINE_TYPE(MyQmlObject,MyQmlObject); +class MyTypeObject : public QObject +{ + Q_OBJECT + Q_ENUMS(MyEnum) + Q_FLAGS(MyFlags) + + Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty); + Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty); + Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty); + Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty); + Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty); + Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty); + Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty); + Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty); + Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty); + Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty); + Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty); + Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); + Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); + Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); + Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); + Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty); + Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); + Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty); + Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); + +public: + enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 }; + Q_DECLARE_FLAGS(MyFlags, MyFlag) + MyFlags flagPropertyValue; + MyFlags flagProperty() const { + return flagPropertyValue; + } + void setFlagProperty(MyFlags v) { + flagPropertyValue = v; + } + + enum MyEnum { EnumVal1, EnumVal2 }; + MyEnum enumPropertyValue; + MyEnum enumProperty() const { + return enumPropertyValue; + } + void setEnumProperty(MyEnum v) { + enumPropertyValue = v; + } + + QString stringPropertyValue; + QString stringProperty() const { + return stringPropertyValue; + } + void setStringProperty(const QString &v) { + stringPropertyValue = v; + } + + uint uintPropertyValue; + uint uintProperty() const { + return uintPropertyValue; + } + void setUintProperty(const uint &v) { + uintPropertyValue = v; + } + + int intPropertyValue; + int intProperty() const { + return intPropertyValue; + } + void setIntProperty(const int &v) { + intPropertyValue = v; + } + + qreal realPropertyValue; + qreal realProperty() const { + return realPropertyValue; + } + void setRealProperty(const qreal &v) { + realPropertyValue = v; + } + + double doublePropertyValue; + double doubleProperty() const { + return doublePropertyValue; + } + void setDoubleProperty(const double &v) { + doublePropertyValue = v; + } + + QColor colorPropertyValue; + QColor colorProperty() const { + return colorPropertyValue; + } + void setColorProperty(const QColor &v) { + colorPropertyValue = v; + } + + QDate datePropertyValue; + QDate dateProperty() const { + return datePropertyValue; + } + void setDateProperty(const QDate &v) { + datePropertyValue = v; + } + + QTime timePropertyValue; + QTime timeProperty() const { + return timePropertyValue; + } + void setTimeProperty(const QTime &v) { + timePropertyValue = v; + } + + QDateTime dateTimePropertyValue; + QDateTime dateTimeProperty() const { + return dateTimePropertyValue; + } + void setDateTimeProperty(const QDateTime &v) { + dateTimePropertyValue = v; + } + + QPoint pointPropertyValue; + QPoint pointProperty() const { + return pointPropertyValue; + } + void setPointProperty(const QPoint &v) { + pointPropertyValue = v; + } + + QPointF pointFPropertyValue; + QPointF pointFProperty() const { + return pointFPropertyValue; + } + void setPointFProperty(const QPointF &v) { + pointFPropertyValue = v; + } + + QSize sizePropertyValue; + QSize sizeProperty() const { + return sizePropertyValue; + } + void setSizeProperty(const QSize &v) { + sizePropertyValue = v; + } + + QSizeF sizeFPropertyValue; + QSizeF sizeFProperty() const { + return sizeFPropertyValue; + } + void setSizeFProperty(const QSizeF &v) { + sizeFPropertyValue = v; + } + + QRect rectPropertyValue; + QRect rectProperty() const { + return rectPropertyValue; + } + void setRectProperty(const QRect &v) { + rectPropertyValue = v; + } + + QRectF rectFPropertyValue; + QRectF rectFProperty() const { + return rectFPropertyValue; + } + void setRectFProperty(const QRectF &v) { + rectFPropertyValue = v; + } + + bool boolPropertyValue; + bool boolProperty() const { + return boolPropertyValue; + } + void setBoolProperty(const bool &v) { + boolPropertyValue = v; + } + + QVariant variantPropertyValue; + QVariant variantProperty() const { + return variantPropertyValue; + } + void setVariantProperty(const QVariant &v) { + variantPropertyValue = v; + } +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags) + +QML_DECLARE_TYPE(MyTypeObject); +QML_DEFINE_TYPE(MyTypeObject,MyTypeObject); + class MyContainer : public QObject { Q_OBJECT @@ -144,8 +331,12 @@ private slots: void interfaceProperty(); void interfaceQmlList(); void interfaceQList(); - void assignObjectToSignal(); + void assignQmlComponent(); + void assignBasicTypes(); + void customParserTypes(); + void rootAsQmlComponent(); + void inlineQmlComponents(); // regression tests for crashes void crash1(); @@ -199,6 +390,16 @@ void tst_qmlparser::errors_data() QTest::newRow("wrongType (int for bool)") << "wrongType.2.txt" << "wrongType.2.errors.txt" << false; QTest::newRow("wrongType (bad rect)") << "wrongType.3.txt" << "wrongType.3.errors.txt" << false; + QTest::newRow("wrongType (invalid enum)") << "wrongType.4.txt" << "wrongType.4.errors.txt" << false; + QTest::newRow("wrongType (int for uint)") << "wrongType.5.txt" << "wrongType.5.errors.txt" << false; + QTest::newRow("wrongType (string for real)") << "wrongType.6.txt" << "wrongType.6.errors.txt" << false; + QTest::newRow("wrongType (int for color)") << "wrongType.7.txt" << "wrongType.7.errors.txt" << false; + QTest::newRow("wrongType (int for date)") << "wrongType.8.txt" << "wrongType.8.errors.txt" << false; + QTest::newRow("wrongType (int for time)") << "wrongType.9.txt" << "wrongType.9.errors.txt" << false; + QTest::newRow("wrongType (int for datetime)") << "wrongType.10.txt" << "wrongType.10.errors.txt" << false; + 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("nonExistantProperty.1") << "readOnly.1.txt" << "readOnly.1.errors.txt" << false; QTest::newRow("nonExistantProperty.2") << "readOnly.2.txt" << "readOnly.2.errors.txt" << true; @@ -208,7 +409,8 @@ void tst_qmlparser::errors_data() 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") << "invalidID.txt" << "invalidID.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; @@ -284,6 +486,79 @@ void tst_qmlparser::assignObjectToSignal() emit object->basicSignal(); } + +// Test is an external component can be loaded and assigned (to a qlist) +void tst_qmlparser::assignQmlComponent() +{ + QmlComponent component(&engine, TEST_FILE("assignQmlComponent.txt")); + MyContainer *object = qobject_cast<MyContainer *>(component.create()); + QVERIFY(object != 0); + QVERIFY(object->children()->count() == 1); + QObject *child = object->children()->at(0); + QCOMPARE(child->property("x"), QVariant(10)); + QCOMPARE(child->property("y"), QVariant(11)); +} + +// Test literal assignment to all the basic types +void tst_qmlparser::assignBasicTypes() +{ + QmlComponent component(&engine, TEST_FILE("assignBasicTypes.txt")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3); + QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2); + QCOMPARE(object->stringProperty(), QString("Hello World!")); + QCOMPARE(object->uintProperty(), uint(10)); + QCOMPARE(object->intProperty(), -19); + QCOMPARE((float)object->realProperty(), float(23.2)); + QCOMPARE((float)object->doubleProperty(), float(-19.7)); + QCOMPARE(object->colorProperty(), QColor("red")); + QCOMPARE(object->dateProperty(), QDate(1982, 11, 25)); + QCOMPARE(object->timeProperty(), QTime(11, 11, 32)); + QCOMPARE(object->dateTimeProperty(), QDateTime(QDate(2009, 5, 12), QTime(13, 22, 1))); + QCOMPARE(object->pointProperty(), QPoint(99,13)); + QCOMPARE(object->pointFProperty(), QPointF((float)-10.1, (float)12.3)); + QCOMPARE(object->sizeProperty(), QSize(99, 13)); + QCOMPARE(object->sizeFProperty(), QSizeF((float)0.1, (float)0.2)); + QCOMPARE(object->rectProperty(), QRect(9, 7, 100, 200)); + 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!")); +} + +// Tests that custom parser tyeps can be instantiated +void tst_qmlparser::customParserTypes() +{ + QmlComponent component(&engine, TEST_FILE("customParserTypes.txt")); + QObject *object = component.create(); + QVERIFY(object != 0); + QVERIFY(object->property("count") == QVariant(2)); +} + +// Tests that the root item can be a custom component +void tst_qmlparser::rootAsQmlComponent() +{ + QmlComponent component(&engine, TEST_FILE("rootAsQmlComponent.txt")); + MyContainer *object = qobject_cast<MyContainer *>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->property("x"), QVariant(11)); + QCOMPARE(object->children()->count(), 2); +} + +// Tests that components can be specified inline +void tst_qmlparser::inlineQmlComponents() +{ + QmlComponent component(&engine, TEST_FILE("inlineQmlComponents.txt")); + MyContainer *object = qobject_cast<MyContainer *>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->children()->count(), 1); + QmlComponent *comp = qobject_cast<QmlComponent *>(object->children()->at(0)); + QVERIFY(comp != 0); + MyQmlObject *compObject = qobject_cast<MyQmlObject *>(comp->create()); + QVERIFY(compObject != 0); + QCOMPARE(compObject->value(), 11); +} + void tst_qmlparser::crash1() { QmlComponent component(&engine, "Component {}"); diff --git a/tests/auto/declarative/qmlparser/wrongType.10.errors.txt b/tests/auto/declarative/qmlparser/wrongType.10.errors.txt new file mode 100644 index 0000000..562cd6c --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.10.errors.txt @@ -0,0 +1 @@ +2:23:Cannot assign value "12" to property dateTimeProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.10.txt b/tests/auto/declarative/qmlparser/wrongType.10.txt new file mode 100644 index 0000000..07a90e0 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.10.txt @@ -0,0 +1,4 @@ +MyTypeObject { + dateTimeProperty: 12 +} + diff --git a/tests/auto/declarative/qmlparser/wrongType.11.errors.txt b/tests/auto/declarative/qmlparser/wrongType.11.errors.txt new file mode 100644 index 0000000..24d27d5 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.11.errors.txt @@ -0,0 +1 @@ +2:20:Cannot assign value "apples" to property pointProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.11.txt b/tests/auto/declarative/qmlparser/wrongType.11.txt new file mode 100644 index 0000000..90a3797 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.11.txt @@ -0,0 +1,4 @@ +MyTypeObject { + pointProperty: "apples" +} + diff --git a/tests/auto/declarative/qmlparser/wrongType.12.errors.txt b/tests/auto/declarative/qmlparser/wrongType.12.errors.txt new file mode 100644 index 0000000..b57e70e --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.12.errors.txt @@ -0,0 +1 @@ +2:19:Cannot assign value "red" to property sizeProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.12.txt b/tests/auto/declarative/qmlparser/wrongType.12.txt new file mode 100644 index 0000000..c3fa4a0 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.12.txt @@ -0,0 +1,4 @@ +MyTypeObject { + sizeProperty: "red" +} + diff --git a/tests/auto/declarative/qmlparser/wrongType.4.errors.txt b/tests/auto/declarative/qmlparser/wrongType.4.errors.txt new file mode 100644 index 0000000..6bf88be --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.4.errors.txt @@ -0,0 +1 @@ +2:19:Cannot assign value "InvalidEnumName" to property enumProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.4.txt b/tests/auto/declarative/qmlparser/wrongType.4.txt new file mode 100644 index 0000000..6fa4a9c --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.4.txt @@ -0,0 +1,3 @@ +MyTypeObject { + enumProperty: "InvalidEnumName" +} diff --git a/tests/auto/declarative/qmlparser/wrongType.5.errors.txt b/tests/auto/declarative/qmlparser/wrongType.5.errors.txt new file mode 100644 index 0000000..0e40d84 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.5.errors.txt @@ -0,0 +1 @@ +2:19:Cannot assign value "-13" to property uintProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.5.txt b/tests/auto/declarative/qmlparser/wrongType.5.txt new file mode 100644 index 0000000..95b0904 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.5.txt @@ -0,0 +1,4 @@ +MyTypeObject { + uintProperty: -13 +} + diff --git a/tests/auto/declarative/qmlparser/wrongType.6.errors.txt b/tests/auto/declarative/qmlparser/wrongType.6.errors.txt new file mode 100644 index 0000000..9692997 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.6.errors.txt @@ -0,0 +1 @@ +2:19:Cannot assign value "Hello" to property realProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.6.txt b/tests/auto/declarative/qmlparser/wrongType.6.txt new file mode 100644 index 0000000..78351f4 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.6.txt @@ -0,0 +1,4 @@ +MyTypeObject { + realProperty: "Hello" +} + diff --git a/tests/auto/declarative/qmlparser/wrongType.7.errors.txt b/tests/auto/declarative/qmlparser/wrongType.7.errors.txt new file mode 100644 index 0000000..f44073a --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.7.errors.txt @@ -0,0 +1 @@ +2:20:Cannot assign value "12" to property colorProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.7.txt b/tests/auto/declarative/qmlparser/wrongType.7.txt new file mode 100644 index 0000000..8279ffa --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.7.txt @@ -0,0 +1,4 @@ +MyTypeObject { + colorProperty: 12 +} + diff --git a/tests/auto/declarative/qmlparser/wrongType.8.errors.txt b/tests/auto/declarative/qmlparser/wrongType.8.errors.txt new file mode 100644 index 0000000..8a45ffb --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.8.errors.txt @@ -0,0 +1 @@ +2:19:Cannot assign value "12" to property dateProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.8.txt b/tests/auto/declarative/qmlparser/wrongType.8.txt new file mode 100644 index 0000000..e1cfe9a --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.8.txt @@ -0,0 +1,4 @@ +MyTypeObject { + dateProperty: 12 +} + diff --git a/tests/auto/declarative/qmlparser/wrongType.9.errors.txt b/tests/auto/declarative/qmlparser/wrongType.9.errors.txt new file mode 100644 index 0000000..cba3339 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.9.errors.txt @@ -0,0 +1 @@ +2:19:Cannot assign value "12" to property timeProperty diff --git a/tests/auto/declarative/qmlparser/wrongType.9.txt b/tests/auto/declarative/qmlparser/wrongType.9.txt new file mode 100644 index 0000000..84dfa66 --- /dev/null +++ b/tests/auto/declarative/qmlparser/wrongType.9.txt @@ -0,0 +1,4 @@ +MyTypeObject { + timeProperty: 12 +} + |