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>
|
57
|
19 |
#include <QDebug>
|
45
|
20 |
|
|
21 |
|
|
22 |
#include <HbMainWindow>
|
57
|
23 |
#include "calendaycommonheaders.h"
|
|
24 |
#include "calendayutils.h"
|
|
25 |
|
|
26 |
#define private public
|
45
|
27 |
|
|
28 |
#include "calendayinfo.h"
|
|
29 |
|
|
30 |
class TestCalenDayInfo : public QObject
|
|
31 |
{
|
|
32 |
Q_OBJECT
|
|
33 |
|
|
34 |
public:
|
|
35 |
TestCalenDayInfo();
|
|
36 |
virtual ~TestCalenDayInfo();
|
|
37 |
|
|
38 |
private slots:
|
|
39 |
void initTestCase();
|
|
40 |
void cleanupTestCase();
|
|
41 |
void init();
|
|
42 |
void cleanup();
|
|
43 |
|
57
|
44 |
void testReset();
|
|
45 |
void testInsertTimedEvent();
|
|
46 |
void testInsertUntimedEvent();
|
|
47 |
void testInsertAlldayEvent();
|
|
48 |
void testSuggestedUntimedSlotPos();
|
|
49 |
void testNeededUntimedSlotCount();
|
|
50 |
void testFirstOccupiedSlot();
|
|
51 |
void testLastOccupiedSlot();
|
|
52 |
void testEarliestEndSlot();
|
|
53 |
void testLastStartSlot();
|
|
54 |
void testSlotIndexForStartTime();
|
|
55 |
void testSlotIndexForEndTime();
|
|
56 |
void testAlldayCount();
|
|
57 |
void testTodoCount();
|
81
|
58 |
void testTimeColumnContainsEvent();
|
|
59 |
void testTimeColumnAddOffset();
|
|
60 |
void testSlotIntervalAddOffset();
|
|
61 |
void testSlotIntervalOverlaps();
|
|
62 |
void testSlotIntervalUnion();
|
|
63 |
void testSlotIntervalAdjacent();
|
|
64 |
void testRegionAddOffset();
|
|
65 |
void testRegionOverlaps();
|
|
66 |
void testIsAlldayEvent_data();
|
|
67 |
void testIsAlldayEvent();
|
|
68 |
void testGetLocation();
|
|
69 |
void testGetSelectedSlot();
|
|
70 |
void testFindRegion();
|
|
71 |
void testFindEvent();
|
|
72 |
void testIsAlldayEventSelected();
|
|
73 |
void testAlldayEvent();
|
57
|
74 |
|
45
|
75 |
void testConstructors();
|
|
76 |
|
|
77 |
private:
|
|
78 |
CalenDayInfo *mInfo;
|
|
79 |
};
|
|
80 |
|
|
81 |
/*!
|
|
82 |
Constructor
|
|
83 |
*/
|
|
84 |
TestCalenDayInfo::TestCalenDayInfo() :
|
|
85 |
mInfo(NULL)
|
|
86 |
{
|
57
|
87 |
qDebug() << "test start";
|
45
|
88 |
}
|
|
89 |
|
|
90 |
/*!
|
|
91 |
Destructor
|
|
92 |
*/
|
|
93 |
TestCalenDayInfo::~TestCalenDayInfo()
|
|
94 |
{
|
57
|
95 |
|
45
|
96 |
}
|
|
97 |
|
|
98 |
/*!
|
|
99 |
Called before testcase
|
|
100 |
*/
|
|
101 |
void TestCalenDayInfo::initTestCase()
|
|
102 |
{
|
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
|
106 |
Called after testcase
|
|
107 |
*/
|
|
108 |
void TestCalenDayInfo::cleanupTestCase()
|
|
109 |
{
|
|
110 |
|
|
111 |
}
|
|
112 |
|
|
113 |
/*!
|
|
114 |
Called before every function
|
|
115 |
*/
|
|
116 |
void TestCalenDayInfo::init()
|
|
117 |
{
|
|
118 |
mInfo = new CalenDayInfo(CalenDayInfo::ETwo);
|
|
119 |
}
|
|
120 |
|
|
121 |
/*!
|
|
122 |
Called after everyfunction
|
|
123 |
*/
|
|
124 |
void TestCalenDayInfo::cleanup()
|
|
125 |
{
|
|
126 |
if (mInfo) {
|
|
127 |
delete mInfo;
|
|
128 |
mInfo = NULL;
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
57
|
132 |
void TestCalenDayInfo::testReset()
|
|
133 |
{
|
|
134 |
SCalenApptInfo info;
|
|
135 |
mInfo->InsertAlldayEvent(info);
|
|
136 |
mInfo->InsertTimedEvent(info);
|
|
137 |
|
|
138 |
mInfo->Reset();
|
|
139 |
|
|
140 |
QCOMPARE (mInfo->iAlldayEvents.length(), 0);
|
|
141 |
QCOMPARE (mInfo->iRegionList.length(), 0);
|
|
142 |
}
|
|
143 |
|
|
144 |
void TestCalenDayInfo::testInsertTimedEvent()
|
|
145 |
{
|
|
146 |
SCalenApptInfo info;
|
|
147 |
info.iStartTime = QDateTime(QDate(2010, 7, 10), QTime(23, 45, 45));
|
|
148 |
|
|
149 |
info.iEndTime = QDateTime(QDate(2010, 7, 10), QTime(23, 49, 45));
|
|
150 |
mInfo->InsertTimedEvent(info);
|
|
151 |
|
|
152 |
QCOMPARE (mInfo->iRegionList.count(), 1);
|
|
153 |
}
|
|
154 |
|
|
155 |
void TestCalenDayInfo::testInsertUntimedEvent()
|
|
156 |
{
|
|
157 |
|
|
158 |
}
|
|
159 |
|
|
160 |
void TestCalenDayInfo::testInsertAlldayEvent()
|
|
161 |
{
|
|
162 |
SCalenApptInfo info;
|
|
163 |
info.iId = TCalenInstanceId::nullInstanceId();
|
|
164 |
info.iStatus = AgendaEntry::StatusUnknown;
|
|
165 |
|
|
166 |
mInfo->InsertAlldayEvent(info);
|
|
167 |
|
|
168 |
QCOMPARE(mInfo->iAlldayEvents.length(), 1);
|
|
169 |
}
|
|
170 |
|
|
171 |
void TestCalenDayInfo::testSuggestedUntimedSlotPos()
|
|
172 |
{
|
|
173 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
174 |
//iregionlist.length = 0
|
|
175 |
mInfo->iRegionList.clear();
|
|
176 |
QCOMPARE(mInfo->SuggestedUntimedSlotPos(), 16);
|
|
177 |
|
|
178 |
//iregionlist.length <> 0
|
|
179 |
CalenTimeRegion region;
|
|
180 |
region.iStartSlot = 10;
|
|
181 |
mInfo->iRegionList.append(region);
|
|
182 |
|
|
183 |
QCOMPARE(mInfo->SuggestedUntimedSlotPos(), 10);
|
|
184 |
}
|
|
185 |
|
|
186 |
void TestCalenDayInfo::testNeededUntimedSlotCount()
|
|
187 |
{
|
|
188 |
mInfo->iUntimedEvents.append(TCalenInstanceId());
|
|
189 |
QCOMPARE(mInfo->iUntimedEvents.count(), mInfo->NeededUntimedSlotCount());
|
|
190 |
|
|
191 |
mInfo->iTodoEvents.append(TCalenInstanceId());
|
|
192 |
QCOMPARE(mInfo->iUntimedEvents.count() + 1, mInfo->NeededUntimedSlotCount());
|
|
193 |
}
|
|
194 |
|
|
195 |
void TestCalenDayInfo::testFirstOccupiedSlot()
|
|
196 |
{
|
|
197 |
mInfo->iUntimedSlotCount = 0;
|
|
198 |
QCOMPARE(mInfo->FirstOccupiedSlot(), -1);
|
|
199 |
|
|
200 |
mInfo->iUntimedSlotCount = 1;
|
|
201 |
mInfo->iFirstUntimedSlot = 8;
|
|
202 |
QCOMPARE(mInfo->FirstOccupiedSlot(), 8);
|
|
203 |
|
|
204 |
mInfo->iUntimedSlotCount = 0;
|
|
205 |
CalenTimeRegion region;
|
|
206 |
region.iStartSlot = 16;
|
|
207 |
|
|
208 |
mInfo->iRegionList.append(region);
|
|
209 |
QCOMPARE(mInfo->FirstOccupiedSlot(), 16);
|
|
210 |
}
|
|
211 |
|
|
212 |
void TestCalenDayInfo::testLastOccupiedSlot()
|
|
213 |
{
|
|
214 |
mInfo->iUntimedSlotCount = 0;
|
|
215 |
QCOMPARE(mInfo->LastOccupiedSlot(), -1);
|
|
216 |
|
|
217 |
mInfo->iUntimedSlotCount = 1;
|
|
218 |
mInfo->iFirstUntimedSlot = 8;
|
|
219 |
QCOMPARE(mInfo->LastOccupiedSlot(), 8);
|
|
220 |
|
|
221 |
CalenTimeRegion region;
|
|
222 |
region.iEndSlot = 16;
|
|
223 |
mInfo->iRegionList.append(region);
|
|
224 |
QCOMPARE(mInfo->LastOccupiedSlot(), 16);
|
|
225 |
}
|
|
226 |
|
|
227 |
void TestCalenDayInfo::testEarliestEndSlot()
|
|
228 |
{
|
|
229 |
mInfo->iUntimedSlotCount = 10;
|
|
230 |
mInfo->iEmptyUntimedSlots = 10;
|
|
231 |
mInfo->iEarliestEndSlot = 2;
|
|
232 |
|
|
233 |
QCOMPARE(mInfo->EarliestEndSlot(), -1);
|
|
234 |
|
|
235 |
CalenTimeRegion region;
|
|
236 |
region.iEndSlot = 16;
|
|
237 |
mInfo->iRegionList.append(region);
|
|
238 |
QCOMPARE(mInfo->EarliestEndSlot(), 12);
|
|
239 |
|
|
240 |
mInfo->iUntimedSlotCount = 15;
|
|
241 |
mInfo->iEmptyUntimedSlots = 10;
|
|
242 |
mInfo->iFirstUntimedSlot = 2;
|
|
243 |
|
|
244 |
QCOMPARE(mInfo->EarliestEndSlot(), 13);
|
|
245 |
}
|
|
246 |
|
|
247 |
void TestCalenDayInfo::testLastStartSlot()
|
|
248 |
{
|
|
249 |
|
|
250 |
mInfo->iUntimedSlotCount = 5;
|
|
251 |
mInfo->iEmptyUntimedSlots = 5;
|
|
252 |
QCOMPARE(mInfo->LastStartSlot(), -1);
|
|
253 |
|
|
254 |
mInfo->iUntimedSlotCount = 8;
|
|
255 |
mInfo->iEmptyUntimedSlots = 5;
|
|
256 |
mInfo->iFirstUntimedSlot = 10;
|
|
257 |
QCOMPARE(mInfo->LastStartSlot(), 17);
|
|
258 |
|
|
259 |
CalenTimeRegion region;
|
|
260 |
region.iEndSlot = 16;
|
|
261 |
mInfo->iRegionList.append(region);
|
|
262 |
mInfo->iLastStartSlot = 5;
|
|
263 |
mInfo->iUntimedSlotCount = 8;
|
|
264 |
QCOMPARE(mInfo->LastStartSlot(), 13);
|
|
265 |
}
|
|
266 |
|
|
267 |
void TestCalenDayInfo::testSlotIndexForStartTime()
|
|
268 |
{
|
|
269 |
QDateTime dt;
|
|
270 |
dt.setTime(QTime(10, 5, 0));
|
|
271 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
272 |
mInfo->iUntimedSlotCount = 0;
|
|
273 |
mInfo->SlotIndexForStartTime(dt);
|
|
274 |
|
|
275 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
276 |
|
|
277 |
qDebug() << dt.time().hour() << ":" << dt.time().minute();
|
|
278 |
|
|
279 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
280 |
mInfo->SlotIndexForStartTime(dt);
|
|
281 |
|
|
282 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 20);
|
|
283 |
|
|
284 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
285 |
mInfo->SlotIndexForStartTime(dt);
|
|
286 |
|
|
287 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 30);
|
|
288 |
|
|
289 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
290 |
mInfo->SlotIndexForStartTime(dt);
|
|
291 |
|
|
292 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 40);
|
|
293 |
//---------
|
|
294 |
|
|
295 |
dt.setTime(QTime(10, 20, 0));
|
|
296 |
|
|
297 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
298 |
mInfo->SlotIndexForStartTime(dt);
|
|
299 |
|
|
300 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
301 |
|
|
302 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
303 |
mInfo->SlotIndexForStartTime(dt);
|
|
304 |
|
|
305 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 20);
|
|
306 |
|
|
307 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
308 |
mInfo->SlotIndexForStartTime(dt);
|
|
309 |
|
|
310 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 31);
|
|
311 |
|
|
312 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
313 |
mInfo->SlotIndexForStartTime(dt);
|
|
314 |
|
|
315 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 41);
|
|
316 |
|
|
317 |
//---------
|
|
318 |
|
|
319 |
dt.setTime(QTime(10, 35, 0));
|
|
320 |
|
|
321 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
322 |
mInfo->SlotIndexForStartTime(dt);
|
|
323 |
|
|
324 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
325 |
|
|
326 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
327 |
mInfo->SlotIndexForStartTime(dt);
|
|
328 |
|
|
329 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 21);
|
|
330 |
|
|
331 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
332 |
mInfo->SlotIndexForStartTime(dt);
|
|
333 |
|
|
334 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 31);
|
|
335 |
|
|
336 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
337 |
mInfo->SlotIndexForStartTime(dt);
|
|
338 |
|
|
339 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 42);
|
|
340 |
|
|
341 |
//---------
|
|
342 |
dt.setTime(QTime(10, 45, 0));
|
|
343 |
|
|
344 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
345 |
mInfo->SlotIndexForStartTime(dt);
|
|
346 |
|
|
347 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
348 |
|
|
349 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
350 |
mInfo->SlotIndexForStartTime(dt);
|
|
351 |
|
|
352 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 21);
|
|
353 |
|
|
354 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
355 |
mInfo->SlotIndexForStartTime(dt);
|
|
356 |
|
|
357 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 32);
|
|
358 |
|
|
359 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
360 |
mInfo->SlotIndexForStartTime(dt);
|
|
361 |
|
|
362 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 43);
|
|
363 |
|
|
364 |
}
|
|
365 |
|
|
366 |
void TestCalenDayInfo::testSlotIndexForEndTime()
|
|
367 |
{
|
|
368 |
|
|
369 |
}
|
|
370 |
|
|
371 |
void TestCalenDayInfo::testAlldayCount()
|
|
372 |
{
|
|
373 |
QCOMPARE(mInfo->AlldayCount(), 0);
|
|
374 |
mInfo->iAlldayEvents.append(CalenTimedEventInfo());
|
|
375 |
QCOMPARE(mInfo->AlldayCount(), 1);
|
|
376 |
}
|
|
377 |
|
|
378 |
void TestCalenDayInfo::testTodoCount()
|
|
379 |
{
|
|
380 |
QCOMPARE(mInfo->TodoCount(), 0);
|
|
381 |
mInfo->iTodoEvents.append(TCalenInstanceId());
|
|
382 |
QCOMPARE(mInfo->TodoCount(), 1);
|
|
383 |
}
|
|
384 |
|
45
|
385 |
/*!
|
81
|
386 |
Test CalenTimeColumn::ContainsEvent() function
|
|
387 |
1. Test ContainsEvent(), no events
|
|
388 |
2. Test ContainsEvent(), events found
|
|
389 |
*/
|
|
390 |
void TestCalenDayInfo::testTimeColumnContainsEvent()
|
|
391 |
{
|
|
392 |
CalenTimeColumn column;
|
|
393 |
|
|
394 |
//1)
|
|
395 |
ulong id = 1;
|
|
396 |
QDateTime dateTime = QDateTime::currentDateTime();
|
|
397 |
bool instanceViewed = true;
|
|
398 |
TCalenInstanceId instanceId(id, dateTime, instanceViewed);
|
|
399 |
QCOMPARE(column.ContainsEvent(instanceId), false);
|
|
400 |
|
|
401 |
//2)
|
|
402 |
CalenTimedEventInfo info;
|
|
403 |
info.iStartSlot = 5;
|
|
404 |
info.iEndSlot = 10;
|
|
405 |
info.iId = instanceId;
|
|
406 |
column.AddEvent(info);
|
|
407 |
QCOMPARE(column.ContainsEvent(instanceId), true);
|
|
408 |
}
|
|
409 |
|
|
410 |
/*!
|
|
411 |
Test CalenTimeColumn::AddOffset() function
|
|
412 |
1. Test addOffset, offset = 0
|
|
413 |
2. Test addOffset, offset != 0, no events
|
|
414 |
3. Test addOffset, offset != 0, events count > 0
|
|
415 |
*/
|
|
416 |
void TestCalenDayInfo::testTimeColumnAddOffset()
|
|
417 |
{
|
|
418 |
const int start = 5;
|
|
419 |
const int end = 10;
|
|
420 |
CalenTimeColumn column;
|
|
421 |
column.iStartSlot = start;
|
|
422 |
column.iEndSlot = end;
|
|
423 |
|
|
424 |
//1)
|
|
425 |
int offset = 0;
|
|
426 |
column.AddOffset(offset, 0);
|
|
427 |
QCOMPARE(column.iStartSlot, start);
|
|
428 |
QCOMPARE(column.iEndSlot, end);
|
|
429 |
|
|
430 |
//2)
|
|
431 |
offset = 5;
|
|
432 |
column.AddOffset(offset, 0);
|
|
433 |
QCOMPARE(column.iStartSlot, start + offset);
|
|
434 |
QCOMPARE(column.iEndSlot, end + offset);
|
|
435 |
|
|
436 |
//3)
|
|
437 |
column.iStartSlot = start;
|
|
438 |
column.iEndSlot = end;
|
|
439 |
CalenTimedEventInfo eventInfo;
|
|
440 |
eventInfo.iStartSlot = start;
|
|
441 |
eventInfo.iEndSlot = end;
|
|
442 |
column.iEventArray.append(eventInfo);
|
|
443 |
column.AddOffset(offset, 0);
|
|
444 |
QCOMPARE(column.iStartSlot, start + offset);
|
|
445 |
QCOMPARE(column.iEndSlot, end + offset);
|
|
446 |
QCOMPARE(column.iEventArray.at(0).iStartSlot, start + offset);
|
|
447 |
QCOMPARE(column.iEventArray.at(0).iEndSlot, end + offset);
|
|
448 |
}
|
|
449 |
|
|
450 |
/*!
|
|
451 |
Test CalenSlotInterval::AddOffset() function
|
|
452 |
1. Test addOffset, pos < iStartSlot
|
|
453 |
2. Test addOffset, pos > iStartSlot
|
|
454 |
3. Test addOffset, pos > iEndSlot
|
|
455 |
*/
|
|
456 |
void TestCalenDayInfo::testSlotIntervalAddOffset()
|
|
457 |
{
|
|
458 |
const int start = 5;
|
|
459 |
const int end = 10;
|
|
460 |
|
|
461 |
CalenSlotInterval interval;
|
|
462 |
interval.iStartSlot = start;
|
|
463 |
interval.iEndSlot = end;
|
|
464 |
|
|
465 |
//1)
|
|
466 |
int offset = 2;
|
|
467 |
int pos = 0;
|
|
468 |
interval.AddOffset(offset, pos);
|
|
469 |
QCOMPARE(interval.iStartSlot, start + offset);
|
|
470 |
QCOMPARE(interval.iEndSlot, end + offset);
|
|
471 |
|
|
472 |
//2)
|
|
473 |
pos = 6;
|
|
474 |
interval.iStartSlot = start;
|
|
475 |
interval.iEndSlot = end;
|
|
476 |
interval.AddOffset(offset, pos);
|
|
477 |
QCOMPARE(interval.iStartSlot, start);
|
|
478 |
QCOMPARE(interval.iEndSlot, end + offset);
|
|
479 |
|
|
480 |
//3)
|
|
481 |
pos = 12;
|
|
482 |
interval.iStartSlot = start;
|
|
483 |
interval.iEndSlot = end;
|
|
484 |
interval.AddOffset(offset, pos);
|
|
485 |
QCOMPARE(interval.iStartSlot, start);
|
|
486 |
QCOMPARE(interval.iEndSlot, end);
|
|
487 |
}
|
|
488 |
|
|
489 |
/*!
|
|
490 |
Test CalenSlotInterval::Overlaps() function
|
|
491 |
1. Test non overlapping interval
|
|
492 |
2. Test overlapping interval
|
|
493 |
3. Test overlapping interval
|
|
494 |
*/
|
|
495 |
void TestCalenDayInfo::testSlotIntervalOverlaps()
|
|
496 |
{
|
|
497 |
CalenSlotInterval interval;
|
|
498 |
interval.iStartSlot = 5;
|
|
499 |
interval.iEndSlot = 10;
|
|
500 |
|
|
501 |
//1)
|
|
502 |
CalenSlotInterval testInterval;
|
|
503 |
testInterval.iStartSlot = 15;
|
|
504 |
testInterval.iEndSlot = 25;
|
|
505 |
QCOMPARE(interval.Overlaps(testInterval), false);
|
|
506 |
|
|
507 |
//2)
|
|
508 |
testInterval.iStartSlot = 1;
|
|
509 |
testInterval.iEndSlot = 8;
|
|
510 |
QCOMPARE(interval.Overlaps(testInterval), true);
|
|
511 |
|
|
512 |
//3)
|
|
513 |
testInterval.iStartSlot = 9;
|
|
514 |
testInterval.iEndSlot = 15;
|
|
515 |
QCOMPARE(interval.Overlaps(testInterval), true);
|
|
516 |
}
|
|
517 |
|
|
518 |
/*!
|
|
519 |
Test CalenSlotInterval::Union() function
|
|
520 |
1. Test Union(), empty test interval
|
|
521 |
2. TTest Union(), non empty test interval
|
|
522 |
*/
|
|
523 |
void TestCalenDayInfo::testSlotIntervalUnion()
|
|
524 |
{
|
|
525 |
const int start = 5;
|
|
526 |
const int end = 10;
|
|
527 |
|
|
528 |
CalenSlotInterval interval;
|
|
529 |
interval.iStartSlot = start;
|
|
530 |
interval.iEndSlot = end;
|
|
531 |
|
|
532 |
//1)
|
|
533 |
CalenSlotInterval testInterval;
|
|
534 |
testInterval.iStartSlot = start - 1;
|
|
535 |
testInterval.iEndSlot = start - 2;
|
|
536 |
interval.Union(testInterval);
|
|
537 |
QCOMPARE(interval.iStartSlot, start);
|
|
538 |
QCOMPARE(interval.iEndSlot, end);
|
|
539 |
|
|
540 |
//2)
|
|
541 |
testInterval.iStartSlot = start + 1;
|
|
542 |
testInterval.iEndSlot = end + 1;
|
|
543 |
interval.Union(testInterval);
|
|
544 |
QCOMPARE(interval.iStartSlot, start);
|
|
545 |
QCOMPARE(interval.iEndSlot, end + 1);
|
|
546 |
}
|
|
547 |
|
|
548 |
/*!
|
|
549 |
Test CalenSlotInterval::Adjacent() function
|
|
550 |
1. Test overlapping interval
|
|
551 |
2. Test non overlapping interval, adjacent
|
|
552 |
3. Test non overlapping interval, non adjacent
|
|
553 |
*/
|
|
554 |
void TestCalenDayInfo::testSlotIntervalAdjacent()
|
|
555 |
{
|
|
556 |
const int start = 5;
|
|
557 |
const int end = 10;
|
|
558 |
|
|
559 |
CalenSlotInterval interval;
|
|
560 |
interval.iStartSlot = start;
|
|
561 |
interval.iEndSlot = end;
|
|
562 |
|
|
563 |
//1)
|
|
564 |
CalenSlotInterval testInterval;
|
|
565 |
testInterval.iStartSlot = start + 1;
|
|
566 |
testInterval.iEndSlot = end - 1;
|
|
567 |
QCOMPARE(interval.Adjacent(testInterval), true);
|
|
568 |
|
|
569 |
//2)
|
|
570 |
testInterval.iStartSlot = start - 3;
|
|
571 |
testInterval.iEndSlot = start;
|
|
572 |
QCOMPARE(interval.Adjacent(testInterval), true);
|
|
573 |
|
|
574 |
//3)
|
|
575 |
testInterval.iStartSlot = start - 3;
|
|
576 |
testInterval.iEndSlot = start - 1;
|
|
577 |
QCOMPARE(interval.Adjacent(testInterval), false);
|
|
578 |
}
|
|
579 |
|
|
580 |
/*!
|
|
581 |
Test CalenTimeRegion::AddOffset() function
|
|
582 |
1. Test addOffset, offset = 0, intervals empty, columns empty
|
|
583 |
2. Test addOffset, offset != 0, intervals empty, columns empty
|
|
584 |
3. Test addOffset, offset != 0, intervals not empty, columns not empty
|
|
585 |
*/
|
|
586 |
void TestCalenDayInfo::testRegionAddOffset()
|
|
587 |
{
|
|
588 |
CalenTimeRegion region;
|
|
589 |
|
|
590 |
//1)
|
|
591 |
int offset = 0;
|
|
592 |
int pos = 0;
|
|
593 |
region.AddOffset(offset, pos);
|
|
594 |
QCOMPARE(region.iIntervals.count(), 0);
|
|
595 |
QCOMPARE(region.iColumns.count(), 0);
|
|
596 |
|
|
597 |
//2)
|
|
598 |
offset = 2;
|
|
599 |
region.AddOffset(offset, pos);
|
|
600 |
QCOMPARE(region.iIntervals.count(), 0);
|
|
601 |
QCOMPARE(region.iColumns.count(), 0);
|
|
602 |
|
|
603 |
//3)
|
|
604 |
CalenEventInterval interval;
|
|
605 |
interval.iStartSlot = 1;
|
|
606 |
interval.iEndSlot = 5;
|
|
607 |
region.iIntervals.append(interval);
|
|
608 |
|
|
609 |
CalenTimeColumn column;
|
|
610 |
column.iStartSlot = 2;
|
|
611 |
column.iEndSlot = 4;
|
|
612 |
region.iColumns.append(column);
|
|
613 |
|
|
614 |
region.AddOffset(offset, pos);
|
|
615 |
|
|
616 |
QCOMPARE(region.iIntervals.at(0).iStartSlot, interval.iStartSlot + offset);
|
|
617 |
QCOMPARE(region.iIntervals.at(0).iEndSlot, interval.iEndSlot + offset);
|
|
618 |
|
|
619 |
QCOMPARE(region.iColumns.at(0).iStartSlot, column.iStartSlot + offset);
|
|
620 |
QCOMPARE(region.iColumns.at(0).iEndSlot, column.iEndSlot + offset);
|
|
621 |
}
|
|
622 |
|
|
623 |
/*!
|
|
624 |
Test CalenTimeRegion::Overlaps() function
|
|
625 |
1. Test non overlapping
|
|
626 |
2. Test overlapping
|
|
627 |
*/
|
|
628 |
void TestCalenDayInfo::testRegionOverlaps()
|
|
629 |
{
|
|
630 |
CalenTimeRegion region;
|
|
631 |
region.iStartSlot = 5;
|
|
632 |
region.iEndSlot = 10;
|
|
633 |
|
|
634 |
CalenTimeColumn column;
|
|
635 |
region.iColumns.append(column);
|
|
636 |
|
|
637 |
//1)
|
|
638 |
CalenSlotInterval testInterval;
|
|
639 |
testInterval.iStartSlot = 15;
|
|
640 |
testInterval.iEndSlot = 20;
|
|
641 |
QCOMPARE(region.Overlaps(testInterval), false);
|
|
642 |
|
|
643 |
//2)
|
|
644 |
testInterval.iStartSlot = 4;
|
|
645 |
testInterval.iEndSlot = 12;
|
|
646 |
QCOMPARE(region.Overlaps(testInterval), true);
|
|
647 |
}
|
|
648 |
|
|
649 |
/*!
|
45
|
650 |
Test function for constructors
|
|
651 |
1. Test if CalenDayInfo is not initialized
|
|
652 |
2. Test if CalenDayInfo is correcty created
|
|
653 |
*/
|
|
654 |
void TestCalenDayInfo::testConstructors()
|
|
655 |
{
|
|
656 |
//1)
|
|
657 |
CalenDayInfo *testCalenDayInfo = 0;
|
|
658 |
QVERIFY(!testCalenDayInfo);
|
|
659 |
|
|
660 |
//2)
|
|
661 |
testCalenDayInfo = new CalenDayInfo(CalenDayInfo::ETwo);
|
|
662 |
QVERIFY(testCalenDayInfo);
|
|
663 |
}
|
|
664 |
|
81
|
665 |
/*!
|
|
666 |
Test data for testIsAlldayEvent
|
|
667 |
Data:
|
|
668 |
1. Test if false is return when days are diferent
|
|
669 |
Below days are the same
|
|
670 |
2. Test when start and end time are not midnight
|
|
671 |
3. Test when start is midnight and end not
|
|
672 |
4. Test when start is not midnight and end is
|
|
673 |
5. Test when start and end are midnight
|
|
674 |
*/
|
|
675 |
void TestCalenDayInfo::testIsAlldayEvent_data()
|
|
676 |
{
|
|
677 |
QTest::addColumn<QDateTime>("testedValueStart");
|
|
678 |
QTest::addColumn<QDateTime>("testedValueEnd");
|
|
679 |
QTest::addColumn<bool>("testValue");
|
|
680 |
|
|
681 |
QTest::newRow("Diferent days")
|
|
682 |
<< QDateTime(QDate(2010,9,14),QTime(12,20))
|
|
683 |
<< QDateTime(QDate(2010,9,15),QTime(12,20))
|
|
684 |
<< false;
|
|
685 |
QTest::newRow("Diferent times, not midnight")
|
|
686 |
<< QDateTime(QDate(2010,9,14),QTime(12,20))
|
|
687 |
<< QDateTime(QDate(2010,9,14),QTime(16,40))
|
|
688 |
<< false;
|
|
689 |
QTest::newRow("Diferent times, start is mignight")
|
|
690 |
<< QDateTime(QDate(2010,9,14),QTime(0,0))
|
|
691 |
<< QDateTime(QDate(2010,9,14),QTime(12,20))
|
|
692 |
<< false;
|
|
693 |
QTest::newRow("Diferent times, end is mignight")
|
|
694 |
<< QDateTime(QDate(2010,9,14),QTime(12,20))
|
|
695 |
<< QDateTime(QDate(2010,9,14),QTime(0,0))
|
|
696 |
<< false;
|
|
697 |
QTest::newRow("Both are midnight")
|
|
698 |
<< QDateTime(QDate(2010,9,14),QTime(0,0,0,0))
|
|
699 |
<< QDateTime(QDate(2010,9,15),QTime(0,0,0,0))
|
|
700 |
<< true;
|
|
701 |
}
|
|
702 |
|
|
703 |
/*!
|
|
704 |
Test function for IsAllDayEvent, it use data from testIsAlldayEvent_data
|
|
705 |
|
|
706 |
*/
|
|
707 |
void TestCalenDayInfo::testIsAlldayEvent()
|
|
708 |
{
|
|
709 |
//get data to test
|
|
710 |
QFETCH(QDateTime, testedValueStart);
|
|
711 |
QFETCH(QDateTime, testedValueEnd);
|
|
712 |
QFETCH(bool, testValue);
|
|
713 |
|
|
714 |
//make test
|
|
715 |
QCOMPARE(mInfo->IsAlldayEvent(testedValueStart,testedValueEnd),testValue);
|
|
716 |
|
|
717 |
}
|
|
718 |
|
|
719 |
void TestCalenDayInfo::testGetLocation()
|
|
720 |
{
|
|
721 |
|
|
722 |
}
|
|
723 |
|
|
724 |
/*!
|
|
725 |
Test function for getSelectedSlot
|
|
726 |
1)Check when there is no region is selected
|
|
727 |
2)Check when region is selected
|
|
728 |
*/
|
|
729 |
void TestCalenDayInfo::testGetSelectedSlot()
|
|
730 |
{
|
|
731 |
int slot = 0;
|
|
732 |
int region = 0;
|
|
733 |
int columnIndex = 0;
|
|
734 |
int columns = 0;
|
|
735 |
//1)
|
|
736 |
mInfo->iSelectedRegion = -1;
|
|
737 |
mInfo->GetSelectedSlot(slot,region,columnIndex,columns);
|
|
738 |
QCOMPARE(slot , mInfo->iSelectedSlot);
|
|
739 |
QCOMPARE(region, KErrNotFound);
|
|
740 |
QCOMPARE(columnIndex, mInfo->iSelectedColumn);
|
|
741 |
QCOMPARE(columns, 0);
|
|
742 |
|
|
743 |
//2)
|
|
744 |
CalenTimeRegion timeRegion = CalenTimeRegion();
|
|
745 |
timeRegion.iColumns << CalenTimeColumn();
|
|
746 |
mInfo->iRegionList.append(CalenTimeRegion());
|
|
747 |
mInfo->iRegionList.append(CalenTimeRegion());
|
|
748 |
|
|
749 |
mInfo->iSelectedRegion = 1;
|
|
750 |
mInfo->GetSelectedSlot(slot,region,columnIndex,columns);
|
|
751 |
QCOMPARE(slot , mInfo->iSelectedSlot);
|
|
752 |
QCOMPARE(region, mInfo->iSelectedRegion);
|
|
753 |
QCOMPARE(columnIndex, mInfo->iSelectedColumn);
|
|
754 |
QCOMPARE(columns, 0);
|
|
755 |
}
|
|
756 |
|
|
757 |
/*!
|
|
758 |
Test function for FindRegion.
|
|
759 |
1)Preapre region in day infor
|
|
760 |
2)Prepare region inside above
|
|
761 |
3)Find this inside region
|
|
762 |
*/
|
|
763 |
void TestCalenDayInfo::testFindRegion()
|
|
764 |
{
|
|
765 |
#ifndef __WINSCW__
|
|
766 |
//1)
|
|
767 |
CalenTimeRegion region;
|
|
768 |
region.iStartSlot = 1;
|
|
769 |
region.iEndSlot = 16;
|
|
770 |
region.iColumns << CalenTimeColumn();
|
|
771 |
mInfo->iRegionList.append(region);
|
|
772 |
|
|
773 |
//2)
|
|
774 |
CalenSlotInterval interval;
|
|
775 |
interval.iStartSlot = 8;
|
|
776 |
interval.iEndSlot = 12;
|
|
777 |
|
|
778 |
//3)
|
|
779 |
QVERIFY(mInfo->FindRegion(interval,1) == 0);
|
|
780 |
#endif /*__WINSCW__*/
|
|
781 |
}
|
|
782 |
|
|
783 |
/*!
|
|
784 |
Test function for FindEvent
|
|
785 |
1)Prepare events and select one to test
|
|
786 |
2)Find selected event
|
|
787 |
*/
|
|
788 |
void TestCalenDayInfo::testFindEvent()
|
|
789 |
{
|
|
790 |
#ifndef __WINSCW__
|
|
791 |
//1)
|
|
792 |
CalenTimedEventInfo event;
|
|
793 |
event.iStartSlot = 3;
|
|
794 |
event.iEndSlot = 13;
|
|
795 |
|
|
796 |
CalenTimeColumn column = CalenTimeColumn();
|
|
797 |
column.AddEvent(event);
|
|
798 |
|
|
799 |
CalenTimeRegion region;
|
|
800 |
region.iStartSlot = 1;
|
|
801 |
region.iEndSlot = 16;
|
|
802 |
region.iColumns << column;
|
|
803 |
mInfo->iRegionList.append(region);
|
|
804 |
|
|
805 |
|
|
806 |
region.iStartSlot = 17;
|
|
807 |
region.iEndSlot = 20;
|
|
808 |
mInfo->iRegionList.append(region);
|
|
809 |
|
|
810 |
//preapre data to search
|
|
811 |
CalenSlotInterval interval;
|
|
812 |
interval.iStartSlot = 8;
|
|
813 |
interval.iEndSlot = 12;
|
|
814 |
|
|
815 |
mInfo->iSelectedRegion = 0;
|
|
816 |
mInfo->iSelectedColumn = 0;
|
|
817 |
|
|
818 |
//2)
|
|
819 |
QVERIFY(mInfo->FindEvent(interval,1) == 0);
|
|
820 |
#endif /*__WINSCW__*/
|
|
821 |
}
|
|
822 |
|
|
823 |
/*!
|
|
824 |
Test function for IsAlldayEventSelected
|
|
825 |
1)There is no all day event selected
|
|
826 |
2)There is all day event selected
|
|
827 |
*/
|
|
828 |
void TestCalenDayInfo::testIsAlldayEventSelected()
|
|
829 |
{
|
|
830 |
//1)
|
|
831 |
QVERIFY(mInfo->IsAlldayEventSelected() == false);
|
|
832 |
|
|
833 |
//2)
|
|
834 |
mInfo->iSelectedAlldayEvent = 0;
|
|
835 |
mInfo->iAlldayEvents.append(CalenTimedEventInfo());
|
|
836 |
|
|
837 |
QVERIFY(mInfo->IsAlldayEventSelected() == true);
|
|
838 |
}
|
|
839 |
|
|
840 |
/*!
|
|
841 |
Test function for AlldayEvent
|
|
842 |
1)Prepare all day event at inxdex 0
|
|
843 |
2)Check if good all day event is returned
|
|
844 |
*/
|
|
845 |
void TestCalenDayInfo::testAlldayEvent()
|
|
846 |
{
|
|
847 |
CalenTimedEventInfo allDayEvent;
|
|
848 |
TCalenInstanceId id;
|
|
849 |
id = TCalenInstanceId::create(100, QDateTime(QDate(2010,9,21), QTime(12,12,12)),false);
|
|
850 |
allDayEvent.iId = id;
|
|
851 |
mInfo->iAlldayEvents.append(allDayEvent);
|
|
852 |
|
|
853 |
QVERIFY(mInfo->AlldayEvent(0).iId == id);
|
|
854 |
}
|
45
|
855 |
|
|
856 |
QTEST_MAIN(TestCalenDayInfo);
|
|
857 |
|
|
858 |
#include "unittest_calendayinfo.moc"
|