From 4672ff71c5c02b13b6435594cc55638d428053ab Mon Sep 17 00:00:00 2001 From: aavit Date: Wed, 19 Jan 2011 15:31:25 +0100 Subject: Re-added the update-all-baselines command --- tests/arthur/baselineserver/src/baselineserver.cpp | 34 ++++++++++------------ tests/arthur/baselineserver/src/baselineserver.h | 2 +- tests/arthur/baselineserver/src/report.cpp | 26 +++++++++++++---- tests/arthur/baselineserver/src/report.h | 2 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/tests/arthur/baselineserver/src/baselineserver.cpp b/tests/arthur/baselineserver/src/baselineserver.cpp index 8aaa8ff..75309a4 100644 --- a/tests/arthur/baselineserver/src/baselineserver.cpp +++ b/tests/arthur/baselineserver/src/baselineserver.cpp @@ -426,27 +426,25 @@ QString BaselineHandler::clearAllBaselines(const QString &context) return QString(QLS("%1 of %2 baselines cleared from context ")).arg((tot-failed)/2).arg(tot/2) + context; } -QString BaselineHandler::updateSingleBaseline(const QString &oldBaseline, const QString &newBaseline) +QString BaselineHandler::updateBaselines(const QString &context, const QString &mismatchContext, const QString &itemId) { - QString res; - QString basePath(BaselineServer::storagePath() + QLC('/')); - QString srcBase(basePath + newBaseline.left(newBaseline.length() - 3)); - QString dstDir(basePath + oldBaseline.left(oldBaseline.lastIndexOf(QLC('/')))); - - QProcess proc; - proc.setProcessChannelMode(QProcess::MergedChannels); - proc.start(QLS("cp"), QStringList() << QLS("-f") << srcBase + QLS(FileFormat) << srcBase + QLS(MetadataFileExt) << dstDir); - proc.waitForFinished(); - if (proc.exitCode() == 0) - res = QString("Successfully updated '%1'").arg(oldBaseline); - else - res = QString("Error updating baseline: %1
" - "Command output:
%2
").arg(proc.errorString(), proc.readAll().constData()); - - return res; + int tot = 0; + int failed = 0; + QString storagePrefix = BaselineServer::storagePath() + QLC('/'); + // If itemId is set, update just that one, otherwise, update all: + QString filter = (itemId.isEmpty() ? QLS("*") : itemId) + QLS("_????."); // Match any checksum. #vulnerable to changes in file naming + QDirIterator it(storagePrefix + mismatchContext, QStringList() << filter + QLS(FileFormat) << filter + QLS(MetadataFileExt)); + while (it.hasNext()) { + tot++; + it.next(); + QString oldFile = storagePrefix + context + QLC('/') + it.fileName(); + QFile::remove(oldFile); // Remove existing baseline file + if (!QFile::copy(it.filePath(), oldFile)) // and replace it with the mismatch + failed++; + } + return QString(QLS("%1 of %2 baselines updated in context %3 from context %4")).arg((tot-failed)/2).arg(tot/2).arg(context, mismatchContext); } - QString BaselineHandler::blacklistTest(const QString &context, const QString &itemId, bool removeFromBlacklist) { QFile file(BaselineServer::storagePath() + QLC('/') + context + QLS("/BLACKLIST")); diff --git a/tests/arthur/baselineserver/src/baselineserver.h b/tests/arthur/baselineserver/src/baselineserver.h index a5683b2..0f14c8c 100644 --- a/tests/arthur/baselineserver/src/baselineserver.h +++ b/tests/arthur/baselineserver/src/baselineserver.h @@ -109,7 +109,7 @@ public: // CGI callbacks: static QString view(const QString &baseline, const QString &rendered, const QString &compared); static QString clearAllBaselines(const QString &context); - static QString updateSingleBaseline(const QString &oldBaseline, const QString &newBaseline); + static QString updateBaselines(const QString &context, const QString &mismatchContext, const QString &itemId); static QString blacklistTest(const QString &context, const QString &itemId, bool removeFromBlacklist = false); private slots: diff --git a/tests/arthur/baselineserver/src/report.cpp b/tests/arthur/baselineserver/src/report.cpp index c85f144..217b92c 100644 --- a/tests/arthur/baselineserver/src/report.cpp +++ b/tests/arthur/baselineserver/src/report.cpp @@ -154,10 +154,14 @@ void Report::writeFunctionResults(const ImageItemList &list) QString testFunction = list.at(0).testFunction; QString pageUrl = BaselineServer::baseUrl() + path; QString ctx = handler->pathForItem(list.at(0), true, false).section(QLC('/'), 0, -2); + QString misCtx = handler->pathForItem(list.at(0), false, false).section(QLC('/'), 0, -2); + out << "\n

 

Test function: " << testFunction << "

\n"; out << "

Clear all baselines (They will be recreated by the next run)

\n\n"; + << "\">Clear all baselines for this testfunction (They will be recreated by the next run)

\n"; + out << "

Let these mismatching images be the new baselines for this testfunction

\n\n"; out << "\n" "\n" @@ -176,7 +180,7 @@ void Report::writeFunctionResults(const ImageItemList &list) QString metadata = prefix + QLS(MetadataFileExt); if (item.status == ImageItem::Mismatch) { QString rendered = handler->pathForItem(item, false, false) + QLS(FileFormat); - writeItem(baseline, rendered, item, ctx, metadata); + writeItem(baseline, rendered, item, ctx, misCtx, metadata); } else { out << "\n" @@ -207,7 +211,7 @@ void Report::writeFunctionResults(const ImageItemList &list) out << "
image info
\n"; } -void Report::writeItem(const QString &baseline, const QString &rendered, const ImageItem &item, const QString &ctx, const QString &metadata) +void Report::writeItem(const QString &baseline, const QString &rendered, const ImageItem &item, const QString &ctx, const QString &misCtx, const QString &metadata) { QString compared = generateCompared(baseline, rendered); QString pageUrl = BaselineServer::baseUrl() + path; @@ -219,8 +223,13 @@ void Report::writeItem(const QString &baseline, const QString &rendered, const I out << "\n" << "

Mismatch reported

\n" << "

Baseline Info\n" +#if 0 << "

Replace baseline with rendered

\n" + << "&newBaseline=" << rendered << "&url=" << pageUrl << "\">Let this be the new baseline

\n" +#else + << "

Let this be the new baseline

\n" +#endif << "

Blacklist this item

\n" << "