summaryrefslogtreecommitdiffstats
path: root/tests/auto/qwindowsurface
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /tests/auto/qwindowsurface
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'tests/auto/qwindowsurface')
-rw-r--r--tests/auto/qwindowsurface/.gitignore1
-rw-r--r--tests/auto/qwindowsurface/qwindowsurface.pro5
-rw-r--r--tests/auto/qwindowsurface/tst_qwindowsurface.cpp291
3 files changed, 297 insertions, 0 deletions
diff --git a/tests/auto/qwindowsurface/.gitignore b/tests/auto/qwindowsurface/.gitignore
new file mode 100644
index 0000000000..e4be7d078d
--- /dev/null
+++ b/tests/auto/qwindowsurface/.gitignore
@@ -0,0 +1 @@
+tst_qwindowsurface
diff --git a/tests/auto/qwindowsurface/qwindowsurface.pro b/tests/auto/qwindowsurface/qwindowsurface.pro
new file mode 100644
index 0000000000..e5686beb6a
--- /dev/null
+++ b/tests/auto/qwindowsurface/qwindowsurface.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+SOURCES += tst_qwindowsurface.cpp
+
+
+
diff --git a/tests/auto/qwindowsurface/tst_qwindowsurface.cpp b/tests/auto/qwindowsurface/tst_qwindowsurface.cpp
new file mode 100644
index 0000000000..b209258224
--- /dev/null
+++ b/tests/auto/qwindowsurface/tst_qwindowsurface.cpp
@@ -0,0 +1,291 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <QPainter>
+#include <QPalette>
+#include <QWindowsStyle>
+
+#ifndef Q_WS_MAC
+
+#include <private/qwindowsurface_p.h>
+#include <QDesktopWidget>
+#include <QX11Info>
+
+
+#include "../../shared/util.h"
+
+class tst_QWindowSurface : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QWindowSurface() {}
+ ~tst_QWindowSurface() {}
+
+private slots:
+ void getSetWindowSurface();
+ void flushOutsidePaintEvent();
+ void grabWidget();
+};
+
+class MyWindowSurface : public QWindowSurface
+{
+public:
+ MyWindowSurface(QWidget *w) : QWindowSurface(w) {}
+
+ QPaintDevice *paintDevice() {
+ return &image;
+ }
+
+ void flush(QWidget*, const QRegion&, const QPoint&) {
+ /* nothing */
+ }
+
+private:
+ QImage image;
+};
+
+class ColorWidget : public QWidget
+{
+public:
+ ColorWidget(QWidget *parent = 0, const QColor &c = QColor(Qt::red))
+ : QWidget(parent, Qt::FramelessWindowHint), color(c)
+ {
+ QPalette opaquePalette = palette();
+ opaquePalette.setColor(backgroundRole(), color);
+ setPalette(opaquePalette);
+ setAutoFillBackground(true);
+ }
+
+ void paintEvent(QPaintEvent *e) {
+ r += e->region();
+ }
+
+ void reset() {
+ r = QRegion();
+ }
+
+ QColor color;
+ QRegion r;
+};
+
+//from tst_qwidget.cpp
+static void VERIFY_COLOR(const QRegion &region, const QColor &color)
+{
+ const QRegion r = QRegion(region);
+ for (int i = 0; i < r.rects().size(); ++i) {
+ const QRect rect = r.rects().at(i);
+ for (int t = 0; t < 5; t++) {
+ const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(),
+ rect.left(), rect.top(),
+ rect.width(), rect.height());
+ QCOMPARE(pixmap.size(), rect.size());
+ QPixmap expectedPixmap(pixmap); /* ensure equal formats */
+ expectedPixmap.fill(color);
+ if (pixmap.toImage().pixel(0,0) != QColor(color).rgb() && t < 4 )
+ { QTest::qWait(200); continue; }
+ QCOMPARE(pixmap.toImage().pixel(0,0), QColor(color).rgb());
+ QCOMPARE(pixmap, expectedPixmap);
+ break;
+ }
+ }
+}
+
+void tst_QWindowSurface::getSetWindowSurface()
+{
+ QWidget w;
+ QVERIFY(!w.windowSurface());
+
+ w.show();
+ QApplication::processEvents();
+ QVERIFY(w.windowSurface());
+
+ for (int i = 0; i < 2; ++i) {
+ MyWindowSurface *surface = new MyWindowSurface(&w);
+ QCOMPARE(w.windowSurface(), (QWindowSurface *)surface);
+
+ w.setWindowSurface(surface);
+ QCOMPARE(w.windowSurface(), (QWindowSurface *)surface);
+ }
+}
+
+void tst_QWindowSurface::flushOutsidePaintEvent()
+{
+#ifdef Q_WS_X11
+ if (QX11Info::isCompositingManagerRunning())
+ QSKIP("Test is unreliable with composition manager", SkipAll);
+#endif
+
+#ifdef Q_WS_WIN
+ if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) {
+ QTest::qWait(1000);
+ }
+#endif
+ ColorWidget w(0, Qt::red);
+ w.setGeometry(10, 100, 50, 50);
+ // prevent custom styles from messing up the background
+ w.setStyle(new QWindowsStyle);
+ w.show();
+ QTest::qWaitForWindowShown(&w);
+
+ QApplication::processEvents();
+#if defined(Q_WS_QWS)
+ QApplication::sendPostedEvents(); //for the glib event loop
+#elif defined(Q_WS_S60)
+ QTest::qWait(5000);
+#endif
+ VERIFY_COLOR(w.geometry(), w.color);
+ w.reset();
+
+ // trigger a paintEvent() the next time the event loop is entered
+ w.update();
+
+ // draw a black rectangle inside the widget
+ QWindowSurface *surface = w.windowSurface();
+ QVERIFY(surface);
+ const QRect rect = surface->rect(&w);
+ surface->beginPaint(rect);
+ QImage *img = surface->buffer(&w);
+ if (img) {
+ QPainter p(img);
+ p.fillRect(QRect(QPoint(),img->size()), Qt::black);
+ }
+ surface->endPaint(rect);
+ surface->flush(&w, rect, QPoint());
+
+#ifdef Q_WS_QWS
+ VERIFY_COLOR(w.geometry(), Qt::black);
+#endif
+
+ // the paintEvent() should overwrite the painted rectangle
+ QApplication::processEvents();
+
+#if defined(Q_WS_QWS)
+ QSKIP("task 176755", SkipAll);
+#endif
+ VERIFY_COLOR(w.geometry(), w.color);
+ QCOMPARE(QRegion(w.rect()), w.r);
+ w.reset();
+}
+
+
+void tst_QWindowSurface::grabWidget()
+{
+ QWidget parentWidget;
+ QWidget childWidget(&parentWidget);
+ QWidget babyWidget(&childWidget);
+
+ parentWidget.resize(300, 300);
+ childWidget.setGeometry(50, 50, 200, 200);
+ childWidget.setAutoFillBackground(true);
+ babyWidget.setGeometry(50, 50, 100, 100);
+ babyWidget.setAutoFillBackground(true);
+
+ QPalette pal = parentWidget.palette();
+ pal.setColor(QPalette::Window, QColor(Qt::blue));
+ parentWidget.setPalette(pal);
+
+ pal = childWidget.palette();
+ pal.setColor(QPalette::Window, QColor(Qt::white));
+ childWidget.setPalette(pal);
+
+ pal = babyWidget.palette();
+ pal.setColor(QPalette::Window, QColor(Qt::red));
+ babyWidget.setPalette(pal);
+
+ // prevent custom styles from messing up the background
+ parentWidget.setStyle(new QWindowsStyle);
+
+ babyWidget.show();
+ childWidget.show();
+ parentWidget.show();
+ QTest::qWaitForWindowShown(&parentWidget);
+
+ QPixmap parentPixmap;
+ QTRY_COMPARE((parentPixmap = parentWidget.windowSurface()->grabWidget(&parentWidget)).size(),
+ QSize(300,300));
+ QPixmap childPixmap = childWidget.windowSurface()->grabWidget(&childWidget);
+ QPixmap babyPixmap = babyWidget.windowSurface()->grabWidget(&babyWidget);
+ QPixmap parentSubPixmap = parentWidget.windowSurface()->grabWidget(&parentWidget, QRect(25, 25, 100, 100));
+ QPixmap childSubPixmap = childWidget.windowSurface()->grabWidget(&childWidget, QRect(55, 55, 50, 50));
+ QPixmap childInvalidSubPixmap = childWidget.windowSurface()->grabWidget(&childWidget, QRect(-50, -50, 150, 150));
+
+ QCOMPARE(parentPixmap.size(), QSize(300, 300));
+ QCOMPARE(childPixmap.size(), QSize(200, 200));
+ QCOMPARE(babyPixmap.size(), QSize(100, 100));
+ QCOMPARE(parentSubPixmap.size(), QSize(100, 100));
+ QCOMPARE(childSubPixmap.size(), QSize(50, 50));
+ QCOMPARE(childInvalidSubPixmap.size(), QSize(100, 100));
+
+ QImage parentImage = parentPixmap.toImage();
+ QImage childImage = childPixmap.toImage();
+ QImage babyImage = babyPixmap.toImage();
+ QImage parentSubImage = parentSubPixmap.toImage();
+ QImage childSubImage = childSubPixmap.toImage();
+ QImage childInvalidSubImage = childInvalidSubPixmap.toImage();
+
+ QVERIFY(QColor(parentImage.pixel(0, 0)) == QColor(Qt::blue));
+ QVERIFY(QColor(parentImage.pixel(75, 75)) == QColor(Qt::white));
+ QVERIFY(QColor(parentImage.pixel(149, 149)) == QColor(Qt::red));
+
+ QVERIFY(QColor(childImage.pixel(0, 0)) == QColor(Qt::white));
+ QVERIFY(QColor(childImage.pixel(99, 99)) == QColor(Qt::red));
+
+ QVERIFY(QColor(parentSubImage.pixel(0, 0)) == QColor(Qt::blue));
+ QVERIFY(QColor(parentSubImage.pixel(30, 30)) == QColor(Qt::white));
+ QVERIFY(QColor(parentSubImage.pixel(80, 80)) == QColor(Qt::red));
+
+ QVERIFY(QColor(childSubImage.pixel(0, 0)) == QColor(Qt::red));
+
+ QVERIFY(QColor(childInvalidSubImage.pixel(0, 0)) == QColor(Qt::white));
+}
+
+QTEST_MAIN(tst_QWindowSurface)
+
+#else // Q_WS_MAC
+
+QTEST_NOOP_MAIN
+
+#endif
+
+#include "tst_qwindowsurface.moc"