2015-05-07 15:12:53 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file abstracttest.h
|
|
|
|
** @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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef ABSTRACTTEST_H
|
|
|
|
#define ABSTRACTTEST_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QMetaObject>
|
2015-05-07 15:12:53 +02:00
|
|
|
#include <QObject>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QString>
|
2022-10-28 15:16:02 +02:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <qtestcase.h>
|
2022-11-14 19:16:20 +01:00
|
|
|
#include <typeinfo>
|
2023-02-14 13:52:48 +01:00
|
|
|
#include <QtCore/qcontainerfwd.h>
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
#include "../vgeometry/vpointf.h"
|
|
|
|
#include "../vlayout/vsapoint.h"
|
|
|
|
#include "../vlayout/vrawsapoint.h"
|
|
|
|
#include "../ifc/exception/vexception.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2015-10-23 19:47:33 +02:00
|
|
|
#include <ciso646>
|
|
|
|
|
2016-08-21 17:57:08 +02:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define V_UNUSED __attribute__ ((unused))
|
|
|
|
#else
|
|
|
|
#define V_UNUSED
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 13:09:06 +02:00
|
|
|
// Return codes for testing run application
|
2016-08-21 17:57:08 +02:00
|
|
|
static const auto V_UNUSED TST_EX_BIN = -1; // Can't find binary.
|
2016-12-03 09:20:45 +01:00
|
|
|
static const auto V_UNUSED TST_EX_FINISH_TIME_OUT = -2; // The operation timed out or an error occurred.
|
|
|
|
static const auto V_UNUSED TST_EX_START_TIME_OUT = -3; // The operation timed out or an error occurred.
|
|
|
|
static const auto V_UNUSED TST_EX_CRASH = -4; // Program crashed.
|
2016-08-21 17:57:08 +02:00
|
|
|
|
|
|
|
#undef V_UNUSED
|
2015-10-03 13:09:06 +02:00
|
|
|
|
2015-10-16 13:55:23 +02:00
|
|
|
enum ErrorState {ErrorLoad = 0, ErrorInstall, ErrorSize, NoError};
|
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
class VPiece;
|
|
|
|
class VContainer;
|
|
|
|
class VPointF;
|
|
|
|
class VSplinePoint;
|
|
|
|
class VPieceNode;
|
2020-01-07 11:54:01 +01:00
|
|
|
enum class GOType : qint8;
|
2019-09-05 13:13:22 +02:00
|
|
|
struct VPiecePassmarkData;
|
2021-03-30 15:20:38 +02:00
|
|
|
class VRawSAPoint;
|
2019-08-29 14:01:27 +02:00
|
|
|
|
2015-05-07 15:12:53 +02:00
|
|
|
class AbstractTest : public QObject
|
|
|
|
{
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_OBJECT // NOLINT
|
2015-05-07 15:12:53 +02:00
|
|
|
public:
|
2016-02-24 16:31:44 +01:00
|
|
|
explicit AbstractTest(QObject *parent = nullptr);
|
2015-05-07 15:12:53 +02:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
template <class T>
|
|
|
|
static auto VectorFromJson(const QString &json) -> QVector<T>;
|
2019-08-07 16:53:18 +02:00
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
void PieceFromJson(const QString &json, VPiece &piece, QSharedPointer<VContainer> &data);
|
|
|
|
|
2019-09-05 13:13:22 +02:00
|
|
|
void PassmarkDataFromJson(const QString &json, VPiecePassmarkData& data);
|
|
|
|
void PassmarkShapeFromJson(const QString &json, QVector<QLineF> &shape);
|
|
|
|
|
2015-05-07 15:12:53 +02:00
|
|
|
protected:
|
2022-11-11 16:57:34 +01:00
|
|
|
static void ComparePaths(const QVector<QPointF> &actual, const QVector<QPointF> &expected);
|
2022-10-28 15:16:02 +02:00
|
|
|
void ComparePathsDistance(const QVector<QPointF> &ekv, const QVector<QPointF> &ekvOrig) const;
|
|
|
|
void ComparePointsDistance(const QPointF &result, const QPointF &expected, qreal testAccuracy) const;
|
|
|
|
void CompareLinesDistance(const QVector<QLineF> &result, const QVector<QLineF> &expected) const;
|
2015-05-07 15:12:53 +02:00
|
|
|
|
2023-01-06 16:41:45 +01:00
|
|
|
auto PuzzlePath() const -> QString;
|
2022-10-28 15:16:02 +02:00
|
|
|
auto ValentinaPath() const -> QString;
|
|
|
|
auto TapePath() const -> QString;
|
|
|
|
auto TranslationsPath() const -> QString;
|
2015-09-28 12:42:26 +02:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
static auto RunTimeout(int defMsecs) -> int;
|
2020-11-12 15:01:10 +01:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
auto Run(int exit, const QString &program, const QStringList &arguments, QString &error, int msecs = 120000) -> int;
|
|
|
|
auto CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const -> bool;
|
2019-08-29 14:01:27 +02:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
static void PrepareDocument(const QString &json, QByteArray &data);
|
|
|
|
static void TestRoot(const QJsonObject &root, const QString &attribute, const QString &file);
|
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* = nullptr>
|
2022-10-28 15:16:02 +02:00
|
|
|
static void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
|
|
|
const QString &defaultValue = QString());
|
2019-09-05 16:21:06 +02:00
|
|
|
template <typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
|
2022-10-28 15:16:02 +02:00
|
|
|
static void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
|
|
|
const QString &defaultValue = QString());
|
2019-09-05 16:21:06 +02:00
|
|
|
template <typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
|
2022-10-28 15:16:02 +02:00
|
|
|
static void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
|
|
|
const QString &defaultValue = QString());
|
|
|
|
static void ReadStringValue(const QJsonObject &itemObject, const QString &attribute, QString &value,
|
|
|
|
const QString &defaultValue = QString());
|
|
|
|
static void ReadBooleanValue(const QJsonObject &itemObject, const QString &attribute, bool &value,
|
|
|
|
const QString &defaultValue = QString());
|
2019-08-29 14:01:27 +02:00
|
|
|
void ReadPointValue(const QJsonObject &itemObject, const QString &attribute, VPointF &value);
|
|
|
|
void ReadSplinePointValues(const QJsonObject &itemObject, const QString &attribute, QVector<VSplinePoint> &points);
|
|
|
|
void ReadSplinePointValue(const QJsonObject &itemObject, VSplinePoint &point);
|
|
|
|
void ReadPieceNodeValue(const QJsonObject &itemObject, VPieceNode &node);
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
template <class T>
|
|
|
|
static void CheckClassType(const QJsonObject &itemObject);
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
static auto ReadPointData(const QJsonObject &pointObject) -> T;
|
|
|
|
|
|
|
|
template <class T>
|
2022-10-29 13:46:10 +02:00
|
|
|
static auto PointFromJson(const QJsonObject &pointObject, T &point) -> void;
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
auto QLineFromJson(const QJsonObject &itemObject) -> QLineF;
|
2019-08-29 14:01:27 +02:00
|
|
|
void SplineFromJson(const QJsonObject &itemObject, QSharedPointer<VContainer> &data);
|
|
|
|
void SplinePathFromJson(const QJsonObject &itemObject, QSharedPointer<VContainer> &data);
|
|
|
|
|
|
|
|
void DBFromJson(const QJsonObject &dbObject, QSharedPointer<VContainer> &data);
|
|
|
|
void MainPathFromJson(const QJsonObject &pieceObject, VPiece &piece);
|
2015-05-07 15:12:53 +02:00
|
|
|
};
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<class T>
|
|
|
|
inline auto AbstractTest::VectorFromJson(const QString &json) -> QVector<T>
|
|
|
|
{
|
|
|
|
QByteArray saveData;
|
|
|
|
PrepareDocument(json, saveData);
|
|
|
|
QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
|
|
|
|
|
|
|
|
const QString vectorKey = QStringLiteral("vector");
|
|
|
|
|
|
|
|
QJsonObject vectorObject = loadDoc.object();
|
|
|
|
TestRoot(vectorObject, vectorKey, json);
|
|
|
|
|
|
|
|
QJsonArray vectorArray = vectorObject[vectorKey].toArray();
|
2022-10-29 13:46:10 +02:00
|
|
|
QVector<T> vector;
|
|
|
|
vector.reserve(vectorArray.size());
|
2022-10-28 15:16:02 +02:00
|
|
|
|
2022-11-10 15:15:11 +01:00
|
|
|
for (auto item : vectorArray)
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-10-29 13:46:10 +02:00
|
|
|
T point;
|
|
|
|
PointFromJson(item.toObject(), point);
|
|
|
|
vector.append(point);
|
2022-10-28 15:16:02 +02:00
|
|
|
}
|
|
|
|
catch (const VException &e)
|
|
|
|
{
|
|
|
|
throw VException(QStringLiteral("Invalid json file '%1'. %2").arg(json, e.ErrorMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vector;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<class T>
|
|
|
|
inline void AbstractTest::CheckClassType(const QJsonObject &itemObject)
|
|
|
|
{
|
|
|
|
const QString typeKey = QStringLiteral("type");
|
|
|
|
|
|
|
|
QString type;
|
|
|
|
AbstractTest::ReadStringValue(itemObject, typeKey, type);
|
|
|
|
|
2022-10-29 13:46:10 +02:00
|
|
|
const QStringList types
|
|
|
|
{
|
|
|
|
QStringLiteral("QPointF"), // 0
|
|
|
|
QStringLiteral("VLayoutPoint"), // 1
|
|
|
|
QStringLiteral("VRawSAPoint"), // 2
|
|
|
|
QStringLiteral("VSAPoint"), // 3
|
|
|
|
};
|
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
switch (types.indexOf(type))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
res = (typeid(T) == typeid(QPointF));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
res = (typeid(T) == typeid(VLayoutPoint));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
res = (typeid(T) == typeid(VRawSAPoint));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
res = (typeid(T) == typeid(VSAPoint));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not res)
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
throw VException(QStringLiteral("Unexpected class '%2'.").arg(itemObject[typeKey].toString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<class T>
|
|
|
|
inline auto AbstractTest::ReadPointData(const QJsonObject &pointObject) -> T
|
|
|
|
{
|
|
|
|
T point;
|
|
|
|
qreal x = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QChar('x'), x);
|
|
|
|
point.setX(x);
|
|
|
|
|
|
|
|
qreal y = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QChar('y'), y);
|
|
|
|
point.setY(y);
|
|
|
|
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<class T>
|
2022-10-29 13:46:10 +02:00
|
|
|
inline auto AbstractTest::PointFromJson(const QJsonObject &pointObject, T &point) -> void
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
CheckClassType<T>(pointObject);
|
2022-10-29 13:46:10 +02:00
|
|
|
point = ReadPointData<T>(pointObject);
|
2022-10-28 15:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<>
|
2022-10-29 13:46:10 +02:00
|
|
|
inline auto AbstractTest::PointFromJson(const QJsonObject &pointObject, VPointF &point) -> void
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
vidtype id = NULL_ID;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("id"), id);
|
|
|
|
|
|
|
|
qreal mx = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("mx"), mx);
|
|
|
|
|
|
|
|
qreal my = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("my"), my);
|
|
|
|
|
|
|
|
QString name;
|
|
|
|
AbstractTest::ReadStringValue(pointObject, QStringLiteral("name"), name);
|
|
|
|
|
|
|
|
qreal x = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QChar('x'), x);
|
|
|
|
|
|
|
|
qreal y = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QChar('y'), y);
|
|
|
|
|
2022-10-29 13:46:10 +02:00
|
|
|
point = VPointF(x, y, name, mx, my);
|
2022-10-28 15:16:02 +02:00
|
|
|
point.setId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<>
|
|
|
|
inline auto AbstractTest::ReadPointData(const QJsonObject &pointObject) -> VLayoutPoint
|
|
|
|
{
|
|
|
|
VLayoutPoint point(ReadPointData<QPointF>(pointObject));
|
|
|
|
|
|
|
|
bool turnPoint;
|
|
|
|
AbstractTest::ReadBooleanValue(pointObject, QStringLiteral("turnPoint"), turnPoint, QStringLiteral("0"));
|
|
|
|
point.SetTurnPoint(turnPoint);
|
|
|
|
|
|
|
|
bool curvePoint;
|
|
|
|
AbstractTest::ReadBooleanValue(pointObject, QStringLiteral("curvePoint"), curvePoint, QStringLiteral("0"));
|
|
|
|
point.SetCurvePoint(curvePoint);
|
|
|
|
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<>
|
2022-10-29 13:46:10 +02:00
|
|
|
inline auto AbstractTest::PointFromJson(const QJsonObject &pointObject, VLayoutPoint &point) -> void
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
CheckClassType<VLayoutPoint>(pointObject);
|
2022-10-29 13:46:10 +02:00
|
|
|
point = ReadPointData<VLayoutPoint>(pointObject);
|
2022-10-28 15:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<>
|
2022-10-29 13:46:10 +02:00
|
|
|
inline auto AbstractTest::PointFromJson(const QJsonObject &pointObject, VSAPoint &point) -> void
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
CheckClassType<VSAPoint>(pointObject);
|
|
|
|
|
2022-10-29 13:46:10 +02:00
|
|
|
point = VSAPoint(ReadPointData<VLayoutPoint>(pointObject));
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
qreal saBefore;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("saBefore"), saBefore, QStringLiteral("-1"));
|
|
|
|
point.SetSABefore(saBefore);
|
|
|
|
|
|
|
|
qreal saAfter;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("saAfter"), saAfter, QStringLiteral("-1"));
|
|
|
|
point.SetSAAfter(saAfter);
|
|
|
|
|
|
|
|
PieceNodeAngle angleType = PieceNodeAngle::ByLength;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("angle"), angleType,
|
|
|
|
QString::number(static_cast<int>(PieceNodeAngle::ByLength)));
|
|
|
|
point.SetAngleType(angleType);
|
2023-05-06 19:01:15 +02:00
|
|
|
|
|
|
|
bool manualPassmarkLength = false;
|
|
|
|
AbstractTest::ReadBooleanValue(pointObject, QLatin1String("manualPassmarkLength"), manualPassmarkLength,
|
|
|
|
QStringLiteral("0"));
|
|
|
|
point.SetManualPasskmarkLength(manualPassmarkLength);
|
|
|
|
|
|
|
|
if (manualPassmarkLength)
|
|
|
|
{
|
|
|
|
qreal passmarkLength = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("passmarkLength"), passmarkLength,
|
|
|
|
QStringLiteral("0"));
|
|
|
|
point.SetPasskmarkLength(passmarkLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool manualPassmarkWidth = false;
|
|
|
|
AbstractTest::ReadBooleanValue(pointObject, QLatin1String("manualPassmarkWidth"), manualPassmarkWidth,
|
|
|
|
QStringLiteral("0"));
|
|
|
|
point.SetManualPasskmarkWidth(manualPassmarkWidth);
|
|
|
|
|
|
|
|
if (manualPassmarkWidth)
|
|
|
|
{
|
|
|
|
qreal passmarkWidth = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("passmarkWidth"), passmarkWidth, QStringLiteral("0"));
|
|
|
|
point.SetPasskmarkWidth(passmarkWidth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool passmarkClockwiseOpening = false;
|
|
|
|
AbstractTest::ReadBooleanValue(pointObject, QLatin1String("passmarkClockwiseOpening"), passmarkClockwiseOpening,
|
|
|
|
QStringLiteral("0"));
|
|
|
|
point.SetPassmarkClockwiseOpening(passmarkClockwiseOpening);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool manualPassmarkAngle = false;
|
|
|
|
AbstractTest::ReadBooleanValue(pointObject, QLatin1String("manualPassmarkAngle"), manualPassmarkAngle,
|
|
|
|
QStringLiteral("0"));
|
|
|
|
point.SetManualPasskmarkAngle(manualPassmarkAngle);
|
|
|
|
|
|
|
|
if (manualPassmarkAngle)
|
|
|
|
{
|
|
|
|
qreal passmarkAngle = 0;
|
|
|
|
AbstractTest::ReadDoubleValue(pointObject, QStringLiteral("passmarkAngle"), passmarkAngle, QStringLiteral("0"));
|
|
|
|
point.SetPasskmarkAngle(passmarkAngle);
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<>
|
2022-10-29 13:46:10 +02:00
|
|
|
inline auto AbstractTest::PointFromJson(const QJsonObject &pointObject, VRawSAPoint &point) -> void
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
CheckClassType<VRawSAPoint>(pointObject);
|
|
|
|
|
2022-10-29 13:46:10 +02:00
|
|
|
point = VRawSAPoint(ReadPointData<VLayoutPoint>(pointObject));
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
bool loopPoint;
|
|
|
|
AbstractTest::ReadBooleanValue(pointObject, QStringLiteral("loopPoint"), loopPoint, QStringLiteral("0"));
|
|
|
|
point.SetLoopPoint(loopPoint);
|
|
|
|
}
|
|
|
|
|
2015-05-07 15:12:53 +02:00
|
|
|
#endif // ABSTRACTTEST_H
|