Modified tests/tests.pro.
[situare] / tests / ui / friendlist / testfriendlist.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 #include <QtGui>
24
25 #include "../../../src/ui/friendlistitem.h"
26 #include "../../../src/ui/friendlistview.h"
27 #include "../../../src/user/user.h"
28 #include "../../../src/ui/avatarimage.h"
29
30
31 class TestFriendList: public QObject
32 {
33     Q_OBJECT
34 private slots:
35     /**
36     * @brief Add widgets to the view.
37     */
38     void friendListViewAddWidget();
39
40
41     /**
42     * @brief Clear unused widgets from the view.
43     */
44     void friendListViewClearUnused();
45 };
46
47 void TestFriendList::friendListViewAddWidget()
48 {
49     FriendListView *view = new FriendListView();
50
51     User *user1 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
52                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
53                            QString("UserID1"), QString("Units"), 44.12);
54     user1->setProfileImage(QPixmap("situare_user.gif"));
55     User *user2 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
56                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
57                            QString("UserID2"), QString("Units"), 44.12);
58     user2->setProfileImage(QPixmap("situare_user.gif"));
59
60     FriendListItem *item1 = new FriendListItem(view);
61     item1->setData(user1);
62     FriendListItem *item2 = new FriendListItem(view);
63     item2->setData(user2);
64
65     view->addWidget(user1->userId(), item1);
66     view->addWidget(user2->userId(), item2);
67
68     QCOMPARE(view->layout()->count(), 2);
69
70     User *user3 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
71                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
72                            QString("UserID3"), QString("Units"), 44.12);
73     user3->setProfileImage(QPixmap("situare_user.gif"));
74
75     FriendListItem *item3 = new FriendListItem(view);
76     item3->setData(user3);
77     view->addWidget(user3->userId(), item3);
78
79     QCOMPARE(view->layout()->count(), 3);
80
81     view->addWidget(user3->userId(), item3);
82
83     QCOMPARE(view->layout()->count(), 3);
84 }
85
86 void TestFriendList::friendListViewClearUnused()
87 {
88     FriendListView *view = new FriendListView();
89
90     User *user1 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
91                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
92                            QString("UserID1"), QString("Units"), 44.12);
93     user1->setProfileImage(QPixmap("situare_user.gif"));
94     User *user2 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
95                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
96                            QString("UserID2"), QString("Units"), 44.12);
97     user2->setProfileImage(QPixmap("situare_user.gif"));
98
99     FriendListItem *item1 = new FriendListItem(view);
100     item1->setData(user1);
101     FriendListItem *item2 = new FriendListItem(view);
102     item2->setData(user2);
103
104     view->addWidget(user1->userId(), item1);
105     view->addWidget(user2->userId(), item2);
106
107     QCOMPARE(view->layout()->count(), 2);
108
109     QStringList newUserIDs;
110     newUserIDs.append(user2->userId());
111     view->clearUnused(newUserIDs);
112
113     QCOMPARE(view->layout()->count(), 1);
114 }
115
116
117 QTEST_MAIN(TestFriendList)
118 #include "testfriendlist.moc"