Fix QQuickImage tiling_QTBUG_6716 and mirror tests.
authorYann Bodson <yann.bodson@nokia.com>
Wed, 2 May 2012 04:29:20 +0000 (14:29 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 2 May 2012 23:20:05 +0000 (01:20 +0200)
QQuickView::grabFrameBuffer doesn't crash on mac anymore.
Also update mirror test to reflect the way we handle tiling now
(centered if no horizontal or vertical alignment set).

Task-number: QTBUG-21688
Change-Id: Ifaa321ac0914840562ee61241c8f30d8fe8e8f04
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
tests/auto/quick/qquickimage/data/mirror.qml
tests/auto/quick/qquickimage/tst_qquickimage.cpp

index 98fddf0..ba23050 100644 (file)
@@ -5,6 +5,7 @@ Rectangle {
     height: 250
     Image {
         objectName: "image"
+        smooth: false
         anchors.fill: parent
         source: "pattern.png"
     }
index be815d8..aa64490 100644 (file)
@@ -282,12 +282,10 @@ void tst_qquickimage::smooth()
 
 void tst_qquickimage::mirror()
 {
-    QSKIP("Test is broken on multiple levels, will need incremental fixes");
-
     QMap<QQuickImage::FillMode, QImage> screenshots;
     QList<QQuickImage::FillMode> fillModes;
     fillModes << QQuickImage::Stretch << QQuickImage::PreserveAspectFit << QQuickImage::PreserveAspectCrop
-              << QQuickImage::Tile << QQuickImage::TileVertically << QQuickImage::TileHorizontally;
+              << QQuickImage::Tile << QQuickImage::TileVertically << QQuickImage::TileHorizontally << QQuickImage::Pad;
 
     qreal width = 300;
     qreal height = 250;
@@ -302,6 +300,8 @@ void tst_qquickimage::mirror()
         obj->setFillMode(fillMode);
         obj->setProperty("mirror", true);
         canvas->show();
+        canvas->requestActivateWindow();
+        QTest::qWaitForWindowShown(canvas);
 
         QImage screenshot = canvas->grabFrameBuffer();
         screenshots[fillMode] = screenshot;
@@ -319,6 +319,8 @@ void tst_qquickimage::mirror()
         transform.translate(width, 0).scale(-1, 1.0);
         p_e.setTransform(transform);
 
+        QPoint offset(width / 2 - srcPixmap.width() / 2, height / 2 - srcPixmap.height() / 2);
+
         switch (fillMode) {
         case QQuickImage::Stretch:
             p_e.drawPixmap(QRect(0, 0, width, height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height()));
@@ -335,24 +337,24 @@ void tst_qquickimage::mirror()
             break;
         }
         case QQuickImage::Tile:
-            p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap);
+            p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap, -offset);
             break;
         case QQuickImage::TileVertically:
             transform.scale(width / srcPixmap.width(), 1.0);
             p_e.setTransform(transform);
-            p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap);
+            p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap, QPoint(0, -offset.y()));
             break;
         case QQuickImage::TileHorizontally:
             transform.scale(1.0, height / srcPixmap.height());
             p_e.setTransform(transform);
-            p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap);
+            p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap, QPoint(-offset.x(), 0));
             break;
         case QQuickImage::Pad:
+            p_e.drawPixmap(offset, srcPixmap);
             break;
         }
 
         QImage img = expected.toImage();
-        QEXPECT_FAIL("", "QTBUG-21005 fails", Continue);
         QCOMPARE(screenshots[fillMode], img);
     }
 }
@@ -467,41 +469,24 @@ void tst_qquickimage::big()
     delete obj;
 }
 
-// As tiling_QTBUG_6716 doesn't complete, it doesn't delete the
-// canvas which causes leak warnings.  Use this delete on stack
-// destruction pattern to work around this.
-template<typename T>
-struct AutoDelete {
-    AutoDelete(T *t) : t(t) {}
-    ~AutoDelete() { delete t; }
-private:
-    T *t;
-};
-
 void tst_qquickimage::tiling_QTBUG_6716()
 {
-    QSKIP("Test is broken on multiple levels, will need incremental fixes");
-
     QFETCH(QString, source);
 
-    QQuickView *canvas = new QQuickView(0);
-    AutoDelete<QQuickView> del(canvas);
-
-    canvas->setSource(testFileUrl(source));
-    canvas->show();
-    qApp->processEvents();
+    QQuickView view(testFileUrl(source));
+    view.show();
+    view.requestActivateWindow();
+    QTest::qWaitForWindowShown(&view);
 
-    QQuickImage *tiling = findItem<QQuickImage>(canvas->rootObject(), "tiling");
+    QQuickImage *tiling = findItem<QQuickImage>(view.rootObject(), "tiling");
 
     QVERIFY(tiling != 0);
-    QImage img = canvas->grabFrameBuffer();
+    QImage img = view.grabFrameBuffer();
     for (int x = 0; x < tiling->width(); ++x) {
         for (int y = 0; y < tiling->height(); ++y) {
             QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0));
         }
     }
-
-    delete canvas;
 }
 
 void tst_qquickimage::tiling_QTBUG_6716_data()