mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
First success with running from command line.
This commit is contained in:
parent
a3e4fa8429
commit
93afbcdc08
5 changed files with 70 additions and 44 deletions
|
@ -27,7 +27,7 @@ Test::Test() {
|
|||
mismatchWindow.setModal(true);
|
||||
}
|
||||
|
||||
bool Test::createTestResultsFolderPath(QString directory) {
|
||||
bool Test::createTestResultsFolderPath(const QString& directory) {
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
testResultsFolderPath = directory + "/" + TEST_RESULTS_FOLDER + "--" + now.toString(DATETIME_FORMAT);
|
||||
QDir testResultsFolder(testResultsFolderPath);
|
||||
|
@ -125,7 +125,7 @@ bool Test::compareImageLists(bool isInteractiveMode, QProgressBar* progressBar)
|
|||
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)) {
|
||||
messageBox.critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "Folder " + testResultsFolderPath + " not found");
|
||||
exit(-1);
|
||||
|
@ -174,10 +174,16 @@ void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure te
|
|||
comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg");
|
||||
}
|
||||
|
||||
void Test::startTestsEvaluation() {
|
||||
// Get list of JPEG images in folder, sorted by name
|
||||
pathToTestResultsDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly);
|
||||
if (pathToTestResultsDirectory == "") {
|
||||
void Test::startTestsEvaluation(const QString& testFolder) {
|
||||
QString pathToTestResultsDirectory;
|
||||
if (testFolder.isNull()) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -221,9 +227,6 @@ void Test::startTestsEvaluation() {
|
|||
QString expectedImageFilenameTail = currentFilename.left(currentFilename.length() - 4).right(NUM_DIGITS);
|
||||
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 + "/" +
|
||||
expectedImagePartialSourceDirectory + "/" + expectedImageStoredFilename);
|
||||
|
||||
|
@ -240,19 +243,21 @@ void Test::startTestsEvaluation() {
|
|||
autoTester->downloadImages(expectedImagesURLs, pathToTestResultsDirectory, expectedImagesFilenames);
|
||||
}
|
||||
|
||||
void Test::finishTestsEvaluation(bool interactiveMode, QProgressBar* progressBar) {
|
||||
bool success = compareImageLists(interactiveMode, progressBar);
|
||||
void Test::finishTestsEvaluation(bool isRunningFromCommandline, bool interactiveMode, QProgressBar* progressBar) {
|
||||
bool success = compareImageLists((!isRunningFromCommandline && interactiveMode), progressBar);
|
||||
|
||||
if (success) {
|
||||
messageBox.information(0, "Success", "All images are as expected");
|
||||
} else {
|
||||
messageBox.information(0, "Failure", "One or more images are not as expected");
|
||||
if (!isRunningFromCommandline) {
|
||||
if (success) {
|
||||
messageBox.information(0, "Success", "All images are as expected");
|
||||
} else {
|
||||
messageBox.information(0, "Failure", "One or more images are not as expected");
|
||||
}
|
||||
}
|
||||
|
||||
zipAndDeleteTestResultsFolder();
|
||||
}
|
||||
|
||||
bool Test::isAValidDirectory(QString pathname) {
|
||||
bool Test::isAValidDirectory(const QString& pathname) {
|
||||
// Only process directories
|
||||
QDir dir(pathname);
|
||||
if (!dir.exists()) {
|
||||
|
@ -267,7 +272,7 @@ bool Test::isAValidDirectory(QString pathname) {
|
|||
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`
|
||||
QStringList pathParts = fullPath.split('/');
|
||||
int i{ 0 };
|
||||
|
@ -348,7 +353,7 @@ void Test::createAllRecursiveScripts() {
|
|||
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");
|
||||
QFile allTestsFilename(topLevelDirectory + "/" + recursiveTestsFilename);
|
||||
if (!allTestsFilename.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
|
@ -615,7 +620,7 @@ void Test::createAllMDFiles() {
|
|||
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
|
||||
QString testFileName(testDirectory + "/" + TEST_FILENAME);
|
||||
QFileInfo testFileInfo(testFileName);
|
||||
|
@ -790,7 +795,7 @@ void Test::createTestsOutline() {
|
|||
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);
|
||||
|
||||
QImageReader reader;
|
||||
|
@ -803,7 +808,7 @@ void Test::copyJPGtoPNG(QString sourceJPGFullFilename, QString destinationPNGFul
|
|||
writer.write(image);
|
||||
}
|
||||
|
||||
QStringList Test::createListOfAll_imagesInDirectory(QString imageFormat, QString pathToImageDirectory) {
|
||||
QStringList Test::createListOfAll_imagesInDirectory(const QString& imageFormat, const QString& pathToImageDirectory) {
|
||||
imageDirectory = QDir(pathToImageDirectory);
|
||||
QStringList nameFilters;
|
||||
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
|
||||
// Last 5 characters in filename are digits
|
||||
// Extension is jpg
|
||||
bool Test::isInSnapshotFilenameFormat(QString imageFormat, QString filename) {
|
||||
bool Test::isInSnapshotFilenameFormat(const QString& imageFormat, const QString& filename) {
|
||||
QStringList filenameParts = filename.split(".");
|
||||
|
||||
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
|
||||
// D:/GitHub/hifi-tests/tests/content/entity/zone/create
|
||||
// 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];
|
||||
QStringList filenameParts = filenameWithoutExtension.split("_");
|
||||
|
||||
|
@ -850,7 +855,7 @@ QString Test::getExpectedImageDestinationDirectory(QString filename) {
|
|||
// is ...tests/content/entity/zone/create
|
||||
// This is used to create the full URL
|
||||
// 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];
|
||||
QStringList filenameParts = filenameWithoutExtension.split("_");
|
||||
|
||||
|
|
|
@ -43,39 +43,39 @@ class Test {
|
|||
public:
|
||||
Test();
|
||||
|
||||
void startTestsEvaluation();
|
||||
void finishTestsEvaluation(bool interactiveMode, QProgressBar* progressBar);
|
||||
void startTestsEvaluation(const QString& testFolder = QString());
|
||||
void finishTestsEvaluation(bool isRunningFromCommandline, bool interactiveMode, QProgressBar* progressBar);
|
||||
|
||||
void createRecursiveScript();
|
||||
void createAllRecursiveScripts();
|
||||
void createRecursiveScript(QString topLevelDirectory, bool interactiveMode);
|
||||
void createRecursiveScript(const QString& topLevelDirectory, bool interactiveMode);
|
||||
|
||||
void createTest();
|
||||
void createMDFile();
|
||||
void createAllMDFiles();
|
||||
void createMDFile(QString topLevelDirectory);
|
||||
void createMDFile(const QString& topLevelDirectory);
|
||||
|
||||
void createTestsOutline();
|
||||
|
||||
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 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();
|
||||
|
||||
bool isAValidDirectory(QString pathname);
|
||||
QString extractPathFromTestsDown(QString fullPath);
|
||||
QString getExpectedImageDestinationDirectory(QString filename);
|
||||
QString getExpectedImagePartialSourceDirectory(QString filename);
|
||||
bool isAValidDirectory(const QString& pathname);
|
||||
QString extractPathFromTestsDown(const QString& fullPath);
|
||||
QString getExpectedImageDestinationDirectory(const QString& filename);
|
||||
QString getExpectedImagePartialSourceDirectory(const QString& filename);
|
||||
|
||||
void copyJPGtoPNG(QString sourceJPGFullFilename, QString destinationPNGFullFilename);
|
||||
void copyJPGtoPNG(const QString& sourceJPGFullFilename, const QString& destinationPNGFullFilename);
|
||||
|
||||
private:
|
||||
const QString TEST_FILENAME { "test.js" };
|
||||
|
@ -90,14 +90,13 @@ private:
|
|||
|
||||
ImageComparer imageComparer;
|
||||
|
||||
QString testResultsFolderPath { "" };
|
||||
QString testResultsFolderPath;
|
||||
int index { 1 };
|
||||
|
||||
// Expected images are in the format ExpectedImage_dddd.jpg (d == decimal digit)
|
||||
const int NUM_DIGITS { 5 };
|
||||
const QString EXPECTED_IMAGE_PREFIX { "ExpectedImage_" };
|
||||
|
||||
QString pathToTestResultsDirectory;
|
||||
QStringList expectedImagesFilenames;
|
||||
QStringList expectedImagesFullFilenames;
|
||||
QStringList resultImagesFullFilenames;
|
||||
|
|
|
@ -13,10 +13,23 @@
|
|||
AutoTester* autoTester;
|
||||
|
||||
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);
|
||||
|
||||
autoTester = new AutoTester();
|
||||
autoTester->show();
|
||||
|
||||
if (!testFolder.isNull()) {
|
||||
autoTester->runFromCommandLine(testFolder);
|
||||
} else {
|
||||
autoTester->show();
|
||||
}
|
||||
|
||||
return application.exec();
|
||||
}
|
||||
|
|
|
@ -15,12 +15,17 @@ AutoTester::AutoTester(QWidget *parent) : QMainWindow(parent) {
|
|||
ui.checkBoxInteractiveMode->setChecked(true);
|
||||
ui.progressBar->setVisible(false);
|
||||
|
||||
test = new Test();
|
||||
|
||||
signalMapper = new QSignalMapper();
|
||||
|
||||
connect(ui.actionClose, &QAction::triggered, this, &AutoTester::on_closeButton_clicked);
|
||||
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() {
|
||||
|
@ -86,7 +91,6 @@ void AutoTester::downloadImages(const QStringList& URLs, const QString& director
|
|||
}
|
||||
|
||||
void AutoTester::saveImage(int index) {
|
||||
QByteArray q = downloaders[index]->downloadedData();
|
||||
QPixmap pixmap;
|
||||
pixmap.loadFromData(downloaders[index]->downloadedData());
|
||||
|
||||
|
@ -105,7 +109,7 @@ void AutoTester::saveImage(int index) {
|
|||
++_numberOfImagesDownloaded;
|
||||
|
||||
if (_numberOfImagesDownloaded == _numberOfImagesToDownload) {
|
||||
test->finishTestsEvaluation(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar);
|
||||
test->finishTestsEvaluation(isRunningFromCommandline, ui.checkBoxInteractiveMode->isChecked(), ui.progressBar);
|
||||
} else {
|
||||
ui.progressBar->setValue(_numberOfImagesDownloaded);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ class AutoTester : public QMainWindow {
|
|||
|
||||
public:
|
||||
AutoTester(QWidget *parent = Q_NULLPTR);
|
||||
|
||||
void runFromCommandLine(const QString& testFolder);
|
||||
|
||||
void downloadImage(const QUrl& url);
|
||||
void downloadImages(const QStringList& URLs, const QString& directoryName, const QStringList& filenames);
|
||||
|
||||
|
@ -55,6 +58,8 @@ private:
|
|||
int _numberOfImagesToDownload { 0 };
|
||||
int _numberOfImagesDownloaded { 0 };
|
||||
int _index { 0 };
|
||||
|
||||
bool isRunningFromCommandline { false };
|
||||
};
|
||||
|
||||
#endif // hifi_AutoTester_h
|
Loading…
Reference in a new issue