Added tests/ui/friendlistitem.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Jul 2010 10:08:37 +0000 (13:08 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 19 Jul 2010 10:08:37 +0000 (13:08 +0300)
tests/ui/friendlistitem/friendlistitem.pro [new file with mode: 0644]
tests/ui/friendlistitem/testfriendlistitem.cpp [new file with mode: 0644]

diff --git a/tests/ui/friendlistitem/friendlistitem.pro b/tests/ui/friendlistitem/friendlistitem.pro
new file mode 100644 (file)
index 0000000..b3e8995
--- /dev/null
@@ -0,0 +1,13 @@
+CONFIG += qtestlib
+DEFINES += QT_NO_DEBUG_OUTPUT
+INCLUDEPATH += . \
+    ../../../src/
+HEADERS += ../../../src/ui/friendlistitem.h \
+    ../../../src/ui/listitem.h \
+    ../../../src/ui/listcommon.h \
+    ../../../src/user/user.h
+SOURCES += ../../../src/ui/friendlistitem.cpp \
+    ../../../src/ui/listitem.cpp \
+    ../../../src/user/user.cpp \
+    testfriendlistitem.cpp
+RESOURCES += ../../../images.qrc
diff --git a/tests/ui/friendlistitem/testfriendlistitem.cpp b/tests/ui/friendlistitem/testfriendlistitem.cpp
new file mode 100644 (file)
index 0000000..830ef32
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@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>
+#include <QtGui>
+
+#include "../../../src/ui/friendlistitem.h"
+#include "../../../src/user/user.h"
+#include "../../../src/ui/listcommon.h"
+
+class TestFriendListItem: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void cleanupTestCase();
+    void initTestCase();
+    void setUserData();
+    void toggleSelection();
+
+private:
+    FriendListItem *friendListItem;
+    User *user1;
+    User *user2;
+};
+
+void TestFriendListItem::cleanupTestCase()
+{
+    delete friendListItem;
+    delete user1;
+    delete user2;
+}
+
+void TestFriendListItem::initTestCase()
+{
+    friendListItem = new FriendListItem();
+
+    user1 = new User(QString("Address address address address address"),
+                           QPointF(12.22, 23.33), QString("Name na msfdsa dsfadsaf sdaf"),
+                           QString("Note note note note note note note note"),
+                           QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
+                           true, QString("id1"), QString("km"), 44.12);
+    user1->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
+
+    user2 = new User(QString("Address address"),
+                           QPointF(12.1, 44.33), QString("Name na msfdsa dsfadsaf sdaf"),
+                           QString("Note note note note note note note note"),
+                           QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
+                           true, QString("id2"), QString("km"), 144.12);
+    user2->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
+
+    QVERIFY(friendListItem != 0);
+    QVERIFY(user1 != 0);
+    QVERIFY(user2 != 0);
+}
+
+void TestFriendListItem::setUserData()
+{
+    friendListItem->setUserData(user1);
+    QCOMPARE(friendListItem->id(), QString("id1"));
+    QCOMPARE(friendListItem->coordinates(), QPointF(12.22, 23.33));
+
+    QPixmap profileImage = QPixmap(qvariant_cast<QPixmap>(friendListItem->data(
+            AVATAR_IMAGE_INDEX)));
+    QCOMPARE(profileImage, QPixmap(":/res/images/profile_pic_border.png"));
+
+    friendListItem->setUserData(user2);
+    QCOMPARE(friendListItem->id(), QString("id2"));
+    QCOMPARE(friendListItem->coordinates(), QPointF(12.1, 44.33));
+}
+
+void TestFriendListItem::toggleSelection()
+{
+    QCOMPARE(friendListItem->id(), QString("id2"));
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 141));
+    QCOMPARE(friendListItem->data(STATUS_TEXT_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(friendListItem->data(LOCATION_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(friendListItem->data(UPDATED_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+
+    friendListItem->toggleSelection();
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 141 + 2*24));
+    QCOMPARE(friendListItem->data(STATUS_TEXT_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 2*24));
+    QCOMPARE(friendListItem->data(LOCATION_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(friendListItem->data(UPDATED_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 2*24));
+
+    friendListItem->toggleSelection();
+    QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 141));
+    QCOMPARE(friendListItem->data(STATUS_TEXT_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(friendListItem->data(LOCATION_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+    QCOMPARE(friendListItem->data(UPDATED_SIZE_HINT_INDEX).toRect(), QRect(0, 0, 250, 24));
+}
+
+QTEST_MAIN(TestFriendListItem)
+#include "testfriendlistitem.moc"