--- a/calendarui/views/dayview/tsrc/unittests/unittest_calendayinfo/unittest_calendayinfo.cpp Mon Jul 26 13:54:38 2010 +0530
+++ b/calendarui/views/dayview/tsrc/unittests/unittest_calendayinfo/unittest_calendayinfo.cpp Mon Aug 09 18:30:52 2010 +0530
@@ -16,12 +16,16 @@
*/
#include <QGraphicsItem>
#include <QtTest/QtTest>
+#include <QDebug>
#include <HbMainWindow>
+#include "calendaycommonheaders.h"
+#include "calendayutils.h"
+
+#define private public
#include "calendayinfo.h"
-#include "calendaycommonheaders.h"
class TestCalenDayInfo : public QObject
{
@@ -37,6 +41,21 @@
void init();
void cleanup();
+ void testReset();
+ void testInsertTimedEvent();
+ void testInsertUntimedEvent();
+ void testInsertAlldayEvent();
+ void testSuggestedUntimedSlotPos();
+ void testNeededUntimedSlotCount();
+ void testFirstOccupiedSlot();
+ void testLastOccupiedSlot();
+ void testEarliestEndSlot();
+ void testLastStartSlot();
+ void testSlotIndexForStartTime();
+ void testSlotIndexForEndTime();
+ void testAlldayCount();
+ void testTodoCount();
+
void testConstructors();
private:
@@ -49,7 +68,7 @@
TestCalenDayInfo::TestCalenDayInfo() :
mInfo(NULL)
{
-
+ qDebug() << "test start";
}
/*!
@@ -57,7 +76,7 @@
*/
TestCalenDayInfo::~TestCalenDayInfo()
{
-
+
}
/*!
@@ -94,6 +113,259 @@
}
}
+void TestCalenDayInfo::testReset()
+ {
+ SCalenApptInfo info;
+ mInfo->InsertAlldayEvent(info);
+ mInfo->InsertTimedEvent(info);
+
+ mInfo->Reset();
+
+ QCOMPARE (mInfo->iAlldayEvents.length(), 0);
+ QCOMPARE (mInfo->iRegionList.length(), 0);
+ }
+
+void TestCalenDayInfo::testInsertTimedEvent()
+ {
+ SCalenApptInfo info;
+ info.iStartTime = QDateTime(QDate(2010, 7, 10), QTime(23, 45, 45));
+
+ info.iEndTime = QDateTime(QDate(2010, 7, 10), QTime(23, 49, 45));
+ mInfo->InsertTimedEvent(info);
+
+ QCOMPARE (mInfo->iRegionList.count(), 1);
+ }
+
+void TestCalenDayInfo::testInsertUntimedEvent()
+ {
+
+ }
+
+void TestCalenDayInfo::testInsertAlldayEvent()
+ {
+ SCalenApptInfo info;
+ info.iId = TCalenInstanceId::nullInstanceId();
+ info.iStatus = AgendaEntry::StatusUnknown;
+
+ mInfo->InsertAlldayEvent(info);
+
+ QCOMPARE(mInfo->iAlldayEvents.length(), 1);
+ }
+
+void TestCalenDayInfo::testSuggestedUntimedSlotPos()
+ {
+ mInfo->iSlotsInHour = CalenDayInfo::ETwo;
+ //iregionlist.length = 0
+ mInfo->iRegionList.clear();
+ QCOMPARE(mInfo->SuggestedUntimedSlotPos(), 16);
+
+ //iregionlist.length <> 0
+ CalenTimeRegion region;
+ region.iStartSlot = 10;
+ mInfo->iRegionList.append(region);
+
+ QCOMPARE(mInfo->SuggestedUntimedSlotPos(), 10);
+ }
+
+void TestCalenDayInfo::testNeededUntimedSlotCount()
+ {
+ mInfo->iUntimedEvents.append(TCalenInstanceId());
+ QCOMPARE(mInfo->iUntimedEvents.count(), mInfo->NeededUntimedSlotCount());
+
+ mInfo->iTodoEvents.append(TCalenInstanceId());
+ QCOMPARE(mInfo->iUntimedEvents.count() + 1, mInfo->NeededUntimedSlotCount());
+ }
+
+void TestCalenDayInfo::testFirstOccupiedSlot()
+ {
+ mInfo->iUntimedSlotCount = 0;
+ QCOMPARE(mInfo->FirstOccupiedSlot(), -1);
+
+ mInfo->iUntimedSlotCount = 1;
+ mInfo->iFirstUntimedSlot = 8;
+ QCOMPARE(mInfo->FirstOccupiedSlot(), 8);
+
+ mInfo->iUntimedSlotCount = 0;
+ CalenTimeRegion region;
+ region.iStartSlot = 16;
+
+ mInfo->iRegionList.append(region);
+ QCOMPARE(mInfo->FirstOccupiedSlot(), 16);
+ }
+
+void TestCalenDayInfo::testLastOccupiedSlot()
+ {
+ mInfo->iUntimedSlotCount = 0;
+ QCOMPARE(mInfo->LastOccupiedSlot(), -1);
+
+ mInfo->iUntimedSlotCount = 1;
+ mInfo->iFirstUntimedSlot = 8;
+ QCOMPARE(mInfo->LastOccupiedSlot(), 8);
+
+ CalenTimeRegion region;
+ region.iEndSlot = 16;
+ mInfo->iRegionList.append(region);
+ QCOMPARE(mInfo->LastOccupiedSlot(), 16);
+ }
+
+void TestCalenDayInfo::testEarliestEndSlot()
+ {
+ mInfo->iUntimedSlotCount = 10;
+ mInfo->iEmptyUntimedSlots = 10;
+ mInfo->iEarliestEndSlot = 2;
+
+ QCOMPARE(mInfo->EarliestEndSlot(), -1);
+
+ CalenTimeRegion region;
+ region.iEndSlot = 16;
+ mInfo->iRegionList.append(region);
+ QCOMPARE(mInfo->EarliestEndSlot(), 12);
+
+ mInfo->iUntimedSlotCount = 15;
+ mInfo->iEmptyUntimedSlots = 10;
+ mInfo->iFirstUntimedSlot = 2;
+
+ QCOMPARE(mInfo->EarliestEndSlot(), 13);
+ }
+
+void TestCalenDayInfo::testLastStartSlot()
+ {
+
+ mInfo->iUntimedSlotCount = 5;
+ mInfo->iEmptyUntimedSlots = 5;
+ QCOMPARE(mInfo->LastStartSlot(), -1);
+
+ mInfo->iUntimedSlotCount = 8;
+ mInfo->iEmptyUntimedSlots = 5;
+ mInfo->iFirstUntimedSlot = 10;
+ QCOMPARE(mInfo->LastStartSlot(), 17);
+
+ CalenTimeRegion region;
+ region.iEndSlot = 16;
+ mInfo->iRegionList.append(region);
+ mInfo->iLastStartSlot = 5;
+ mInfo->iUntimedSlotCount = 8;
+ QCOMPARE(mInfo->LastStartSlot(), 13);
+ }
+
+void TestCalenDayInfo::testSlotIndexForStartTime()
+ {
+ QDateTime dt;
+ dt.setTime(QTime(10, 5, 0));
+ mInfo->iSlotsInHour = CalenDayInfo::EOne;
+ mInfo->iUntimedSlotCount = 0;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
+
+ qDebug() << dt.time().hour() << ":" << dt.time().minute();
+
+ mInfo->iSlotsInHour = CalenDayInfo::ETwo;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 20);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EThree;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 30);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EFour;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 40);
+ //---------
+
+ dt.setTime(QTime(10, 20, 0));
+
+ mInfo->iSlotsInHour = CalenDayInfo::EOne;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
+
+ mInfo->iSlotsInHour = CalenDayInfo::ETwo;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 20);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EThree;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 31);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EFour;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 41);
+
+ //---------
+
+ dt.setTime(QTime(10, 35, 0));
+
+ mInfo->iSlotsInHour = CalenDayInfo::EOne;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
+
+ mInfo->iSlotsInHour = CalenDayInfo::ETwo;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 21);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EThree;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 31);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EFour;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 42);
+
+ //---------
+ dt.setTime(QTime(10, 45, 0));
+
+ mInfo->iSlotsInHour = CalenDayInfo::EOne;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 10);
+
+ mInfo->iSlotsInHour = CalenDayInfo::ETwo;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 21);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EThree;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 32);
+
+ mInfo->iSlotsInHour = CalenDayInfo::EFour;
+ mInfo->SlotIndexForStartTime(dt);
+
+ QCOMPARE(mInfo->SlotIndexForStartTime(dt), 43);
+
+ }
+
+void TestCalenDayInfo::testSlotIndexForEndTime()
+ {
+
+ }
+
+void TestCalenDayInfo::testAlldayCount()
+ {
+ QCOMPARE(mInfo->AlldayCount(), 0);
+ mInfo->iAlldayEvents.append(CalenTimedEventInfo());
+ QCOMPARE(mInfo->AlldayCount(), 1);
+ }
+
+void TestCalenDayInfo::testTodoCount()
+ {
+ QCOMPARE(mInfo->TodoCount(), 0);
+ mInfo->iTodoEvents.append(TCalenInstanceId());
+ QCOMPARE(mInfo->TodoCount(), 1);
+ }
+
/*!
Test function for constructors
1. Test if CalenDayInfo is not initialized