54 #include <qtestcase.h>
55 #include <QApplication>
64 #include <QScopedPointer>
65 #include <QStaticStringData>
66 #include <QStringData>
67 #include <QStringDataPtr>
68 #include <QStringList>
75 #include "../vgeometry/vgeometrydef.h"
76 #include "../vgeometry/vgobject.h"
77 #include "../vgeometry/vpointf.h"
78 #include "../vgeometry/vspline.h"
79 #include "../vgeometry/vsplinepath.h"
80 #include "../vlayout/vabstractpiece.h"
81 #include "../vpatterndb/vcontainer.h"
82 #include "../vpatterndb/vpiece.h"
83 #include "../vpatterndb/vpiecenode.h"
95 QCOMPARE(ekv.size(), ekvOrig.size());
96 const qreal testAccuracy = (1.0 / 25.4) *
PrintDPI;
98 for (
int i=0; i < ekv.size(); i++)
100 Comparison(ekv.at(i), ekvOrig.at(i), testAccuracy);
107 const QString msg = QStringLiteral(
"Actual '%2;%3', Expected '%4;%5'. Distance between points %6 mm.")
108 .arg(result.x()).arg(result.y()).arg(expected.x()).arg(expected.y())
117 const QString path = QStringLiteral(
"/../../../app/seamly2d/bin/");
118 #if defined(Q_OS_WIN)
119 return QCoreApplication::applicationDirPath() + path + QLatin1String(
"seamly2d.exe");
120 #elif defined(Q_OS_MACOS)
121 return QCoreApplication::applicationDirPath() + path + QLatin1String(
"Seamly2D.app/Contents/MacOS/seamly2d");
123 return QCoreApplication::applicationDirPath() + path + QLatin1String(
"seamly2d");
130 const QString path = QStringLiteral(
"/../../../app/seamlyme/bin/");
131 #if defined(Q_OS_WIN)
132 return QCoreApplication::applicationDirPath() + path + QLatin1String(
"seamlyme.exe");
133 #elif defined(Q_OS_MACOS)
134 return QCoreApplication::applicationDirPath() + path + QLatin1String(
"seamlyme.app/Contents/MacOS/seamlyme");
136 return QCoreApplication::applicationDirPath() + path + QLatin1String(
"seamlyme");
143 return QCoreApplication::applicationDirPath() + QStringLiteral(
"/../../../app/seamly2d/.qm");
147 int AbstractTest::Run(
int exit,
const QString &program,
const QStringList &arguments, QString &error,
int msecs)
149 const QString parameters = QString(
"Program: %1 \nArguments: %2.").arg(program).arg(arguments.join(
", "));
151 QFileInfo info(program);
152 if (not info.exists())
154 error = QString(
"Can't find binary.\n%1").arg(parameters);
158 QScopedPointer<QProcess> process(
new QProcess());
159 process->setWorkingDirectory(info.absoluteDir().absolutePath());
160 process->start(program, arguments);
162 if (not process->waitForStarted(msecs))
164 error = QString(
"The start operation timed out or an error occurred.\n%1").arg(parameters);
169 if (not process->waitForFinished(msecs))
171 error = QString(
"The finish operation timed out or an error occurred.\n%1").arg(parameters);
176 if (process->exitStatus() == QProcess::CrashExit)
178 error = QString(
"Program crashed.\n%1\n%2").arg(parameters).arg(QString(process->readAllStandardError()));
182 if (process->exitCode() != exit)
184 error = QString(
"Unexpected finish.\n%1").arg(QString(process->readAllStandardError()));
185 return process->exitCode();
188 return process->exitCode();
194 QFileInfo srcFileInfo(srcFilePath);
195 if (srcFileInfo.isDir())
197 QDir targetDir(tgtFilePath);
199 const QString dirName = QFileInfo(tgtFilePath).fileName();
200 if (not targetDir.mkdir(dirName))
202 const QString msg = QString(
"Can't create dir '%1'.").arg(dirName);
203 QWARN(qUtf8Printable(msg));
206 QDir sourceDir(srcFilePath);
207 QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden |
209 foreach (
const QString &fileName, fileNames)
211 const QString newSrcFilePath = srcFilePath + QDir::separator() + fileName;
212 const QString newTgtFilePath = tgtFilePath + QDir::separator() + fileName;
221 if (QFileInfo(tgtFilePath).exists())
223 const QString msg = QString(
"File '%1' exists.").arg(srcFilePath);
224 QWARN(qUtf8Printable(msg));
226 if (QFile::remove(tgtFilePath))
228 QWARN(
"File successfully removed.");
232 QWARN(
"Can't remove file.");
238 QFile srcFile(srcFilePath);
239 if (not srcFile.open(QFile::ReadOnly))
241 const QString msg = QString(
"Can't copy file '%1'. Error: %2").arg(srcFilePath).arg(srcFile.errorString());
242 QWARN(qUtf8Printable(msg));
247 if (not srcFile.copy(tgtFilePath))
249 const QString msg = QString(
"Can't copy file '%1' to '%2'. Error: %3").arg(srcFilePath).arg(tgtFilePath)
250 .arg(srcFile.errorString());
251 QWARN(qUtf8Printable(msg));
static const auto TST_EX_CRASH
static const auto TST_EX_BIN
static const auto TST_EX_START_TIME_OUT
static const auto TST_EX_FINISH_TIME_OUT
QString TranslationsPath() const
int Run(int exit, const QString &program, const QStringList &arguments, QString &error, int msecs=120000)
bool CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const
AbstractTest(QObject *parent=nullptr)
QString SeamlyMePath() const
QString Seamly2DPath() const
void Comparison(const QVector< QPointF > &ekv, const QVector< QPointF > &ekvOrig) const
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
static Q_REQUIRED_RESULT bool VFuzzyComparePoints(const QPointF &p1, const QPointF &p2, qreal accuracy=accuracyPointOnLine)