2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Ville Tiensuu - ville.tiensuu@ixonos.com
6 Sami Rämö - sami.ramo@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include <QtTest/QtTest>
28 #include "map/friendlocationitem.h"
29 #include "map/mapscene.h"
30 #include "map/maptile.h"
31 #include "map/mapengine.h"
32 #include "map/mapcommon.h"
33 #include "map/mapview.h"
34 #include "map/baselocationitem.h"
35 #include "user/user.h"
36 #include "map/friendlocationitem.h"
38 namespace Testfriendlocation // Test data for function is defined in namespace
40 const QPointF defaultPosition(UNDEFINED, UNDEFINED);
41 const QString userID("ABC123");
42 const QUrl url("http://www.test.com/test.png");
43 const int itemIgnoresTransformationsFlagValue = 0x20;
46 using namespace Testfriendlocation;
49 * @brief Class that test FriendLocationItem
51 * @author Ville Tiensuu - ville.tiensuu@ixonos.com
52 * @author Sami Rämö - sami.ramo@ixonos.com
54 class TestFriendLocationItem: public QObject
60 * @brief Test method for constructors.
62 * Creates instance of FriendLocationItem
63 * Tests that Z-values are set correctly.
64 * Tests that ItemIgnoresTransformations flag is set.
65 * Tests that default position is set.
66 * Tests that user ID is set
71 * @brief Test grouping functionality
76 * @brief Tests that friend location item is possible to set visible and unvisible
78 void setProfileImage();
81 void TestFriendLocationItem::constructor()
83 FriendLocationItem friendLocation(userID);
86 QCOMPARE(static_cast<int>(friendLocation.zValue()), FRIEND_LOCATION_ICON_Z_LEVEL);
88 // Test ItemIgnoresTransformations Flags
89 QGraphicsItem::GraphicsItemFlags friendLocationItemFlags = friendLocation.flags();
90 QCOMPARE(friendLocationItemFlags, itemIgnoresTransformationsFlagValue);
92 // test default position
93 QCOMPARE(friendLocation.pos(), defaultPosition);
96 QCOMPARE(friendLocation.userId(), userID);
98 // test isPartOfGroup default value
99 QCOMPARE(friendLocation.isPartOfGroup(), false);
102 void TestFriendLocationItem::grouping()
104 FriendLocationItem friendLocation(userID);
107 QCOMPARE(friendLocation.isPartOfGroup(), false);
108 QCOMPARE(friendLocation.isVisible(), true);
111 friendLocation.setPartOfGroup(true);
113 // flag should be set and item should be hidden
114 QCOMPARE(friendLocation.isPartOfGroup(), true);
115 QCOMPARE(friendLocation.isVisible(), false);
117 // back to ungrouped state
118 friendLocation.setPartOfGroup(false);
121 QCOMPARE(friendLocation.isPartOfGroup(), false);
122 QCOMPARE(friendLocation.isVisible(), true);
125 void TestFriendLocationItem::setProfileImage()
127 FriendLocationItem friendLocation(userID);
129 //default pixmap and URL should be empty
130 QCOMPARE(friendLocation.pixmap().isNull(), true);
131 QCOMPARE(friendLocation.profileImageUrl().isEmpty(), true);
133 QPixmap friendIcon("situare_user.gif");
134 friendLocation.setProfileImage(friendIcon, url);
136 // picture should be set
137 QCOMPARE(friendLocation.pixmap().isNull(), false);
140 QCOMPARE(friendLocation.offset(),
141 QPointF(-friendIcon.width() / 2, -friendIcon.height() / 2));
144 QCOMPARE(friendLocation.profileImageUrl(), url);
147 QTEST_MAIN(TestFriendLocationItem)
148 #include "testfriendlocationitem.moc"