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;
54 void TestFriendGroupItem::initTestCase()
56 pixmap = new QPixmap("situare_user.gif");
59 void TestFriendGroupItem::cleanupTestCase()
64 void TestFriendGroupItem::init()
66 // create test friends
67 friend1 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
68 friend2 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
69 friend3 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
70 friend4 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
71 QVERIFY(friend1 != 0);
72 QVERIFY(friend2 != 0);
73 QVERIFY(friend3 != 0);
74 QVERIFY(friend4 != 0);
76 // add friends to scene
77 scene.addItem(friend1);
78 scene.addItem(friend2);
79 scene.addItem(friend3);
80 scene.addItem(friend4);
82 // override coordinate positions with scene pixel positions so testing is more
84 friend1->setPos(100, 100);
85 friend2->setPos(100, 150);
86 friend3->setPos(150, 100);
87 friend4->setPos(150, 150);
90 group = new FriendGroupItem(friend1);
92 QVERIFY(friend1->isPartOfGroup());
95 void TestFriendGroupItem::cleanup()
99 // remove and delete all items from the scene
103 void TestFriendGroupItem::addFriends()
105 group->joinFriend(friend2);
106 group->joinFriend(friend3);
107 QCOMPARE(friend2->isPartOfGroup(), true);
108 QCOMPARE(friend3->isPartOfGroup(), true);
109 QCOMPARE(friend4->isPartOfGroup(), false); // not yet part of group
111 // group position should still be same as first group members
112 QCOMPARE(group->pos(), QPointF(100, 100));
115 void TestFriendGroupItem::constructor()
117 // group picture should be set
118 QVERIFY(!group->pixmap().isNull());
120 // group position should be same as first group members
121 QCOMPARE(group->pos(), QPointF(100, 100));
123 // zValue should be set
124 QCOMPARE(group->zValue(), static_cast<qreal>(FRIEND_LOCATION_ICON_Z_LEVEL));
126 // icon offset should be set
127 QCOMPARE(group->offset(), QPointF(-pixmap->width() / 2, -pixmap->height() / 2));
130 void TestFriendGroupItem::dropFriends()
132 group->joinFriend(friend2);
133 group->joinFriend(friend3);
134 group->joinFriend(friend4);
136 QCOMPARE(friend1->isPartOfGroup(), true);
137 QCOMPARE(friend2->isPartOfGroup(), true);
138 QCOMPARE(friend3->isPartOfGroup(), true);
139 QCOMPARE(friend4->isPartOfGroup(), true);
141 // move friend4 to overlap one pixel with friend1
142 friend4->setPos(friend4->pos() - QPointF(1, 1));
144 // dropping should return false because there should be two friends remaining
145 QVERIFY(group->dropFriends(MAX_MAP_ZOOM_LEVEL) == false);
147 // friends 2 & 3 should be dropped
148 QCOMPARE(friend1->isPartOfGroup(), true);
149 QCOMPARE(friend2->isPartOfGroup(), false);
150 QCOMPARE(friend3->isPartOfGroup(), false);
151 QCOMPARE(friend4->isPartOfGroup(), true);
153 // move friend4 back to original position
154 friend4->setPos(friend4->pos() + QPointF(1, 1));
156 // dropping should return true because there should be no overlapping friends anymore
157 QVERIFY(group->dropFriends(MAX_MAP_ZOOM_LEVEL) == true);
159 // no-one should be part of group anymore
160 QCOMPARE(friend1->isPartOfGroup(), false);
161 QCOMPARE(friend2->isPartOfGroup(), false);
162 QCOMPARE(friend3->isPartOfGroup(), false);
163 QCOMPARE(friend4->isPartOfGroup(), false);
166 void TestFriendGroupItem::mergeWithGroup()
168 group->joinFriend(friend2);
170 // create another group
171 FriendGroupItem anotherGroup(friend3);
172 anotherGroup.joinFriend(friend4);
174 // move friends to first group
175 anotherGroup.mergeWithGroup(group);
177 // no-one should actually be dropped because groups should be empty already
178 // and shoud return true because group shoud be empty
179 QVERIFY(anotherGroup.dropFriends(MAX_MAP_ZOOM_LEVEL) == true);
181 // everyone shoul still be part of first group
182 QCOMPARE(friend1->isPartOfGroup(), true);
183 QCOMPARE(friend2->isPartOfGroup(), true);
184 QCOMPARE(friend3->isPartOfGroup(), true);
185 QCOMPARE(friend4->isPartOfGroup(), true);
188 QTEST_MAIN(TestFriendGroupItem)
190 #include "testfriendgroupitem.moc"