Merge branch 'master' of https://vcs.maemo.org/git/situare into list_panel
[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 widgets from the view.
43     */
44     void friendListViewClear();
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("UserID"), QString("Units"), 44.12);
54     User *user2 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
55                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
56                            QString("UserID"), QString("Units"), 44.12);
57
58     FriendListItem *item1 = new FriendListItem(view);
59     item1->setData(user1);
60     FriendListItem *item2 = new FriendListItem(view);
61     item2->setData(user2);
62
63     view->addWidget(item1);
64     view->addWidget(item2);
65
66     QCOMPARE(view->layout()->count(), 2);
67
68     User *user3 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
69                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
70                            QString("UserID"), QString("Units"), 44.12);
71
72     FriendListItem *item3 = new FriendListItem(view);
73     item3->setData(user3);
74     view->addWidget(item3);
75
76     QCOMPARE(view->layout()->count(), 3);
77
78     view->addWidget(item3);
79
80     QCOMPARE(view->layout()->count(), 3);
81 }
82
83 void TestFriendList::friendListViewClear()
84 {
85     FriendListView *view = new FriendListView();
86
87     User *user1 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
88                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
89                            QString("UserID"), QString("Units"), 44.12);
90     User *user2 = new User(QString("Address"), QPointF(12.22, 23.33), QString("Name"),
91                            QString("Note"), QUrl("http://image.url"), QString("Timestamp"), true,
92                            QString("UserID"), QString("Units"), 44.12);
93
94     FriendListItem *item1 = new FriendListItem(view);
95     item1->setData(user1);
96     FriendListItem *item2 = new FriendListItem(view);
97     item2->setData(user2);
98
99     view->addWidget(item1);
100     view->addWidget(item2);
101
102     QCOMPARE(view->layout()->count(), 2);
103
104     view->clear();
105
106     QCOMPARE(view->layout()->count(), 0);
107 }
108
109
110 QTEST_MAIN(TestFriendList)
111 #include "testfriendlist.moc"