From 346c691f0c977718944a19c02415b03e35967974 Mon Sep 17 00:00:00 2001 From: "nissim.hadar" Date: Wed, 22 Nov 2017 10:56:32 -0800 Subject: [PATCH] Implemented creation of allTests.js --- tools/auto-tester/src/Test.cpp | 43 +++++++++++++++++++++-- tools/auto-tester/src/Test.h | 1 + tools/auto-tester/src/ui/AutoTester.cpp | 14 +++++--- tools/auto-tester/src/ui/AutoTester.h | 1 + tools/auto-tester/src/ui/AutoTester.ui | 45 +++++++++++++++---------- 5 files changed, 81 insertions(+), 23 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index cf0cb0d08c..502cc29682 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -31,6 +31,7 @@ #include #include +#include Test::Test() { snapshotFilenameFormat = QRegularExpression("hifi-snap-by-.+-on-\\d\\d\\d\\d-\\d\\d-\\d\\d_\\d\\d-\\d\\d-\\d\\d.jpg"); @@ -105,7 +106,45 @@ void Test::evaluateTests() { messageBox.information(0, "Failure", "One or more images are not as expected"); } } - + +// Creates a single script in a user-selected folder. +// This script will run all text.js scripts in every applicable sub-folder +void Test::createRecursiveScript() { + // Select folder to start recursing from + QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder that will contain the top level test script", ".", QFileDialog::ShowDirsOnly); + QDirIterator it(topLevelDirectory.toStdString().c_str(), QDirIterator::Subdirectories); + + QFile allTestsFilename(topLevelDirectory + "/" + "allTests.js"); + if (!allTestsFilename.open(QIODevice::WriteOnly | QIODevice::Text)) { + messageBox.critical(0, + "Internal Error", + "Failed to create \"allTests.js\" in directory \"" + topLevelDirectory + "\""); + + exit(-1); + } + + QTextStream textStream(&allTestsFilename); + textStream << "// This is an automatically generated file, created by auto-tester" << endl; + + const QString testFilename{ "test.js" }; + while (it.hasNext()) { + QString directory = it.next(); + if (directory[directory.length() - 1] == '.') { + continue; // ignore '.', '..' directories + } + + const QString testPathname{ directory + "/" + testFilename }; + + QFileInfo fileInfo(testPathname); + if (fileInfo.exists()) { + // Current folder contains a test + textStream << "Script.include(\"" << testPathname << "/" << " ? raw = true\")" << endl; + } + } + + allTestsFilename.close(); +} + void Test::createTest() { // Rename files sequentially, as ExpectedResult_1.jpeg, ExpectedResult_2.jpg and so on // Any existing expected result images will be deleted @@ -130,7 +169,7 @@ void Test::createTest() { } void Test::createListOfAllJPEGimagesInDirectory() { - // get list of JPEG images in folder, sorted by name + // Get list of JPEG images in folder, sorted by name pathToImageDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); imageDirectory = QDir(pathToImageDirectory); diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 5f6276063c..ea9e6a5417 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -24,6 +24,7 @@ public: Test(); void evaluateTests(); + void createRecursiveScript(); void createTest(); void createListOfAllJPEGimagesInDirectory(); diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index 2190d61856..aa18dc4378 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -16,17 +16,23 @@ AutoTester::AutoTester(QWidget *parent) ui.setupUi(this); } -void AutoTester::on_closeButton_clicked() -{ - exit(0); -} void AutoTester::on_evaluateTestsButton_clicked() { test.evaluateTests(); } +void AutoTester::on_createRecursiveScriptButton_clicked() +{ + test.createRecursiveScript(); +} + void AutoTester::on_createTestButton_clicked() { test.createTest(); } + +void AutoTester::on_closeButton_clicked() +{ + exit(0); +} \ No newline at end of file diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/auto-tester/src/ui/AutoTester.h index 6b44b77cd7..93eb22af7d 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/auto-tester/src/ui/AutoTester.h @@ -24,6 +24,7 @@ public: private slots: void on_evaluateTestsButton_clicked(); + void on_createRecursiveScriptButton_clicked(); void on_createTestButton_clicked(); void on_closeButton_clicked(); diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index 793188d184..d6c16beeb4 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -6,8 +6,8 @@ 0 0 - 261 - 330 + 277 + 351 @@ -17,10 +17,10 @@ - 80 - 210 - 100 - 23 + 60 + 240 + 159 + 40 @@ -30,10 +30,10 @@ - 80 - 160 - 100 - 23 + 60 + 180 + 160 + 40 @@ -43,23 +43,36 @@ - 80 + 60 20 - 100 - 23 + 160 + 40 Evaulate Tests + + + + 60 + 120 + 160 + 40 + + + + Create Recursive Script + + 0 0 - 261 + 277 21 @@ -75,8 +88,6 @@ - - - +