tst_QImageReader: fix missing checks for "newly"-added ImageOptions

The following commits neglected to amend
tst_QImageReader::supportsOption() with the ImageOption enumerators
they added to QImageIOHandler:

- c0ba249a48fd85ee8e047ff47448a4ed32d6cd91
- 163af2cf53d3441b453744b99254c07a175af5de
- ba323b04cd78fb43e9e63b891e973d24b08250af

Fix first and foremost by adding the missing ImageOption::ImageFormat
to the list of PNG-supported formats (which, curiously enough, predates
the public history and therefore the above three commits), and second,
by rewriting the whole test function to enable -Wswitch, so further
additions are less likely to be forgotten.

Change-Id: I102121b2c8a9067864b8ade2ebe2650be6fb6010
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
(cherry picked from commit 679bb388f09ca09f29ad23d22f9b381bf4f6eea0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-08-08 20:06:24 +02:00 committed by Qt Cherry-pick Bot
parent 1d84c2d479
commit 7dda27c95e

View File

@ -12,6 +12,7 @@
#include <QImageWriter>
#include <QPixmap>
#include <QSet>
#include <QScopeGuard>
#include <QTcpSocket>
#include <QTcpServer>
#include <QTimer>
@ -1623,43 +1624,56 @@ void tst_QImageReader::supportsOption_data()
QTest::addColumn<QIntList>("options");
QTest::newRow("png") << QString("black.png")
<< (QIntList() << QImageIOHandler::Gamma
<< QImageIOHandler::Description
<< QImageIOHandler::Quality
<< QImageIOHandler::CompressionRatio
<< QImageIOHandler::Size
<< QImageIOHandler::ScaledSize);
<< QIntList{
QImageIOHandler::Gamma,
QImageIOHandler::Description,
QImageIOHandler::Quality,
QImageIOHandler::CompressionRatio,
QImageIOHandler::Size,
QImageIOHandler::ScaledSize,
QImageIOHandler::ImageFormat,
};
}
void tst_QImageReader::supportsOption()
{
QFETCH(QString, fileName);
QFETCH(QIntList, options);
QSet<QImageIOHandler::ImageOption> allOptions;
allOptions << QImageIOHandler::Size
<< QImageIOHandler::ClipRect
<< QImageIOHandler::Description
<< QImageIOHandler::ScaledClipRect
<< QImageIOHandler::ScaledSize
<< QImageIOHandler::CompressionRatio
<< QImageIOHandler::Gamma
<< QImageIOHandler::Quality
<< QImageIOHandler::Name
<< QImageIOHandler::SubType
<< QImageIOHandler::IncrementalReading
<< QImageIOHandler::Endianness
<< QImageIOHandler::Animation
<< QImageIOHandler::BackgroundColor;
QFETCH(const QIntList, options);
QImageReader reader(prefix + fileName);
for (int i = 0; i < options.size(); ++i) {
QVERIFY(reader.supportsOption(QImageIOHandler::ImageOption(options.at(i))));
allOptions.remove(QImageIOHandler::ImageOption(options.at(i)));
}
foreach (QImageIOHandler::ImageOption option, allOptions)
QVERIFY(!reader.supportsOption(option));
for (int i = 0; ; ++i) {
// this switch ensures the compiler warns when we miss an enumerator [-Wswitch]
// do _not_ add a default case!
switch (const auto o = QImageIOHandler::ImageOption(i)) {
case QImageIOHandler::Size:
case QImageIOHandler::ClipRect:
case QImageIOHandler::Description:
case QImageIOHandler::ScaledClipRect:
case QImageIOHandler::ScaledSize:
case QImageIOHandler::CompressionRatio:
case QImageIOHandler::Gamma:
case QImageIOHandler::Quality:
case QImageIOHandler::Name:
case QImageIOHandler::SubType:
case QImageIOHandler::IncrementalReading:
case QImageIOHandler::Endianness:
case QImageIOHandler::Animation:
case QImageIOHandler::BackgroundColor:
case QImageIOHandler::ImageFormat:
case QImageIOHandler::SupportedSubTypes:
case QImageIOHandler::OptimizedWrite:
case QImageIOHandler::ProgressiveScanWrite:
case QImageIOHandler::ImageTransformation:
{
auto printOnFailure = qScopeGuard([&] { qDebug("failed at %d", i); });
QCOMPARE(reader.supportsOption(o), options.contains(i));
printOnFailure.dismiss();
continue; // ... as long as `i` represents a valid ImageOption value
}
}
break; // ... once `i` no longer represents a valid ImageOption value
}
}
void tst_QImageReader::autoDetectImageFormat()