QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquickborderimage / tst_qquickborderimage.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 <QTextDocument>
43 #include <QTcpServer>
44 #include <QTcpSocket>
45 #include <QDir>
46 #include <QPainter>
47 #include <QSignalSpy>
48
49 #include <QtQml/qqmlengine.h>
50 #include <QtQml/qqmlcomponent.h>
51 #include <private/qquickborderimage_p.h>
52 #include <private/qquickimagebase_p.h>
53 #include <private/qquickscalegrid_p_p.h>
54 #include <private/qquickloader_p.h>
55 #include <QtQuick/qquickview.h>
56 #include <QtQml/qqmlcontext.h>
57
58 #include "../../shared/testhttpserver.h"
59 #include "../../shared/util.h"
60
61 #define SERVER_PORT 14446
62 #define SERVER_ADDR "http://127.0.0.1:14446"
63
64 Q_DECLARE_METATYPE(QQuickImageBase::Status)
65
66 class tst_qquickborderimage : public QQmlDataTest
67
68 {
69     Q_OBJECT
70 public:
71     tst_qquickborderimage();
72
73 private slots:
74     void cleanup();
75     void noSource();
76     void imageSource();
77     void imageSource_data();
78     void clearSource();
79     void resized();
80     void smooth();
81     void mirror();
82     void tileModes();
83     void sciSource();
84     void sciSource_data();
85     void invalidSciFile();
86     void validSciFiles_data();
87     void validSciFiles();
88     void pendingRemoteRequest();
89     void pendingRemoteRequest_data();
90     void statusChanges();
91     void statusChanges_data();
92     void sourceSizeChanges();
93     void progressAndStatusChanges();
94
95 private:
96     QQmlEngine engine;
97 };
98
99 void tst_qquickborderimage::cleanup()
100 {
101     QQuickWindow window;
102     window.releaseResources();
103     engine.clearComponentCache();
104 }
105
106 tst_qquickborderimage::tst_qquickborderimage()
107 {
108 }
109
110 void tst_qquickborderimage::noSource()
111 {
112     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"\" }";
113     QQmlComponent component(&engine);
114     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
115     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
116     QVERIFY(obj != 0);
117     QCOMPARE(obj->source(), QUrl());
118     QCOMPARE(obj->width(), 0.);
119     QCOMPARE(obj->height(), 0.);
120     QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Stretch);
121     QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Stretch);
122
123     delete obj;
124 }
125
126 void tst_qquickborderimage::imageSource_data()
127 {
128     QTest::addColumn<QString>("source");
129     QTest::addColumn<bool>("remote");
130     QTest::addColumn<QString>("error");
131
132     QTest::newRow("local") << testFileUrl("colors.png").toString() << false << "";
133     QTest::newRow("local not found") << testFileUrl("no-such-file.png").toString() << false
134         << "file::2:1: QML BorderImage: Cannot open: " + testFileUrl("no-such-file.png").toString();
135     QTest::newRow("remote") << SERVER_ADDR "/colors.png" << true << "";
136     QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << true
137         << "file::2:1: QML BorderImage: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found";
138 }
139
140 void tst_qquickborderimage::imageSource()
141 {
142     QFETCH(QString, source);
143     QFETCH(bool, remote);
144     QFETCH(QString, error);
145
146     TestHTTPServer *server = 0;
147     if (remote) {
148         server = new TestHTTPServer(SERVER_PORT);
149         QVERIFY(server->isValid());
150         server->serveDirectory(dataDirectory());
151     }
152
153     if (!error.isEmpty())
154         QTest::ignoreMessage(QtWarningMsg, error.toUtf8());
155
156     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + source + "\" }";
157     QQmlComponent component(&engine);
158     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
159     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
160     QVERIFY(obj != 0);
161
162     if (remote)
163         QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading);
164
165     QCOMPARE(obj->source(), remote ? source : QUrl(source));
166
167     if (error.isEmpty()) {
168         QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready);
169         QCOMPARE(obj->width(), 120.);
170         QCOMPARE(obj->height(), 120.);
171         QCOMPARE(obj->sourceSize().width(), 120);
172         QCOMPARE(obj->sourceSize().height(), 120);
173         QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Stretch);
174         QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Stretch);
175     } else {
176         QTRY_VERIFY(obj->status() == QQuickBorderImage::Error);
177     }
178
179     delete obj;
180     delete server;
181 }
182
183 void tst_qquickborderimage::clearSource()
184 {
185     QString componentStr = "import QtQuick 2.0\nBorderImage { source: srcImage }";
186     QQmlContext *ctxt = engine.rootContext();
187     ctxt->setContextProperty("srcImage", testFileUrl("colors.png"));
188     QQmlComponent component(&engine);
189     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
190     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
191     QVERIFY(obj != 0);
192     QVERIFY(obj->status() == QQuickBorderImage::Ready);
193     QCOMPARE(obj->width(), 120.);
194     QCOMPARE(obj->height(), 120.);
195
196     ctxt->setContextProperty("srcImage", "");
197     QVERIFY(obj->source().isEmpty());
198     QVERIFY(obj->status() == QQuickBorderImage::Null);
199     QCOMPARE(obj->width(), 0.);
200     QCOMPARE(obj->height(), 0.);
201
202     delete obj;
203 }
204
205 void tst_qquickborderimage::resized()
206 {
207     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + testFileUrl("colors.png").toString() + "\"; width: 300; height: 300 }";
208     QQmlComponent component(&engine);
209     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
210     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
211     QVERIFY(obj != 0);
212     QCOMPARE(obj->width(), 300.);
213     QCOMPARE(obj->height(), 300.);
214     QCOMPARE(obj->sourceSize().width(), 120);
215     QCOMPARE(obj->sourceSize().height(), 120);
216     QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Stretch);
217     QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Stretch);
218
219     delete obj;
220 }
221
222 void tst_qquickborderimage::smooth()
223 {
224     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + testFile("colors.png") + "\"; smooth: true; width: 300; height: 300 }";
225     QQmlComponent component(&engine);
226     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
227     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
228     QVERIFY(obj != 0);
229     QCOMPARE(obj->width(), 300.);
230     QCOMPARE(obj->height(), 300.);
231     QCOMPARE(obj->smooth(), true);
232     QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Stretch);
233     QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Stretch);
234
235     delete obj;
236 }
237
238 void tst_qquickborderimage::mirror()
239 {
240     QQuickView *window = new QQuickView;
241     window->setSource(testFileUrl("mirror.qml"));
242     QQuickBorderImage *image = qobject_cast<QQuickBorderImage*>(window->rootObject());
243     QVERIFY(image != 0);
244
245     QImage screenshot = window->grabWindow();
246
247     QImage srcPixmap(screenshot);
248     QTransform transform;
249     transform.translate(image->width(), 0).scale(-1, 1.0);
250     srcPixmap = srcPixmap.transformed(transform);
251
252     image->setProperty("mirror", true);
253     screenshot = window->grabWindow();
254     QCOMPARE(screenshot, srcPixmap);
255
256     delete window;
257 }
258
259 void tst_qquickborderimage::tileModes()
260 {
261     {
262         QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + testFile("colors.png") + "\"; width: 100; height: 300; horizontalTileMode: BorderImage.Repeat; verticalTileMode: BorderImage.Repeat }";
263         QQmlComponent component(&engine);
264         component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
265         QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
266         QVERIFY(obj != 0);
267         QCOMPARE(obj->width(), 100.);
268         QCOMPARE(obj->height(), 300.);
269         QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Repeat);
270         QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Repeat);
271
272         delete obj;
273     }
274     {
275         QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + testFile("colors.png") + "\"; width: 300; height: 150; horizontalTileMode: BorderImage.Round; verticalTileMode: BorderImage.Round }";
276         QQmlComponent component(&engine);
277         component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
278         QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
279         QVERIFY(obj != 0);
280         QCOMPARE(obj->width(), 300.);
281         QCOMPARE(obj->height(), 150.);
282         QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Round);
283         QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Round);
284
285         delete obj;
286     }
287 }
288
289 void tst_qquickborderimage::sciSource()
290 {
291     QFETCH(QString, source);
292     QFETCH(bool, valid);
293
294     bool remote = source.startsWith("http");
295     TestHTTPServer *server = 0;
296     if (remote) {
297         server = new TestHTTPServer(SERVER_PORT);
298         QVERIFY(server->isValid());
299         server->serveDirectory(dataDirectory());
300     }
301
302     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + source + "\"; width: 300; height: 300 }";
303     QQmlComponent component(&engine);
304     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
305     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
306     QVERIFY(obj != 0);
307
308     if (remote)
309         QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading);
310
311     QCOMPARE(obj->source(), remote ? source : QUrl(source));
312     QCOMPARE(obj->width(), 300.);
313     QCOMPARE(obj->height(), 300.);
314
315     if (valid) {
316         QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready);
317         QCOMPARE(obj->border()->left(), 10);
318         QCOMPARE(obj->border()->top(), 20);
319         QCOMPARE(obj->border()->right(), 30);
320         QCOMPARE(obj->border()->bottom(), 40);
321         QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Round);
322         QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Repeat);
323     } else {
324         QTRY_VERIFY(obj->status() == QQuickBorderImage::Error);
325     }
326
327     delete obj;
328     delete server;
329 }
330
331 void tst_qquickborderimage::sciSource_data()
332 {
333     QTest::addColumn<QString>("source");
334     QTest::addColumn<bool>("valid");
335
336     QTest::newRow("local") << testFileUrl("colors-round.sci").toString() << true;
337     QTest::newRow("local quoted filename") << testFileUrl("colors-round-quotes.sci").toString() << true;
338     QTest::newRow("local not found") << testFileUrl("no-such-file.sci").toString() << false;
339     QTest::newRow("remote") << SERVER_ADDR "/colors-round.sci" << true;
340     QTest::newRow("remote filename quoted") << SERVER_ADDR "/colors-round-quotes.sci" << true;
341     QTest::newRow("remote image") << SERVER_ADDR "/colors-round-remote.sci" << true;
342     QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.sci" << false;
343 }
344
345 void tst_qquickborderimage::invalidSciFile()
346 {
347     QTest::ignoreMessage(QtWarningMsg, "QQuickGridScaledImage: Invalid tile rule specified. Using Stretch."); // for "Roun"
348     QTest::ignoreMessage(QtWarningMsg, "QQuickGridScaledImage: Invalid tile rule specified. Using Stretch."); // for "Repea"
349
350     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + testFileUrl("invalid.sci").toString() +"\"; width: 300; height: 300 }";
351     QQmlComponent component(&engine);
352     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
353     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
354     QVERIFY(obj != 0);
355     QCOMPARE(obj->width(), 300.);
356     QCOMPARE(obj->height(), 300.);
357     QCOMPARE(obj->status(), QQuickImageBase::Error);
358     QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Stretch);
359     QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Stretch);
360
361     delete obj;
362 }
363
364 void tst_qquickborderimage::validSciFiles_data()
365 {
366     QTest::addColumn<QString>("source");
367
368     QTest::newRow("valid1") << testFileUrl("valid1.sci").toString();
369     QTest::newRow("valid2") << testFileUrl("valid2.sci").toString();
370     QTest::newRow("valid3") << testFileUrl("valid3.sci").toString();
371     QTest::newRow("valid4") << testFileUrl("valid4.sci").toString();
372 }
373
374 void tst_qquickborderimage::validSciFiles()
375 {
376     QFETCH(QString, source);
377
378     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + source +"\"; width: 300; height: 300 }";
379     QQmlComponent component(&engine);
380     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
381     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
382     QVERIFY(obj != 0);
383     QCOMPARE(obj->width(), 300.);
384     QCOMPARE(obj->height(), 300.);
385     QCOMPARE(obj->horizontalTileMode(), QQuickBorderImage::Round);
386     QCOMPARE(obj->verticalTileMode(), QQuickBorderImage::Repeat);
387
388     delete obj;
389 }
390
391 void tst_qquickborderimage::pendingRemoteRequest()
392 {
393     QFETCH(QString, source);
394
395     QString componentStr = "import QtQuick 2.0\nBorderImage { source: \"" + source + "\" }";
396     QQmlComponent component(&engine);
397     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
398     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
399     QVERIFY(obj != 0);
400     QCOMPARE(obj->status(), QQuickBorderImage::Loading);
401
402     // verify no crash
403     // This will cause a delayed "QThread: Destroyed while thread is still running" warning
404     delete obj;
405     QTest::qWait(50);
406 }
407
408 void tst_qquickborderimage::pendingRemoteRequest_data()
409 {
410     QTest::addColumn<QString>("source");
411
412     QTest::newRow("png file") << "http://localhost/none.png";
413     QTest::newRow("sci file") << "http://localhost/none.sci";
414 }
415
416 //QTBUG-26155
417 void tst_qquickborderimage::statusChanges_data()
418 {
419     QTest::addColumn<QString>("source");
420     QTest::addColumn<int>("emissions");
421     QTest::addColumn<bool>("remote");
422     QTest::addColumn<QQuickImageBase::Status>("finalStatus");
423
424     QTest::newRow("localfile") << testFileUrl("colors.png").toString() << 1 << false << QQuickImageBase::Ready;
425     QTest::newRow("nofile") << "" << 0 << false << QQuickImageBase::Null;
426     QTest::newRow("nonexistent") << testFileUrl("thisfiledoesnotexist.png").toString() << 1 << false << QQuickImageBase::Error;
427     QTest::newRow("noprotocol") << QString("thisfiledoesnotexisteither.png") << 2 << false << QQuickImageBase::Error;
428     QTest::newRow("remote") << "http://localhost:14446/colors.png" << 2 << true << QQuickImageBase::Ready;
429 }
430
431 void tst_qquickborderimage::statusChanges()
432 {
433     QFETCH(QString, source);
434     QFETCH(int, emissions);
435     QFETCH(bool, remote);
436     QFETCH(QQuickImageBase::Status, finalStatus);
437
438     TestHTTPServer *server = 0;
439     if (remote) {
440         server = new TestHTTPServer(SERVER_PORT);
441         QVERIFY(server->isValid());
442         server->serveDirectory(dataDirectory(), TestHTTPServer::Delay);
443     }
444
445     QString componentStr = "import QtQuick 2.0\nBorderImage { width: 300; height: 300 }";
446     QQmlComponent component(&engine);
447     component.setData(componentStr.toLatin1(), QUrl(""));
448
449     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
450     qRegisterMetaType<QQuickImageBase::Status>();
451     QSignalSpy spy(obj, SIGNAL(statusChanged(QQuickImageBase::Status)));
452     QVERIFY(obj != 0);
453     obj->setSource(source);
454     QTRY_VERIFY(obj->status() == finalStatus);
455     QCOMPARE(spy.count(), emissions);
456
457     delete obj;
458     delete server;
459 }
460
461 void tst_qquickborderimage::sourceSizeChanges()
462 {
463     TestHTTPServer server(14449);
464     QVERIFY(server.isValid());
465     server.serveDirectory(dataDirectory());
466
467     QQmlEngine engine;
468     QQmlComponent component(&engine);
469     component.setData("import QtQuick 2.0\nBorderImage { source: srcImage }", QUrl::fromLocalFile(""));
470     QTRY_VERIFY(component.isReady());
471     QQmlContext *ctxt = engine.rootContext();
472     ctxt->setContextProperty("srcImage", "");
473     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
474     QVERIFY(obj != 0);
475
476     QSignalSpy sourceSizeSpy(obj, SIGNAL(sourceSizeChanged()));
477
478     // Local
479     ctxt->setContextProperty("srcImage", QUrl(""));
480     QTRY_COMPARE(obj->status(), QQuickBorderImage::Null);
481     QTRY_COMPARE(sourceSizeSpy.count(), 0);
482
483     ctxt->setContextProperty("srcImage", testFileUrl("heart200.png"));
484     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
485     QTRY_COMPARE(sourceSizeSpy.count(), 1);
486
487     ctxt->setContextProperty("srcImage", testFileUrl("heart200.png"));
488     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
489     QTRY_COMPARE(sourceSizeSpy.count(), 1);
490
491     ctxt->setContextProperty("srcImage", testFileUrl("heart200_copy.png"));
492     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
493     QTRY_COMPARE(sourceSizeSpy.count(), 1);
494
495     ctxt->setContextProperty("srcImage", testFileUrl("colors.png"));
496     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
497     QTRY_COMPARE(sourceSizeSpy.count(), 2);
498
499     ctxt->setContextProperty("srcImage", QUrl(""));
500     QTRY_COMPARE(obj->status(), QQuickBorderImage::Null);
501     QTRY_COMPARE(sourceSizeSpy.count(), 3);
502
503     // Remote
504     ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200.png"));
505     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
506     QTRY_COMPARE(sourceSizeSpy.count(), 4);
507
508     ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200.png"));
509     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
510     QTRY_COMPARE(sourceSizeSpy.count(), 4);
511
512     ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/heart200_copy.png"));
513     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
514     QTRY_COMPARE(sourceSizeSpy.count(), 4);
515
516     ctxt->setContextProperty("srcImage", QUrl("http://127.0.0.1:14449/colors.png"));
517     QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready);
518     QTRY_COMPARE(sourceSizeSpy.count(), 5);
519
520     ctxt->setContextProperty("srcImage", QUrl(""));
521     QTRY_COMPARE(obj->status(), QQuickBorderImage::Null);
522     QTRY_COMPARE(sourceSizeSpy.count(), 6);
523
524     delete obj;
525 }
526
527 void tst_qquickborderimage::progressAndStatusChanges()
528 {
529     TestHTTPServer server(14449);
530     QVERIFY(server.isValid());
531     server.serveDirectory(dataDirectory());
532
533     QQmlEngine engine;
534     QString componentStr = "import QtQuick 2.0\nBorderImage { source: srcImage }";
535     QQmlContext *ctxt = engine.rootContext();
536     ctxt->setContextProperty("srcImage", testFileUrl("heart200.png"));
537     QQmlComponent component(&engine);
538     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
539     QQuickBorderImage *obj = qobject_cast<QQuickBorderImage*>(component.create());
540     QVERIFY(obj != 0);
541     QVERIFY(obj->status() == QQuickBorderImage::Ready);
542     QTRY_VERIFY(obj->progress() == 1.0);
543
544     qRegisterMetaType<QQuickBorderImage::Status>();
545     QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(const QUrl &)));
546     QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal)));
547     QSignalSpy statusSpy(obj, SIGNAL(statusChanged(QQuickImageBase::Status)));
548
549     // Same file
550     ctxt->setContextProperty("srcImage", testFileUrl("heart200.png"));
551     QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready);
552     QTRY_VERIFY(obj->progress() == 1.0);
553     QTRY_COMPARE(sourceSpy.count(), 0);
554     QTRY_COMPARE(progressSpy.count(), 0);
555     QTRY_COMPARE(statusSpy.count(), 0);
556
557     // Loading local file
558     ctxt->setContextProperty("srcImage", testFileUrl("colors.png"));
559     QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready);
560     QTRY_VERIFY(obj->progress() == 1.0);
561     QTRY_COMPARE(sourceSpy.count(), 1);
562     QTRY_COMPARE(progressSpy.count(), 0);
563     QTRY_COMPARE(statusSpy.count(), 1);
564
565     // Loading remote file
566     ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/heart200.png");
567     QTRY_VERIFY(obj->status() == QQuickBorderImage::Loading);
568     QTRY_VERIFY(obj->progress() == 0.0);
569     QTRY_VERIFY(obj->status() == QQuickBorderImage::Ready);
570     QTRY_VERIFY(obj->progress() == 1.0);
571     QTRY_COMPARE(sourceSpy.count(), 2);
572     QTRY_VERIFY(progressSpy.count() > 1);
573     QTRY_COMPARE(statusSpy.count(), 3);
574
575     ctxt->setContextProperty("srcImage", "");
576     QTRY_VERIFY(obj->status() == QQuickBorderImage::Null);
577     QTRY_VERIFY(obj->progress() == 0.0);
578     QTRY_COMPARE(sourceSpy.count(), 3);
579     QTRY_VERIFY(progressSpy.count() > 2);
580     QTRY_COMPARE(statusSpy.count(), 4);
581
582     delete obj;
583 }
584
585 QTEST_MAIN(tst_qquickborderimage)
586
587 #include "tst_qquickborderimage.moc"