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();
|
|
58 |
|
45
|
59 |
void testConstructors();
|
|
60 |
|
|
61 |
private:
|
|
62 |
CalenDayInfo *mInfo;
|
|
63 |
};
|
|
64 |
|
|
65 |
/*!
|
|
66 |
Constructor
|
|
67 |
*/
|
|
68 |
TestCalenDayInfo::TestCalenDayInfo() :
|
|
69 |
mInfo(NULL)
|
|
70 |
{
|
57
|
71 |
qDebug() << "test start";
|
45
|
72 |
}
|
|
73 |
|
|
74 |
/*!
|
|
75 |
Destructor
|
|
76 |
*/
|
|
77 |
TestCalenDayInfo::~TestCalenDayInfo()
|
|
78 |
{
|
57
|
79 |
|
45
|
80 |
}
|
|
81 |
|
|
82 |
/*!
|
|
83 |
Called before testcase
|
|
84 |
*/
|
|
85 |
void TestCalenDayInfo::initTestCase()
|
|
86 |
{
|
|
87 |
}
|
|
88 |
|
|
89 |
/*!
|
|
90 |
Called after testcase
|
|
91 |
*/
|
|
92 |
void TestCalenDayInfo::cleanupTestCase()
|
|
93 |
{
|
|
94 |
|
|
95 |
}
|
|
96 |
|
|
97 |
/*!
|
|
98 |
Called before every function
|
|
99 |
*/
|
|
100 |
void TestCalenDayInfo::init()
|
|
101 |
{
|
|
102 |
mInfo = new CalenDayInfo(CalenDayInfo::ETwo);
|
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
|
106 |
Called after everyfunction
|
|
107 |
*/
|
|
108 |
void TestCalenDayInfo::cleanup()
|
|
109 |
{
|
|
110 |
if (mInfo) {
|
|
111 |
delete mInfo;
|
|
112 |
mInfo = NULL;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
57
|
116 |
void TestCalenDayInfo::testReset()
|
|
117 |
{
|
|
118 |
SCalenApptInfo info;
|
|
119 |
mInfo->InsertAlldayEvent(info);
|
|
120 |
mInfo->InsertTimedEvent(info);
|
|
121 |
|
|
122 |
mInfo->Reset();
|
|
123 |
|
|
124 |
QCOMPARE (mInfo->iAlldayEvents.length(), 0);
|
|
125 |
QCOMPARE (mInfo->iRegionList.length(), 0);
|
|
126 |
}
|
|
127 |
|
|
128 |
void TestCalenDayInfo::testInsertTimedEvent()
|
|
129 |
{
|
|
130 |
SCalenApptInfo info;
|
|
131 |
info.iStartTime = QDateTime(QDate(2010, 7, 10), QTime(23, 45, 45));
|
|
132 |
|
|
133 |
info.iEndTime = QDateTime(QDate(2010, 7, 10), QTime(23, 49, 45));
|
|
134 |
mInfo->InsertTimedEvent(info);
|
|
135 |
|
|
136 |
QCOMPARE (mInfo->iRegionList.count(), 1);
|
|
137 |
}
|
|
138 |
|
|
139 |
void TestCalenDayInfo::testInsertUntimedEvent()
|
|
140 |
{
|
|
141 |
|
|
142 |
}
|
|
143 |
|
|
144 |
void TestCalenDayInfo::testInsertAlldayEvent()
|
|
145 |
{
|
|
146 |
SCalenApptInfo info;
|
|
147 |
info.iId = TCalenInstanceId::nullInstanceId();
|
|
148 |
info.iStatus = AgendaEntry::StatusUnknown;
|
|
149 |
|
|
150 |
mInfo->InsertAlldayEvent(info);
|
|
151 |
|
|
152 |
QCOMPARE(mInfo->iAlldayEvents.length(), 1);
|
|
153 |
}
|
|
154 |
|
|
155 |
void TestCalenDayInfo::testSuggestedUntimedSlotPos()
|
|
156 |
{
|
|
157 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
158 |
//iregionlist.length = 0
|
|
159 |
mInfo->iRegionList.clear();
|
|
160 |
QCOMPARE(mInfo->SuggestedUntimedSlotPos(), 16);
|
|
161 |
|
|
162 |
//iregionlist.length <> 0
|
|
163 |
CalenTimeRegion region;
|
|
164 |
region.iStartSlot = 10;
|
|
165 |
mInfo->iRegionList.append(region);
|
|
166 |
|
|
167 |
QCOMPARE(mInfo->SuggestedUntimedSlotPos(), 10);
|
|
168 |
}
|
|
169 |
|
|
170 |
void TestCalenDayInfo::testNeededUntimedSlotCount()
|
|
171 |
{
|
|
172 |
mInfo->iUntimedEvents.append(TCalenInstanceId());
|
|
173 |
QCOMPARE(mInfo->iUntimedEvents.count(), mInfo->NeededUntimedSlotCount());
|
|
174 |
|
|
175 |
mInfo->iTodoEvents.append(TCalenInstanceId());
|
|
176 |
QCOMPARE(mInfo->iUntimedEvents.count() + 1, mInfo->NeededUntimedSlotCount());
|
|
177 |
}
|
|
178 |
|
|
179 |
void TestCalenDayInfo::testFirstOccupiedSlot()
|
|
180 |
{
|
|
181 |
mInfo->iUntimedSlotCount = 0;
|
|
182 |
QCOMPARE(mInfo->FirstOccupiedSlot(), -1);
|
|
183 |
|
|
184 |
mInfo->iUntimedSlotCount = 1;
|
|
185 |
mInfo->iFirstUntimedSlot = 8;
|
|
186 |
QCOMPARE(mInfo->FirstOccupiedSlot(), 8);
|
|
187 |
|
|
188 |
mInfo->iUntimedSlotCount = 0;
|
|
189 |
CalenTimeRegion region;
|
|
190 |
region.iStartSlot = 16;
|
|
191 |
|
|
192 |
mInfo->iRegionList.append(region);
|
|
193 |
QCOMPARE(mInfo->FirstOccupiedSlot(), 16);
|
|
194 |
}
|
|
195 |
|
|
196 |
void TestCalenDayInfo::testLastOccupiedSlot()
|
|
197 |
{
|
|
198 |
mInfo->iUntimedSlotCount = 0;
|
|
199 |
QCOMPARE(mInfo->LastOccupiedSlot(), -1);
|
|
200 |
|
|
201 |
mInfo->iUntimedSlotCount = 1;
|
|
202 |
mInfo->iFirstUntimedSlot = 8;
|
|
203 |
QCOMPARE(mInfo->LastOccupiedSlot(), 8);
|
|
204 |
|
|
205 |
CalenTimeRegion region;
|
|
206 |
region.iEndSlot = 16;
|
|
207 |
mInfo->iRegionList.append(region);
|
|
208 |
QCOMPARE(mInfo->LastOccupiedSlot(), 16);
|
|
209 |
}
|
|
210 |
|
|
211 |
void TestCalenDayInfo::testEarliestEndSlot()
|
|
212 |
{
|
|
213 |
mInfo->iUntimedSlotCount = 10;
|
|
214 |
mInfo->iEmptyUntimedSlots = 10;
|
|
215 |
mInfo->iEarliestEndSlot = 2;
|
|
216 |
|
|
217 |
QCOMPARE(mInfo->EarliestEndSlot(), -1);
|
|
218 |
|
|
219 |
CalenTimeRegion region;
|
|
220 |
region.iEndSlot = 16;
|
|
221 |
mInfo->iRegionList.append(region);
|
|
222 |
QCOMPARE(mInfo->EarliestEndSlot(), 12);
|
|
223 |
|
|
224 |
mInfo->iUntimedSlotCount = 15;
|
|
225 |
mInfo->iEmptyUntimedSlots = 10;
|
|
226 |
mInfo->iFirstUntimedSlot = 2;
|
|
227 |
|
|
228 |
QCOMPARE(mInfo->EarliestEndSlot(), 13);
|
|
229 |
}
|
|
230 |
|
|
231 |
void TestCalenDayInfo::testLastStartSlot()
|
|
232 |
{
|
|
233 |
|
|
234 |
mInfo->iUntimedSlotCount = 5;
|
|
235 |
mInfo->iEmptyUntimedSlots = 5;
|
|
236 |
QCOMPARE(mInfo->LastStartSlot(), -1);
|
|
237 |
|
|
238 |
mInfo->iUntimedSlotCount = 8;
|
|
239 |
mInfo->iEmptyUntimedSlots = 5;
|
|
240 |
mInfo->iFirstUntimedSlot = 10;
|
|
241 |
QCOMPARE(mInfo->LastStartSlot(), 17);
|
|
242 |
|
|
243 |
CalenTimeRegion region;
|
|
244 |
region.iEndSlot = 16;
|
|
245 |
mInfo->iRegionList.append(region);
|
|
246 |
mInfo->iLastStartSlot = 5;
|
|
247 |
mInfo->iUntimedSlotCount = 8;
|
|
248 |
QCOMPARE(mInfo->LastStartSlot(), 13);
|
|
249 |
}
|
|
250 |
|
|
251 |
void TestCalenDayInfo::testSlotIndexForStartTime()
|
|
252 |
{
|
|
253 |
QDateTime dt;
|
|
254 |
dt.setTime(QTime(10, 5, 0));
|
|
255 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
256 |
mInfo->iUntimedSlotCount = 0;
|
|
257 |
mInfo->SlotIndexForStartTime(dt);
|
|
258 |
|
|
259 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
260 |
|
|
261 |
qDebug() << dt.time().hour() << ":" << dt.time().minute();
|
|
262 |
|
|
263 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
264 |
mInfo->SlotIndexForStartTime(dt);
|
|
265 |
|
|
266 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 20);
|
|
267 |
|
|
268 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
269 |
mInfo->SlotIndexForStartTime(dt);
|
|
270 |
|
|
271 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 30);
|
|
272 |
|
|
273 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
274 |
mInfo->SlotIndexForStartTime(dt);
|
|
275 |
|
|
276 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 40);
|
|
277 |
//---------
|
|
278 |
|
|
279 |
dt.setTime(QTime(10, 20, 0));
|
|
280 |
|
|
281 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
282 |
mInfo->SlotIndexForStartTime(dt);
|
|
283 |
|
|
284 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
285 |
|
|
286 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
287 |
mInfo->SlotIndexForStartTime(dt);
|
|
288 |
|
|
289 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 20);
|
|
290 |
|
|
291 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
292 |
mInfo->SlotIndexForStartTime(dt);
|
|
293 |
|
|
294 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 31);
|
|
295 |
|
|
296 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
297 |
mInfo->SlotIndexForStartTime(dt);
|
|
298 |
|
|
299 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 41);
|
|
300 |
|
|
301 |
//---------
|
|
302 |
|
|
303 |
dt.setTime(QTime(10, 35, 0));
|
|
304 |
|
|
305 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
306 |
mInfo->SlotIndexForStartTime(dt);
|
|
307 |
|
|
308 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
309 |
|
|
310 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
311 |
mInfo->SlotIndexForStartTime(dt);
|
|
312 |
|
|
313 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 21);
|
|
314 |
|
|
315 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
316 |
mInfo->SlotIndexForStartTime(dt);
|
|
317 |
|
|
318 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 31);
|
|
319 |
|
|
320 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
321 |
mInfo->SlotIndexForStartTime(dt);
|
|
322 |
|
|
323 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 42);
|
|
324 |
|
|
325 |
//---------
|
|
326 |
dt.setTime(QTime(10, 45, 0));
|
|
327 |
|
|
328 |
mInfo->iSlotsInHour = CalenDayInfo::EOne;
|
|
329 |
mInfo->SlotIndexForStartTime(dt);
|
|
330 |
|
|
331 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
|
|
332 |
|
|
333 |
mInfo->iSlotsInHour = CalenDayInfo::ETwo;
|
|
334 |
mInfo->SlotIndexForStartTime(dt);
|
|
335 |
|
|
336 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 21);
|
|
337 |
|
|
338 |
mInfo->iSlotsInHour = CalenDayInfo::EThree;
|
|
339 |
mInfo->SlotIndexForStartTime(dt);
|
|
340 |
|
|
341 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 32);
|
|
342 |
|
|
343 |
mInfo->iSlotsInHour = CalenDayInfo::EFour;
|
|
344 |
mInfo->SlotIndexForStartTime(dt);
|
|
345 |
|
|
346 |
QCOMPARE(mInfo->SlotIndexForStartTime(dt), 43);
|
|
347 |
|
|
348 |
}
|
|
349 |
|
|
350 |
void TestCalenDayInfo::testSlotIndexForEndTime()
|
|
351 |
{
|
|
352 |
|
|
353 |
}
|
|
354 |
|
|
355 |
void TestCalenDayInfo::testAlldayCount()
|
|
356 |
{
|
|
357 |
QCOMPARE(mInfo->AlldayCount(), 0);
|
|
358 |
mInfo->iAlldayEvents.append(CalenTimedEventInfo());
|
|
359 |
QCOMPARE(mInfo->AlldayCount(), 1);
|
|
360 |
}
|
|
361 |
|
|
362 |
void TestCalenDayInfo::testTodoCount()
|
|
363 |
{
|
|
364 |
QCOMPARE(mInfo->TodoCount(), 0);
|
|
365 |
mInfo->iTodoEvents.append(TCalenInstanceId());
|
|
366 |
QCOMPARE(mInfo->TodoCount(), 1);
|
|
367 |
}
|
|
368 |
|
45
|
369 |
/*!
|
|
370 |
Test function for constructors
|
|
371 |
1. Test if CalenDayInfo is not initialized
|
|
372 |
2. Test if CalenDayInfo is correcty created
|
|
373 |
*/
|
|
374 |
void TestCalenDayInfo::testConstructors()
|
|
375 |
{
|
|
376 |
//1)
|
|
377 |
CalenDayInfo *testCalenDayInfo = 0;
|
|
378 |
QVERIFY(!testCalenDayInfo);
|
|
379 |
|
|
380 |
//2)
|
|
381 |
testCalenDayInfo = new CalenDayInfo(CalenDayInfo::ETwo);
|
|
382 |
QVERIFY(testCalenDayInfo);
|
|
383 |
}
|
|
384 |
|
|
385 |
|
|
386 |
QTEST_MAIN(TestCalenDayInfo);
|
|
387 |
|
|
388 |
#include "unittest_calendayinfo.moc"
|