2015-05-07 15:12:53 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file abstracttest.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 7 5, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-05-07 15:12:53 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-05-07 15:12:53 +02:00
|
|
|
**
|
|
|
|
** 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"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <qtestcase.h>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QFlags>
|
|
|
|
#include <QIODevice>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QScopedPointer>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QtGlobal>
|
2019-01-09 16:46:02 +01:00
|
|
|
#include <QLineF>
|
2019-08-07 16:53:18 +02:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2017-06-01 12:04:25 +02:00
|
|
|
#include "../vgeometry/vgobject.h"
|
2019-08-29 14:01:27 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vgeometry/vspline.h"
|
|
|
|
#include "../vgeometry/vsplinepath.h"
|
2019-08-07 16:53:18 +02:00
|
|
|
#include "../vlayout/vabstractpiece.h"
|
2019-08-29 14:01:27 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vpatterndb/vpiece.h"
|
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2019-09-05 13:13:22 +02:00
|
|
|
#include "../vpatterndb/vpassmark.h"
|
2015-05-07 15:12:53 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
AbstractTest::AbstractTest(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::PieceFromJson(const QString &json, VPiece &piece, QSharedPointer<VContainer> &data)
|
|
|
|
{
|
|
|
|
QByteArray saveData;
|
|
|
|
PrepareDocument(json, saveData);
|
|
|
|
QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
|
|
|
|
|
|
|
|
const QString testCaseKey = QStringLiteral("testCase");
|
|
|
|
const QString bdKey = QStringLiteral("bd");
|
|
|
|
const QString pieceKey = QStringLiteral("piece");
|
|
|
|
|
|
|
|
QJsonObject testCaseObject = loadDoc.object();
|
|
|
|
TestRoot(testCaseObject, testCaseKey, json);
|
|
|
|
|
|
|
|
QJsonObject testCase = testCaseObject[testCaseKey].toObject();
|
|
|
|
|
|
|
|
if (testCase.contains(bdKey))
|
|
|
|
{
|
|
|
|
DBFromJson(testCase[bdKey].toObject(), data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Test case json object does not contain db data.");
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (testCase.contains(pieceKey))
|
|
|
|
{
|
|
|
|
MainPathFromJson(testCase[pieceKey].toObject(), piece);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Test case json object does not contain piece data.");
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 13:13:22 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::PassmarkDataFromJson(const QString &json, VPiecePassmarkData &data)
|
|
|
|
{
|
|
|
|
QByteArray saveData;
|
|
|
|
PrepareDocument(json, saveData);
|
|
|
|
QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
|
|
|
|
|
|
|
|
const QString dataKey = QStringLiteral("data");
|
|
|
|
|
|
|
|
QJsonObject dataObject = loadDoc.object();
|
|
|
|
TestRoot(dataObject, dataKey, json);
|
|
|
|
|
|
|
|
QJsonObject passmarkData = dataObject[dataKey].toObject();
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
try
|
|
|
|
{
|
2022-10-29 13:46:10 +02:00
|
|
|
VSAPoint previousSAPoint;
|
|
|
|
PointFromJson(passmarkData[QStringLiteral("previousSAPoint")].toObject(), previousSAPoint);
|
2022-10-28 15:16:02 +02:00
|
|
|
data.previousSAPoint = previousSAPoint;
|
2019-09-05 13:13:22 +02:00
|
|
|
|
2022-10-29 13:46:10 +02:00
|
|
|
VSAPoint passmarkSAPoint;
|
|
|
|
PointFromJson(passmarkData[QStringLiteral("passmarkSAPoint")].toObject(), passmarkSAPoint);
|
2022-10-28 15:16:02 +02:00
|
|
|
data.passmarkSAPoint = passmarkSAPoint;
|
2019-09-05 13:13:22 +02:00
|
|
|
|
2022-10-29 13:46:10 +02:00
|
|
|
VSAPoint nextSAPoint;
|
|
|
|
PointFromJson(passmarkData[QStringLiteral("nextSAPoint")].toObject(), nextSAPoint);
|
2022-10-28 15:16:02 +02:00
|
|
|
data.nextSAPoint = nextSAPoint;
|
|
|
|
}
|
|
|
|
catch (const VException &e)
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Invalid json file '%1'. %2").arg(json, e.ErrorMessage());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
2019-09-05 13:13:22 +02:00
|
|
|
|
|
|
|
qreal saWidth = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(passmarkData, QStringLiteral("saWidth"), saWidth);
|
|
|
|
data.saWidth = saWidth;
|
|
|
|
|
|
|
|
QString nodeName;
|
|
|
|
AbstractTest::ReadStringValue(passmarkData, QStringLiteral("nodeName"), nodeName);
|
|
|
|
data.nodeName = nodeName;
|
|
|
|
|
|
|
|
QString pieceName;
|
|
|
|
AbstractTest::ReadStringValue(passmarkData, QStringLiteral("pieceName"), pieceName);
|
|
|
|
data.pieceName = pieceName;
|
|
|
|
|
2021-07-01 15:03:38 +02:00
|
|
|
PassmarkLineType passmarkLineType = PassmarkLineType::OneLine;
|
2019-09-05 13:13:22 +02:00
|
|
|
AbstractTest::ReadDoubleValue(passmarkData, QStringLiteral("passmarkLineType"), passmarkLineType,
|
|
|
|
QString::number(static_cast<int>(PassmarkLineType::OneLine)));
|
|
|
|
data.passmarkLineType = passmarkLineType;
|
|
|
|
|
2021-07-01 15:03:38 +02:00
|
|
|
PassmarkAngleType passmarkAngleType = PassmarkAngleType::Straightforward;
|
2019-09-05 13:13:22 +02:00
|
|
|
AbstractTest::ReadDoubleValue(passmarkData, QStringLiteral("passmarkAngleType"), passmarkAngleType,
|
|
|
|
QString::number(static_cast<int>(PassmarkAngleType::Straightforward)));
|
|
|
|
data.passmarkAngleType = passmarkAngleType;
|
|
|
|
|
|
|
|
bool isMainPathNode = true;
|
|
|
|
AbstractTest::ReadBooleanValue(passmarkData, QStringLiteral("isMainPathNode"), isMainPathNode);
|
|
|
|
data.isMainPathNode = isMainPathNode;
|
|
|
|
|
|
|
|
bool isShowSecondPassmark = true;
|
|
|
|
AbstractTest::ReadBooleanValue(passmarkData, QStringLiteral("isShowSecondPassmark"), isShowSecondPassmark);
|
|
|
|
data.isShowSecondPassmark = isShowSecondPassmark;
|
|
|
|
|
2021-07-01 15:03:38 +02:00
|
|
|
int passmarkIndex = -1;
|
2019-09-05 13:13:22 +02:00
|
|
|
AbstractTest::ReadDoubleValue(passmarkData, QStringLiteral("passmarkIndex"), passmarkIndex, QStringLiteral("-1"));
|
|
|
|
data.passmarkIndex = passmarkIndex;
|
|
|
|
|
2021-07-01 15:03:38 +02:00
|
|
|
vidtype id = NULL_ID;
|
2019-09-05 13:13:22 +02:00
|
|
|
AbstractTest::ReadDoubleValue(passmarkData, QStringLiteral("id"), id, QString::number(NULL_ID));
|
|
|
|
data.id = id;
|
2021-05-10 15:39:17 +02:00
|
|
|
|
|
|
|
qreal globalPassmarkLength;
|
|
|
|
AbstractTest::ReadDoubleValue(passmarkData, QStringLiteral("globalPassmarkLength"), globalPassmarkLength,
|
|
|
|
QString::number(NULL_ID));
|
|
|
|
data.globalPassmarkLength = globalPassmarkLength;
|
2019-09-05 13:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::PassmarkShapeFromJson(const QString &json, QVector<QLineF> &shape)
|
|
|
|
{
|
|
|
|
QByteArray saveData;
|
|
|
|
PrepareDocument(json, saveData);
|
|
|
|
QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
|
|
|
|
|
|
|
|
const QString shapeKey = QStringLiteral("shape");
|
|
|
|
const QString typeKey = QStringLiteral("type");
|
|
|
|
|
|
|
|
QJsonObject shapeObject = loadDoc.object();
|
|
|
|
TestRoot(shapeObject, shapeKey, json);
|
|
|
|
|
|
|
|
QJsonArray vectorArray = shapeObject[shapeKey].toArray();
|
2022-10-28 15:16:02 +02:00
|
|
|
for (auto && item : vectorArray)
|
2019-09-05 13:13:22 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QJsonObject lineObject = item.toObject();
|
2019-09-05 13:13:22 +02:00
|
|
|
|
|
|
|
QString type;
|
|
|
|
AbstractTest::ReadStringValue(lineObject, typeKey, type);
|
|
|
|
|
2022-10-29 13:46:10 +02:00
|
|
|
if (type != QLatin1String("QLineF"))
|
2019-09-05 13:13:22 +02:00
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Invalid json file '%1'. Unexpected class '%2'.")
|
|
|
|
.arg(json, lineObject[typeKey].toString());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
shape.append(QLineFromJson(lineObject));
|
2019-09-05 13:13:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 15:12:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void AbstractTest::ComparePathsDistance(const QVector<QPointF> &ekv, const QVector<QPointF> &ekvOrig) const
|
2015-05-07 15:12:53 +02:00
|
|
|
{
|
|
|
|
// Begin comparison
|
2022-10-29 13:46:10 +02:00
|
|
|
QCOMPARE(ekv.size(), ekvOrig.size());// First check if sizes are equal
|
2022-09-02 16:14:03 +02:00
|
|
|
const qreal testAccuracy = MmToPixel(1.);
|
2017-06-01 12:04:25 +02:00
|
|
|
|
2015-05-07 15:12:53 +02:00
|
|
|
for (int i=0; i < ekv.size(); i++)
|
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
ComparePointsDistance(ekv.at(i), ekvOrig.at(i), testAccuracy);
|
2015-05-07 15:12:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-28 12:42:26 +02:00
|
|
|
|
2019-01-02 14:58:59 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void AbstractTest::ComparePointsDistance(const QPointF &result, const QPointF &expected, qreal testAccuracy) const
|
2019-01-02 14:58:59 +01:00
|
|
|
{
|
2021-04-20 18:56:30 +02:00
|
|
|
const QString msg = QStringLiteral("Actual '%2;%3', Expected '%4;%5'. Distance between points %6 mm.")
|
|
|
|
.arg(result.x()).arg(result.y()).arg(expected.x()).arg(expected.y())
|
|
|
|
.arg(UnitConvertor(QLineF(result, expected).length(), Unit::Px, Unit::Mm));
|
2019-01-02 14:58:59 +01:00
|
|
|
// Check each point. Don't use comparison float values
|
2021-04-20 18:56:30 +02:00
|
|
|
QVERIFY2(VFuzzyComparePoints(result, expected, testAccuracy), qUtf8Printable(msg));
|
2019-01-02 14:58:59 +01:00
|
|
|
}
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void AbstractTest::CompareLinesDistance(const QVector<QLineF> &result, const QVector<QLineF> &expected) const
|
2019-01-09 16:46:02 +01:00
|
|
|
{
|
|
|
|
// Begin comparison
|
|
|
|
QCOMPARE(result.size(), expected.size());// First check if sizes equal
|
|
|
|
|
|
|
|
for (int i=0; i < result.size(); i++)
|
|
|
|
{
|
|
|
|
const QLineF &line1 = result.at(i);
|
|
|
|
const QLineF &line2 = expected.at(i);
|
|
|
|
// Check each point. Don't use comparison float values
|
|
|
|
QVERIFY2(VFuzzyComparePoints(line1.p1(), line2.p1()) && VFuzzyComparePoints(line1.p2(), line2.p2()),
|
|
|
|
qUtf8Printable(
|
|
|
|
QStringLiteral("Index: %1. Got line '(%2;%3):(%4;%5)', Expected line '(%6;%7):(%8;%9)'.")
|
|
|
|
.arg(i)
|
|
|
|
.arg(line1.p1().x())
|
|
|
|
.arg(line1.p1().y())
|
|
|
|
.arg(line1.p2().x())
|
|
|
|
.arg(line1.p2().y())
|
|
|
|
.arg(line2.p1().x())
|
|
|
|
.arg(line2.p1().y())
|
|
|
|
.arg(line2.p2().x())
|
|
|
|
.arg(line2.p2().y())
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 12:42:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AbstractTest::ValentinaPath() const
|
|
|
|
{
|
|
|
|
const QString path = QStringLiteral("/../../../app/valentina/bin/valentina");
|
|
|
|
#ifdef Q_OS_WIN
|
2017-07-09 08:02:26 +02:00
|
|
|
return QCoreApplication::applicationDirPath() + path + QLatin1String(".exe");
|
2015-09-28 12:42:26 +02:00
|
|
|
#else
|
2017-07-09 08:02:26 +02:00
|
|
|
return QCoreApplication::applicationDirPath() + path;
|
2015-09-28 12:42:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AbstractTest::TapePath() const
|
|
|
|
{
|
|
|
|
const QString path = QStringLiteral("/../../../app/tape/bin/tape");
|
|
|
|
#ifdef Q_OS_WIN
|
2017-07-09 08:02:26 +02:00
|
|
|
return QCoreApplication::applicationDirPath() + path + QLatin1String(".exe");
|
2015-09-28 12:42:26 +02:00
|
|
|
#else
|
2017-07-09 08:02:26 +02:00
|
|
|
return QCoreApplication::applicationDirPath() + path;
|
2015-09-28 12:42:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-16 13:55:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString AbstractTest::TranslationsPath() const
|
|
|
|
{
|
2017-07-09 08:02:26 +02:00
|
|
|
return QCoreApplication::applicationDirPath() + QStringLiteral("/../../../app/valentina/bin/translations");
|
2015-10-16 13:55:23 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 15:01:10 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int AbstractTest::RunTimeout(int defMsecs)
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
|
|
|
|
QString timeout = QString::fromLocal8Bit(qgetenv("VTEST_RUN_TIMEOUT"));
|
|
|
|
if (timeout.isEmpty())
|
|
|
|
{
|
|
|
|
return defMsecs;
|
|
|
|
}
|
|
|
|
#else
|
2020-11-12 16:30:30 +01:00
|
|
|
QString timeout = qEnvironmentVariable("VTEST_RUN_TIMEOUT", QString::number(defMsecs));
|
2020-11-12 15:01:10 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
int msecs = timeout.toInt(&ok);
|
|
|
|
return ok ? msecs : defMsecs;
|
|
|
|
}
|
|
|
|
|
2015-09-28 12:42:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-12-03 09:20:45 +01:00
|
|
|
int AbstractTest::Run(int exit, const QString &program, const QStringList &arguments, QString &error, int msecs)
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2020-11-12 15:01:10 +01:00
|
|
|
msecs = AbstractTest::RunTimeout(msecs);
|
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
const QString parameters = QStringLiteral("Program: %1 \nArguments: %2.")
|
|
|
|
.arg(program, arguments.join(QStringLiteral(", ")));
|
2015-09-28 12:42:26 +02:00
|
|
|
|
|
|
|
QFileInfo info(program);
|
|
|
|
if (not info.exists())
|
|
|
|
{
|
2019-08-29 14:01:27 +02:00
|
|
|
error = QStringLiteral("Can't find binary.\n%1").arg(parameters);
|
2016-11-04 14:15:11 +01:00
|
|
|
return TST_EX_BIN;
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
|
|
|
|
2016-07-30 17:17:43 +02:00
|
|
|
QScopedPointer<QProcess> process(new QProcess());
|
2015-09-28 12:42:26 +02:00
|
|
|
process->setWorkingDirectory(info.absoluteDir().absolutePath());
|
|
|
|
process->start(program, arguments);
|
|
|
|
|
2016-12-03 09:20:45 +01:00
|
|
|
if (not process->waitForStarted(msecs))
|
|
|
|
{
|
2019-01-02 15:28:51 +01:00
|
|
|
error = QStringLiteral("The start operation timed out or an error occurred.\n%1\n%2")
|
|
|
|
.arg(parameters, QString(process->readAllStandardError()));
|
2016-12-03 09:20:45 +01:00
|
|
|
process->kill();
|
|
|
|
return TST_EX_START_TIME_OUT;
|
|
|
|
}
|
|
|
|
|
2016-11-14 19:34:26 +01:00
|
|
|
if (not process->waitForFinished(msecs))
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2019-01-02 15:28:51 +01:00
|
|
|
error = QStringLiteral("The finish operation timed out or an error occurred.\n%1\n%2")
|
|
|
|
.arg(parameters, QString(process->readAllStandardError()));
|
2016-07-30 17:17:43 +02:00
|
|
|
process->kill();
|
2016-12-03 09:20:45 +01:00
|
|
|
return TST_EX_FINISH_TIME_OUT;
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process->exitStatus() == QProcess::CrashExit)
|
|
|
|
{
|
2018-06-21 13:41:36 +02:00
|
|
|
error = QStringLiteral("Program crashed.\n%1\n%2").arg(parameters, QString(process->readAllStandardError()));
|
2016-11-04 14:15:11 +01:00
|
|
|
return TST_EX_CRASH;
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 14:15:11 +01:00
|
|
|
if (process->exitCode() != exit)
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2018-07-13 15:18:04 +02:00
|
|
|
error = QStringLiteral("Unexpected finish. Exit code: %1\n%2").arg(process->exitCode())
|
|
|
|
.arg(QString(process->readAllStandardError()));
|
2016-11-04 14:15:11 +01:00
|
|
|
return process->exitCode();
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 14:15:11 +01:00
|
|
|
return process->exitCode();
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool AbstractTest::CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const
|
|
|
|
{
|
|
|
|
QFileInfo srcFileInfo(srcFilePath);
|
|
|
|
if (srcFileInfo.isDir())
|
|
|
|
{
|
|
|
|
QDir targetDir(tgtFilePath);
|
|
|
|
targetDir.cdUp();
|
2016-07-25 19:01:19 +02:00
|
|
|
const QString dirName = QFileInfo(tgtFilePath).fileName();
|
|
|
|
if (not targetDir.mkdir(dirName))
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2019-08-29 14:01:27 +02:00
|
|
|
const QString msg = QStringLiteral("Can't create dir '%1'.").arg(dirName);
|
2016-07-25 19:01:19 +02:00
|
|
|
QWARN(qUtf8Printable(msg));
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QDir sourceDir(srcFilePath);
|
2018-04-03 10:15:58 +02:00
|
|
|
const QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot |
|
|
|
|
QDir::Hidden | QDir::System);
|
|
|
|
for (auto &fileName : fileNames)
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
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
|
|
|
{
|
2018-03-14 14:39:15 +01:00
|
|
|
if (QFileInfo::exists(tgtFilePath))
|
2016-07-25 19:01:19 +02:00
|
|
|
{
|
2019-08-29 14:01:27 +02:00
|
|
|
const QString msg = QStringLiteral("File '%1' exists.").arg(srcFilePath);
|
2016-07-25 19:01:19 +02:00
|
|
|
QWARN(qUtf8Printable(msg));
|
|
|
|
|
|
|
|
if (QFile::remove(tgtFilePath))
|
|
|
|
{
|
|
|
|
QWARN("File successfully removed.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QWARN("Can't remove file.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 11:02:28 +02:00
|
|
|
// Check error: Cannot open %file for input
|
2016-07-28 10:38:30 +02:00
|
|
|
QFile srcFile(srcFilePath);
|
2016-07-28 11:02:28 +02:00
|
|
|
if (not srcFile.open(QFile::ReadOnly))
|
|
|
|
{
|
2019-08-29 14:01:27 +02:00
|
|
|
const QString msg = QStringLiteral("Can't copy file '%1'. Error: %2")
|
|
|
|
.arg(srcFilePath, srcFile.errorString());
|
2016-07-28 11:02:28 +02:00
|
|
|
QWARN(qUtf8Printable(msg));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
srcFile.close();
|
|
|
|
|
2016-07-28 10:38:30 +02:00
|
|
|
if (not srcFile.copy(tgtFilePath))
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2019-08-29 14:01:27 +02:00
|
|
|
const QString msg = QStringLiteral("Can't copy file '%1' to '%2'. Error: %3")
|
2018-03-14 14:39:15 +01:00
|
|
|
.arg(srcFilePath, tgtFilePath, srcFile.errorString());
|
2016-07-25 19:01:19 +02:00
|
|
|
QWARN(qUtf8Printable(msg));
|
2015-09-28 12:42:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-29 14:01:27 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void AbstractTest::PrepareDocument(const QString &json, QByteArray &data)
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
QFile loadFile(json);
|
|
|
|
if (not loadFile.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Couldn't open json file. %1").arg(loadFile.errorString());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
data = loadFile.readAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void AbstractTest::TestRoot(const QJsonObject &root, const QString &attribute, const QString &file)
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
if (not root.contains(attribute))
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Invalid json file '%1'. File doesn't contain root object.").arg(file);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::ReadStringValue(const QJsonObject &itemObject, const QString &attribute, QString &value,
|
2022-10-28 15:16:02 +02:00
|
|
|
const QString &defaultValue)
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
if (itemObject.contains(attribute))
|
|
|
|
{
|
|
|
|
QJsonValue attributeValue = itemObject[attribute];
|
|
|
|
if (attributeValue.isString())
|
|
|
|
{
|
|
|
|
value = attributeValue.toString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("%1 is not string '%2'.").arg(attribute, attributeValue.toString());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (not defaultValue.isEmpty())
|
|
|
|
{
|
|
|
|
value = defaultValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::ReadBooleanValue(const QJsonObject &itemObject, const QString &attribute, bool &value,
|
2022-10-28 15:16:02 +02:00
|
|
|
const QString &defaultValue)
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
if (itemObject.contains(attribute))
|
|
|
|
{
|
|
|
|
QJsonValue attributeValue = itemObject[attribute];
|
|
|
|
if (attributeValue.isBool())
|
|
|
|
{
|
|
|
|
value = attributeValue.toBool();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("%1 is not boolean value '%2'.").arg(attribute,
|
|
|
|
attributeValue.toString());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (not defaultValue.isEmpty())
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
int defVal = defaultValue.toInt(&ok);
|
|
|
|
|
|
|
|
if (not ok)
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Cannot convert default value '%1' to int.").arg(defaultValue);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
value = static_cast<bool>(defVal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::ReadPointValue(const QJsonObject &itemObject, const QString &attribute, VPointF &value)
|
|
|
|
{
|
|
|
|
if (itemObject.contains(attribute))
|
|
|
|
{
|
2022-10-29 13:46:10 +02:00
|
|
|
PointFromJson(itemObject[attribute].toObject(), value);
|
2019-08-29 14:01:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::ReadSplinePointValues(const QJsonObject &itemObject, const QString &attribute,
|
|
|
|
QVector<VSplinePoint> &points)
|
|
|
|
{
|
|
|
|
points.clear();
|
|
|
|
if (itemObject.contains(attribute))
|
|
|
|
{
|
|
|
|
QJsonArray nodes = itemObject[attribute].toArray();
|
|
|
|
for (int i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
QJsonObject item = nodes[i].toObject();
|
|
|
|
VSplinePoint point;
|
|
|
|
ReadSplinePointValue(item, point);
|
|
|
|
points.append(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::ReadSplinePointValue(const QJsonObject &itemObject, VSplinePoint &point)
|
|
|
|
{
|
|
|
|
qreal angle1 = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("angle1"), angle1);
|
|
|
|
|
|
|
|
QString angle1Formula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("angle1Formula"), angle1Formula);
|
|
|
|
|
|
|
|
qreal angle2 = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("angle2"), angle2);
|
|
|
|
|
|
|
|
QString angle2Formula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("angle2Formula"), angle2Formula);
|
|
|
|
|
|
|
|
qreal length1 = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("length1"), length1);
|
|
|
|
|
|
|
|
QString length1Formula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("length1Formula"), length1Formula);
|
|
|
|
|
|
|
|
qreal length2 = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("length2"), length2);
|
|
|
|
|
|
|
|
QString length2Formula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("length2Formula"), length2Formula);
|
|
|
|
|
|
|
|
VPointF pSpline;
|
|
|
|
ReadPointValue(itemObject, QStringLiteral("point"), pSpline);
|
|
|
|
|
|
|
|
point = VSplinePoint(pSpline, angle1, angle1Formula, angle2, angle2Formula, length1, length1Formula, length2,
|
|
|
|
length2Formula);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::ReadPieceNodeValue(const QJsonObject &itemObject, VPieceNode &node)
|
|
|
|
{
|
|
|
|
vidtype id = NULL_ID;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("id"), id);
|
|
|
|
|
|
|
|
Tool typeTool = Tool::LAST_ONE_DO_NOT_USE;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("type"), typeTool);
|
|
|
|
|
|
|
|
bool reverse = false;
|
|
|
|
AbstractTest::ReadBooleanValue(itemObject, QStringLiteral("reverse"), reverse, QChar('0'));
|
|
|
|
|
|
|
|
node = VPieceNode(id, typeTool, reverse);
|
|
|
|
}
|
|
|
|
|
2019-09-05 13:13:22 +02:00
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-09-05 16:21:06 +02:00
|
|
|
template<typename T, typename std::enable_if<std::is_floating_point<T>::value>::type*>
|
2019-08-29 14:01:27 +02:00
|
|
|
void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
2022-10-28 15:16:02 +02:00
|
|
|
const QString &defaultValue)
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
if (itemObject.contains(attribute))
|
|
|
|
{
|
|
|
|
QJsonValue attributeValue = itemObject[attribute];
|
|
|
|
if (attributeValue.isDouble())
|
|
|
|
{
|
|
|
|
value = static_cast<T>(attributeValue.toDouble());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("%1 is not double '%2'.").arg(attribute, attributeValue.toString());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (not defaultValue.isEmpty())
|
|
|
|
{
|
|
|
|
bool ok = false;
|
2019-09-05 13:59:22 +02:00
|
|
|
value = static_cast<T>(defaultValue.toDouble(&ok));
|
2019-08-29 14:01:27 +02:00
|
|
|
|
|
|
|
if (not ok)
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Cannot convert default value '%1' to double.").arg(defaultValue);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 16:21:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename T, typename std::enable_if<std::is_enum<T>::value>::type*>
|
|
|
|
void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
2022-10-28 15:16:02 +02:00
|
|
|
const QString &defaultValue)
|
2019-09-05 16:21:06 +02:00
|
|
|
{
|
|
|
|
if (itemObject.contains(attribute))
|
|
|
|
{
|
|
|
|
QJsonValue attributeValue = itemObject[attribute];
|
|
|
|
if (attributeValue.isDouble())
|
|
|
|
{
|
|
|
|
value = static_cast<T>(static_cast<int>(attributeValue.toDouble()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("%1 is not double '%2'.").arg(attribute, attributeValue.toString());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (not defaultValue.isEmpty())
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
value = static_cast<T>(defaultValue.toInt(&ok));
|
|
|
|
|
|
|
|
if (not ok)
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Cannot convert default value '%1' to int.").arg(defaultValue);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type*>
|
|
|
|
void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
2022-10-28 15:16:02 +02:00
|
|
|
const QString &defaultValue)
|
2019-09-05 16:21:06 +02:00
|
|
|
{
|
|
|
|
if (itemObject.contains(attribute))
|
|
|
|
{
|
|
|
|
QJsonValue attributeValue = itemObject[attribute];
|
|
|
|
if (attributeValue.isDouble())
|
|
|
|
{
|
|
|
|
value = static_cast<T>(attributeValue.toDouble());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("%1 is not double '%2'.").arg(attribute, attributeValue.toString());
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (not defaultValue.isEmpty())
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
value = static_cast<T>(defaultValue.toInt(&ok));
|
|
|
|
|
|
|
|
if (not ok)
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Cannot convert default value '%1' to int.").arg(defaultValue);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute);
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
auto AbstractTest::QLineFromJson(const QJsonObject &itemObject) -> QLineF
|
2019-09-05 13:13:22 +02:00
|
|
|
{
|
2022-10-29 13:46:10 +02:00
|
|
|
QPointF p1;
|
|
|
|
QPointF p2;
|
|
|
|
PointFromJson(itemObject[QStringLiteral("p1")].toObject(), p1);
|
|
|
|
PointFromJson(itemObject[QStringLiteral("p2")].toObject(), p2);
|
|
|
|
return {p1, p2};
|
2021-03-30 15:20:38 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::SplineFromJson(const QJsonObject &itemObject, QSharedPointer<VContainer> &data)
|
|
|
|
{
|
|
|
|
vidtype id = NULL_ID;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("id"), id);
|
|
|
|
|
|
|
|
qreal aScale = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("aScale"), aScale);
|
|
|
|
|
|
|
|
qreal angle1 = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("angle1"), angle1);
|
|
|
|
|
|
|
|
QString angle1Formula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("angle1Formula"), angle1Formula);
|
|
|
|
|
|
|
|
qreal angle2 = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("angle2"), angle2);
|
|
|
|
|
|
|
|
QString angle2Formula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("angle2Formula"), angle2Formula);
|
|
|
|
|
|
|
|
qreal c1Length = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("c1Length"), c1Length);
|
|
|
|
|
|
|
|
QString c1LengthFormula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("c1LengthFormula"), c1LengthFormula);
|
|
|
|
|
|
|
|
qreal c2Length = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("c2Length"), c2Length);
|
|
|
|
|
|
|
|
QString c2LengthFormula;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, QStringLiteral("c2LengthFormula"), c2LengthFormula);
|
|
|
|
|
|
|
|
VPointF p1;
|
|
|
|
ReadPointValue(itemObject, QStringLiteral("p1"), p1);
|
|
|
|
data->UpdateGObject(p1.id(), new VPointF(p1));
|
|
|
|
|
|
|
|
VPointF p4;
|
|
|
|
ReadPointValue(itemObject, QStringLiteral("p4"), p4);
|
|
|
|
data->UpdateGObject(p4.id(), new VPointF(p4));
|
|
|
|
|
|
|
|
VSpline *spl = new VSpline(p1, p4, angle1, angle1Formula, angle2, angle2Formula, c1Length, c1LengthFormula,
|
|
|
|
c2Length, c2LengthFormula);
|
|
|
|
spl->SetApproximationScale(aScale);
|
|
|
|
data->UpdateGObject(id, spl);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::SplinePathFromJson(const QJsonObject &itemObject, QSharedPointer<VContainer> &data)
|
|
|
|
{
|
|
|
|
vidtype id = NULL_ID;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("id"), id);
|
|
|
|
|
|
|
|
qreal aScale = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("aScale"), aScale);
|
|
|
|
|
|
|
|
QVector<VSplinePoint> points;
|
|
|
|
AbstractTest::ReadSplinePointValues(itemObject, QStringLiteral("nodes"), points);
|
|
|
|
for (auto &point : points)
|
|
|
|
{
|
|
|
|
data->UpdateGObject(point.P().id(), new VPointF(point.P()));
|
|
|
|
}
|
|
|
|
|
|
|
|
VSplinePath *path = new VSplinePath(points);
|
|
|
|
path->SetApproximationScale(aScale);
|
|
|
|
data->UpdateGObject(id, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::DBFromJson(const QJsonObject &dbObject, QSharedPointer<VContainer> &data)
|
|
|
|
{
|
|
|
|
const QString itemsKey = QStringLiteral("items");
|
|
|
|
|
|
|
|
if (dbObject.contains(itemsKey))
|
|
|
|
{
|
|
|
|
QJsonArray items = dbObject[itemsKey].toArray();
|
2022-10-29 13:46:10 +02:00
|
|
|
for (auto && item : items)
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
2022-10-29 13:46:10 +02:00
|
|
|
QJsonObject itemObject = item.toObject();
|
2019-08-29 14:01:27 +02:00
|
|
|
GOType objectType;
|
|
|
|
AbstractTest::ReadDoubleValue(itemObject, QStringLiteral("type"), objectType);
|
|
|
|
|
|
|
|
switch(objectType)
|
|
|
|
{
|
|
|
|
case GOType::Point:
|
|
|
|
{
|
2022-10-29 13:46:10 +02:00
|
|
|
VPointF point;
|
|
|
|
PointFromJson(itemObject, point);
|
2019-08-29 14:01:27 +02:00
|
|
|
data->UpdateGObject(point.id(), new VPointF(point));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GOType::Spline:
|
|
|
|
SplineFromJson(itemObject, data);
|
|
|
|
break;
|
|
|
|
case GOType::SplinePath:
|
|
|
|
SplinePathFromJson(itemObject, data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Not supported item type '%1'.")
|
|
|
|
.arg(static_cast<int>(objectType));
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("DB json object does not contain items.");
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void AbstractTest::MainPathFromJson(const QJsonObject &pieceObject, VPiece &piece)
|
|
|
|
{
|
|
|
|
qreal saWidth = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pieceObject, QStringLiteral("saWidth"), saWidth);
|
|
|
|
|
|
|
|
bool seamAllowance = false;
|
|
|
|
AbstractTest::ReadBooleanValue(pieceObject, QStringLiteral("seamAllowance"), seamAllowance);
|
|
|
|
|
|
|
|
piece.SetSeamAllowance(seamAllowance);
|
|
|
|
piece.SetSAWidth(saWidth);
|
|
|
|
|
|
|
|
piece.GetPath().Clear();
|
|
|
|
|
|
|
|
const QString nodesKey = QStringLiteral("nodes");
|
|
|
|
|
|
|
|
if (pieceObject.contains(nodesKey))
|
|
|
|
{
|
|
|
|
QJsonArray nodes = pieceObject[nodesKey].toArray();
|
|
|
|
for (int i = 0; i < nodes.size(); ++i)
|
|
|
|
{
|
|
|
|
QJsonObject itemObject = nodes[i].toObject();
|
|
|
|
|
|
|
|
VPieceNode node;
|
|
|
|
ReadPieceNodeValue(itemObject, node);
|
|
|
|
piece.GetPath().Append(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString error = QStringLiteral("Piece json object does not contain nodes.");
|
|
|
|
QFAIL(qUtf8Printable(error));
|
|
|
|
}
|
|
|
|
}
|