aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickpath/tst_qquickpath.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickpath/tst_qquickpath.cpp')
-rw-r--r--tests/auto/quick/qquickpath/tst_qquickpath.cpp186
1 files changed, 135 insertions, 51 deletions
diff --git a/tests/auto/quick/qquickpath/tst_qquickpath.cpp b/tests/auto/quick/qquickpath/tst_qquickpath.cpp
index 12a8c673b0..c89ce730a8 100644
--- a/tests/auto/quick/qquickpath/tst_qquickpath.cpp
+++ b/tests/auto/quick/qquickpath/tst_qquickpath.cpp
@@ -42,18 +42,44 @@ public:
private slots:
void arc();
void angleArc();
- void catmullromCurve();
- void closedCatmullromCurve();
+ void catmullRomCurve();
+ void closedCatmullRomCurve();
void svg();
void line();
+
+private:
+ void arc(QSizeF scale);
+ void angleArc(QSizeF scale);
+ void catmullRomCurve(QSizeF scale, const QVector<QPointF> &points);
+ void closedCatmullRomCurve(QSizeF scale, const QVector<QPointF> &points);
+ void svg(QSizeF scale);
+ void line(QSizeF scale);
};
-void tst_QuickPath::arc()
+static void compare(const QPointF &point, const QSizeF &scale, int line, double x, double y)
+{
+ QVERIFY2(qFuzzyCompare(float(point.x()), float(x * scale.width())),
+ (QStringLiteral("Actual: ") + QString::number(point.x(),'g',14)
+ + QStringLiteral(" Expected: ") + QString::number(x * scale.width(),'g',14)
+ + QStringLiteral(" At: ") + QString::number(line)).toLatin1().data());
+ QVERIFY2(qFuzzyCompare(float(point.y()), float(y * scale.height())),
+ (QStringLiteral("Actual: ") + QString::number(point.y(),'g',14)
+ + QStringLiteral(" Expected: ") + QString::number(y * scale.height(),'g',14)
+ + QStringLiteral(" At: ") + QString::number(line)).toLatin1().data());
+}
+static void compare(const QPointF &point, int line, const QPointF &pt)
+{
+ return compare(point, QSizeF(1,1), line, pt.x(), pt.y());
+}
+
+void tst_QuickPath::arc(QSizeF scale)
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("arc.qml"));
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
QVERIFY(obj != nullptr);
+ if (scale != QSizeF(1,1))
+ obj->setProperty("scale", scale);
QCOMPARE(obj->startX(), 0.);
QCOMPARE(obj->startY(), 0.);
@@ -73,22 +99,30 @@ void tst_QuickPath::arc()
QPainterPath path = obj->path();
QVERIFY(path != QPainterPath());
- QPointF pos = obj->pointAt(0);
+ QPointF pos = obj->pointAtPercent(0);
QCOMPARE(pos, QPointF(0,0));
- pos = obj->pointAt(.25);
- QCOMPARE(pos.toPoint(), QPoint(39,8)); //fuzzy compare
- pos = obj->pointAt(.75);
- QCOMPARE(pos.toPoint(), QPoint(92,61)); //fuzzy compare
- pos = obj->pointAt(1);
- QCOMPARE(pos, QPointF(100,100));
+ pos = obj->pointAtPercent(.25);
+ compare(pos, scale, __LINE__, 38.9244897744, 7.85853964341);
+ pos = obj->pointAtPercent(.75);
+ compare(pos, scale, __LINE__, 92.141460356592, 61.07551022559);
+ pos = obj->pointAtPercent(1);
+ QCOMPARE(pos, QPointF(100 * scale.width(), 100 * scale.height()));
}
-void tst_QuickPath::angleArc()
+void tst_QuickPath::arc()
+{
+ arc(QSizeF(1,1));
+ arc(QSizeF(2.2,3.4));
+}
+
+void tst_QuickPath::angleArc(QSizeF scale)
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("anglearc.qml"));
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
QVERIFY(obj != nullptr);
+ if (scale != QSizeF(1,1))
+ obj->setProperty("scale", scale);
QQmlListReference list(obj, "pathElements");
QCOMPARE(list.count(), 1);
@@ -106,28 +140,35 @@ void tst_QuickPath::angleArc()
QPainterPath path = obj->path();
QVERIFY(path != QPainterPath());
- // using QPoint to do fuzzy compare
- QPointF pos = obj->pointAt(0);
- QCOMPARE(pos.toPoint(), QPoint(135,135));
- pos = obj->pointAt(.25);
- QCOMPARE(pos.toPoint(), QPoint(119,146));
- pos = obj->pointAt(.75);
- QCOMPARE(pos.toPoint(), QPoint(81,146));
- pos = obj->pointAt(1);
- QCOMPARE(pos.toPoint(), QPoint(65,135));
+ QPointF pos = obj->pointAtPercent(0);
+ compare(pos, scale, __LINE__, 135.35533905867, 135.35533905867);
+ pos = obj->pointAtPercent(.25);
+ compare(pos, scale, __LINE__, 119.46222180396, 146.07068621369);
+ pos = obj->pointAtPercent(.75);
+ compare(pos, scale, __LINE__, 80.537778196007, 146.07068621366);
+ pos = obj->pointAtPercent(1);
+ compare(pos, scale, __LINE__, 64.644660941173, 135.35533905867);
// if moveToStart is false, we should have a line starting from startX/Y
arc->setMoveToStart(false);
- pos = obj->pointAt(0);
+ pos = obj->pointAtPercent(0);
QCOMPARE(pos, QPointF(0,0));
}
-void tst_QuickPath::catmullromCurve()
+void tst_QuickPath::angleArc()
+{
+ angleArc(QSizeF(1,1));
+ angleArc(QSizeF(2.7,0.92));
+}
+
+void tst_QuickPath::catmullRomCurve(QSizeF scale, const QVector<QPointF> &points)
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("curve.qml"));
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
QVERIFY(obj != nullptr);
+ if (scale != QSizeF(1,1))
+ obj->setProperty("scale", scale);
QCOMPARE(obj->startX(), 0.);
QCOMPARE(obj->startY(), 0.);
@@ -148,22 +189,36 @@ void tst_QuickPath::catmullromCurve()
QPainterPath path = obj->path();
QVERIFY(path != QPainterPath());
- QPointF pos = obj->pointAt(0);
- QCOMPARE(pos, QPointF(0,0));
- pos = obj->pointAt(.25);
- QCOMPARE(pos.toPoint(), QPoint(63,26)); //fuzzy compare
- pos = obj->pointAt(.75);
- QCOMPARE(pos.toPoint(), QPoint(51,105)); //fuzzy compare
- pos = obj->pointAt(1);
- QCOMPARE(pos.toPoint(), QPoint(100,150));
+ QPointF pos = path.pointAtPercent(0);
+ QCOMPARE(pos, points.at(0));
+ pos = path.pointAtPercent(.25);
+ compare(pos, __LINE__, points.at(1));
+ pos = path.pointAtPercent(.75);
+ compare(pos, __LINE__, points.at(2));
+ pos = path.pointAtPercent(1);
+ compare(pos, __LINE__, points.at(3));
+}
+
+void tst_QuickPath::catmullRomCurve()
+{
+ catmullRomCurve(QSizeF(1,1), { QPointF(0,0),
+ QPointF(62.917022919131, 26.175485291549),
+ QPointF(51.194527196674 , 105.27985623074),
+ QPointF(100, 150) });
+ catmullRomCurve(QSizeF(2,5.3), { QPointF(0,0),
+ QPointF(150.80562419914, 170.34065984615),
+ QPointF(109.08400252853 , 588.35165918579),
+ QPointF(200, 795) });
}
-void tst_QuickPath::closedCatmullromCurve()
+void tst_QuickPath::closedCatmullRomCurve(QSizeF scale, const QVector<QPointF> &points)
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("closedcurve.qml"));
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
QVERIFY(obj != nullptr);
+ if (scale != QSizeF(1,1))
+ obj->setProperty("scale", scale);
QCOMPARE(obj->startX(), 50.);
QCOMPARE(obj->startY(), 50.);
@@ -181,22 +236,36 @@ void tst_QuickPath::closedCatmullromCurve()
QPainterPath path = obj->path();
QVERIFY(path != QPainterPath());
- QPointF pos = obj->pointAt(0);
- QCOMPARE(pos, QPointF(50,50));
- pos = obj->pointAt(.1);
- QCOMPARE(pos.toPoint(), QPoint(67,56)); //fuzzy compare
- pos = obj->pointAt(.75);
- QCOMPARE(pos.toPoint(), QPoint(44,116)); //fuzzy compare
- pos = obj->pointAt(1);
- QCOMPARE(pos, QPointF(50,50));
+ QPointF pos = path.pointAtPercent(0);
+ QCOMPARE(pos, points.at(0));
+ pos = path.pointAtPercent(.1);
+ compare(pos, __LINE__, points.at(1));
+ pos = path.pointAtPercent(.75);
+ compare(pos, __LINE__, points.at(2));
+ pos = path.pointAtPercent(1);
+ compare(pos, __LINE__, points.at(3));
}
-void tst_QuickPath::svg()
+void tst_QuickPath::closedCatmullRomCurve()
+{
+ closedCatmullRomCurve(QSizeF(1,1), { QPointF(50,50),
+ QPointF(66.776225481812, 55.617435304145),
+ QPointF(44.10269379731 , 116.33512508175),
+ QPointF(50, 50) });
+ closedCatmullRomCurve(QSizeF(2,3), { QPointF(100,150),
+ QPointF(136.49725836178, 170.25466686363),
+ QPointF(87.713232151943 , 328.29232737977),
+ QPointF(100, 150) });
+}
+
+void tst_QuickPath::svg(QSizeF scale)
{
QQmlEngine engine;
QQmlComponent c(&engine, testFileUrl("svg.qml"));
QQuickPath *obj = qobject_cast<QQuickPath*>(c.create());
QVERIFY(obj != nullptr);
+ if (scale != QSizeF(1,1))
+ obj->setProperty("scale", scale);
QCOMPARE(obj->startX(), 0.);
QCOMPARE(obj->startY(), 0.);
@@ -211,17 +280,23 @@ void tst_QuickPath::svg()
QPainterPath path = obj->path();
QVERIFY(path != QPainterPath());
- QPointF pos = obj->pointAt(0);
- QCOMPARE(pos, QPointF(200,300));
- pos = obj->pointAt(.25);
- QCOMPARE(pos.toPoint(), QPoint(400,175)); //fuzzy compare
- pos = obj->pointAt(.75);
- QCOMPARE(pos.toPoint(), QPoint(800,425)); //fuzzy compare
- pos = obj->pointAt(1);
- QCOMPARE(pos, QPointF(1000,300));
+ QPointF pos = obj->pointAtPercent(0);
+ QCOMPARE(pos, QPointF(200 * scale.width(),300 * scale.height()));
+ pos = obj->pointAtPercent(.25);
+ QCOMPARE(pos.toPoint(), QPoint(400 * scale.width(),175 * scale.height())); //fuzzy compare
+ pos = obj->pointAtPercent(.75);
+ QCOMPARE(pos.toPoint(), QPoint(800 * scale.width(),425 * scale.height())); //fuzzy compare
+ pos = obj->pointAtPercent(1);
+ QCOMPARE(pos, QPointF(1000 * scale.width(),300 * scale.height()));
}
-void tst_QuickPath::line()
+void tst_QuickPath::svg()
+{
+ svg(QSizeF(1,1));
+ svg(QSizeF(5,3));
+}
+
+void tst_QuickPath::line(QSizeF scale)
{
QQmlEngine engine;
QQmlComponent c1(&engine);
@@ -234,6 +309,8 @@ void tst_QuickPath::line()
QScopedPointer<QObject> o1(c1.create());
QQuickPath *path1 = qobject_cast<QQuickPath *>(o1.data());
QVERIFY(path1);
+ if (scale != QSizeF(1,1))
+ path1->setProperty("scale", scale);
QQmlComponent c2(&engine);
c2.setData(
@@ -246,18 +323,25 @@ void tst_QuickPath::line()
QScopedPointer<QObject> o2(c2.create());
QQuickPath *path2 = qobject_cast<QQuickPath *>(o2.data());
QVERIFY(path2);
+ if (scale != QSizeF(1,1))
+ path2->setProperty("scale", scale);
for (int i = 0; i < 167; ++i) {
qreal t = i / 167.0;
- QPointF p1 = path1->pointAt(t);
+ QPointF p1 = path1->pointAtPercent(t);
QCOMPARE(p1.x(), p1.y());
- QPointF p2 = path2->pointAt(t);
+ QPointF p2 = path2->pointAtPercent(t);
QCOMPARE(p1.toPoint(), p2.toPoint());
}
}
+void tst_QuickPath::line()
+{
+ line(QSizeF(1,1));
+ line(QSizeF(7.23,7.23));
+}
QTEST_MAIN(tst_QuickPath)