summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2012-07-05 14:52:53 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-06 13:58:34 +0200
commitd13e3441a9a3f11c7f9c9ebb21a514526987f56e (patch)
tree6c2494acd66c2b3598787fd41114b421369b548a /tests/auto/gui
parent16f8afa5b1c906ae60f98619d17c34b40c21804e (diff)
Fix division by zero in triangulating stroker.
Task-number: QTBUG-15621 Change-Id: I10e0e39e57078507a01e1c2edb59fa52fd932f6c Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/qopengl/tst_qopengl.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index 324e1f5d12..a0671be270 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -65,6 +65,7 @@ private slots:
void fboHandleNulledAfterContextDestroyed();
void openGLPaintDevice();
void aboutToBeDestroyed();
+ void QTBUG15621_triangulatingStrokerDivZero();
};
struct SharedResourceTracker
@@ -535,5 +536,79 @@ void tst_QOpenGL::aboutToBeDestroyed()
QCOMPARE(spy.size(), 1);
}
+void tst_QOpenGL::QTBUG15621_triangulatingStrokerDivZero()
+{
+#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__)
+ QSKIP("QTBUG-22617");
+#endif
+
+ QWindow window;
+ window.setSurfaceType(QWindow::OpenGLSurface);
+ window.setGeometry(0, 0, 128, 128);
+ window.create();
+
+ QOpenGLContext ctx;
+ ctx.create();
+ ctx.makeCurrent(&window);
+
+ if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects())
+ QSKIP("QOpenGLFramebufferObject not supported on this platform");
+
+ QOpenGLFramebufferObject fbo(128, 128);
+ fbo.bind();
+
+ QOpenGLPaintDevice device(128, 128);
+
+ // QTBUG-15621 is only a problem when qreal is double, but do the test anyway.
+ qreal delta = sizeof(qreal) == sizeof(float) ? 1e-4 : 1e-8;
+ QVERIFY(128 != 128 + delta);
+
+ QPainterPath path;
+ path.moveTo(16 + delta, 16);
+ path.moveTo(16, 16);
+
+ path.lineTo(16 + delta, 16); // Short lines to check for division by zero.
+ path.lineTo(112 - delta, 16);
+ path.lineTo(112, 16);
+
+ path.quadTo(112, 16, 112, 16 + delta);
+ path.quadTo(112, 64, 112, 112 - delta);
+ path.quadTo(112, 112, 112, 112);
+
+ path.cubicTo(112, 112, 112, 112, 112 - delta, 112);
+ path.cubicTo(80, 112, 48, 112, 16 + delta, 112);
+ path.cubicTo(16 + delta, 112, 16 + delta, 112, 16, 112);
+
+ path.closeSubpath();
+
+ QPen pen(Qt::red, 28, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
+
+ QPainter p(&device);
+ p.fillRect(QRect(0, 0, 128, 128), Qt::blue);
+ p.strokePath(path, pen);
+ p.end();
+ QImage image = fbo.toImage().convertToFormat(QImage::Format_RGB32);
+
+ const QRgb red = 0xffff0000;
+ const QRgb blue = 0xff0000ff;
+
+ QCOMPARE(image.pixel(8, 8), red);
+ QCOMPARE(image.pixel(119, 8), red);
+ QCOMPARE(image.pixel(8, 119), red);
+ QCOMPARE(image.pixel(119, 119), red);
+
+ QCOMPARE(image.pixel(0, 0), blue);
+ QCOMPARE(image.pixel(127, 0), blue);
+ QCOMPARE(image.pixel(0, 127), blue);
+ QCOMPARE(image.pixel(127, 127), blue);
+
+ QCOMPARE(image.pixel(32, 32), blue);
+ QCOMPARE(image.pixel(95, 32), blue);
+ QCOMPARE(image.pixel(32, 95), blue);
+ QCOMPARE(image.pixel(95, 95), blue);
+}
+
+
QTEST_MAIN(tst_QOpenGL)
+
#include "tst_qopengl.moc"