1 /************************************************************************
2  **
3  **  @file   abstracttest.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   7 5, 2015
6  **
7  **  @brief
8  **  @copyright
9  **  This source code is part of the Valentina project, a pattern making
10  **  program, whose allow create and modeling patterns of clothing.
11  **  Copyright (C) 2015 Valentina project
12  **  <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13  **
14  **  Valentina is free software: you can redistribute it and/or modify
15  **  it under the terms of the GNU General Public License as published by
16  **  the Free Software Foundation, either version 3 of the License, or
17  **  (at your option) any later version.
18  **
19  **  Valentina is distributed in the hope that it will be useful,
20  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  **  GNU General Public License for more details.
23  **
24  **  You should have received a copy of the GNU General Public License
25  **  along with Valentina.  If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #ifndef ABSTRACTTEST_H
30 #define ABSTRACTTEST_H
31 
32 #include <QMetaObject>
33 #include <QObject>
34 #include <QString>
35 
36 template <class T> class QVector;
37 class VSAPoint;
38 
39 #include <ciso646>
40 
41 #ifdef __GNUC__
42 #define V_UNUSED __attribute__ ((unused))
43 #else
44 #define V_UNUSED
45 #endif
46 
47 // Return codes for testing run application
48 static const auto V_UNUSED TST_EX_BIN = -1;      // Can't find binary.
49 static const auto V_UNUSED TST_EX_FINISH_TIME_OUT = -2; // The operation timed out or an error occurred.
50 static const auto V_UNUSED TST_EX_START_TIME_OUT = -3; // The operation timed out or an error occurred.
51 static const auto V_UNUSED TST_EX_CRASH = -4;    // Program crashed.
52 
53 #undef V_UNUSED
54 
55 enum ErrorState {ErrorLoad = 0, ErrorInstall, ErrorSize, NoError};
56 
57 class VPiece;
58 class VContainer;
59 class VPointF;
60 class VSplinePoint;
61 class VPieceNode;
62 enum class GOType : qint8;
63 struct VPiecePassmarkData;
64 class VRawSAPoint;
65 
66 class AbstractTest : public QObject
67 {
68     Q_OBJECT
69 public:
70     explicit AbstractTest(QObject *parent = nullptr);
71 
72     void VectorFromJson(const QString &json, QVector<QPointF>& vector) const;
73     void VectorFromJson(const QString &json, QVector<VSAPoint>& vector) const;
74     void VectorFromJson(const QString &json, QVector<VRawSAPoint>& vector) const;
75 
76     void PieceFromJson(const QString &json, VPiece &piece, QSharedPointer<VContainer> &data);
77 
78     void PassmarkDataFromJson(const QString &json, VPiecePassmarkData& data);
79     void PassmarkShapeFromJson(const QString &json, QVector<QLineF> &shape);
80 
81 protected:
82     void Comparison(const QVector<QPointF> &ekv, const QVector<QPointF> &ekvOrig) const;
83     void Comparison(const QPointF &result, const QPointF &expected, qreal testAccuracy) const;
84     void Comparison(const QVector<QLineF> &result, const QVector<QLineF> &expected) const;
85 
86     QString ValentinaPath() const;
87     QString TapePath() const;
88     QString TranslationsPath() const;
89 
90     static int RunTimeout(int defMsecs);
91 
92     int Run(int exit, const QString &program, const QStringList &arguments, QString &error, int msecs = 120000);
93     bool CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const;
94 
95     void PrepareDocument(const QString &json, QByteArray &data) const;
96     void TestRoot(const QJsonObject &root, const QString &attribute, const QString &file) const;
97 
98     template <typename T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr>
99     void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
100                          const QString &defaultValue = QString()) const;
101     template <typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
102     void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
103                          const QString &defaultValue = QString()) const;
104     template <typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
105     void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
106                          const QString &defaultValue = QString()) const;
107     void ReadStringValue(const QJsonObject &itemObject, const QString &attribute, QString &value,
108                          const QString &defaultValue = QString()) const;
109     void ReadBooleanValue(const QJsonObject &itemObject, const QString &attribute, bool &value,
110                           const QString &defaultValue = QString()) const;
111     void ReadPointValue(const QJsonObject &itemObject, const QString &attribute, VPointF &value);
112     void ReadSplinePointValues(const QJsonObject &itemObject, const QString &attribute, QVector<VSplinePoint> &points);
113     void ReadSplinePointValue(const QJsonObject &itemObject, VSplinePoint &point);
114     void ReadPieceNodeValue(const QJsonObject &itemObject, VPieceNode &node);
115 
116     void QPointFromJson(const QJsonObject &itemObject, QPointF &point) const;
117     void VPointFromJson(const QJsonObject &itemObject, VPointF &point);
118     void QLineFromJson(const QJsonObject &itemObject, QLineF &line);
119     void SAPointFromJson(const QJsonObject &itemObject, VSAPoint &point) const;
120     void RawSAPointFromJson(const QJsonObject &itemObject, VRawSAPoint &point) const;
121     void SplineFromJson(const QJsonObject &itemObject, QSharedPointer<VContainer> &data);
122     void SplinePathFromJson(const QJsonObject &itemObject, QSharedPointer<VContainer> &data);
123 
124     void DBFromJson(const QJsonObject &dbObject, QSharedPointer<VContainer> &data);
125     void MainPathFromJson(const QJsonObject &pieceObject, VPiece &piece);
126 };
127 
128 #endif // ABSTRACTTEST_H
129