diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-04 07:00:16 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-04 07:00:16 (GMT) |
commit | 7add5c26d7d4bbef452c261d5cbb99ac740724a2 (patch) | |
tree | 255aa453f061321b3946c4accf3114d5f11428ee /tests | |
parent | ec502c9e9a26f984023e4f08126e033a504970b2 (diff) | |
download | Qt-7add5c26d7d4bbef452c261d5cbb99ac740724a2.zip Qt-7add5c26d7d4bbef452c261d5cbb99ac740724a2.tar.gz Qt-7add5c26d7d4bbef452c261d5cbb99ac740724a2.tar.bz2 |
Improve Loader tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qfxloader/SetSourceComponent.qml | 4 | ||||
-rw-r--r-- | tests/auto/declarative/qfxloader/tst_qfxloader.cpp | 68 |
2 files changed, 70 insertions, 2 deletions
diff --git a/tests/auto/declarative/qfxloader/SetSourceComponent.qml b/tests/auto/declarative/qfxloader/SetSourceComponent.qml index c5dd7ff..1db56c4 100644 --- a/tests/auto/declarative/qfxloader/SetSourceComponent.qml +++ b/tests/auto/declarative/qfxloader/SetSourceComponent.qml @@ -1,6 +1,6 @@ import Qt 4.6 Item { - Component { id: Comp; Rectangle { width: 120; height: 60 } } - Loader { sourceComponent: Comp } + Component { id: comp; Rectangle { width: 100; height: 50 } } + Loader { sourceComponent: comp } } diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp index 38d06b8..9a8f8f1 100644 --- a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp +++ b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp @@ -53,6 +53,9 @@ public: private slots: void url(); void component(); + void clear(); + void urlToComponent(); + void componentToUrl(); void sizeLoaderToItem(); void sizeItemToLoader(); void noResize(); @@ -86,6 +89,8 @@ void tst_qfxloader::url() QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + + delete loader; } void tst_qfxloader::component() @@ -99,6 +104,69 @@ void tst_qfxloader::component() QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + + delete loader; +} + +void tst_qfxloader::clear() +{ + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QVERIFY(loader != 0); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + + loader->setSource(QUrl("")); + QVERIFY(loader->item() == 0); + QCOMPARE(loader->progress(), 0.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0); + + delete loader; +} + +void tst_qfxloader::urlToComponent() +{ + QmlComponent component(&engine, QByteArray("import Qt 4.6\n" + "Loader {\n" + " id: loader\n" + " Component { id: myComp; Rectangle { width: 10; height: 10 } }\n" + " source: \"Rect120x60.qml\"\n" + " Timer { interval: 100; running: true; onTriggered: loader.sourceComponent = myComp }\n" + "}" ) + , QUrl("file://" SRCDIR "/")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QTest::qWait(1000); + QVERIFY(loader != 0); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + QCOMPARE(loader->width(), 10.0); + QCOMPARE(loader->height(), 10.0); + + delete loader; +} + +void tst_qfxloader::componentToUrl() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); + QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(component.create()); + QVERIFY(item); + + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(item->QGraphicsObject::children().at(1)); + QVERIFY(loader); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + + loader->setSource(QUrl("file://" SRCDIR "/Rect120x60.qml")); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + QCOMPARE(loader->width(), 120.0); + QCOMPARE(loader->height(), 60.0); + + delete loader; } void tst_qfxloader::sizeLoaderToItem() |