From 4a2529399dc8c6a30677bd7c3ded6b93a6715b51 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 25 Aug 2009 11:27:38 +0200 Subject: Add an autotest to check rendering to a QGLWidget works Reviewed-by: Samuel --- tests/auto/qgl/tst_qgl.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index f92670d..5ed8406 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,7 @@ private slots: void graphicsViewClipping(); void partialGLWidgetUpdates_data(); void partialGLWidgetUpdates(); + void glWidgetRendering(); void colormap(); }; @@ -625,6 +627,50 @@ void tst_QGL::partialGLWidgetUpdates() QCOMPARE(widget.paintEventRegion, QRegion(widget.rect())); } + +class GLWidget : public QGLWidget +{ +public: + GLWidget(QWidget* p = 0) + : QGLWidget(p), beginOk(false), engineType(QPaintEngine::MaxUser) {} + bool beginOk; + QPaintEngine::Type engineType; + void paintGL() + { + QPainter p; + beginOk = p.begin(this); + QPaintEngine* pe = p.paintEngine(); + engineType = pe->type(); + + // This test only ensures it's possible to paint onto a QGLWidget. Full + // paint engine feature testing is way out of scope! + + p.fillRect(0, 0, width(), height(), Qt::red); + // No p.end() or swap buffers, should be done automatically + } + +}; + +void tst_QGL::glWidgetRendering() +{ + GLWidget w; + w.show(); + +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&w); +#endif + QTest::qWait(200); + + QVERIFY(w.beginOk); + QVERIFY(w.engineType == QPaintEngine::OpenGL); + + QImage fb = w.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); + QImage reference(fb.size(), QImage::Format_RGB32); + reference.fill(0xffff0000); + + QCOMPARE(fb, reference); +} + class ColormapExtended : public QGLColormap { public: -- cgit v0.12 From 5daf4391bcf40416c7ea99f8dbbfe28efe1cb19f Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 25 Aug 2009 11:29:24 +0200 Subject: Add an autotest to check reparenting a QGLWidget works If this is broken it will usually seg-fault, but there's a few checks in there just to make sure. Reviewed-by: Samuel --- tests/auto/qgl/tst_qgl.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index 5ed8406..8958530 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -50,6 +50,7 @@ #include #include +#include //TESTED_CLASS= //TESTED_FILES= @@ -69,6 +70,7 @@ private slots: void partialGLWidgetUpdates_data(); void partialGLWidgetUpdates(); void glWidgetRendering(); + void glWidgetReparent(); void colormap(); }; @@ -671,6 +673,72 @@ void tst_QGL::glWidgetRendering() QCOMPARE(fb, reference); } +void tst_QGL::glWidgetReparent() +{ + // Try it as a top-level first: + GLWidget *widget = new GLWidget; + widget->setGeometry(0, 0, 200, 30); + widget->show(); + + QWidget grandParentWidget; + grandParentWidget.setPalette(Qt::blue); + QVBoxLayout grandParentLayout(&grandParentWidget); + + QWidget parentWidget(&grandParentWidget); + grandParentLayout.addWidget(&parentWidget); + parentWidget.setPalette(Qt::green); + parentWidget.setAutoFillBackground(true); + QVBoxLayout parentLayout(&parentWidget); + + grandParentWidget.setGeometry(0, 100, 200, 200); + grandParentWidget.show(); + +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(widget); + qt_x11_wait_for_window_manager(&parentWidget); +#endif + QTest::qWait(2000); + + QVERIFY(parentWidget.children().count() == 1); // The layout + + // Now both widgets should be created & shown, time to re-parent: + parentLayout.addWidget(widget); + +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&parentWidget); +#endif + QTest::qWait(2000); + + QVERIFY(parentWidget.children().count() == 2); // Layout & glwidget + QVERIFY(parentWidget.children().contains(widget)); + QVERIFY(widget->height() > 30); + + delete widget; + +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&parentWidget); +#endif + QTest::qWait(2000); + + QVERIFY(parentWidget.children().count() == 1); // The layout + + // Now do pretty much the same thing, but don't show the + // widget first: + widget = new GLWidget; + parentLayout.addWidget(widget); + +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&parentWidget); +#endif + QTest::qWait(2000); + + QVERIFY(parentWidget.children().count() == 2); // Layout & glwidget + QVERIFY(parentWidget.children().contains(widget)); + QVERIFY(widget->height() > 30); + + delete widget; +} + class ColormapExtended : public QGLColormap { public: -- cgit v0.12