Added TextModifier class to test classes.
[situare] / tests / ui / friendlistitem / testfriendlistitem.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
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.
10
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.
15
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,
19    USA.
20 */
21
22 #include <QtTest>
23
24 #include "ui/extendedlistitemstore.h"
25 #include "ui/listcommon.h"
26 #include "user/user.h"
27
28 #include "ui/friendlistitem.h"
29
30 class TestFriendListItem: public QObject
31 {
32     Q_OBJECT
33
34 private slots:
35     void cleanupTestCase();
36     void initTestCase();
37     void setUserData();
38     void toggleSelection();
39
40 private:
41     FriendListItem *friendListItem;
42     User *user1;
43     User *user2;
44 };
45
46 void TestFriendListItem::cleanupTestCase()
47 {
48     delete friendListItem;
49     delete user1;
50     delete user2;
51 }
52
53 void TestFriendListItem::initTestCase()
54 {
55     friendListItem = new FriendListItem();
56
57     user1 = new User(QString("Address address address address address"),
58                            GeoCoordinate(12.22, 23.33), QString("Name na msfdsa dsfadsaf sdaf"),
59                            QString("Note note note note note note note note note note note note " \
60                                    "note note note note note"),
61                            QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
62                            true, QString("id1"), QString("km"), 44.12);
63     user1->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
64
65     user2 = new User(QString("Address address"),
66                            GeoCoordinate(12.1, 44.33), QString("Name na msfdsa dsfadsaf sdaf"),
67                            QString("Note note note note note note note note note note note note" \
68                                    "note note note note note"),
69                            QUrl("http://image.url"), QString("Timestamp timestamp timestamp tim"),
70                            true, QString("id2"), QString("km"), 144.12);
71     user2->setProfileImage(QPixmap(":/res/images/profile_pic_border.png"));
72
73     QVERIFY(friendListItem != 0);
74     QVERIFY(user1 != 0);
75     QVERIFY(user2 != 0);
76 }
77
78 void TestFriendListItem::setUserData()
79 {
80     friendListItem->setUserData(user1);
81     QCOMPARE(friendListItem->coordinates().latitude(), GeoCoordinate(12.22, 23.33).latitude());
82     QCOMPARE(friendListItem->coordinates().longitude(), GeoCoordinate(12.22, 23.33).longitude());
83
84     QPixmap profileImage = QPixmap(qvariant_cast<QPixmap>(friendListItem->data(
85             AVATAR_IMAGE_INDEX)));
86     QCOMPARE(profileImage, QPixmap(":/res/images/profile_pic_border.png"));
87
88     friendListItem->setUserData(user2);
89     QCOMPARE(friendListItem->coordinates().latitude(), GeoCoordinate(12.1, 44.33).latitude());
90     QCOMPARE(friendListItem->coordinates().longitude(), GeoCoordinate(12.1, 44.33).longitude());
91 }
92
93 void TestFriendListItem::toggleSelection()
94 {
95     QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 139));
96
97     QList<ExtendedListItemStore *> *subItems = (QList<ExtendedListItemStore *> *)
98                                                (friendListItem->data(SUBITEM_STORE_INDEX)
99                                                 .value<void *>());
100
101     QVERIFY(friendListItem->data(ITEM_HAS_IMAGE_INDEX).toBool());
102
103     QVERIFY(subItems);
104     QCOMPARE(subItems->count(), 3);
105
106     friendListItem->toggleSelection();
107     QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), true);
108
109     friendListItem->toggleSelection();
110     QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 139));
111     QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), false);
112 }
113
114 QTEST_MAIN(TestFriendListItem)
115 #include "testfriendlistitem.moc"