baed4973dcd0c9e6f56d873401df0e419eecaa0e
[profile/ivi/qtdeclarative.git] / tests / auto / qtquick1 / qdeclarativeloader / tst_qdeclarativeloader.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include <qtest.h>
42 #include <QtGui/QGraphicsWidget>
43 #include <QtGui/QGraphicsScene>
44
45 #include <QSignalSpy>
46 #include <QtDeclarative/qdeclarativeengine.h>
47 #include <QtDeclarative/qdeclarativecomponent.h>
48 #include <QtQuick1/private/qdeclarativeloader_p.h>
49 #include "testhttpserver.h"
50 #include "../../../shared/util.h"
51
52 #define SERVER_PORT 14450
53
54 #ifdef Q_OS_SYMBIAN
55 // In Symbian OS test data is located in applications private dir
56 #define SRCDIR "."
57 #endif
58
59 inline QUrl TEST_FILE(const QString &filename)
60 {
61     return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
62 }
63
64 class tst_QDeclarative1Loader : public QObject
65
66 {
67     Q_OBJECT
68 public:
69     tst_QDeclarative1Loader();
70
71 private slots:
72     void sourceOrComponent();
73     void sourceOrComponent_data();
74     void clear();
75     void urlToComponent();
76     void componentToUrl();
77     void anchoredLoader();
78     void sizeLoaderToItem();
79     void sizeItemToLoader();
80     void noResize();
81     void sizeLoaderToGraphicsWidget();
82     void sizeGraphicsWidgetToLoader();
83     void noResizeGraphicsWidget();
84     void networkRequestUrl();
85     void failNetworkRequest();
86 //    void networkComponent();
87
88     void deleteComponentCrash();
89     void nonItem();
90     void vmeErrors();
91     void creationContext();
92     void QTBUG_16928();
93     void implicitSize();
94     void QTBUG_17114();
95
96 private:
97     QDeclarativeEngine engine;
98 };
99
100
101 tst_QDeclarative1Loader::tst_QDeclarative1Loader()
102 {
103 }
104
105 void tst_QDeclarative1Loader::sourceOrComponent()
106 {
107     QFETCH(QString, sourceDefinition);
108     QFETCH(QUrl, sourceUrl);
109     QFETCH(QString, errorString);
110
111     bool error = !errorString.isEmpty();
112     if (error)
113         QTest::ignoreMessage(QtWarningMsg, errorString.toUtf8().constData());
114
115     QDeclarativeComponent component(&engine);
116     component.setData(QByteArray(
117             "import QtQuick 1.0\n"
118             "Loader {\n"
119             "   property int onItemChangedCount: 0\n"
120             "   property int onSourceChangedCount: 0\n"
121             "   property int onStatusChangedCount: 0\n"
122             "   property int onProgressChangedCount: 0\n"
123             "   property int onLoadedCount: 0\n")
124             + sourceDefinition.toUtf8()
125             + QByteArray(
126             "   onItemChanged: onItemChangedCount += 1\n"
127             "   onSourceChanged: onSourceChangedCount += 1\n"
128             "   onStatusChanged: onStatusChangedCount += 1\n"
129             "   onProgressChanged: onProgressChangedCount += 1\n"
130             "   onLoaded: onLoadedCount += 1\n"
131             "}")
132         , TEST_FILE(""));
133
134     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
135     QVERIFY(loader != 0);
136     QCOMPARE(loader->item() == 0, error);
137     QCOMPARE(loader->source(), sourceUrl);
138     QCOMPARE(loader->progress(), 1.0);
139
140     QCOMPARE(loader->status(), error ? QDeclarative1Loader::Error : QDeclarative1Loader::Ready);
141     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), error ? 0: 1);
142
143     if (!error) {
144         QDeclarativeComponent *c = qobject_cast<QDeclarativeComponent*>(loader->QGraphicsObject::children().at(0));
145         QVERIFY(c);
146         QCOMPARE(loader->sourceComponent(), c);
147     }
148
149     QCOMPARE(loader->property("onSourceChangedCount").toInt(), 1);
150     QCOMPARE(loader->property("onStatusChangedCount").toInt(), 1);
151     QCOMPARE(loader->property("onProgressChangedCount").toInt(), 1);
152
153     QCOMPARE(loader->property("onItemChangedCount").toInt(), error ? 0 : 1);
154     QCOMPARE(loader->property("onLoadedCount").toInt(), error ? 0 : 1);
155
156     delete loader;
157 }
158
159 void tst_QDeclarative1Loader::sourceOrComponent_data()
160 {
161     QTest::addColumn<QString>("sourceDefinition");
162     QTest::addColumn<QUrl>("sourceUrl");
163     QTest::addColumn<QString>("errorString");
164
165     QTest::newRow("source") << "source: 'Rect120x60.qml'\n" << QUrl::fromLocalFile(SRCDIR "/data/Rect120x60.qml") << "";
166     QTest::newRow("sourceComponent") << "Component { id: comp; Rectangle { width: 100; height: 50 } }\n sourceComponent: comp\n" << QUrl() << "";
167
168     QTest::newRow("invalid source") << "source: 'IDontExist.qml'\n" << QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml")
169             << QString(QUrl::fromLocalFile(SRCDIR "/data/IDontExist.qml").toString() + ": File not found");
170 }
171
172 void tst_QDeclarative1Loader::clear()
173 {
174     {
175         QDeclarativeComponent component(&engine);
176         component.setData(QByteArray(
177                     "import QtQuick 1.0\n"
178                     " Loader { id: loader\n"
179                     "  source: 'Rect120x60.qml'\n"
180                     "  Timer { interval: 200; running: true; onTriggered: loader.source = '' }\n"
181                     " }")
182                 , TEST_FILE(""));
183         QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
184         QVERIFY(loader != 0);
185         QVERIFY(loader->item());
186         QCOMPARE(loader->progress(), 1.0);
187         QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
188
189         QTRY_VERIFY(loader->item() == 0);
190         QCOMPARE(loader->progress(), 0.0);
191         QCOMPARE(loader->status(), QDeclarative1Loader::Null);
192         QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
193
194         delete loader;
195     }
196     {
197         QDeclarativeComponent component(&engine, TEST_FILE("/SetSourceComponent.qml"));
198         QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
199         QVERIFY(item);
200
201         QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(item->QGraphicsObject::children().at(1)); 
202         QVERIFY(loader);
203         QVERIFY(loader->item());
204         QCOMPARE(loader->progress(), 1.0);
205         QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
206
207         loader->setSourceComponent(0);
208
209         QVERIFY(loader->item() == 0);
210         QCOMPARE(loader->progress(), 0.0);
211         QCOMPARE(loader->status(), QDeclarative1Loader::Null);
212         QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
213
214         delete item;
215     }
216     {
217         QDeclarativeComponent component(&engine, TEST_FILE("/SetSourceComponent.qml"));
218         QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
219         QVERIFY(item);
220
221         QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(item->QGraphicsObject::children().at(1)); 
222         QVERIFY(loader);
223         QVERIFY(loader->item());
224         QCOMPARE(loader->progress(), 1.0);
225         QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
226
227         QMetaObject::invokeMethod(item, "clear");
228
229         QVERIFY(loader->item() == 0);
230         QCOMPARE(loader->progress(), 0.0);
231         QCOMPARE(loader->status(), QDeclarative1Loader::Null);
232         QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
233
234         delete item;
235     }
236 }
237
238 void tst_QDeclarative1Loader::urlToComponent()
239 {
240     QDeclarativeComponent component(&engine);
241     component.setData(QByteArray("import QtQuick 1.0\n"
242                 "Loader {\n"
243                 " id: loader\n"
244                 " Component { id: myComp; Rectangle { width: 10; height: 10 } }\n"
245                 " source: \"Rect120x60.qml\"\n"
246                 " Timer { interval: 100; running: true; onTriggered: loader.sourceComponent = myComp }\n"
247                 "}" )
248             , TEST_FILE(""));
249     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
250     QTest::qWait(200);
251     QTRY_VERIFY(loader != 0);
252     QVERIFY(loader->item());
253     QCOMPARE(loader->progress(), 1.0);
254     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
255     QCOMPARE(loader->width(), 10.0);
256     QCOMPARE(loader->height(), 10.0);
257
258     delete loader;
259 }
260
261 void tst_QDeclarative1Loader::componentToUrl()
262 {
263     QDeclarativeComponent component(&engine, TEST_FILE("/SetSourceComponent.qml"));
264     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
265     QVERIFY(item);
266
267     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(item->QGraphicsObject::children().at(1)); 
268     QVERIFY(loader);
269     QVERIFY(loader->item());
270     QCOMPARE(loader->progress(), 1.0);
271     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
272
273     loader->setSource(TEST_FILE("/Rect120x60.qml"));
274     QVERIFY(loader->item());
275     QCOMPARE(loader->progress(), 1.0);
276     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
277     QCOMPARE(loader->width(), 120.0);
278     QCOMPARE(loader->height(), 60.0);
279
280     delete item;
281 }
282
283 void tst_QDeclarative1Loader::anchoredLoader()
284 {
285     QDeclarativeComponent component(&engine, TEST_FILE("/AnchoredLoader.qml"));
286     QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(component.create());
287     QVERIFY(rootItem != 0);
288     QDeclarativeItem *loader = rootItem->findChild<QDeclarativeItem*>("loader");
289     QDeclarativeItem *sourceElement = rootItem->findChild<QDeclarativeItem*>("sourceElement");
290
291     QVERIFY(loader != 0);
292     QVERIFY(sourceElement != 0);
293
294     QCOMPARE(rootItem->width(), 300.0);
295     QCOMPARE(rootItem->height(), 200.0);
296
297     QCOMPARE(loader->width(), 300.0);
298     QCOMPARE(loader->height(), 200.0);
299
300     QCOMPARE(sourceElement->width(), 300.0);
301     QCOMPARE(sourceElement->height(), 200.0);
302 }
303
304 void tst_QDeclarative1Loader::sizeLoaderToItem()
305 {
306     QDeclarativeComponent component(&engine, TEST_FILE("/SizeToItem.qml"));
307     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
308     QVERIFY(loader != 0);
309     QCOMPARE(loader->width(), 120.0);
310     QCOMPARE(loader->height(), 60.0);
311
312     // Check resize
313     QDeclarativeItem *rect = qobject_cast<QDeclarativeItem*>(loader->item());
314     QVERIFY(rect);
315     rect->setWidth(150);
316     rect->setHeight(45);
317     QCOMPARE(loader->width(), 150.0);
318     QCOMPARE(loader->height(), 45.0);
319
320     // Check explicit width
321     loader->setWidth(200.0);
322     QCOMPARE(loader->width(), 200.0);
323     QCOMPARE(rect->width(), 200.0);
324     rect->setWidth(100.0); // when rect changes ...
325     QCOMPARE(rect->width(), 100.0); // ... it changes
326     QCOMPARE(loader->width(), 200.0); // ... but loader stays the same
327
328     // Check explicit height
329     loader->setHeight(200.0);
330     QCOMPARE(loader->height(), 200.0);
331     QCOMPARE(rect->height(), 200.0);
332     rect->setHeight(100.0); // when rect changes ...
333     QCOMPARE(rect->height(), 100.0); // ... it changes
334     QCOMPARE(loader->height(), 200.0); // ... but loader stays the same
335
336     // Switch mode
337     loader->setWidth(180);
338     loader->setHeight(30);
339     QCOMPARE(rect->width(), 180.0);
340     QCOMPARE(rect->height(), 30.0);
341
342     delete loader;
343 }
344
345 void tst_QDeclarative1Loader::sizeItemToLoader()
346 {
347     QDeclarativeComponent component(&engine, TEST_FILE("/SizeToLoader.qml"));
348     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
349     QVERIFY(loader != 0);
350     QCOMPARE(loader->width(), 200.0);
351     QCOMPARE(loader->height(), 80.0);
352
353     QDeclarativeItem *rect = qobject_cast<QDeclarativeItem*>(loader->item());
354     QVERIFY(rect);
355     QCOMPARE(rect->width(), 200.0);
356     QCOMPARE(rect->height(), 80.0);
357
358     // Check resize
359     loader->setWidth(180);
360     loader->setHeight(30);
361     QCOMPARE(rect->width(), 180.0);
362     QCOMPARE(rect->height(), 30.0);
363
364     // Switch mode
365     loader->resetWidth(); // reset explicit size
366     loader->resetHeight();
367     rect->setWidth(160);
368     rect->setHeight(45);
369     QCOMPARE(loader->width(), 160.0);
370     QCOMPARE(loader->height(), 45.0);
371
372     delete loader;
373 }
374
375 void tst_QDeclarative1Loader::noResize()
376 {
377     QDeclarativeComponent component(&engine, TEST_FILE("/NoResize.qml"));
378     QDeclarativeItem* item = qobject_cast<QDeclarativeItem*>(component.create());
379     QVERIFY(item != 0);
380     QCOMPARE(item->width(), 200.0);
381     QCOMPARE(item->height(), 80.0);
382
383     delete item;
384 }
385
386 void tst_QDeclarative1Loader::sizeLoaderToGraphicsWidget()
387 {
388     QDeclarativeComponent component(&engine, TEST_FILE("/SizeLoaderToGraphicsWidget.qml"));
389     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
390     QGraphicsScene scene;
391     scene.addItem(loader);
392
393     QVERIFY(loader != 0);
394     QCOMPARE(loader->width(), 250.0);
395     QCOMPARE(loader->height(), 250.0);
396
397     // Check resize
398     QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(loader->item());
399     QVERIFY(widget);
400     widget->resize(QSizeF(150,45));
401     QCOMPARE(loader->width(), 150.0);
402     QCOMPARE(loader->height(), 45.0);
403
404     // Switch mode
405     loader->setWidth(180);
406     loader->setHeight(30);
407     QCOMPARE(widget->size().width(), 180.0);
408     QCOMPARE(widget->size().height(), 30.0);
409
410     delete loader;
411 }
412
413 void tst_QDeclarative1Loader::sizeGraphicsWidgetToLoader()
414 {
415     QDeclarativeComponent component(&engine, TEST_FILE("/SizeGraphicsWidgetToLoader.qml"));
416     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
417     QGraphicsScene scene;
418     scene.addItem(loader);
419
420     QVERIFY(loader != 0);
421     QCOMPARE(loader->width(), 200.0);
422     QCOMPARE(loader->height(), 80.0);
423
424     QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(loader->item());
425     QVERIFY(widget);
426     QCOMPARE(widget->size().width(), 200.0);
427     QCOMPARE(widget->size().height(), 80.0);
428
429     // Check resize
430     loader->setWidth(180);
431     loader->setHeight(30);
432     QCOMPARE(widget->size().width(), 180.0);
433     QCOMPARE(widget->size().height(), 30.0);
434
435     // Switch mode
436     loader->resetWidth(); // reset explicit size
437     loader->resetHeight();
438     widget->resize(QSizeF(160,45));
439     QCOMPARE(loader->width(), 160.0);
440     QCOMPARE(loader->height(), 45.0);
441
442     delete loader;
443 }
444
445 void tst_QDeclarative1Loader::noResizeGraphicsWidget()
446 {
447     QDeclarativeComponent component(&engine, TEST_FILE("/NoResizeGraphicsWidget.qml"));
448     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
449     QGraphicsScene scene;
450     scene.addItem(item);
451
452     QVERIFY(item != 0);
453     QCOMPARE(item->width(), 200.0);
454     QCOMPARE(item->height(), 80.0);
455
456     delete item;
457 }
458
459 void tst_QDeclarative1Loader::networkRequestUrl()
460 {
461     TestHTTPServer server(SERVER_PORT);
462     QVERIFY(server.isValid());
463     server.serveDirectory(SRCDIR "/data");
464
465     QDeclarativeComponent component(&engine);
466     component.setData(QByteArray("import QtQuick 1.0\nLoader { property int signalCount : 0; source: \"http://127.0.0.1:14450/Rect120x60.qml\"; onLoaded: signalCount += 1 }"), QUrl::fromLocalFile(SRCDIR "/dummy.qml"));
467     if (component.isError())
468         qDebug() << component.errors();
469     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
470     QVERIFY(loader != 0);
471
472     QTRY_VERIFY(loader->status() == QDeclarative1Loader::Ready);
473
474     QVERIFY(loader->item());
475     QCOMPARE(loader->progress(), 1.0);
476     QCOMPARE(loader->property("signalCount").toInt(), 1);
477     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
478
479     delete loader;
480 }
481
482 /* XXX Component waits until all dependencies are loaded.  Is this actually possible?
483 void tst_QDeclarative1Loader::networkComponent()
484 {
485     TestHTTPServer server(SERVER_PORT);
486     QVERIFY(server.isValid());
487     server.serveDirectory("slowdata", TestHTTPServer::Delay);
488
489     QDeclarativeComponent component(&engine);
490     component.setData(QByteArray(
491                 "import QtQuick 1.0\n"
492                 "import \"http://127.0.0.1:14450/\" as NW\n"
493                 "Item {\n"
494                 " Component { id: comp; NW.SlowRect {} }\n"
495                 " Loader { sourceComponent: comp } }")
496             , TEST_FILE(""));
497
498     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
499     QVERIFY(item);
500
501     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(item->QGraphicsObject::children().at(1)); 
502     QVERIFY(loader);
503     QTRY_VERIFY(loader->status() == QDeclarative1Loader::Ready);
504
505     QVERIFY(loader->item());
506     QCOMPARE(loader->progress(), 1.0);
507     QCOMPARE(loader->status(), QDeclarative1Loader::Ready);
508     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
509
510     delete loader;
511 }
512 */
513
514 void tst_QDeclarative1Loader::failNetworkRequest()
515 {
516     TestHTTPServer server(SERVER_PORT);
517     QVERIFY(server.isValid());
518     server.serveDirectory(SRCDIR "/data");
519
520     QTest::ignoreMessage(QtWarningMsg, "http://127.0.0.1:14450/IDontExist.qml: File not found");
521
522     QDeclarativeComponent component(&engine);
523     component.setData(QByteArray("import QtQuick 1.0\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"));
524     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
525     QVERIFY(loader != 0);
526
527     QTRY_VERIFY(loader->status() == QDeclarative1Loader::Error);
528
529     QVERIFY(loader->item() == 0);
530     QCOMPARE(loader->progress(), 0.0);
531     QCOMPARE(loader->property("did_load").toInt(), 123);
532     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0);
533
534     delete loader;
535 }
536
537 // QTBUG-9241
538 void tst_QDeclarative1Loader::deleteComponentCrash()
539 {
540     QDeclarativeComponent component(&engine, TEST_FILE("crash.qml"));
541     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
542     QVERIFY(item);
543
544     item->metaObject()->invokeMethod(item, "setLoaderSource");
545
546     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(item->QGraphicsObject::children().at(0));
547     QVERIFY(loader);
548     QVERIFY(loader->item());
549     QCOMPARE(loader->item()->objectName(), QLatin1String("blue"));
550     QCOMPARE(loader->progress(), 1.0);
551     QCOMPARE(loader->status(), QDeclarative1Loader::Ready);
552     QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
553     QVERIFY(loader->source() == QUrl::fromLocalFile(SRCDIR "/data/BlueRect.qml"));
554
555     delete item;
556 }
557
558 void tst_QDeclarative1Loader::nonItem()
559 {
560     QDeclarativeComponent component(&engine, TEST_FILE("nonItem.qml"));
561     QString err = QUrl::fromLocalFile(SRCDIR).toString() + "/data/nonItem.qml:3:1: QML Loader: Loader does not support loading non-visual elements.";
562
563     QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData());
564     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
565     QVERIFY(loader);
566     QVERIFY(loader->item() == 0);
567
568     delete loader;
569 }
570
571 void tst_QDeclarative1Loader::vmeErrors()
572 {
573     QDeclarativeComponent component(&engine, TEST_FILE("vmeErrors.qml"));
574     QString err = QUrl::fromLocalFile(SRCDIR).toString() + "/data/VmeError.qml:6: Cannot assign object type QObject with no default method";
575     QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData());
576     QDeclarative1Loader *loader = qobject_cast<QDeclarative1Loader*>(component.create());
577     QVERIFY(loader);
578     QVERIFY(loader->item() == 0);
579
580     delete loader;
581 }
582
583 // QTBUG-13481
584 void tst_QDeclarative1Loader::creationContext()
585 {
586     QDeclarativeComponent component(&engine, TEST_FILE("creationContext.qml"));
587
588     QObject *o = component.create();
589     QVERIFY(o != 0);
590
591     QCOMPARE(o->property("test").toBool(), true);
592
593     delete o;
594 }
595
596 void tst_QDeclarative1Loader::QTBUG_16928()
597 {
598     QDeclarativeComponent component(&engine, TEST_FILE("QTBUG_16928.qml"));
599     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
600     QVERIFY(item);
601
602     QCOMPARE(item->width(), 250.);
603     QCOMPARE(item->height(), 250.);
604
605     delete item;
606 }
607
608 void tst_QDeclarative1Loader::implicitSize()
609 {
610     QDeclarativeComponent component(&engine, TEST_FILE("implicitSize.qml"));
611     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
612     QVERIFY(item);
613
614     QCOMPARE(item->width(), 150.);
615     QCOMPARE(item->height(), 150.);
616
617     QCOMPARE(item->property("implHeight").toReal(), 100.);
618     QCOMPARE(item->property("implWidth").toReal(), 100.);
619
620     delete item;
621 }
622
623 void tst_QDeclarative1Loader::QTBUG_17114()
624 {
625     QDeclarativeComponent component(&engine, TEST_FILE("QTBUG_17114.qml"));
626     QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(component.create());
627     QVERIFY(item);
628
629     QCOMPARE(item->property("loaderWidth").toReal(), 32.);
630     QCOMPARE(item->property("loaderHeight").toReal(), 32.);
631
632     delete item;
633 }
634
635 QTEST_MAIN(tst_QDeclarative1Loader)
636
637 #include "tst_qdeclarativeloader.moc"