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 |
*
|
57
|
14 |
* Description: Test class for CalenDayItem
|
45
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <QGraphicsItem>
|
|
18 |
#include <QtTest/QtTest>
|
57
|
19 |
#include <QGraphicsSceneEvent>
|
|
20 |
#include <QDebug>
|
45
|
21 |
|
|
22 |
|
57
|
23 |
#include "agendaentry.h"
|
|
24 |
#include "calendaycontainer.h"
|
|
25 |
|
70
|
26 |
// System includes
|
|
27 |
#include <HbFrameItem>
|
|
28 |
#include <HbTextItem>
|
|
29 |
#include <HbStyle>
|
|
30 |
#include <HbColorScheme>
|
|
31 |
#include <agendaentry.h>
|
|
32 |
|
|
33 |
// User includes
|
|
34 |
#include "calendaycommonheaders.h"
|
|
35 |
#include "calendaystatusstrip.h"
|
|
36 |
#include "calendaymodel.h"
|
|
37 |
#include "calendayutils.h"
|
|
38 |
#include "calenagendautils.h"
|
|
39 |
#include "calendaycontainer.h"
|
|
40 |
|
|
41 |
#ifndef __WINSCW__
|
57
|
42 |
#define private public
|
|
43 |
#define protected public
|
70
|
44 |
#endif
|
57
|
45 |
|
45
|
46 |
#include "calendayitem.h"
|
70
|
47 |
#include "calendayitemtest.h"
|
57
|
48 |
|
|
49 |
|
|
50 |
QRectF gTestWindowRect;
|
|
51 |
Qt::Orientation gTestOrientation;
|
45
|
52 |
|
|
53 |
class TestCalenDayItem : public QObject
|
|
54 |
{
|
|
55 |
Q_OBJECT
|
|
56 |
|
|
57 |
public:
|
|
58 |
TestCalenDayItem();
|
|
59 |
virtual ~TestCalenDayItem();
|
|
60 |
|
|
61 |
private slots:
|
|
62 |
void initTestCase();
|
|
63 |
void cleanupTestCase();
|
|
64 |
void init();
|
|
65 |
void cleanup();
|
|
66 |
|
57
|
67 |
void testCreateItem();
|
|
68 |
void testUpdateChildItems();
|
|
69 |
void testHasEventDescription();
|
|
70 |
void testHasBackgroundFrame();
|
81
|
71 |
void testSetDescription();
|
|
72 |
void testSetStatusStrip();
|
57
|
73 |
|
45
|
74 |
void testConstructors();
|
|
75 |
private:
|
70
|
76 |
CalenDayItemTest *mItem;
|
55
|
77 |
CalenDayContainer *mContainer;
|
45
|
78 |
};
|
|
79 |
|
|
80 |
/*!
|
|
81 |
Constructor
|
|
82 |
*/
|
70
|
83 |
TestCalenDayItem::TestCalenDayItem() : mItem(NULL), mContainer(NULL)
|
45
|
84 |
{
|
|
85 |
|
|
86 |
}
|
|
87 |
|
|
88 |
/*!
|
|
89 |
Destructor
|
|
90 |
*/
|
|
91 |
TestCalenDayItem::~TestCalenDayItem()
|
|
92 |
{
|
|
93 |
|
|
94 |
}
|
|
95 |
|
|
96 |
/*!
|
|
97 |
Called before testcase
|
|
98 |
*/
|
|
99 |
void TestCalenDayItem::initTestCase()
|
|
100 |
{
|
|
101 |
}
|
|
102 |
|
|
103 |
/*!
|
|
104 |
Called after testcase
|
|
105 |
*/
|
|
106 |
void TestCalenDayItem::cleanupTestCase()
|
|
107 |
{
|
|
108 |
|
|
109 |
}
|
|
110 |
|
|
111 |
/*!
|
|
112 |
Called before every function
|
|
113 |
*/
|
|
114 |
void TestCalenDayItem::init()
|
|
115 |
{
|
55
|
116 |
mContainer = new CalenDayContainer();
|
70
|
117 |
mItem = new CalenDayItemTest(mContainer);
|
|
118 |
#ifndef __WINSCW__
|
57
|
119 |
mItem->mBg = new HbFrameItem();
|
|
120 |
mItem->mEventDesc = new HbTextItem(0);
|
70
|
121 |
#endif
|
45
|
122 |
}
|
|
123 |
|
|
124 |
/*!
|
|
125 |
Called after everyfunction
|
|
126 |
*/
|
|
127 |
void TestCalenDayItem::cleanup()
|
|
128 |
{
|
|
129 |
if (mItem) {
|
|
130 |
delete mItem;
|
|
131 |
mItem = NULL;
|
|
132 |
}
|
55
|
133 |
|
|
134 |
if (mContainer) {
|
57
|
135 |
delete mContainer;
|
|
136 |
mContainer = NULL;
|
55
|
137 |
}
|
45
|
138 |
}
|
|
139 |
|
|
140 |
/*!
|
|
141 |
Test function for constructors
|
|
142 |
1. Test if content widget is not initialized
|
|
143 |
2. Test if content widget is correcty created
|
|
144 |
*/
|
|
145 |
void TestCalenDayItem::testConstructors()
|
|
146 |
{
|
|
147 |
//1)
|
70
|
148 |
CalenDayItemTest *testItem = 0;
|
45
|
149 |
QVERIFY(!testItem);
|
|
150 |
|
|
151 |
//2)
|
70
|
152 |
testItem = new CalenDayItemTest(mContainer);
|
45
|
153 |
QVERIFY(testItem);
|
|
154 |
delete testItem;
|
|
155 |
}
|
|
156 |
|
|
157 |
/*!
|
57
|
158 |
Test function for creating new abstract items.
|
|
159 |
1. Test if item is created
|
|
160 |
2. Test if is the same as orginal.
|
45
|
161 |
*/
|
|
162 |
void TestCalenDayItem::testCreateItem()
|
70
|
163 |
{
|
|
164 |
HbAbstractViewItem *testItem = mItem->createItem();
|
|
165 |
QVERIFY(testItem);
|
|
166 |
delete testItem;
|
|
167 |
}
|
57
|
168 |
|
81
|
169 |
/*!
|
|
170 |
Test function for updating child items
|
|
171 |
1. Test if child items are updated
|
|
172 |
2. Just for coverage testing
|
|
173 |
*/
|
57
|
174 |
void TestCalenDayItem::testUpdateChildItems()
|
70
|
175 |
{
|
81
|
176 |
#ifndef __WINSCW__
|
|
177 |
//1)
|
|
178 |
mItem->mUpdated = false;
|
|
179 |
mItem->updateChildItems();
|
|
180 |
QCOMPARE(mItem->mUpdated, true);
|
|
181 |
|
|
182 |
//2)
|
|
183 |
mItem->mUpdated = true;
|
|
184 |
mItem->updateChildItems();
|
|
185 |
QCOMPARE(mItem->mUpdated, true);
|
|
186 |
#endif
|
|
187 |
}
|
70
|
188 |
|
81
|
189 |
/*!
|
|
190 |
Test setting description of entry
|
|
191 |
1. Setting description if only location is set
|
|
192 |
2. Setting description if location and summary are set
|
|
193 |
3. Setting description if location and summary are not set
|
|
194 |
4. Setting description if summary is set and event is for all day
|
|
195 |
5. Setting description if location and summary are set and event is
|
|
196 |
for all day
|
|
197 |
*/
|
|
198 |
void TestCalenDayItem::testSetDescription()
|
|
199 |
{
|
|
200 |
#ifndef __WINSCW__
|
|
201 |
AgendaEntry entry;
|
|
202 |
QString location("testLocation");
|
|
203 |
QString summary("testSummary");
|
|
204 |
|
|
205 |
//1)
|
|
206 |
entry.setLocation(location);
|
|
207 |
entry.setSummary("");
|
|
208 |
mItem->setDescription(entry, false);
|
|
209 |
QCOMPARE(mItem->mEventDesc->text(), location);
|
|
210 |
|
|
211 |
//2)
|
|
212 |
entry.setLocation(location);
|
|
213 |
entry.setSummary(summary);
|
|
214 |
mItem->setDescription(entry, false);
|
|
215 |
QString expected(summary);
|
|
216 |
expected.append(", ");
|
|
217 |
expected.append(location);
|
|
218 |
QCOMPARE(mItem->mEventDesc->text(), expected);
|
|
219 |
|
|
220 |
//3)
|
|
221 |
entry.setLocation("");
|
|
222 |
entry.setSummary("");
|
|
223 |
mItem->setDescription(entry, false);
|
|
224 |
QCOMPARE(mItem->mEventDesc->text(), hbTrId("txt_calendar_dblist_unnamed"));
|
|
225 |
|
|
226 |
//4)
|
|
227 |
entry.setLocation("");
|
|
228 |
entry.setSummary(summary);
|
|
229 |
mItem->setDescription(entry, true);
|
|
230 |
expected = "";
|
|
231 |
for (int i = 0; i < summary.count(); i++) {
|
|
232 |
expected.append(QString(summary.at(i)) + "\n");
|
|
233 |
}
|
|
234 |
QCOMPARE(mItem->mEventDesc->text(), expected);
|
|
235 |
|
|
236 |
//5)
|
|
237 |
entry.setLocation(location);
|
|
238 |
entry.setSummary(summary);
|
|
239 |
mItem->setDescription(entry, true);
|
|
240 |
QString description(summary + ", " + location);
|
|
241 |
expected = "";
|
|
242 |
for (int i = 0; i < description.count(); i++) {
|
|
243 |
expected.append(QString(description.at(i)) + "\n");
|
|
244 |
}
|
|
245 |
if (summary.count()) {
|
|
246 |
expected.remove(2 * summary.count() - 1, 1);
|
|
247 |
}
|
|
248 |
QCOMPARE(mItem->mEventDesc->text(), expected);
|
|
249 |
#endif
|
|
250 |
}
|
|
251 |
|
|
252 |
/*!
|
|
253 |
Test setting status strip
|
|
254 |
1. Setting status strip for event
|
|
255 |
2. Setting status strip for all day event
|
|
256 |
3. Setting status strip for confirmed event
|
|
257 |
4. Setting status strip for tentative event
|
|
258 |
5. Setting status strip for cancelled event
|
|
259 |
*/
|
|
260 |
void TestCalenDayItem::testSetStatusStrip()
|
|
261 |
{
|
|
262 |
#ifndef __WINSCW__
|
|
263 |
AgendaEntry entry;
|
|
264 |
QDateTime startTimeIn(QDate(12, 07, 2010), QTime(7, 0));
|
|
265 |
QDateTime endTimeIn(QDate(12, 07, 2010), QTime(10, 0));
|
|
266 |
|
|
267 |
//1)
|
|
268 |
entry.setStartAndEndTime(startTimeIn, endTimeIn);
|
|
269 |
mItem->setStatusStrip(entry, false);
|
|
270 |
|
|
271 |
QDateTime startTime;
|
|
272 |
QDateTime endTime;
|
|
273 |
QDateTime currentDateTime;
|
|
274 |
currentDateTime.setDate(mItem->container()->date());
|
|
275 |
CalenDayUtils::instance()->getEventValidStartEndTime(startTime, endTime,
|
|
276 |
entry, currentDateTime);
|
|
277 |
QPair<QTime, QTime> startEndTime = mItem->mColorStripe->startEndTime();
|
|
278 |
QCOMPARE(startEndTime.first, startTime.time());
|
|
279 |
QCOMPARE(startEndTime.second, endTime.time());
|
|
280 |
|
|
281 |
//2)
|
|
282 |
mItem->setStatusStrip(entry, true);
|
|
283 |
startEndTime = mItem->mColorStripe->startEndTime();
|
|
284 |
QCOMPARE(startEndTime.first, startTime.time());
|
|
285 |
QCOMPARE(startEndTime.second, endTime.time().addSecs(-1));
|
|
286 |
|
|
287 |
//3)
|
|
288 |
entry.setStatus(AgendaEntry::Confirmed);
|
|
289 |
mItem->setStatusStrip(entry, false);
|
|
290 |
QCOMPARE(CalenDayStatusStrip::Filled,
|
|
291 |
mItem->mColorStripe->drawingStyle());
|
|
292 |
|
|
293 |
//4)
|
|
294 |
entry.setStatus(AgendaEntry::Tentative);
|
|
295 |
mItem->setStatusStrip(entry, false);
|
|
296 |
QCOMPARE(CalenDayStatusStrip::StripWithLines,
|
|
297 |
mItem->mColorStripe->drawingStyle());
|
|
298 |
|
|
299 |
//5)
|
|
300 |
entry.setStatus(AgendaEntry::Cancelled);
|
|
301 |
mItem->setStatusStrip(entry, false);
|
|
302 |
QCOMPARE(CalenDayStatusStrip::OnlyFrame,
|
|
303 |
mItem->mColorStripe->drawingStyle());
|
|
304 |
#endif
|
70
|
305 |
}
|
57
|
306 |
|
|
307 |
void TestCalenDayItem::testHasEventDescription()
|
70
|
308 |
{
|
|
309 |
#ifndef __WINSCW__
|
|
310 |
QGraphicsSceneResizeEvent *event = new QGraphicsSceneResizeEvent();
|
|
311 |
qreal width = mItem->rect().width();
|
|
312 |
|
|
313 |
qDebug() << "inited";
|
|
314 |
|
|
315 |
mItem->mEventDescMinWidth = width - 4;
|
|
316 |
|
|
317 |
qDebug() << "before resize";
|
|
318 |
|
|
319 |
mItem->resizeEvent(event);
|
|
320 |
|
|
321 |
qDebug() << "resize called";
|
|
322 |
|
|
323 |
QVERIFY(mItem->hasEventDescription() == true);
|
|
324 |
|
|
325 |
mItem->mEventDescMinWidth = width + 8;
|
|
326 |
mItem->resizeEvent(event);
|
|
327 |
|
|
328 |
qDebug() << "resize 2 called";
|
|
329 |
|
|
330 |
QVERIFY(mItem->hasEventDescription() == false);
|
|
331 |
#endif
|
|
332 |
}
|
57
|
333 |
|
|
334 |
void TestCalenDayItem::testHasBackgroundFrame()
|
70
|
335 |
{
|
|
336 |
#ifndef __WINSCW__
|
|
337 |
QGraphicsSceneResizeEvent *event = new QGraphicsSceneResizeEvent();
|
|
338 |
qreal width = mItem->rect().width();
|
57
|
339 |
|
70
|
340 |
mItem->mFrameMinWidth = width - 4;
|
|
341 |
mItem->resizeEvent(event);
|
57
|
342 |
|
70
|
343 |
QVERIFY(mItem->hasBackgroundFrame() == true);
|
|
344 |
|
|
345 |
mItem->mFrameMinWidth = width + 8;
|
|
346 |
mItem->resizeEvent(event);
|
|
347 |
|
|
348 |
QVERIFY(mItem->hasBackgroundFrame() == false);
|
|
349 |
#endif
|
|
350 |
}
|
45
|
351 |
|
|
352 |
QTEST_MAIN(TestCalenDayItem);
|
|
353 |
#include "unittest_calendayitem.moc"
|