summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp44
-rw-r--r--tests/auto/gui/image/qpicture/tst_qpicture.cpp107
-rw-r--r--tests/auto/gui/kernel/kernel.pro1
-rw-r--r--tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp46
-rw-r--r--tests/auto/gui/kernel/qguiapplication/icons/appicon.pngbin0 -> 175 bytes
-rw-r--r--tests/auto/gui/kernel/qguiapplication/icons/usericon.pngbin0 -> 14743 bytes
-rw-r--r--tests/auto/gui/kernel/qguiapplication/qguiapplication.pro2
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp19
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc6
-rw-r--r--tests/auto/gui/kernel/qpixelformat/qpixelformat.pro6
-rw-r--r--tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp243
-rw-r--r--tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp35
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp13
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp22
-rw-r--r--tests/auto/gui/painting/qpen/tst_qpen.cpp53
-rw-r--r--tests/auto/gui/qopengl/qopengl.pro2
-rw-r--r--tests/auto/gui/qopengl/tst_qopengl.cpp66
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp124
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp39
19 files changed, 752 insertions, 76 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 95a9b142ec..d2072e0e56 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -170,6 +170,10 @@ private slots:
void scaled_QTBUG35972();
+ void convertToPixelFormat();
+ void convertToImageFormat_data();
+ void convertToImageFormat();
+
void cleanupFunctions();
};
@@ -2460,6 +2464,46 @@ void tst_QImage::scaled_QTBUG35972()
QCOMPARE(pixels[i], 0xffffffff);
}
+void tst_QImage::convertToPixelFormat()
+{
+ QPixelFormat rgb565 = QPixelFormatRgb(5,6,5,0,QPixelFormat::IgnoresAlpha, QPixelFormat::AtBeginning, QPixelFormat::NotPremultiplied, QPixelFormat::UnsignedShort);
+ QPixelFormat rgb565ImageFormat = QImage::toPixelFormat(QImage::Format_RGB16);
+ QCOMPARE(rgb565, rgb565ImageFormat);
+}
+
+void tst_QImage::convertToImageFormat_data()
+{
+ QTest::addColumn<QImage::Format>("image_format");
+ QTest::newRow("Convert Format_Invalid") << QImage::Format_Invalid;
+ QTest::newRow("Convert Format_Mono") << QImage::Format_Mono;
+ //This ends up being a QImage::Format_Mono since we cant specify LSB in QPixelFormat
+ //QTest::newRow("Convert Format_MonoLSB") << QImage::Format_MonoLSB;
+ QTest::newRow("Convert Format_Indexed8") << QImage::Format_Indexed8;
+ QTest::newRow("Convert Format_RGB32") << QImage::Format_RGB32;
+ QTest::newRow("Convert Format_ARGB32") << QImage::Format_ARGB32;
+ QTest::newRow("Convert Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("Convert Format_RGB16") << QImage::Format_RGB16;
+ QTest::newRow("Convert Format_ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied;
+ QTest::newRow("Convert Format_RGB666") << QImage::Format_RGB666;
+ QTest::newRow("Convert Format_ARGB6666_Premultiplied") << QImage::Format_ARGB6666_Premultiplied;
+ QTest::newRow("Convert Format_RGB555") << QImage::Format_RGB555;
+ QTest::newRow("Convert Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied;
+ QTest::newRow("Convert Format_RGB888") << QImage::Format_RGB888;
+ QTest::newRow("Convert Format_RGB444") << QImage::Format_RGB444;
+ QTest::newRow("Convert Format_ARGB4444_Premultiplied") << QImage::Format_ARGB4444_Premultiplied;
+ QTest::newRow("Convert Format_RGBX8888") << QImage::Format_RGBX8888;
+ QTest::newRow("Convert Format_RGBA8888") << QImage::Format_RGBA8888;
+ QTest::newRow("Convert Format_RGBA8888_Premultiplied") << QImage::Format_RGBA8888_Premultiplied;
+}
+void tst_QImage::convertToImageFormat()
+{
+ QFETCH(QImage::Format, image_format);
+
+ QPixelFormat pixel_format = QImage::toPixelFormat(image_format);
+ QImage::Format format = QImage::toImageFormat(pixel_format);
+ QCOMPARE(format, image_format);
+}
+
static void cleanupFunction(void* info)
{
bool *called = static_cast<bool*>(info);
diff --git a/tests/auto/gui/image/qpicture/tst_qpicture.cpp b/tests/auto/gui/image/qpicture/tst_qpicture.cpp
index 2e766c5bf5..986431941f 100644
--- a/tests/auto/gui/image/qpicture/tst_qpicture.cpp
+++ b/tests/auto/gui/image/qpicture/tst_qpicture.cpp
@@ -45,6 +45,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 +65,7 @@ private slots:
void paintingActive();
void boundingRect();
void swap();
- void operator_lt_lt();
+ void serialization();
#ifndef QT_NO_WIDGETS
void save_restore();
@@ -169,36 +170,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)
{
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro
index e4d9ce9d27..bbcdd91ea3 100644
--- a/tests/auto/gui/kernel/kernel.pro
+++ b/tests/auto/gui/kernel/kernel.pro
@@ -20,6 +20,7 @@ SUBDIRS=\
qtouchevent \
qwindow \
qguiapplication \
+ qpixelformat \
!qtHaveModule(widgets): SUBDIRS -= \
qmouseevent_modal \
diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
index cf786c1dca..8a2009a601 100644
--- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
+++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** 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.
@@ -134,6 +134,29 @@ void tst_QClipboard::modes()
}
}
+// A predicate to be used with a QSignalSpy / QTRY_VERIFY to ensure all delayed
+// notifications are eaten. It waits at least one cycle and returns true when
+// no new signals arrive.
+class EatSignalSpyNotificationsPredicate
+{
+public:
+ explicit EatSignalSpyNotificationsPredicate(QSignalSpy &spy) : m_spy(spy) { reset(); }
+
+ operator bool() const
+ {
+ if (m_timer.elapsed() && !m_spy.count())
+ return true;
+ m_spy.clear();
+ return false;
+ }
+
+ inline void reset() { m_timer.start(); }
+
+private:
+ QSignalSpy &m_spy;
+ QElapsedTimer m_timer;
+};
+
/*
Test that the appropriate signals are emitted when the clipboard
contents is changed by calling the qt functions.
@@ -149,6 +172,13 @@ void tst_QClipboard::testSignals()
QSignalSpy changedSpy(clipboard, SIGNAL(changed(QClipboard::Mode)));
QSignalSpy dataChangedSpy(clipboard, SIGNAL(dataChanged()));
+ // Clipboard notifications are asynchronous with the new AddClipboardFormatListener
+ // in Windows Vista (5.4). Eat away all signals to ensure they don't interfere
+ // with the QTRY_COMPARE below.
+ EatSignalSpyNotificationsPredicate noLeftOverDataChanges(dataChangedSpy);
+ EatSignalSpyNotificationsPredicate noLeftOverChanges(changedSpy);
+ QTRY_VERIFY(noLeftOverChanges && noLeftOverDataChanges);
+
QSignalSpy searchChangedSpy(clipboard, SIGNAL(findBufferChanged()));
QSignalSpy selectionChangedSpy(clipboard, SIGNAL(selectionChanged()));
@@ -156,7 +186,7 @@ void tst_QClipboard::testSignals()
// Test the default mode signal.
clipboard->setText(text);
- QCOMPARE(dataChangedSpy.count(), 1);
+ QTRY_COMPARE(dataChangedSpy.count(), 1);
QCOMPARE(searchChangedSpy.count(), 0);
QCOMPARE(selectionChangedSpy.count(), 0);
QCOMPARE(changedSpy.count(), 1);
@@ -296,6 +326,11 @@ void tst_QClipboard::setMimeData()
QSignalSpy spySelection(QGuiApplication::clipboard(), SIGNAL(selectionChanged()));
QSignalSpy spyData(QGuiApplication::clipboard(), SIGNAL(dataChanged()));
+ // Clipboard notifications are asynchronous with the new AddClipboardFormatListener
+ // in Windows Vista (5.4). Eat away all signals to ensure they don't interfere
+ // with the QTRY_COMPARE below.
+ EatSignalSpyNotificationsPredicate noLeftOverDataChanges(spyData);
+ QTRY_VERIFY(noLeftOverDataChanges);
QSignalSpy spyFindBuffer(QGuiApplication::clipboard(), SIGNAL(findBufferChanged()));
QGuiApplication::clipboard()->clear(QClipboard::Clipboard);
@@ -312,7 +347,7 @@ void tst_QClipboard::setMimeData()
else
QCOMPARE(spyFindBuffer.count(), 0);
- QCOMPARE(spyData.count(), 1);
+ QTRY_COMPARE(spyData.count(), 1);
// an other crash test
data = new QMimeData;
@@ -326,7 +361,8 @@ void tst_QClipboard::setMimeData()
newData->setText("bar");
spySelection.clear();
- spyData.clear();
+ noLeftOverDataChanges.reset();
+ QTRY_VERIFY(noLeftOverDataChanges);
spyFindBuffer.clear();
QGuiApplication::clipboard()->setMimeData(newData, QClipboard::Clipboard);
@@ -343,7 +379,7 @@ void tst_QClipboard::setMimeData()
else
QCOMPARE(spyFindBuffer.count(), 0);
- QCOMPARE(spyData.count(), 1);
+ QTRY_COMPARE(spyData.count(), 1);
}
void tst_QClipboard::clearBeforeSetText()
diff --git a/tests/auto/gui/kernel/qguiapplication/icons/appicon.png b/tests/auto/gui/kernel/qguiapplication/icons/appicon.png
new file mode 100644
index 0000000000..b5d3ecbddf
--- /dev/null
+++ b/tests/auto/gui/kernel/qguiapplication/icons/appicon.png
Binary files differ
diff --git a/tests/auto/gui/kernel/qguiapplication/icons/usericon.png b/tests/auto/gui/kernel/qguiapplication/icons/usericon.png
new file mode 100644
index 0000000000..8d703640c1
--- /dev/null
+++ b/tests/auto/gui/kernel/qguiapplication/icons/usericon.png
Binary files differ
diff --git a/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro b/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro
index cd363bab31..895c2a0307 100644
--- a/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro
+++ b/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro
@@ -7,3 +7,5 @@ INCLUDEPATH += $$CORE_TEST_PATH
TARGET = tst_qguiapplication
QT += gui-private
SOURCES += tst_qguiapplication.cpp
+
+RESOURCES = tst_qguiapplication.qrc
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
index e551d99959..e1cdb8db45 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -65,6 +65,7 @@ class tst_QGuiApplication: public tst_QCoreApplication
private slots:
void displayName();
void firstWindowTitle();
+ void windowIcon();
void focusObject();
void allWindows();
void topLevelWindows();
@@ -99,6 +100,24 @@ void tst_QGuiApplication::firstWindowTitle()
QCOMPARE(window.title(), QString("User Title"));
}
+void tst_QGuiApplication::windowIcon()
+{
+ int argc = 3;
+ char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-qwindowicon"), const_cast<char*>(":/icons/usericon.png") };
+ QGuiApplication app(argc, argv);
+ QIcon appIcon(":/icons/appicon.png");
+ app.setWindowIcon(appIcon);
+
+ QWindow window;
+ window.show();
+
+ QIcon userIcon(":/icons/usericon.png");
+ // Comparing icons is hard. cacheKey() differs because the icon was independently loaded.
+ // So we use availableSizes, after making sure that the app and user icons do have different sizes.
+ QVERIFY(userIcon.availableSizes() != appIcon.availableSizes());
+ QCOMPARE(window.icon().availableSizes(), userIcon.availableSizes());
+}
+
class DummyWindow : public QWindow
{
public:
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc
new file mode 100644
index 0000000000..b26fba37b9
--- /dev/null
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>icons/usericon.png</file>
+ <file>icons/appicon.png</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro b/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro
new file mode 100644
index 0000000000..970e5c7c2d
--- /dev/null
+++ b/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro
@@ -0,0 +1,6 @@
+CONFIG += testcase
+TARGET = tst_qpixelformat
+
+QT += gui testlib
+
+SOURCES += tst_qpixelformat.cpp
diff --git a/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp
new file mode 100644
index 0000000000..c3b19a3b44
--- /dev/null
+++ b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp
@@ -0,0 +1,243 @@
+/****************************************************************************
+**
+** 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$
+** 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
+** 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.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** 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$
+**
+****************************************************************************/
+#include <QtTest/QtTest>
+
+#include <QtGui/qpixelformat.h>
+
+class tst_QPixelFormat : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testOperators();
+ void testQVectorOfFormats();
+ void testRGB();
+ void testCMYK();
+ void testHSLandHSV();
+ void testYUV_data();
+ void testYUV();
+ void testEnums();
+};
+
+void tst_QPixelFormat::testOperators()
+{
+ QPixelFormat first = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtBeginning, QPixelFormat::Premultiplied);
+ QPixelFormat second = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtBeginning, QPixelFormat::Premultiplied);
+ QVERIFY(first == second);
+
+ QPixelFormat third = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtEnd, QPixelFormat::NotPremultiplied);
+ QVERIFY(first != third);
+}
+
+void tst_QPixelFormat::testQVectorOfFormats()
+{
+ QVector<QPixelFormat> reallocedVector;
+ QVector<QPixelFormat> reservedVector;
+ reservedVector.reserve(QImage::NImageFormats);
+ for (int i = 0; i < QImage::NImageFormats; i++) {
+ if (i == 0 || i == 2) // skip invalid and monolsb
+ continue;
+ QImage::Format image_format = static_cast<QImage::Format>(i);
+ QPixelFormat format = QImage::toPixelFormat(image_format);
+ reallocedVector.append(format);
+ reservedVector.append(format);
+ }
+
+ for (int i = 0; i < reallocedVector.size(); i++) {
+ QCOMPARE(reallocedVector.at(i), reservedVector.at(i));
+ }
+}
+
+void tst_QPixelFormat::testRGB()
+{
+ QPixelFormat argb8888 = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha,QPixelFormat::AtBeginning, QPixelFormat::Premultiplied);
+ QCOMPARE(argb8888.redSize(), uchar(8));
+ QCOMPARE(argb8888.greenSize(), uchar(8));
+ QCOMPARE(argb8888.blueSize(), uchar(8));
+ QCOMPARE(argb8888.alphaSize(), uchar(8));
+
+ QPixelFormat rgb565 = QPixelFormatRgb(5,6,5,0,QPixelFormat::IgnoresAlpha,QPixelFormat::AtBeginning, QPixelFormat::NotPremultiplied);
+ QCOMPARE(rgb565.redSize(), uchar(5));
+ QCOMPARE(rgb565.greenSize(), uchar(6));
+ QCOMPARE(rgb565.blueSize(), uchar(5));
+ QCOMPARE(rgb565.alphaSize(), uchar(0));
+ QCOMPARE(rgb565.bitsPerPixel(), uchar(16));
+
+ QPixelFormat rgba1235 = QPixelFormatRgb(1,2,3,5,QPixelFormat::IgnoresAlpha, QPixelFormat::AtEnd, QPixelFormat::Premultiplied);
+ QCOMPARE(rgba1235.redSize(), uchar(1));
+ QCOMPARE(rgba1235.greenSize(), uchar(2));
+ QCOMPARE(rgba1235.blueSize(), uchar(3));
+ QCOMPARE(rgba1235.alphaSize(), uchar(5));
+ QCOMPARE(rgba1235.bitsPerPixel(), uchar(1 + 2 + 3 + 5));
+}
+
+void tst_QPixelFormat::testCMYK()
+{
+ QPixelFormat cmyk6 = QPixelFormatCmyk(6);
+ QCOMPARE(cmyk6.cyanSize(), uchar(6));
+ QCOMPARE(cmyk6.magentaSize(), uchar(6));
+ QCOMPARE(cmyk6.yellowSize(), uchar(6));
+ QCOMPARE(cmyk6.blackSize(), uchar(6));
+ QCOMPARE(cmyk6.bitsPerPixel(), uchar(6*4));
+
+ QPixelFormat cmykWithAlpha = QPixelFormatCmyk(8,8);
+ QCOMPARE(cmykWithAlpha.bitsPerPixel(), uchar(8*5));
+}
+void tst_QPixelFormat::testHSLandHSV()
+{
+ QPixelFormat hsl = QPixelFormatHsl(3,5);
+
+ QCOMPARE(hsl.hueSize(), uchar(3));
+ QCOMPARE(hsl.saturationSize(), uchar(3));
+ QCOMPARE(hsl.lightnessSize(), uchar(3));
+ QCOMPARE(hsl.bitsPerPixel(), uchar(3 * 3 + 5));
+
+ QPixelFormat hsv = QPixelFormatHsv(5,7);
+
+ QCOMPARE(hsv.hueSize(), uchar(5));
+ QCOMPARE(hsv.saturationSize(), uchar(5));
+ QCOMPARE(hsv.brightnessSize(), uchar(5));
+ QCOMPARE(hsv.bitsPerPixel(), uchar(5 * 3 + 7));
+}
+
+Q_DECLARE_METATYPE(QPixelFormat::YUVLayout)
+void tst_QPixelFormat::testYUV_data()
+{
+ QTest::addColumn<QPixelFormat::YUVLayout>("yuv_layout");
+ QTest::newRow("YUV Layout YUV444") << QPixelFormat::YUV444;
+ QTest::newRow("YUV Layout YUV422") << QPixelFormat::YUV422;
+ QTest::newRow("YUV Layout YUV411") << QPixelFormat::YUV411;
+ QTest::newRow("YUV Layout YUV420P") << QPixelFormat::YUV420P;
+ QTest::newRow("YUV Layout YUV420SP") << QPixelFormat::YUV420SP;
+ QTest::newRow("YUV Layout YV12") << QPixelFormat::YV12;
+ QTest::newRow("YUV Layout UYVY") << QPixelFormat::UYVY;
+ QTest::newRow("YUV Layout YUYV") << QPixelFormat::YUYV;
+ QTest::newRow("YUV Layout NV12") << QPixelFormat::NV12;
+ QTest::newRow("YUV Layout NV21") << QPixelFormat::NV21;
+ QTest::newRow("YUV Layout IMC1") << QPixelFormat::IMC1;
+ QTest::newRow("YUV Layout IMC2") << QPixelFormat::IMC2;
+ QTest::newRow("YUV Layout IMC3") << QPixelFormat::IMC3;
+ QTest::newRow("YUV Layout IMC4") << QPixelFormat::IMC4;
+ QTest::newRow("YUV Layout Y8") << QPixelFormat::Y8;
+ QTest::newRow("YUV Layout Y16") << QPixelFormat::Y16;
+}
+
+void tst_QPixelFormat::testYUV()
+{
+ QFETCH(QPixelFormat::YUVLayout, yuv_layout);
+
+ QPixelFormat format = QPixelFormatYuv(yuv_layout, 0);
+
+ switch (yuv_layout) {
+ case QPixelFormat::YUV444:
+ QCOMPARE(format.bitsPerPixel(), uchar(24));
+ break;
+ case QPixelFormat::YUV422:
+ QCOMPARE(format.bitsPerPixel(), uchar(16));
+ break;
+ case QPixelFormat::YUV411:
+ case QPixelFormat::YUV420P:
+ case QPixelFormat::YUV420SP:
+ case QPixelFormat::YV12:
+ QCOMPARE(format.bitsPerPixel(), uchar(12));
+ break;
+ case QPixelFormat::UYVY:
+ case QPixelFormat::YUYV:
+ QCOMPARE(format.bitsPerPixel(), uchar(16));
+ break;
+ case QPixelFormat::NV12:
+ case QPixelFormat::NV21:
+ QCOMPARE(format.bitsPerPixel(), uchar(12));
+ break;
+ case QPixelFormat::IMC1:
+ case QPixelFormat::IMC2:
+ case QPixelFormat::IMC3:
+ case QPixelFormat::IMC4:
+ QCOMPARE(format.bitsPerPixel(), uchar(12));
+ break;
+ case QPixelFormat::Y8:
+ QCOMPARE(format.bitsPerPixel(), uchar(8));
+ break;
+ case QPixelFormat::Y16:
+ QCOMPARE(format.bitsPerPixel(), uchar(16));
+ break;
+ default:
+ QVERIFY(!"the value stored for the yuvLayout is wrong!");
+ }
+
+}
+
+void tst_QPixelFormat::testEnums()
+{
+ QPixelFormat allSet = QPixelFormat(QPixelFormat::BGR,1,2,3,4,5,6,
+ QPixelFormat::UsesAlpha,
+ QPixelFormat::AtEnd,
+ QPixelFormat::Premultiplied,
+ QPixelFormat::FloatingPoint,
+ QPixelFormat::BigEndian,
+ (1 << 6) - 1);
+
+ QCOMPARE(allSet.alphaUsage(), QPixelFormat::UsesAlpha);
+ QCOMPARE(allSet.alphaPosition(), QPixelFormat::AtEnd);
+ QCOMPARE(allSet.premultiplied(), QPixelFormat::Premultiplied);
+ QCOMPARE(allSet.byteOrder(), QPixelFormat::BigEndian);
+ QCOMPARE(allSet.typeInterpretation(), QPixelFormat::FloatingPoint);
+ QCOMPARE(allSet.byteOrder(), QPixelFormat::BigEndian);
+ QCOMPARE(allSet.subEnum(), uchar(63));
+
+ QPixelFormat nonSet = QPixelFormat(QPixelFormat::RGB,6,5,4,3,2,1,
+ QPixelFormat::IgnoresAlpha,
+ QPixelFormat::AtBeginning,
+ QPixelFormat::NotPremultiplied,
+ QPixelFormat::UnsignedInteger,
+ QPixelFormat::LittleEndian);
+
+ QCOMPARE(nonSet.alphaUsage(), QPixelFormat::IgnoresAlpha);
+ QCOMPARE(nonSet.alphaPosition(), QPixelFormat::AtBeginning);
+ QCOMPARE(nonSet.premultiplied(), QPixelFormat::NotPremultiplied);
+ QCOMPARE(nonSet.byteOrder(), QPixelFormat::LittleEndian);
+ QCOMPARE(nonSet.typeInterpretation(), QPixelFormat::UnsignedInteger);
+ QCOMPARE(nonSet.byteOrder(), QPixelFormat::LittleEndian);
+ QCOMPARE(nonSet.subEnum(), uchar(0));
+}
+
+#include <tst_qpixelformat.moc>
+QTEST_MAIN(tst_QPixelFormat);
diff --git a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
index 98f1c1c8f9..e492a8f7bf 100644
--- a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
+++ b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
@@ -147,6 +147,7 @@ private slots:
void ortho();
void frustum();
void perspective();
+ void viewport();
void flipCoordinates();
void convertGeneric();
@@ -2794,6 +2795,40 @@ void tst_QMatrixNxN::perspective()
QVERIFY(m5.isIdentity());
}
+// Test viewport transformations
+void tst_QMatrixNxN::viewport()
+{
+ // Uses default depth range of 0->1
+ QMatrix4x4 m1;
+ m1.viewport(0.0f, 0.0f, 1024.0f, 768.0f);
+
+ // Lower left
+ QVector4D p1 = m1 * QVector4D(-1.0f, -1.0f, 0.0f, 1.0f);
+ QVERIFY(qFuzzyIsNull(p1.x()));
+ QVERIFY(qFuzzyIsNull(p1.y()));
+ QVERIFY(qFuzzyCompare(p1.z(), 0.5f));
+
+ // Lower right
+ QVector4D p2 = m1 * QVector4D(1.0f, -1.0f, 0.0f, 1.0f);
+ QVERIFY(qFuzzyCompare(p2.x(), 1024.0f));
+ QVERIFY(qFuzzyIsNull(p2.y()));
+
+ // Upper right
+ QVector4D p3 = m1 * QVector4D(1.0f, 1.0f, 0.0f, 1.0f);
+ QVERIFY(qFuzzyCompare(p3.x(), 1024.0f));
+ QVERIFY(qFuzzyCompare(p3.y(), 768.0f));
+
+ // Upper left
+ QVector4D p4 = m1 * QVector4D(-1.0f, 1.0f, 0.0f, 1.0f);
+ QVERIFY(qFuzzyIsNull(p4.x()));
+ QVERIFY(qFuzzyCompare(p4.y(), 768.0f));
+
+ // Center
+ QVector4D p5 = m1 * QVector4D(0.0f, 0.0f, 0.0f, 1.0f);
+ QVERIFY(qFuzzyCompare(p5.x(), 1024.0f / 2.0f));
+ QVERIFY(qFuzzyCompare(p5.y(), 768.0f / 2.0f));
+}
+
// Test left-handed vs right-handed coordinate flipping.
void tst_QMatrixNxN::flipCoordinates()
{
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 1b1f5575b1..2e1d55ced4 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -530,10 +530,19 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData);
void tst_QColor::setNamedColor()
{
for (int i = 0; i < rgbTblSize; ++i) {
- QColor color;
- color.setNamedColor(QLatin1String(rgbTbl[i].name));
QColor expected;
expected.setRgba(rgbTbl[i].value);
+
+ QColor color;
+ color.setNamedColor(QLatin1String(rgbTbl[i].name));
+ QCOMPARE(color, expected);
+
+ // name should be case insensitive
+ color.setNamedColor(QString(rgbTbl[i].name).toUpper());
+ QCOMPARE(color, expected);
+
+ // spaces should be ignored
+ color.setNamedColor(QString(rgbTbl[i].name).insert(1, ' '));
QCOMPARE(color, expected);
}
}
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index e4340451ce..4604f840da 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -282,6 +282,8 @@ private slots:
void QTBUG17053_zeroDashPattern();
+ void QTBUG38781_NoBrushAndQBitmap();
+
void drawTextOutsideGuiThread();
void drawTextWithComplexBrush();
@@ -4473,6 +4475,26 @@ void tst_QPainter::QTBUG17053_zeroDashPattern()
QCOMPARE(image, original);
}
+void tst_QPainter::QTBUG38781_NoBrushAndQBitmap()
+{
+ QBitmap bitmap(10, 10);
+ bitmap.fill(Qt::color0);
+ QPainter p(&bitmap);
+ p.setPen(Qt::color1);
+ p.drawLine(0, 1, 9, 1); // at horizontal line at y=1
+ p.setBrush(Qt::NoBrush);
+ p.drawRect(0, 0, 9, 9); // a rect all around
+
+ QRgb white = qRgb(0xff, 0xff, 0xff);
+ QRgb black = qRgb(0, 0, 0);
+ QImage image = bitmap.toImage();
+ QCOMPARE(image.pixel(0, 0), black);
+ QCOMPARE(image.pixel(5, 5), white);
+
+ // Check that the rect didn't overwrite the line
+ QCOMPARE(image.pixel(5, 1), black);
+}
+
class TextDrawerThread : public QThread
{
public:
diff --git a/tests/auto/gui/painting/qpen/tst_qpen.cpp b/tests/auto/gui/painting/qpen/tst_qpen.cpp
index 07c996d026..a373c51710 100644
--- a/tests/auto/gui/painting/qpen/tst_qpen.cpp
+++ b/tests/auto/gui/painting/qpen/tst_qpen.cpp
@@ -57,6 +57,8 @@ public:
private slots:
void getSetCheck();
void swap();
+ void move();
+ void move_assign();
void operator_eq_eq();
void operator_eq_eq_data();
@@ -101,6 +103,57 @@ void tst_QPen::swap()
QCOMPARE(p2.color(), QColor(Qt::black));
}
+void tst_QPen::move()
+{
+ QPen p1(Qt::black);
+
+ // check that moving does the right thing:
+ QPen p2 = qMove(p1); // could be move or copy construction, so don't check p1's state
+ QCOMPARE(p2.color(), QColor(Qt::black));
+
+ // this, executed ehre, would crash:
+ // QVERIFY(p1.style() != Qt::NoPen);
+
+ // check that moved-from QPen p1 can still be safely copied:
+ const QPen p3 = p1;
+
+ // check that moved-from QPen p1 can still be safely assigned to:
+ const QPen p4(Qt::yellow);
+ p1 = p4;
+ QCOMPARE(p1.color(), QColor(Qt::yellow));
+
+ // check that moved-from QPens p2, p3 can still be safely destroyed:
+ QPen p5 = qMove(p2);
+
+ // intentionally no more statements beyond this point
+}
+
+void tst_QPen::move_assign()
+{
+ QPen p1(Qt::black), p2(Qt::white);
+
+ // check that moving does the right thing:
+ p2 = qMove(p1); // could be move or copy assignment, so don't check p1's state
+ QCOMPARE(p2.color(), QColor(Qt::black));
+
+ // check that move-assigned-from QPen p1 can still be used, albeit
+ // with undocumented state (it's p2's original state):
+ QVERIFY(p1.style() != Qt::NoPen);
+
+ // check that moved-from QPen p1 can still be safely copied:
+ const QPen p3 = p1;
+
+ // check that moved-from QPen p1 can still be safely assigned to:
+ const QPen p4(Qt::yellow);
+ p1 = p4;
+ QCOMPARE(p1.color(), QColor(Qt::yellow));
+
+ // check that moved-from QPens p2, p3 can still be safely destroyed:
+ QPen p5;
+ p5 = qMove(p2);
+
+ // intentionally no more statements beyond this point
+}
tst_QPen::tst_QPen()
diff --git a/tests/auto/gui/qopengl/qopengl.pro b/tests/auto/gui/qopengl/qopengl.pro
index 12429bbeed..fcf457fec4 100644
--- a/tests/auto/gui/qopengl/qopengl.pro
+++ b/tests/auto/gui/qopengl/qopengl.pro
@@ -10,3 +10,5 @@ QT += gui-private core-private testlib
SOURCES += tst_qopengl.cpp
win32-msvc2010:contains(QT_CONFIG, angle):CONFIG += insignificant_test # QTBUG-31611
+
+linux:contains(QT_CONFIG, xcb-glx):contains(QT_CONFIG, xcb-xlib): DEFINES += USE_GLX
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index 63fe8b9693..c32edd3f71 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -51,12 +51,19 @@
#include <QtGui/QGenericMatrix>
#include <QtGui/QMatrix4x4>
#include <QtGui/private/qopengltextureblitter_p.h>
-
+#include <QtGui/private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
+#include <qpa/qplatformnativeinterface.h>
#include <QtTest/QtTest>
#include <QSignalSpy>
+#ifdef USE_GLX
+// Must be included last due to the X11 types
+#include <QtPlatformHeaders/QGLXNativeContext>
+#endif
+
class tst_QOpenGL : public QObject
{
Q_OBJECT
@@ -85,6 +92,10 @@ private slots:
void textureblitterPartOriginTopLeftSourceRectTransform();
void textureblitterFullTargetRectTransform();
void textureblitterPartTargetRectTransform();
+
+#ifdef USE_GLX
+ void glxContextWrap();
+#endif
};
struct SharedResourceTracker
@@ -448,9 +459,9 @@ void tst_QOpenGL::fboSimpleRendering()
QVERIFY(fbo->bind());
- glClearColor(1.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glFinish();
+ ctx.functions()->glClearColor(1.0, 0.0, 0.0, 1.0);
+ ctx.functions()->glClear(GL_COLOR_BUFFER_BIT);
+ ctx.functions()->glFinish();
const QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(fb.size(), size);
@@ -494,9 +505,9 @@ void tst_QOpenGL::fboTextureOwnership()
fbo->bind();
QVERIFY(fbo->texture() != 0 && fbo->texture() != texture);
- glClearColor(1.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glFinish();
+ ctx.functions()->glClearColor(1.0, 0.0, 0.0, 1.0);
+ ctx.functions()->glClear(GL_COLOR_BUFFER_BIT);
+ ctx.functions()->glFinish();
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QImage reference(fb.size(), QImage::Format_RGB32);
@@ -504,7 +515,7 @@ void tst_QOpenGL::fboTextureOwnership()
QFUZZY_COMPARE_IMAGES(fb, reference);
- glDeleteTextures(1, &texture);
+ ctx.functions()->glDeleteTextures(1, &texture);
delete fbo;
}
@@ -970,6 +981,45 @@ void tst_QOpenGL::textureblitterPartTargetRectTransform()
QCOMPARE(targetBottomRight, expectedBottomRight);
}
+#ifdef USE_GLX
+void tst_QOpenGL::glxContextWrap()
+{
+ QWindow *window = new QWindow;
+ window->setSurfaceType(QWindow::OpenGLSurface);
+ window->setGeometry(0, 0, 10, 10);
+ window->show();
+ QTest::qWaitForWindowExposed(window);
+
+ QPlatformNativeInterface *nativeIf = QGuiApplicationPrivate::instance()->platformIntegration()->nativeInterface();
+ QVERIFY(nativeIf);
+
+ // Fetch a GLXContext.
+ QOpenGLContext *ctx0 = new QOpenGLContext;
+ ctx0->setFormat(window->format());
+ QVERIFY(ctx0->create());
+ QVariant v = ctx0->nativeHandle();
+ QVERIFY(!v.isNull());
+ QVERIFY(v.canConvert<QGLXNativeContext>());
+ GLXContext context = v.value<QGLXNativeContext>().context();
+ QVERIFY(context);
+
+ // Then create another QOpenGLContext wrapping it.
+ QOpenGLContext *ctx = new QOpenGLContext;
+ ctx->setNativeHandle(QVariant::fromValue<QGLXNativeContext>(QGLXNativeContext(context)));
+ QVERIFY(ctx->create());
+ QVERIFY(ctx->nativeHandle().value<QGLXNativeContext>().context() == context);
+ QVERIFY(nativeIf->nativeResourceForContext(QByteArrayLiteral("glxcontext"), ctx) == (void *) context);
+
+ QVERIFY(ctx->makeCurrent(window));
+ ctx->doneCurrent();
+
+ delete ctx;
+ delete ctx0;
+
+ delete window;
+}
+#endif // USE_GLX
+
QTEST_MAIN(tst_QOpenGL)
#include "tst_qopengl.moc"
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index 4c88212c72..6f75a1f8bb 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -76,7 +76,8 @@ private slots:
void isCopyOf();
void italicOblique();
void insertAndRemoveSubstitutions();
- void serializeSpacing();
+ void serialize_data();
+ void serialize();
void lastResortFont();
void styleName();
void defaultFamily_data();
@@ -534,7 +535,6 @@ void tst_QFont::insertAndRemoveSubstitutions()
QVERIFY(QFont::substitutes("bogusfontfamily").isEmpty());
}
-
static QFont copyFont(const QFont &font1) // copy using a QDataStream
{
QBuffer buffer;
@@ -549,29 +549,115 @@ static QFont copyFont(const QFont &font1) // copy using a QDataStream
return font2;
}
-void tst_QFont::serializeSpacing()
+Q_DECLARE_METATYPE(QDataStream::Version)
+
+void tst_QFont::serialize_data()
{
- QFont font;
- QCOMPARE(font.letterSpacing(), 0.);
- QCOMPARE(font.wordSpacing(), 0.);
+ QTest::addColumn<QFont>("font");
+ // The version in which the tested feature was added.
+ QTest::addColumn<QDataStream::Version>("minimumStreamVersion");
+
+ QFont basicFont;
+ // Versions <= Qt 2.1 had broken point size serialization,
+ // so we set an integer point size.
+ basicFont.setPointSize(9);
+
+ QFont font = basicFont;
+ QTest::newRow("defaultConstructed") << font << QDataStream::Qt_1_0;
font.setLetterSpacing(QFont::AbsoluteSpacing, 105);
- QCOMPARE(font.letterSpacing(), 105.);
- QCOMPARE(font.letterSpacingType(), QFont::AbsoluteSpacing);
- QCOMPARE(font.wordSpacing(), 0.);
- QFont font2 = copyFont(font);
- QCOMPARE(font2.letterSpacing(), 105.);
- QCOMPARE(font2.letterSpacingType(), QFont::AbsoluteSpacing);
- QCOMPARE(font2.wordSpacing(), 0.);
+ QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5;
+ font = basicFont;
font.setWordSpacing(50.0);
- QCOMPARE(font.letterSpacing(), 105.);
- QCOMPARE(font.wordSpacing(), 50.);
+ QTest::newRow("wordSpacing") << font << QDataStream::Qt_4_5;
+
+ font = basicFont;
+ font.setPointSize(20);
+ QTest::newRow("pointSize") << font << QDataStream::Qt_1_0;
+
+ font = basicFont;
+ font.setPixelSize(32);
+ QTest::newRow("pixelSize") << font << QDataStream::Qt_3_0;
+
+ font = basicFont;
+ font.setStyleHint(QFont::Monospace);
+ QTest::newRow("styleHint") << font << QDataStream::Qt_1_0;
+
+ font = basicFont;
+ font.setStretch(4000);
+ QTest::newRow("stretch") << font << QDataStream::Qt_4_3;
+
+ font = basicFont;
+ font.setWeight(99);
+ QTest::newRow("weight") << font << QDataStream::Qt_1_0;
+
+ font = basicFont;
+ font.setUnderline(true);
+ QTest::newRow("underline") << font << QDataStream::Qt_1_0;
+
+ font = basicFont;
+ font.setStrikeOut(true);
+ QTest::newRow("strikeOut") << font << QDataStream::Qt_1_0;
+
+ font = basicFont;
+ font.setFixedPitch(true);
+ // This fails for versions less than this, as ignorePitch is set to false
+ // whenever setFixedPitch() is called, but ignorePitch is considered an
+ // extended bit, which were apparently not available until 4.4.
+ QTest::newRow("fixedPitch") << font << QDataStream::Qt_4_4;
+
+ font = basicFont;
+ font.setLetterSpacing(QFont::AbsoluteSpacing, 10);
+ // Fails for 4.4 because letterSpacing wasn't read until 4.5.
+ QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5;
+
+ font = basicFont;
+ font.setRawMode(true);
+ QTest::newRow("rawMode") << font << QDataStream::Qt_1_0;
+
+ font = basicFont;
+ font.setKerning(false);
+ QTest::newRow("kerning") << font << QDataStream::Qt_4_0;
+
+ font = basicFont;
+ font.setStyleStrategy(QFont::NoFontMerging);
+ // This wasn't read properly until 5.4.
+ QTest::newRow("styleStrategy") << font << QDataStream::Qt_5_4;
+
+ font = basicFont;
+ font.setHintingPreference(QFont::PreferFullHinting);
+ // This wasn't read until 5.4.
+ QTest::newRow("hintingPreference") << font << QDataStream::Qt_5_4;
+
+ font = basicFont;
+ font.setStyleName("Regular Black Condensed");
+ // This wasn't read until 5.4.
+ QTest::newRow("styleName") << font << QDataStream::Qt_5_4;
+}
- QFont font3 = copyFont(font);
- QCOMPARE(font3.letterSpacing(), 105.);
- QCOMPARE(font3.letterSpacingType(), QFont::AbsoluteSpacing);
- QCOMPARE(font3.wordSpacing(), 50.);
+void tst_QFont::serialize()
+{
+ QFETCH(QFont, font);
+ QFETCH(QDataStream::Version, minimumStreamVersion);
+
+ QDataStream stream;
+ const int thisVersion = stream.version();
+
+ for (int version = minimumStreamVersion; version <= thisVersion; ++version) {
+ QBuffer buffer;
+ buffer.open(QIODevice::WriteOnly);
+ stream.setDevice(&buffer);
+ stream.setVersion(version);
+ stream << font;
+ buffer.close();
+
+ buffer.open(QIODevice::ReadOnly);
+ QFont readFont;
+ stream >> readFont;
+ QVERIFY2(readFont == font, qPrintable(QString::fromLatin1("Fonts do not compare equal for QDataStream version ") +
+ QString::fromLatin1("%1:\nactual: %2\nexpected: %3").arg(version).arg(readFont.toString()).arg(font.toString())));
+ }
}
// QFont::lastResortFont() may abort with qFatal() on QWS/QPA
diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
index a39277b093..a4e1490b01 100644
--- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
+++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
@@ -314,16 +314,24 @@ void tst_QRawFont::advances()
bool supportsSubPixelPositions = font_d->fontEngine->supportsSubPixelPositions();
QVector<QPointF> advances = font.advancesForGlyphIndexes(glyphIndices);
- for (int i=0; i<glyphIndices.size(); ++i) {
-#ifdef Q_OS_WIN
- // In Windows, freetype engine returns advance of 9 when full hinting is used (default) for
- // some of the glyphs.
- if (font_d->fontEngine->type() == QFontEngine::Freetype
- && (hintingPreference == QFont::PreferFullHinting || hintingPreference == QFont::PreferDefaultHinting)
- && (i == 0 || i == 5)) {
- QEXPECT_FAIL("", "Advance for some glyphs is not the expected with Windows Freetype engine (9 instead of 8)", Continue);
- }
+
+ // On Windows and QNX, freetype engine returns advance of 9 for some of the glyphs
+ // when full hinting is used (default on Windows).
+ bool mayFail = false;
+#if defined (Q_OS_WIN)
+ mayFail = font_d->fontEngine->type() == QFontEngine::Freetype
+ && (hintingPreference == QFont::PreferFullHinting
+ || hintingPreference == QFont::PreferDefaultHinting);
+#elif defined(Q_OS_QNX)
+ mayFail = font_d->fontEngine->type() == QFontEngine::Freetype
+ && hintingPreference == QFont::PreferFullHinting;
#endif
+
+ for (int i = 0; i < glyphIndices.size(); ++i) {
+ if (mayFail && (i == 0 || i == 5)) {
+ QEXPECT_FAIL("", "FreeType engine reports unexpected advance "
+ "for some glyphs (9 instead of 8)", Continue);
+ }
QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0));
if (supportsSubPixelPositions)
QVERIFY(advances.at(i).x() > 8.0);
@@ -341,16 +349,11 @@ void tst_QRawFont::advances()
QVERIFY(font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), numGlyphs));
- for (int i=0; i<glyphIndices.size(); ++i) {
-#ifdef Q_OS_WIN
- // In Windows, freetype engine returns advance of 9 when full hinting is used (default) for
- // some of the glyphs.
- if (font_d->fontEngine->type() == QFontEngine::Freetype
- && (hintingPreference == QFont::PreferFullHinting || hintingPreference == QFont::PreferDefaultHinting)
- && (i == 0 || i == 5)) {
- QEXPECT_FAIL("", "Advance for some glyphs is not the expected with Windows Freetype engine (9 instead of 8)", Continue);
+ for (int i = 0; i < glyphIndices.size(); ++i) {
+ if (mayFail && (i == 0 || i == 5)) {
+ QEXPECT_FAIL("", "FreeType engine reports unexpected advance "
+ "for some glyphs (9 instead of 8)", Continue);
}
-#endif
QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0));
if (supportsSubPixelPositions)
QVERIFY(advances.at(i).x() > 8.0);