Make QSGImage autotests compile.
authorYann Bodson <yann.bodson@nokia.com>
Tue, 17 May 2011 05:50:03 +0000 (15:50 +1000)
committerYann Bodson <yann.bodson@nokia.com>
Tue, 17 May 2011 05:51:46 +0000 (15:51 +1000)
tests/auto/declarative/qsgborderimage/data/mirror.qml
tests/auto/declarative/qsgimage/data/htiling.qml [new file with mode: 0644]
tests/auto/declarative/qsgimage/data/mirror.qml [new file with mode: 0644]
tests/auto/declarative/qsgimage/data/nullpixmap.qml [new file with mode: 0644]
tests/auto/declarative/qsgimage/data/tiling.qml [deleted file]
tests/auto/declarative/qsgimage/data/vtiling.qml [new file with mode: 0644]
tests/auto/declarative/qsgimage/tst_qsgimage.cpp

diff --git a/tests/auto/declarative/qsgimage/data/htiling.qml b/tests/auto/declarative/qsgimage/data/htiling.qml
new file mode 100644 (file)
index 0000000..f192f93
--- /dev/null
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+
+Rectangle {
+    width: 200; height: 550
+
+    Image {
+        objectName: "tiling"; anchors.fill: parent
+        source: "green.png"; fillMode: Image.TileHorizontally
+    }
+}
+
diff --git a/tests/auto/declarative/qsgimage/data/mirror.qml b/tests/auto/declarative/qsgimage/data/mirror.qml
new file mode 100644 (file)
index 0000000..69bdcb9
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Image {
+    source: "heart200.png"
+}
diff --git a/tests/auto/declarative/qsgimage/data/nullpixmap.qml b/tests/auto/declarative/qsgimage/data/nullpixmap.qml
new file mode 100644 (file)
index 0000000..d52f41f
--- /dev/null
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+Image {
+    width: 10; height:10; fillMode: Image.PreserveAspectFit
+    source: ""
+}
diff --git a/tests/auto/declarative/qsgimage/data/tiling.qml b/tests/auto/declarative/qsgimage/data/tiling.qml
deleted file mode 100644 (file)
index 986b770..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-import QtQuick 2.0
-
-Rectangle {
-    width: 800; height: 600
-
-    Image {
-        objectName: "vTiling"; height: 550; width: 200
-        source: "green.png"; fillMode: Image.TileVertically
-    }
-
-    Image {
-        objectName: "hTiling"; x: 225; height: 250; width: 550
-        source: "green.png"; fillMode: Image.TileHorizontally
-    }
-}
-
diff --git a/tests/auto/declarative/qsgimage/data/vtiling.qml b/tests/auto/declarative/qsgimage/data/vtiling.qml
new file mode 100644 (file)
index 0000000..f730f6e
--- /dev/null
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+
+Rectangle {
+    width: 550; height: 200
+
+    Image {
+        objectName: "tiling"; anchors.fill: parent
+        source: "green.png"; fillMode: Image.TileVertically
+    }
+}
+
index e7366ff..84172c2 100644 (file)
@@ -86,13 +86,12 @@ private slots:
     void geometry_data();
     void big();
     void tiling_QTBUG_6716();
+    void tiling_QTBUG_6716_data();
     void noLoading();
     void paintedWidthHeight();
     void sourceSize_QTBUG_14303();
     void sourceSize_QTBUG_16389();
     void nullPixmapPaint();
-    void testQtQuick11Attributes();
-    void testQtQuick11Attributes_data();
 
 private:
     template<typename T>
@@ -284,12 +283,11 @@ void tst_qsgimage::mirror()
     qreal width = 300;
     qreal height = 250;
 
-    QString src = QUrl::fromLocalFile(SRCDIR "/data/heart200.png").toString();
-    QString componentStr = "import QtQuick 1.1\nImage { source: \"" + src + "\"; }";
+    QSGView *canvas = new QSGView;
+    canvas->show();
+    canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/mirror.qml"));
 
-    QDeclarativeComponent component(&engine);
-    component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
-    QSGImage *obj = qobject_cast<QSGImage*>(component.create());
+    QSGImage *obj = qobject_cast<QSGImage*>(canvas->rootObject());
     QVERIFY(obj != 0);
 
     obj->setProperty("width", width);
@@ -297,12 +295,7 @@ void tst_qsgimage::mirror()
     obj->setFillMode((QSGImage::FillMode)fillMode);
     obj->setProperty("mirror", true);
 
