From 079a623b30ec83454bcc6f0c19dc972e0093c098 Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Wed, 5 Dec 2018 17:25:03 -0800 Subject: [PATCH] Added text results to HTML. --- tools/nitpick/src/AWSInterface.cpp | 158 +++++++++++++++++++++++------ tools/nitpick/src/AWSInterface.h | 4 +- 2 files changed, 131 insertions(+), 31 deletions(-) diff --git a/tools/nitpick/src/AWSInterface.cpp b/tools/nitpick/src/AWSInterface.cpp index 2e9ba7ad6d..034feae7f9 100644 --- a/tools/nitpick/src/AWSInterface.cpp +++ b/tools/nitpick/src/AWSInterface.cpp @@ -10,6 +10,8 @@ #include "AWSInterface.h" #include +#include +#include #include #include @@ -168,7 +170,7 @@ void AWSInterface::writeTable(QTextStream& stream) { continue; } - // Only process failure folders + // Only process result folders if (!nextDirectory.contains("--tests.")) { continue; } @@ -209,9 +211,9 @@ void AWSInterface::writeTable(QTextStream& stream) { // Mac does not read folders in lexicographic order, so this step is divided into 2 // Each test consists of the test name and its index. - QDirIterator it2(_htmlFailuresFolder); QStringList folderNames; + QDirIterator it2(_htmlFailuresFolder); while (it2.hasNext()) { QString nextDirectory = it2.next(); @@ -242,8 +244,7 @@ void AWSInterface::writeTable(QTextStream& stream) { previousTestName = testName; stream << "\t\t

" << testName << "

\n"; - - openTable(stream); + openTable(stream, folderName, true); } createEntry(testNumber, folderName, stream, true); @@ -253,6 +254,9 @@ void AWSInterface::writeTable(QTextStream& stream) { stream << "\t" << "\t" << "\n"; stream << "\t" << "\t" << "

The following tests passed:

"; + // Now do the same for passes + folderNames.clear(); + QDirIterator it3(_htmlSuccessesFolder); while (it3.hasNext()) { QString nextDirectory = it3.next(); @@ -263,10 +267,17 @@ void AWSInterface::writeTable(QTextStream& stream) { } QStringList pathComponents = nextDirectory.split('/'); - QString filename = pathComponents[pathComponents.length() - 1]; - int splitIndex = filename.lastIndexOf("."); - QString testName = filename.left(splitIndex).replace(".", " / "); - QString testNumber = filename.right(filename.length() - (splitIndex + 1)); + QString folderName = pathComponents[pathComponents.length() - 1]; + + folderNames << folderName; + } + + folderNames.sort(); + for (const auto& folderName : folderNames) { + int splitIndex = folderName.lastIndexOf("."); + QString testName = folderName.left(splitIndex).replace('.', " / "); + + int testNumber = folderName.right(folderName.length() - (splitIndex + 1)).toInt(); // The failures are ordered lexicographically, so we know that we can rely on the testName changing to create a new table if (testName != previousTestName) { @@ -277,39 +288,67 @@ void AWSInterface::writeTable(QTextStream& stream) { previousTestName = testName; stream << "\t\t

" << testName << "

\n"; - - openTable(stream); + openTable(stream, folderName, false); } - createEntry(testNumber.toInt(), filename, stream, false); + createEntry(testNumber, folderName, stream, false); } closeTable(stream); } -void AWSInterface::openTable(QTextStream& stream) { - stream << "\t\t\n"; - stream << "\t\t\t\n"; - stream << "\t\t\t\t\n"; - stream << "\t\t\t\t\n"; - stream << "\t\t\t\t\n"; - stream << "\t\t\t\t\n"; - stream << "\t\t\t\n"; +void AWSInterface::openTable(QTextStream& stream, const QString& testResult, const bool isFailure) { + QStringList resultNameComponents = testResult.split('/'); + QString resultName = resultNameComponents[resultNameComponents.length() - 1]; + + bool textResultsFileFound; + if (isFailure) { + textResultsFileFound = QFile::exists(_htmlFailuresFolder + "/" + resultName + "/Result.txt"); + } else { + textResultsFileFound = QFile::exists(_htmlSuccessesFolder + "/" + resultName + "/Result.txt"); + } + + if (textResultsFileFound) { + if (isFailure) { + stream << "\t\t

Test

Actual Image

Expected Image

Difference Image

\n"; + stream << "\t\t\t\n"; + stream << "\t\t\t\t\n"; + stream << "\t\t\t\t\n"; + stream << "\t\t\t\t\n"; + stream << "\t\t\t\n"; + } else { + stream << "\t\t

No errors found

\n\n"; + stream << "\t\t

===============

\n\n"; + } + } else { + stream << "\t\t

Element

Actual Value

Expected Value

