First success with running from command line.

This commit is contained in:
NissimHadar 2018-05-01 17:59:07 -07:00
parent a3e4fa8429
commit 93afbcdc08
5 changed files with 70 additions and 44 deletions

View file

@ -27,7 +27,7 @@ Test::Test() {
mismatchWindow.setModal(true); mismatchWindow.setModal(true);
} }
bool Test::createTestResultsFolderPath(QString directory) { bool Test::createTestResultsFolderPath(const QString& directory) {
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
testResultsFolderPath = directory + "/" + TEST_RESULTS_FOLDER + "--" + now.toString(DATETIME_FORMAT); testResultsFolderPath = directory + "/" + TEST_RESULTS_FOLDER + "--" + now.toString(DATETIME_FORMAT);
QDir testResultsFolder(testResultsFolderPath); QDir testResultsFolder(testResultsFolderPath);
@ -125,7 +125,7 @@ bool Test::compareImageLists(bool isInteractiveMode, QProgressBar* progressBar)
return success; return success;
} }
void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage) { void Test::appendTestResultsToFile(const QString& testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage) {
if (!QDir().exists(testResultsFolderPath)) { if (!QDir().exists(testResultsFolderPath)) {
messageBox.critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "Folder " + testResultsFolderPath + " not found"); messageBox.critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "Folder " + testResultsFolderPath + " not found");
exit(-1); exit(-1);
@ -174,10 +174,16 @@ void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure te
comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg"); comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg");
} }
void Test::startTestsEvaluation() { void Test::startTestsEvaluation(const QString& testFolder) {
// Get list of JPEG images in folder, sorted by name QString pathToTestResultsDirectory;
pathToTestResultsDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); if (testFolder.isNull()) {
if (pathToTestResultsDirectory == "") { // Get list of JPEG images in folder, sorted by name
pathToTestResultsDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly);
} else {
pathToTestResultsDirectory = testFolder;
}
if (pathToTestResultsDirectory == QString()) {
return; return;
} }
@ -221,9 +227,6 @@ void Test::startTestsEvaluation() {
QString expectedImageFilenameTail = currentFilename.left(currentFilename.length() - 4).right(NUM_DIGITS); QString expectedImageFilenameTail = currentFilename.left(currentFilename.length() - 4).right(NUM_DIGITS);
QString expectedImageStoredFilename = EXPECTED_IMAGE_PREFIX + expectedImageFilenameTail + ".png"; QString expectedImageStoredFilename = EXPECTED_IMAGE_PREFIX + expectedImageFilenameTail + ".png";
//https://raw.githubusercontent.com/highfidelity/hifi_tests/master/tests/content/entity/zone/zoneOrientation/ExpectedImage_00001.png
QString imageURLString("https://raw.githubusercontent.com/" + githubUser + "/hifi_tests/" + gitHubBranch + "/" + QString imageURLString("https://raw.githubusercontent.com/" + githubUser + "/hifi_tests/" + gitHubBranch + "/" +
expectedImagePartialSourceDirectory + "/" + expectedImageStoredFilename); expectedImagePartialSourceDirectory + "/" + expectedImageStoredFilename);
@ -240,19 +243,21 @@ void Test::startTestsEvaluation() {
autoTester->downloadImages(expectedImagesURLs, pathToTestResultsDirectory, expectedImagesFilenames); autoTester->downloadImages(expectedImagesURLs, pathToTestResultsDirectory, expectedImagesFilenames);
} }
void Test::finishTestsEvaluation(bool interactiveMode, QProgressBar* progressBar) { void Test::finishTestsEvaluation(bool isRunningFromCommandline, bool interactiveMode, QProgressBar* progressBar) {
bool success = compareImageLists(interactiveMode, progressBar); bool success = compareImageLists((!isRunningFromCommandline && interactiveMode), progressBar);
if (success) { if (!isRunningFromCommandline) {
messageBox.information(0, "Success", "All images are as expected"); if (success) {
} else { messageBox.information(0, "Success", "All images are as expected");
messageBox.information(0, "Failure", "One or more images are not as expected"); } else {
messageBox.information(0, "Failure", "One or more images are not as expected");
}
} }
zipAndDeleteTestResultsFolder(); zipAndDeleteTestResultsFolder();
} }
bool Test::isAValidDirectory(QString pathname) { bool Test::isAValidDirectory(const QString& pathname) {
// Only process directories // Only process directories
QDir dir(pathname); QDir dir(pathname);
if (!dir.exists()) { if (!dir.exists()) {
@ -267,7 +272,7 @@ bool Test::isAValidDirectory(QString pathname) {
return true; return true;
} }
QString Test::extractPathFromTestsDown(QString fullPath) { QString Test::extractPathFromTestsDown(const QString& fullPath) {
// `fullPath` includes the full path to the test. We need the portion below (and including) `tests` // `fullPath` includes the full path to the test. We need the portion below (and including) `tests`
QStringList pathParts = fullPath.split('/'); QStringList pathParts = fullPath.split('/');
int i{ 0 }; int i{ 0 };
@ -348,7 +353,7 @@ void Test::createAllRecursiveScripts() {
messageBox.information(0, "Success", "Scripts have been created"); messageBox.information(0, "Success", "Scripts have been created");
} }
void Test::createRecursiveScript(QString topLevelDirectory, bool interactiveMode) { void Test::createRecursiveScript(const QString& topLevelDirectory, bool interactiveMode) {
const QString recursiveTestsFilename("testRecursive.js"); const QString recursiveTestsFilename("testRecursive.js");
QFile allTestsFilename(topLevelDirectory + "/" + recursiveTestsFilename); QFile allTestsFilename(topLevelDirectory + "/" + recursiveTestsFilename);
if (!allTestsFilename.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!allTestsFilename.open(QIODevice::WriteOnly | QIODevice::Text)) {
@ -615,7 +620,7 @@ void Test::createAllMDFiles() {
messageBox.information(0, "Success", "MD files have been created"); messageBox.information(0, "Success", "MD files have been created");
} }
void Test::createMDFile(QString testDirectory) { void Test::createMDFile(const QString& testDirectory) {
// Verify folder contains test.js file // Verify folder contains test.js file
QString testFileName(testDirectory + "/" + TEST_FILENAME); QString testFileName(testDirectory + "/" + TEST_FILENAME);
QFileInfo testFileInfo(testFileName); QFileInfo testFileInfo(testFileName);
@ -790,7 +795,7 @@ void Test::createTestsOutline() {
messageBox.information(0, "Success", "Test outline file " + testsOutlineFilename + " has been created"); messageBox.information(0, "Success", "Test outline file " + testsOutlineFilename + " has been created");
} }
void Test::copyJPGtoPNG(QString sourceJPGFullFilename, QString destinationPNGFullFilename) { void Test::copyJPGtoPNG(const QString& sourceJPGFullFilename, const QString& destinationPNGFullFilename) {
QFile::remove(destinationPNGFullFilename); QFile::remove(destinationPNGFullFilename);
QImageReader reader; QImageReader reader;
@ -803,7 +808,7 @@ void Test::copyJPGtoPNG(QString sourceJPGFullFilename, QString destinationPNGFul
writer.write(image); writer.write(image);
} }
QStringList Test::createListOfAll_imagesInDirectory(QString imageFormat, QString pathToImageDirectory) { QStringList Test::createListOfAll_imagesInDirectory(const QString& imageFormat, const QString& pathToImageDirectory) {
imageDirectory = QDir(pathToImageDirectory); imageDirectory = QDir(pathToImageDirectory);
QStringList nameFilters; QStringList nameFilters;
nameFilters << "*." + imageFormat; nameFilters << "*." + imageFormat;
@ -816,7 +821,7 @@ QStringList Test::createListOfAll_imagesInDirectory(QString imageFormat, QString
// Filename (i.e. without extension) contains _tests_ (this is based on all test scripts being within the tests folder // Filename (i.e. without extension) contains _tests_ (this is based on all test scripts being within the tests folder
// Last 5 characters in filename are digits // Last 5 characters in filename are digits
// Extension is jpg // Extension is jpg
bool Test::isInSnapshotFilenameFormat(QString imageFormat, QString filename) { bool Test::isInSnapshotFilenameFormat(const QString& imageFormat, const QString& filename) {
QStringList filenameParts = filename.split("."); QStringList filenameParts = filename.split(".");
bool filnameHasNoPeriods = (filenameParts.size() == 2); bool filnameHasNoPeriods = (filenameParts.size() == 2);
@ -833,7 +838,7 @@ bool Test::isInSnapshotFilenameFormat(QString imageFormat, QString filename) {
// For a file named "D_GitHub_hifi-tests_tests_content_entity_zone_create_0.jpg", the test directory is // For a file named "D_GitHub_hifi-tests_tests_content_entity_zone_create_0.jpg", the test directory is
// D:/GitHub/hifi-tests/tests/content/entity/zone/create // D:/GitHub/hifi-tests/tests/content/entity/zone/create
// This method assumes the filename is in the correct format // This method assumes the filename is in the correct format
QString Test::getExpectedImageDestinationDirectory(QString filename) { QString Test::getExpectedImageDestinationDirectory(const QString& filename) {
QString filenameWithoutExtension = filename.split(".")[0]; QString filenameWithoutExtension = filename.split(".")[0];
QStringList filenameParts = filenameWithoutExtension.split("_"); QStringList filenameParts = filenameWithoutExtension.split("_");
@ -850,7 +855,7 @@ QString Test::getExpectedImageDestinationDirectory(QString filename) {
// is ...tests/content/entity/zone/create // is ...tests/content/entity/zone/create
// This is used to create the full URL // This is used to create the full URL
// This method assumes the filename is in the correct format // This method assumes the filename is in the correct format
QString Test::getExpectedImagePartialSourceDirectory(QString filename) { QString Test::getExpectedImagePartialSourceDirectory(const QString& filename) {
QString filenameWithoutExtension = filename.split(".")[0]; QString filenameWithoutExtension = filename.split(".")[0];
QStringList filenameParts = filenameWithoutExtension.split("_"); QStringList filenameParts = filenameWithoutExtension.split("_");

View file

@ -43,39 +43,39 @@ class Test {
public: public:
Test(); Test();
void startTestsEvaluation(); void startTestsEvaluation(const QString& testFolder = QString());
void finishTestsEvaluation(bool interactiveMode, QProgressBar* progressBar); void finishTestsEvaluation(bool isRunningFromCommandline, bool interactiveMode, QProgressBar* progressBar);
void createRecursiveScript(); void createRecursiveScript();
void createAllRecursiveScripts(); void createAllRecursiveScripts();
void createRecursiveScript(QString topLevelDirectory, bool interactiveMode); void createRecursiveScript(const QString& topLevelDirectory, bool interactiveMode);
void createTest(); void createTest();
void createMDFile(); void createMDFile();
void createAllMDFiles(); void createAllMDFiles();
void createMDFile(QString topLevelDirectory); void createMDFile(const QString& topLevelDirectory);
void createTestsOutline(); void createTestsOutline();
bool compareImageLists(bool isInteractiveMode, QProgressBar* progressBar); bool compareImageLists(bool isInteractiveMode, QProgressBar* progressBar);
QStringList createListOfAll_imagesInDirectory(QString imageFormat, QString pathToImageDirectory); QStringList createListOfAll_imagesInDirectory(const QString& imageFormat, const QString& pathToImageDirectory);
bool isInSnapshotFilenameFormat(QString imageFormat, QString filename); bool isInSnapshotFilenameFormat(const QString& imageFormat, const QString& filename);
void importTest(QTextStream& textStream, const QString& testPathname); void importTest(QTextStream& textStream, const QString& testPathname);
void appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage); void appendTestResultsToFile(const QString& testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage);
bool createTestResultsFolderPath(QString directory); bool createTestResultsFolderPath(const QString& directory);
void zipAndDeleteTestResultsFolder(); void zipAndDeleteTestResultsFolder();
bool isAValidDirectory(QString pathname); bool isAValidDirectory(const QString& pathname);
QString extractPathFromTestsDown(QString fullPath); QString extractPathFromTestsDown(const QString& fullPath);
QString getExpectedImageDestinationDirectory(QString filename); QString getExpectedImageDestinationDirectory(const QString& filename);
QString getExpectedImagePartialSourceDirectory(QString filename); QString getExpectedImagePartialSourceDirectory(const QString& filename);
void copyJPGtoPNG(QString sourceJPGFullFilename, QString destinationPNGFullFilename); void copyJPGtoPNG(const QString& sourceJPGFullFilename, const QString& destinationPNGFullFilename);
private: private:
const QString TEST_FILENAME { "test.js" }; const QString TEST_FILENAME { "test.js" };
@ -90,14 +90,13 @@ private:
ImageComparer imageComparer; ImageComparer imageComparer;
QString testResultsFolderPath { "" }; QString testResultsFolderPath;
int index { 1 }; int index { 1 };
// Expected images are in the format ExpectedImage_dddd.jpg (d == decimal digit) // Expected images are in the format ExpectedImage_dddd.jpg (d == decimal digit)
const int NUM_DIGITS { 5 }; const int NUM_DIGITS { 5 };
const QString EXPECTED_IMAGE_PREFIX { "ExpectedImage_" }; const QString EXPECTED_IMAGE_PREFIX { "ExpectedImage_" };
QString pathToTestResultsDirectory;
QStringList expectedImagesFilenames; QStringList expectedImagesFilenames;
QStringList expectedImagesFullFilenames; QStringList expectedImagesFullFilenames;
QStringList resultImagesFullFilenames; QStringList resultImagesFullFilenames;

View file

@ -13,10 +13,23 @@
AutoTester* autoTester; AutoTester* autoTester;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Only parameter is "--testFolder"
QString testFolder;
if (argc == 3) {
if (QString(argv[1]) == "--testFolder") {
testFolder = QString(argv[2]);
}
}
QApplication application(argc, argv); QApplication application(argc, argv);
autoTester = new AutoTester(); autoTester = new AutoTester();
autoTester->show();
if (!testFolder.isNull()) {
autoTester->runFromCommandLine(testFolder);
} else {
autoTester->show();
}
return application.exec(); return application.exec();
} }

View file

@ -15,12 +15,17 @@ AutoTester::AutoTester(QWidget *parent) : QMainWindow(parent) {
ui.checkBoxInteractiveMode->setChecked(true); ui.checkBoxInteractiveMode->setChecked(true);
ui.progressBar->setVisible(false); ui.progressBar->setVisible(false);
test = new Test();
signalMapper = new QSignalMapper(); signalMapper = new QSignalMapper();
connect(ui.actionClose, &QAction::triggered, this, &AutoTester::on_closeButton_clicked); connect(ui.actionClose, &QAction::triggered, this, &AutoTester::on_closeButton_clicked);
connect(ui.actionAbout, &QAction::triggered, this, &AutoTester::about); connect(ui.actionAbout, &QAction::triggered, this, &AutoTester::about);
test = new Test();
}
void AutoTester::runFromCommandLine(const QString& testFolder) {
isRunningFromCommandline = true;
test->startTestsEvaluation(testFolder);
} }
void AutoTester::on_evaluateTestsButton_clicked() { void AutoTester::on_evaluateTestsButton_clicked() {
@ -86,7 +91,6 @@ void AutoTester::downloadImages(const QStringList& URLs, const QString& director
} }
void AutoTester::saveImage(int index) { void AutoTester::saveImage(int index) {
QByteArray q = downloaders[index]->downloadedData();
QPixmap pixmap; QPixmap pixmap;
pixmap.loadFromData(downloaders[index]->downloadedData()); pixmap.loadFromData(downloaders[index]->downloadedData());
@ -105,7 +109,7 @@ void AutoTester::saveImage(int index) {
++_numberOfImagesDownloaded; ++_numberOfImagesDownloaded;
if (_numberOfImagesDownloaded == _numberOfImagesToDownload) { if (_numberOfImagesDownloaded == _numberOfImagesToDownload) {
test->finishTestsEvaluation(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar); test->finishTestsEvaluation(isRunningFromCommandline, ui.checkBoxInteractiveMode->isChecked(), ui.progressBar);
} else { } else {
ui.progressBar->setValue(_numberOfImagesDownloaded); ui.progressBar->setValue(_numberOfImagesDownloaded);
} }

View file

@ -22,6 +22,9 @@ class AutoTester : public QMainWindow {
public: public:
AutoTester(QWidget *parent = Q_NULLPTR); AutoTester(QWidget *parent = Q_NULLPTR);
void runFromCommandLine(const QString& testFolder);
void downloadImage(const QUrl& url); void downloadImage(const QUrl& url);
void downloadImages(const QStringList& URLs, const QString& directoryName, const QStringList& filenames); void downloadImages(const QStringList& URLs, const QString& directoryName, const QStringList& filenames);
@ -55,6 +58,8 @@ private:
int _numberOfImagesToDownload { 0 }; int _numberOfImagesToDownload { 0 };
int _numberOfImagesDownloaded { 0 }; int _numberOfImagesDownloaded { 0 };
int _index { 0 }; int _index { 0 };
bool isRunningFromCommandline { false };
}; };
#endif // hifi_AutoTester_h #endif // hifi_AutoTester_h