-    QGraphicsScene scene;
-    scene.addItem(qobject_cast<QSGItem *>(obj));
-    QPixmap screenshot(width, height);
-    screenshot.fill();
-    QPainter p_screenshot(&screenshot);
-    scene.render(&p_screenshot, QRect(0, 0, width, height), QRect(0, 0, width, height));
+    QPixmap screenshot = canvas->renderPixmap();
 
     QPixmap srcPixmap;
     QVERIFY(srcPixmap.load(SRCDIR "/data/heart200.png"));
@@ -344,9 +337,10 @@ void tst_qsgimage::mirror()
             break;
     }
 
+    QEXPECT_FAIL("", "QTBUG-19351", Abort);
     QCOMPARE(screenshot, expected);
 
-    delete obj;
+    delete canvas;
 }
 
 void tst_qsgimage::mirror_data()
@@ -369,8 +363,6 @@ void tst_qsgimage::svg()
     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
     QSGImage *obj = qobject_cast<QSGImage*>(component.create());
     QVERIFY(obj != 0);
-    QCOMPARE(obj->pixmap().width(), 300);
-    QCOMPARE(obj->pixmap().height(), 300);
     QCOMPARE(obj->width(), 300.0);
     QCOMPARE(obj->height(), 300.0);
 #if defined(Q_OS_LINUX)
@@ -381,8 +373,6 @@ void tst_qsgimage::svg()
 
     obj->setSourceSize(QSize(200,200));
 
-    QCOMPARE(obj->pixmap().width(), 200);
-    QCOMPARE(obj->pixmap().height(), 200);
     QCOMPARE(obj->width(), 200.0);
     QCOMPARE(obj->height(), 200.0);
 #if defined(Q_OS_LINUX)
@@ -477,57 +467,42 @@ void tst_qsgimage::big()
     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
     QSGImage *obj = qobject_cast<QSGImage*>(component.create());
     QVERIFY(obj != 0);
-    QCOMPARE(obj->pixmap().width(), 256);
-    QCOMPARE(obj->pixmap().height(), 256);
     QCOMPARE(obj->width(), 100.0);
     QCOMPARE(obj->height(), 256.0);
-    QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/big256.png"));
 
     delete obj;
 }
 
 void tst_qsgimage::tiling_QTBUG_6716()
 {
+    QFETCH(QString, source);
+
     QSGView *canvas = new QSGView(0);
-    canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/tiling.qml"));
+    canvas->setSource(QUrl::fromLocalFile(SRCDIR + source));
     canvas->show();
     qApp->processEvents();
 
-    QSGImage *vTiling = findItem<QSGImage>(canvas->rootObject(), "vTiling");
-    QSGImage *hTiling = findItem<QSGImage>(canvas->rootObject(), "hTiling");
-
-    QVERIFY(vTiling != 0);
-    QVERIFY(hTiling != 0);
+    QSGImage *tiling = findItem<QSGImage>(canvas->rootObject(), "tiling");
 
-    {
-        QPixmap pm(vTiling->width(), vTiling->height());
-        QPainter p(&pm);
-        vTiling->paint(&p, 0, 0);
-
-        QImage img = pm.toImage();
-        for (int x = 0; x < vTiling->width(); ++x) {
-            for (int y = 0; y < vTiling->height(); ++y) {
-                QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0));
-            }
+    QVERIFY(tiling != 0);
+    QPixmap pm = canvas->renderPixmap();
+    QImage img = pm.toImage();
+    for (int x = 0; x < tiling->width(); ++x) {
+        for (int y = 0; y < tiling->height(); ++y) {
+            QEXPECT_FAIL("", "QTBUG-19351", Abort);
+            QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0));
         }
     }
-
-    {
-        QPixmap pm(hTiling->width(), hTiling->height());
-        QPainter p(&pm);
-        hTiling->paint(&p, 0, 0);
-
-        QImage img = pm.toImage();
-        for (int x = 0; x < hTiling->width(); ++x) {
-            for (int y = 0; y < hTiling->height(); ++y) {
-                QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0));
-            }
-        }
-    }
-
     delete canvas;
 }
 
