summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp')
-rw-r--r--tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp103
1 files changed, 64 insertions, 39 deletions
diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
index 7cdadb4276..d047a2a0df 100644
--- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
+++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
@@ -50,6 +50,11 @@
#define SERVER_PORT 14450
+#ifdef Q_OS_SYMBIAN
+// In Symbian OS test data is located in applications private dir
+#define SRCDIR "."
+#endif
+
inline QUrl TEST_FILE(const QString &filename)
{
return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
@@ -78,6 +83,7 @@ private slots:
void clear();
void urlToComponent();
void componentToUrl();
+ void anchoredLoader();
void sizeLoaderToItem();
void sizeItemToLoader();
void noResize();
@@ -104,13 +110,14 @@ tst_QDeclarativeLoader::tst_QDeclarativeLoader()
void tst_QDeclarativeLoader::url()
{
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"Rect120x60.qml\" }"), TEST_FILE(""));
+ component.setData(QByteArray("import Qt 4.7\nLoader { property int did_load: 0; onLoaded: did_load=123; source: \"Rect120x60.qml\" }"), TEST_FILE(""));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
QVERIFY(loader->item());
QVERIFY(loader->source() == QUrl::fromLocalFile(SRCDIR "/data/Rect120x60.qml"));
QCOMPARE(loader->progress(), 1.0);
QCOMPARE(loader->status(), QDeclarativeLoader::Ready);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
delete loader;
@@ -265,12 +272,32 @@ void tst_QDeclarativeLoader::componentToUrl()
delete item;
}
+void tst_QDeclarativeLoader::anchoredLoader()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("/AnchoredLoader.qml"));
+ QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(rootItem != 0);
+ QDeclarativeItem *loader = rootItem->findChild<QDeclarativeItem*>("loader");
+ QDeclarativeItem *sourceElement = rootItem->findChild<QDeclarativeItem*>("sourceElement");
+
+ QVERIFY(loader != 0);
+ QVERIFY(sourceElement != 0);
+
+ QCOMPARE(rootItem->width(), 300.0);
+ QCOMPARE(rootItem->height(), 200.0);
+
+ QCOMPARE(loader->width(), 300.0);
+ QCOMPARE(loader->height(), 200.0);
+
+ QCOMPARE(sourceElement->width(), 300.0);
+ QCOMPARE(sourceElement->height(), 200.0);
+}
+
void tst_QDeclarativeLoader::sizeLoaderToItem()
{
QDeclarativeComponent component(&engine, TEST_FILE("/SizeToItem.qml"));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
- QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeLoaderToItem);
QCOMPARE(loader->width(), 120.0);
QCOMPARE(loader->height(), 60.0);
@@ -282,20 +309,28 @@ void tst_QDeclarativeLoader::sizeLoaderToItem()
QCOMPARE(loader->width(), 150.0);
QCOMPARE(loader->height(), 45.0);
+ // Check explicit width
+ loader->setWidth(200.0);
+ QCOMPARE(loader->width(), 200.0);
+ QCOMPARE(rect->width(), 200.0);
+ rect->setWidth(100.0); // when rect changes ...
+ QCOMPARE(rect->width(), 100.0); // ... it changes
+ QCOMPARE(loader->width(), 200.0); // ... but loader stays the same
+
+ // Check explicit height
+ loader->setHeight(200.0);
+ QCOMPARE(loader->height(), 200.0);
+ QCOMPARE(rect->height(), 200.0);
+ rect->setHeight(100.0); // when rect changes ...
+ QCOMPARE(rect->height(), 100.0); // ... it changes
+ QCOMPARE(loader->height(), 200.0); // ... but loader stays the same
+
// Switch mode
- loader->setResizeMode(QDeclarativeLoader::SizeItemToLoader);
loader->setWidth(180);
loader->setHeight(30);
QCOMPARE(rect->width(), 180.0);
QCOMPARE(rect->height(), 30.0);
- // notify
- QSignalSpy spy(loader, SIGNAL(resizeModeChanged()));
- loader->setResizeMode(QDeclarativeLoader::NoResize);
- QCOMPARE(spy.count(),1);
- loader->setResizeMode(QDeclarativeLoader::NoResize);
- QCOMPARE(spy.count(),1);
-
delete loader;
}
@@ -304,7 +339,6 @@ void tst_QDeclarativeLoader::sizeItemToLoader()
QDeclarativeComponent component(&engine, TEST_FILE("/SizeToLoader.qml"));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
- QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeItemToLoader);
QCOMPARE(loader->width(), 200.0);
QCOMPARE(loader->height(), 80.0);
@@ -320,7 +354,8 @@ void tst_QDeclarativeLoader::sizeItemToLoader()
QCOMPARE(rect->height(), 30.0);
// Switch mode
- loader->setResizeMode(QDeclarativeLoader::SizeLoaderToItem);
+ loader->resetWidth(); // reset explicit size
+ loader->resetHeight();
rect->setWidth(160);
rect->setHeight(45);
QCOMPARE(loader->width(), 160.0);
@@ -332,17 +367,12 @@ void tst_QDeclarativeLoader::sizeItemToLoader()
void tst_QDeclarativeLoader::noResize()
{
QDeclarativeComponent component(&engine, TEST_FILE("/NoResize.qml"));
- QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
- QVERIFY(loader != 0);
- QCOMPARE(loader->width(), 200.0);
- QCOMPARE(loader->height(), 80.0);
+ QDeclarativeItem* item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item != 0);
+ QCOMPARE(item->width(), 200.0);
+ QCOMPARE(item->height(), 80.0);
- QDeclarativeItem *rect = qobject_cast<QDeclarativeItem*>(loader->item());
- QVERIFY(rect);
- QCOMPARE(rect->width(), 120.0);
- QCOMPARE(rect->height(), 60.0);
-
- delete loader;
+ delete item;
}
void tst_QDeclarativeLoader::sizeLoaderToGraphicsWidget()
@@ -353,7 +383,6 @@ void tst_QDeclarativeLoader::sizeLoaderToGraphicsWidget()
scene.addItem(loader);
QVERIFY(loader != 0);
- QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeLoaderToItem);
QCOMPARE(loader->width(), 250.0);
QCOMPARE(loader->height(), 250.0);
@@ -365,7 +394,6 @@ void tst_QDeclarativeLoader::sizeLoaderToGraphicsWidget()
QCOMPARE(loader->height(), 45.0);
// Switch mode
- loader->setResizeMode(QDeclarativeLoader::SizeItemToLoader);
loader->setWidth(180);
loader->setHeight(30);
QCOMPARE(widget->size().width(), 180.0);
@@ -382,7 +410,6 @@ void tst_QDeclarativeLoader::sizeGraphicsWidgetToLoader()
scene.addItem(loader);
QVERIFY(loader != 0);
- QVERIFY(loader->resizeMode() == QDeclarativeLoader::SizeItemToLoader);
QCOMPARE(loader->width(), 200.0);
QCOMPARE(loader->height(), 80.0);
@@ -398,7 +425,8 @@ void tst_QDeclarativeLoader::sizeGraphicsWidgetToLoader()
QCOMPARE(widget->size().height(), 30.0);
// Switch mode
- loader->setResizeMode(QDeclarativeLoader::SizeLoaderToItem);
+ loader->resetWidth(); // reset explicit size
+ loader->resetHeight();
widget->resize(QSizeF(160,45));
QCOMPARE(loader->width(), 160.0);
QCOMPARE(loader->height(), 45.0);
@@ -409,20 +437,15 @@ void tst_QDeclarativeLoader::sizeGraphicsWidgetToLoader()
void tst_QDeclarativeLoader::noResizeGraphicsWidget()
{
QDeclarativeComponent component(&engine, TEST_FILE("/NoResizeGraphicsWidget.qml"));
- QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
QGraphicsScene scene;
- scene.addItem(loader);
+ scene.addItem(item);
- QVERIFY(loader != 0);
- QCOMPARE(loader->width(), 200.0);
- QCOMPARE(loader->height(), 80.0);
-
- QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(loader->item());
- QVERIFY(widget);
- QCOMPARE(widget->size().width(), 250.0);
- QCOMPARE(widget->size().height(), 250.0);
+ QVERIFY(item != 0);
+ QCOMPARE(item->width(), 200.0);
+ QCOMPARE(item->height(), 80.0);
- delete loader;
+ delete item;
}
void tst_QDeclarativeLoader::networkRequestUrl()
@@ -432,7 +455,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
server.serveDirectory(SRCDIR "/data");
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"http://127.0.0.1:14450/Rect120x60.qml\" }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
+ component.setData(QByteArray("import Qt 4.7\nLoader { property int did_load : 0; source: \"http://127.0.0.1:14450/Rect120x60.qml\"; onLoaded: did_load=123 }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
if (component.isError())
qDebug() << component.errors();
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
@@ -442,6 +465,7 @@ void tst_QDeclarativeLoader::networkRequestUrl()
QVERIFY(loader->item());
QCOMPARE(loader->progress(), 1.0);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
delete loader;
@@ -488,7 +512,7 @@ void tst_QDeclarativeLoader::failNetworkRequest()
QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Network error for URL http://127.0.0.1:14450/IDontExist.qml");
QDeclarativeComponent component(&engine);
- component.setData(QByteArray("import Qt 4.7\nLoader { source: \"http://127.0.0.1:14450/IDontExist.qml\" }"), QUrl::fromLocalFile("http://127.0.0.1:14450/dummy.qml"));
+ component.setData(QByteArray("import Qt 4.7\nLoader { property int did_load: 123; source: \"http://127.0.0.1:14450/IDontExist.qml\"; onLoaded: did_load=456 }"), QUrl::fromLocalFile("http://127.0.0.1:14450/dummy.qml"));
QDeclarativeLoader *loader = qobject_cast<QDeclarativeLoader*>(component.create());
QVERIFY(loader != 0);
@@ -496,6 +520,7 @@ void tst_QDeclarativeLoader::failNetworkRequest()
QVERIFY(loader->item() == 0);
QCOMPARE(loader->progress(), 0.0);
+ QCOMPARE(loader->property("did_load").toInt(), 123);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
delete loader;