pimappservices/calendar/tsrc/tcal_datasync.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 #include <caldataformat.h>
       
    18 #include <s32file.h>
       
    19 #include <e32test.h>
       
    20 #include <calentry.h>
       
    21 #include <calentryview.h>
       
    22 #include <calsession.h>
       
    23 #include <calrrule.h>
       
    24 #include <tz.h>
       
    25 #include <caldataexchange.h>
       
    26 
       
    27 RTest test(_L("tcal_datasync"));
       
    28 _LIT(KCalendarFile1,"c:tcal_datasync1");
       
    29 _LIT(KCalendarFile2,"c:tcal_datasync2");
       
    30 
       
    31 
       
    32 const TInt KNumOfEntriesToTest = 500;
       
    33 
       
    34 
       
    35 class CDataSyncTestManager : public CBase
       
    36 	{
       
    37 public:
       
    38     static CDataSyncTestManager* NewLC();
       
    39     ~CDataSyncTestManager();
       
    40 	
       
    41 	// Test Methods
       
    42 	void TestConsistentLocalIdL();
       
    43 	void TestFileIdL();
       
    44 	void TestGetIdsModifiedSinceDateL();
       
    45 	void TestSyncDuringDeleteL();
       
    46 	void TestGetIdsModifiedOnCurrentTimeL();
       
    47 	void TestDeleteParentAndChildEntriesL();
       
    48 	
       
    49 private:
       
    50 	void ConstructL();
       
    51 	
       
    52 	void CreateEntriesL(RPointerArray<CCalEntry>& aCalEntryArray, TInt aNumOfEntries);
       
    53 
       
    54 
       
    55 private:
       
    56 	CCalTestLibrary* iTestLibrary;
       
    57 	
       
    58 	};
       
    59 
       
    60 
       
    61 CDataSyncTestManager* CDataSyncTestManager::NewLC()
       
    62 	{
       
    63 	CDataSyncTestManager* self = new(ELeave) CDataSyncTestManager;
       
    64 	
       
    65 	CleanupStack::PushL(self);
       
    66 	self->ConstructL();
       
    67 
       
    68 	return (self);
       
    69 	}
       
    70 
       
    71 
       
    72 void CDataSyncTestManager::ConstructL()
       
    73 	{
       
    74 	iTestLibrary = CCalTestLibrary::NewL();
       
    75 	iTestLibrary->ReplaceFileL(KCalendarFile1);
       
    76 	iTestLibrary->OpenFileL(KCalendarFile1);	
       
    77 	}
       
    78 
       
    79 
       
    80 CDataSyncTestManager::~CDataSyncTestManager()	
       
    81 	{
       
    82 	TRAP_IGNORE(iTestLibrary->DeleteFileL(KCalendarFile1));
       
    83 	TRAP_IGNORE(iTestLibrary->DeleteFileL(KCalendarFile2));
       
    84 	delete iTestLibrary;
       
    85 	}
       
    86 
       
    87 
       
    88 void CDataSyncTestManager::CreateEntriesL(RPointerArray<CCalEntry>& aCalEntryArray, TInt aNumOfEntries)
       
    89 	{
       
    90 	TCalTime dummyTime;
       
    91 	dummyTime.SetTimeLocalL(TDateTime(2006, EJanuary, 0, 0, 0, 0, 0));
       
    92 	for (TInt i(0) ; i < aNumOfEntries ; ++i)
       
    93 		{
       
    94 		HBufC8* uid = HBufC8::NewLC(255);
       
    95 		TPtr8 ptr = uid->Des();
       
    96 		iTestLibrary->RandomText8(ptr);
       
    97 		//create and append the entry
       
    98 		CCalEntry* calEntry = iTestLibrary->CreateCalEntryL(CCalEntry::EEvent, uid);
       
    99 		CleanupStack::Pop(uid);
       
   100 		CleanupStack::PushL(calEntry);
       
   101 		calEntry->SetStartAndEndTimeL(dummyTime, dummyTime);
       
   102 		aCalEntryArray.AppendL(calEntry);
       
   103 		CleanupStack::Pop(calEntry);
       
   104 		}
       
   105 	}
       
   106 
       
   107 
       
   108 
       
   109 void CDataSyncTestManager::TestGetIdsModifiedSinceDateL()
       
   110 	{
       
   111 	test.Next(_L("Test TestGetIdsModifiedSinceDateL"));
       
   112 
       
   113 	// test we don't get back unmodified entries and deleted entries
       
   114 	
       
   115 	RPointerArray<CCalEntry> calEntryArray;
       
   116 	CleanupResetAndDestroyPushL(calEntryArray);
       
   117 	RArray<TCalLocalUid> calLocalIds;
       
   118 	CleanupClosePushL(calLocalIds);
       
   119 	RArray<TCalLocalUid> calLocalIdsToDelete;
       
   120 	CleanupClosePushL(calLocalIdsToDelete);
       
   121 	
       
   122 	TInt entriesModified(0);
       
   123 	TInt deletedEntries(0);
       
   124 	
       
   125 	// create some entries
       
   126 	CreateEntriesL(calEntryArray, KNumOfEntriesToTest);
       
   127 	TInt numCompleted(0);
       
   128 	test.Printf(_L("Total number of entries created and stored = %d\n"), calEntryArray.Count());
       
   129 	iTestLibrary->SynCGetEntryViewL().StoreL(calEntryArray, numCompleted);
       
   130 	test(calEntryArray.Count() == numCompleted);
       
   131 	
       
   132 	calEntryArray.ResetAndDestroy();
       
   133 	
       
   134 	
       
   135 	TCalTime calTime2000;
       
   136 	calTime2000.SetTimeLocalL(TTime(_L("20000101:120000.000000")));
       
   137 	
       
   138 	iTestLibrary->SynCGetEntryViewL().GetIdsModifiedSinceDateL(calTime2000, calLocalIds);
       
   139 	test(calLocalIds.Count()==KNumOfEntriesToTest);
       
   140 
       
   141 	// update a third of the entries 
       
   142 	const TInt KThirdEntries = KNumOfEntriesToTest / 3;
       
   143 	test.Printf(_L("number of entries modified = %d\n"), KThirdEntries);
       
   144 	for (TInt i(0) ; i < KThirdEntries ; ++i)
       
   145 		{
       
   146 		CCalEntry* calEntryFetched = iTestLibrary->SynCGetEntryViewL().FetchL(calLocalIds[i]);
       
   147 		calEntryFetched->SetLastModifiedDateL();
       
   148 		calEntryArray.AppendL(calEntryFetched);
       
   149 		++entriesModified;
       
   150 		}
       
   151 
       
   152 	// record the time
       
   153 	TCalTime calTime;
       
   154 	TTime time;
       
   155 	time.HomeTime();
       
   156 	calTime.SetTimeLocalL(time);
       
   157 
       
   158 	iTestLibrary->SynCGetEntryViewL().UpdateL(calEntryArray, numCompleted);	
       
   159 	
       
   160 	// delete half of those
       
   161 	const TInt KHalfUpdatedEntries = KThirdEntries / 2;
       
   162 	test.Printf(_L("number of modified entries that we have deleted = %d\n"), KHalfUpdatedEntries);
       
   163 	for (TInt i(0) ; i < KHalfUpdatedEntries ; ++i)
       
   164 		{
       
   165 		calLocalIdsToDelete.AppendL(calLocalIds[i]);
       
   166 		++deletedEntries;
       
   167 		}
       
   168 		
       
   169 	// delete the entries by local id entry	
       
   170 	TInt numEntries(0);
       
   171 	iTestLibrary->SynCGetEntryViewL().DeleteL(calLocalIdsToDelete, numEntries);
       
   172 	
       
   173 	test(numEntries == calLocalIdsToDelete.Count());
       
   174 	
       
   175 	calLocalIds.Reset();
       
   176 	// There should be five modified since the date
       
   177 	iTestLibrary->SynCGetEntryViewL().GetIdsModifiedSinceDateL(calTime, calLocalIds);
       
   178 	test.Printf(_L("number of returned entries from GetIdsModifiedSinceDateL = %d\n"), calLocalIds.Count());
       
   179 	test( calLocalIds.Count() == (entriesModified - deletedEntries) );
       
   180 	
       
   181 	iTestLibrary->CleanDatabaseL();
       
   182 	
       
   183 	CleanupStack::PopAndDestroy(&calLocalIdsToDelete);
       
   184 	CleanupStack::PopAndDestroy(&calLocalIds);
       
   185 	CleanupStack::PopAndDestroy(&calEntryArray);
       
   186 	}
       
   187 	
       
   188 	
       
   189 
       
   190 void CDataSyncTestManager::TestGetIdsModifiedOnCurrentTimeL()
       
   191 	{
       
   192 	test.Next(_L("Test TestGetIdsModifiedSinceDate1L"));
       
   193 
       
   194 	_LIT8(KEntry,	"BEGIN:VCALENDAR\r\n"
       
   195 					"VERSION:1.0\r\n"
       
   196 					"BEGIN:VEVENT\r\n"
       
   197 					"UID:1\r\n"
       
   198  			   		"X-EPOCAGENDAENTRYTYPE:TODO\r\n"
       
   199 					"DTSTART:20050415:133000.000000\r\n"
       
   200 					"DTEND:20050415:143000.000000\r\n"
       
   201 					"SUMMARY:hi there\r\n"
       
   202 					"END:VEVENT\r\n"
       
   203 					"BEGIN:VEVENT\r\n"
       
   204 					"UID:2\r\n"
       
   205  			   		"X-EPOCAGENDAENTRYTYPE:TODO\r\n"
       
   206 					"DTSTART:20050415:133000.000000\r\n"
       
   207 					"DTEND:20050415:143000.000000\r\n"
       
   208 					"SUMMARY:hi there\r\n"
       
   209 					"END:VEVENT\r\n"
       
   210 					"BEGIN:VEVENT\r\n"
       
   211 					"UID:3\r\n"
       
   212  			   		"X-EPOCAGENDAENTRYTYPE:TODO\r\n"
       
   213 					"DTSTART:20050415:133000.000000\r\n"
       
   214 					"DTEND:20050415:143000.000000\r\n"
       
   215 					"SUMMARY:hi there\r\n"
       
   216 					"END:VEVENT\r\n"
       
   217 					"BEGIN:VEVENT\r\n"
       
   218 					"UID:4\r\n"
       
   219  			   		"X-EPOCAGENDAENTRYTYPE:TODO\r\n"
       
   220 					"DTSTART:20050415:133000.000000\r\n"
       
   221 					"DTEND:20050415:143000.000000\r\n"
       
   222 					"SUMMARY:hi there\r\n"
       
   223 					"END:VEVENT\r\n"
       
   224 					"BEGIN:VEVENT\r\n"
       
   225 					"UID:5\r\n"
       
   226  			   		"X-EPOCAGENDAENTRYTYPE:TODO\r\n"
       
   227 					"DTSTART:20050415:133000.000000\r\n"
       
   228 					"DTEND:20050415:143000.000000\r\n"
       
   229 					"SUMMARY:hi there\r\n"
       
   230 					"END:VEVENT\r\n"
       
   231 					"END:VCALENDAR\r\n");
       
   232 	
       
   233     _LIT(KFileName, "c:\\modifiedvcard.vcs");
       
   234 
       
   235 	TTime oldTime; 
       
   236 	oldTime.HomeTime();
       
   237 	RTz tzServer;
       
   238 	
       
   239 	User::LeaveIfError(tzServer.Connect());
       
   240 	CleanupClosePushL(tzServer);
       
   241 
       
   242 	tzServer.SetHomeTime(TTime(_L("19990627:000000.000000")));
       
   243 
       
   244     RFile outfile;
       
   245     TInt err = outfile.Replace(iTestLibrary->FileSession(), KFileName(), EFileWrite);
       
   246     User::LeaveIfError(err);
       
   247   
       
   248     outfile.Write(KEntry());   
       
   249     outfile.Close();
       
   250 
       
   251     RFile infile;
       
   252     User::LeaveIfError(infile.Open(iTestLibrary->FileSession(),KFileName,EFileRead));   
       
   253     CleanupClosePushL(infile);
       
   254    
       
   255     RFileReadStream readStream(infile);
       
   256     CleanupClosePushL(readStream);
       
   257    
       
   258     RPointerArray<CCalEntry> entryArray;
       
   259     CleanupResetAndDestroyPushL(entryArray);
       
   260    
       
   261     CCalDataExchange* sync = CCalDataExchange::NewL(iTestLibrary->GetSession());
       
   262     CleanupStack::PushL(sync);
       
   263 
       
   264     sync->ImportL(KUidVCalendar, readStream, entryArray);
       
   265    
       
   266     CleanupStack::PopAndDestroy(sync);   
       
   267    
       
   268     test(entryArray.Count()==5);
       
   269 
       
   270     TInt success = 0;
       
   271     iTestLibrary->SynCGetEntryViewL().StoreL(entryArray, success);
       
   272     test(entryArray.Count() == success);
       
   273     
       
   274     CleanupStack::PopAndDestroy(3, &infile);//entryArray, readStream
       
   275 
       
   276     iTestLibrary->DeleteFileL(KFileName, 0);
       
   277     
       
   278 	RArray<TCalLocalUid> calLocalIds;
       
   279 	CleanupClosePushL(calLocalIds);
       
   280 	
       
   281 	tzServer.SetHomeTime(TTime(_L("19990627:010000.000000")));
       
   282 	TCalTime calTime2000;
       
   283 	calTime2000.SetTimeLocalL(TTime(_L("19990627:000000.000000")));
       
   284 
       
   285 	iTestLibrary->SynCGetEntryViewL().GetIdsModifiedSinceDateL(calTime2000, calLocalIds);
       
   286 	// There should be five modified since the time of creation
       
   287 	test.Printf(_L("number of returned entries from GetIdsModifiedSinceDateL = %d\n"), calLocalIds.Count());
       
   288 	test(calLocalIds.Count()==5);
       
   289 	
       
   290 	calLocalIds.Reset();
       
   291 
       
   292 	// There should be no modified since current time
       
   293 	calTime2000.SetTimeLocalL(TTime(_L("19990627:010000.000000")));
       
   294 	iTestLibrary->SynCGetEntryViewL().GetIdsModifiedSinceDateL(calTime2000, calLocalIds);
       
   295 	test.Printf(_L("number of returned entries from GetIdsModifiedSinceDateL = %d\n"), calLocalIds.Count());
       
   296 	test( calLocalIds.Count() == 0 );
       
   297 	
       
   298 	iTestLibrary->CleanDatabaseL();
       
   299 	tzServer.SetHomeTime(oldTime);
       
   300 
       
   301 	CleanupStack::PopAndDestroy(2, &tzServer);//calLocalIds
       
   302 	}
       
   303 
       
   304 
       
   305 
       
   306 void CDataSyncTestManager::TestFileIdL()
       
   307 	{	
       
   308 	test.Next(_L("Test the file ids are different"));
       
   309 
       
   310 	TCalFileId fileId1;
       
   311 	TCalFileId fileId2;
       
   312 	iTestLibrary->GetSession().FileIdL(fileId1);
       
   313 	iTestLibrary->ReplaceFileL(KCalendarFile2);
       
   314 	iTestLibrary->OpenFileL(KCalendarFile2);
       
   315 	iTestLibrary->GetSession().FileIdL(fileId2);
       
   316 	
       
   317 	test.Printf(_L("File ID 1 = %d\nFile ID 2 =  %d\n"), fileId1, fileId2);
       
   318 	
       
   319 	test(fileId1 != fileId2);
       
   320 	
       
   321 	// reopen the original file
       
   322 	iTestLibrary->OpenFileL(KCalendarFile1);
       
   323 	}
       
   324 
       
   325 
       
   326 
       
   327 void CDataSyncTestManager::TestConsistentLocalIdL()
       
   328 	{//This test is to test the fix for the defect  DEF067513  "Local UID is not preserved when Updating CCalEntrys" 
       
   329 
       
   330 	test.Next(_L("Test entry's local uid is the same after being updated"));
       
   331 
       
   332 	
       
   333 	
       
   334 	RPointerArray<CCalEntry> entriesToStore;
       
   335 	CleanupResetAndDestroyPushL(entriesToStore);
       
   336 	
       
   337 
       
   338 	_LIT8(KUid, "UID_BB");
       
   339 
       
   340 	TInt entriesStored = 0;
       
   341 	HBufC8* 	guid = NULL;
       
   342 	CCalEntry*	entry = NULL;
       
   343 
       
   344 
       
   345 //
       
   346 	test.Printf(_L("Create a simple entry and store it to the file\n"));
       
   347 	
       
   348 	TBuf<50> summary;
       
   349 	TBuf<50> location;
       
   350 	TBuf<50> description;
       
   351 
       
   352 	guid = KUid().AllocLC();
       
   353 	entry = iTestLibrary->CreateCalEntryL(CCalEntry::EAppt, guid);
       
   354 	CleanupStack::Pop(guid);
       
   355 	CleanupStack::PushL(entry);
       
   356 	
       
   357 	iTestLibrary->SetEntryStartAndEndTimeL(entry);		
       
   358 	iTestLibrary->RandomText(summary);
       
   359 	entry->SetSummaryL(summary);
       
   360 	iTestLibrary->RandomText(location);
       
   361 	entry->SetLocationL(location);
       
   362 	iTestLibrary->RandomText(description);
       
   363 	entry->SetDescriptionL(description);
       
   364 	
       
   365 	User::LeaveIfError(entriesToStore.Append(entry));
       
   366 	CleanupStack::Pop(entry);
       
   367 
       
   368 	iTestLibrary->SynCGetEntryViewL().StoreL(entriesToStore, entriesStored);
       
   369 	test(entriesToStore.Count() == entriesStored);
       
   370 	
       
   371 	TCalLocalUid storedUid1 = entriesToStore[0]->LocalUidL();
       
   372 	test.Printf(_L("storedUid1 = %d\n"), storedUid1);
       
   373 
       
   374 
       
   375 	entriesToStore.ResetAndDestroy();
       
   376 
       
   377 
       
   378 //
       
   379 	test.Printf(_L("Fetch and store it again to make sure local UId is still the same\n"));
       
   380 
       
   381 	iTestLibrary->SynCGetEntryViewL().FetchL(KUid, entriesToStore);
       
   382 	test(entriesToStore.Count() == 1);
       
   383 	
       
   384 	TCalLocalUid fetchedUid = entriesToStore[0]->LocalUidL();
       
   385 	test.Printf(_L("fetchedUid = %d\n"), fetchedUid);	
       
   386 	
       
   387 	iTestLibrary->SynCGetEntryViewL().StoreL(entriesToStore, entriesStored);
       
   388 	test(entriesToStore.Count() == entriesStored);	
       
   389 
       
   390 	TCalLocalUid storedUid2 = entriesToStore[0]->LocalUidL();
       
   391 	test.Printf(_L("storedUid2 = %d\n"), storedUid2);
       
   392 	
       
   393 	test(storedUid1 == fetchedUid);
       
   394 	test(storedUid2 == fetchedUid);	
       
   395 
       
   396 
       
   397 	entriesToStore.ResetAndDestroy();
       
   398 
       
   399 
       
   400 //
       
   401 	test.Printf(_L("Delete entries from the file\n"));
       
   402 	
       
   403 	iTestLibrary->CleanDatabaseL();	
       
   404 		
       
   405 	iTestLibrary->SynCGetEntryViewL().FetchL(KUid, entriesToStore);
       
   406 	test(entriesToStore.Count() == 0);
       
   407 
       
   408 	
       
   409 	entriesToStore.ResetAndDestroy();
       
   410 	
       
   411 	
       
   412 //
       
   413 	test.Printf(_L("Create a repeating entry (parent) and store it to the file\n"));
       
   414 		
       
   415 	guid = KUid().AllocLC();
       
   416 	entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
       
   417 	CleanupStack::Pop(guid);
       
   418 	CleanupStack::PushL(entry);
       
   419 
       
   420 	TTime startTime (TDateTime(2005, EJanuary, 7, 10, 0, 0, 0)); 
       
   421 	TCalTime calStartTime;
       
   422 	calStartTime.SetTimeLocalL(startTime);
       
   423 	TTime endTime (TDateTime(2005, EJanuary, 7, 11, 0, 0, 0)); 
       
   424 	TCalTime calEndTime;
       
   425 	calEndTime.SetTimeLocalL(endTime);
       
   426 	entry->SetStartAndEndTimeL(calStartTime, calEndTime);
       
   427 
       
   428 	TCalRRule* rpt = new (ELeave) TCalRRule(TCalRRule::EDaily);
       
   429 	CleanupStack::PushL(rpt);
       
   430 	TTime daily1end(TDateTime(2005, EJanuary, 9, 10, 0, 0, 0));
       
   431 	TCalTime rptendTime;
       
   432 	rptendTime.SetTimeLocalL(daily1end);
       
   433 
       
   434 	rpt->SetDtStart(calStartTime);
       
   435 	rpt->SetUntil(rptendTime);
       
   436 	rpt->SetInterval(1);
       
   437 	entry->SetRRuleL(*rpt);//take a copy of the rule
       
   438 	CleanupStack::PopAndDestroy(rpt);
       
   439 	
       
   440 	entriesToStore.Append(entry);
       
   441 	CleanupStack::Pop(entry);
       
   442 	
       
   443 	iTestLibrary->SynCGetEntryViewL().StoreL(entriesToStore, entriesStored);
       
   444 	test(entriesToStore.Count() == entriesStored);
       
   445 
       
   446 
       
   447 	entriesToStore.ResetAndDestroy();
       
   448 
       
   449 
       
   450 //
       
   451 	test.Printf(_L("Create a child entry and store it\n"));
       
   452 			
       
   453 	guid = KUid().AllocLC();
       
   454 	TTime ttime (TDateTime(2005, EJanuary, 8, 10, 0, 0, 0));
       
   455 	TCalTime recurrenceId;
       
   456 	recurrenceId.SetTimeUtcL(ttime);
       
   457 	entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodRequest, 0, recurrenceId, CalCommon::EThisOnly);
       
   458 	CleanupStack::Pop(guid);
       
   459 	CleanupStack::PushL(entry);
       
   460 
       
   461 	// Start date same as RecId. End time is 1 hour later.
       
   462 	TTime newStartDate (TDateTime(2005, EJanuary, 8, 11, 0, 0, 0));
       
   463 	TTime newEndDate (TDateTime(2005, EJanuary, 8, 12, 0, 0, 0));
       
   464 	
       
   465 	TCalTime newCalstartTime;
       
   466 	newCalstartTime.SetTimeUtcL(newStartDate);
       
   467 	
       
   468 	TCalTime newCalendTime;
       
   469 	newCalendTime.SetTimeUtcL(newEndDate);
       
   470 	
       
   471 	entry->SetStartAndEndTimeL(newCalstartTime, newCalendTime);
       
   472 	
       
   473 	entriesToStore.Append(entry);
       
   474 	CleanupStack::Pop(entry);
       
   475 
       
   476 	iTestLibrary->SynCGetEntryViewL().StoreL(entriesToStore, entriesStored);
       
   477 	test(entriesToStore.Count() == entriesStored);	
       
   478 
       
   479 
       
   480 	entriesToStore.ResetAndDestroy();
       
   481 
       
   482 	
       
   483 //
       
   484 	test.Printf(_L("Store the parent which should delete the child\n"));
       
   485 	
       
   486 	iTestLibrary->SynCGetEntryViewL().FetchL(KUid, entriesToStore);
       
   487 	test(entriesToStore.Count() == 2); // 1 parent and 1 child so far
       
   488 	
       
   489 	CCalEntry* parent = entriesToStore[0];
       
   490 	TCalLocalUid parentId = parent->LocalUidL();
       
   491 	test.Printf(_L("parentId = %d\n"), parentId);
       
   492 	CCalEntry* child = entriesToStore[1];
       
   493 	entriesToStore.Remove(1);
       
   494 	delete child;
       
   495 
       
   496  	iTestLibrary->SynCGetEntryViewL().StoreL(entriesToStore, entriesStored);
       
   497  	test(entriesToStore.Count() == entriesStored);
       
   498 
       
   499 	entriesToStore.ResetAndDestroy();
       
   500 	
       
   501 	iTestLibrary->SynCGetEntryViewL().FetchL(KUid, entriesToStore);
       
   502 	test(entriesToStore.Count() == 1);//make sure children is deleted from the file when the parent is updated
       
   503 	TCalLocalUid fetchedParentId = entriesToStore[0]->LocalUidL();
       
   504 	test.Printf(_L("fetchedParentId = %d\n"),fetchedParentId);
       
   505 	
       
   506 	test(parentId == fetchedParentId);
       
   507 
       
   508 
       
   509 	entriesToStore.ResetAndDestroy();
       
   510 
       
   511 
       
   512 //
       
   513 	test.Printf(_L("Delete entries from the file\n"));
       
   514 	
       
   515 	iTestLibrary->CleanDatabaseL();
       
   516 
       
   517 	iTestLibrary->SynCGetEntryViewL().FetchL(KUid, entriesToStore);
       
   518 	test(entriesToStore.Count() == 0);
       
   519 
       
   520 
       
   521 	CleanupStack::PopAndDestroy(&entriesToStore);
       
   522 	}
       
   523 
       
   524 void CDataSyncTestManager::TestSyncDuringDeleteL()
       
   525 	{
       
   526 	test.Printf(_L("Adding 1000 entries\n"));
       
   527 	_LIT8(KGuid, "entryToDelete");
       
   528 	TBuf8<32> buffer;
       
   529 	TCalTime startTime;
       
   530 	const TTime KInitialTime(TDateTime(2006, EJanuary, 0, 0, 0, 0, 0));
       
   531 	
       
   532 	RPointerArray<CCalEntry> entryArray;
       
   533 	CleanupResetAndDestroyPushL(entryArray);
       
   534 	
       
   535 	for (TInt i = 0; i < 1000; i++)
       
   536 		{
       
   537 		buffer.Copy(KGuid);
       
   538 		buffer.AppendNum(i);
       
   539 		HBufC8* guid = buffer.AllocLC();
       
   540 		CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
       
   541 		CleanupStack::Pop(guid);
       
   542 		CleanupStack::PushL(entry);
       
   543 		
       
   544 		startTime.SetTimeLocalL(KInitialTime + TTimeIntervalDays(i));
       
   545 		entry->SetStartAndEndTimeL(startTime, startTime);
       
   546 		TCalRRule rule(TCalRRule::EDaily);
       
   547 		rule.SetDtStart(startTime);
       
   548 		rule.SetCount(50);
       
   549 		entry->SetRRuleL(rule);
       
   550 		
       
   551 		entryArray.AppendL(entry);
       
   552 		CleanupStack::Pop(entry);
       
   553 		
       
   554 		if (i % 100 == 99)
       
   555 			{
       
   556 			TInt success = 0;
       
   557 			iTestLibrary->SynCGetEntryViewL().StoreL(entryArray, success);
       
   558 			test.Printf(_L("Stored %d entries...\n"), i+1);
       
   559 			entryArray.ResetAndDestroy();
       
   560 			}
       
   561 		}
       
   562 	CleanupStack::PopAndDestroy(&entryArray);
       
   563 	
       
   564 	test.Printf(_L("Delete all entries asynchronously...\n"));
       
   565 	// now delete all entries
       
   566 	TCalTime minTime, maxTime;
       
   567 	minTime.SetTimeUtcL(TCalTime::MinTime());
       
   568 	maxTime.SetTimeUtcL(TCalTime::MaxTime());
       
   569 	iTestLibrary->SynCGetEntryViewL().DeleteL(CalCommon::TCalTimeRange(minTime, maxTime), CalCommon::EIncludeAll, *iTestLibrary);
       
   570 	
       
   571 	test.Printf(_L("Fetch all local uids\n"));
       
   572 	RArray<TCalLocalUid> luids;
       
   573 	CleanupClosePushL(luids);
       
   574 	TRAPD(err, iTestLibrary->SynCGetEntryViewL().GetIdsModifiedSinceDateL(minTime, luids));
       
   575 	test(err == KErrLocked);
       
   576 	CleanupStack::PopAndDestroy(&luids);
       
   577 	
       
   578 	test.Printf(_L("Complete delete operation\n"));
       
   579 	// wait for entries to be deleted
       
   580 	CActiveScheduler::Start();
       
   581 	
       
   582 	iTestLibrary->SynCGetEntryViewL().GetIdsModifiedSinceDateL(minTime, luids);
       
   583 	test(luids.Count() == 0);
       
   584 	}
       
   585 
       
   586 
       
   587 
       
   588 void CDataSyncTestManager::TestDeleteParentAndChildEntriesL()
       
   589 	{
       
   590 	test.Next(_L("Create many parent and child entries and delete them all by local UID"));
       
   591 
       
   592 	
       
   593 	const TInt KNumEntryPairs = 50;
       
   594 	_LIT8(KGuidStart, "uid:");
       
   595 	TBuf8<16> guidBuf;
       
   596 	TTime startTime(TDateTime(2006, EJanuary, 0, 9, 0, 0, 0)); // 0900 on 1 Jan
       
   597 	for (TInt i = 0; i < KNumEntryPairs; i++, startTime += TTimeIntervalDays(1))
       
   598 		{
       
   599 		guidBuf.Copy(KGuidStart);
       
   600 		guidBuf.AppendNum(i);
       
   601 		HBufC8* guid = guidBuf.AllocLC();
       
   602 		
       
   603 		CCalEntry* parent = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0);
       
   604 		CleanupStack::Pop(guid);
       
   605 		CleanupStack::PushL(parent);
       
   606 
       
   607 		TCalTime calStartTime;
       
   608 		calStartTime.SetTimeLocalL(startTime);
       
   609 		parent->SetStartAndEndTimeL(calStartTime, calStartTime);
       
   610 		
       
   611 		TCalRRule rule(TCalRRule::EDaily);
       
   612 		rule.SetDtStart(calStartTime);
       
   613 		rule.SetCount(5);
       
   614 		parent->SetRRuleL(rule);
       
   615 
       
   616 		iTestLibrary->StoreEntryL(*parent);
       
   617 		CleanupStack::PopAndDestroy(parent);
       
   618 		
       
   619 		TCalTime recId;
       
   620 		recId.SetTimeLocalL(startTime + TTimeIntervalDays(2));
       
   621 		guid = guidBuf.AllocLC();
       
   622 		
       
   623 		CCalEntry* child = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0, recId, CalCommon::EThisOnly);
       
   624 		CleanupStack::Pop(guid);
       
   625 		CleanupStack::PushL(child);
       
   626 
       
   627 		child->SetStartAndEndTimeL(recId, recId);
       
   628 		
       
   629 		iTestLibrary->StoreEntryL(*child);
       
   630 		CleanupStack::PopAndDestroy(child);
       
   631 		}
       
   632 	
       
   633 	TCalTime sinceDate;
       
   634 	sinceDate.SetTimeLocalL(TCalTime::MinTime());
       
   635 	
       
   636 	RArray<TCalLocalUid> luids;
       
   637 	CleanupClosePushL(luids);
       
   638 	iTestLibrary->SynCGetEntryViewL().GetIdsModifiedSinceDateL(sinceDate, luids);
       
   639 	TInt success = 0;
       
   640 	iTestLibrary->SynCGetEntryViewL().DeleteL(luids, success);
       
   641 	test(success == luids.Count());
       
   642 	CleanupStack::PopAndDestroy(&luids);
       
   643 	}
       
   644 
       
   645 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
       
   646  * DoTestL()
       
   647  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
       
   648 	
       
   649 static void DoTestL()
       
   650 	{
       
   651 	CDataSyncTestManager* testManager = CDataSyncTestManager::NewLC();
       
   652 
       
   653 
       
   654 	TPerformanceTimer timer(test);
       
   655 	timer.Start();
       
   656 
       
   657 
       
   658 	// Run the test suite
       
   659 
       
   660 	testManager->TestConsistentLocalIdL();
       
   661 	testManager->TestGetIdsModifiedSinceDateL();
       
   662 	testManager->TestGetIdsModifiedOnCurrentTimeL();
       
   663 	testManager->TestFileIdL();
       
   664 	testManager->TestSyncDuringDeleteL();
       
   665 	testManager->TestDeleteParentAndChildEntriesL();
       
   666 	
       
   667 
       
   668 	timer.Stop();
       
   669 	test.Printf(_L("Done\n"));
       
   670 	// printout performance time
       
   671 	timer.PrintOut();
       
   672 
       
   673 	
       
   674 	CleanupStack::PopAndDestroy(testManager);		
       
   675 	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
       
   676 
       
   677 
       
   678 /**
       
   679 
       
   680 @SYMTestCaseID     PIM-TCAL-DATASYNC-0001
       
   681 
       
   682 */
       
   683 
       
   684 TInt E32Main()
       
   685     {
       
   686 	__UHEAP_MARK;
       
   687 
       
   688 	test.Start(_L("@SYMTESTCaseID:PIM-TCAL-DATASYNC-0001 Calendar Interim API Data Sync test suite"));
       
   689 
       
   690 	test.Title();
       
   691 
       
   692 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
       
   693 	if (!trapCleanup)
       
   694 		{
       
   695 		return KErrNoMemory;
       
   696 		}
       
   697 
       
   698 	CActiveScheduler* scheduler = new CActiveScheduler();
       
   699 	if (!scheduler)
       
   700 		{
       
   701 		delete trapCleanup;
       
   702 		return KErrNoMemory;
       
   703 		}
       
   704 	CActiveScheduler::Install(scheduler);	
       
   705 
       
   706 	TRAPD(ret, DoTestL());
       
   707 	test(ret == KErrNone);
       
   708 	
       
   709 	delete scheduler;
       
   710 	delete trapCleanup;	
       
   711 
       
   712 	test.End();
       
   713 	test.Close();
       
   714 
       
   715 	__UHEAP_MARKEND;
       
   716 
       
   717 	return (KErrNone);
       
   718     }
       
   719