summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/image/qpicture/tst_qpicture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/image/qpicture/tst_qpicture.cpp')
-rw-r--r--tests/auto/gui/image/qpicture/tst_qpicture.cpp137
1 files changed, 94 insertions, 43 deletions
diff --git a/tests/auto/gui/image/qpicture/tst_qpicture.cpp b/tests/auto/gui/image/qpicture/tst_qpicture.cpp
index 2e766c5bf5..ff1829458e 100644
--- a/tests/auto/gui/image/qpicture/tst_qpicture.cpp
+++ b/tests/auto/gui/image/qpicture/tst_qpicture.cpp
@@ -1,40 +1,32 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -45,6 +37,7 @@
#include <qpicture.h>
#include <qpainter.h>
#include <qimage.h>
+#include <qpaintengine.h>
#ifndef QT_NO_WIDGETS
#include <qdesktopwidget.h>
#include <qapplication.h>
@@ -64,7 +57,7 @@ private slots:
void paintingActive();
void boundingRect();
void swap();
- void operator_lt_lt();
+ void serialization();
#ifndef QT_NO_WIDGETS
void save_restore();
@@ -169,36 +162,94 @@ void tst_QPicture::swap()
QCOMPARE(p2.boundingRect(), QRect(0,0,5,5));
}
-// operator<< and operator>>
-void tst_QPicture::operator_lt_lt()
+Q_DECLARE_METATYPE(QDataStream::Version)
+Q_DECLARE_METATYPE(QPicture)
+
+void ensureSerializesCorrectly(const QPicture &picture, QDataStream::Version version)
+ {
+ QDataStream stream;
+
+ QBuffer buffer;
+ buffer.open(QIODevice::WriteOnly);
+ stream.setDevice(&buffer);
+ stream.setVersion(version);
+ stream << picture;
+ buffer.close();
+
+ buffer.open(QIODevice::ReadOnly);
+ QPicture readpicture;
+ stream >> readpicture;
+ QVERIFY2(memcmp(picture.data(), readpicture.data(), picture.size()) == 0,
+ qPrintable(QString::fromLatin1("Picture data does not compare equal for QDataStream version %1").arg(version)));
+}
+
+class PaintEngine : public QPaintEngine
{
- // streaming of null pictures
- {
- QPicture pic1, pic2;
- QByteArray ba( 100, 0 );
- QDataStream str1( &ba, QIODevice::WriteOnly );
- str1 << pic1;
- QDataStream str2( &ba, QIODevice::ReadOnly );
- str2 >> pic2;
- QVERIFY( pic2.isNull() );
+public:
+ PaintEngine() : QPaintEngine() {}
+ bool begin(QPaintDevice *) { return true; }
+ bool end() { return true; }
+ void updateState(const QPaintEngineState &) {}
+ void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) {}
+ Type type() const { return Raster; }
+
+ QFont font() { return state->font(); }
+};
+
+class Picture : public QPicture
+{
+public:
+ Picture() : QPicture() {}
+ QPaintEngine *paintEngine() const { return (QPaintEngine*)&mPaintEngine; }
+private:
+ PaintEngine mPaintEngine;
+};
+
+void tst_QPicture::serialization()
+{
+ QDataStream stream;
+ const int thisVersion = stream.version();
+
+ for (int version = QDataStream::Qt_1_0; version <= thisVersion; ++version) {
+ const QDataStream::Version versionEnum = static_cast<QDataStream::Version>(version);
+
+ {
+ // streaming of null pictures
+ ensureSerializesCorrectly(QPicture(), versionEnum);
+ }
+ {
+ // picture with a simple line, checking bitwise equality
+ QPicture picture;
+ QPainter painter(&picture);
+ painter.drawLine(10, 20, 30, 40);
+ ensureSerializesCorrectly(picture, versionEnum);
+ }
}
- // picture with a simple line, checking bitwise equality
{
- QPicture pic1, pic2;
- QPainter p( &pic1 );
- p.drawLine( 10, 20, 30, 40 );
- p.end();
- QByteArray ba( 10 * pic1.size(), 0 );
- QDataStream str1( &ba, QIODevice::WriteOnly );
- str1 << pic1;
- QDataStream str2( &ba, QIODevice::ReadOnly );
- str2 >> pic2;
- QCOMPARE( pic1.size(), pic2.size() );
- QVERIFY( memcmp( pic1.data(), pic2.data(), pic1.size() ) == 0 );
+ // Test features that were added after Qt 4.5, as that was hard-coded as the major
+ // version for a while, which was incorrect. In this case, we'll test font hints.
+ QPicture picture;
+ QPainter painter;
+ QFont font;
+ font.setStyleName("Blah");
+ font.setHintingPreference(QFont::PreferFullHinting);
+ painter.begin(&picture);
+ painter.setFont(font);
+ painter.drawText(20, 20, "Hello");
+ painter.end();
+
+ Picture customPicture;
+ painter.begin(&customPicture);
+ picture.play(&painter);
+ const QFont actualFont = ((PaintEngine*)customPicture.paintEngine())->font();
+ painter.end();
+ QCOMPARE(actualFont.styleName(), QStringLiteral("Blah"));
+ QCOMPARE(actualFont.hintingPreference(), QFont::PreferFullHinting);
}
}
+
#ifndef QT_NO_WIDGETS
static QPointF scalePoint(const QPointF &point, QPaintDevice *sourceDevice, QPaintDevice *destDevice)
{