summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/image/qicoimageformat/icons/valid/yellow.curbin0 -> 4286 bytes
-rw-r--r--tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp19
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp125
-rw-r--r--tests/auto/gui/image/qpicture/tst_qpicture.cpp107
-rw-r--r--tests/auto/gui/image/qpixmap/tst_qpixmap.cpp100
-rw-r--r--tests/auto/gui/kernel/kernel.pro1
-rw-r--r--tests/auto/gui/kernel/qclipboard/paster/main.cpp55
-rw-r--r--tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp79
-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.cpp73
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc6
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp6
-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/kernel/qwindow/tst_qwindow.cpp23
-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.cpp50
-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.cpp173
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp124
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp39
25 files changed, 1155 insertions, 179 deletions
diff --git a/tests/auto/gui/image/qicoimageformat/icons/valid/yellow.cur b/tests/auto/gui/image/qicoimageformat/icons/valid/yellow.cur
new file mode 100644
index 0000000000..0a649aa7f7
--- /dev/null
+++ b/tests/auto/gui/image/qicoimageformat/icons/valid/yellow.cur
Binary files differ
diff --git a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp
index cd9d4b448e..71adbabb84 100644
--- a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp
+++ b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp
@@ -111,9 +111,17 @@ void tst_QIcoImageFormat::cleanupTestCase()
void tst_QIcoImageFormat::format()
{
- QImageReader reader(m_IconPath + "/valid/35FLOPPY.ICO", "ico");
- QByteArray fmt = reader.format();
- QCOMPARE(const_cast<const char*>(fmt.data()), "ico" );
+ {
+ QImageReader reader(m_IconPath + "/valid/35FLOPPY.ICO", "ico");
+ QByteArray fmt = reader.format();
+ QCOMPARE(const_cast<const char*>(fmt.data()), "ico" );
+ }
+
+ {
+ QImageReader reader(m_IconPath + "/valid/yellow.cur", "ico");
+ QByteArray fmt = reader.format();
+ QCOMPARE(const_cast<const char*>(fmt.data()), "ico" );
+ }
}
void tst_QIcoImageFormat::canRead_data()
@@ -133,6 +141,7 @@ void tst_QIcoImageFormat::canRead_data()
QTest::newRow("103x16px, 24BPP") << "valid/trolltechlogo_tiny.ico" << 1;
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 1;
QTest::newRow("PNG compression") << "valid/Qt.ico" << 1;
+ QTest::newRow("CUR file") << "valid/yellow.cur" << 1;
}
void tst_QIcoImageFormat::canRead()
@@ -203,7 +212,7 @@ void tst_QIcoImageFormat::imageCount_data()
QTest::newRow("invalid floppy (first 8 bytes = 0xff)") << "invalid/35floppy.ico" << 0;
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 9;
QTest::newRow("PNG compression") << "valid/Qt.ico" << 4;
-
+ QTest::newRow("CUR file") << "valid/yellow.cur" << 1;
}
void tst_QIcoImageFormat::imageCount()
@@ -231,6 +240,7 @@ void tst_QIcoImageFormat::jumpToNextImage_data()
QTest::newRow("16px16c, 32px32c, 32px256c 2") << "valid/WORLDH.ico" << 3;
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 9;
QTest::newRow("PNG compression") << "valid/Qt.ico" << 4;
+ QTest::newRow("CUR file") << "valid/yellow.cur" << 1;
}
void tst_QIcoImageFormat::jumpToNextImage()
@@ -281,6 +291,7 @@ void tst_QIcoImageFormat::nextImageDelay_data()
QTest::newRow("invalid floppy (first 8 bytes = 0xff)") << "invalid/35floppy.ico" << -1;
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 9;
QTest::newRow("PNG compression") << "valid/Qt.ico" << 4;
+ QTest::newRow("CUR file") << "valid/yellow.cur" << 1;
}
void tst_QIcoImageFormat::nextImageDelay()
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 6c496ba6d4..d885ab6dd4 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.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.
@@ -62,6 +62,7 @@ public:
tst_QImage();
private slots:
+ void initTestCase();
void swap();
void create();
void createInvalidXPM();
@@ -173,12 +174,24 @@ private slots:
void scaled_QTBUG35972();
+ void convertToPixelFormat();
+ void convertToImageFormat_data();
+ void convertToImageFormat();
+
void cleanupFunctions();
+
+private:
+ const QString m_prefix;
};
tst_QImage::tst_QImage()
+ : m_prefix(QFINDTESTDATA("images/"))
+{
+}
+void tst_QImage::initTestCase()
{
+ QVERIFY(!m_prefix.isEmpty());
}
void tst_QImage::swap()
@@ -287,21 +300,17 @@ void tst_QImage::formatHandlersInput_data()
QTest::addColumn<QString>("testFormat");
QTest::addColumn<QString>("testFile");
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
-
// add a new line here when a file is added
- QTest::newRow("ICO") << "ICO" << prefix + "image.ico";
- QTest::newRow("PNG") << "PNG" << prefix + "image.png";
- QTest::newRow("GIF") << "GIF" << prefix + "image.gif";
- QTest::newRow("BMP") << "BMP" << prefix + "image.bmp";
- QTest::newRow("JPEG") << "JPEG" << prefix + "image.jpg";
- QTest::newRow("PBM") << "PBM" << prefix + "image.pbm";
- QTest::newRow("PGM") << "PGM" << prefix + "image.pgm";
- QTest::newRow("PPM") << "PPM" << prefix + "image.ppm";
- QTest::newRow("XBM") << "XBM" << prefix + "image.xbm";
- QTest::newRow("XPM") << "XPM" << prefix + "image.xpm";
+ QTest::newRow("ICO") << "ICO" << m_prefix + "image.ico";
+ QTest::newRow("PNG") << "PNG" << m_prefix + "image.png";
+ QTest::newRow("GIF") << "GIF" << m_prefix + "image.gif";
+ QTest::newRow("BMP") << "BMP" << m_prefix + "image.bmp";
+ QTest::newRow("JPEG") << "JPEG" << m_prefix + "image.jpg";
+ QTest::newRow("PBM") << "PBM" << m_prefix + "image.pbm";
+ QTest::newRow("PGM") << "PGM" << m_prefix + "image.pgm";
+ QTest::newRow("PPM") << "PPM" << m_prefix + "image.ppm";
+ QTest::newRow("XBM") << "XBM" << m_prefix + "image.xbm";
+ QTest::newRow("XPM") << "XPM" << m_prefix + "image.xpm";
}
void tst_QImage::formatHandlersInput()
@@ -762,6 +771,13 @@ void tst_QImage::convertToFormat_data()
<< int(QImage::Format_ARGB32_Premultiplied) << 0x7f7f7f7fu;
QTest::newRow("semiblack rgba8888 -> argb pm") << int(QImage::Format_RGBA8888) << 0x7f000000u
<< int(QImage::Format_ARGB32_Premultiplied) << 0x7f000000u;
+
+ QTest::newRow("red rgb30 -> argb32") << int(QImage::Format_RGB30) << 0xffff0000
+ << int(QImage::Format_ARGB32) << 0xffff0000;
+ QTest::newRow("green rgb30 -> argb32") << int(QImage::Format_RGB30) << 0xff00ff00
+ << int(QImage::Format_ARGB32) << 0xff00ff00;
+ QTest::newRow("blue rgb30 -> argb32") << int(QImage::Format_RGB30) << 0xff0000ff
+ << int(QImage::Format_ARGB32) << 0xff0000ff;
}
@@ -1074,10 +1090,7 @@ void tst_QImage::copy()
void tst_QImage::load()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("image.jpg");
+ const QString filePath = m_prefix + QLatin1String("image.jpg");
QImage dest(filePath);
QVERIFY(!dest.isNull());
@@ -1089,10 +1102,7 @@ void tst_QImage::load()
void tst_QImage::loadFromData()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("image.jpg");
+ const QString filePath = m_prefix + QLatin1String("image.jpg");
QImage original(filePath);
QVERIFY(!original.isNull());
@@ -1118,10 +1128,7 @@ void tst_QImage::loadFromData()
#if !defined(QT_NO_DATASTREAM)
void tst_QImage::loadFromDataStream()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("image.jpg");
+ const QString filePath = m_prefix + QLatin1String("image.jpg");
QImage original(filePath);
QVERIFY(!original.isNull());
@@ -1214,6 +1221,18 @@ void tst_QImage::setPixel_data()
QTest::newRow("RGBA8888 blue") << int(QImage::Format_RGBA8888)
<< 0xff0000ffu << 0xffff0000u;
#endif
+ QTest::newRow("A2BGR30_Premultiplied red") << int(QImage::Format_A2BGR30_Premultiplied)
+ << 0xffff0000u << 0xc00003ffu;
+ QTest::newRow("A2BGR30_Premultiplied green") << int(QImage::Format_A2BGR30_Premultiplied)
+ << 0xff00ff00u << 0xc00ffc00u;
+ QTest::newRow("A2BGR30_Premultiplied blue") << int(QImage::Format_A2BGR30_Premultiplied)
+ << 0xff0000ffu << 0xfff00000u;
+ QTest::newRow("RGB30 red") << int(QImage::Format_RGB30)
+ << 0xffff0000u << 0xfff00000u;
+ QTest::newRow("RGB30 green") << int(QImage::Format_RGB30)
+ << 0xff00ff00u << 0xc00ffc00u;
+ QTest::newRow("RGB30 blue") << int(QImage::Format_RGB30)
+ << 0xff0000ffu << 0xc00003ffu;
}
void tst_QImage::setPixel()
@@ -1240,6 +1259,8 @@ void tst_QImage::setPixel()
case int(QImage::Format_RGBX8888):
case int(QImage::Format_RGBA8888):
case int(QImage::Format_RGBA8888_Premultiplied):
+ case int(QImage::Format_A2BGR30_Premultiplied):
+ case int(QImage::Format_RGB30):
{
for (int y = 0; y < h; ++y) {
const quint32 *row = (const quint32*)(img.scanLine(y));
@@ -1959,6 +1980,8 @@ void tst_QImage::fillColor_data()
"ARGB4444pm",
"RGBx8888",
"RGBA8888pm",
+ "BGR30",
+ "A2RGB30pm",
0
};
@@ -1978,6 +2001,8 @@ void tst_QImage::fillColor_data()
QImage::Format_ARGB4444_Premultiplied,
QImage::Format_RGBX8888,
QImage::Format_RGBA8888_Premultiplied,
+ QImage::Format_BGR30,
+ QImage::Format_A2RGB30_Premultiplied,
};
for (int i=0; names[i] != 0; ++i) {
@@ -1996,6 +2021,7 @@ void tst_QImage::fillColor_data()
QTest::newRow("ARGB32, transparent") << QImage::Format_ARGB32 << Qt::transparent << 0x00000000u;
QTest::newRow("ARGB32pm, transparent") << QImage::Format_ARGB32_Premultiplied << Qt::transparent << 0x00000000u;
QTest::newRow("RGBA8888pm, transparent") << QImage::Format_RGBA8888_Premultiplied << Qt::transparent << 0x00000000u;
+ QTest::newRow("A2RGB30pm, transparent") << QImage::Format_A2RGB30_Premultiplied << Qt::transparent << 0x00000000u;
}
void tst_QImage::fillColor()
@@ -2112,6 +2138,8 @@ void tst_QImage::rgbSwapped_data()
QTest::newRow("Format_RGB444") << QImage::Format_RGB444;
QTest::newRow("Format_RGBX8888") << QImage::Format_RGBX8888;
QTest::newRow("Format_RGBA8888_Premultiplied") << QImage::Format_RGBA8888_Premultiplied;
+ QTest::newRow("Format_A2BGR30_Premultiplied") << QImage::Format_A2BGR30_Premultiplied;
+ QTest::newRow("Format_RGB30") << QImage::Format_RGB30;
}
void tst_QImage::rgbSwapped()
@@ -2180,6 +2208,8 @@ void tst_QImage::mirrored_data()
QTest::newRow("Format_RGB444, vertical") << QImage::Format_RGB444 << true << false << 16 << 16;
QTest::newRow("Format_RGBX8888, vertical") << QImage::Format_RGBX8888 << true << false << 16 << 16;
QTest::newRow("Format_RGBA8888_Premultiplied, vertical") << QImage::Format_RGBA8888_Premultiplied << true << false << 16 << 16;
+ QTest::newRow("Format_A2BGR30_Premultiplied, vertical") << QImage::Format_A2BGR30_Premultiplied << true << false << 16 << 16;
+ QTest::newRow("Format_RGB30, vertical") << QImage::Format_RGB30 << true << false << 16 << 16;
QTest::newRow("Format_Indexed8, vertical") << QImage::Format_Indexed8 << true << false << 16 << 16;
QTest::newRow("Format_Mono, vertical") << QImage::Format_Mono << true << false << 16 << 16;
QTest::newRow("Format_MonoLSB, vertical") << QImage::Format_MonoLSB << true << false << 16 << 16;
@@ -2279,6 +2309,7 @@ void tst_QImage::inplaceRgbSwapped_data()
QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied;
QTest::newRow("Format_RGBA8888") << QImage::Format_RGBA8888;
+ QTest::newRow("Format_A2RGB30_Premultiplied") << QImage::Format_A2RGB30_Premultiplied;
QTest::newRow("Format_RGB888") << QImage::Format_RGB888;
QTest::newRow("Format_RGB16") << QImage::Format_RGB16;
QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8;
@@ -2523,6 +2554,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/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
index b9d0adcd21..0c5d9f23b9 100644
--- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.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.
@@ -78,6 +78,7 @@ public:
public slots:
void init();
void cleanup();
+ void initTestCase();
void cleanupTestCase();
private slots:
@@ -171,6 +172,11 @@ private slots:
void detachOnLoad_QTBUG29639();
void copyOnNonAlignedBoundary();
+
+private:
+ const QString m_prefix;
+ const QString m_convertFromImage;
+ const QString m_loadFromData;
};
static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
@@ -207,6 +213,9 @@ static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
tst_QPixmap::tst_QPixmap()
+ : m_prefix(QFINDTESTDATA("images/"))
+ , m_convertFromImage(QFINDTESTDATA("convertFromImage"))
+ , m_loadFromData(QFINDTESTDATA("loadFromData"))
{
}
@@ -222,6 +231,13 @@ void tst_QPixmap::cleanup()
{
}
+void tst_QPixmap::initTestCase()
+{
+ QVERIFY(!m_prefix.isEmpty());
+ QVERIFY(!m_convertFromImage.isEmpty());
+ QVERIFY(!m_loadFromData.isEmpty());
+}
+
void tst_QPixmap::cleanupTestCase()
{
QFile::remove(QLatin1String("temp_image.png"));
@@ -312,22 +328,21 @@ void tst_QPixmap::convertFromImage_data()
{
QTest::addColumn<QImage>("img1");
QTest::addColumn<QImage>("img2");
- const QString prefix = QFINDTESTDATA("convertFromImage");
{
QImage img1;
QImage img2;
- QVERIFY(img1.load(prefix + "/task31722_0/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_0/img2.png"));
- QVERIFY(img1.load(prefix + "/task31722_0/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_0/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_0/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_0/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_0/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_0/img2.png"));
QTest::newRow("Task 31722 0") << img1 << img2;
}
{
QImage img1;
QImage img2;
- QVERIFY(img1.load(prefix + "/task31722_1/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_1/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_1/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_1/img2.png"));
QTest::newRow("Task 31722 1") << img1 << img2;
}
}
@@ -346,11 +361,10 @@ void tst_QPixmap::convertFromImage()
void tst_QPixmap::convertFromImageShouldDetach()
{
- const QString prefix = QFINDTESTDATA("convertFromImage");
QImage img1;
QImage img2;
- QVERIFY(img1.load(prefix + "/task31722_0/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_0/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_0/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_0/img2.png"));
QPixmap pix = QPixmap::fromImage(img1);
QPixmap pix1 = pix;
pix.convertFromImage(img2);
@@ -1202,10 +1216,7 @@ void tst_QPixmap::transformed2()
void tst_QPixmap::load()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("designer.png");
+ const QString filePath = m_prefix + QLatin1String("designer.png");
QPixmap dest(filePath);
QVERIFY(!dest.isNull());
@@ -1217,10 +1228,7 @@ void tst_QPixmap::load()
void tst_QPixmap::loadFromData()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("designer.png");
+ const QString filePath = m_prefix + QLatin1String("designer.png");
QPixmap original(filePath);
QVERIFY(!original.isNull());
@@ -1246,10 +1254,7 @@ void tst_QPixmap::loadFromData()
#if !defined(QT_NO_DATASTREAM)
void tst_QPixmap::loadFromDataStream()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("designer.png");
+ const QString filePath = m_prefix + QLatin1String("designer.png");
QPixmap original(filePath);
QVERIFY(!original.isNull());
@@ -1344,17 +1349,15 @@ void tst_QPixmap::loadFromDataImage_data()
{
QTest::addColumn<QString>("imagePath");
- const QString prefix = QFINDTESTDATA("loadFromData");
-
- QTest::newRow("designer_argb32.png") << prefix + "/designer_argb32.png";
+ QTest::newRow("designer_argb32.png") << m_loadFromData + "/designer_argb32.png";
// When no extension is provided we try all extensions that has been registered by image providers
- QTest::newRow("designer_argb32") << prefix + "/designer_argb32.png";
- QTest::newRow("designer_indexed8_no_alpha.png") << prefix + "/designer_indexed8_no_alpha.png";
- QTest::newRow("designer_indexed8_with_alpha.png") << prefix + "/designer_indexed8_with_alpha.png";
- QTest::newRow("designer_rgb32.png") << prefix + "/designer_rgb32.png";
- QTest::newRow("designer_indexed8_no_alpha.gif") << prefix + "/designer_indexed8_no_alpha.gif";
- QTest::newRow("designer_indexed8_with_alpha.gif") << prefix + "/designer_indexed8_with_alpha.gif";
- QTest::newRow("designer_rgb32.jpg") << prefix + "/designer_rgb32.jpg";
+ QTest::newRow("designer_argb32") << m_loadFromData + "/designer_argb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.png") << m_loadFromData + "/designer_indexed8_no_alpha.png";
+ QTest::newRow("designer_indexed8_with_alpha.png") << m_loadFromData + "/designer_indexed8_with_alpha.png";
+ QTest::newRow("designer_rgb32.png") << m_loadFromData + "/designer_rgb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.gif") << m_loadFromData + "/designer_indexed8_no_alpha.gif";
+ QTest::newRow("designer_indexed8_with_alpha.gif") << m_loadFromData + "/designer_indexed8_with_alpha.gif";
+ QTest::newRow("designer_rgb32.jpg") << m_loadFromData + "/designer_rgb32.jpg";
}
void tst_QPixmap::loadFromDataImage()
@@ -1378,17 +1381,15 @@ void tst_QPixmap::fromImageReader_data()
{
QTest::addColumn<QString>("imagePath");
- const QString prefix = QFINDTESTDATA("loadFromData");
-
- QTest::newRow("designer_argb32.png") << prefix + "/designer_argb32.png";
- QTest::newRow("designer_indexed8_no_alpha.png") << prefix + "/designer_indexed8_no_alpha.png";
- QTest::newRow("designer_indexed8_with_alpha.png") << prefix + "/designer_indexed8_with_alpha.png";
- QTest::newRow("designer_rgb32.png") << prefix + "/designer_rgb32.png";
- QTest::newRow("designer_indexed8_no_alpha.gif") << prefix + "/designer_indexed8_no_alpha.gif";
- QTest::newRow("designer_indexed8_with_alpha.gif") << prefix + "/designer_indexed8_with_alpha.gif";
- QTest::newRow("designer_rgb32.jpg") << prefix + "/designer_rgb32.jpg";
- QTest::newRow("designer_indexed8_with_alpha_animated") << prefix + "/designer_indexed8_with_alpha_animated.gif";
- QTest::newRow("designer_indexed8_no_alpha_animated") << prefix + "/designer_indexed8_no_alpha_animated.gif";
+ QTest::newRow("designer_argb32.png") << m_loadFromData + "/designer_argb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.png") << m_loadFromData + "/designer_indexed8_no_alpha.png";
+ QTest::newRow("designer_indexed8_with_alpha.png") << m_loadFromData + "/designer_indexed8_with_alpha.png";
+ QTest::newRow("designer_rgb32.png") << m_loadFromData + "/designer_rgb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.gif") << m_loadFromData + "/designer_indexed8_no_alpha.gif";
+ QTest::newRow("designer_indexed8_with_alpha.gif") << m_loadFromData + "/designer_indexed8_with_alpha.gif";
+ QTest::newRow("designer_rgb32.jpg") << m_loadFromData + "/designer_rgb32.jpg";
+ QTest::newRow("designer_indexed8_with_alpha_animated") << m_loadFromData + "/designer_indexed8_with_alpha_animated.gif";
+ QTest::newRow("designer_indexed8_no_alpha_animated") << m_loadFromData + "/designer_indexed8_no_alpha_animated.gif";
}
void tst_QPixmap::fromImageReader()
@@ -1416,8 +1417,7 @@ void tst_QPixmap::fromImageReaderAnimatedGif()
{
QFETCH(QString, imagePath);
- const QString prefix = QFINDTESTDATA("loadFromData");
- const QString path = prefix + imagePath;
+ const QString path = m_loadFromData + imagePath;
QImageReader referenceReader(path);
QImageReader pixmapReader(path);
@@ -1533,14 +1533,12 @@ void tst_QPixmap::scaled_QTBUG19157()
void tst_QPixmap::detachOnLoad_QTBUG29639()
{
- const QString prefix = QFINDTESTDATA("convertFromImage");
-
QPixmap a;
- a.load(prefix + "/task31722_0/img1.png");
- a.load(prefix + "/task31722_0/img2.png");
+ a.load(m_convertFromImage + "/task31722_0/img1.png");
+ a.load(m_convertFromImage + "/task31722_0/img2.png");
QPixmap b;
- b.load(prefix + "/task31722_0/img1.png");
+ b.load(m_convertFromImage + "/task31722_0/img1.png");
QVERIFY(a.toImage() != b.toImage());
}
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/paster/main.cpp b/tests/auto/gui/kernel/qclipboard/paster/main.cpp
index 0dd7dd87af..3fd4267598 100644
--- a/tests/auto/gui/kernel/qclipboard/paster/main.cpp
+++ b/tests/auto/gui/kernel/qclipboard/paster/main.cpp
@@ -40,20 +40,59 @@
****************************************************************************/
#include <QtGui/QGuiApplication>
#include <QtGui/QClipboard>
+#include <QtGui/QImage>
+#include <QtGui/QColor>
#include <QtCore/QStringList>
+#include <QtCore/QCommandLineParser>
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- QString expected = QStringLiteral("testString.!");
-#ifndef Q_OS_WINCE
- const QStringList arguments = app.arguments();
- if (arguments.size() > 1)
- expected = arguments.at(1);
+ QCommandLineParser parser;
+ parser.addHelpOption();
+ QCommandLineOption textOption(QStringLiteral("text"),
+ QStringLiteral("Text to compare"),
+ QStringLiteral("text"));
+ parser.addOption(textOption);
+ QCommandLineOption imageOption(QStringLiteral("image"),
+ QStringLiteral("Perform image check"));
+ parser.addOption(imageOption);
+ parser.process(QCoreApplication::arguments());
+
+ if (parser.isSet(imageOption)) {
+#ifndef QT_NO_CLIPBOARD
+ const QImage actual = QGuiApplication::clipboard()->image();
+#else
+ const QImage actual;
#endif
- QString actual;
+ // Perform hard-coded checks on copied image (size, pixel 0,0: transparent,
+ // pixel 1,0: blue). Note: Windows sets RGB of transparent to 0xFF when converting
+ // to DIB5.
+ if (actual.size() != QSize(100, 100))
+ return 1;
+ const QRgb pixel00 = actual.pixel(QPoint(0, 0));
+ if (qAlpha(pixel00))
+ return 2;
+ const QRgb pixel01 = actual.pixel(QPoint(1, 0));
+ if (pixel01 != QColor(Qt::blue).rgba())
+ return 3;
+ return 0;
+ }
+
+#ifndef Q_OS_WINCE
+ QString expected;
+ if (parser.isSet(textOption))
+ expected = parser.value(textOption);
+#else // !Q_OS_WINCE
+ const QString expected = QStringLiteral("testString.!");
+#endif // Q_OS_WINCE
+ if (!expected.isEmpty()) {
#ifndef QT_NO_CLIPBOARD
- actual = QGuiApplication::clipboard()->text();
+ const QString actual = QGuiApplication::clipboard()->text();
+#else
+ const QString actual;
#endif
- return actual == expected ? 0 : 1;
+ return actual == expected ? 0 : 1;
+ }
+ return -2;
}
diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
index cf786c1dca..b677ee1ea4 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.
@@ -46,6 +46,8 @@
#include <QtCore/QDir>
#include <QtGui/QGuiApplication>
#include <QtGui/QClipboard>
+#include <QtGui/QImage>
+#include <QtGui/QColor>
#include "../../../shared/platformclipboard.h"
class tst_QClipboard : public QObject
@@ -59,6 +61,7 @@ private slots:
void init();
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_QNX)
void copy_exit_paste();
+ void copyImage();
#endif
void capabilityFunctions();
void modes();
@@ -134,6 +137,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 +175,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 +189,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);
@@ -248,18 +281,42 @@ void tst_QClipboard::copy_exit_paste()
// ### It's still possible to test copy/paste - just keep the apps running
if (!PlatformClipboard::isAvailable())
QSKIP("Native clipboard not working in this setup");
- const QStringList stringArgument(QStringLiteral("Test string."));
+ const QString stringArgument(QStringLiteral("Test string."));
QByteArray errorMessage;
- QVERIFY2(runHelper(QStringLiteral("copier/copier"), stringArgument, &errorMessage),
+ QVERIFY2(runHelper(QStringLiteral("copier/copier"), QStringList(stringArgument), &errorMessage),
errorMessage.constData());
#ifdef Q_OS_MAC
// The Pasteboard needs a moment to breathe (at least on older Macs).
QTest::qWait(100);
#endif // Q_OS_MAC
- QVERIFY2(runHelper(QStringLiteral("paster/paster"), stringArgument, &errorMessage),
+ QVERIFY2(runHelper(QStringLiteral("paster/paster"),
+ QStringList() << QStringLiteral("--text") << stringArgument,
+ &errorMessage),
errorMessage.constData());
#endif // QT_NO_PROCESS
}
+
+void tst_QClipboard::copyImage()
+{
+#ifndef QT_NO_PROCESS
+ if (!PlatformClipboard::isAvailable())
+ QSKIP("Native clipboard not working in this setup");
+ QImage image(100, 100, QImage::Format_ARGB32);
+ image.fill(QColor(Qt::transparent));
+ image.setPixel(QPoint(1, 0), QColor(Qt::blue).rgba());
+ QGuiApplication::clipboard()->setImage(image);
+#ifdef Q_OS_OSX
+ // The Pasteboard needs a moment to breathe (at least on older Macs).
+ QTest::qWait(100);
+#endif // Q_OS_OSX
+ // paster will perform hard-coded checks on the copied image.
+ QByteArray errorMessage;
+ QVERIFY2(runHelper(QStringLiteral("paster/paster"),
+ QStringList(QStringLiteral("--image")), &errorMessage),
+ errorMessage.constData());
+#endif // QT_NO_PROCESS
+}
+
#endif // Q_OS_WIN || Q_OS_MAC || Q_OS_QNX
void tst_QClipboard::setMimeData()
@@ -296,6 +353,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 +374,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 +388,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 +406,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..9a6b9f488b 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -45,6 +45,7 @@
#include <QtGui/QWindow>
#include <QtGui/QScreen>
#include <QtGui/QCursor>
+#include <QtGui/QPalette>
#include <qpa/qwindowsysteminterface.h>
#include <qgenericplugin.h>
@@ -65,15 +66,18 @@ class tst_QGuiApplication: public tst_QCoreApplication
private slots:
void displayName();
void firstWindowTitle();
+ void windowIcon();
void focusObject();
void allWindows();
void topLevelWindows();
void abortQuitOnShow();
void changeFocusWindow();
void keyboardModifiers();
+ void palette();
void modalWindow();
void quitOnLastWindowClosed();
void genericPluginsAndWindowSystemEvents();
+ void layoutDirection();
};
void tst_QGuiApplication::displayName()
@@ -99,6 +103,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:
@@ -414,6 +436,31 @@ void tst_QGuiApplication::keyboardModifiers()
window->close();
}
+void tst_QGuiApplication::palette()
+{
+ int argc = 1;
+ char *argv[] = { const_cast<char*>("tst_qguiapplication") };
+ QGuiApplication app(argc, argv);
+ QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette)));
+
+ QPalette oldPalette = QGuiApplication::palette();
+ QPalette newPalette = QPalette(Qt::red);
+
+ QGuiApplication::setPalette(newPalette);
+ QCOMPARE(QGuiApplication::palette(), newPalette);
+ QCOMPARE(signalSpy.count(), 1);
+ QCOMPARE(signalSpy.at(0).at(0), QVariant(newPalette));
+
+ QGuiApplication::setPalette(oldPalette);
+ QCOMPARE(QGuiApplication::palette(), oldPalette);
+ QCOMPARE(signalSpy.count(), 2);
+ QCOMPARE(signalSpy.at(1).at(0), QVariant(oldPalette));
+
+ QGuiApplication::setPalette(oldPalette);
+ QCOMPARE(QGuiApplication::palette(), oldPalette);
+ QCOMPARE(signalSpy.count(), 2);
+}
+
class BlockableWindow : public QWindow
{
Q_OBJECT
@@ -829,4 +876,30 @@ void tst_QGuiApplication::genericPluginsAndWindowSystemEvents()
QCOMPARE(testReceiver.customEvents, 1);
}
+Q_DECLARE_METATYPE(Qt::LayoutDirection)
+void tst_QGuiApplication::layoutDirection()
+{
+ qRegisterMetaType<Qt::LayoutDirection>();
+
+ Qt::LayoutDirection oldDirection = QGuiApplication::layoutDirection();
+ Qt::LayoutDirection newDirection = oldDirection == Qt::LeftToRight ? Qt::RightToLeft : Qt::LeftToRight;
+
+ QGuiApplication::setLayoutDirection(newDirection);
+ QCOMPARE(QGuiApplication::layoutDirection(), newDirection);
+
+ int argc = 1;
+ char *argv[] = { const_cast<char*>("tst_qguiapplication") };
+ QGuiApplication app(argc, argv);
+ QSignalSpy signalSpy(&app, SIGNAL(layoutDirectionChanged(Qt::LayoutDirection)));
+
+ QGuiApplication::setLayoutDirection(oldDirection);
+ QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
+ QCOMPARE(signalSpy.count(), 1);
+ QCOMPARE(signalSpy.at(0).at(0).toInt(), static_cast<int>(oldDirection));
+
+ QGuiApplication::setLayoutDirection(oldDirection);
+ QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
+ QCOMPARE(signalSpy.count(), 1);
+}
+
QTEST_APPLESS_MAIN(tst_QGuiApplication)
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/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index 431db86330..dc139cfa94 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -145,18 +145,16 @@ void tst_QGuiVariant::constructor_invalid()
QFETCH(uint, typeId);
{
- MessageHandlerInvalidType msg;
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:"));
QVariant variant(static_cast<QVariant::Type>(typeId));
QVERIFY(!variant.isValid());
QVERIFY(variant.userType() == QMetaType::UnknownType);
- QVERIFY(msg.ok);
}
{
- MessageHandlerInvalidType msg;
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:"));
QVariant variant(typeId, /* copy */ 0);
QVERIFY(!variant.isValid());
QVERIFY(variant.userType() == QMetaType::UnknownType);
- QVERIFY(msg.ok);
}
}
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/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 868288e36e..9517264e55 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -67,6 +67,7 @@ private slots:
void mapGlobal();
void positioning_data();
void positioning();
+ void positioningDuringMinimized();
void isExposed();
void isActive();
void testInputEvents();
@@ -306,6 +307,28 @@ void tst_QWindow::positioning()
}
}
+void tst_QWindow::positioningDuringMinimized()
+{
+ // QTBUG-39544, setting a geometry in minimized state should work as well.
+ if (QGuiApplication::platformName().compare("windows", Qt::CaseInsensitive))
+ QSKIP("Not supported on this platform");
+ Window window;
+ window.setTitle(QStringLiteral("positioningDuringMinimized"));
+ const QRect initialGeometry(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(100, 100),
+ QSize(200, 200));
+ window.setGeometry(initialGeometry);
+ window.showNormal();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QCOMPARE(window.geometry(), initialGeometry);
+ window.setWindowState(Qt::WindowMinimized);
+ QCOMPARE(window.geometry(), initialGeometry);
+ const QRect newGeometry(initialGeometry.topLeft() + QPoint(50, 50), initialGeometry.size() + QSize(50, 50));
+ window.setGeometry(newGeometry);
+ QTRY_COMPARE(window.geometry(), newGeometry);
+ window.setWindowState(Qt::WindowNoState);
+ QTRY_COMPARE(window.geometry(), newGeometry);
+}
+
void tst_QWindow::isExposed()
{
QRect geometry(80, 80, 40, 40);
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..5af5b1a269 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();
@@ -1134,6 +1136,8 @@ void tst_QPainter::fillRect2_data()
QTest::newRow("argb32pm") << QImage::Format_ARGB32_Premultiplied;
QTest::newRow("rgba8888") << QImage::Format_RGBA8888;
QTest::newRow("rgba8888pm") << QImage::Format_RGBA8888_Premultiplied;
+ QTest::newRow("a2rgb30pm") << QImage::Format_A2RGB30_Premultiplied;
+ QTest::newRow("a2bgr30pm") << QImage::Format_A2BGR30_Premultiplied;
}
void tst_QPainter::fillRect2()
@@ -1526,6 +1530,8 @@ void tst_QPainter::qimageFormats_data()
QTest::newRow("Qimage::Format_RGB555") << QImage::Format_RGB555;
QTest::newRow("Qimage::Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied;
QTest::newRow("Qimage::Format_RGB888") << QImage::Format_RGB888;
+ QTest::newRow("Qimage::Format_A2RGB30_Premultiplied") << QImage::Format_A2RGB30_Premultiplied;
+ QTest::newRow("Qimage::Format_RGB30") << QImage::Format_RGB30;
}
/*
@@ -2342,6 +2348,26 @@ void tst_QPainter::setOpacity_data()
QTest::newRow("RGB32 on RGBx8888") << QImage::Format_RGB32
<< QImage::Format_RGBX8888;
+
+ QTest::newRow("A2RGB30P on A2RGB30P") << QImage::Format_A2RGB30_Premultiplied
+ << QImage::Format_A2RGB30_Premultiplied;
+
+ QTest::newRow("ARGB32P on A2RGB30P") << QImage::Format_ARGB32_Premultiplied
+ << QImage::Format_A2RGB30_Premultiplied;
+
+
+ QTest::newRow("RGB32 on A2BGR30P") << QImage::Format_ARGB32_Premultiplied
+ << QImage::Format_A2BGR30_Premultiplied;
+
+ QTest::newRow("A2RGB30P on A2BGR30P") << QImage::Format_A2RGB30_Premultiplied
+ << QImage::Format_A2BGR30_Premultiplied;
+
+ QTest::newRow("ARGB32P on BGR30") << QImage::Format_ARGB32_Premultiplied
+ << QImage::Format_BGR30;
+
+ QTest::newRow("ARGB32P on RGB30") << QImage::Format_A2RGB30_Premultiplied
+ << QImage::Format_RGB30;
+
}
void tst_QPainter::setOpacity()
@@ -2430,7 +2456,9 @@ void tst_QPainter::drawhelper_blend_untransformed()
dest.bytesPerLine(), dest.format());
if (dest.format() == QImage::Format_ARGB8565_Premultiplied ||
- dest.format() == QImage::Format_ARGB8555_Premultiplied) {
+ dest.format() == QImage::Format_ARGB8555_Premultiplied ||
+ dest.format() == QImage::Format_A2BGR30_Premultiplied ||
+ dest.format() == QImage::Format_A2RGB30_Premultiplied ) {
// Test skipped due to rounding errors...
continue;
}
@@ -4473,6 +4501,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..85297de1e1 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):!contains(QT_CONFIG, opengles2): DEFINES += USE_GLX
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index 63fe8b9693..972c2a7ea4 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -43,6 +43,7 @@
#include <QtGui/private/qopenglcontext_p.h>
#include <QtGui/QOpenGLFramebufferObject>
#include <QtGui/QOpenGLFunctions>
+#include <QtGui/QOpenGLVertexArrayObject>
#include <QtGui/QOpenGLPaintDevice>
#include <QtGui/QPainter>
#include <QtGui/QScreen>
@@ -51,12 +52,25 @@
#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
+
+#if defined(Q_OS_WIN32) && !defined(QT_OPENGL_ES_2)
+#include <QtPlatformHeaders/QWGLNativeContext>
+#endif
+
+Q_DECLARE_METATYPE(QImage::Format)
+
class tst_QOpenGL : public QObject
{
Q_OBJECT
@@ -85,6 +99,16 @@ private slots:
void textureblitterPartOriginTopLeftSourceRectTransform();
void textureblitterFullTargetRectTransform();
void textureblitterPartTargetRectTransform();
+
+#ifdef USE_GLX
+ void glxContextWrap();
+#endif
+
+#if defined(Q_OS_WIN32) && !defined(QT_OPENGL_ES_2)
+ void wglContextWrap();
+#endif
+
+ void vaoCreate();
};
struct SharedResourceTracker
@@ -448,9 +472,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 +518,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 +528,7 @@ void tst_QOpenGL::fboTextureOwnership()
QFUZZY_COMPARE_IMAGES(fb, reference);
- glDeleteTextures(1, &texture);
+ ctx.functions()->glDeleteTextures(1, &texture);
delete fbo;
}
@@ -591,7 +615,14 @@ void tst_QOpenGL::fboHandleNulledAfterContextDestroyed()
void tst_QOpenGL::openGLPaintDevice_data()
{
- common_data();
+ QTest::addColumn<int>("surfaceClass");
+ QTest::addColumn<QImage::Format>("imageFormat");
+
+ QTest::newRow("Using QWindow - RGB32") << int(QSurface::Window) << QImage::Format_RGB32;
+ QTest::newRow("Using QOffscreenSurface - RGB32") << int(QSurface::Offscreen) << QImage::Format_RGB32;
+ QTest::newRow("Using QOffscreenSurface - RGBx8888") << int(QSurface::Offscreen) << QImage::Format_RGBX8888;
+ QTest::newRow("Using QOffscreenSurface - RGB888") << int(QSurface::Offscreen) << QImage::Format_RGB888;
+ QTest::newRow("Using QOffscreenSurface - RGB16") << int(QSurface::Offscreen) << QImage::Format_RGB16;
}
void tst_QOpenGL::openGLPaintDevice()
@@ -601,6 +632,7 @@ void tst_QOpenGL::openGLPaintDevice()
#endif
QFETCH(int, surfaceClass);
+ QFETCH(QImage::Format, imageFormat);
QScopedPointer<QSurface> surface(createSurface(surfaceClass));
QOpenGLContext ctx;
@@ -613,7 +645,7 @@ void tst_QOpenGL::openGLPaintDevice()
const QSize size(128, 128);
- QImage image(size, QImage::Format_RGB32);
+ QImage image(size, imageFormat);
QPainter p(&image);
p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red);
p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green);
@@ -632,7 +664,7 @@ void tst_QOpenGL::openGLPaintDevice()
p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white);
p.end();
- QImage actual = fbo.toImage().convertToFormat(QImage::Format_RGB32);
+ QImage actual = fbo.toImage().convertToFormat(imageFormat);
QCOMPARE(image.size(), actual.size());
QCOMPARE(image, actual);
@@ -641,7 +673,7 @@ void tst_QOpenGL::openGLPaintDevice()
p.drawImage(0, 0, image);
p.end();
- actual = fbo.toImage().convertToFormat(QImage::Format_RGB32);
+ actual = fbo.toImage().convertToFormat(imageFormat);
QCOMPARE(image.size(), actual.size());
QCOMPARE(image, actual);
@@ -650,7 +682,7 @@ void tst_QOpenGL::openGLPaintDevice()
p.fillRect(0, 0, image.width(), image.height(), QBrush(image));
p.end();
- actual = fbo.toImage().convertToFormat(QImage::Format_RGB32);
+ actual = fbo.toImage().convertToFormat(imageFormat);
QCOMPARE(image.size(), actual.size());
QCOMPARE(image, actual);
}
@@ -970,6 +1002,121 @@ 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
+
+#if defined(Q_OS_WIN32) && !defined(QT_OPENGL_ES_2)
+void tst_QOpenGL::wglContextWrap()
+{
+ QScopedPointer<QOpenGLContext> ctx(new QOpenGLContext);
+ QVERIFY(ctx->create());
+ if (ctx->isOpenGLES())
+ QSKIP("Not applicable to EGL");
+
+ QScopedPointer<QWindow> window(new QWindow);
+ window->setSurfaceType(QWindow::OpenGLSurface);
+ window->setGeometry(0, 0, 256, 256);
+ window->show();
+ QTest::qWaitForWindowExposed(window.data());
+
+ QVariant v = ctx->nativeHandle();
+ QVERIFY(!v.isNull());
+ QVERIFY(v.canConvert<QWGLNativeContext>());
+ QWGLNativeContext nativeContext = v.value<QWGLNativeContext>();
+ QVERIFY(nativeContext.context());
+
+ // Now do a makeCurrent() do make sure the pixel format on the native
+ // window (the HWND we are going to retrieve below) is set.
+ QVERIFY(ctx->makeCurrent(window.data()));
+ ctx->doneCurrent();
+
+ HWND wnd = (HWND) qGuiApp->platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("handle"), window.data());
+ QVERIFY(wnd);
+
+ QScopedPointer<QOpenGLContext> adopted(new QOpenGLContext);
+ adopted->setNativeHandle(QVariant::fromValue<QWGLNativeContext>(QWGLNativeContext(nativeContext.context(), wnd)));
+ QVERIFY(adopted->create());
+
+ // This tests two things: that a regular, non-adopted QOpenGLContext is
+ // able to return a QSurfaceFormat containing the real values after
+ // create(), and that the adopted context got the correct pixel format from
+ // window and was able to update its format accordingly.
+ QCOMPARE(adopted->format().version(), ctx->format().version());
+ QCOMPARE(adopted->format().profile(), ctx->format().profile());
+ QVERIFY(ctx->format().redBufferSize() > 0);
+ QCOMPARE(adopted->format().redBufferSize(), ctx->format().redBufferSize());
+ QVERIFY(ctx->format().greenBufferSize() > 0);
+ QCOMPARE(adopted->format().greenBufferSize(), ctx->format().greenBufferSize());
+ QVERIFY(ctx->format().blueBufferSize() > 0);
+ QCOMPARE(adopted->format().blueBufferSize(), ctx->format().blueBufferSize());
+ QVERIFY(ctx->format().depthBufferSize() > 0);
+ QCOMPARE(adopted->format().depthBufferSize(), ctx->format().depthBufferSize());
+ QVERIFY(ctx->format().stencilBufferSize() > 0);
+ QCOMPARE(adopted->format().stencilBufferSize(), ctx->format().stencilBufferSize());
+
+ // This must work since we are using the exact same window.
+ QVERIFY(adopted->makeCurrent(window.data()));
+ adopted->doneCurrent();
+}
+#endif // Q_OS_WIN32 && !QT_OPENGL_ES_2
+
+void tst_QOpenGL::vaoCreate()
+{
+ QScopedPointer<QSurface> surface(createSurface(QSurface::Window));
+ QOpenGLContext *ctx = new QOpenGLContext;
+ ctx->create();
+ ctx->makeCurrent(surface.data());
+
+ QOpenGLVertexArrayObject vao;
+ bool success = vao.create();
+ if (ctx->isOpenGLES()) {
+ if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object")))
+ QVERIFY(success);
+ } else {
+ if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object")))
+ QVERIFY(success);
+ }
+
+ vao.destroy();
+ ctx->doneCurrent();
+}
+
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 995f7a0378..57cf3a1fb6 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);