mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
Simplifying code.
This commit is contained in:
parent
1ffd005b77
commit
0c8f80026a
3 changed files with 40 additions and 22 deletions
|
@ -23,7 +23,10 @@ extern AutoTester* autoTester;
|
|||
|
||||
#include <math.h>
|
||||
|
||||
Test::Test() {
|
||||
Test::Test(QProgressBar* progressBar, QCheckBox* checkBoxInteractiveMode) {
|
||||
_progressBar = progressBar;
|
||||
_checkBoxInteractiveMode = checkBoxInteractiveMode;
|
||||
|
||||
_mismatchWindow.setModal(true);
|
||||
|
||||
if (autoTester) {
|
||||
|
@ -58,11 +61,11 @@ void Test::zipAndDeleteTestResultsFolder() {
|
|||
_index = 1;
|
||||
}
|
||||
|
||||
bool Test::compareImageLists(bool isInteractiveMode, QProgressBar* progressBar) {
|
||||
progressBar->setMinimum(0);
|
||||
progressBar->setMaximum(_expectedImagesFullFilenames.length() - 1);
|
||||
progressBar->setValue(0);
|
||||
progressBar->setVisible(true);
|
||||
bool Test::compareImageLists() {
|
||||
_progressBar->setMinimum(0);
|
||||
_progressBar->setMaximum(_expectedImagesFullFilenames.length() - 1);
|
||||
_progressBar->setValue(0);
|
||||
_progressBar->setVisible(true);
|
||||
|
||||
// Loop over both lists and compare each pair of images
|
||||
// Quit loop if user has aborted due to a failed test.
|
||||
|
@ -74,6 +77,8 @@ bool Test::compareImageLists(bool isInteractiveMode, QProgressBar* progressBar)
|
|||
QImage expectedImage(_expectedImagesFullFilenames[i]);
|
||||
|
||||
double similarityIndex; // in [-1.0 .. 1.0], where 1.0 means images are identical
|
||||
|
||||
bool isInteractiveMode = (!_isRunningFromCommandLine && _checkBoxInteractiveMode->isChecked());
|
||||
|
||||
// similarityIndex is set to -100.0 to indicate images are not the same size
|
||||
if (isInteractiveMode && (resultImage.width() != expectedImage.width() || resultImage.height() != expectedImage.height())) {
|
||||
|
@ -117,10 +122,10 @@ bool Test::compareImageLists(bool isInteractiveMode, QProgressBar* progressBar)
|
|||
}
|
||||
}
|
||||
|
||||
progressBar->setValue(i);
|
||||
_progressBar->setValue(i);
|
||||
}
|
||||
|
||||
progressBar->setVisible(false);
|
||||
_progressBar->setVisible(false);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -173,7 +178,13 @@ void Test::appendTestResultsToFile(const QString& _testResultsFolderPath, TestFa
|
|||
comparisonImage.save(failureFolderPath + "/" + "Difference Image.png");
|
||||
}
|
||||
|
||||
void Test::startTestsEvaluation(const QString& testFolder, const QString& branchFromCommandLine, const QString& userFromCommandLine) {
|
||||
void Test::startTestsEvaluation(const bool isRunningFromCommandLine,
|
||||
const QString& testFolder,
|
||||
const QString& branchFromCommandLine,
|
||||
const QString& userFromCommandLine
|
||||
) {
|
||||
_isRunningFromCommandLine = isRunningFromCommandLine;
|
||||
|
||||
if (testFolder.isNull()) {
|
||||
// Get list of JPEG images in folder, sorted by name
|
||||
QString previousSelection = _snapshotDirectory;
|
||||
|
@ -240,11 +251,10 @@ void Test::startTestsEvaluation(const QString& testFolder, const QString& branch
|
|||
|
||||
autoTester->downloadFiles(expectedImagesURLs, _snapshotDirectory, _expectedImagesFilenames);
|
||||
}
|
||||
|
||||
void Test::finishTestsEvaluation(bool isRunningFromCommandline, bool interactiveMode, QProgressBar* progressBar) {
|
||||
bool success = compareImageLists((!isRunningFromCommandline && interactiveMode), progressBar);
|
||||
void Test::finishTestsEvaluation() {
|
||||
bool success = compareImageLists();
|
||||
|
||||
if (!isRunningFromCommandline) {
|
||||
if (!_isRunningFromCommandLine) {
|
||||
if (success) {
|
||||
QMessageBox::information(0, "Success", "All images are as expected");
|
||||
} else {
|
||||
|
|
|
@ -41,10 +41,14 @@ enum TestRailCreateMode {
|
|||
|
||||
class Test {
|
||||
public:
|
||||
Test();
|
||||
Test(QProgressBar* progressBar, QCheckBox* checkBoxInteractiveMode);
|
||||
|
||||
void startTestsEvaluation(const QString& testFolder = QString(), const QString& branchFromCommandLine = QString(), const QString& userFromCommandLine = QString());
|
||||
void finishTestsEvaluation(bool isRunningFromCommandline, bool interactiveMode, QProgressBar* progressBar);
|
||||
void startTestsEvaluation(const bool isRunningFromCommandLine,
|
||||
const QString& testFolder = QString(),
|
||||
const QString& branchFromCommandLine = QString(),
|
||||
const QString& userFromCommandLine = QString());
|
||||
|
||||
void finishTestsEvaluation();
|
||||
|
||||
void createTests();
|
||||
|
||||
|
@ -70,7 +74,7 @@ public:
|
|||
void createAllRecursiveScripts();
|
||||
void createRecursiveScript(const QString& topLevelDirectory, bool interactiveMode);
|
||||
|
||||
bool compareImageLists(bool isInteractiveMode, QProgressBar* progressBar);
|
||||
bool compareImageLists();
|
||||
|
||||
QStringList createListOfAll_imagesInDirectory(const QString& imageFormat, const QString& pathToImageDirectory);
|
||||
|
||||
|
@ -93,6 +97,11 @@ public:
|
|||
void setTestRailCreateMode(TestRailCreateMode testRailCreateMode);
|
||||
|
||||
private:
|
||||
QProgressBar* _progressBar;
|
||||
QCheckBox* _checkBoxInteractiveMode;
|
||||
|
||||
bool _isRunningFromCommandLine{ false };
|
||||
|
||||
const QString TEST_FILENAME { "test.js" };
|
||||
const QString TEST_RESULTS_FOLDER { "TestResults" };
|
||||
const QString TEST_RESULTS_FILENAME { "TestResults.txt" };
|
||||
|
|
|
@ -36,12 +36,11 @@ AutoTester::AutoTester(QWidget* parent) : QMainWindow(parent) {
|
|||
}
|
||||
|
||||
void AutoTester::setup() {
|
||||
_test = new Test();
|
||||
_test = new Test(_ui.progressBar, _ui.checkBoxInteractiveMode);
|
||||
}
|
||||
|
||||
void AutoTester::runFromCommandLine(const QString& testFolder, const QString& branch, const QString& user) {
|
||||
_isRunningFromCommandline = true;
|
||||
_test->startTestsEvaluation(testFolder, branch, user);
|
||||
_test->startTestsEvaluation(true, testFolder, branch, user);
|
||||
}
|
||||
|
||||
void AutoTester::on_tabWidget_currentChanged(int index) {
|
||||
|
@ -55,7 +54,7 @@ void AutoTester::on_tabWidget_currentChanged(int index) {
|
|||
}
|
||||
|
||||
void AutoTester::on_evaluateTestsButton_clicked() {
|
||||
_test->startTestsEvaluation();
|
||||
_test->startTestsEvaluation(false);
|
||||
}
|
||||
|
||||
void AutoTester::on_createRecursiveScriptButton_clicked() {
|
||||
|
@ -188,7 +187,7 @@ void AutoTester::saveFile(int index) {
|
|||
|
||||
if (_numberOfFilesDownloaded == _numberOfFilesToDownload) {
|
||||
disconnect(_signalMapper, SIGNAL(mapped(int)), this, SLOT(saveFile(int)));
|
||||
_test->finishTestsEvaluation(_isRunningFromCommandline, _ui.checkBoxInteractiveMode->isChecked(), _ui.progressBar);
|
||||
_test->finishTestsEvaluation();
|
||||
} else {
|
||||
_ui.progressBar->setValue(_numberOfFilesDownloaded);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue