From 60f4c6788faeddda9524936f98240a3b73703cfe Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Tue, 10 Apr 2018 23:04:56 -0700 Subject: [PATCH] Added creation of tests outline .MD file. --- tools/auto-tester/src/Test.cpp | 54 +++++++++++++++++++++++++ tools/auto-tester/src/Test.h | 2 + tools/auto-tester/src/ui/AutoTester.cpp | 4 ++ tools/auto-tester/src/ui/AutoTester.h | 1 + tools/auto-tester/src/ui/AutoTester.ui | 17 +++++++- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 9af5f3a079..b5a0069701 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -688,6 +688,60 @@ void Test::createMDFile(QString testDirectory) { mdFile.close(); } +void Test::createTestsOutline() { + QString testsRootDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select the tests root folder", ".", QFileDialog::ShowDirsOnly); + if (testsRootDirectory == "") { + return; + } + + const QString testsOutlineFilename { "testsOutline.md" }; + QString mdFilename(testsRootDirectory + "/" + testsOutlineFilename); + QFile mdFile(mdFilename); + if (!mdFile.open(QIODevice::WriteOnly)) { + messageBox.critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "Failed to create file " + mdFilename); + exit(-1); + } + + QTextStream stream(&mdFile); + + //Test title + stream << "# Outline of all tests\n"; + stream << "Directories with an appended (*) have an automatic test\n\n"; + + // We need to know our current depth, as this isn't given by QDirIterator + int rootDepth { testsRootDirectory.count('/') }; + + QDirIterator it(testsRootDirectory.toStdString().c_str(), QDirIterator::Subdirectories); + while (it.hasNext()) { + QString directory = it.next(); + + // Only process directories + QDir dir; + if (!isAValidDirectory(directory)) { + continue; + } + + // Ignore the utils directory + if (directory.right(5) == "utils") { + continue; + } + + int currentDepth = directory.count('/') - rootDepth; + QString prefix = QString(" ").repeated(2 * currentDepth - 1) + " - "; + stream << prefix; + stream << directory.right(directory.length() - directory.lastIndexOf("/") - 1); + QFileInfo fileInfo(directory + "/" + TEST_FILENAME); + if (fileInfo.exists()) { + stream << " (*)"; + } + stream << "\n"; + } + + mdFile.close(); + + messageBox.information(0, "Success", "Test outline file " + testsOutlineFilename + " has been created"); +} + void Test::copyJPGtoPNG(QString sourceJPGFullFilename, QString destinationPNGFullFilename) { QFile::remove(destinationPNGFullFilename); diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 64923da729..e69459fef2 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -53,6 +53,8 @@ public: void createAllMDFiles(); void createMDFile(QString topLevelDirectory); + void createTestsOutline(); + bool compareImageLists(bool isInteractiveMode, QProgressBar* progressBar); QStringList createListOfAll_imagesInDirectory(QString imageFormat, QString pathToImageDirectory); diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index fd001cc774..21acfe9569 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -44,6 +44,10 @@ void AutoTester::on_createAllMDFilesButton_clicked() { test->createAllMDFiles(); } +void AutoTester::on_createTestsOutlineButton_clicked() { + test->createTestsOutline(); +} + void AutoTester::on_closeButton_clicked() { exit(0); } diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/auto-tester/src/ui/AutoTester.h index 643286563c..1788e97177 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/auto-tester/src/ui/AutoTester.h @@ -32,6 +32,7 @@ private slots: void on_createTestButton_clicked(); void on_createMDFileButton_clicked(); void on_createAllMDFilesButton_clicked(); + void on_createTestsOutlineButton_clicked(); void on_closeButton_clicked(); void saveImage(int index); diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index 391bb61fd4..2eb1314481 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -57,7 +57,7 @@ 360 - 75 + 35 220 40 @@ -99,7 +99,7 @@ 360 - 140 + 100 220 40 @@ -134,6 +134,19 @@ Create all MD files + + + + 20 + 180 + 220 + 40 + + + + Create Tests Outline + +