summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp3
-rw-r--r--tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp44
-rw-r--r--tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp46
3 files changed, 77 insertions, 16 deletions
diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index 8c8ab81..16a621a 100644
--- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -1669,6 +1669,9 @@ void tst_QGraphicsAnchorLayout::floatConflict()
void tst_QGraphicsAnchorLayout::infiniteMaxSizes()
{
+ if (sizeof(qreal) <= 4) {
+ QSKIP("qreal has too little precision, result will be wrong", SkipAll);
+ }
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
index e3d1bbe..7880d2d 100644
--- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
+++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
@@ -1525,7 +1525,11 @@ void tst_QGraphicsAnchorLayout1::testMulti_data()
}
- QTest::newRow("Linear multi") << QSizeF(width, height) << theData << theResult;
+ if (sizeof(qreal) == 4) {
+ qDebug("Linear multi: Skipping! (qreal has too little precision, result will be wrong)");
+ } else {
+ QTest::newRow("Linear multi") << QSizeF(width, height) << theData << theResult;
+ }
}
// Multiple widgets, V shape
@@ -1595,7 +1599,11 @@ void tst_QGraphicsAnchorLayout1::testMulti_data()
}
}
- QTest::newRow("V multi") << QSizeF(width, height) << theData << theResult;
+ if (sizeof(qreal) == 4) {
+ qDebug("V multi: Skipping! (qreal has too little precision, result will be wrong)");
+ } else {
+ QTest::newRow("V multi") << QSizeF(width, height) << theData << theResult;
+ }
}
// Multiple widgets, grid
@@ -1653,7 +1661,11 @@ void tst_QGraphicsAnchorLayout1::testMulti_data()
<< BasicResult(i, QRectF(((i%d)+1)*horizontalStep, ((i/d)+1)*verticalStep, horizontalStep, verticalStep) );
}
- QTest::newRow("Grid multi") << QSizeF(200, 100) << theData << theResult;
+ if (sizeof(qreal) == 4) {
+ qDebug("Grid multi: Skipping! (qreal has too little precision, result will be wrong)");
+ } else {
+ QTest::newRow("Grid multi") << QSizeF(200, 100) << theData << theResult;
+ }
}
}
@@ -1669,16 +1681,16 @@ inline QGraphicsLayoutItem *getItem(
return widgets[index];
}
-static QRectF truncate(QRectF original)
+static bool fuzzierCompare(qreal a, qreal b)
{
- QRectF result;
+ return qAbs(a - b) <= qreal(0.0001);
+}
- result.setX(qRound(original.x() * 1000000) / 1000000.0);
- result.setY(qRound(original.y() * 1000000) / 1000000.0);
- result.setWidth(qRound(original.width() * 1000000) / 1000000.0);
- result.setHeight(qRound(original.height() * 1000000) / 1000000.0);
+static bool fuzzierCompare(const QRectF &r1, const QRectF &r2)
+{
- return result;
+ return fuzzierCompare(r1.x(), r2.x()) && fuzzierCompare(r1.y(), r2.y())
+ && fuzzierCompare(r1.width(), r2.width()) && fuzzierCompare(r1.height(), r2.height());
}
void tst_QGraphicsAnchorLayout1::testBasicLayout()
@@ -1727,10 +1739,10 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout()
// Validate
for (int i = 0; i < result.count(); ++i) {
const BasicLayoutTestResult item = result[i];
- QRectF expected = truncate(item.rect);
- QRectF actual = truncate(widgets[item.index]->geometry());
+ QRectF expected = item.rect;
+ QRectF actual = widgets[item.index]->geometry();
- QCOMPARE(actual, expected);
+ QVERIFY(fuzzierCompare(actual, expected));
}
// Test mirrored mode
@@ -1744,10 +1756,10 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout()
if (mirroredRect.isValid()){
mirroredRect.moveLeft(size.width()-item.rect.width()-item.rect.left());
}
- QRectF expected = truncate(mirroredRect);
- QRectF actual = truncate(widgets[item.index]->geometry());
+ QRectF expected = mirroredRect;
+ QRectF actual = widgets[item.index]->geometry();
- QCOMPARE(actual, expected);
+ QVERIFY(fuzzierCompare(actual, expected));
}
qDeleteAll(widgets);
diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
index 95de70e..51e2a57 100644
--- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
+++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
@@ -70,6 +70,7 @@ private slots:
void grayscale();
void colorize();
void drawPixmapItem();
+ void deviceCoordinateTranslateCaching();
};
void tst_QGraphicsEffect::initTestCase()
@@ -514,6 +515,51 @@ void tst_QGraphicsEffect::drawPixmapItem()
QTRY_VERIFY(effect->repaints >= 2);
}
+class DeviceEffect : public QGraphicsEffect
+{
+public:
+ QRectF boundingRectFor(const QRectF &rect) const
+ { return rect; }
+
+ void draw(QPainter *painter)
+ {
+ QPoint offset;
+ QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, QGraphicsEffect::NoPad);
+
+ if (pixmap.isNull())
+ return;
+
+ painter->save();
+ painter->setWorldTransform(QTransform());
+ painter->drawPixmap(offset, pixmap);
+ painter->restore();
+ }
+};
+
+void tst_QGraphicsEffect::deviceCoordinateTranslateCaching()
+{
+ QGraphicsScene scene;
+ CustomItem *item = new CustomItem(0, 0, 10, 10);
+ scene.addItem(item);
+ scene.setSceneRect(0, 0, 50, 0);
+
+ item->setGraphicsEffect(new DeviceEffect);
+ item->setPen(Qt::NoPen);
+ item->setBrush(Qt::red);
+
+ QGraphicsView view(&scene);
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ QTRY_VERIFY(item->numRepaints >= 1);
+ int numRepaints = item->numRepaints;
+
+ item->translate(10, 0);
+ QTest::qWait(50);
+
+ QVERIFY(item->numRepaints == numRepaints);
+}
+
QTEST_MAIN(tst_QGraphicsEffect)
#include "tst_qgraphicseffect.moc"