autotests: Fix testWindowmanagement

Currently, testIcon fails because the actual and the expected pixmaps
have mismatching formats.

The root cause is that images with an alpha channel will loose the alpha
channel if they are converted to QPixmap using QPixmap::fromImage().

The >> stream operator for the QPixmap class will deserialize pixel data
in a temporary QImage and then use QPixmap::fromImage() to get a pixmap
object.

The >> stream operator for the QIcon class will delegate the task of
reading the icon from a QDataStream to QPixmapIconEngine, which uses the
>> stream operator under the hood to deserialize icon data.

In order to fix testIcon, this change constructs a dummy icon from a
pixmap object returned by QPixmap::fromImage().
This commit is contained in:
Vlad Zahorodnii 2021-03-16 15:03:38 +02:00
parent bdb138bdcd
commit f321882177

View file

@ -586,12 +586,13 @@ void TestWindowManagement::testIcon()
QCOMPARE(m_window->icon().name(), QStringLiteral("wayland"));
// create an icon with a pixmap
QPixmap p(32, 32);
QImage p(32, 32, QImage::Format_ARGB32_Premultiplied);
p.fill(Qt::red);
m_windowInterface->setIcon(p);
const QIcon dummyIcon(QPixmap::fromImage(p));
m_windowInterface->setIcon(dummyIcon);
QVERIFY(iconChangedSpy.wait());
QCOMPARE(iconChangedSpy.count(), 3);
QCOMPARE(m_window->icon().pixmap(32, 32), p);
QCOMPARE(m_window->icon().pixmap(32, 32), dummyIcon.pixmap(32, 32));
// let's set a themed icon
m_windowInterface->setIcon(QIcon::fromTheme(QStringLiteral("xorg")));