Implemented unit tests for MapRouteItem
[situare] / tests / map / maprouteitem / testmaprouteitem.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@ixonos.com
6
7     Situare is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     version 2 as published by the Free Software Foundation.
10
11     Situare is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with Situare; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19     USA.
20 */
21
22 #include <QtCore/QString>
23 #include <QPen>
24 #include <QtTest/QtTest>
25
26 #include "coordinates/geocoordinate.h"
27 #include "coordinates/scenecoordinate.h"
28 #include "map/maprouteitem.h"
29 #include "routing/route.h"
30
31 class TestMapRouteItem : public QObject
32 {
33     Q_OBJECT
34
35 public:
36     TestMapRouteItem();
37
38 private Q_SLOTS:
39     void testCase1();
40
41 private:
42     Route route;
43
44     GeoCoordinate coordinates[3];
45 };
46
47 TestMapRouteItem::TestMapRouteItem()
48 {
49     // test points
50     coordinates[0] = GeoCoordinate(12.3456, 54.3210);
51     coordinates[1] = GeoCoordinate(65.5000, 25.0000);
52     coordinates[2] = GeoCoordinate(-23.4567, 43.0987);
53
54     // append points to route
55     route.appendGeometryPoint(coordinates[0]);
56     route.appendGeometryPoint(coordinates[1]);
57     route.appendGeometryPoint(coordinates[2]);
58 }
59
60 void TestMapRouteItem::testCase1()
61 {
62     MapRouteItem item;
63     item.setRoute(&route);
64
65     // check amount of lines
66     QList<QGraphicsItem *> lines = item.childItems();
67     QCOMPARE(lines.count(), 2);
68
69     // test each line
70     for (int i = 0; i < lines.count(); i++) {
71         // check if the item really is a line item
72         QGraphicsLineItem *lineItem = dynamic_cast<QGraphicsLineItem *>(lines.at(i));
73         QVERIFY(lineItem);
74
75         // check begin and end point scene coordinates of the line
76         QLineF line = lineItem->line();
77         QCOMPARE(line.p1(), SceneCoordinate(coordinates[i]).toPointF());
78         QCOMPARE(line.p2(), SceneCoordinate(coordinates[i + 1]).toPointF());
79
80         // check visual properties of the line
81         QPen pen = lineItem->pen();
82         QVERIFY(pen.isCosmetic());
83         QCOMPARE(pen.width(), 5);
84         QCOMPARE(pen.color(), QColor(Qt::red));
85     }
86 }
87
88 QTEST_APPLESS_MAIN(TestMapRouteItem);
89
90 #include "testmaprouteitem.moc"