summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstatictext
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-05 16:07:21 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-02-05 16:07:21 (GMT)
commitf85b35d5b8a005e2d7128c203f7402750b94e1da (patch)
tree5ffdfa368ca52a6ffa2d02350e6a6af81a9e3207 /tests/auto/qstatictext
parent3d89703be18d13cc4a571ce875cff3ec6cca498f (diff)
downloadQt-f85b35d5b8a005e2d7128c203f7402750b94e1da.zip
Qt-f85b35d5b8a005e2d7128c203f7402750b94e1da.tar.gz
Qt-f85b35d5b8a005e2d7128c203f7402750b94e1da.tar.bz2
Add tests for using QStaticText with a QGLWidget
Some tests with and without VBO caching.
Diffstat (limited to 'tests/auto/qstatictext')
-rw-r--r--tests/auto/qstatictext/qstatictext.pro2
-rw-r--r--tests/auto/qstatictext/tst_qstatictext.cpp211
2 files changed, 212 insertions, 1 deletions
diff --git a/tests/auto/qstatictext/qstatictext.pro b/tests/auto/qstatictext/qstatictext.pro
index 0f1ca68..a759a90 100644
--- a/tests/auto/qstatictext/qstatictext.pro
+++ b/tests/auto/qstatictext/qstatictext.pro
@@ -1,4 +1,4 @@
load(qttest_p4)
-QT = core gui
+QT = core gui opengl
SOURCES += tst_qstatictext.cpp
diff --git a/tests/auto/qstatictext/tst_qstatictext.cpp b/tests/auto/qstatictext/tst_qstatictext.cpp
index 9e6f3d6..9e4b540 100644
--- a/tests/auto/qstatictext/tst_qstatictext.cpp
+++ b/tests/auto/qstatictext/tst_qstatictext.cpp
@@ -44,6 +44,8 @@
#include <QtGui/QPainter>
#include <QtGui/QImage>
+#include <QtOpenGl/QGLWidget>
+
#include <private/qstatictext_p.h>
#include <private/qstatictext_p_p.h>
#include <private/qpainter_p.h>
@@ -73,6 +75,11 @@ private slots:
void projectedPainter();
void rotatedScaledAndTranslatedPainter();
void transformationChanged();
+
+ void drawToGLWidget();
+ void drawToGLWidgetRepeated();
+ void drawToGLWidgetWithCaching();
+ void drawToGLWidgetWithCachingRepeated();
};
void tst_QStaticText::init()
@@ -430,5 +437,209 @@ void tst_QStaticText::transformationChanged()
QCOMPARE(imageDrawStaticText, imageDrawText);
}
+class MyGLWidget: public QGLWidget
+{
+public:
+ enum PaintEventType {
+ NormalDrawText,
+ NormalDrawStaticText,
+ DrawStaticTextWithCaching
+ };
+
+ MyGLWidget(PaintEventType paintEventType, QWidget *parent = 0)
+ : QGLWidget(parent), m_paintEventType(paintEventType)
+ {
+ m_staticText.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
+ if (m_paintEventType == DrawStaticTextWithCaching)
+ m_staticText.setUseBackendOptimizations(true);
+ shown = false;
+ }
+
+ void paintEvent(QPaintEvent *)
+ {
+ QPainter painter(this);
+ painter.fillRect(rect(), Qt::white);
+ switch (m_paintEventType) {
+ case NormalDrawStaticText:
+ case DrawStaticTextWithCaching:
+ qt_draw_static_text(&painter, QPointF(11, 12), m_staticText);
+ break;
+ case NormalDrawText:
+ painter.drawText(11, 12, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
+ break;
+ };
+ shown = true;
+ }
+
+ bool shown;
+
+private:
+ QStaticText m_staticText;
+ PaintEventType m_paintEventType;
+};
+
+void tst_QStaticText::drawToGLWidget()
+{
+ QImage imageDrawText;
+ {
+ MyGLWidget glWidget(MyGLWidget::NormalDrawText);
+ glWidget.show();
+ while (!glWidget.shown)
+ QApplication::processEvents();
+ imageDrawText = glWidget.grabFrameBuffer();
+ }
+
+ QImage imageDrawStaticText;
+ {
+ MyGLWidget glWidget(MyGLWidget::NormalDrawStaticText);
+ glWidget.show();
+ while (!glWidget.shown)
+ QApplication::processEvents();
+ imageDrawStaticText = glWidget.grabFrameBuffer();
+ }
+
+#if defined(DEBUG_SAVE_IMAGE)
+ imageDrawText.save("drawToGLWidget_imageDrawText.png");
+ imageDrawStaticText.save("drawToGLWidget_imageDrawStaticText.png");
+#endif
+
+ QCOMPARE(imageDrawStaticText, imageDrawText);
+}
+
+void tst_QStaticText::drawToGLWidgetWithCaching()
+{
+ QImage imageDrawText;
+ {
+ MyGLWidget glWidget(MyGLWidget::NormalDrawText);
+ glWidget.show();
+ while (!glWidget.shown)
+ QApplication::processEvents();
+ imageDrawText = glWidget.grabFrameBuffer();
+ }
+
+ QImage imageDrawStaticText;
+ {
+ MyGLWidget glWidget(MyGLWidget::DrawStaticTextWithCaching);
+ glWidget.show();
+ while (!glWidget.shown)
+ QApplication::processEvents();
+ imageDrawStaticText = glWidget.grabFrameBuffer();
+ }
+
+#if defined(DEBUG_SAVE_IMAGE)
+ imageDrawText.save("drawToGLWidgetWithCaching_imageDrawText.png");
+ imageDrawStaticText.save("drawToGLWidgetWithCaching_imageDrawStaticText.png");
+#endif
+
+ QCOMPARE(imageDrawStaticText, imageDrawText);
+}
+
+void tst_QStaticText::drawToGLWidgetWithCachingRepeated()
+{
+ QImage imageDrawText;
+ MyGLWidget glWidgetNormal(MyGLWidget::NormalDrawText);
+
+ {
+ glWidgetNormal.show();
+ while (!glWidgetNormal.shown)
+ QApplication::processEvents();
+ imageDrawText = glWidgetNormal.grabFrameBuffer();
+ }
+
+ QImage imageDrawStaticText;
+ MyGLWidget glWidgetAbnormal(MyGLWidget::DrawStaticTextWithCaching);
+ {
+
+ glWidgetAbnormal.show();
+ while (!glWidgetAbnormal.shown)
+ QApplication::processEvents();
+ imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer();
+ }
+
+#if defined(DEBUG_SAVE_IMAGE)
+ imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText1.png");
+ imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText1.png");
+#endif
+
+ QCOMPARE(imageDrawStaticText, imageDrawText);
+
+ {
+ glWidgetNormal.shown = false;
+ glWidgetNormal.update();
+ while (!glWidgetNormal.shown)
+ QApplication::processEvents();
+ imageDrawText = glWidgetNormal.grabFrameBuffer();
+ }
+
+ {
+ glWidgetAbnormal.shown = false;
+ glWidgetAbnormal.update();
+ while (!glWidgetAbnormal.shown)
+ QApplication::processEvents();
+ imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer();
+ }
+
+#if defined(DEBUG_SAVE_IMAGE)
+ imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText2.png");
+ imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText2.png");
+#endif
+
+ QCOMPARE(imageDrawStaticText, imageDrawText);
+}
+
+void tst_QStaticText::drawToGLWidgetRepeated()
+{
+ QImage imageDrawText;
+ MyGLWidget glWidgetNormal(MyGLWidget::NormalDrawText);
+
+ {
+ glWidgetNormal.show();
+ while (!glWidgetNormal.shown)
+ QApplication::processEvents();
+ imageDrawText = glWidgetNormal.grabFrameBuffer();
+ }
+
+ QImage imageDrawStaticText;
+ MyGLWidget glWidgetAbnormal(MyGLWidget::NormalDrawStaticText);
+ {
+
+ glWidgetAbnormal.show();
+ while (!glWidgetAbnormal.shown)
+ QApplication::processEvents();
+ imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer();
+ }
+
+#if defined(DEBUG_SAVE_IMAGE)
+ imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText1.png");
+ imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText1.png");
+#endif
+
+ QCOMPARE(imageDrawStaticText, imageDrawText);
+
+ {
+ glWidgetNormal.shown = false;
+ glWidgetNormal.update();
+ while (!glWidgetNormal.shown)
+ QApplication::processEvents();
+ imageDrawText = glWidgetNormal.grabFrameBuffer();
+ }
+
+ {
+ glWidgetAbnormal.shown = false;
+ glWidgetAbnormal.update();
+ while (!glWidgetAbnormal.shown)
+ QApplication::processEvents();
+ imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer();
+ }
+
+#if defined(DEBUG_SAVE_IMAGE)
+ imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText2.png");
+ imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText2.png");
+#endif
+
+ QCOMPARE(imageDrawStaticText, imageDrawText);
+}
+
+
QTEST_MAIN(tst_QStaticText)
#include "tst_qstatictext.moc"