From 6b3f959cb3170561276e86b3abbf8ed69ec38c71 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 6 Jul 2011 13:39:23 +1000 Subject: Fix QSGImage autotests Change-Id: I05b7bd4ad98c952ef4d536b987e6afd589a729fb Reviewed-on: http://codereview.qt.nokia.com/1194 Reviewed-by: Qt Sanity Bot Reviewed-by: Yann Bodson --- tests/auto/declarative/qsgimage/data/mirror.qml | 2 +- tests/auto/declarative/qsgimage/data/pattern.png | Bin 0 -> 1371 bytes tests/auto/declarative/qsgimage/tst_qsgimage.cpp | 73 ++++++++++------------- 3 files changed, 33 insertions(+), 42 deletions(-) create mode 100644 tests/auto/declarative/qsgimage/data/pattern.png (limited to 'tests') diff --git a/tests/auto/declarative/qsgimage/data/mirror.qml b/tests/auto/declarative/qsgimage/data/mirror.qml index 101a3a28ce..98fddf083e 100644 --- a/tests/auto/declarative/qsgimage/data/mirror.qml +++ b/tests/auto/declarative/qsgimage/data/mirror.qml @@ -6,6 +6,6 @@ Rectangle { Image { objectName: "image" anchors.fill: parent - source: "heart200.png" + source: "pattern.png" } } diff --git a/tests/auto/declarative/qsgimage/data/pattern.png b/tests/auto/declarative/qsgimage/data/pattern.png new file mode 100644 index 0000000000..d3d5e1e007 Binary files /dev/null and b/tests/auto/declarative/qsgimage/data/pattern.png differ diff --git a/tests/auto/declarative/qsgimage/tst_qsgimage.cpp b/tests/auto/declarative/qsgimage/tst_qsgimage.cpp index 3f5f6a1a97..63c58eb286 100644 --- a/tests/auto/declarative/qsgimage/tst_qsgimage.cpp +++ b/tests/auto/declarative/qsgimage/tst_qsgimage.cpp @@ -80,7 +80,6 @@ private slots: void preserveAspectRatio(); void smooth(); void mirror(); - void mirror_data(); void svg(); void geometry(); void geometry_data(); @@ -278,40 +277,47 @@ void tst_qsgimage::smooth() void tst_qsgimage::mirror() { - QFETCH(int, fillMode); + QMap screenshots; + QList fillModes; + fillModes << QSGImage::Stretch << QSGImage::PreserveAspectFit << QSGImage::PreserveAspectCrop + << QSGImage::Tile << QSGImage::TileVertically << QSGImage::TileHorizontally; qreal width = 300; qreal height = 250; - QSGView *canvas = new QSGView; - canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/mirror.qml")); + foreach (QSGImage::FillMode fillMode, fillModes) { + QSGView *canvas = new QSGView; + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/mirror.qml")); - QSGImage *obj = canvas->rootObject()->findChild("image"); - QVERIFY(obj != 0); - - obj->setFillMode((QSGImage::FillMode)fillMode); - obj->setProperty("mirror", true); + QSGImage *obj = canvas->rootObject()->findChild("image"); + QVERIFY(obj != 0); - canvas->show(); + obj->setFillMode(fillMode); + obj->setProperty("mirror", true); + canvas->show(); - QPixmap screenshot = canvas->renderPixmap(); + QImage screenshot = canvas->grabFrameBuffer(); + screenshots[fillMode] = screenshot; + delete canvas; + } - QPixmap srcPixmap; - QVERIFY(srcPixmap.load(SRCDIR "/data/heart200.png")); + foreach (QSGImage::FillMode fillMode, fillModes) { + QPixmap srcPixmap; + QVERIFY(srcPixmap.load(SRCDIR "/data/pattern.png")); - QPixmap expected(width, height); - expected.fill(); - QPainter p_e(&expected); - QTransform transform; - transform.translate(width, 0).scale(-1, 1.0); - p_e.setTransform(transform); + QPixmap expected(width, height); + expected.fill(); + QPainter p_e(&expected); + QTransform transform; + transform.translate(width, 0).scale(-1, 1.0); + p_e.setTransform(transform); - switch (fillMode) { + switch (fillMode) { case QSGImage::Stretch: p_e.drawPixmap(QRect(0, 0, width, height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height())); break; case QSGImage::PreserveAspectFit: - p_e.drawPixmap(QRect(25, 0, width / (width/height), height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height())); + p_e.drawPixmap(QRect(25, 0, height, height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height())); break; case QSGImage::PreserveAspectCrop: { @@ -334,24 +340,11 @@ void tst_qsgimage::mirror() p_e.setTransform(transform); p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap); break; - } - - QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved", SkipSingle); - QCOMPARE(screenshot, expected); - - delete canvas; -} + } -void tst_qsgimage::mirror_data() -{ - QTest::addColumn("fillMode"); - - QTest::newRow("Stretch") << int(QSGImage::Stretch); - QTest::newRow("PreserveAspectFit") << int(QSGImage::PreserveAspectFit); - QTest::newRow("PreserveAspectCrop") << int(QSGImage::PreserveAspectCrop); - QTest::newRow("Tile") << int(QSGImage::Tile); - QTest::newRow("TileVertically") << int(QSGImage::TileVertically); - QTest::newRow("TileHorizontally") << int(QSGImage::TileHorizontally); + QImage img = expected.toImage(); + QCOMPARE(screenshots[fillMode], img); + } } void tst_qsgimage::svg() @@ -473,11 +466,9 @@ void tst_qsgimage::tiling_QTBUG_6716() QSGImage *tiling = findItem(canvas->rootObject(), "tiling"); QVERIFY(tiling != 0); - QPixmap pm = canvas->renderPixmap(); - QImage img = pm.toImage(); + QImage img = canvas->grabFrameBuffer(); 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)); } } -- cgit v1.2.3