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,
23 #include <QtTest/QtTest>
27 #include "map/friendlocationitem.h"
28 #include "map/mapscene.h"
29 #include "map/maptile.h"
30 #include "map/mapengine.h"
31 #include "map/mapcommon.h"
32 #include "map/mapview.h"
33 #include "map/baselocationitem.h"
34 #include "user/user.h"
35 #include "map/friendlocationitem.h"
37 namespace Testfriendlocation // Test data for function is defined in namespace
39 const qreal xCoordinate = 65.525;
40 const qreal yCoordinate = 25.345;
41 const QPointF testLocationPoint(65.525, 25.345);
42 const QPointF defaultLocationPoint(DEFAULT_LONGITUDE,DEFAULT_LATITUDE);
43 const QPointF locationIconOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
44 const int itemIgnoresTransformationsFlagValue = 0x20;
47 using namespace Testfriendlocation;
51 * @brief Class that test FriendLocationItem
53 * @author Ville Tiensuu
55 class TestFriendLocationItem: public QObject
61 * @brief Test method for constructors.
62 * Creates instance of FriendLocationItem
63 * Tests that Z-values are set correctly.
64 * Tests that offses are set correctly.
65 * Tests that ItemIgnoresTransformations flag is set.
67 void testConstructor();
70 * @brief Tests that friend location item is possible to set visible and unvisible
72 void testHideAndShowPosition();
75 * @brief Tests that it is possible to set and get userId for friend location item
80 void TestFriendLocationItem::testConstructor()
82 QPixmap friendIcon("situare_user.gif");
83 FriendLocationItem friendLocation(friendIcon);
87 QCOMPARE (pixmap.isNull(), true);
89 pixmap = friendLocation.pixmap();
90 QCOMPARE (pixmap.isNull(), false);
93 QCOMPARE(static_cast<int>(friendLocation.zValue()), FRIEND_LOCATION_ICON_Z_LEVEL);
96 QCOMPARE(friendLocation.offset(),
97 QPointF(-friendLocation.pixmap().width()/2, -friendLocation.pixmap().height()/2));
99 // Test ItemIgnoresTransformations Flags
100 QGraphicsItem::GraphicsItemFlags friendLocationItemFlags = friendLocation.flags();
101 QCOMPARE(friendLocationItemFlags, itemIgnoresTransformationsFlagValue);
105 void TestFriendLocationItem::testHideAndShowPosition()
107 QPixmap friendIcon(":/res/images/situare_user.jpg");
108 FriendLocationItem friendLocation(friendIcon);
109 QCOMPARE(friendLocation.isVisible(), true);
111 friendLocation.hideLocation();
112 QCOMPARE(friendLocation.isVisible(), false);
114 friendLocation.showLocation();
115 QCOMPARE(friendLocation.isVisible(), true);
118 void TestFriendLocationItem::testSetUserId()
120 QPixmap friendIcon("situare_user.jpg");
121 FriendLocationItem friendLocation(friendIcon);
123 QString userIdentity = "110022";
124 friendLocation.setUserId(userIdentity);
125 QCOMPARE(friendLocation.userId(), userIdentity);
128 QTEST_MAIN(TestFriendLocationItem)
129 #include "testfriendlocationitem.moc"