From c8b163fdf6bb1796e6131e66cbb71c452dd1983d Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 1 Sep 2009 10:23:10 +1000 Subject: Split import tests up. Update tests. --- .../qmlparser/failingComponent.errors.txt | 3 +- tests/auto/declarative/qmlparser/testtypes.h | 5 +- tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 71 +++++++++++++++++----- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/tests/auto/declarative/qmlparser/failingComponent.errors.txt b/tests/auto/declarative/qmlparser/failingComponent.errors.txt index 190a649..0cf0ef3 100644 --- a/tests/auto/declarative/qmlparser/failingComponent.errors.txt +++ b/tests/auto/declarative/qmlparser/failingComponent.errors.txt @@ -1,2 +1 @@ -3:5:Unable to create type FailingComponent -4:5:Cannot assign to non-existant property "a" +3:5:Type FailingComponent unavailable diff --git a/tests/auto/declarative/qmlparser/testtypes.h b/tests/auto/declarative/qmlparser/testtypes.h index ace7ef9..f700484 100644 --- a/tests/auto/declarative/qmlparser/testtypes.h +++ b/tests/auto/declarative/qmlparser/testtypes.h @@ -357,12 +357,13 @@ private: QML_DECLARE_TYPE(MyContainer); -class MyPropertyValueSource : public QmlPropertyValueSource +class MyPropertyValueSource : public QObject, public QmlPropertyValueSource { Q_OBJECT + Q_INTERFACES(QmlPropertyValueSource) public: MyPropertyValueSource() - : QmlPropertyValueSource(0) {} + : QmlPropertyValueSource() {} QmlMetaProperty prop; virtual void setTarget(const QmlMetaProperty &p) diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index 3047bb0..c21d672 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -48,14 +48,19 @@ private slots: void customVariantTypes(); void valueTypes(); - void imports_data(); - void imports(); + void importsBuiltin_data(); + void importsBuiltin(); + void importsLocal_data(); + void importsLocal(); + void importsInstalled_data(); + void importsInstalled(); // regression tests for crashes void crash1(); private: QmlEngine engine; + void testType(const QString& qml, const QString& type); }; #define VERIFY_ERRORS(errorfile) \ @@ -420,6 +425,10 @@ void tst_qmlparser::autoComponentCreation() void tst_qmlparser::propertyValueSource() { + QVERIFY(false); + +/* Does not compile... + QmlComponent component(&engine, TEST_FILE("propertyValueSource.qml")); VERIFY_ERRORS(0); MyTypeObject *object = qobject_cast(component.create()); @@ -432,6 +441,7 @@ void tst_qmlparser::propertyValueSource() QVERIFY(valueSource != 0); QCOMPARE(valueSource->prop.object(), object); QCOMPARE(valueSource->prop.name(), QString(QLatin1String("intProperty"))); +*/ } void tst_qmlparser::attachedProperties() @@ -502,6 +512,21 @@ public: TestType2(QObject *p=0) : QObject(p) {} }; +// Check that first child of qml is of given type. Empty type insists on error. +void tst_qmlparser::testType(const QString& qml, const QString& type) +{ + QmlComponent component(&engine, qml.toUtf8(), TEST_FILE("empty.qml")); // just a file for relative local imports + + if (type.isEmpty()) { + QVERIFY(component.isError()); + } else { + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(QString(object->metaObject()->className()), type); + } +} + QML_DECLARE_TYPE(TestType) QML_DECLARE_TYPE(TestType2) @@ -511,7 +536,7 @@ QML_DEFINE_TYPE(com.nokia.Test, 1, 8, 9, Test, TestType2) QML_DEFINE_TYPE(com.nokia.Test, 1, 12, 13, Test, TestType2) QML_DEFINE_TYPE(com.nokia.Test, 1, 9, 11, OldTest, TestType) -void tst_qmlparser::imports_data() +void tst_qmlparser::importsBuiltin_data() { QTest::addColumn("qml"); QTest::addColumn("type"); @@ -605,6 +630,19 @@ void tst_qmlparser::imports_data() "import com.nokia.Test 1.10 as T10\n" "T10.Test {}" << ""; +} + +void tst_qmlparser::importsBuiltin() +{ + QFETCH(QString, qml); + QFETCH(QString, type); + testType(qml,type); +} + +void tst_qmlparser::importsLocal_data() +{ + QTest::addColumn("qml"); + QTest::addColumn("type"); // import locals QTest::newRow("local import") @@ -624,6 +662,19 @@ void tst_qmlparser::imports_data() "import com.nokia.Test 1.0\n" "Test {}" << "TestType"; +} + +void tst_qmlparser::importsLocal() +{ + QFETCH(QString, qml); + QFETCH(QString, type); + testType(qml,type); +} + +void tst_qmlparser::importsInstalled_data() +{ + QTest::addColumn("qml"); + QTest::addColumn("type"); // import installed QTest::newRow("installed import") @@ -636,21 +687,11 @@ void tst_qmlparser::imports_data() << "QFxText"; } -void tst_qmlparser::imports() +void tst_qmlparser::importsInstalled() { QFETCH(QString, qml); QFETCH(QString, type); - - QmlComponent component(&engine, qml.toUtf8(), TEST_FILE("empty.qml")); // just a file for relative local imports - - if (type.isEmpty()) { - QVERIFY(component.isError()); - } else { - VERIFY_ERRORS(0); - QObject *object = component.create(); - QVERIFY(object != 0); - QCOMPARE(QString(object->metaObject()->className()), type); - } + testType(qml,type); } void tst_qmlparser::crash1() -- cgit v0.12