\n"; + stream << "\t\t\t\n"; + stream << "\t\t\t\t\n"; + stream << "\t\t\t\t\n"; + stream << "\t\t\t\t\n"; + stream << "\t\t\t\t\n"; + stream << "\t\t\t\n"; + } } void AWSInterface::closeTable(QTextStream& stream) { stream << "\t\t

Test

Actual Image

Expected Image

Difference Image

\n"; } -void AWSInterface::createEntry(int index, const QString& testResult, QTextStream& stream, const bool isFailure) { - stream << "\t\t\t\n"; - stream << "\t\t\t\t

" << QString::number(index) << "

\n"; - +void AWSInterface::createEntry(const int index, const QString& testResult, QTextStream& stream, const bool isFailure) { // For a test named `D:/t/fgadhcUDHSFaidsfh3478JJJFSDFIUSOEIrf/Failure_1--tests.engine.interaction.pick.collision.many.00000` // we need `Failure_1--tests.engine.interaction.pick.collision.many.00000` QStringList resultNameComponents = testResult.split('/'); QString resultName = resultNameComponents[resultNameComponents.length() - 1]; + QString textResultFilename; + if (isFailure) { + textResultFilename = _htmlFailuresFolder + "/" + resultName + "/Result.txt"; + } else { + textResultFilename = _htmlSuccessesFolder + "/" + resultName + "/Result.txt"; + } + bool textResultsFileFound{ QFile::exists(textResultFilename) }; + QString folder; bool differenceFileFound; if (isFailure) { @@ -320,17 +359,78 @@ void AWSInterface::createEntry(int index, const QString& testResult, QTextStream differenceFileFound = QFile::exists(_htmlSuccessesFolder + "/" + resultName + "/Difference Image.png"); } + if (textResultsFileFound) { + // Parse the JSON file + QFile file; + file.setFileName(textResultFilename); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Failed to open file " + textResultFilename); + } - stream << "\t\t\t\t\n"; - stream << "\t\t\t\t\n"; + QString value = file.readAll(); + file.close(); - if (differenceFileFound) { - stream << "\t\t\t\t\n"; + // The Result.txt file is an object containing elements such as the following: + // "angularDamping": { + // "actual": 0.3938899040222168, + // "expected" : 0.3938899, + // "result" : "pass" + // }, + // + // Failures are thos element that have "fail for the result + + QJsonDocument document = QJsonDocument::fromJson(value.toUtf8()); + QJsonObject json = document.object(); + foreach(const QString& key, json.keys()) { + QJsonValue value = json.value(key); + QJsonObject object = value.toObject(); + + QJsonValue actualValue = object.value("actual"); + QString actualValueString; + if (actualValue.isString()) { + actualValueString = actualValue.toString(); + } else if (actualValue.isBool()) { + actualValueString = actualValue.toBool() ? "true" : "false"; + } else if (actualValue.isDouble()) { + actualValueString = QString::number(actualValue.toDouble()); + } + + QJsonValue expectedValue = object.value("expected"); + QString expectedValueString; + if (expectedValue.isString()) { + expectedValueString = expectedValue.toString(); + } else if (expectedValue.isBool()) { + expectedValueString = expectedValue.toBool() ? "true" : "false"; + } else if (expectedValue.isDouble()) { + expectedValueString = QString::number(expectedValue.toDouble()); + } + QString result = object.value("result").toString(); + + if (result == "fail") { + stream << "\t\t\t\n"; + stream << "\t\t\t\t" + key + "\n"; + stream << "\t\t\t\t" + actualValueString + "\n"; + stream << "\t\t\t\t" + expectedValueString + "\n"; + stream << "\t\t\t\n"; + } + } } else { - stream << "\t\t\t\t

No Image Found

\n"; + stream << "\t\t\t\n"; + stream << "\t\t\t\t

" << QString::number(index) << "

\n"; + + stream << "\t\t\t\t\n"; + stream << "\t\t\t\t\n"; + + if (differenceFileFound) { + stream << "\t\t\t\t\n"; + } else { + stream << "\t\t\t\t

No Image Found

\n"; + } + + stream << "\t\t\t\n"; } - stream << "\t\t\t\n"; } void AWSInterface::updateAWS() { diff --git a/tools/nitpick/src/AWSInterface.h b/tools/nitpick/src/AWSInterface.h index c5be5f35bb..43d2240c19 100644 --- a/tools/nitpick/src/AWSInterface.h +++ b/tools/nitpick/src/AWSInterface.h @@ -40,10 +40,10 @@ public: void writeTitle(QTextStream& stream); void writeTable(QTextStream& stream); - void openTable(QTextStream& stream); + void openTable(QTextStream& stream, const QString& testResult, const bool isFailure); void closeTable(QTextStream& stream); - void createEntry(int index, const QString& testResult, QTextStream& stream, const bool isFailure); + void createEntry(const int index, const QString& testResult, QTextStream& stream, const bool isFailure); void updateAWS();