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