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"
25 #include "map/friendgroupitem.h"
26 #include "map/friendlocationitem.h"
27 #include "map/mapscene.h"
29 class TestFriendGroupItem: public QObject
34 void initTestCase(); // before first test
35 void cleanupTestCase(); // after last test have been run
36 void init(); // before each test
37 void cleanup(); // after each test
42 void mergeWithGroup();
45 FriendLocationItem *friend1;
46 FriendLocationItem *friend2;
47 FriendLocationItem *friend3;
48 FriendLocationItem *friend4;
49 FriendGroupItem *group;
55 void TestFriendGroupItem::initTestCase()
57 pixmap = new QPixmap("situare_user.gif");
58 url = QUrl("http://www.something.com/pict.png");
61 void TestFriendGroupItem::cleanupTestCase()
66 void TestFriendGroupItem::init()
68 QString userID("ABC123");
70 // create test friends
71 friend1 = new FriendLocationItem(userID, this);
72 friend2 = new FriendLocationItem(userID, this);
73 friend3 = new FriendLocationItem(userID, this);
74 friend4 = new FriendLocationItem(userID, this);
75 QVERIFY(friend1 != 0);
76 QVERIFY(friend2 != 0);
77 QVERIFY(friend3 != 0);
78 QVERIFY(friend4 != 0);
81 friend1->setProfileImage(*pixmap, url);
82 friend2->setProfileImage(*pixmap, url);
83 friend3->setProfileImage(*pixmap, url);
84 friend4->setProfileImage(*pixmap, url);
86 // add friends to scene
87 scene.addItem(friend1);
88 scene.addItem(friend2);
89 scene.addItem(friend3);
90 scene.addItem(friend4);
92 // override coordinate positions with scene pixel positions so testing is more
94 friend1->setPos(100, 100);
95 friend2->setPos(100, 150);
96 friend3->setPos(150, 100);
97 friend4->setPos(150, 150);
100 group = new FriendGroupItem(friend1);
102 QVERIFY(friend1->isPartOfGroup());
105 void TestFriendGroupItem::cleanup()
109 // remove and delete all items from the scene
113 void TestFriendGroupItem::addFriends()
115 group->joinFriend(friend2);
116 group->joinFriend(friend3);
117 QCOMPARE(friend2->isPartOfGroup(), true);
118 QCOMPARE(friend3->isPartOfGroup(), true);
119 QCOMPARE(friend4->isPartOfGroup(), false); // not yet part of group
121 // group position should still be same as first group members
122 QCOMPARE(group->pos(), QPointF(100, 100));
125 void TestFriendGroupItem::constructor()
127 // group picture should be set
128 QVERIFY(!group->pixmap().isNull());
130 // group position should be same as first group members
131 QCOMPARE(group->pos(), QPointF(100, 100));
133 // zValue should be set
134 QCOMPARE(group->zValue(), static_cast<qreal>(FRIEND_LOCATION_ICON_Z_LEVEL));
136 // icon offset should be set
137 QCOMPARE(group->offset(), QPointF(-pixmap->width() / 2, -pixmap->height() / 2));
140 void TestFriendGroupItem::dropFriends()
142 group->joinFriend(friend2);
143 group->joinFriend(friend3);
144 group->joinFriend(friend4);
146 QCOMPARE(friend1->isPartOfGroup(), true);
147 QCOMPARE(friend2->isPartOfGroup(), true);
148 QCOMPARE(friend3->isPartOfGroup(), true);
149 QCOMPARE(friend4->isPartOfGroup(), true);
151 // move friend4 to overlap one pixel with friend1
152 friend4->setPos(friend4->pos() - QPointF(1, 1));
154 // dropping should return false because there should be two friends remaining
155 QVERIFY(group->dropFriends(MAX_MAP_ZOOM_LEVEL) == false);
157 // friends 2 & 3 should be dropped
158 QCOMPARE(friend1->isPartOfGroup(), true);
159 QCOMPARE(friend2->isPartOfGroup(), false);
160 QCOMPARE(friend3->isPartOfGroup(), false);
161 QCOMPARE(friend4->isPartOfGroup(), true);
163 // move friend4 back to original position
164 friend4->setPos(friend4->pos() + QPointF(1, 1));
166 // dropping should return true because there should be no overlapping friends anymore
167 QVERIFY(group->dropFriends(MAX_MAP_ZOOM_LEVEL) == true);
169 // no-one should be part of group anymore
170 QCOMPARE(friend1->isPartOfGroup(), false);
171 QCOMPARE(friend2->isPartOfGroup(), false);
172 QCOMPARE(friend3->isPartOfGroup(), false);
173 QCOMPARE(friend4->isPartOfGroup(), false);
176 void TestFriendGroupItem::mergeWithGroup()
178 group->joinFriend(friend2);
180 // create another group
181 FriendGroupItem anotherGroup(friend3);
182 anotherGroup.joinFriend(friend4);
184 // move friends to first group
185 anotherGroup.mergeWithGroup(group);
187 // no-one should actually be dropped because groups should be empty already
188 // and shoud return true because group shoud be empty
189 QVERIFY(anotherGroup.dropFriends(MAX_MAP_ZOOM_LEVEL) == true);
191 // everyone shoul still be part of first group
192 QCOMPARE(friend1->isPartOfGroup(), true);
193 QCOMPARE(friend2->isPartOfGroup(), true);
194 QCOMPARE(friend3->isPartOfGroup(), true);
195 QCOMPARE(friend4->isPartOfGroup(), true);
198 QTEST_MAIN(TestFriendGroupItem)
200 #include "testfriendgroupitem.moc"