2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Ville Tiensuu - ville.tiensuu@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>
26 #include "map/ownlocationitem.h"
27 #include "map/mapscene.h"
28 #include "map/maptile.h"
29 #include "map/mapengine.h"
30 #include "map/mapcommon.h"
31 #include "map/mapview.h"
33 namespace TestOwnLocation // Test data for function is defined in namespace
35 const qreal xCoordinate = 65.525;
36 const qreal yCoordinate = 25.345;
37 const QPointF testLocationPoint(65.525, 25.345);
38 const QPointF defaultLocationPoint(DEFAULT_LONGITUDE,DEFAULT_LATITUDE);
39 const QPointF locationIconOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
40 const int itemIgnoresTransformationsFlagValue = 0x20;
43 using namespace TestOwnLocation;
47 * @brief Class that test OwnLocationItem
49 * @author Ville Tiensuu
51 class TestOwnLocationItem: public QObject
57 * @brief Test method for constructors.
58 * Creates instance of OwnLocationItem using three different constructors and tests
59 * that positions are set correctly.
60 * Tests that Z-values are set correctly.
61 * Tests that offses are set correctly.
62 * Tests that ItemIgnoresTransformations flag is set.
64 void testConstructors();
67 * @brief Creates instance of OwnLocationItem.
68 * Sets test position for location item in geographic coordinates.
69 * Reads position from location item in scene coordinates and
70 * verifies that it correctly formed.
72 void testSetAndGetPosition();
75 * @brief Creates instance of OwnLocationItem.
76 * Verifies that instance is visible.
77 * Hides instance and verifies that it is not visible.
79 void testHideAndShowPosition();
82 void TestOwnLocationItem::testConstructors()
84 OwnLocationItem ownLocationItem1;
85 OwnLocationItem ownLocationItem2(xCoordinate, yCoordinate);
86 OwnLocationItem ownLocationItem3(testLocationPoint);
89 QCOMPARE(ownLocationItem1.position(),
90 MapEngine::convertLatLonToSceneCoordinate(defaultLocationPoint));
92 QCOMPARE(ownLocationItem2.position(),
93 MapEngine::convertLatLonToSceneCoordinate(testLocationPoint));
95 QCOMPARE(ownLocationItem3.position(),
96 MapEngine::convertLatLonToSceneCoordinate(testLocationPoint));
99 QCOMPARE(static_cast<int>(ownLocationItem1.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
100 QCOMPARE(static_cast<int>(ownLocationItem2.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
101 QCOMPARE(static_cast<int>(ownLocationItem3.zValue()), OWN_LOCATION_ICON_Z_LEVEL);
104 QCOMPARE(ownLocationItem1.offset(), locationIconOffset);
105 QCOMPARE(ownLocationItem2.offset(), locationIconOffset);
106 QCOMPARE(ownLocationItem3.offset(), locationIconOffset);
108 // Test ItemIgnoresTransformations Flags
109 QGraphicsItem::GraphicsItemFlags ownLocationItem1Flags = ownLocationItem1.flags();
110 QGraphicsItem::GraphicsItemFlags ownLocationItem2Flags = ownLocationItem1.flags();
111 QGraphicsItem::GraphicsItemFlags ownLocationItem3Flags = ownLocationItem1.flags();
113 QCOMPARE(ownLocationItem1Flags, itemIgnoresTransformationsFlagValue);
114 QCOMPARE(ownLocationItem2Flags, itemIgnoresTransformationsFlagValue);
115 QCOMPARE(ownLocationItem3Flags, itemIgnoresTransformationsFlagValue);
118 void TestOwnLocationItem::testSetAndGetPosition()
120 OwnLocationItem ownLocation;
121 ownLocation.setPosition(testLocationPoint);
123 QCOMPARE(ownLocation.position(),
124 MapEngine::convertLatLonToSceneCoordinate(testLocationPoint));
127 void TestOwnLocationItem::testHideAndShowPosition()
129 OwnLocationItem ownLocation;
131 QCOMPARE(ownLocation.isVisible(), true);
133 ownLocation.hideOwnLocation();
135 QCOMPARE(ownLocation.isVisible(), false);
139 QTEST_MAIN(TestOwnLocationItem)
140 #include "testownlocationitem.moc"