1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtTest/QtTest>
43 #include <QtDeclarative/qdeclarativeengine.h>
44 #include <QtDeclarative/qdeclarativecomponent.h>
45 #include <QtQuick/private/qdeclarativepath_p.h>
47 #include "../../shared/util.h"
49 class tst_QDeclarativePath : public QDeclarativeDataTest
53 tst_QDeclarativePath() {}
57 void catmullromCurve();
58 void closedCatmullromCurve();
62 void tst_QDeclarativePath::arc()
64 QDeclarativeEngine engine;
65 QDeclarativeComponent c(&engine, testFileUrl("arc.qml"));
66 QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
69 QCOMPARE(obj->startX(), 0.);
70 QCOMPARE(obj->startY(), 0.);
72 QDeclarativeListReference list(obj, "pathElements");
73 QCOMPARE(list.count(), 1);
75 QDeclarativePathArc* arc = qobject_cast<QDeclarativePathArc*>(list.at(0));
77 QCOMPARE(arc->x(), 100.);
78 QCOMPARE(arc->y(), 100.);
79 QCOMPARE(arc->radiusX(), 100.);
80 QCOMPARE(arc->radiusY(), 100.);
81 QCOMPARE(arc->useLargeArc(), false);
82 QCOMPARE(arc->direction(), QDeclarativePathArc::Clockwise);
84 QPainterPath path = obj->path();
85 QVERIFY(path != QPainterPath());
87 QPointF pos = obj->pointAt(0);
88 QCOMPARE(pos, QPointF(0,0));
89 pos = obj->pointAt(.25);
90 QCOMPARE(pos.toPoint(), QPoint(39,8)); //fuzzy compare
91 pos = obj->pointAt(.75);
92 QCOMPARE(pos.toPoint(), QPoint(92,61)); //fuzzy compare
93 pos = obj->pointAt(1);
94 QCOMPARE(pos, QPointF(100,100));
97 void tst_QDeclarativePath::catmullromCurve()
99 QDeclarativeEngine engine;
100 QDeclarativeComponent c(&engine, testFileUrl("curve.qml"));
101 QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
104 QCOMPARE(obj->startX(), 0.);
105 QCOMPARE(obj->startY(), 0.);
107 QDeclarativeListReference list(obj, "pathElements");
108 QCOMPARE(list.count(), 3);
110 QDeclarativePathCatmullRomCurve* curve = qobject_cast<QDeclarativePathCatmullRomCurve*>(list.at(0));
112 QCOMPARE(curve->x(), 100.);
113 QCOMPARE(curve->y(), 50.);
115 curve = qobject_cast<QDeclarativePathCatmullRomCurve*>(list.at(2));
117 QCOMPARE(curve->x(), 100.);
118 QCOMPARE(curve->y(), 150.);
120 QPainterPath path = obj->path();
121 QVERIFY(path != QPainterPath());
123 QPointF pos = obj->pointAt(0);
124 QCOMPARE(pos, QPointF(0,0));
125 pos = obj->pointAt(.25);
126 QCOMPARE(pos.toPoint(), QPoint(63,26)); //fuzzy compare
127 pos = obj->pointAt(.75);
128 QCOMPARE(pos.toPoint(), QPoint(51,105)); //fuzzy compare
129 pos = obj->pointAt(1);
130 QCOMPARE(pos, QPointF(100,150));
133 void tst_QDeclarativePath::closedCatmullromCurve()
135 QDeclarativeEngine engine;
136 QDeclarativeComponent c(&engine, testFileUrl("closedcurve.qml"));
137 QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
140 QCOMPARE(obj->startX(), 50.);
141 QCOMPARE(obj->startY(), 50.);
143 QDeclarativeListReference list(obj, "pathElements");
144 QCOMPARE(list.count(), 3);
146 QDeclarativePathCatmullRomCurve* curve = qobject_cast<QDeclarativePathCatmullRomCurve*>(list.at(2));
148 QCOMPARE(curve->x(), 50.);
149 QCOMPARE(curve->y(), 50.);
151 QVERIFY(obj->isClosed());
153 QPainterPath path = obj->path();
154 QVERIFY(path != QPainterPath());
156 QPointF pos = obj->pointAt(0);
157 QCOMPARE(pos, QPointF(50,50));
158 pos = obj->pointAt(.1);
159 QCOMPARE(pos.toPoint(), QPoint(67,56)); //fuzzy compare
160 pos = obj->pointAt(.75);
161 QCOMPARE(pos.toPoint(), QPoint(44,116)); //fuzzy compare
162 pos = obj->pointAt(1);
163 QCOMPARE(pos, QPointF(50,50));
166 void tst_QDeclarativePath::svg()
168 QDeclarativeEngine engine;
169 QDeclarativeComponent c(&engine, testFileUrl("svg.qml"));
170 QDeclarativePath *obj = qobject_cast<QDeclarativePath*>(c.create());
173 QCOMPARE(obj->startX(), 0.);
174 QCOMPARE(obj->startY(), 0.);
176 QDeclarativeListReference list(obj, "pathElements");
177 QCOMPARE(list.count(), 1);
179 QDeclarativePathSvg* svg = qobject_cast<QDeclarativePathSvg*>(list.at(0));
181 QCOMPARE(svg->path(), QLatin1String("M200,300 Q400,50 600,300 T1000,300"));
183 QPainterPath path = obj->path();
184 QVERIFY(path != QPainterPath());
186 QPointF pos = obj->pointAt(0);
187 QCOMPARE(pos, QPointF(200,300));
188 pos = obj->pointAt(.25);
189 QCOMPARE(pos.toPoint(), QPoint(400,175)); //fuzzy compare
190 pos = obj->pointAt(.75);
191 QCOMPARE(pos.toPoint(), QPoint(800,425)); //fuzzy compare
192 pos = obj->pointAt(1);
193 QCOMPARE(pos, QPointF(1000,300));
197 QTEST_MAIN(tst_QDeclarativePath)
199 #include "tst_qdeclarativepath.moc"