tst_QStaticText: Output verbose message for test failures.
Factor out function to check on the pixel color that outputs a verbose message on failure. Change-Id: I2331fe45f35327d1ff8ae547a58d93a2e6fe9184 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
This commit is contained in:
parent
1fd0d57ce3
commit
45dc347a95
@ -610,6 +610,29 @@ void tst_QStaticText::plainTextVsRichText()
|
||||
QCOMPARE(imagePlainText, imageRichText);
|
||||
}
|
||||
|
||||
static bool checkPixels(const QImage &image,
|
||||
Qt::GlobalColor expectedColor1, Qt::GlobalColor expectedColor2,
|
||||
QByteArray *errorMessage)
|
||||
{
|
||||
const QRgb expectedRgb1 = QColor(expectedColor1).rgba();
|
||||
const QRgb expectedRgb2 = QColor(expectedColor2).rgba();
|
||||
|
||||
for (int x = 0, w = image.width(); x < w; ++x) {
|
||||
for (int y = 0, h = image.height(); y < h; ++y) {
|
||||
const QRgb pixel = image.pixel(x, y);
|
||||
if (pixel != expectedRgb1 && pixel != expectedRgb2) {
|
||||
QString message;
|
||||
QDebug(&message) << "Color mismatch in image" << image
|
||||
<< "at" << x << ',' << y << ':' << showbase << hex << pixel
|
||||
<< "(expected: " << expectedRgb1 << ',' << expectedRgb2 << ')';
|
||||
*errorMessage = message.toLocal8Bit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void tst_QStaticText::setPenPlainText_data()
|
||||
{
|
||||
QTest::addColumn<QImage::Format>("format");
|
||||
@ -640,13 +663,9 @@ void tst_QStaticText::setPenPlainText()
|
||||
p.drawStaticText(0, 0, staticText);
|
||||
}
|
||||
|
||||
for (int x=0; x<image.width(); ++x) {
|
||||
for (int y=0; y<image.height(); ++y) {
|
||||
QRgb pixel = image.pixel(x, y);
|
||||
QVERIFY(pixel == QColor(Qt::white).rgba()
|
||||
|| pixel == QColor(Qt::yellow).rgba());
|
||||
}
|
||||
}
|
||||
QByteArray errorMessage;
|
||||
QVERIFY2(checkPixels(image, Qt::yellow, Qt::white, &errorMessage),
|
||||
errorMessage.constData());
|
||||
}
|
||||
|
||||
void tst_QStaticText::setPenRichText()
|
||||
@ -668,14 +687,9 @@ void tst_QStaticText::setPenRichText()
|
||||
p.drawStaticText(0, 0, staticText);
|
||||
}
|
||||
|
||||
QImage img = image.toImage();
|
||||
for (int x=0; x<img.width(); ++x) {
|
||||
for (int y=0; y<img.height(); ++y) {
|
||||
QRgb pixel = img.pixel(x, y);
|
||||
QVERIFY(pixel == QColor(Qt::white).rgba()
|
||||
|| pixel == QColor(Qt::green).rgba());
|
||||
}
|
||||
}
|
||||
QByteArray errorMessage;
|
||||
QVERIFY2(checkPixels(image.toImage(), Qt::green, Qt::white, &errorMessage),
|
||||
errorMessage.constData());
|
||||
}
|
||||
|
||||
void tst_QStaticText::richTextOverridesPen()
|
||||
@ -697,14 +711,9 @@ void tst_QStaticText::richTextOverridesPen()
|
||||
p.drawStaticText(0, 0, staticText);
|
||||
}
|
||||
|
||||
QImage img = image.toImage();
|
||||
for (int x=0; x<img.width(); ++x) {
|
||||
for (int y=0; y<img.height(); ++y) {
|
||||
QRgb pixel = img.pixel(x, y);
|
||||
QVERIFY(pixel == QColor(Qt::white).rgba()
|
||||
|| pixel == QColor(Qt::red).rgba());
|
||||
}
|
||||
}
|
||||
QByteArray errorMessage;
|
||||
QVERIFY2(checkPixels(image.toImage(), Qt::red, Qt::white, &errorMessage),
|
||||
errorMessage.constData());
|
||||
}
|
||||
|
||||
void tst_QStaticText::drawStruckOutText()
|
||||
|
Loading…
x
Reference in New Issue
Block a user