calendarui/views/dayview/tsrc/unittests/unittest_calendayinfo/unittest_calendayinfo.cpp
changeset 57 bb2d3e476f29
parent 45 b6db4fd4947b
child 81 ce92091cbd61
equal deleted inserted replaced
55:2c54b51f39c4 57:bb2d3e476f29
    14  * Description: Test class for CalenDayContentWidget
    14  * Description: Test class for CalenDayContentWidget
    15  *
    15  *
    16  */
    16  */
    17 #include <QGraphicsItem>
    17 #include <QGraphicsItem>
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
       
    19 #include <QDebug>
    19 
    20 
    20 
    21 
    21 #include <HbMainWindow>
    22 #include <HbMainWindow>
       
    23 #include "calendaycommonheaders.h"
       
    24 #include "calendayutils.h"
       
    25 
       
    26 #define private public
    22 
    27 
    23 #include "calendayinfo.h"
    28 #include "calendayinfo.h"
    24 #include "calendaycommonheaders.h"
       
    25 
    29 
    26 class TestCalenDayInfo : public QObject
    30 class TestCalenDayInfo : public QObject
    27 {
    31 {
    28 Q_OBJECT
    32 Q_OBJECT
    29 
    33 
    35     void initTestCase();
    39     void initTestCase();
    36     void cleanupTestCase();
    40     void cleanupTestCase();
    37     void init();
    41     void init();
    38     void cleanup();
    42     void cleanup();
    39 
    43 
       
    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     
    40     void testConstructors();
    59     void testConstructors();
    41 
    60 
    42 private:
    61 private:
    43     CalenDayInfo *mInfo;
    62     CalenDayInfo *mInfo;
    44 };
    63 };
    47  Constructor
    66  Constructor
    48  */
    67  */
    49 TestCalenDayInfo::TestCalenDayInfo() :
    68 TestCalenDayInfo::TestCalenDayInfo() :
    50    mInfo(NULL)
    69    mInfo(NULL)
    51 {
    70 {
    52 
    71 	qDebug() << "test start";
    53 }
    72 }
    54 
    73 
    55 /*!
    74 /*!
    56  Destructor
    75  Destructor
    57  */
    76  */
    58 TestCalenDayInfo::~TestCalenDayInfo()
    77 TestCalenDayInfo::~TestCalenDayInfo()
    59 {
    78 {
    60 
    79 	
    61 }
    80 }
    62 
    81 
    63 /*!
    82 /*!
    64  Called before testcase
    83  Called before testcase
    65  */
    84  */
    91     if (mInfo) {
   110     if (mInfo) {
    92         delete mInfo;
   111         delete mInfo;
    93         mInfo = NULL;
   112         mInfo = NULL;
    94     }
   113     }
    95 }
   114 }
       
   115 
       
   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 	}
    96 
   368 
    97 /*!
   369 /*!
    98  Test function for constructors
   370  Test function for constructors
    99  1. Test if CalenDayInfo is not initialized
   371  1. Test if CalenDayInfo is not initialized
   100  2. Test if CalenDayInfo is correcty created
   372  2. Test if CalenDayInfo is correcty created