mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:29:32 +02:00
Auto-tester now saves results in a folder hierarchy.
This commit is contained in:
parent
05b4272669
commit
418d741b39
5 changed files with 102 additions and 18 deletions
|
@ -22,10 +22,10 @@ Test::Test() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory) {
|
bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory) {
|
||||||
// Delete any previous test results, if user agrees
|
// If a previous test results folder is found then wait for the user to delete it, or cancel
|
||||||
QString s = testDirectory + "/" + testResultsFolder;
|
// (e.g. the user may want to move the folder elsewhere)
|
||||||
QFileInfo fileInfo(testDirectory + "/" + testResultsFolder);
|
QString testResultsFolderPath { testDirectory + "/" + testResultsFolder };
|
||||||
while (fileInfo.exists()) {
|
while (QDir().exists(testResultsFolderPath)) {
|
||||||
messageBox.setText("Previous test results have been found");
|
messageBox.setText("Previous test results have been found");
|
||||||
messageBox.setInformativeText("Delete " + testResultsFolder + " before continuing");
|
messageBox.setInformativeText("Delete " + testResultsFolder + " before continuing");
|
||||||
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||||
|
@ -35,9 +35,12 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new test results folder
|
||||||
|
QDir().mkdir(testResultsFolderPath);
|
||||||
|
|
||||||
// Loop over both lists and compare each pair of images
|
// Loop over both lists and compare each pair of images
|
||||||
// Quit loop if user has aborted due to a failed test.
|
// Quit loop if user has aborted due to a failed test.
|
||||||
const double THRESHOLD{ 0.999 };
|
const double THRESHOLD { 0.999 };
|
||||||
bool success{ true };
|
bool success{ true };
|
||||||
bool keepOn{ true };
|
bool keepOn{ true };
|
||||||
for (int i = 0; keepOn && i < expectedImages.length(); ++i) {
|
for (int i = 0; keepOn && i < expectedImages.length(); ++i) {
|
||||||
|
@ -73,7 +76,7 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage
|
||||||
case USER_RESPONSE_PASS:
|
case USER_RESPONSE_PASS:
|
||||||
break;
|
break;
|
||||||
case USE_RESPONSE_FAIL:
|
case USE_RESPONSE_FAIL:
|
||||||
appendTestResultsToFile(testDirectory, testFailure);
|
appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage());
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
case USER_RESPONSE_ABORT:
|
case USER_RESPONSE_ABORT:
|
||||||
|
@ -90,11 +93,55 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test::appendTestResultsToFile(QString testDirectory, TestFailure testFailure) {
|
void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage) {
|
||||||
QFileInfo fileInfo(testResultsFileName);
|
if (!QDir().exists(testResultsFolderPath)) {
|
||||||
if (!fileInfo.exists()) {
|
messageBox.critical(0, "Internal error", "Folder " + testResultsFolderPath + " not found");
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int index = 1;
|
||||||
|
QString failureFolderPath { testResultsFolderPath + "/" + "Failure_" + QString::number(index) };
|
||||||
|
if (!QDir().mkdir(failureFolderPath)) {
|
||||||
|
messageBox.critical(0, "Internal error", "Failed to create folder " + failureFolderPath);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
|
||||||
|
QString descriptionFileName { "ReadMe.txt" };
|
||||||
|
QFile descriptionFile(failureFolderPath + "/" +descriptionFileName);
|
||||||
|
if (!descriptionFile.open(QIODevice::ReadWrite)) {
|
||||||
|
messageBox.critical(0, "Internal error", "Failed to create file " + descriptionFileName);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create text file describing the failure
|
||||||
|
QTextStream stream(&descriptionFile);
|
||||||
|
stream << "Test failed in folder " << testFailure._pathname.left(testFailure._pathname.length() - 1) << endl; // remove trailing '/'
|
||||||
|
stream << "Expected image was " << testFailure._expectedImageFilename << endl;
|
||||||
|
stream << "Actual image was " << testFailure._actualImageFilename << endl;
|
||||||
|
stream << "Similarity index was " << testFailure._error << endl;
|
||||||
|
|
||||||
|
descriptionFile.close();
|
||||||
|
|
||||||
|
// Copy expected and actual images, and save the difference image
|
||||||
|
QString sourceFile;
|
||||||
|
QString destinationFile;
|
||||||
|
|
||||||
|
sourceFile = testFailure._pathname + testFailure._expectedImageFilename;
|
||||||
|
destinationFile = failureFolderPath + "/" + "Expected Image.jpg";
|
||||||
|
if (!QFile::copy(sourceFile, destinationFile)) {
|
||||||
|
messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceFile = testFailure._pathname + testFailure._actualImageFilename;
|
||||||
|
destinationFile = failureFolderPath + "/" + "Actual Image.jpg";
|
||||||
|
if (!QFile::copy(sourceFile, destinationFile)) {
|
||||||
|
messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test::evaluateTests() {
|
void Test::evaluateTests() {
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
|
|
||||||
void importTest(QTextStream& textStream, const QString& testPathname, int testNumber);
|
void importTest(QTextStream& textStream, const QString& testPathname, int testNumber);
|
||||||
|
|
||||||
void appendTestResultsToFile(QString testDirectory, TestFailure testFailure);
|
void appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString testFilename{ "test.js" };
|
const QString testFilename{ "test.js" };
|
||||||
|
|
|
@ -33,11 +33,15 @@ QPixmap MismatchWindow::computeDiffPixmap(QImage expectedImage, QImage resultIma
|
||||||
double p = R_Y * qRed(pixelP) + G_Y * qGreen(pixelP) + B_Y * qBlue(pixelP);
|
double p = R_Y * qRed(pixelP) + G_Y * qGreen(pixelP) + B_Y * qBlue(pixelP);
|
||||||
double q = R_Y * qRed(pixelQ) + G_Y * qGreen(pixelQ) + B_Y * qBlue(pixelQ);
|
double q = R_Y * qRed(pixelQ) + G_Y * qGreen(pixelQ) + B_Y * qBlue(pixelQ);
|
||||||
|
|
||||||
int absDiff = (int)(fabs(p - q));
|
// The intensity value is modified to increase the brightness of the displayed image
|
||||||
|
double absoluteDifference = fabs(p - q) / 255.0;
|
||||||
buffer[3 * (x + y * expectedImage.width()) + 0] = absDiff;
|
double modifiedDifference = pow(absoluteDifference, 0.5);
|
||||||
buffer[3 * (x + y * expectedImage.width()) + 1] = absDiff;
|
|
||||||
buffer[3 * (x + y * expectedImage.width()) + 2] = absDiff;
|
int difference = (int)(modifiedDifference * 255.0);
|
||||||
|
|
||||||
|
buffer[3 * (x + y * expectedImage.width()) + 0] = difference;
|
||||||
|
buffer[3 * (x + y * expectedImage.width()) + 1] = difference;
|
||||||
|
buffer[3 * (x + y * expectedImage.width()) + 2] = difference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +64,7 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) {
|
||||||
QPixmap expectedPixmap = QPixmap(testFailure._pathname + testFailure._expectedImageFilename);
|
QPixmap expectedPixmap = QPixmap(testFailure._pathname + testFailure._expectedImageFilename);
|
||||||
QPixmap actualPixmap = QPixmap(testFailure._pathname + testFailure._actualImageFilename);
|
QPixmap actualPixmap = QPixmap(testFailure._pathname + testFailure._actualImageFilename);
|
||||||
|
|
||||||
QPixmap diffPixmap = computeDiffPixmap(
|
diffPixmap = computeDiffPixmap(
|
||||||
QImage(testFailure._pathname + testFailure._expectedImageFilename),
|
QImage(testFailure._pathname + testFailure._expectedImageFilename),
|
||||||
QImage(testFailure._pathname + testFailure._actualImageFilename)
|
QImage(testFailure._pathname + testFailure._actualImageFilename)
|
||||||
);
|
);
|
||||||
|
@ -84,3 +88,7 @@ void MismatchWindow::on_abortTestsButton_clicked() {
|
||||||
_userResponse = USER_RESPONSE_ABORT;
|
_userResponse = USER_RESPONSE_ABORT;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap MismatchWindow::getComparisonImage() {
|
||||||
|
return diffPixmap;
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ public:
|
||||||
UserResponse getUserResponse() { return _userResponse; }
|
UserResponse getUserResponse() { return _userResponse; }
|
||||||
|
|
||||||
QPixmap computeDiffPixmap(QImage expectedImage, QImage resultImage);
|
QPixmap computeDiffPixmap(QImage expectedImage, QImage resultImage);
|
||||||
|
QPixmap getComparisonImage();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_passTestButton_clicked();
|
void on_passTestButton_clicked();
|
||||||
|
@ -34,6 +35,8 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UserResponse _userResponse{ USER_RESPONSE_INVALID };
|
UserResponse _userResponse{ USER_RESPONSE_INVALID };
|
||||||
|
|
||||||
|
QPixmap diffPixmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>10</x>
|
<x>10</x>
|
||||||
<y>20</y>
|
<y>25</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>450</height>
|
<height>450</height>
|
||||||
</rect>
|
</rect>
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>900</x>
|
<x>900</x>
|
||||||
<y>20</y>
|
<y>25</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>450</height>
|
<height>450</height>
|
||||||
</rect>
|
</rect>
|
||||||
|
@ -163,6 +163,32 @@
|
||||||
<string>similarity</string>
|
<string>similarity</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>5</y>
|
||||||
|
<width>151</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Expected Image</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>930</x>
|
||||||
|
<y>5</y>
|
||||||
|
<width>151</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Actual Image</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
Loading…
Reference in a new issue