From 690b72b7c3707f3a8f0120c35f3a4c34b58ff596 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 14 Dec 2009 17:33:04 +1000 Subject: Fix image and pixmapcache tests. --- src/declarative/util/qmlpixmapcache.cpp | 4 ++- .../qmlgraphicsimage/tst_qmlgraphicsimage.cpp | 2 +- .../qmlpixmapcache/tst_qmlpixmapcache.cpp | 32 +++++++++++++--------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/declarative/util/qmlpixmapcache.cpp b/src/declarative/util/qmlpixmapcache.cpp index 0115a7c..99bcb7b 100644 --- a/src/declarative/util/qmlpixmapcache.cpp +++ b/src/declarative/util/qmlpixmapcache.cpp @@ -262,6 +262,8 @@ void QmlPixmapReply::networkRequestDone() if (d->reply->error()) { d->pixmap = QPixmap(); d->status = Error; + QPixmapCache::insert(d->urlKey, d->pixmap); + qWarning() << "Network error loading" << d->urlKey << d->reply->errorString(); emit finished(); } else { qmlImageReader()->read(this); @@ -278,11 +280,11 @@ bool QmlPixmapReply::event(QEvent *event) d->status = de->error ? Error : Ready; if (d->status == Ready) { d->pixmap = QPixmap::fromImage(de->image); - QPixmapCache::insert(d->urlKey, d->pixmap); d->image = QImage(); } else { qWarning() << "Error decoding" << d->urlKey; } + QPixmapCache::insert(d->urlKey, d->pixmap); emit finished(); } return true; diff --git a/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp b/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp index c8a2d3f..26f5175 100644 --- a/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp +++ b/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp @@ -118,7 +118,7 @@ void tst_qmlgraphicsimage::imageSource_data() << "Cannot open QUrl( \"file://" SRCDIR "/data/no-such-file.png\" ) "; QTest::newRow("remote") << SERVER_ADDR "/colors.png" << true << ""; QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << true - << "Network error loading QUrl( \"" SERVER_ADDR "/no-such-file.png\" ) " + << "Network error loading \"" SERVER_ADDR "/no-such-file.png\" " "\"Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found\" "; } diff --git a/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp index a26b097..1951833 100644 --- a/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp +++ b/tests/auto/declarative/qmlpixmapcache/tst_qmlpixmapcache.cpp @@ -122,8 +122,8 @@ void tst_qmlpixmapcache::single() QFETCH(bool, neterror); if (neterror) { - QString expected = "Network error loading QUrl( \"" - +target.toString()+"\" ) \"Error downloading " + QString expected = "Network error loading \"" + +target.toString()+"\" \"Error downloading " +target.toString()+" - server replied: Not Found\" "; QTest::ignoreMessage(QtWarningMsg, expected.toLatin1()); } else if (!exists) { @@ -133,15 +133,18 @@ void tst_qmlpixmapcache::single() QPixmap pixmap; QVERIFY(pixmap.width() <= 0); // Check Qt assumption - QNetworkReply *reply= QmlPixmapCache::get(&engine, target, &pixmap); + QmlPixmapReply::Status status = QmlPixmapCache::get(target, &pixmap); if (incache) { - QVERIFY(!reply); - if (exists) + if (exists) { + QVERIFY(status == QmlPixmapReply::Ready); QVERIFY(pixmap.width() > 0); - else + } else { + QVERIFY(status == QmlPixmapReply::Error); QVERIFY(pixmap.width() <= 0); + } } else { + QmlPixmapReply *reply = QmlPixmapCache::request(&engine, target); QVERIFY(reply); QVERIFY(pixmap.width() <= 0); @@ -151,10 +154,10 @@ void tst_qmlpixmapcache::single() QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(getter.gotslot); if (exists) { - QVERIFY(QmlPixmapCache::find(target, &pixmap)); + QVERIFY(QmlPixmapCache::get(target, &pixmap) == QmlPixmapReply::Ready); QVERIFY(pixmap.width() > 0); } else { - QVERIFY(!QmlPixmapCache::find(target, &pixmap)); + QVERIFY(QmlPixmapCache::get(target, &pixmap) == QmlPixmapReply::Error); QVERIFY(pixmap.width() <= 0); } } @@ -225,12 +228,15 @@ void tst_qmlpixmapcache::parallel() QList targets; targets << target1 << target2; - QList replies; + QList replies; QList getters; for (int i=0; i 0); @@ -246,7 +252,7 @@ void tst_qmlpixmapcache::parallel() QCOMPARE(QmlPixmapCache::pendingRequests(), requests); if (cancel >= 0) { - QmlPixmapCache::cancelGet(targets.at(cancel), getters[cancel]); + QmlPixmapCache::cancel(targets.at(cancel), getters[cancel]); slotters--; } @@ -256,14 +262,14 @@ void tst_qmlpixmapcache::parallel() } for (int i=0; igotslot); } else { QVERIFY(getters[i]->gotslot); QPixmap pixmap; - QVERIFY(QmlPixmapCache::find(targets[i], &pixmap)); + QVERIFY(QmlPixmapCache::get(targets[i], &pixmap) == QmlPixmapReply::Ready); QVERIFY(pixmap.width() > 0); } delete getters[i]; -- cgit v0.12