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>
23 #include <QGraphicsScene>
25 #include "map/mapcommon.h"
26 #include "map/friendgroupitem.h"
27 #include "map/friendlocationitem.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
44 FriendLocationItem *friend1;
45 FriendLocationItem *friend2;
46 FriendLocationItem *friend3;
47 FriendLocationItem *friend4;
48 FriendGroupItem *group;
54 void TestFriendGroupItem::initTestCase()
56 pixmap = new QPixmap("friend_group.png");
57 url = QUrl("http://www.something.com/pict.png");
60 void TestFriendGroupItem::cleanupTestCase()
65 void TestFriendGroupItem::init()
67 QString userID("ABC123");
69 // create test friends
70 friend1 = new FriendLocationItem(userID, this);
71 friend2 = new FriendLocationItem(userID, this);
72 friend3 = new FriendLocationItem(userID, this);
73 friend4 = new FriendLocationItem(userID, this);
74 QVERIFY(friend1 != 0);
75 QVERIFY(friend2 != 0);
76 QVERIFY(friend3 != 0);
77 QVERIFY(friend4 != 0);
80 friend1->setProfileImage(*pixmap, url);
81 friend2->setProfileImage(*pixmap, url);
82 friend3->setProfileImage(*pixmap, url);
83 friend4->setProfileImage(*pixmap, url);
85 // add friends to scene
86 scene.addItem(friend1);
87 scene.addItem(friend2);
88 scene.addItem(friend3);
89 scene.addItem(friend4);
91 // override coordinate positions with scene pixel positions so testing is more
93 const int ITEM_SIDE = 58; // defined in baselocationitem.cpp
94 friend1->setPos(100, 100);
95 friend2->setPos(friend1->pos() + QPoint(0, ITEM_SIDE)); // east from friend1
96 friend3->setPos(friend1->pos() + QPoint(ITEM_SIDE, 0)); // south from friend1
97 friend4->setPos(friend1->pos() + QPoint(ITEM_SIDE, ITEM_SIDE)); // south-east from friend1
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 group->dropFriends();
153 // no-one should be part of group anymore
154 QCOMPARE(friend1->isPartOfGroup(), false);
155 QCOMPARE(friend2->isPartOfGroup(), false);
156 QCOMPARE(friend3->isPartOfGroup(), false);
157 QCOMPARE(friend4->isPartOfGroup(), false);
160 QTEST_MAIN(TestFriendGroupItem)
162 #include "testfriendgroupitem.moc"