45
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Test class for CalenDayContentWidget
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <QGraphicsItem>
|
|
18 |
#include <QtTest/QtTest>
|
|
19 |
|
75
|
20 |
#define private public
|
45
|
21 |
|
75
|
22 |
#include "calendayitemview.h"
|
45
|
23 |
#include "calendaycontentwidget.h"
|
|
24 |
|
|
25 |
class TestCalenContentWidget : public QObject
|
|
26 |
{
|
|
27 |
Q_OBJECT
|
|
28 |
|
|
29 |
public:
|
|
30 |
TestCalenContentWidget();
|
|
31 |
virtual ~TestCalenContentWidget();
|
|
32 |
|
|
33 |
private slots:
|
|
34 |
void initTestCase();
|
|
35 |
void cleanupTestCase();
|
|
36 |
void init();
|
|
37 |
void cleanup();
|
|
38 |
|
|
39 |
void testConstructors();
|
75
|
40 |
void testAdd();
|
|
41 |
void testTake();
|
|
42 |
void testRemove();
|
|
43 |
void testRelayoutWidgets();
|
|
44 |
void testWidgetScrolled();
|
45
|
45 |
|
|
46 |
private:
|
|
47 |
CalenDayContentWidget *mContentWidget;
|
|
48 |
};
|
|
49 |
|
|
50 |
/*!
|
|
51 |
Constructor
|
|
52 |
*/
|
|
53 |
TestCalenContentWidget::TestCalenContentWidget() :
|
75
|
54 |
mContentWidget(NULL)
|
45
|
55 |
{
|
|
56 |
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
Destructor
|
|
61 |
*/
|
|
62 |
TestCalenContentWidget::~TestCalenContentWidget()
|
|
63 |
{
|
|
64 |
|
|
65 |
}
|
|
66 |
|
|
67 |
/*!
|
|
68 |
Called before testcase
|
|
69 |
*/
|
|
70 |
void TestCalenContentWidget::initTestCase()
|
|
71 |
{
|
|
72 |
}
|
|
73 |
|
|
74 |
/*!
|
|
75 |
Called after testcase
|
|
76 |
*/
|
|
77 |
void TestCalenContentWidget::cleanupTestCase()
|
|
78 |
{
|
|
79 |
}
|
|
80 |
|
|
81 |
/*!
|
|
82 |
Called before every function
|
|
83 |
*/
|
|
84 |
void TestCalenContentWidget::init()
|
|
85 |
{
|
75
|
86 |
mContentWidget = new CalenDayContentWidget();
|
45
|
87 |
}
|
|
88 |
|
|
89 |
/*!
|
|
90 |
Called after everyfunction
|
|
91 |
*/
|
|
92 |
void TestCalenContentWidget::cleanup()
|
|
93 |
{
|
|
94 |
if (mContentWidget) {
|
|
95 |
delete mContentWidget;
|
|
96 |
mContentWidget = NULL;
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
Test class for constructors
|
|
102 |
1. Test if content widget is correcty created
|
|
103 |
*/
|
|
104 |
void TestCalenContentWidget::testConstructors()
|
|
105 |
{
|
75
|
106 |
CalenDayContentWidget *contentWidget = NULL;
|
|
107 |
|
|
108 |
QVERIFY(!contentWidget);
|
|
109 |
contentWidget = new CalenDayContentWidget();
|
|
110 |
QVERIFY(contentWidget);
|
|
111 |
|
|
112 |
delete contentWidget;
|
|
113 |
}
|
|
114 |
|
|
115 |
/*!
|
|
116 |
Test add() function
|
|
117 |
1. Test no error when trying to add NULL pointer
|
|
118 |
2. Test if widget is added correctly and layout is created
|
|
119 |
3. Test if widget is added correctly at end of list
|
|
120 |
4. Test if widget is added correctly as first item
|
|
121 |
5. Test if widget is added correctly when no position is specified
|
|
122 |
*/
|
|
123 |
void TestCalenContentWidget::testAdd()
|
|
124 |
{
|
|
125 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
126 |
QVERIFY(!mContentWidget->mLayout);
|
|
127 |
|
|
128 |
//1)
|
|
129 |
mContentWidget->add(NULL);
|
|
130 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
131 |
QVERIFY(!mContentWidget->mLayout);
|
|
132 |
|
|
133 |
//2)
|
|
134 |
HbWidget *second = new HbWidget();
|
|
135 |
mContentWidget->add(second);
|
|
136 |
QVERIFY(mContentWidget->mLayout);
|
|
137 |
QCOMPARE(mContentWidget->mWidgets.count(), 1);
|
|
138 |
|
|
139 |
//3)
|
|
140 |
HbWidget *last = new HbWidget();
|
|
141 |
mContentWidget->add(last, CalenDayContentWidget::ECalenLastWidget);
|
|
142 |
QCOMPARE(mContentWidget->mWidgets.count(), 2);
|
|
143 |
QCOMPARE(mContentWidget->mWidgets.at(1), last);
|
|
144 |
|
|
145 |
//4)
|
|
146 |
HbWidget *first = new HbWidget();
|
|
147 |
mContentWidget->add(first, CalenDayContentWidget::ECalenFirstWidget);
|
|
148 |
QCOMPARE(mContentWidget->mWidgets.count(), 3);
|
|
149 |
QCOMPARE(mContentWidget->mWidgets.at(0), first);
|
|
150 |
|
|
151 |
//5)
|
|
152 |
HbWidget *other = new HbWidget();
|
|
153 |
mContentWidget->add(other, CalenDayContentWidget::CalenWidgetPosition(-1));
|
|
154 |
QCOMPARE(mContentWidget->mWidgets.count(), 4);
|
|
155 |
QCOMPARE(mContentWidget->mWidgets.last(), other);
|
|
156 |
}
|
|
157 |
|
|
158 |
/*!
|
|
159 |
Test take() function
|
|
160 |
1. Test NULL pointer if there are no widgets to be taken
|
|
161 |
2. Test if first widget is taken correctly
|
|
162 |
3. Test if last widget is taken correctly
|
|
163 |
4. Test default behavior if wrong position is specified
|
|
164 |
*/
|
|
165 |
void TestCalenContentWidget::testTake()
|
|
166 |
{
|
|
167 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
168 |
|
|
169 |
//1)
|
|
170 |
QVERIFY(!mContentWidget->take(CalenDayContentWidget::ECalenFirstWidget));
|
|
171 |
|
|
172 |
// Prepare data
|
|
173 |
HbWidget *first = new HbWidget();
|
|
174 |
HbWidget *second = new HbWidget();
|
|
175 |
HbWidget *last = new HbWidget();
|
|
176 |
mContentWidget->add(first);
|
|
177 |
mContentWidget->add(second);
|
|
178 |
mContentWidget->add(last);
|
|
179 |
QCOMPARE(mContentWidget->mWidgets.count(), 3);
|
|
180 |
|
|
181 |
//2)
|
|
182 |
HbWidget *widget = mContentWidget->take(CalenDayContentWidget::ECalenFirstWidget);
|
|
183 |
QCOMPARE(mContentWidget->mWidgets.count(), 2);
|
|
184 |
QCOMPARE(widget, first);
|
|
185 |
|
|
186 |
delete widget;
|
|
187 |
widget = NULL;
|
|
188 |
|
|
189 |
//3)
|
|
190 |
widget = mContentWidget->take(CalenDayContentWidget::ECalenLastWidget);
|
|
191 |
QCOMPARE(mContentWidget->mWidgets.count(), 1);
|
|
192 |
QCOMPARE(widget, last);
|
|
193 |
|
|
194 |
delete widget;
|
|
195 |
widget = NULL;
|
|
196 |
|
|
197 |
//4)
|
|
198 |
widget = mContentWidget->take(CalenDayContentWidget::CalenWidgetPosition(-1));
|
|
199 |
QCOMPARE(mContentWidget->mWidgets.count(), 1);
|
|
200 |
QVERIFY(!widget);
|
|
201 |
}
|
|
202 |
|
|
203 |
/*!
|
|
204 |
Test remove() function
|
|
205 |
1. Test if there is no error if remove is called on empty content
|
|
206 |
2. Test if first widget is removed correctly
|
|
207 |
3. Test if last widget is removed correctly
|
|
208 |
*/
|
|
209 |
void TestCalenContentWidget::testRemove()
|
|
210 |
{
|
|
211 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
212 |
|
|
213 |
//1)
|
|
214 |
mContentWidget->remove(CalenDayContentWidget::ECalenFirstWidget);
|
|
215 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
216 |
|
|
217 |
// Prepare data
|
|
218 |
HbWidget *first = new HbWidget();
|
|
219 |
HbWidget *second = new HbWidget();
|
|
220 |
HbWidget *last = new HbWidget();
|
|
221 |
mContentWidget->add(first);
|
|
222 |
mContentWidget->add(second);
|
|
223 |
mContentWidget->add(last);
|
|
224 |
QCOMPARE(mContentWidget->mWidgets.count(), 3);
|
|
225 |
|
|
226 |
//2)
|
|
227 |
mContentWidget->remove(CalenDayContentWidget::ECalenFirstWidget);
|
|
228 |
QCOMPARE(mContentWidget->mWidgets.count(), 2);
|
|
229 |
QCOMPARE(mContentWidget->mWidgets.first(), second);
|
|
230 |
|
|
231 |
//3)
|
|
232 |
mContentWidget->remove(CalenDayContentWidget::ECalenLastWidget);
|
|
233 |
QCOMPARE(mContentWidget->mWidgets.count(), 1);
|
|
234 |
QCOMPARE(mContentWidget->mWidgets.last(), second);
|
|
235 |
}
|
|
236 |
|
|
237 |
/*!
|
|
238 |
Test relayoutWidgets() slot
|
|
239 |
1. Test if relayout widgets on empty content
|
|
240 |
2. Test ECalenScrollToNext case
|
|
241 |
3. Test ECalenScrollToPrev case
|
|
242 |
4. Test ECalenScrollNoDayChange case
|
|
243 |
5. Test wrong case
|
|
244 |
*/
|
|
245 |
void TestCalenContentWidget::testRelayoutWidgets()
|
|
246 |
{
|
|
247 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
248 |
|
|
249 |
//1)
|
|
250 |
mContentWidget->relayoutWidgets(ECalenScrollNoDayChange);
|
|
251 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
252 |
|
|
253 |
// Prepare data
|
|
254 |
HbWidget *first = new HbWidget();
|
|
255 |
HbWidget *second = new HbWidget();
|
|
256 |
HbWidget *last = new HbWidget();
|
|
257 |
mContentWidget->add(first);
|
|
258 |
mContentWidget->add(second);
|
|
259 |
mContentWidget->add(last);
|
|
260 |
QCOMPARE(mContentWidget->mWidgets.count(), 3);
|
|
261 |
|
|
262 |
//2)
|
|
263 |
mContentWidget->relayoutWidgets(ECalenScrollToNext);
|
|
264 |
QCOMPARE(mContentWidget->mWidgets.first(), second);
|
|
265 |
|
|
266 |
//3)
|
|
267 |
mContentWidget->relayoutWidgets(ECalenScrollToPrev);
|
|
268 |
QCOMPARE(mContentWidget->mWidgets.first(), first);
|
|
269 |
|
|
270 |
//4)
|
|
271 |
mContentWidget->relayoutWidgets(ECalenScrollNoDayChange);
|
|
272 |
QCOMPARE(mContentWidget->mWidgets.first(), first);
|
|
273 |
|
|
274 |
//5)
|
|
275 |
mContentWidget->relayoutWidgets(CalenScrollDirection(-1));
|
|
276 |
QCOMPARE(mContentWidget->mWidgets.first(), first);
|
|
277 |
}
|
|
278 |
|
|
279 |
/*!
|
|
280 |
Test testWidgetScrolled() slot
|
|
281 |
1. Test widgetScrolled with empty content
|
|
282 |
2. Test widgetScrolled with 3 views
|
|
283 |
*/
|
|
284 |
void TestCalenContentWidget::testWidgetScrolled()
|
|
285 |
{
|
|
286 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
287 |
QPointF newPos(10, 20);
|
|
288 |
|
|
289 |
//1)
|
|
290 |
mContentWidget->widgetScrolled(newPos);
|
|
291 |
QCOMPARE(mContentWidget->mWidgets.count(), 0);
|
|
292 |
|
|
293 |
#ifndef __WINSCW__
|
|
294 |
// Prepare data
|
|
295 |
MCalenServices services;
|
|
296 |
HbModelIterator iterator(0);
|
|
297 |
CalenDayItemView *first = new CalenDayItemView(services, &iterator);
|
|
298 |
CalenDayItemView *second = new CalenDayItemView(services, &iterator);
|
|
299 |
CalenDayItemView *last = new CalenDayItemView(services, &iterator);
|
|
300 |
mContentWidget->add(first);
|
|
301 |
mContentWidget->add(second);
|
|
302 |
mContentWidget->add(last);
|
|
303 |
QCOMPARE(mContentWidget->mWidgets.count(), 3);
|
|
304 |
QCOMPARE(first->mCurrentPos, QPointF(0,0));
|
|
305 |
QCOMPARE(second->mCurrentPos, QPointF(0,0));
|
|
306 |
QCOMPARE(last->mCurrentPos, QPointF(0,0));
|
|
307 |
|
|
308 |
//2
|
|
309 |
mContentWidget->widgetScrolled(newPos);
|
|
310 |
CalenDayItemView *view = static_cast<CalenDayItemView *> (mContentWidget->mWidgets.at(0));
|
|
311 |
QCOMPARE(view->mCurrentPos, newPos);
|
|
312 |
view = static_cast<CalenDayItemView *> (mContentWidget->mWidgets.at(1));
|
|
313 |
QCOMPARE(view->mCurrentPos, newPos);
|
|
314 |
view = static_cast<CalenDayItemView *> (mContentWidget->mWidgets.at(2));
|
|
315 |
QCOMPARE(view->mCurrentPos, newPos);
|
|
316 |
#endif // __WINSCW__
|
45
|
317 |
}
|
|
318 |
|
|
319 |
QTEST_MAIN(TestCalenContentWidget);
|
|
320 |
#include "unittest_calendaycontentwidget.moc"
|