diff options
author | aavit <qt-info@nokia.com> | 2010-09-03 08:29:10 (GMT) |
---|---|---|
committer | aavit <qt-info@nokia.com> | 2010-09-03 08:29:10 (GMT) |
commit | 0d18809a78021709f024e85c5251815a5864a7e3 (patch) | |
tree | 0066a909bb2941c853c9f6596b70de9a44f51302 /tests/auto/lancelot | |
parent | 38f0e9dbf41ebc8707398279ccb7038d3927c2d8 (diff) | |
download | Qt-0d18809a78021709f024e85c5251815a5864a7e3.zip Qt-0d18809a78021709f024e85c5251815a5864a7e3.tar.gz Qt-0d18809a78021709f024e85c5251815a5864a7e3.tar.bz2 |
Protocol rewrite done; design cleaned up.
Client no longer fetches baseline images, not even on mismatch.
Bitwise comparison, mismatch score etc. will be done on server, if
wanted.
Diffstat (limited to 'tests/auto/lancelot')
-rw-r--r-- | tests/auto/lancelot/tst_lancelot.cpp | 190 |
1 files changed, 37 insertions, 153 deletions
diff --git a/tests/auto/lancelot/tst_lancelot.cpp b/tests/auto/lancelot/tst_lancelot.cpp index a6bb68f..4485880 100644 --- a/tests/auto/lancelot/tst_lancelot.cpp +++ b/tests/auto/lancelot/tst_lancelot.cpp @@ -64,13 +64,10 @@ public: tst_Lancelot(); private: - QImage getBaseline(const QString &fileName, bool *created); - QImage render(const QString &fileName, QImage::Format format); + ImageItem render(const ImageItem &item); QStringList loadScriptFile(const QString &filePath); - QString computeMismatchScore(const QImage& baseline, const QImage& rendered); void runTestSuite(); - QString errorMsg; BaselineProtocol proto; ImageItemList baseList; @@ -108,24 +105,24 @@ void tst_Lancelot::initTestCase() } baseList.resize(files.count()); - int i = 0; + ImageItemList::iterator it = baseList.begin(); foreach(const QString& file, files) { - baseList[i].scriptName = file; + it->scriptName = file; // tbd: also load, split and generate checksums for scripts - i++; + it++; } } void tst_Lancelot::testRasterARGB32PM_data() { - QTest::addColumn<ImageItem>("item"); + QTest::addColumn<ImageItem>("baseline"); ImageItemList itemList(baseList); - for(int i = 0; i < itemList.size(); i++) { - itemList[i].engine = ImageItem::Raster; - itemList[i].renderFormat = QImage::Format_ARGB32_Premultiplied; + for(ImageItemList::iterator it = itemList.begin(); it != itemList.end(); it++) { + it->engine = ImageItem::Raster; + it->renderFormat = QImage::Format_ARGB32_Premultiplied; } if (!proto.requestBaselineChecksums(&itemList)) { @@ -133,9 +130,8 @@ void tst_Lancelot::testRasterARGB32PM_data() QSKIP("Communication with baseline image server failed.", SkipAll); } - qDebug() << "items:" << itemList.count(); foreach(const ImageItem& item, itemList) { - if (item.scriptName != QLatin1String("sizes.qps")) // Hardcoded blacklisting for this enigine/format + if (item.scriptName != QLatin1String("sizes.qps")) // Example of hardcoded blacklisting for this enigine/format QTest::newRow(item.scriptName.toLatin1()) << item; } } @@ -149,170 +145,58 @@ void tst_Lancelot::testRasterARGB32PM() void tst_Lancelot::runTestSuite() { - errorMsg.clear(); - QFETCH(ImageItem, item); + QFETCH(ImageItem, baseline); - if (item.status == ImageItem::IgnoreItem) + if (baseline.status == ImageItem::IgnoreItem) QSKIP("Blacklisted by baseline server.", SkipSingle); - QImage rendered = render(item.scriptName, item.renderFormat); - if (!errorMsg.isNull() || rendered.isNull()) { // Assume an error in the test environment, not Qt - QWARN("Error: Failed to render image. " + errorMsg.toLatin1()); + ImageItem rendered = render(baseline); + if (rendered.image.isNull()) { // Assume an error in the test environment, not Qt + QWARN("Error: Failed to render image."); QSKIP("Aborted due to errors.", SkipSingle); } - quint64 checksum = ImageItem::computeChecksum(rendered); - - if (item.status == ImageItem::BaselineNotFound) { - item.image = rendered; - item.imageChecksum = checksum; - proto.submitNewBaseline(item); + if (baseline.status == ImageItem::BaselineNotFound) { + proto.submitNewBaseline(rendered, 0); QSKIP("Baseline not found; new baseline created.", SkipSingle); } - qDebug() << "rendered" << QString::number(checksum, 16).prepend("0x") << "baseline" << QString::number(item.imageChecksum, 16).prepend("0x"); - if (checksum != item.imageChecksum) { - /* TBD - - Get baseline image - - compute diffscore - - submit mismatching - - getBaseline(...) - if (!errorMsg.isNull() || baseline.isNull()) { - QWARN("Error: Failed to get baseline image. " + errorMsg.toLatin1()); - QSKIP("Aborted due to errors.", SkipSingle); - } - - - if (rendered.format() != baseline.format()) - rendered = rendered.convertToFormat(baseline.format()); //### depending on format - - QString scoreMsg = computeMismatchScore(baseline, rendered); + if (rendered.imageChecksum != baseline.imageChecksum) { QByteArray serverMsg; - proto.submitMismatch(fileName, rendered, &serverMsg); - */ - QByteArray failMsg = QByteArray("Rendered image differs from baseline. "); - //+ scoreMsg.toLatin1() + '\n' + serverMsg; - QFAIL(failMsg.constData()); + if (!proto.submitMismatch(rendered, &serverMsg)) + serverMsg = "Failed to submit mismatching image to server."; + QFAIL("Rendered image differs from baseline.\n" + serverMsg); } } -QString tst_Lancelot::computeMismatchScore(const QImage &baseline, const QImage &rendered) +ImageItem tst_Lancelot::render(const ImageItem &item) { - if (baseline.size() != rendered.size() || baseline.format() != rendered.format()) - return QLatin1String("[No score, incomparable images.]"); - if (baseline.depth() != 32) - return QLatin1String("[Score computation not implemented for format.]"); - - int w = baseline.width(); - int h = baseline.height(); - - uint ncd = 0; // number of differing color pixels - uint nad = 0; // number of differing alpha pixels - uint scd = 0; // sum of color pixel difference - uint sad = 0; // sum of alpha pixel difference - - for (int y=0; y<h; ++y) { - const QRgb *bl = (const QRgb *) baseline.constScanLine(y); - const QRgb *rl = (const QRgb *) rendered.constScanLine(y); - for (int x=0; x<w; ++x) { - QRgb b = bl[x]; - QRgb r = rl[x]; - if (r != b) { - int dr = qAbs(qRed(b) - qRed(r)); - int dg = qAbs(qGreen(b) - qGreen(r)); - int db = qAbs(qBlue(b) - qBlue(r)); - int ds = dr + dg + db; - int da = qAbs(qAlpha(b) - qAlpha(r)); - if (ds) { - ncd++; - scd += ds; - } - if (da) { - nad++; - sad += da; - } - } - } - } - - double pcd = 100.0 * ncd / (w*h); // percent of pixels that differ - double acd = ncd ? double(scd) / (3*ncd) : 0; // avg. difference - QString res = QString(QLatin1String("Diffscore: %1% (Num:%2 Avg:%3)")).arg(pcd, 0, 'g', 2).arg(ncd).arg(acd, 0, 'g', 2); - if (baseline.hasAlphaChannel()) { - double pad = 100.0 * nad / (w*h); // percent of pixels that differ - double aad = nad ? double(sad) / (3*nad) : 0; // avg. difference - res += QString(QLatin1String(" Alpha-diffscore: %1% (Num:%2 Avg:%3)")).arg(pad, 0, 'g', 2).arg(nad).arg(aad, 0, 'g', 2); + ImageItem res = item; + QString filePath = scriptsDir + item.scriptName; + QStringList script = loadScriptFile(filePath); + if (script.isEmpty()) { + res.image = QImage(); + res.imageChecksum = 0; + } else { + QImage img(800, 800, item.renderFormat); + QPainter p(&img); + PaintCommands pcmd(script, 800, 800); + pcmd.setPainter(&p); + pcmd.setFilePath(QFileInfo(filePath).absoluteFilePath()); // eh yuck + pcmd.runCommands(); + p.end(); + res.image = img; + res.imageChecksum = ImageItem::computeChecksum(img); } return res; } -QImage tst_Lancelot::getBaseline(const QString &fileName, bool *created) -{ - QImage baseline; - //### TBD: rewrite to use ImageItem - /* - BaselineProtocol::Command response; - if (!proto.requestBaseline(fileName, &response, &baseline)) { - errorMsg = QLatin1String("Error downloading baseline from server. ") + proto.errorMessage(); - return QImage(); - } - - if (response == BaselineProtocol::BaselineNotPresent) { - // Here: Create new baseline! - baseline = render(fileName); - if (!errorMsg.isNull() || baseline.isNull()) { - errorMsg.prepend(QLatin1String("Failed to render new baseline. ")); - return QImage(); - } - if (!proto.submitNewBaseline(fileName, baseline)) { - errorMsg = QLatin1String("Failed to submit new baseline to server. ") + proto.errorMessage(); - return QImage(); - } - if (created) - *created = true; - } - else if (response == BaselineProtocol::IgnoreCase) { - // Blacklisted or similar, signal back that this item should be skipped - // Will effectively happen with this: - errorMsg = QLatin1String("Baseline server says skip this"); - return QImage(); - } - else if (response != BaselineProtocol::AcceptBaseline) { - errorMsg = QLatin1String("Unknown response from baseline server. "); - return QImage(); - } - */ - return baseline; -} - - -QImage tst_Lancelot::render(const QString &fileName, QImage::Format format) -{ - QString filePath = scriptsDir + fileName; - QStringList script = loadScriptFile(filePath); - if (script.isEmpty()) - return QImage(); - - QImage img(800, 800, format); - QPainter p(&img); - PaintCommands pcmd(script, 800, 800); - pcmd.setPainter(&p); - pcmd.setFilePath(QFileInfo(filePath).absoluteFilePath()); // eh yuck - pcmd.runCommands(); - p.end(); - - return img; -} - - QStringList tst_Lancelot::loadScriptFile(const QString &filePath) { QFile file(filePath); if (!file.open(QFile::ReadOnly)) { - errorMsg = QLatin1String("Failed to open script file ") + filePath; return QStringList(); } //# use the new readscript function instead? |