2015-05-07 15:12:53 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file abstracttest.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 7 5, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "abstracttest.h"
|
2015-10-01 17:34:03 +02:00
|
|
|
#include "../vmisc/logging.h"
|
2015-10-03 13:09:06 +02:00
|
|
|
#include "../vmisc/vsysexits.h"
|
2015-05-07 15:12:53 +02:00
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
AbstractTest::AbstractTest(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::Comparison(const QVector<QPointF> &ekv, const QVector<QPointF> &ekvOrig) const
|
|
|
|
{
|
|
|
|
// Begin comparison
|
|
|
|
QCOMPARE(ekv.size(), ekvOrig.size());// First check if sizes equal
|
|
|
|
for (int i=0; i < ekv.size(); i++)
|
|
|
|
{
|
|
|
|
// Check each point
|
|
|
|
QCOMPARE(ekv.at(i).toPoint(), ekvOrig.at(i).toPoint()); // Don't use comparison float values
|
|
|
|
}
|
|
|
|
}
|
2015-09-28 12:42:26 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AbstractTest::ValentinaPath() const
|
|
|
|
{
|
|
|
|
const QString path = QStringLiteral("/../../../app/valentina/bin/valentina");
|
|
|
|
#ifdef Q_OS_WIN
|
2016-07-20 10:39:15 +02:00
|
|
|
return QApplication::applicationDirPath() + path + QLatin1String(".exe");
|
2015-09-28 12:42:26 +02:00
|
|
|
#else
|
|
|
|
return QApplication::applicationDirPath() + path;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AbstractTest::TapePath() const
|
|
|
|
{
|
|
|
|
const QString path = QStringLiteral("/../../../app/tape/bin/tape");
|
|
|
|
#ifdef Q_OS_WIN
|
2016-07-20 10:39:15 +02:00
|
|
|
return QApplication::applicationDirPath() + path + QLatin1String(".exe");
|
2015-09-28 12:42:26 +02:00
|
|
|
#else
|
|
|
|
return QApplication::applicationDirPath() + path;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-16 13:55:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AbstractTest::TranslationsPath() const
|
|
|
|
{
|
|
|
|
return QApplication::applicationDirPath() + QStringLiteral("/../../../app/valentina/bin/translations");
|
|
|
|
}
|
|
|
|
|
2015-09-28 12:42:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-07 20:50:40 +02:00
|
|
|
bool AbstractTest::Run(bool showWarn, int exit, int &exitCode, const QString &program, const QStringList &arguments,
|
|
|
|
int msecs)
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
|
|
|
const QString parameters = QString("Program: %1 \nArguments: %2.").arg(program).arg(arguments.join(", "));
|
|
|
|
|
|
|
|
QFileInfo info(program);
|
|
|
|
if (not info.exists())
|
|
|
|
{
|
2015-10-03 13:09:06 +02:00
|
|
|
const QString msg = QString("Can't find binary.\n%1").arg(parameters);
|
|
|
|
QWARN(qUtf8Printable(msg));
|
|
|
|
exitCode = TST_EX_BIN;
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QProcess *process = new QProcess(this);
|
|
|
|
process->setWorkingDirectory(info.absoluteDir().absolutePath());
|
|
|
|
process->start(program, arguments);
|
|
|
|
|
2015-10-04 14:20:12 +02:00
|
|
|
if (not process->waitForFinished(msecs))
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2015-10-03 13:09:06 +02:00
|
|
|
const QString msg = QString("The operation timed out or an error occurred.\n%1").arg(parameters);
|
|
|
|
QWARN(qUtf8Printable(msg));
|
|
|
|
exitCode = TST_EX_TIME_OUT;
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process->exitStatus() == QProcess::CrashExit)
|
|
|
|
{
|
2015-10-03 13:09:06 +02:00
|
|
|
const QString msg = QString("Program crashed.\n%1\n%2").arg(parameters)
|
|
|
|
.arg(QString(process->readAllStandardError()));
|
|
|
|
QWARN(qUtf8Printable(msg));
|
|
|
|
exitCode = TST_EX_CRASH;
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-03 13:09:06 +02:00
|
|
|
if (process->exitCode() != V_EX_OK)
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2015-10-07 20:50:40 +02:00
|
|
|
if (showWarn || process->exitCode() != exit)
|
2015-10-01 20:02:14 +02:00
|
|
|
{
|
2015-10-03 13:09:06 +02:00
|
|
|
const QString msg = QString("\n%1").arg(QString(process->readAllStandardError()));
|
2015-10-01 20:02:14 +02:00
|
|
|
QWARN(qUtf8Printable(msg));
|
|
|
|
}
|
2015-10-03 13:09:06 +02:00
|
|
|
exitCode = process->exitCode();
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-03 13:09:06 +02:00
|
|
|
exitCode = process->exitCode();
|
2015-09-28 12:42:26 +02:00
|
|
|
delete process;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool AbstractTest::CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const
|
|
|
|
{
|
|
|
|
QFileInfo srcFileInfo(srcFilePath);
|
|
|
|
if (srcFileInfo.isDir())
|
|
|
|
{
|
|
|
|
QDir targetDir(tgtFilePath);
|
|
|
|
targetDir.cdUp();
|
|
|
|
if (not targetDir.mkdir(QFileInfo(tgtFilePath).fileName()))
|
|
|
|
{
|
2016-07-25 17:25:13 +02:00
|
|
|
QWARN("Can't create subdir./n");
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QDir sourceDir(srcFilePath);
|
|
|
|
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden |
|
|
|
|
QDir::System);
|
|
|
|
foreach (const QString &fileName, fileNames)
|
|
|
|
{
|
2015-12-22 15:42:00 +01:00
|
|
|
const QString newSrcFilePath = srcFilePath + QDir::separator() + fileName;
|
|
|
|
const QString newTgtFilePath = tgtFilePath + QDir::separator() + fileName;
|
2015-09-28 12:42:26 +02:00
|
|
|
if (not CopyRecursively(newSrcFilePath, newTgtFilePath))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 17:25:13 +02:00
|
|
|
}
|
|
|
|
else
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
|
|
|
if (not QFile::copy(srcFilePath, tgtFilePath))
|
|
|
|
{
|
2016-07-25 17:25:13 +02:00
|
|
|
QWARN("Can't copy file./n");
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|