pimappservices/calendar/tsrc/T_VCAL4.CPP
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 1997-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 <e32test.h>
       
    17 #include <e32std.h>
       
    18 #include <s32file.h>
       
    19 #include <s32mem.h>
       
    20 
       
    21 #include <caldataexchange.h>
       
    22 #include <calentryview.h>
       
    23 #include <calrrule.h>
       
    24 #include <calalarm.h>
       
    25 #include <caliterator.h>
       
    26 #include <caldataformat.h>
       
    27 
       
    28 #include <coreappstest/testserver.h>
       
    29 #include "caltestlib.h"
       
    30 
       
    31 // This testcode reproduces defect EDNSAID-4A6HSS (ER5 defects database)
       
    32 // "Time is being shifted at IrDA Transfer"
       
    33 // 
       
    34 // In order to test that this defect is fixed, a vCalendar stream containing 
       
    35 // 3 appointments and a to-do item is exported.  This provides 100% coverage of 
       
    36 // all date/time properties used in Agenda Model.  The following properties are
       
    37 // exported : LAST-MODIFIED, DTSTART, DTEND, DUE, AALARM, EXDATE, RRULE.
       
    38 //
       
    39 // To check that the test was successful, the localised vCalendar stream is imported
       
    40 // and the entries are compared to the original entry definitions to check they have
       
    41 // the same start/end times etc.  These files can also be inspected manually.  They 
       
    42 // should be identical, other than minor differences in the last modified date.   
       
    43 
       
    44 static RTest test(_L("T_VCAL4"));
       
    45 
       
    46 _LIT(KFrenchFile,"c:\\french.vcs");
       
    47 _LIT(KHomeFile,"c:\\home.vcs");
       
    48 _LIT(KJapanFile,"c:\\japan.vcs");
       
    49 _LIT(KNewYorkFile,"c:\\newyork.vcs");
       
    50 _LIT(KTempFileName,"c:\\temp.vcs");
       
    51 _LIT(KUkFile,"c:\\uk.vcs");
       
    52 
       
    53 
       
    54 _LIT8(KAsiaTokyo, "Asia/Tokyo");
       
    55 _LIT8(KEuropeLondon, "Europe/London");
       
    56 _LIT8(KAmericaNewYork, "America/New_York");
       
    57 	
       
    58 _LIT8(KGuidAppt,		"t_vcal_guid_appt");
       
    59 _LIT8(KGuidAlarmAppt,	"t_vcal_guid_alarmappt");
       
    60 _LIT8(KGuidTodo,		"t_vcal_guid_todo");
       
    61 _LIT8(KGuidAnniv,		"t_vcal_guid_anniv");
       
    62 
       
    63 _LIT(KTestCalendarFile,		"c:t_vcal4");
       
    64 
       
    65 class CTestApp : public CBase
       
    66 	{
       
    67 public:
       
    68 	static CTestApp* NewL();
       
    69 	~CTestApp();
       
    70 	
       
    71 	void CreateToDoL();
       
    72 	void CreateAppointmentL();
       
    73 	void CreateAnniversaryEntryL();
       
    74 	void CreateTimedAlarmedApptEntryL();
       
    75 	void ExportAsVCalendarL(const TDesC& aVCalendarStream, RPointerArray<CCalEntry>& aEntries, const TDesC8& aTimeZone);
       
    76 	void ExportAsVCalendarL(const TDesC& aVCalendarStream);
       
    77 	void DoSyncMLExportTestL();
       
    78 	void SummaryOrDescriptionOnlyTestL();
       
    79 	void CheckLastChangedDateOnVcalImportL();
       
    80 	void CleanFileL();
       
    81 	void ImportAsVCalendarL(const TDesC& aVCalendarStream);
       
    82 	void DeleteFile(const TDesC& aFileName);
       
    83 	void CheckEntriesL();
       
    84 	TBool AreFilesToBeDeleted() //Leave files in the c drive if there is an error for debugging purposes
       
    85 	    {
       
    86 		return iDeleteFiles;
       
    87 	    }
       
    88 
       
    89 
       
    90 private:
       
    91     CTestApp();
       
    92 	void ConstructL();
       
    93 
       
    94 	TInt Diff(RFile anInFile, RFile anOutFile);
       
    95 	void CheckOutputL(const TDesC& aFile, const TDesC& aFile2);
       
    96 	
       
    97 	TInt ContainsTextL(const TDesC& aFileName, const TDesC8& aText);
       
    98 
       
    99 private:
       
   100 	CCalTestLibrary* iCalTestLib;
       
   101 	
       
   102 	TCalTime iToday;
       
   103 	TBool iDeleteFiles;
       
   104 	};
       
   105 	
       
   106 CTestApp* CTestApp::NewL()
       
   107 	{
       
   108 	CTestApp* self = new(ELeave) CTestApp;
       
   109 	CleanupStack::PushL(self);
       
   110 	self->ConstructL();
       
   111 	CleanupStack::Pop(self);
       
   112 	return self;
       
   113 	}
       
   114 	
       
   115 void CTestApp::DeleteFile(const TDesC& aFileName)
       
   116 	{
       
   117 	iCalTestLib->FileSession().Delete(aFileName);
       
   118 	}
       
   119 	
       
   120 void CTestApp::ConstructL()
       
   121 	{
       
   122 	iCalTestLib = CCalTestLibrary::NewL();
       
   123 	iCalTestLib->ReplaceFileL(KTestCalendarFile);
       
   124 	iCalTestLib->OpenFileL(KTestCalendarFile);
       
   125 	
       
   126 	iToday.SetTimeLocalL(TTime(_L("20051123:120000.000000"))); // 12:00 23rd November 2005
       
   127 	}
       
   128 CTestApp::CTestApp() : 	iDeleteFiles(ETrue)
       
   129 {}
       
   130 		
       
   131 CTestApp::~CTestApp()
       
   132 	{
       
   133 	delete iCalTestLib;
       
   134 	}
       
   135 	
       
   136 void CTestApp::CleanFileL()
       
   137 	{
       
   138 	iCalTestLib->CleanDatabaseL();
       
   139 	}
       
   140 
       
   141 
       
   142 TInt CTestApp::Diff(RFile anInFile, RFile anOutFile)
       
   143 	{
       
   144 	TBuf8<256> inBuf;
       
   145 	TBuf8<256> outBuf; 
       
   146 	do	{
       
   147 		inBuf.SetLength(0);
       
   148 		outBuf.SetLength(0);
       
   149 		anInFile.Read(inBuf, 256);
       
   150 		anOutFile.Read(outBuf, 256);
       
   151 		TInt err = inBuf.Compare(outBuf);
       
   152 		if (err)
       
   153 			{
       
   154 		    iDeleteFiles = EFalse;
       
   155 			return err;
       
   156 			}
       
   157 		}
       
   158 	while (inBuf.Length() && outBuf.Length());
       
   159 	return KErrNone;
       
   160 	}
       
   161 
       
   162 void CTestApp::CheckOutputL(const TDesC& aFile, const TDesC& aFile2)
       
   163 	{
       
   164 	RFile inFile;
       
   165 	User::LeaveIfError(inFile.Open(iCalTestLib->FileSession(), aFile, EFileRead));
       
   166 	CleanupClosePushL(inFile);
       
   167 	RFile outFile;
       
   168 	User::LeaveIfError(outFile.Open(iCalTestLib->FileSession(), aFile2, EFileRead));
       
   169 	CleanupClosePushL(outFile);
       
   170 	TInt err = Diff(inFile, outFile);
       
   171 	inFile.Close();
       
   172 	outFile.Close();
       
   173 	test(err==KErrNone);
       
   174 	CleanupStack::PopAndDestroy(2);
       
   175 	}
       
   176 
       
   177 // Create a to-do item, with a due date of five days after the testcode is run.
       
   178 //
       
   179 void CTestApp::CreateToDoL()
       
   180 	{
       
   181 	HBufC8* guid = KGuidTodo().AllocLC();
       
   182 	CCalEntry* todo = iCalTestLib->CreateCalEntryL(CCalEntry::ETodo, guid);
       
   183 	CleanupStack::Pop(guid);
       
   184 	CleanupStack::PushL(todo);
       
   185 	
       
   186 	TCalTime startTime;
       
   187 	startTime.SetTimeLocalL(iToday.TimeLocalL() + TTimeIntervalDays(5));
       
   188 	TCalTime endTime;
       
   189 	endTime.SetTimeLocalL(iToday.TimeLocalL() + TTimeIntervalDays(6));
       
   190 	
       
   191 	todo->SetStartAndEndTimeL(startTime, endTime);
       
   192 	todo->SetSummaryL(_L("A to-do entry"));
       
   193 	
       
   194 	todo->SetCompletedL(ETrue, iToday);
       
   195 	
       
   196 	RPointerArray<CCalEntry> entryArray;
       
   197 	CleanupClosePushL(entryArray);
       
   198 	entryArray.AppendL(todo);
       
   199 	TInt numSuc;
       
   200 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   201 	CleanupStack::PopAndDestroy(); // entryArray.close()
       
   202 	CleanupStack::PopAndDestroy(todo);
       
   203 	}
       
   204 
       
   205 
       
   206 // Create a one hour appointment between 9-10am on the day the testcode is run.
       
   207 //
       
   208 void CTestApp::CreateAppointmentL()
       
   209 	{
       
   210 	TCalTime startTime;
       
   211 	startTime.SetTimeLocalL(TDateTime(iToday.TimeLocalL().DateTime().Year(), iToday.TimeLocalL().DateTime().Month(), iToday.TimeLocalL().DateTime().Day(),9,0,0,0));
       
   212 	TCalTime endTime;
       
   213 	endTime.SetTimeLocalL(startTime.TimeLocalL() + TTimeIntervalMinutes(60));
       
   214 	HBufC8* guid = KGuidAppt().AllocLC();
       
   215 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guid);
       
   216 	CleanupStack::Pop(guid);
       
   217 	CleanupStack::PushL(entry);
       
   218 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   219 	entry->SetSummaryL(_L("An Appointment"));
       
   220 	
       
   221 	RPointerArray<CCalEntry> entryArray;
       
   222 	CleanupClosePushL(entryArray);
       
   223 	entryArray.AppendL(entry);
       
   224 	TInt numSuc;
       
   225 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   226 	CleanupStack::PopAndDestroy(); // entryArray.close()
       
   227 	CleanupStack::PopAndDestroy(entry);
       
   228 	}
       
   229 
       
   230 // Create a repeating entry.
       
   231 // The repeat is set for yearly on June 24th starting in 1998, with the exception of 24/06/2000
       
   232 //
       
   233 void CTestApp::CreateAnniversaryEntryL()
       
   234 	{
       
   235 	HBufC8* guid = KGuidAnniv().AllocLC();
       
   236 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAnniv, guid);
       
   237 	CleanupStack::Pop(guid);
       
   238 	CleanupStack::PushL(entry);
       
   239 	
       
   240 	entry->SetSummaryL(_L("Anniversary of company"));
       
   241 	
       
   242 	TCalTime symbianCreation;
       
   243 	symbianCreation.SetTimeLocalL(TTime(TDateTime(1998,EJune,24,0,0,0,0)));
       
   244 	
       
   245 	entry->SetStartAndEndTimeL(symbianCreation, symbianCreation);
       
   246 	
       
   247 	TCalRRule rRule(TCalRRule::EYearly);
       
   248 	rRule.SetDtStart(symbianCreation);
       
   249 	rRule.SetInterval(1);
       
   250 	TCalTime maxTime;
       
   251 	maxTime.SetTimeUtcL(TCalTime::MaxTime());
       
   252 	rRule.SetUntil(maxTime);
       
   253 	entry->SetRRuleL(rRule);
       
   254 	
       
   255 	RArray<TCalTime> exceptions;
       
   256 	CleanupClosePushL(exceptions);
       
   257 	TCalTime exception;
       
   258 	exception.SetTimeLocalL(TTime(TDateTime(2000,EJune,24,0,0,0,0)));
       
   259 	exceptions.AppendL(exception);
       
   260 
       
   261 	entry->SetExceptionDatesL(exceptions);
       
   262 	
       
   263 	CleanupStack::PopAndDestroy(); // exceptions.close()
       
   264 	
       
   265 	RPointerArray<CCalEntry> entryArray;
       
   266 	CleanupClosePushL(entryArray);
       
   267 	entryArray.AppendL(entry);
       
   268 	TInt numSuc;
       
   269 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   270 	CleanupStack::PopAndDestroy(); // entryArray.close()
       
   271 	CleanupStack::PopAndDestroy(entry); // entry
       
   272 	}
       
   273 
       
   274 
       
   275 // Create an alarmed appointment
       
   276 //
       
   277 void CTestApp::CreateTimedAlarmedApptEntryL()
       
   278 	{
       
   279 	TCalTime startTime;
       
   280 	startTime.SetTimeLocalL(TDateTime(iToday.TimeLocalL().DateTime().Year(), iToday.TimeLocalL().DateTime().Month(), iToday.TimeLocalL().DateTime().Day(),10,0,0,0));
       
   281 	TCalTime endTime;
       
   282 	endTime.SetTimeLocalL(startTime.TimeLocalL() + TTimeIntervalMinutes(90));
       
   283 	HBufC8* guid = KGuidAlarmAppt().AllocLC();
       
   284 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guid);
       
   285 	CleanupStack::Pop(guid);
       
   286 	CleanupStack::PushL(entry);
       
   287 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   288 	
       
   289 	entry->SetSummaryL(_L("app engines weekly meeting APPOINTMENT"));
       
   290 	
       
   291 	CCalAlarm* alarm = CCalAlarm::NewL();
       
   292 	CleanupStack::PushL(alarm);
       
   293 	alarm->SetAlarmSoundNameL(_L("Fanfare"));
       
   294 	alarm->SetTimeOffset(TTimeIntervalMinutes(15));// entry->SetAlarm(0,15);
       
   295 	entry->SetAlarmL(alarm);
       
   296 	CleanupStack::PopAndDestroy(alarm);
       
   297 	
       
   298 	RPointerArray<CCalEntry> entryArray;
       
   299 	CleanupClosePushL(entryArray);
       
   300 	entryArray.AppendL(entry);
       
   301 	TInt numSuc;
       
   302 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   303 	CleanupStack::PopAndDestroy(); // entryArray.close()
       
   304 	
       
   305 	CleanupStack::PopAndDestroy(entry);
       
   306 	}
       
   307 
       
   308 // Export vCalendar file
       
   309 //
       
   310 void CTestApp::ExportAsVCalendarL(const TDesC& aVCalendarStream)
       
   311 	{
       
   312 	RPointerArray<CCalEntry> entryArray;
       
   313 	CleanupResetAndDestroyPushL(entryArray);
       
   314 	
       
   315 	CCalIter* calIter = CCalIter::NewL(iCalTestLib->GetSession());
       
   316 	CleanupStack::PushL(calIter);
       
   317 	
       
   318 	for (TDesC8* guid = const_cast<TDesC8*>(&calIter->FirstL());
       
   319 			guid->CompareF(KNullDesC8) != 0;
       
   320 			guid = const_cast<TDesC8*>(&calIter->NextL()))
       
   321 		{
       
   322 		iCalTestLib->SynCGetEntryViewL().FetchL(*guid, entryArray);
       
   323 		}
       
   324 		
       
   325 	CleanupStack::PopAndDestroy(calIter);
       
   326 	
       
   327 	RFile outFile;
       
   328 	User::LeaveIfError(outFile.Replace(iCalTestLib->FileSession(), aVCalendarStream, EFileWrite));
       
   329 	RFileWriteStream writeStream(outFile);
       
   330 	
       
   331 	iCalTestLib->DataExchangeL().ExportL(KUidVCalendar, writeStream, entryArray);
       
   332 	writeStream.Close();
       
   333 	outFile.Close();
       
   334 	CleanupStack::PopAndDestroy(); // entryArray.Close()
       
   335 	}
       
   336 
       
   337 // Import vCalendar stream
       
   338 //
       
   339 
       
   340 void CTestApp::ImportAsVCalendarL(const TDesC& aVCalendarStream)
       
   341 	{
       
   342 	test.Next(_L("Importing all entries"));
       
   343 
       
   344 	RFile infile;
       
   345 	infile.Open(iCalTestLib->FileSession(), aVCalendarStream, EFileRead);
       
   346 	RFileReadStream readStream(infile);
       
   347 
       
   348 	// Create ptr array for new entries
       
   349 	RPointerArray<CCalEntry> entryArray;
       
   350 	CleanupResetAndDestroyPushL(entryArray);
       
   351 	iCalTestLib->DataExchangeL().ImportL(KUidVCalendar, readStream, entryArray);
       
   352 
       
   353 	readStream.Close();
       
   354 	infile.Close();
       
   355 	
       
   356 	TInt numSuc;
       
   357 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   358 	
       
   359 	CleanupStack::PopAndDestroy(&entryArray); // entryArray.Close()
       
   360 	}
       
   361 
       
   362 void CTestApp::CheckLastChangedDateOnVcalImportL()
       
   363 	{
       
   364 	test.Next(_L("Check last changed date on vcard import..."));
       
   365 
       
   366 
       
   367 	_LIT8(KVcal,	"BEGIN:VCALENDAR\r\n"
       
   368 					"VERSION:1.0\r\n"
       
   369 					"BEGIN:VEVENT\r\n"
       
   370 					"UID:4\r\n"
       
   371 					"SUMMARY:test\r\n"
       
   372 					"DTSTART:20021120T090000Z\r\n"
       
   373 					"DTEND:20021120T100000Z\r\n"
       
   374 					"X-EPOCAGENDAENTRYTYPE:APPOINTMENT\r\n"
       
   375 					"CLASS:PUBLIC\r\n"
       
   376 					"LAST-MODIFIED:20021120T152700Z\r\n"
       
   377 					"PRIORITY:0\r\n"
       
   378 					"STATUS:NEEDS ACTION\r\n"
       
   379 					"END:VEVENT\r\n"
       
   380 					"END:VCALENDAR\r\n");
       
   381 	
       
   382 	_LIT(KDateTime,"20/11/2002 15:27:00");
       
   383 	TTime lastChangedDateExpected;
       
   384 	lastChangedDateExpected.Parse(KDateTime);
       
   385 	
       
   386 	TBuf<30> dateString;
       
   387 	TBuf<30> timeString;
       
   388 	
       
   389 	_LIT(KExpectedDateFormat,"Expected date: %S %S\n");
       
   390 	_LIT(KImportedDateFormat,"Imported date: %S %S\n");
       
   391 	_LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3");
       
   392 	_LIT(KTimeString,"%-B%:0%J%:1%T%:2%S%:3%+B");
       
   393 
       
   394 	lastChangedDateExpected.FormatL(dateString,KDateString);
       
   395 	lastChangedDateExpected.FormatL(timeString,KTimeString);
       
   396 	
       
   397 	test.Printf(KExpectedDateFormat,&dateString,&timeString);
       
   398 	
       
   399 	RDesReadStream readStream(KVcal);
       
   400 	CleanupClosePushL(readStream);
       
   401 
       
   402 	// Create ptr array for new entries
       
   403 	RPointerArray<CCalEntry> entryArray;
       
   404 	CleanupResetAndDestroyPushL(entryArray);
       
   405 	//Import vcal
       
   406 	iCalTestLib->DataExchangeL().ImportL(KUidVCalendar, readStream, entryArray);
       
   407 
       
   408 	test(entryArray.Count() == 1);
       
   409 	CCalEntry* entry = entryArray[0];
       
   410 	
       
   411 	//Print last changed date from the entry imported
       
   412 	entry->LastModifiedDateL().TimeUtcL().FormatL(dateString,KDateString);
       
   413 	entry->LastModifiedDateL().TimeUtcL().FormatL(timeString,KTimeString);
       
   414 	test.Printf(KImportedDateFormat,&dateString,&timeString);
       
   415 	
       
   416 	//Check last changed date
       
   417 	test(entry->LastModifiedDateL().TimeUtcL() == lastChangedDateExpected);
       
   418 	
       
   419 	//now add the entry 
       
   420 	RPointerArray<CCalEntry> storeEntryArray;
       
   421 	CleanupClosePushL(storeEntryArray);
       
   422 	storeEntryArray.AppendL(entry);
       
   423 	TInt numSuc;
       
   424 	iCalTestLib->SynCGetEntryViewL().StoreL(storeEntryArray, numSuc);
       
   425 	CleanupStack::PopAndDestroy(); // entryArray.close()
       
   426 	
       
   427 	//Check that the add entry hasn't changed the date
       
   428 	test(entry->LastModifiedDateL().TimeLocalL() == lastChangedDateExpected); 
       
   429 	lastChangedDateExpected=entry->LastModifiedDateL().TimeLocalL();
       
   430 	
       
   431 	// test that an update does change the last modified date
       
   432 	RPointerArray<CCalEntry> updateEntryArray;
       
   433 	CleanupClosePushL(updateEntryArray);
       
   434 	updateEntryArray.AppendL(entry);
       
   435 	iCalTestLib->SynCGetEntryViewL().UpdateL(updateEntryArray, numSuc);
       
   436 	CleanupStack::PopAndDestroy(); // updateEntryArray.close()
       
   437 	TTime fetchedChangedDate = entry->LastModifiedDateL().TimeLocalL();
       
   438 	test(fetchedChangedDate != lastChangedDateExpected); 
       
   439 
       
   440 	CleanupStack::PopAndDestroy(2,&readStream); //entryArray
       
   441 	}
       
   442 
       
   443 
       
   444 // Check that the entries are correct when they are imported
       
   445 //
       
   446 void CTestApp::CheckEntriesL()
       
   447 	{	
       
   448 	RPointerArray<CCalEntry> entryArray;
       
   449 	CleanupResetAndDestroyPushL(entryArray);
       
   450 	
       
   451 	// todo
       
   452 	iCalTestLib->SynCGetEntryViewL().FetchL(KGuidTodo, entryArray);
       
   453 	test(entryArray.Count() == 1);
       
   454 	test.Printf(_L("Testing the todo; %S\n"), &entryArray[0]->SummaryL());
       
   455 	test(entryArray[0]->EntryTypeL() == CCalEntry::ETodo);
       
   456 	test(entryArray[0]->StartTimeL().TimeUtcL() == TTime(TDateTime(2005, EDecember, 28, 12, 0, 0, 0)));
       
   457 	test(entryArray[0]->EndTimeL().TimeUtcL() == TTime(TDateTime(2005, EDecember, 29, 12, 0, 0, 0)));
       
   458 	test(entryArray[0]->CompletedTimeL().TimeUtcL() == TTime(TDateTime(2005, EDecember, 23, 12, 0, 0, 0)));
       
   459 	
       
   460 	// anniv
       
   461 	entryArray.ResetAndDestroy();
       
   462 	iCalTestLib->SynCGetEntryViewL().FetchL(KGuidAnniv, entryArray);
       
   463 	test(entryArray.Count() == 1);
       
   464 	test.Printf(_L("Testing the anniv; %S\n"), &entryArray[0]->SummaryL());
       
   465 	test(entryArray[0]->EntryTypeL() == CCalEntry::EAnniv);
       
   466 	test(entryArray[0]->StartTimeL().TimeUtcL() == TTime(TDateTime(1998,EJune,23,23,0,0,0)));
       
   467 	test(entryArray[0]->EndTimeL().TimeUtcL() == TTime(TDateTime(1998,EJune,23,23,0,0,0)));
       
   468 	
       
   469 	// appt
       
   470 	entryArray.ResetAndDestroy();
       
   471 	iCalTestLib->SynCGetEntryViewL().FetchL(KGuidAppt, entryArray);
       
   472 	test(entryArray.Count() == 1);
       
   473 	test.Printf(_L("Testing the appt; %S\n"), &entryArray[0]->SummaryL());
       
   474 	test(entryArray[0]->EntryTypeL() == CCalEntry::EAppt);
       
   475 	test(entryArray[0]->StartTimeL().TimeUtcL() == TTime(TDateTime(2005, EDecember, 23, 9, 0, 0, 0)));
       
   476 	test(entryArray[0]->EndTimeL().TimeUtcL() == TTime(TDateTime(2005, EDecember, 23, 10, 0, 0, 0)));
       
   477 	
       
   478 	// alarmed appt
       
   479 	entryArray.ResetAndDestroy();
       
   480 	iCalTestLib->SynCGetEntryViewL().FetchL(KGuidAlarmAppt, entryArray);
       
   481 	test(entryArray.Count() == 1);
       
   482 	test.Printf(_L("Testing the alarmed appt; %S\n"), &entryArray[0]->SummaryL());
       
   483 	test(entryArray[0]->EntryTypeL() == CCalEntry::EAppt);
       
   484 	test(entryArray[0]->StartTimeL().TimeUtcL() == TTime(TDateTime(2005, EDecember, 23, 10, 0, 0, 0)));
       
   485 	test(entryArray[0]->EndTimeL().TimeUtcL() == TTime(TDateTime(2005, EDecember, 23, 11, 30, 0, 0)));
       
   486 	
       
   487 	CCalAlarm* alarm = entryArray[0]->AlarmL();
       
   488 	CleanupStack::PushL(alarm);
       
   489 	test(alarm != NULL);
       
   490 	test(alarm->TimeOffset() == TTimeIntervalMinutes(15));
       
   491 	CleanupStack::PopAndDestroy(alarm);
       
   492 	
       
   493 	CleanupStack::PopAndDestroy(&entryArray);	
       
   494 	}
       
   495 
       
   496 //
       
   497 void CTestApp::ExportAsVCalendarL(const TDesC& aVCalendarStream, RPointerArray<CCalEntry>& aEntries, const TDesC8& aTimeZone)
       
   498 	{
       
   499     RPIMTestServer serv3;
       
   500     User::LeaveIfError(serv3.Connect());
       
   501     serv3.SetTimeZoneL(aTimeZone);
       
   502 
       
   503 	TTime time;
       
   504 	time.HomeTime();
       
   505 	TDateTime dateTime=time.DateTime();
       
   506 	dateTime.SetMinute(0);
       
   507 	dateTime.SetSecond(0);
       
   508 	dateTime.SetMicroSecond(0);
       
   509 	time=dateTime;
       
   510 	
       
   511     serv3.SetHomeTime(time);
       
   512     serv3.Close();
       
   513 
       
   514 	TInt numSuc;
       
   515 	iCalTestLib->SynCGetEntryViewL().UpdateL(aEntries, numSuc);
       
   516 	
       
   517 	RFile outFile;
       
   518 	User::LeaveIfError(outFile.Replace(iCalTestLib->FileSession(), aVCalendarStream, EFileWrite));
       
   519 	RFileWriteStream writeStream(outFile);
       
   520 	
       
   521 	iCalTestLib->DataExchangeL().ExportL(KUidVCalendar, writeStream, aEntries);
       
   522 	writeStream.Close();
       
   523 	outFile.Close();
       
   524 	}
       
   525 
       
   526 // Create two entries (summer and winter) and export in different timezones as if to SyncML Server.
       
   527 //
       
   528 
       
   529 void CTestApp::DoSyncMLExportTestL()
       
   530 	{
       
   531 	const TInt Hours=10;
       
   532 	const TInt MinsPerHour=60;
       
   533 	
       
   534 	RPointerArray<CCalEntry> entryArray;
       
   535 	CleanupResetAndDestroyPushL(entryArray);
       
   536 	test.Next(_L("Checking SyncML Exports"));
       
   537 
       
   538 	
       
   539 	//Create 1st entry (with alarm)
       
   540 	TCalTime startTime;
       
   541 	startTime.SetTimeLocalL(TDateTime(iToday.TimeLocalL().DateTime().Year(),EFebruary,2,Hours,0,0,0));
       
   542 	TCalTime endTime;
       
   543 	endTime.SetTimeLocalL(startTime.TimeLocalL() + TTimeIntervalMinutes(60));
       
   544 	HBufC8* guid1 = NULL;
       
   545 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guid1);
       
   546 	CleanupStack::PushL(entry);
       
   547 	entry->SetStartAndEndTimeL(startTime,endTime);
       
   548 	entry->SetSummaryL(_L("Winter"));
       
   549 	
       
   550 	CCalAlarm* alarm = CCalAlarm::NewL();
       
   551 	CleanupStack::PushL(alarm);
       
   552 	alarm->SetTimeOffset(TTimeIntervalMinutes(Hours*MinsPerHour-5));
       
   553 	entry->SetAlarmL(alarm);
       
   554 	entryArray.AppendL(entry);
       
   555 	CleanupStack::PopAndDestroy(alarm);
       
   556 	CleanupStack::Pop(entry);
       
   557 	
       
   558 	//create 2nd entry (without alarm)
       
   559 	HBufC8* guid2 = NULL;
       
   560 	entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guid2);
       
   561 	CleanupStack::PushL(entry);
       
   562 	startTime.SetTimeLocalL(startTime.TimeLocalL() += TTimeIntervalMonths(3));
       
   563 	endTime.SetTimeLocalL(startTime.TimeLocalL() + TTimeIntervalMinutes(60));
       
   564 	
       
   565 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   566 	entry->SetSummaryL(_L("Summer"));
       
   567 	
       
   568 	entryArray.AppendL(entry);
       
   569 	CleanupStack::Pop(entry);
       
   570 
       
   571 	TInt numSuc;
       
   572 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   573 	
       
   574 	TTime time;
       
   575 	time.HomeTime();
       
   576 	TDateTime dateTime=time.DateTime();
       
   577 	dateTime.SetHour(12);
       
   578 	TTime newTime=dateTime;
       
   579 	
       
   580     RPIMTestServer serv1;
       
   581     User::LeaveIfError(serv1.Connect());
       
   582     serv1.SetHomeTime(newTime);
       
   583     serv1.Close();
       
   584 
       
   585 	time.HomeTime();
       
   586 	dateTime=time.DateTime();
       
   587 	TLocale oldLocale;
       
   588 	ExportAsVCalendarL(KJapanFile, entryArray, KAsiaTokyo);		//Japan
       
   589 	ExportAsVCalendarL(KUkFile, entryArray, KEuropeLondon);			//UK
       
   590 	ExportAsVCalendarL(KNewYorkFile, entryArray, KAmericaNewYork);	//New York
       
   591 	
       
   592 	CleanupStack::PopAndDestroy(&entryArray);
       
   593 	
       
   594 	oldLocale.Set();
       
   595 	time+=TTimeIntervalMinutes(1);
       
   596 	
       
   597     RPIMTestServer serv4;
       
   598     User::LeaveIfError(serv4.Connect());
       
   599     serv4.SetHomeTime(time);
       
   600     serv4.Close();
       
   601 
       
   602 	CheckOutputL(KJapanFile,KUkFile);
       
   603 	CheckOutputL(KUkFile,KNewYorkFile);
       
   604 	}
       
   605 
       
   606 TInt CTestApp::ContainsTextL(const TDesC& aFileName, const TDesC8& aText)
       
   607 	{
       
   608 	//open file
       
   609 	RFile file;
       
   610 	User::LeaveIfError(file.Open(iCalTestLib->FileSession(), aFileName, EFileShareReadersOnly));
       
   611 	CleanupClosePushL(file);
       
   612 	//alloc buffer
       
   613 	TInt sizeOfFile;
       
   614 	User::LeaveIfError(file.Size(sizeOfFile));
       
   615 	HBufC8* buffer = HBufC8::NewLC(sizeOfFile);
       
   616 	//copy file into buffer
       
   617 	TPtr8 ptr(buffer->Des());
       
   618 	User::LeaveIfError(file.Read(ptr,sizeOfFile));
       
   619 	//look for the descriptor
       
   620 	TInt found=ptr.Find(aText);
       
   621 	CleanupStack::PopAndDestroy(2,&file);
       
   622 	return found;
       
   623 	}
       
   624 
       
   625 void CTestApp::SummaryOrDescriptionOnlyTestL()
       
   626 	{
       
   627 	test.Next(_L("Testing function: CAgendaEntryToVCalConverter::AddEntryPropertiesL ..."));
       
   628 
       
   629 	//Initialisation
       
   630 	_LIT(KSummaryText, "summary");
       
   631 	_LIT(KDescriptionText, "description");
       
   632 	
       
   633 	RPointerArray<CCalEntry> entryArray;
       
   634 	CleanupResetAndDestroyPushL(entryArray);
       
   635 
       
   636 	TCalTime startTime;
       
   637 	startTime.SetTimeLocalL(TDateTime(iToday.TimeLocalL().DateTime().Year(), iToday.TimeLocalL().DateTime().Month(), iToday.TimeLocalL().DateTime().Day(),10,0,0,0));
       
   638 	TCalTime endTime;
       
   639 	endTime.SetTimeLocalL(startTime.TimeLocalL() + TTimeIntervalMinutes(90));
       
   640 	//
       
   641 	
       
   642 	//Create appt agenda entry with description only	
       
   643 	HBufC8* guidDescOnly = NULL;
       
   644 	CCalEntry* entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidDescOnly);
       
   645 	CleanupStack::PushL(entry);
       
   646 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   647 	entry->SetDescriptionL(KDescriptionText());
       
   648 	entryArray.AppendL(entry);
       
   649 	CleanupStack::Pop(entry);
       
   650 	
       
   651 	//Create appt agenda entry with summary only
       
   652 	HBufC8* guidSumOnly = NULL;
       
   653 	entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidSumOnly);
       
   654 	CleanupStack::PushL(entry);
       
   655 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   656 	entry->SetSummaryL(KSummaryText);
       
   657 	entryArray.AppendL(entry);
       
   658 	CleanupStack::Pop(entry);
       
   659 	
       
   660 	//Create appt agenda entry with both summary and description
       
   661 	HBufC8* guidBoth = NULL;	
       
   662 	entry = iCalTestLib->CreateCalEntryL(CCalEntry::EAppt, guidBoth);
       
   663 	CleanupStack::PushL(entry);
       
   664 	entry->SetStartAndEndTimeL(startTime, endTime);
       
   665 	entry->SetSummaryL(KSummaryText);
       
   666 	entry->SetDescriptionL(KDescriptionText());
       
   667 	entryArray.AppendL(entry);
       
   668 	CleanupStack::Pop(entry);
       
   669 	
       
   670 	TInt numSuc;
       
   671 	iCalTestLib->SynCGetEntryViewL().StoreL(entryArray, numSuc);
       
   672 	
       
   673 	//Check exported data
       
   674 	_LIT8(KCheckBeamingSummaryOnly,"SUMMARY:summary");
       
   675 	_LIT8(KCheckSummary,"SUMMARY:summary");
       
   676 	_LIT8(KCheckDescription,"DESCRIPTION:description");
       
   677 	_LIT8(KTagSummary,"SUMMARY:");
       
   678 	_LIT8(KTagDescription,"DESCRIPTION:");
       
   679 
       
   680  	//
       
   681 	//Check summary only export
       
   682 	// beaming
       
   683 	
       
   684 	RPointerArray<CCalEntry> exportEntryArray;
       
   685 	CleanupClosePushL(exportEntryArray);
       
   686 	
       
   687 	exportEntryArray.AppendL(entryArray[1]);
       
   688 	ExportAsVCalendarL(KTempFileName, exportEntryArray, KEuropeLondon);
       
   689 	test(ContainsTextL(KTempFileName,KCheckBeamingSummaryOnly)!=KErrNotFound); // check summary value is present in the summary field
       
   690 	test(ContainsTextL(KTempFileName,KTagSummary)!=KErrNotFound); // check summary tag is present
       
   691 	//syncML
       
   692 	ExportAsVCalendarL(KTempFileName, exportEntryArray, KEuropeLondon);
       
   693 	test(ContainsTextL(KTempFileName,KCheckSummary)!=KErrNotFound); // check summary
       
   694 	test(ContainsTextL(KTempFileName,KTagDescription)==KErrNotFound); // check no description
       
   695 	//
       
   696 	//Check description only export
       
   697 	exportEntryArray.Reset();
       
   698 	exportEntryArray.AppendL(entryArray[0]);
       
   699 	// beaming
       
   700 	ExportAsVCalendarL(KTempFileName, exportEntryArray, KEuropeLondon);
       
   701 	test(ContainsTextL(KTempFileName,KTagSummary)==KErrNotFound); // check no summary
       
   702 	test(ContainsTextL(KTempFileName,KCheckDescription)!=KErrNotFound); // check description
       
   703 	//syncML
       
   704 	ExportAsVCalendarL(KTempFileName, exportEntryArray, KEuropeLondon);
       
   705 	test(ContainsTextL(KTempFileName,KTagSummary)==KErrNotFound); // check no summary
       
   706 	test(ContainsTextL(KTempFileName,KCheckDescription)!=KErrNotFound); // check description
       
   707 	//
       
   708 	//Check description and summary export
       
   709 	exportEntryArray.Reset();
       
   710 	exportEntryArray.AppendL(entryArray[2]);
       
   711 	// beaming
       
   712 	ExportAsVCalendarL(KTempFileName, exportEntryArray, KEuropeLondon);
       
   713 	test(ContainsTextL(KTempFileName,KCheckSummary)!=KErrNotFound); // check summary
       
   714 	test(ContainsTextL(KTempFileName,KCheckDescription)!=KErrNotFound); // check description
       
   715 	//syncML
       
   716 	ExportAsVCalendarL(KTempFileName, exportEntryArray, KEuropeLondon);
       
   717 	test(ContainsTextL(KTempFileName,KCheckSummary)!=KErrNotFound); // check summary
       
   718 	test(ContainsTextL(KTempFileName,KCheckDescription)!=KErrNotFound); // check description
       
   719 	
       
   720 	CleanupStack::PopAndDestroy(&exportEntryArray);
       
   721 	CleanupStack::PopAndDestroy(&entryArray);
       
   722 	}
       
   723 	
       
   724 
       
   725 
       
   726 
       
   727 
       
   728 static void doMainL()
       
   729 	{
       
   730 	//get the initial time
       
   731  	TTime homeTime;
       
   732  	homeTime.HomeTime();
       
   733 
       
   734 	TDateTime dt(1999, EJanuary, 0, 0, 0, 0, 0);
       
   735 	TTime arbitary(dt);
       
   736 	
       
   737     RPIMTestServer serv2;
       
   738     User::LeaveIfError(serv2.Connect());
       
   739     serv2.SetHomeTime(arbitary);
       
   740 
       
   741 	CTestApp* testApp = CTestApp::NewL();
       
   742 	CleanupStack::PushL(testApp);
       
   743 
       
   744 	// create entries
       
   745 	testApp->CreateAppointmentL();
       
   746 	testApp->CreateAnniversaryEntryL();
       
   747 	testApp->CreateTimedAlarmedApptEntryL();
       
   748 	testApp->CreateToDoL();
       
   749 	
       
   750 	// export a vCalendar with locale not set (home)
       
   751 	
       
   752 	test.Next(_L("Exporting all entries (home locale)"));
       
   753 
       
   754 	testApp->ExportAsVCalendarL(KHomeFile);
       
   755 	
       
   756 	// change locale to French (+1hr GMT/UTC)
       
   757 	User::SetUTCOffset(TTimeIntervalSeconds(60*60));
       
   758 
       
   759 	// export a vCalendar with the locale set to French 
       
   760 	
       
   761 	test.Next(_L("Exporting all entries (french locale)"));
       
   762 
       
   763 	testApp->ExportAsVCalendarL(KFrenchFile);
       
   764 	User::SetUTCOffset(TTimeIntervalSeconds(0));
       
   765 
       
   766 	testApp->DoSyncMLExportTestL();
       
   767 	testApp->SummaryOrDescriptionOnlyTestL();
       
   768 	testApp->CheckLastChangedDateOnVcalImportL();
       
   769 
       
   770 	testApp->CleanFileL();
       
   771 	
       
   772 	testApp->ImportAsVCalendarL(KFrenchFile);
       
   773  	testApp->CheckEntriesL();
       
   774  
       
   775  	//Set back the time to the initial time
       
   776     serv2.SetHomeTime(homeTime);
       
   777     serv2.Close();
       
   778     if (testApp->AreFilesToBeDeleted())
       
   779         {
       
   780     	testApp->DeleteFile(KFrenchFile);
       
   781 	    testApp->DeleteFile(KHomeFile);
       
   782 	    testApp->DeleteFile(KJapanFile);
       
   783 	    testApp->DeleteFile(KNewYorkFile);
       
   784 	    testApp->DeleteFile(KTempFileName);
       
   785  	    testApp->DeleteFile(KUkFile);
       
   786         }
       
   787     
       
   788 
       
   789 	CleanupStack::PopAndDestroy(testApp);
       
   790 	}
       
   791 
       
   792 
       
   793 /**
       
   794 
       
   795 @SYMTestCaseID     PIM-T-VCAL4-0001
       
   796 
       
   797 */
       
   798 
       
   799 TInt E32Main()
       
   800 	{	
       
   801 	__UHEAP_MARK;
       
   802 	test.Start(_L("@SYMTESTCaseID:PIM-T-VCAL4-0001 T_VCAL4"));
       
   803 
       
   804 	test.Title();
       
   805 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   806 	CActiveScheduler::Install(scheduler);
       
   807 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   808 	TRAPD(ret,doMainL());	
       
   809 	test(ret==KErrNone);
       
   810 	delete theCleanup;	
       
   811 	delete scheduler;
       
   812 	test.End();
       
   813 	test.Close();
       
   814 	__UHEAP_MARKEND;
       
   815 	return(KErrNone);
       
   816 	}
       
   817