Unit tests re-factoring for new coordinates on-going...
[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/coordinates/geocoordinate.h"
26 #include "src/ui/friendlistitem.h"
27 #include "src/ui/friendlistview.h"
28 #include "src/user/user.h"
29 #include "src/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"), QPointF(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"), QPointF(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     User *user2 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
97                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
98                            QString("UserID2"), QString("Units"), 44.12);
99     user2->setProfileImage(QPixmap("situare_user.gif"));
100
101     FriendListItem *item1 = new FriendListItem(view);
102     item1->setData(user1);
103     FriendListItem *item2 = new FriendListItem(view);
104     item2->setData(user2);
105
106     view->addWidget(user1->userId(), item1);
107     view->addWidget(user2->userId(), item2);
108
109     QCOMPARE(view->layout()->count(), 2);
110
111     QStringList newUserIDs;
112     newUserIDs.append(user2->userId());
113     view->clearUnused(newUserIDs);
114
115     QCOMPARE(view->layout()->count(), 1);
116 }
117
118
119 QTEST_MAIN(TestFriendList)
120 #include "testfriendlist.moc"