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