pimappservices/calendar/tsrc/tCal_UndatedToDo.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "caltestlib.h"
       
    17 
       
    18 #include <calentry.h>
       
    19 #include <calentryview.h>
       
    20 #include <calinstance.h>
       
    21 #include <calinstanceview.h>
       
    22 #include <caliterator.h>
       
    23 #include <calprogresscallback.h>
       
    24 #include <calrrule.h>
       
    25 #include <calsession.h>
       
    26 #include <e32test.h>
       
    27 #include <tz.h>
       
    28 
       
    29 RTest test(_L("tcal_undatedtodo"));
       
    30 
       
    31 _LIT(KCalendarFile, "tcal_undatedtodo");
       
    32 _LIT(KDateFormat, "%02d:%02d %02d/%02d/%04d\0");
       
    33 
       
    34 class CTestApp : public CBase
       
    35 	{
       
    36 public:
       
    37 	static CTestApp* NewL();
       
    38 	~CTestApp();
       
    39 	
       
    40 	void DoTestsL();
       
    41 	
       
    42 private:
       
    43 	void ConstructL();
       
    44 	
       
    45 	void TestTodoSortOrderL(const CalCommon::TCalTimeRange& aSearchRange);
       
    46 	void TestFindInstanceNonRepeatingTodoL();
       
    47 	void TestFindInstanceRepeatingTodoL();
       
    48 	void TestNextInstanceL();
       
    49 	
       
    50 	void CreateAndTestNonRptTodoL(const TTime& aStartTime, const TTime& aEndTime, const TTime& aCompletedTime, const CalCommon::TCalTimeRange& aTimeRange, TBool aExpected);
       
    51 	CCalEntry* CreateTodoLC(const TTime& aStartTime, const TTime& aEndTime, const TTime& aCompletedTime);
       
    52 
       
    53 	void CreateAndTestRptTodoL(const TTime& aStartTime, const TTime& aEndTime, const TTime& aCompletedTime, TCalRRule::TType aRepeatType, TInt aInterval, TInt aCount, const CalCommon::TCalTimeRange& aTimeRange, RArray<TTime> aExpectedLocalInstanceTimes);
       
    54 	CCalEntry* CreateRepeatingTodoLC(const TTime& aStartTime, const TTime& aEndTime, const TTime& aCompletedTime, TCalRRule::TType aRepeatType, TInt aInterval, TInt aCount);
       
    55 		
       
    56 	void PrintDetailsInstancesL(const RPointerArray<CCalInstance>& aInstanceList);
       
    57 	HBufC* TimeBufLC(const TTime& aLocalTime);
       
    58 		
       
    59 private: // member data
       
    60 	CCalTestLibrary* iTestLib;
       
    61 	
       
    62 	CCalEntryView* iEntryView;		// not owned
       
    63 	CCalInstanceView* iInstanceView;// not owned
       
    64 	
       
    65 	TTime iToday;
       
    66 	};
       
    67 
       
    68 CTestApp* CTestApp::NewL()
       
    69 	{
       
    70 	CTestApp* app = new (ELeave) CTestApp();
       
    71 	CleanupStack::PushL(app);
       
    72 	app->ConstructL();
       
    73 	CleanupStack::Pop(app);
       
    74 	return app;
       
    75 	}
       
    76 	
       
    77 CTestApp::~CTestApp()
       
    78 	{
       
    79 	delete iTestLib;
       
    80 	}
       
    81 
       
    82 void CTestApp::ConstructL()
       
    83 	{
       
    84 	iTestLib = CCalTestLibrary::NewL();
       
    85 
       
    86 	iTestLib->ReplaceFileL(KCalendarFile());
       
    87 	iTestLib->OpenFileL(KCalendarFile());
       
    88 
       
    89 	iInstanceView = &iTestLib->SynCGetInstanceViewL();
       
    90 	iEntryView = &iTestLib->SynCGetEntryViewL();
       
    91 	
       
    92 	iToday.HomeTime();
       
    93 	}
       
    94 	
       
    95 HBufC* CTestApp::TimeBufLC(const TTime& aLocalTime)
       
    96 	{
       
    97 	TBuf<17> timeBuf;
       
    98 	TDateTime localDateTime = aLocalTime.DateTime();
       
    99 	timeBuf.AppendFormat(KDateFormat,
       
   100 							localDateTime.Hour(),
       
   101 							localDateTime.Minute(),
       
   102 							localDateTime.Day() + 1, 
       
   103 							static_cast<TInt>(localDateTime.Month()) + 1, 
       
   104 							localDateTime.Year());
       
   105 							
       
   106 	return timeBuf.AllocLC();
       
   107 	}
       
   108 		
       
   109 void CTestApp::PrintDetailsInstancesL(const RPointerArray<CCalInstance>& aInstanceList)
       
   110 	{
       
   111 	const TInt KInstanceCount(aInstanceList.Count());
       
   112 	
       
   113 	if (KInstanceCount == 0)
       
   114 		{	
       
   115 		test.Printf(_L("No instances found!"));
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		test.Printf(_L("%d instances found"), KInstanceCount);
       
   120 		
       
   121 		// print the entry details
       
   122 		if (aInstanceList[0]->Entry().EndTimeL().TimeLocalL() != Time::NullTTime())
       
   123 			{
       
   124 			// get the instance and entry due dates as strings	
       
   125 			HBufC* entryEndTimeBuf = TimeBufLC(aInstanceList[0]->Entry().EndTimeL().TimeLocalL());
       
   126 			
       
   127 			// does entry have start time?
       
   128 			TCalTime entryStartTime = aInstanceList[0]->Entry().StartTimeL();
       
   129 			if (entryStartTime.TimeLocalL() == Time::NullTTime())
       
   130 				{
       
   131 				test.Printf(_L("Entry due date := %s"), entryEndTimeBuf->Ptr());
       
   132 				}
       
   133 			else
       
   134 				{
       
   135 				// get the instance and entry start times as strings
       
   136 				HBufC* entryStartTimeBuf = TimeBufLC(aInstanceList[0]->Entry().StartTimeL().TimeLocalL());
       
   137 			
       
   138 				test.Printf(_L("Entry start and due date := %s - %s"), entryStartTimeBuf->Ptr(), entryEndTimeBuf->Ptr());
       
   139 				CleanupStack::PopAndDestroy(entryStartTimeBuf);
       
   140 				}
       
   141 			
       
   142 			CleanupStack::PopAndDestroy(entryEndTimeBuf);
       
   143 			}
       
   144 		else
       
   145 			{
       
   146 			test.Printf(_L("undated entry"));
       
   147 			}
       
   148 		}
       
   149 	
       
   150 	for (TInt i(0) ; i < KInstanceCount ; ++i)
       
   151 		{	
       
   152 		if (aInstanceList[i]->Entry().EndTimeL().TimeLocalL() != Time::NullTTime())
       
   153 			{
       
   154 			// get the instance and entry due dates as strings	
       
   155 			HBufC* instanceEndTimeBuf = TimeBufLC(aInstanceList[i]->EndTimeL().TimeLocalL());
       
   156 			
       
   157 			// does entry have start time?
       
   158 			TCalTime entryStartTime = aInstanceList[i]->Entry().StartTimeL();
       
   159 			if (entryStartTime.TimeLocalL() == Time::NullTTime())
       
   160 				{
       
   161 				test.Printf(_L("Instance %d due date := %s"), i + 1, instanceEndTimeBuf->Ptr());
       
   162 				}
       
   163 			else
       
   164 				{
       
   165 				// get the instance and entry start times as strings
       
   166 				HBufC* instanceStartTimeBuf = TimeBufLC(aInstanceList[i]->StartTimeL().TimeLocalL());
       
   167 			
       
   168 				test.Printf(_L("Instance %d start and due date := %s - %s"), i + 1, instanceStartTimeBuf->Ptr(), instanceEndTimeBuf->Ptr());
       
   169 				CleanupStack::PopAndDestroy(instanceStartTimeBuf);
       
   170 				}
       
   171 			
       
   172 			CleanupStack::PopAndDestroy(instanceEndTimeBuf);
       
   173 			}
       
   174 		else
       
   175 			{
       
   176 			test.Printf(_L("undated"));
       
   177 			}
       
   178 		
       
   179 		// display the completed time if the is one
       
   180 		TTime completedTimeLocal = aInstanceList[i]->Entry().CompletedTimeL().TimeLocalL();
       
   181 		if (completedTimeLocal != Time::NullTTime())
       
   182 			{
       
   183 			HBufC* completedTimeBuf = TimeBufLC(completedTimeLocal);
       
   184 			test.Printf(_L("Completed time = %s"), completedTimeBuf->Ptr());
       
   185 			CleanupStack::PopAndDestroy(completedTimeBuf);
       
   186 			}
       
   187 		else
       
   188 			{
       
   189 			test.Printf(_L("incomplete"));
       
   190 			}
       
   191 		}
       
   192 	}
       
   193 
       
   194 CCalEntry* CTestApp::CreateTodoLC(const TTime& aStartTime, const TTime& aEndTime,  const TTime& aCompletedTime)
       
   195 	{
       
   196 	HBufC8* guid = NULL;
       
   197 	CCalEntry* entry = iTestLib->CreateCalEntryL(CCalEntry::ETodo, guid);
       
   198 	CleanupStack::PushL(entry);
       
   199 	TCalTime calStartTime;
       
   200 	calStartTime.SetTimeLocalL(aStartTime);
       
   201 	TCalTime calEndTime;
       
   202 	calEndTime.SetTimeLocalL(aEndTime);
       
   203 	entry->SetStartAndEndTimeL(calStartTime, calEndTime);
       
   204 
       
   205 	if (aCompletedTime != Time::NullTTime())
       
   206 		{
       
   207 		TCalTime calTime;
       
   208 		calTime.SetTimeLocalL(aCompletedTime);
       
   209 		entry->SetCompletedL(ETrue, calTime);
       
   210 		}
       
   211 
       
   212 	return entry;
       
   213 	}
       
   214 	
       
   215 CCalEntry* CTestApp::CreateRepeatingTodoLC(const TTime& aStartTime, const TTime& aEndTime, const TTime& aCompletedTime, TCalRRule::TType aRepeatType, TInt aInterval, TInt aCount)
       
   216 	{
       
   217 	HBufC8* guid = NULL;
       
   218 	CCalEntry* entry = iTestLib->CreateCalEntryL(CCalEntry::ETodo, guid);
       
   219 	CleanupStack::PushL(entry);
       
   220 	TCalTime calStartTime;
       
   221 	calStartTime.SetTimeLocalL(aStartTime);
       
   222 	TCalTime calEndTime;
       
   223 	calEndTime.SetTimeLocalL(aEndTime);
       
   224 	entry->SetStartAndEndTimeL(calStartTime, calEndTime);
       
   225 	
       
   226 	TCalRRule rRule(aRepeatType);
       
   227 	rRule.SetDtStart(calEndTime);
       
   228 	rRule.SetInterval(aInterval);
       
   229 	rRule.SetCount(aCount);
       
   230 	
       
   231 	switch (aRepeatType)
       
   232 		{
       
   233 		case TCalRRule::EWeekly:
       
   234 			{
       
   235 			RArray<TDay> days;
       
   236 			CleanupClosePushL(days);
       
   237 			days.AppendL(aEndTime.DayNoInWeek());
       
   238 			rRule.SetByDay(days);
       
   239 			CleanupStack::PopAndDestroy(&days);
       
   240 			}
       
   241 			break;
       
   242 		case TCalRRule::EMonthly:
       
   243 			{
       
   244 			RArray<TInt> monthDays;
       
   245 			CleanupClosePushL(monthDays);
       
   246 			monthDays.AppendL(aEndTime.DayNoInMonth());
       
   247 			rRule.SetByMonthDay(monthDays);
       
   248 			CleanupStack::PopAndDestroy(&monthDays);
       
   249 			}
       
   250 			break;
       
   251 		case TCalRRule::EYearly:
       
   252 			{
       
   253 			RArray<TMonth> months;
       
   254 			CleanupClosePushL(months);
       
   255 			months.AppendL(aEndTime.DateTime().Month());
       
   256 			rRule.SetByMonth(months);
       
   257 			CleanupStack::PopAndDestroy(&months);
       
   258 			}
       
   259 			break;
       
   260 		}
       
   261 	
       
   262 	entry->SetRRuleL(rRule);
       
   263 	
       
   264 	if (aCompletedTime != Time::NullTTime())
       
   265 		{
       
   266 		TCalTime calTime;
       
   267 		calTime.SetTimeLocalL(aCompletedTime);
       
   268 		entry->SetCompletedL(ETrue, calTime);
       
   269 		}
       
   270 		
       
   271 	return entry;
       
   272 	}
       
   273 	
       
   274 void CTestApp::TestTodoSortOrderL(const CalCommon::TCalTimeRange& aSearchRange)
       
   275 	{
       
   276 	RPointerArray<CCalEntry> entryArray;
       
   277 	CleanupClosePushL(entryArray);
       
   278 	
       
   279 	// Create 3 TODOs 2 days in the past
       
   280 	// with different priorities
       
   281 	entryArray.AppendL(CreateTodoLC(iToday - TTimeIntervalDays(2), iToday - TTimeIntervalDays(2), Time::NullTTime()));
       
   282 	entryArray[entryArray.Count() - 1]->SetPriorityL(4);
       
   283 	entryArray.AppendL(CreateTodoLC(iToday - TTimeIntervalDays(2), iToday - TTimeIntervalDays(2), Time::NullTTime()));
       
   284 	entryArray[entryArray.Count() - 1]->SetPriorityL(2);
       
   285 	entryArray.AppendL(CreateTodoLC(iToday - TTimeIntervalDays(2), iToday - TTimeIntervalDays(2), Time::NullTTime()));
       
   286 	entryArray[entryArray.Count() - 1]->SetPriorityL(3);
       
   287 	
       
   288 	// Create 3 TODOs 1 day in the past
       
   289 	// with different completed times
       
   290 	entryArray.AppendL(CreateTodoLC(iToday - TTimeIntervalDays(1), iToday - TTimeIntervalDays(1), iToday - TTimeIntervalDays(1) - TTimeIntervalMinutes(4)));
       
   291 	entryArray.AppendL(CreateTodoLC(iToday - TTimeIntervalDays(1), iToday - TTimeIntervalDays(1), iToday - TTimeIntervalDays(1) - TTimeIntervalMinutes(2)));
       
   292 	entryArray.AppendL(CreateTodoLC(iToday - TTimeIntervalDays(1), iToday - TTimeIntervalDays(1), iToday - TTimeIntervalDays(1) - TTimeIntervalMinutes(7)));
       
   293 
       
   294 	// Create 2 undated TODOs
       
   295 	entryArray.AppendL(CreateTodoLC(Time::NullTTime(), Time::NullTTime(), Time::NullTTime()));
       
   296 	entryArray.AppendL(CreateTodoLC(Time::NullTTime(), Time::NullTTime(), Time::NullTTime()));
       
   297 	// Create 2 undated TODOs
       
   298 	// with completed times
       
   299 	entryArray.AppendL(CreateTodoLC(Time::NullTTime(), Time::NullTTime(), iToday - TTimeIntervalMinutes(4)));
       
   300 	entryArray.AppendL(CreateTodoLC(Time::NullTTime(), Time::NullTTime(), iToday - TTimeIntervalMinutes(7)));
       
   301 	
       
   302 	// Create a TODO in the future
       
   303 	entryArray.AppendL(CreateTodoLC(iToday + TTimeIntervalDays(2), iToday + TTimeIntervalDays(2), Time::NullTTime()));	
       
   304 	
       
   305 	TInt success(0);
       
   306 	iEntryView->StoreL(entryArray, success);
       
   307 	test(success == entryArray.Count());
       
   308 	
       
   309 	CleanupStack::PopAndDestroy(entryArray.Count());
       
   310 	CleanupStack::PopAndDestroy(&entryArray);
       
   311 	RPointerArray<CCalInstance> instanceArray;
       
   312 	CleanupResetAndDestroyPushL(instanceArray);
       
   313 
       
   314 	iInstanceView->FindInstanceL(instanceArray, CalCommon::EIncludeAll, aSearchRange);
       
   315 	
       
   316 	test.Printf(_L("Test we found the expected number of instances!"));
       
   317 	//test(instanceArray.Count() == 11);
       
   318 
       
   319 	const TInt KInstanceCount(instanceArray.Count());
       
   320 	for (TInt i(0) ; i < KInstanceCount ; ++i)
       
   321 		{
       
   322 		TDateTime dt = instanceArray[i]->Time().TimeLocalL().DateTime();
       
   323 		test.Printf(_L("the time of instance [%d] = %d:%d %d/%d/%d: \n"), i, dt.Hour(), dt.Minute(),dt.Day() + 1, dt.Month() + 1, dt.Year());
       
   324 		}
       
   325 
       
   326 	test.Printf(_L("Test the times of the todos"));
       
   327 	test(instanceArray[0]->Time().TimeLocalL() == iToday - TTimeIntervalDays(2));
       
   328 	test(instanceArray[1]->Time().TimeLocalL() == iToday - TTimeIntervalDays(2));
       
   329 	test(instanceArray[2]->Time().TimeLocalL() == iToday - TTimeIntervalDays(2));
       
   330 		
       
   331 	// completed todos are sorted by completed time
       
   332 	test(instanceArray[3]->Time().TimeLocalL() == iToday - TTimeIntervalDays(1) - TTimeIntervalMinutes(7));
       
   333 	test(instanceArray[4]->Time().TimeLocalL() == iToday - TTimeIntervalDays(1) - TTimeIntervalMinutes(4));
       
   334 	test(instanceArray[5]->Time().TimeLocalL() == iToday - TTimeIntervalDays(1) - TTimeIntervalMinutes(2));	
       
   335 	
       
   336 	// due date should be Time::NullTTime but instance time should be set to completed time
       
   337 	test(instanceArray[6]->Entry().EndTimeL().TimeLocalL() == Time::NullTTime());
       
   338 	test(instanceArray[7]->Entry().EndTimeL().TimeLocalL() == Time::NullTTime());
       
   339 	test(instanceArray[6]->Time().TimeLocalL() == iToday - TTimeIntervalMinutes(7));
       
   340 	test(instanceArray[7]->Time().TimeLocalL() == iToday - TTimeIntervalMinutes(4));
       
   341 	
       
   342 	test(instanceArray[8]->Entry().EndTimeL().TimeLocalL() == Time::NullTTime());
       
   343 	test(instanceArray[9]->Entry().EndTimeL().TimeLocalL() == Time::NullTTime());
       
   344 	
       
   345 	test(instanceArray[10]->Time().TimeLocalL() == iToday + TTimeIntervalDays(2));
       
   346 	
       
   347 	test.Printf(_L("Test the priority of the todos"));
       
   348 	test(instanceArray[0]->Entry().PriorityL() == 2);
       
   349 	test(instanceArray[1]->Entry().PriorityL() == 3);
       
   350 	test(instanceArray[2]->Entry().PriorityL() == 4);
       
   351 
       
   352 	CleanupStack::PopAndDestroy(&instanceArray);
       
   353 	}
       
   354 	
       
   355 	
       
   356 void CTestApp::CreateAndTestNonRptTodoL(const TTime& aStartTime, const TTime& aEndTime, const TTime& aCompletedTime, const CalCommon::TCalTimeRange& aTimeRange, TBool aExpected)
       
   357 	{
       
   358 	iTestLib->CleanDatabaseL();
       
   359 	
       
   360 	// Create and store entry
       
   361 	RPointerArray<CCalEntry> entryArray;
       
   362 	CleanupResetAndDestroyPushL(entryArray);
       
   363 	CCalEntry* todo = CreateTodoLC(aStartTime, aEndTime, aCompletedTime);
       
   364 	entryArray.AppendL(todo);
       
   365 	CleanupStack::Pop(todo);
       
   366 	TInt numSuc;
       
   367 	iTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   368 	CleanupStack::PopAndDestroy(&entryArray);
       
   369 	
       
   370 	// find the todo
       
   371 	RPointerArray<CCalInstance> instanceList;
       
   372 	CleanupResetAndDestroyPushL(instanceList);
       
   373 	iTestLib->SynCGetInstanceViewL().FindInstanceL(instanceList, CalCommon::EIncludeAll, aTimeRange);
       
   374 	PrintDetailsInstancesL(instanceList);
       
   375 	
       
   376 	if (aExpected)
       
   377 		{
       
   378 		// We are expecting an instance so test it
       
   379 		test(instanceList.Count() == 1);
       
   380 		
       
   381 		// test the entry times
       
   382 		if (aEndTime != Time::NullTTime())
       
   383 			{
       
   384 			// dated
       
   385 			test(instanceList[0]->Entry().EndTimeL().TimeLocalL() == aEndTime);
       
   386 			}
       
   387 		else
       
   388 			{
       
   389 			// undated
       
   390 			test(instanceList[0]->Entry().StartTimeL().TimeLocalL() == Time::NullTTime());
       
   391 			test(instanceList[0]->Entry().EndTimeL().TimeLocalL() == Time::NullTTime());
       
   392 			}
       
   393 		
       
   394 		// test the instance times
       
   395 		if (instanceList[0]->Entry().CompletedTimeL().TimeLocalL() == Time::NullTTime())
       
   396 			{
       
   397 			// incomplete
       
   398 			if (aEndTime != Time::NullTTime())
       
   399 				{
       
   400 				// the todo is dated
       
   401 				
       
   402 				// the instance due date should always be the same as the entry due date 
       
   403 				test(instanceList[0]->EndTimeL().TimeLocalL() == aEndTime);
       
   404 				
       
   405 				if (aStartTime != Time::NullTTime())
       
   406 					{
       
   407 					// The entry has a start time so the instance should have the same start time
       
   408 					test(instanceList[0]->StartTimeL().TimeLocalL() == aStartTime);
       
   409 					}
       
   410 				else
       
   411 					{
       
   412 					// The entry was not stored with a start time
       
   413 					// so the instance start time should be the same as the due date
       
   414 					test(instanceList[0]->StartTimeL().TimeLocalL() == instanceList[0]->EndTimeL().TimeLocalL());
       
   415 					}
       
   416 				}
       
   417 			else
       
   418 				{
       
   419 				// The todo is undated
       
   420 				// so test that the start and end times are the same and that they are set as some time today
       
   421 				test(instanceList[0]->StartTimeL().TimeLocalL() == instanceList[0]->EndTimeL().TimeLocalL());
       
   422 				test(instanceList[0]->StartTimeL().TimeLocalL() != Time::NullTTime());
       
   423 				test(instanceList[0]->StartTimeL().TimeLocalL().DaysFrom(iToday).Int() == 0);
       
   424 				}
       
   425 			}
       
   426 		else
       
   427 			{
       
   428 			// complete
       
   429 			test(instanceList[0]->StartTimeL().TimeLocalL() == instanceList[0]->Entry().CompletedTimeL().TimeLocalL());
       
   430 			test(instanceList[0]->EndTimeL().TimeLocalL() == instanceList[0]->Entry().CompletedTimeL().TimeLocalL());
       
   431 			}
       
   432 		}
       
   433 	else
       
   434 		{
       
   435 		test(instanceList.Count() == 0);
       
   436 		}
       
   437 	CleanupStack::PopAndDestroy(&instanceList);
       
   438 	}
       
   439 
       
   440 void CTestApp::CreateAndTestRptTodoL(const TTime& aStartTime, const TTime& aEndTime, const TTime& aCompletedTime, TCalRRule::TType aRepeatType, TInt aInterval, TInt aCount, const CalCommon::TCalTimeRange& aTimeRange, RArray<TTime> aExpectedLocalInstanceTimes)
       
   441 	{
       
   442 	iTestLib->CleanDatabaseL();
       
   443 	
       
   444 	// Create and store repeating todo entry
       
   445 	RPointerArray<CCalEntry> entryArray;
       
   446 	CleanupResetAndDestroyPushL(entryArray);
       
   447 	CCalEntry* rptTodo = CreateRepeatingTodoLC(aStartTime, aEndTime, aCompletedTime, aRepeatType, aInterval, aCount);
       
   448 	entryArray.AppendL(rptTodo);
       
   449 	CleanupStack::Pop(rptTodo);
       
   450 	TInt numSuc;
       
   451 	iTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   452 	CleanupStack::PopAndDestroy(&entryArray);
       
   453 	
       
   454 	// find the todo
       
   455 	RPointerArray<CCalInstance> instanceList;
       
   456 	CleanupResetAndDestroyPushL(instanceList);
       
   457 	iTestLib->SynCGetInstanceViewL().FindInstanceL(instanceList, CalCommon::EIncludeAll, aTimeRange);
       
   458 	PrintDetailsInstancesL(instanceList);
       
   459 	
       
   460 	test(instanceList.Count() == aExpectedLocalInstanceTimes.Count());
       
   461 	
       
   462 	for (TInt i(0) ; i < instanceList.Count() ; ++i)
       
   463 		{
       
   464 		test(instanceList[i]->EndTimeL().TimeLocalL() == aExpectedLocalInstanceTimes[i]);
       
   465 		}
       
   466 		
       
   467 	CleanupStack::PopAndDestroy(&instanceList);
       
   468 	}
       
   469 	
       
   470 void CTestApp::TestFindInstanceNonRepeatingTodoL()
       
   471 	{
       
   472 	// set up a search range +- 10 days from now
       
   473 	TCalTime startDateTime1;
       
   474 	startDateTime1.SetTimeLocalL(iToday - TTimeIntervalDays(10));	
       
   475 	TCalTime endDateTime1;
       
   476 	endDateTime1.SetTimeLocalL(iToday + TTimeIntervalDays(10));
       
   477 	CalCommon::TCalTimeRange timeRangeWithToday(startDateTime1, endDateTime1);
       
   478 	
       
   479 	TCalTime startDateTime2;
       
   480 	startDateTime2.SetTimeLocalL(iToday + TTimeIntervalDays(1));	
       
   481 	TCalTime endDateTime2;
       
   482 	endDateTime2.SetTimeLocalL(iToday + TTimeIntervalDays(20));
       
   483 	CalCommon::TCalTimeRange timeRangeAfterToday(startDateTime2, endDateTime2);
       
   484 	
       
   485 	TCalTime startDateTime3;
       
   486 	startDateTime3.SetTimeLocalL(iToday - TTimeIntervalDays(20));	
       
   487 	TCalTime endDateTime3;
       
   488 	endDateTime3.SetTimeLocalL(iToday - TTimeIntervalDays(1));
       
   489 	CalCommon::TCalTimeRange timeRangeBeforeToday(startDateTime3, endDateTime3);
       
   490 	
       
   491 	// completed todos
       
   492 	test.Printf(_L("\n--Completed todo with completion date before the time range (due before)--"));
       
   493 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   494 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2), // due before
       
   495 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2),
       
   496 						timeRangeWithToday,
       
   497 						EFalse);
       
   498 	
       
   499 	test.Printf(_L("\n--Completed todo with completion date before the time range (due inside)--"));
       
   500 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   501 						timeRangeWithToday.StartTime().TimeLocalL() + TTimeIntervalDays(2), // due inside
       
   502 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2),
       
   503 						timeRangeWithToday,
       
   504 						EFalse);
       
   505 	
       
   506 	test.Printf(_L("\n--Completed todo with completion date before the time range (due after)--"));
       
   507 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   508 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2), // due after
       
   509 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2),
       
   510 						timeRangeWithToday,
       
   511 						EFalse);
       
   512 						
       
   513 	test.Printf(_L("\n--Completed todo with completion date after the time range (due after)--"));
       
   514 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   515 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2), // due after
       
   516 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2),
       
   517 						timeRangeWithToday,
       
   518 						EFalse);
       
   519 	
       
   520 	test.Printf(_L("\n--Completed todo with completion date after the time range (due inside)--"));
       
   521 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   522 						timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2), // due inside
       
   523 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2),
       
   524 						timeRangeWithToday,
       
   525 						EFalse);
       
   526 						
       
   527 	test.Printf(_L("\n--Completed todo with completion date after the time range (due inside)--"));
       
   528 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   529 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2), // due before
       
   530 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2),
       
   531 						timeRangeWithToday,
       
   532 						EFalse);
       
   533 						
       
   534 	test.Printf(_L("\n--Completed todo with completion date inside the time range (due before)--"));
       
   535 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   536 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2), // due before
       
   537 						timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2),
       
   538 						timeRangeWithToday,
       
   539 						ETrue);
       
   540 		
       
   541 	test.Printf(_L("\n--Completed todo with completion date inside the time range (due after)--"));				
       
   542 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   543 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2), // due after
       
   544 						timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2),
       
   545 						timeRangeWithToday,
       
   546 						ETrue);
       
   547 				
       
   548 	test.Printf(_L("\n--Completed todo with completion date inside the time range (due inside)--"));		
       
   549 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   550 						timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2), // due inside
       
   551 						timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2),
       
   552 						timeRangeWithToday,
       
   553 						ETrue);
       
   554 						
       
   555 	// incomplete todos
       
   556 	test.Printf(_L("\n--incomplete dated todo with start and due date before time range--"));
       
   557 	CreateAndTestNonRptTodoL(timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2), // before
       
   558 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2),
       
   559 						Time::NullTTime(),
       
   560 						timeRangeWithToday,
       
   561 						EFalse);
       
   562 			
       
   563 	test.Printf(_L("\n--incomplete dated todo with only due date before time range--"));			
       
   564 	CreateAndTestNonRptTodoL(Time::NullTTime(), // no start date
       
   565 						timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2), // only due date before
       
   566 						Time::NullTTime(),
       
   567 						timeRangeWithToday,
       
   568 						EFalse);
       
   569 						
       
   570 	test.Printf(_L("\n--incomplete dated todo crossing the start time of the search range--"));	
       
   571 	CreateAndTestNonRptTodoL(timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(1), 
       
   572 						timeRangeWithToday.StartTime().TimeLocalL() + TTimeIntervalDays(1), // crossing the start time
       
   573 						Time::NullTTime(),
       
   574 						timeRangeWithToday,
       
   575 						ETrue);
       
   576 						
       
   577 	test.Printf(_L("\n--incomplete dated todo with start and due date inside the search range--"));
       
   578 	CreateAndTestNonRptTodoL(timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2),
       
   579 						timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2), // totally inside
       
   580 						Time::NullTTime(),
       
   581 						timeRangeWithToday,
       
   582 						ETrue);
       
   583 						
       
   584 	test.Printf(_L("\n--incomplete dated todo with only due date inside the search range--"));	
       
   585 	CreateAndTestNonRptTodoL(Time::NullTTime(), // no start date
       
   586 						timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2), // only due date inside
       
   587 						Time::NullTTime(),
       
   588 						timeRangeWithToday,
       
   589 						ETrue);
       
   590 					
       
   591 	test.Printf(_L("\n--incomplete dated todo crossing the end of the search range--"));
       
   592 	CreateAndTestNonRptTodoL(timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(1), 
       
   593 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(1), // crossing the end of the range
       
   594 						Time::NullTTime(),
       
   595 						timeRangeWithToday,
       
   596 						ETrue);
       
   597 						
       
   598 	test.Printf(_L("\n--incomplete dated todo with start and due date after the search range--"));
       
   599 	CreateAndTestNonRptTodoL(timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2),
       
   600 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2), // totally after range
       
   601 						Time::NullTTime(),
       
   602 						timeRangeWithToday,
       
   603 						EFalse);
       
   604 	
       
   605 	test.Printf(_L("\n--incomplete dated todo with only due date after the search range--"));					
       
   606 	CreateAndTestNonRptTodoL(Time::NullTTime(), // no start date
       
   607 						timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2), // only due after
       
   608 						Time::NullTTime(),
       
   609 						timeRangeWithToday,
       
   610 						EFalse);
       
   611 	
       
   612 	// undated todos
       
   613 	test.Printf(_L("\n--undated todo (completed before search range)--"));
       
   614 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   615 								Time::NullTTime(),
       
   616 								timeRangeWithToday.StartTime().TimeLocalL() - TTimeIntervalDays(2),// before
       
   617 								timeRangeWithToday,
       
   618 								EFalse); 
       
   619 						
       
   620 	test.Printf(_L("\n--undated todo (completed inside search range)--"));
       
   621 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   622 								Time::NullTTime(),
       
   623 								timeRangeWithToday.EndTime().TimeLocalL() - TTimeIntervalDays(2), // during
       
   624 								timeRangeWithToday,
       
   625 								ETrue);
       
   626 						
       
   627 	test.Printf(_L("\n--undated todo (completed after search range)--"));
       
   628 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   629 								Time::NullTTime(),
       
   630 								timeRangeWithToday.EndTime().TimeLocalL() + TTimeIntervalDays(2), // after
       
   631 								timeRangeWithToday,
       
   632 								EFalse);
       
   633 						
       
   634 	test.Printf(_L("\n--undated todo (incomplete)--"));
       
   635 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   636 								Time::NullTTime(),
       
   637 								Time::NullTTime(), // incomplete
       
   638 								timeRangeWithToday,
       
   639 								ETrue);
       
   640 								
       
   641 	test.Printf(_L("\n----Test undated todos are not found when search range does not include today--"));
       
   642 	test.Printf(_L("\n--Search for undated todos after today--"));
       
   643 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   644 								Time::NullTTime(),
       
   645 								Time::NullTTime(), // incomplete
       
   646 								timeRangeAfterToday,
       
   647 								EFalse);
       
   648 	
       
   649 	test.Printf(_L("\n--Search for undated todos before today--"));
       
   650 	CreateAndTestNonRptTodoL(Time::NullTTime(),
       
   651 								Time::NullTTime(),
       
   652 								Time::NullTTime(), // incomplete
       
   653 								timeRangeBeforeToday,
       
   654 								EFalse);
       
   655 	
       
   656 	}
       
   657 	
       
   658 void CTestApp::TestFindInstanceRepeatingTodoL()
       
   659 	{	
       
   660 	RArray<TTime> expectedLocalInstanceTimes;
       
   661 	CleanupClosePushL(expectedLocalInstanceTimes);
       
   662 	
       
   663 	const TTime KArbitraryTime(TDateTime(2006, ENovember, 22, 11, 30, 0, 0));
       
   664 	
       
   665 // set up a search range +- 10 days from (11:30 23 November 2006)
       
   666 	TCalTime startDateTime;
       
   667 	startDateTime.SetTimeLocalL(KArbitraryTime - TTimeIntervalDays(10));	
       
   668 	TCalTime endDateTime;
       
   669 	endDateTime.SetTimeLocalL(KArbitraryTime + TTimeIntervalDays(10));
       
   670 	CalCommon::TCalTimeRange timeRange(startDateTime, endDateTime);
       
   671 	
       
   672 // Create repeating todos of all different repeat types
       
   673 	// Make sure instances of all repeat types have instances before, after, in and on the time range
       
   674 	// 1. With and without a completed date set
       
   675 	// 2. With and without a start date
       
   676 	test.Printf(_L("\n--Testing Daily Repeats--"));
       
   677 	test.Printf(_L("\n--incomplete with start date and due date set--"));
       
   678 	expectedLocalInstanceTimes.Reset();
       
   679 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(1));
       
   680 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(6));
       
   681 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(11));
       
   682 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(16));
       
   683 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(21));
       
   684 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(6), // The middle of the first instance is 5 days before
       
   685 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   686 							Time::NullTTime(), // incomplete
       
   687 							TCalRRule::EDaily,
       
   688 							5, // interval
       
   689 							8, // count
       
   690 							timeRange,
       
   691 							expectedLocalInstanceTimes);
       
   692 	
       
   693 	test.Printf(_L("\n--incomplete with only due date set--"));
       
   694 	expectedLocalInstanceTimes.Reset();
       
   695 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(1));
       
   696 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(6));
       
   697 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(11));
       
   698 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(16));
       
   699 	CreateAndTestRptTodoL(Time::NullTTime(), // without start date
       
   700 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   701 							Time::NullTTime(), // incomplete
       
   702 							TCalRRule::EDaily,
       
   703 							5,
       
   704 							7,
       
   705 							timeRange,
       
   706 							expectedLocalInstanceTimes);
       
   707 	
       
   708 	test.Printf(_L("\n--Complete with only due date set--"));
       
   709 	expectedLocalInstanceTimes.Reset();
       
   710 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(1));
       
   711 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(6));
       
   712 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(11));
       
   713 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(16));
       
   714 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(21));
       
   715 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(6),
       
   716 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   717 							timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2), // complete inside
       
   718 							TCalRRule::EDaily,
       
   719 							5,
       
   720 							7,
       
   721 							timeRange,
       
   722 							expectedLocalInstanceTimes);
       
   723 							
       
   724 	test.Printf(_L("\n--Complete with only due date set--"));
       
   725 	expectedLocalInstanceTimes.Reset();
       
   726 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(1));
       
   727 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(6));
       
   728 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(11));
       
   729 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(16));
       
   730 	CreateAndTestRptTodoL(Time::NullTTime(), // without start date
       
   731 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   732 							timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2), // complete outside
       
   733 							TCalRRule::EDaily,
       
   734 							5,
       
   735 							7,
       
   736 							timeRange,
       
   737 							expectedLocalInstanceTimes);
       
   738 							
       
   739 	test.Printf(_L("\n--Testing weekly Repeats--"));
       
   740 	test.Printf(_L("\n--Complete with only due date set--"));
       
   741 	expectedLocalInstanceTimes.Reset();
       
   742 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(3));
       
   743 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(10));
       
   744 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(17));
       
   745 	CreateAndTestRptTodoL(Time::NullTTime(), // without start date
       
   746 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   747 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(2), // complete outside
       
   748 							TCalRRule::EWeekly,
       
   749 							1,
       
   750 							7,
       
   751 							timeRange,
       
   752 							expectedLocalInstanceTimes);
       
   753 	
       
   754 	test.Printf(_L("\n--Complete with start and due date set--"));
       
   755 	expectedLocalInstanceTimes.Reset();
       
   756 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(3));
       
   757 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(10));
       
   758 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(17));
       
   759 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(24));
       
   760 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(9),
       
   761 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   762 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(2), // complete outside
       
   763 							TCalRRule::EWeekly,
       
   764 							1,
       
   765 							7,
       
   766 							timeRange,
       
   767 							expectedLocalInstanceTimes);
       
   768 	test.Printf(_L("\n--Incomplete with only due date set--"));
       
   769 	expectedLocalInstanceTimes.Reset();
       
   770 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(3));
       
   771 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(10));
       
   772 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(17));
       
   773 	CreateAndTestRptTodoL(Time::NullTTime(), // without start date
       
   774 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   775 							Time::NullTTime(), // incomplete
       
   776 							TCalRRule::EWeekly,
       
   777 							1,
       
   778 							7,
       
   779 							timeRange,
       
   780 							expectedLocalInstanceTimes);
       
   781 	
       
   782 	test.Printf(_L("\n--Incomplete with start and due date set--"));
       
   783 	expectedLocalInstanceTimes.Reset();
       
   784 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(3));
       
   785 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(10));
       
   786 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(17));
       
   787 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(24));
       
   788 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(9),
       
   789 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4),
       
   790 							Time::NullTTime(), // incomplete
       
   791 							TCalRRule::EWeekly,
       
   792 							1,
       
   793 							7,
       
   794 							timeRange,
       
   795 							expectedLocalInstanceTimes);
       
   796 							
       
   797 	test.Printf(_L("\n--Testing monthly Repeats--"));
       
   798 	test.Printf(_L("\n--Complete with start and due date set--"));
       
   799 	expectedLocalInstanceTimes.Reset();
       
   800 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2));
       
   801 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2) + TTimeIntervalMonths(1));
       
   802 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalMonths(1) - TTimeIntervalDays(20),
       
   803 							timeRange.StartTime().TimeLocalL() - TTimeIntervalMonths(1) + TTimeIntervalDays(2),
       
   804 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4), // complete before
       
   805 							TCalRRule::EMonthly,
       
   806 							1,
       
   807 							4,
       
   808 							timeRange,
       
   809 							expectedLocalInstanceTimes);
       
   810 							
       
   811 	test.Printf(_L("\n--Complete with only due date set--"));
       
   812 	expectedLocalInstanceTimes.Reset();
       
   813 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2));
       
   814 	CreateAndTestRptTodoL(Time::NullTTime(),
       
   815 							timeRange.StartTime().TimeLocalL() - TTimeIntervalMonths(1) + TTimeIntervalDays(2),
       
   816 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(4), // complete before
       
   817 							TCalRRule::EMonthly,
       
   818 							1,
       
   819 							4,
       
   820 							timeRange,
       
   821 							expectedLocalInstanceTimes);
       
   822 							
       
   823 	test.Printf(_L("\n--Incomplete with start and due date set--"));
       
   824 	expectedLocalInstanceTimes.Reset();
       
   825 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2));
       
   826 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2) + TTimeIntervalMonths(1));
       
   827 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalMonths(1) - TTimeIntervalDays(20),
       
   828 							timeRange.StartTime().TimeLocalL() - TTimeIntervalMonths(1) + TTimeIntervalDays(2),
       
   829 							Time::NullTTime(), // incomplete
       
   830 							TCalRRule::EMonthly,
       
   831 							1,
       
   832 							4,
       
   833 							timeRange,
       
   834 							expectedLocalInstanceTimes);
       
   835 	test.Printf(_L("\n--Incomplete with only due date set--"));
       
   836 	expectedLocalInstanceTimes.Reset();
       
   837 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2));
       
   838 	CreateAndTestRptTodoL(Time::NullTTime(),
       
   839 							timeRange.StartTime().TimeLocalL() - TTimeIntervalMonths(1) + TTimeIntervalDays(2),
       
   840 							Time::NullTTime(), // incomplete
       
   841 							TCalRRule::EMonthly,
       
   842 							1,
       
   843 							4,
       
   844 							timeRange,
       
   845 							expectedLocalInstanceTimes);
       
   846 							
       
   847 	test.Printf(_L("\n--Testing yearly Repeats--"));
       
   848 	test.Printf(_L("\n--Complete with only due date set--"));
       
   849 	expectedLocalInstanceTimes.Reset();
       
   850 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2));
       
   851 	CreateAndTestRptTodoL(Time::NullTTime(),
       
   852 							timeRange.StartTime().TimeLocalL() - TTimeIntervalYears(1) + TTimeIntervalDays(2),
       
   853 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(2), // complete before
       
   854 							TCalRRule::EYearly,
       
   855 							1,
       
   856 							3,
       
   857 							timeRange,
       
   858 							expectedLocalInstanceTimes);
       
   859 							
       
   860 	test.Printf(_L("\n--Complete with start and due date set (across start of range)--"));
       
   861 	expectedLocalInstanceTimes.Reset();
       
   862 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(2));
       
   863 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalYears(1) - TTimeIntervalDays(2),
       
   864 							timeRange.StartTime().TimeLocalL() - TTimeIntervalYears(1) + TTimeIntervalDays(2),
       
   865 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(2), // complete before
       
   866 							TCalRRule::EYearly,
       
   867 							1,
       
   868 							3,
       
   869 							timeRange,
       
   870 							expectedLocalInstanceTimes);
       
   871 							
       
   872 	test.Printf(_L("\n--Complete with start and due date set (inside range)--"));
       
   873 	expectedLocalInstanceTimes.Reset();
       
   874 	expectedLocalInstanceTimes.AppendL(timeRange.StartTime().TimeLocalL() + TTimeIntervalDays(4));
       
   875 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalYears(1) + TTimeIntervalDays(2),
       
   876 							timeRange.StartTime().TimeLocalL() - TTimeIntervalYears(1) + TTimeIntervalDays(4),
       
   877 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(2), // complete before
       
   878 							TCalRRule::EYearly,
       
   879 							1,
       
   880 							3,
       
   881 							timeRange,
       
   882 							expectedLocalInstanceTimes);
       
   883 							
       
   884 	test.Printf(_L("\n--Complete with start and due date set (across end of range)--"));
       
   885 	expectedLocalInstanceTimes.Reset();
       
   886 	expectedLocalInstanceTimes.AppendL(timeRange.EndTime().TimeLocalL() + TTimeIntervalDays(2));
       
   887 	CreateAndTestRptTodoL(timeRange.EndTime().TimeLocalL() - TTimeIntervalYears(1) - TTimeIntervalDays(2),
       
   888 							timeRange.EndTime().TimeLocalL() - TTimeIntervalYears(1) + TTimeIntervalDays(2),
       
   889 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(2), // complete before
       
   890 							TCalRRule::EYearly,
       
   891 							1,
       
   892 							3,
       
   893 							timeRange,
       
   894 							expectedLocalInstanceTimes);
       
   895 							
       
   896 	test.Printf(_L("\n--Complete with start and due date set (across whole range)--"));
       
   897 	expectedLocalInstanceTimes.Reset();
       
   898 	expectedLocalInstanceTimes.AppendL(timeRange.EndTime().TimeLocalL() + TTimeIntervalDays(2));
       
   899 	CreateAndTestRptTodoL(timeRange.StartTime().TimeLocalL() - TTimeIntervalYears(1) - TTimeIntervalDays(2),
       
   900 							timeRange.EndTime().TimeLocalL() - TTimeIntervalYears(1) + TTimeIntervalDays(2),
       
   901 							timeRange.StartTime().TimeLocalL() - TTimeIntervalDays(2), // complete before
       
   902 							TCalRRule::EYearly,
       
   903 							1,
       
   904 							3,
       
   905 							timeRange,
       
   906 							expectedLocalInstanceTimes);
       
   907 							
       
   908 							
       
   909 	CleanupStack::PopAndDestroy(&expectedLocalInstanceTimes);
       
   910 	}
       
   911 	
       
   912 void CTestApp::TestNextInstanceL()
       
   913 	{
       
   914 	// create TCalTime for a day after today
       
   915 	TCalTime today;
       
   916 	today.SetTimeLocalL(iToday + TTimeIntervalDays(1));
       
   917 	
       
   918 	RPointerArray<CCalEntry> entryArray;
       
   919 	CleanupResetAndDestroyPushL(entryArray);
       
   920 	
       
   921 	// create a todo that is 20 days in the future
       
   922 	CCalEntry* entry = CreateTodoLC(iToday + TTimeIntervalDays(20),
       
   923 									iToday + TTimeIntervalDays(20),
       
   924 									Time::NullTTime());
       
   925 									
       
   926 	HBufC* entryDueTimeBuf = TimeBufLC(entry->EndTimeL().TimeLocalL());			
       
   927 	test.Printf(_L("Adding an entry with due time := %s"), entryDueTimeBuf->Ptr());
       
   928 	CleanupStack::PopAndDestroy(entryDueTimeBuf);
       
   929 	
       
   930 	entryArray.AppendL(entry);
       
   931 	CleanupStack::Pop(entry);
       
   932 	TInt numSuc;
       
   933 	iTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   934 	entryArray.ResetAndDestroy();
       
   935 	
       
   936 	TCalTime nextTime = iTestLib->SynCGetInstanceViewL().NextInstanceL(CalCommon::EIncludeAll, today);
       
   937 	
       
   938 	HBufC* nextTimeBuf = TimeBufLC(nextTime.TimeLocalL());
       
   939 	test.Printf(_L("Original NextInstanceL(), from tomorrow := %s"), nextTimeBuf->Ptr());
       
   940 	CleanupStack::PopAndDestroy(nextTimeBuf);
       
   941 	
       
   942 	CCalEntry* todo = CreateTodoLC(Time::NullTTime(),
       
   943 									Time::NullTTime(),
       
   944 									Time::NullTTime());
       
   945 	
       
   946 	entryArray.AppendL(todo);
       
   947 	CleanupStack::Pop(todo);
       
   948 	iTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   949 	CleanupStack::PopAndDestroy(&entryArray);
       
   950 	
       
   951 	TCalTime nextTime2 = iTestLib->SynCGetInstanceViewL().NextInstanceL(CalCommon::EIncludeAll, today);
       
   952 	
       
   953 	HBufC* nextTime2Buf = TimeBufLC(nextTime.TimeLocalL());
       
   954 	test.Printf(_L("NextInstanceL() with undated todo added, from tomorrow := %s"), nextTime2Buf->Ptr());
       
   955 	CleanupStack::PopAndDestroy(nextTime2Buf);
       
   956 	
       
   957 	test(nextTime.TimeLocalL() == nextTime2.TimeLocalL());
       
   958 	}
       
   959 
       
   960 
       
   961 
       
   962 void CTestApp::DoTestsL()
       
   963 	{
       
   964 	// Set up time range for +- 10 days
       
   965 	TCalTime startDateTime;
       
   966 	startDateTime.SetTimeLocalL(iToday - TTimeIntervalDays(10));	
       
   967 	TCalTime endDateTime;
       
   968 	endDateTime.SetTimeLocalL(iToday + TTimeIntervalDays(10));
       
   969 	CalCommon::TCalTimeRange timeRange(startDateTime, endDateTime);
       
   970 	
       
   971 	// Set up time range for min max time
       
   972 	TCalTime minCalTime;
       
   973 	minCalTime.SetTimeUtcL(TCalTime::MinTime());
       
   974 	TCalTime maxCalTime;
       
   975 	maxCalTime.SetTimeUtcL(TCalTime::MaxTime());
       
   976 	CalCommon::TCalTimeRange timeRangeMinToMax(minCalTime, maxCalTime);
       
   977 
       
   978 
       
   979 	test.Next(_L("Test that todos are sorted in the correct order (with time range +- 10 days)"));
       
   980 
       
   981 	iTestLib->CleanDatabaseL();
       
   982 	TestTodoSortOrderL(timeRange);
       
   983 	
       
   984 	test.Next(_L("Test that todos are sorted in the correct order (with time range min at max time)"));
       
   985 
       
   986 	iTestLib->CleanDatabaseL();
       
   987 	TestTodoSortOrderL(timeRangeMinToMax);
       
   988 
       
   989 	
       
   990 	test.Next(_L("Test all types of non-repeating todos are returned correctly"));
       
   991 
       
   992 	iTestLib->CleanDatabaseL();
       
   993 	TestFindInstanceNonRepeatingTodoL();
       
   994 	
       
   995 	test.Next(_L("Test all types of repeating todos are returned correctly"));
       
   996 
       
   997 	iTestLib->CleanDatabaseL();
       
   998 	TestFindInstanceRepeatingTodoL();
       
   999 
       
  1000 	test.Next(_L("Test NextInstanceL with and without an undated todo"));
       
  1001 
       
  1002 	iTestLib->CleanDatabaseL();
       
  1003 	TestNextInstanceL();
       
  1004 	}
       
  1005 
       
  1006 static void doMainL()
       
  1007 	{
       
  1008 	CTestApp* app = CTestApp::NewL();
       
  1009 	CleanupStack::PushL(app);
       
  1010 	
       
  1011 	app->DoTestsL();
       
  1012 
       
  1013 	CleanupStack::PopAndDestroy(app);
       
  1014 	}
       
  1015 
       
  1016 /**
       
  1017 
       
  1018 @SYMTestCaseID     PIM-TCAL-UNDATEDTODO-0001
       
  1019 
       
  1020 */
       
  1021 
       
  1022 TInt E32Main()
       
  1023 	{
       
  1024 	__UHEAP_MARK;
       
  1025 	test.Start(_L("@SYMTESTCaseID:PIM-TCAL-UNDATEDTODO-0001 tCal_Instance"));
       
  1026 
       
  1027 	test.Title();
       
  1028 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
  1029 	CActiveScheduler* scheduler = new(ELeave)CActiveScheduler;
       
  1030 	CActiveScheduler::Install(scheduler);
       
  1031 	TRAPD(ret,doMainL());
       
  1032 	delete scheduler;
       
  1033 	test(ret == KErrNone);
       
  1034 	delete theCleanup;	
       
  1035 	test.End();
       
  1036 	test.Close();
       
  1037 	__UHEAP_MARKEND;
       
  1038 	return(KErrNone);
       
  1039 	}
       
  1040