Added forgotten FriendGroupItem unit test files
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 10 May 2010 08:27:51 +0000 (11:27 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 10 May 2010 08:27:51 +0000 (11:27 +0300)
tests/map/friendgroupitem/situare_user.gif [new file with mode: 0644]
tests/map/friendgroupitem/testfriendgroupitem.cpp [new file with mode: 0644]
tests/map/friendgroupitem/testfriendgroupitem.pro [new file with mode: 0644]

diff --git a/tests/map/friendgroupitem/situare_user.gif b/tests/map/friendgroupitem/situare_user.gif
new file mode 100644 (file)
index 0000000..cd34a82
Binary files /dev/null and b/tests/map/friendgroupitem/situare_user.gif differ
diff --git a/tests/map/friendgroupitem/testfriendgroupitem.cpp b/tests/map/friendgroupitem/testfriendgroupitem.cpp
new file mode 100644 (file)
index 0000000..ffa08b6
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+#include <QtTest/QtTest>
+
+#include "map/mapcommon.h"
+#include "map/friendgroupitem.h"
+#include "map/friendlocationitem.h"
+#include "map/mapscene.h"
+
+class TestFriendGroupItem: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void initTestCase(); // before first test
+    void cleanupTestCase(); // after last test have been run
+    void init(); // before each test
+    void cleanup(); // after each test
+
+    void addFriends();
+    void constructor();
+    void dropFriends();
+    void mergeWithGroup();
+
+private:
+    FriendLocationItem *friend1;
+    FriendLocationItem *friend2;
+    FriendLocationItem *friend3;
+    FriendLocationItem *friend4;
+    FriendGroupItem *group;
+    QPixmap *pixmap;
+    MapScene scene;
+};
+
+void TestFriendGroupItem::initTestCase()
+{
+    pixmap = new QPixmap("situare_user.gif");
+}
+
+void TestFriendGroupItem::cleanupTestCase()
+{
+    delete pixmap;
+}
+
+void TestFriendGroupItem::init()
+{
+    // create test friends
+    friend1 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
+    friend2 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
+    friend3 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
+    friend4 = new FriendLocationItem(*pixmap, QPoint(0, 0), this);
+    QVERIFY(friend1 != 0);
+    QVERIFY(friend2 != 0);
+    QVERIFY(friend3 != 0);
+    QVERIFY(friend4 != 0);
+
+    // add friends to scene
+    scene.addItem(friend1);
+    scene.addItem(friend2);
+    scene.addItem(friend3);
+    scene.addItem(friend4);
+
+    // override coordinate positions with scene pixel positions so testing is more
+    // convenient
+    friend1->setPos(100, 100);
+    friend2->setPos(100, 150);
+    friend3->setPos(150, 100);
+    friend4->setPos(150, 150);
+
+    // create test group
+    group = new FriendGroupItem(friend1);
+    QVERIFY(group != 0);
+}
+
+void TestFriendGroupItem::cleanup()
+{
+    delete group;
+
+    // remove and delete all items from the scene
+    scene.clear();
+}
+
+void TestFriendGroupItem::addFriends()
+{
+    group->joinFriend(friend2);
+    group->joinFriend(friend3);
+    QCOMPARE(friend2->isPartOfGroup(), true);
+    QCOMPARE(friend3->isPartOfGroup(), true);
+    QCOMPARE(friend4->isPartOfGroup(), false); // not yet part of group
+
+    // group position should still be same as first group members
+    QCOMPARE(group->pos(), QPointF(100, 100));
+}
+
+void TestFriendGroupItem::constructor()
+{
+    // group picture should be set
+    QVERIFY(!group->pixmap().isNull());
+
+    // group position should be same as first group members
+    QCOMPARE(group->pos(), QPointF(100, 100));
+
+    // zValue should be set
+    QCOMPARE(group->zValue(), static_cast<qreal>(FRIEND_LOCATION_ICON_Z_LEVEL));
+
+    // icon offset should be set
+    QCOMPARE(group->offset(), QPointF(-pixmap->width() / 2, -pixmap->height() / 2));
+}
+
+void TestFriendGroupItem::dropFriends()
+{
+    group->joinFriend(friend2);
+    group->joinFriend(friend3);
+    group->joinFriend(friend4);
+
+    QCOMPARE(friend1->isPartOfGroup(), true);
+    QCOMPARE(friend2->isPartOfGroup(), true);
+    QCOMPARE(friend3->isPartOfGroup(), true);
+    QCOMPARE(friend4->isPartOfGroup(), true);
+
+    // move friend4 to overlap one pixel with friend1
+    friend4->setPos(friend4->pos() - QPointF(1, 1));
+
+    // dropping should return false because there should be two friends remaining
+    QVERIFY(group->dropFriends(MAX_MAP_ZOOM_LEVEL) == false);
+
+    // friends 2 & 3 should be dropped
+    QCOMPARE(friend1->isPartOfGroup(), true);
+    QCOMPARE(friend2->isPartOfGroup(), false);
+    QCOMPARE(friend3->isPartOfGroup(), false);
+    QCOMPARE(friend4->isPartOfGroup(), true);
+
+    // move friend4 back to original position
+    friend4->setPos(friend4->pos() + QPointF(1, 1));
+
+    // dropping should return true because there should be no overlapping friends anymore
+    QVERIFY(group->dropFriends(MAX_MAP_ZOOM_LEVEL) == true);
+
+    // no-one should be part of group anymore
+    QCOMPARE(friend1->isPartOfGroup(), false);
+    QCOMPARE(friend2->isPartOfGroup(), false);
+    QCOMPARE(friend3->isPartOfGroup(), false);
+    QCOMPARE(friend4->isPartOfGroup(), false);
+}
+
+void TestFriendGroupItem::mergeWithGroup()
+{
+    group->joinFriend(friend2);
+
+    // create another group
+    FriendGroupItem anotherGroup(friend3);
+    anotherGroup.joinFriend(friend4);
+
+    // move friens to first group
+    anotherGroup.mergeWithGroup(group);
+
+    // no-one should actually be dropped because groups should be empty already
+    // and shoud return true because group shoud be empty
+    QVERIFY(anotherGroup.dropFriends(MAX_MAP_ZOOM_LEVEL) == true);
+
+    // everyone shoul still be part of first group
+    QCOMPARE(friend1->isPartOfGroup(), true);
+    QCOMPARE(friend2->isPartOfGroup(), true);
+    QCOMPARE(friend3->isPartOfGroup(), true);
+    QCOMPARE(friend4->isPartOfGroup(), true);
+}
+
+QTEST_MAIN(TestFriendGroupItem)
+
+#include "testfriendgroupitem.moc"
diff --git a/tests/map/friendgroupitem/testfriendgroupitem.pro b/tests/map/friendgroupitem/testfriendgroupitem.pro
new file mode 100644 (file)
index 0000000..7b4e73e
--- /dev/null
@@ -0,0 +1,42 @@
+# #####################################################################
+# Automatically generated by qmake (2.01a) Fri Mar 26 15:09:16 2010
+# #####################################################################
+CONFIG += qtestlib
+QT += network
+TEMPLATE = app
+TARGET = 
+DEPENDPATH += .
+INCLUDEPATH += . \
+    ../../../src/
+
+# Input
+SOURCES += testfriendgroupitem.cpp \
+    ../../../src/map/friendgroupitem.cpp \
+    ../../../src/map/friendlocationitem.cpp \
+    ../../../src/map/baselocationitem.cpp \
+    ../../../src/map/mapengine.cpp \
+    ../../../src/map/ownlocationitem.cpp \
+    ../../../src/map/mapzoompanel.cpp \
+    ../../../src/map/maptilerequest.cpp \
+    ../../../src/map/maptile.cpp \
+    ../../../src/map/mapscene.cpp \
+    ../../../src/map/mapfetcher.cpp \
+    ../../../src/map/mapbutton.cpp \
+    ../../../src/map/frienditemshandler.cpp \
+    ../../../src/user/user.cpp
+HEADERS += ../../../src/map/friendgroupitem.h \
+    ../../../src/map/friendlocationitem.h \
+    ../../../src/map/baselocationitem.h \
+    ../../../src/map/mapengine.h \
+    ../../../src/map/ownlocationitem.h \
+    ../../../src/map/mapzoompanel.h \
+    ../../../src/map/maptilerequest.h \
+    ../../../src/map/maptile.h \
+    ../../../src/map/mapscene.h \
+    ../../../src/map/mapfetcher.h \
+    ../../../src/map/mapcommon.h \
+    ../../../src/map/mapbutton.h \
+    ../../../src/map/frienditemshandler.h \
+    ../../../src/user/user.h
+DEFINES += QT_NO_DEBUG_OUTPUT
+RESOURCES += ../../../images.qrc