+void tst_qsgimage::tiling_QTBUG_6716_data()
+{
+    QTest::addColumn<QString>("source");
+    QTest::newRow("vertical_tiling") << "/data/vtiling.qml";
+    QTest::newRow("horizontal_tiling") << "/data/htiling.qml";
+}
+
 void tst_qsgimage::noLoading()
 {
     TestHTTPServer server(SERVER_PORT);
@@ -588,13 +563,10 @@ void tst_qsgimage::paintedWidthHeight()
         component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
         QSGImage *obj = qobject_cast<QSGImage*>(component.create());
         QVERIFY(obj != 0);
-        QCOMPARE(obj->pixmap().width(), 300);
-        QCOMPARE(obj->pixmap().height(), 300);
         QCOMPARE(obj->width(), 200.0);
         QCOMPARE(obj->height(), 25.0);
         QCOMPARE(obj->paintedWidth(), 25.0);
         QCOMPARE(obj->paintedHeight(), 25.0);
-        QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png"));
 
         delete obj;
     }
@@ -606,13 +578,10 @@ void tst_qsgimage::paintedWidthHeight()
         component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
         QSGImage *obj = qobject_cast<QSGImage*>(component.create());
         QVERIFY(obj != 0);
-        QCOMPARE(obj->pixmap().width(), 300);
-        QCOMPARE(obj->pixmap().height(), 300);
         QCOMPARE(obj->width(), 26.0);
         QCOMPARE(obj->height(), 175.0);
         QCOMPARE(obj->paintedWidth(), 26.0);
         QCOMPARE(obj->paintedHeight(), 26.0);
-        QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png"));
 
         delete obj;
     }
@@ -681,65 +650,24 @@ static void checkWarnings(QtMsgType, const char *)
 // QTBUG-15690
 void tst_qsgimage::nullPixmapPaint()
 {
-    QString componentStr = QString("import QtQuick 1.0\nImage { width: 10; height:10; fillMode: Image.PreserveAspectFit; source: \"")
-            + SERVER_ADDR + QString("/no-such-file.png\" }");
-    QDeclarativeComponent component(&engine);
-    component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
-    QSGImage *image = qobject_cast<QSGImage*>(component.create());
+    QSGView *canvas = new QSGView(0);
+    canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/nullpixmap.qml"));
+    canvas->show();
 
+    QSGImage *image = qobject_cast<QSGImage*>(canvas->rootObject());
     QTRY_VERIFY(image != 0);
-    
-    QtMsgHandler previousMsgHandler = qInstallMsgHandler(checkWarnings);
+    image->setSource(SERVER_ADDR + QString("/no-such-file.png"));
 
-    QPixmap pm(100, 100);
-    QPainter p(&pm);
+    QtMsgHandler previousMsgHandler = qInstallMsgHandler(checkWarnings);
 
     // used to print "QTransform::translate with NaN called"
-    image->paint(&p, 0, 0);
+    QPixmap pm = canvas->renderPixmap();
+
     qInstallMsgHandler(previousMsgHandler);
     QVERIFY(numberOfWarnings == 0);
     delete image;
 }
 
-void tst_qsgimage::testQtQuick11Attributes()
-{
-    QFETCH(QString, code);
-    QFETCH(QString, warning);
-    QFETCH(QString, error);
-
-    QDeclarativeEngine engine;
-    QObject *obj;
-
-    QDeclarativeComponent valid(&engine);
-    valid.setData("import QtQuick 1.1; Image { " + code.toUtf8() + " }", QUrl(""));
-    obj = valid.create();
-    QVERIFY(obj);
-    QVERIFY(valid.errorString().isEmpty());
-    delete obj;
-
-    QDeclarativeComponent invalid(&engine);
-    invalid.setData("import QtQuick 1.0; Image { " + code.toUtf8() + " }", QUrl(""));
-    QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
-    obj = invalid.create();
-    QCOMPARE(invalid.errorString(), error);
-    delete obj;
-}
-
-void tst_qsgimage::testQtQuick11Attributes_data()
-{
-    QTest::addColumn<QString>("code");
-    QTest::addColumn<QString>("warning");
-    QTest::addColumn<QString>("error");
-
-    QTest::newRow("mirror") << "mirror: true"
-        << "QDeclarativeComponent: Component is not ready"
-        << ":1 \"Image.mirror\" is not available in QtQuick 1.0.\n";
-
-    QTest::newRow("cache") << "cache: true"
-        << "QDeclarativeComponent: Component is not ready"
-        << ":1 \"Image.cache\" is not available in QtQuick 1.0.\n";
-}
-
 /*
    Find an item with the specified objectName.  If index is supplied then the
    item must also evaluate the {index} expression equal to index