2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
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.
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.
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,
22 #include <QtTest/QtTest>
24 #include "map/mapcommon.h"
26 #include "map/gpslocationitem.h"
28 class TestGPSLocationItem: public QObject
37 void updateItem_data();
40 void TestGPSLocationItem::constructor()
44 // position should be UNDEFINED
45 QCOMPARE(item.pos(), QPointF(UNDEFINED, UNDEFINED));
47 // zValue should be set
48 QCOMPARE(item.zValue(), static_cast<qreal>(OWN_LOCATION_ICON_Z_LEVEL));
50 // by default the item should be hidden
51 QVERIFY(item.isVisible() == false);
55 * The actual GPS location red spot is in a child QGraphicsPixmapItem
57 void TestGPSLocationItem::childPixmap()
61 // there should be one QGraphicsPixmapItem child item
62 QList<QGraphicsItem *> childs = item.childItems();
63 QVERIFY(childs.count() == 1);
64 QGraphicsPixmapItem *childPixmap = dynamic_cast<QGraphicsPixmapItem *>(childs.at(0));
67 // pixmap should be set
68 QVERIFY(!childPixmap->pixmap().isNull());
70 // pixmap offset should be set based on pixmap
71 QCOMPARE(childPixmap->offset(),
72 QPointF(-childPixmap->pixmap().width() / 2, -childPixmap->pixmap().height() / 2));
74 // ItemIgnoresTransformations flag should be set
75 QVERIFY(childPixmap->flags() & QGraphicsItem::ItemIgnoresTransformations);
79 * When setEnabled(true) is called, the item should become visible only after the first location
80 * update from the GPS is received
82 void TestGPSLocationItem::enable()
84 const qreal SCENE_RESOLUTION = 0.252006;
85 const qreal ACCURACY_100M = 100;
86 const QPointF POSITION_IN_SCENE = QPointF(1000, 1000);
88 // create item and update it's position so pixmap is set
91 // item should not be visible because it's location is not yet set
92 QCOMPARE(item.isVisible(), false);
94 // setting the location when item is not set enabled should not make the item visible
95 item.updateItem(POSITION_IN_SCENE, ACCURACY_100M, SCENE_RESOLUTION);
96 QCOMPARE(item.isVisible(), false);
98 // setting the item enabled should not make the item visible before first location update
100 item.setEnabled(true);
101 QCOMPARE(item.isVisible(), false);
103 // item should become visible after the first location update
104 item.updateItem(POSITION_IN_SCENE, ACCURACY_100M, SCENE_RESOLUTION);
105 QCOMPARE(item.isVisible(), true);
109 * Item's position and accuracy ring diameter should be updated. Because accuracy ring diameter
110 * is changed, the bounding rect should also be changed.
112 void TestGPSLocationItem::updateItem()
114 QFETCH(QPointF, position);
115 QFETCH(qreal, accuracy);
116 QFETCH(qreal, sceneResolution);
117 QFETCH(QPointF, expectedPosition);
118 QFETCH(QRectF, expectedRect);
120 GPSLocationItem item;
121 item.updateItem(position, accuracy, sceneResolution);
123 QCOMPARE(item.pos(), expectedPosition);
124 QCOMPARE(item.boundingRect(), expectedRect);
127 void TestGPSLocationItem::updateItem_data()
129 const qreal PEN_WIDTH = 1;
131 const QPointF POSITION1 = QPointF(1000, 1000);
132 const QPointF POSITION2 = QPointF(2000, 4000);
134 const qreal ACCURACY_100M = 100;
135 const qreal ACCURACY_15M = 15;
137 const qreal SCENE_RESOLUTION1 = 0.250000;
138 const qreal SCENE_RESOLUTION2 = 0.500000;
140 QTest::addColumn<QPointF>("position");
141 QTest::addColumn<qreal>("accuracy");
142 QTest::addColumn<qreal>("sceneResolution");
143 QTest::addColumn<QPointF>("expectedPosition");
144 QTest::addColumn<QRectF>("expectedRect");
146 qreal radius = ACCURACY_100M / SCENE_RESOLUTION1;
148 QRectF rect = QRectF(-radius - PEN_WIDTH / 2,
149 -radius - PEN_WIDTH / 2,
150 2 * radius + PEN_WIDTH,
151 2 * radius + PEN_WIDTH);
153 QTest::newRow("1st test") << POSITION1
159 QTest::newRow("change only position") << POSITION2
165 radius = ACCURACY_15M / SCENE_RESOLUTION1;
167 rect = QRectF(-radius - PEN_WIDTH / 2,
168 -radius - PEN_WIDTH / 2,
169 2 * radius + PEN_WIDTH,
170 2 * radius + PEN_WIDTH);
172 QTest::newRow("change only accuracy") << POSITION1
178 radius = ACCURACY_100M / SCENE_RESOLUTION2;
180 rect = QRectF(-radius - PEN_WIDTH / 2,
181 -radius - PEN_WIDTH / 2,
182 2 * radius + PEN_WIDTH,
183 2 * radius + PEN_WIDTH);
185 QTest::newRow("change only scene resolution") << POSITION1
192 QTEST_MAIN(TestGPSLocationItem)
194 #include "testgpslocationitem.moc"