20 #include <HbWidget> |
20 #include <HbWidget> |
21 #include <HbAbstractViewItem> |
21 #include <HbAbstractViewItem> |
22 |
22 |
23 #include "calendayinfo.h" |
23 #include "calendayinfo.h" |
24 #include "calendaymodel.h" |
24 #include "calendaymodel.h" |
25 #include "calendayitem.h" |
25 #include "calendayeventspane.h" |
26 |
26 |
27 #define private public |
27 #define private public |
28 |
28 |
29 #include "calendaycontainertest.h" |
29 #include "calendaycontainertest.h" |
30 |
30 |
32 QDateTime MOCK_EVENTS_DATE; |
32 QDateTime MOCK_EVENTS_DATE; |
33 |
33 |
34 // Test variables |
34 // Test variables |
35 QRectF gTestWindowRect = QRectF(0, 0, 10, 20); |
35 QRectF gTestWindowRect = QRectF(0, 0, 10, 20); |
36 Qt::Orientation gTestOrientation = Qt::Vertical; |
36 Qt::Orientation gTestOrientation = Qt::Vertical; |
|
37 QSizeF gTestContainerSize = QSizeF(100, 500); |
37 |
38 |
38 class TestCalenDayContainer : public QObject |
39 class TestCalenDayContainer : public QObject |
39 { |
40 { |
40 Q_OBJECT |
41 Q_OBJECT |
41 |
42 |
55 void testItemAdded(); |
56 void testItemAdded(); |
56 void testItemRemoved(); |
57 void testItemRemoved(); |
57 void testReset(); |
58 void testReset(); |
58 void testViewResized(); |
59 void testViewResized(); |
59 void testOrientationChanged(); |
60 void testOrientationChanged(); |
|
61 void testupdateFloatingItemsList(); |
60 void testCreateDefaultPrototype(); |
62 void testCreateDefaultPrototype(); |
61 void testGetTimedEventLayoutValues(); |
63 void testGetTimedEventLayoutValues(); |
62 void testCreateTouchEventAbsorbers(); |
64 void testCreateTouchEventAbsorbers(); |
63 void testCrateAbsorberBetweenSlots(); |
65 void testCrateAbsorberBetweenSlots(); |
|
66 void testDateTimeAtPos(); |
64 |
67 |
65 |
68 |
66 private: |
69 private: |
67 CalenDayContainerTest *mContainer; |
70 CalenDayContainerTest *mContainer; |
68 CalenDayInfo *mInfo; |
71 CalenDayInfo *mInfo; |
247 //2) |
250 //2) |
248 QCOMPARE(mContainer->size(),newSize); |
251 QCOMPARE(mContainer->size(),newSize); |
249 } |
252 } |
250 |
253 |
251 /*! |
254 /*! |
252 It test change of orientation based on count of absorbers |
255 It tests change of orientation based on count of absorbers |
253 */ |
256 */ |
254 void TestCalenDayContainer::testOrientationChanged() |
257 void TestCalenDayContainer::testOrientationChanged() |
255 { |
258 { |
256 mContainer->setDayInfo(mInfo); |
259 mContainer->setDayInfo(mInfo); |
257 QVERIFY(mContainer->mAbsorbers.count() == 0); |
260 QVERIFY(mContainer->mAbsorbers.count() == 0); |
258 |
261 |
259 mContainer->orientationChanged(Qt::Vertical); |
262 mContainer->orientationChanged(Qt::Vertical); |
260 |
263 |
261 QVERIFY(mContainer->mAbsorbers.count() != 0); |
264 QVERIFY(mContainer->mAbsorbers.count() != 0); |
|
265 } |
|
266 |
|
267 /*! |
|
268 Test function that maintains floating items list |
|
269 1) Null pointer check |
|
270 2) Floating item notification received |
|
271 3) The same floating item notification received |
|
272 4) Static item notification received |
|
273 */ |
|
274 void TestCalenDayContainer::testupdateFloatingItemsList() |
|
275 { |
|
276 |
|
277 CalenDayItemViewTest *itemView = new CalenDayItemViewTest(mContainer, new HbModelIterator()); |
|
278 //CalenDayContainer *container = itemView->mContainer; |
|
279 const int floatingItemsCount = mContainer->mFloatingItemsList.count(); |
|
280 const int connectedSlotsCount = itemView->connectedSlots(SIGNAL(scrollPositionChanged(const QPointF&))); |
|
281 |
|
282 // 1) Test null pointer |
|
283 mContainer->updateFloatingItemsList(0); |
|
284 //Nothing happend, list remains unchanged |
|
285 QCOMPARE(mContainer->mFloatingItemsList.count(), floatingItemsCount); |
|
286 QCOMPARE(itemView->connectedSlots(SIGNAL(scrollPositionChanged(const QPointF&))), connectedSlotsCount); |
|
287 |
|
288 // 2) Floating item notification received |
|
289 CalenDayItemTest *item = new CalenDayItemTest(mContainer); |
|
290 item->mBackgroundType = CalenDayItem::EFloatingBackground; |
|
291 mContainer->updateFloatingItemsList(item); |
|
292 QCOMPARE(mContainer->mFloatingItemsList.count(), floatingItemsCount + 1); |
|
293 QCOMPARE(itemView->connectedSlots(SIGNAL(scrollPositionChanged(const QPointF&))), connectedSlotsCount + 1); |
|
294 |
|
295 // 3) The same floating item notification received |
|
296 mContainer->updateFloatingItemsList(item); |
|
297 QCOMPARE(mContainer->mFloatingItemsList.count(), floatingItemsCount + 1); |
|
298 QCOMPARE(itemView->connectedSlots(SIGNAL(scrollPositionChanged(const QPointF&))), connectedSlotsCount + 1); |
|
299 |
|
300 // 4) Static item notification received |
|
301 item->mBackgroundType = CalenDayItem::EStaticBackground; |
|
302 mContainer->updateFloatingItemsList(item); |
|
303 QCOMPARE(mContainer->mFloatingItemsList.count(), floatingItemsCount); |
|
304 QCOMPARE(itemView->connectedSlots(SIGNAL(scrollPositionChanged(const QPointF&))), connectedSlotsCount); |
262 } |
305 } |
263 |
306 |
264 /*! |
307 /*! |
265 Test creating item prototype |
308 Test creating item prototype |
266 */ |
309 */ |
321 testValue = mContainer->crateAbsorberBetweenSlots(0,1,false); |
364 testValue = mContainer->crateAbsorberBetweenSlots(0,1,false); |
322 QVERIFY(testValue); |
365 QVERIFY(testValue); |
323 delete testValue; |
366 delete testValue; |
324 } |
367 } |
325 |
368 |
|
369 /*! |
|
370 Test dateTimeAtPos |
|
371 1. Position outside control |
|
372 2. Position in control, first half of hour (0-30 min) |
|
373 3. Position in control, second half of hour (30-60 min) |
|
374 */ |
|
375 void TestCalenDayContainer::testDateTimeAtPos() |
|
376 { |
|
377 mContainer->setDate(QDate(2010, 10, 1)); |
|
378 mContainer->viewResized(gTestContainerSize); |
|
379 |
|
380 QRectF geometry = mContainer->mEventsPaneElements.at(0)->geometry(); |
|
381 qreal halfHour = geometry.height() / 2; |
|
382 |
|
383 //1) |
|
384 QPointF point(50, geometry.top() - 10); |
|
385 QDateTime dateTime = mContainer->dateTimeAtPos(point); |
|
386 QVERIFY(!dateTime.isValid()); |
|
387 |
|
388 //2) |
|
389 point = QPointF(50, geometry.top() + halfHour - 1); |
|
390 dateTime = mContainer->dateTimeAtPos(point); |
|
391 QVERIFY(dateTime.isValid()); |
|
392 QCOMPARE(dateTime.time(), QTime(0, 0)); |
|
393 |
|
394 //3) |
|
395 point = QPointF(50, geometry.top() + halfHour + 1); |
|
396 dateTime = mContainer->dateTimeAtPos(point); |
|
397 QVERIFY(dateTime.isValid()); |
|
398 QCOMPARE(dateTime.time(), QTime(0, 30)); |
|
399 } |
|
400 |
326 |
401 |
327 QTEST_MAIN(TestCalenDayContainer); |
402 QTEST_MAIN(TestCalenDayContainer); |
328 #include "unittest_calendaycontainer.moc" |
403 #include "unittest_calendaycontainer.moc" |