diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-08-19 13:04:05 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-08-19 13:04:05 (GMT) |
commit | e82b5535c170c82d3ba7369eb1957f8d264300e2 (patch) | |
tree | 957159b580b5155b3f6518beedf83333480d80ec /tests | |
parent | 8ae4ad3ac2f47a76be6d0f14f4466070ffcb07a9 (diff) | |
parent | da005580969b2501a246027f47f75ed3ee52670e (diff) | |
download | Qt-e82b5535c170c82d3ba7369eb1957f8d264300e2.zip Qt-e82b5535c170c82d3ba7369eb1957f8d264300e2.tar.gz Qt-e82b5535c170c82d3ba7369eb1957f8d264300e2.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2:
Fixes a regression preventing loading images without extensions
Made GL pixmap backend respect Qt::NoOpaqueDetection flag..
QTextCodec: fix wodring of a comment
QDeclarativeImageProvider: Do not keep the global declarative mutex locked when processing.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp | 105 | ||||
-rw-r--r-- | tests/auto/qpixmap/tst_qpixmap.cpp | 18 |
2 files changed, 110 insertions, 13 deletions
diff --git a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp index e0b46f0..4a9224e 100644 --- a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp +++ b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp @@ -44,6 +44,7 @@ #include <QtDeclarative/qdeclarativeimageprovider.h> #include <private/qdeclarativeimage_p.h> #include <QImageReader> +#include <QWaitCondition> #ifdef Q_OS_SYMBIAN // In Symbian OS test data is located in applications private dir @@ -85,6 +86,8 @@ private slots: void removeProvider_data(); void removeProvider(); + void threadTest(); + private: QString newImageFileName() const; void fillRequestTestsData(const QString &id); @@ -95,9 +98,15 @@ private: class TestQImageProvider : public QDeclarativeImageProvider { public: - TestQImageProvider() - : QDeclarativeImageProvider(Image) + TestQImageProvider(bool *deleteWatch = 0) + : QDeclarativeImageProvider(Image), deleteWatch(deleteWatch) + { + } + + ~TestQImageProvider() { + if (deleteWatch) + *deleteWatch = true; } QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) @@ -114,6 +123,8 @@ public: image = image.scaled(requestedSize); return image; } + + bool *deleteWatch; }; Q_DECLARE_METATYPE(TestQImageProvider*); @@ -121,11 +132,17 @@ Q_DECLARE_METATYPE(TestQImageProvider*); class TestQPixmapProvider : public QDeclarativeImageProvider { public: - TestQPixmapProvider() - : QDeclarativeImageProvider(Pixmap) + TestQPixmapProvider(bool *deleteWatch = 0) + : QDeclarativeImageProvider(Pixmap), deleteWatch(deleteWatch) { } + ~TestQPixmapProvider() + { + if (deleteWatch) + *deleteWatch = true; + } + QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) { if (id == QLatin1String("no-such-file.png")) @@ -140,6 +157,8 @@ public: image = image.scaled(requestedSize); return image; } + + bool *deleteWatch; }; Q_DECLARE_METATYPE(TestQPixmapProvider*); @@ -225,7 +244,9 @@ void tst_qdeclarativeimageprovider::requestImage_sync_data() void tst_qdeclarativeimageprovider::requestImage_sync() { - runTest(false, new TestQImageProvider); + bool deleteWatch = false; + runTest(false, new TestQImageProvider(&deleteWatch)); + QVERIFY(deleteWatch); } void tst_qdeclarativeimageprovider::requestImage_async_data() @@ -235,7 +256,9 @@ void tst_qdeclarativeimageprovider::requestImage_async_data() void tst_qdeclarativeimageprovider::requestImage_async() { - runTest(true, new TestQImageProvider); + bool deleteWatch = false; + runTest(true, new TestQImageProvider(&deleteWatch)); + QVERIFY(deleteWatch); } void tst_qdeclarativeimageprovider::requestPixmap_sync_data() @@ -245,13 +268,15 @@ void tst_qdeclarativeimageprovider::requestPixmap_sync_data() void tst_qdeclarativeimageprovider::requestPixmap_sync() { - runTest(false, new TestQPixmapProvider); + bool deleteWatch = false; + runTest(false, new TestQPixmapProvider(&deleteWatch)); + QVERIFY(deleteWatch); } void tst_qdeclarativeimageprovider::requestPixmap_async() { QDeclarativeEngine engine; - QDeclarativeImageProvider *provider = new TestQPixmapProvider; + QDeclarativeImageProvider *provider = new TestQPixmapProvider(); engine.addImageProvider("test", provider); QVERIFY(engine.imageProvider("test") != 0); @@ -305,6 +330,70 @@ void tst_qdeclarativeimageprovider::removeProvider() delete obj; } +class TestThreadProvider : public QDeclarativeImageProvider +{ + public: + TestThreadProvider() : QDeclarativeImageProvider(Image), ok(false) {} + + ~TestThreadProvider() {} + + QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) + { + mutex.lock(); + if (!ok) + cond.wait(&mutex); + mutex.unlock(); + QVector<int> v; + for (int i = 0; i < 10000; i++) + v.prepend(i); //do some computation + QImage image(50,50, QImage::Format_RGB32); + image.fill(QColor(id).rgb()); + if (size) + *size = image.size(); + if (requestedSize.isValid()) + image = image.scaled(requestedSize); + return image; + } + + QWaitCondition cond; + QMutex mutex; + bool ok; +}; + + +void tst_qdeclarativeimageprovider::threadTest() +{ + QDeclarativeEngine engine; + + TestThreadProvider *provider = new TestThreadProvider; + + engine.addImageProvider("test_thread", provider); + QVERIFY(engine.imageProvider("test_thread") != 0); + + QString componentStr = "import Qt 4.7\nItem { \n" + "Image { source: \"image://test_thread/blue\"; asynchronous: true; }\n" + "Image { source: \"image://test_thread/red\"; asynchronous: true; }\n" + "Image { source: \"image://test_thread/green\"; asynchronous: true; }\n" + "Image { source: \"image://test_thread/yellow\"; asynchronous: true; }\n" + " }"; + QDeclarativeComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QObject *obj = component.create(); + //MUST not deadlock + QVERIFY(obj != 0); + QList<QDeclarativeImage *> images = obj->findChildren<QDeclarativeImage *>(); + QCOMPARE(images.count(), 4); + QTest::qWait(100); + foreach(QDeclarativeImage *img, images) { + QCOMPARE(img->status(), QDeclarativeImage::Loading); + } + provider->ok = true; + provider->cond.wakeAll(); + foreach(QDeclarativeImage *img, images) { + TRY_WAIT(img->status() == QDeclarativeImage::Ready); + } +} + QTEST_MAIN(tst_qdeclarativeimageprovider) diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index f22edf6..e461b64 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -1673,31 +1673,39 @@ void tst_QPixmap::preserveDepth() void tst_QPixmap::loadAsBitmapOrPixmap() { QImage tmp(10, 10, QImage::Format_RGB32); - tmp.save("tmp.png"); + tmp.save("temp_image.png"); bool ok; // Check that we can load the pixmap as a pixmap and that it then turns into a pixmap - QPixmap pixmap("tmp.png"); + QPixmap pixmap("temp_image.png"); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); QVERIFY(!pixmap.isQBitmap()); pixmap = QPixmap(); - ok = pixmap.load("tmp.png"); + ok = pixmap.load("temp_image.png"); + QVERIFY(ok); + QVERIFY(!pixmap.isNull()); + QVERIFY(pixmap.depth() > 1); + QVERIFY(!pixmap.isQBitmap()); + + //now we can try to load it without an extension + pixmap = QPixmap(); + ok = pixmap.load("temp_image"); QVERIFY(ok); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); QVERIFY(!pixmap.isQBitmap()); // The do the same check for bitmaps.. - QBitmap bitmap("tmp.png"); + QBitmap bitmap("temp_image.png"); QVERIFY(!bitmap.isNull()); QVERIFY(bitmap.depth() == 1); QVERIFY(bitmap.isQBitmap()); bitmap = QBitmap(); - ok = bitmap.load("tmp.png"); + ok = bitmap.load("temp_image.png"); QVERIFY(ok); QVERIFY(!bitmap.isNull()); QVERIFY(bitmap.depth() == 1); |