pimappsupport/vcardandvcal/tsrc/TBugFix.CPP
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2001-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 // System includes
       
    17 #include <e32std.h>
       
    18 #include <e32base.h>
       
    19 #include <e32test.h>
       
    20 #include <s32mem.h>
       
    21 
       
    22 // User includes
       
    23 #include <versit.h>
       
    24 #include <vcal.h>
       
    25 #include <vcard.h>
       
    26 #include "Observ.H"
       
    27 #include "base64extension.h"
       
    28 #include <coreappstest/testserver.h>
       
    29 
       
    30 // Globals
       
    31 RTest TheTest(_L("Versit Escaping Test"));
       
    32 
       
    33 _LIT(KSimpleFileName,"C:\\SimpleO.VCF");
       
    34 _LIT(KOutEscFileName,"C:\\Output-Escaped.vcf");
       
    35 _LIT(KOutputFileName,"C:\\Output-QP.vcf");
       
    36 _LIT(KVCardFileShiftJIS,"c:\\charsetSJIS.vcf");
       
    37 _LIT(KVCardFileJIS,"c:\\charsetJIS.vcf ");
       
    38 _LIT(KBase64FileName,"C:\\Output-Base64.vcf");
       
    39 
       
    40 _LIT(KOutputQPFileName,"C:\\Export-QP-Vcard.vcf");
       
    41 _LIT(KQPFileName,"C:\\QP-Vcard.vcf");
       
    42 _LIT(KOutputQPHashFileName,"C:\\Export-QP-Hash.vcf");
       
    43 _LIT(KQPHashFileName, "C:\\QP-Hash.vcf");
       
    44 
       
    45 _LIT(KHugeVCardFileName,"z:\\testvcards\\various\\HugeVCard.vcf");
       
    46 _LIT(KExportHugeVCardFileName,"C:\\OutputHugeVCard.vcf");
       
    47 
       
    48 
       
    49 class CTests;
       
    50 
       
    51 // Typedefs
       
    52 typedef void (*TVersitStreamFunction)(CVersitParser& aParser);
       
    53 typedef void (*TOOMCallback)(CTests& aSelf);
       
    54 
       
    55 
       
    56 //#define TBUGFIX_INCLUDE_OOM //Comment this OOM test out as it's time spending so not good for overnight build tests
       
    57 
       
    58 /**
       
    59 @file 
       
    60 @SYMTestCaseID PIM-TBUGFIX-Versit_Escaping_Test-0001
       
    61 @SYMTestCaseDesc Importing and exporting of VCards and VCals of different formats.
       
    62 @SYMTestStatus Implemented
       
    63 @SYMTestPriority 3
       
    64 @SYMTestActions Imports pre-existing VCard and VCal files, exports them and than compares their output with a pre-existing VCard or VCal file containing the expected output.
       
    65 @SYMTestExpectedResults KErrNone, all outputed VCards and VCals are identical with expected output.
       
    66 @SYMTestType CT
       
    67 @SYMPREQ 234
       
    68 */
       
    69 class TParserSetUp
       
    70 	{
       
    71 public:
       
    72 	enum TSyncMLTest {eSyncMLTest};
       
    73 public:
       
    74 	inline TParserSetUp(TUint aType): iType(aType), iCharset(Versit::EUSAsciiCharSet), iEncoding(Versit::ENoEncoding),
       
    75 		iAutoDetect(EFalse), iInternaliseFlags(0), iTimeFlags(0) {}
       
    76 	inline TParserSetUp(TUint aType,Versit::TVersitCharSet aCharSet,Versit::TVersitEncoding aEncoding)
       
    77 		: iType(aType), iCharset(aCharSet), iEncoding(aEncoding), iAutoDetect(EFalse), iInternaliseFlags(0), iTimeFlags(0) {}
       
    78 	inline TParserSetUp(TUint aType,TBool aAutoDetect): iType(aType), iCharset(Versit::EUSAsciiCharSet), iEncoding(Versit::ENoEncoding),
       
    79 		iAutoDetect(aAutoDetect), iInternaliseFlags(0), iTimeFlags(0) {}
       
    80 	inline TParserSetUp(TSyncMLTest);
       
    81 public:
       
    82 	TUint iType;
       
    83 	Versit::TVersitCharSet iCharset;
       
    84 	Versit::TVersitEncoding iEncoding;
       
    85 	TBool iAutoDetect;
       
    86 	TUint iInternaliseFlags;
       
    87 	TUint iTimeFlags;
       
    88 	};
       
    89 
       
    90 class CTests : public CBase
       
    91 	{
       
    92 public:
       
    93 	enum TParserType
       
    94 		{
       
    95 		ETvCard,
       
    96 		ETvCal,
       
    97 		ETuseBaseParser=0x08,
       
    98 		//Masks
       
    99 		ETparserType=ETuseBaseParser-1,
       
   100 		};
       
   101 public:
       
   102 	static CTests* NewL();
       
   103 	static TBool CheckRun();
       
   104 	~CTests();
       
   105 	void ConstructL();
       
   106 	void AllTestsL();
       
   107 	
       
   108 	static void TestL(CTests& aSelf);
       
   109 	static void LeaveTestsL(CTests& aSelf);
       
   110 	static void TestJapanL(CTests& aSelf);
       
   111 	static void SyncMLTestsL(CTests& aSelf);
       
   112 	static void Test0L(CTests& aSelf);
       
   113 	static void Test1L(CTests& aSelf);
       
   114 	static void Test2L(CTests& aSelf);
       
   115 	static void Test3L(CTests& aSelf);
       
   116 	static void Test4L(CTests& aSelf);
       
   117 	static void Test5L(CTests& aSelf);
       
   118 	static void Test6L(CTests& aSelf);
       
   119 	static void Test7L(CTests& aSelf);
       
   120 	static void Test8L(CTests& aSelf);
       
   121 	static void Test9L(CTests& aSelf);
       
   122 	static void Test10L(CTests& aSelf);
       
   123 	static void Test11L(CTests& aSelf);
       
   124 	static void Test12L(CTests& aSelf);
       
   125 
       
   126 	static void TestHugeVCardL(CTests& aSelf);
       
   127 	static void TestNullDateL(CTests& aSelf);
       
   128 	static void TestAlarmRepeatCountL(CTests& aSelf);
       
   129 	static void TestHashSignEncodingL(CTests& aSelf);
       
   130 	static void TestBase64ExtensionL(CTests& aSelf);
       
   131 private:
       
   132 	void ReportErrorL(TInt aErr,const TDesC&aFileName);
       
   133 	void CreateFileName(TParserType aType,TFileName& aName,TChar aPrefix,const TDesC& aFile,TInt aPath=1);
       
   134 	void ExistingFileName(TParserType aType,TFileName& aName,TChar aPrefix,const TDesC& aFile,TInt aPath=1);
       
   135 	void SetTimeFlags(CVersitParser& aParser,TUint aTimeFlags);
       
   136 	void IntAndExtL(const TFileName& aInputFile,const TFileName& aOutputFile,const TParserSetUp& aSetUp);
       
   137 	void TestFileL(TUint aType,const TDesC& aTestName,const TDesC& aFile,Versit::TVersitCharSet aCharset=Versit::EUSAsciiCharSet
       
   138 																				,Versit::TVersitEncoding aEncoding=Versit::ENoEncoding, TBool aCompareFile = ETrue);
       
   139 	void TestFileL(const TDesC& aTestName,const TDesC& aFile,const TParserSetUp& aSetUp,TBool aCompareFile = ETrue);
       
   140 	CVersitParser* CreateParserLC(TParserType aType,const TDesC& aTestName);
       
   141 	void DoLeaveTestL(TParserType aType,TInt aLeaveCode,const TDesC& aTestName,const TDesC& aFile);
       
   142 	void DoOomTestL(TParserType aType,TInt aFailAfter,const TDesC& aTestName,const TDesC& aFile);
       
   143 	void DoJapanTestL(const TDesC& aTestName,TInt aTest,TParserType aType=ETvCard);
       
   144 	void DoSyncMLTestL(TTimeIntervalSeconds aUTCOffset,const TDesC& aTestName,const TDesC& aFile);
       
   145 	void ExternaliseFileL(CVersitParser& aParser,const TDesC& aFileName);
       
   146 	void CreateAndExternaliseVCardL(const TDesC8& aVCardText,const TDesC& aFileName,Versit::TVersitEncoding aEncoding=Versit::ENoEncoding);
       
   147 	void InternaliseFileL(CVersitParser& aParser,const TDesC& aFileName,TBool aUseBaseParser=EFalse);
       
   148 	void InternalizeFileL(CVersitParser& aParser,RFile& aInputFile);
       
   149 	void CompareFilesL(const TDesC& aOutputFile,const TDesC& aCompareFile,const TDesC& aInputFile=KNullDesC);
       
   150 	void LineWrappingTestL(const TDesC& aFullFileName);
       
   151 private:
       
   152 	enum {eSecondsPerHour=3600};
       
   153 private:
       
   154 	RFs iFsSession;
       
   155 	TBool iSessionConnected;
       
   156 	CFileMan* iFm;
       
   157 	CTestRegister* iTempFiles;
       
   158 	CTestVersitExtension* iBase64Extension;
       
   159 	};
       
   160 void doOOMTest(CTests& aTest, TOOMCallback aCallback, TInt aFailStart);
       
   161 
       
   162 GLREF_C void ResetAndDestroyArrayOfParams(TAny* aObject)
       
   163 	{
       
   164 	CArrayPtr<CParserParam>* array=REINTERPRET_CAST(CArrayPtr<CParserParam>*,aObject);
       
   165 	if (array)
       
   166 		array->ResetAndDestroy();
       
   167 	delete array;
       
   168 	}
       
   169 
       
   170 GLREF_C void ResetAndDestroyArrayOfProperties(TAny* aObject)
       
   171 	{
       
   172 	CArrayPtr<CParserProperty>* array=REINTERPRET_CAST(CArrayPtr<CParserProperty>*,aObject);
       
   173 	if (array)
       
   174 		array->ResetAndDestroy();
       
   175 	delete array;
       
   176 	}
       
   177 
       
   178 
       
   179 inline TParserSetUp::TParserSetUp(TSyncMLTest): iType(CTests::ETvCal), iCharset(Versit::EUSAsciiCharSet), iEncoding(Versit::ENoEncoding),
       
   180 	iAutoDetect(EFalse), iInternaliseFlags(CVersitParser::EImportSyncML), iTimeFlags(TVersitDateTime::EExportLeaveAsLocalTime) {}
       
   181 
       
   182 
       
   183 CTests* CTests::NewL()
       
   184 	{
       
   185 	CTests* self=new(ELeave) CTests;
       
   186 	CleanupStack::PushL(self);
       
   187 	self->ConstructL();
       
   188 	CleanupStack::Pop(self);
       
   189 	return self;
       
   190 	}
       
   191 
       
   192 TBool CTests::CheckRun()
       
   193 	{
       
   194 	TInt key=TheTest.Getch();
       
   195 	if (key==EKeySpace)
       
   196 		return ETrue;
       
   197 	_LIT(KNot,"Not running this test\r\n");
       
   198 	TheTest.Printf(KNot);
       
   199 	return EFalse;
       
   200 	}
       
   201 
       
   202 void CTests::ConstructL()
       
   203 	{
       
   204 	User::LeaveIfError(iFsSession.Connect());
       
   205 	iSessionConnected=ETrue;
       
   206 	iFm = CFileMan::NewL(iFsSession);
       
   207 	iTempFiles = CTestRegister::NewLC();
       
   208 	CleanupStack::Pop(iTempFiles);
       
   209 	iFsSession.MkDir(_L("C:\\TestvCards\\"));
       
   210 	iFsSession.MkDir(_L("C:\\TestFiles\\"));
       
   211 	iFsSession.MkDir(_L("C:\\K3Data\\"));
       
   212 	}
       
   213 
       
   214 CTests::~CTests()
       
   215 	{
       
   216 	delete(iTempFiles);
       
   217 
       
   218 	if(iFm)
       
   219 		{
       
   220 		iFm->RmDir(_L("C:\\TestvCards\\"));
       
   221 		iFm->RmDir(_L("C:\\TestFiles\\"));
       
   222 		iFm->RmDir(_L("C:\\K3Data\\"));
       
   223 		delete iFm;
       
   224 		}
       
   225 
       
   226 	if (iSessionConnected)
       
   227 		{
       
   228 		iFsSession.Close();
       
   229 		}
       
   230 	delete iBase64Extension;
       
   231 	}
       
   232 
       
   233 void CTests::ReportErrorL(TInt aErr,const TDesC& aFileName)
       
   234 	{
       
   235 	if (aErr==KErrNotFound)
       
   236 		{
       
   237 		_LIT(KMissingFile,"\r\n** FILE NOT FOUND: %S\r\n\r\n");
       
   238 		TheTest.Printf(KMissingFile,&aFileName);
       
   239 		}
       
   240 	else if (aErr==KErrPathNotFound)
       
   241 		{	//You will get this error if you have not exported the test data files.
       
   242 		_LIT(KMissingPath,"\r\n** PATH NOT FOUND: %S\r\n\r\n");
       
   243 		TheTest.Printf(KMissingPath,&aFileName);
       
   244 		}
       
   245 	else
       
   246 		{
       
   247 		_LIT(KError,"Error %d opening file %S\r\n");
       
   248 		TheTest.Printf(KError,aErr,&aFileName);
       
   249 		}
       
   250 	__DEBUGGER();
       
   251 	User::Leave(aErr);
       
   252 	}
       
   253 
       
   254 void CTests::ExternaliseFileL(CVersitParser& aParser,const TDesC& aFileName)
       
   255 	{
       
   256 	RFile file;
       
   257 	User::LeaveIfError(file.Replace(iFsSession, aFileName, EFileWrite));
       
   258 	CleanupClosePushL(file);
       
   259 	aParser.ExternalizeL(file);
       
   260 	CleanupStack::PopAndDestroy(&file);
       
   261 	}
       
   262 
       
   263 void CTests::CreateAndExternaliseVCardL(const TDesC8& aVCardText,const TDesC& aFileName,Versit::TVersitEncoding aEncoding/*=ENoEncoding*/)
       
   264 	{
       
   265 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   266 	CleanupStack::PushL(vCardParser);
       
   267 
       
   268 	RDesReadStream stream(aVCardText);
       
   269 	vCardParser->InternalizeL(stream);
       
   270 
       
   271 	vCardParser->SetDefaultEncoding(aEncoding);
       
   272 	ExternaliseFileL(*vCardParser,aFileName);
       
   273 
       
   274 	CleanupStack::PopAndDestroy(vCardParser);
       
   275 	}
       
   276 
       
   277 void CTests::InternaliseFileL(CVersitParser& aParser,const TDesC& aFileName,TBool aUseBaseParser/*=EFalse*/)
       
   278 	{
       
   279 	RFile file;
       
   280 	TInt err=file.Open(iFsSession, aFileName, EFileRead);
       
   281 	if (err!=KErrNone)
       
   282 		ReportErrorL(err,aFileName);
       
   283 	CleanupClosePushL(file);
       
   284 	TInt start = 0;
       
   285 	
       
   286 	if (iBase64Extension)
       
   287 		{
       
   288 		aParser.SetPlugIn(iBase64Extension);
       
   289 		}
       
   290 
       
   291 	if (aUseBaseParser)
       
   292 		InternalizeFileL(aParser,file);
       
   293 	else
       
   294 		aParser.InternalizeL(file, start);
       
   295 	CleanupStack::PopAndDestroy(&file);
       
   296 	}
       
   297 
       
   298 void CTests::InternalizeFileL(CVersitParser& aParser,RFile& aInputFile)
       
   299 	{
       
   300 	TInt size;
       
   301 	if (aInputFile.Size(size)==KErrNone)
       
   302 		{
       
   303 		RFileReadStream stream(aInputFile);
       
   304 		TRAPD(err,aParser.CVersitParser::InternalizeL(stream));
       
   305 		STATIC_CAST(RFileBuf*,stream.Source())->Reset();
       
   306 		stream.Close();
       
   307 		User::LeaveIfError(err);
       
   308 		}
       
   309 	}
       
   310 
       
   311 LOCAL_C TBool CompareLines(const TDesC8& aLine1, const TDesC8& aLine2)
       
   312 	{
       
   313 	_LIT8(KDayl,"DAYL");
       
   314 	_LIT8(KTzPlus,"TZ:+");
       
   315 	_LIT8(KTzMinus,"TZ:-");
       
   316 
       
   317 	TBool ret=!aLine1.Compare(aLine2);
       
   318 	if (!ret)
       
   319 		{
       
   320 		TBufC8<4> first4char(aLine1.Left(4));
       
   321 		if(!first4char.Compare(KDayl())||!first4char.Compare(KTzPlus())||!first4char.Compare(KTzMinus()))
       
   322 			{
       
   323 			return ETrue;
       
   324 			}
       
   325 		}
       
   326 	return ret;
       
   327 	}
       
   328 
       
   329 
       
   330 void CTests::CompareFilesL(const TDesC& aOutputFile,const TDesC& aCompareFile,const TDesC& aInputFile)
       
   331 	{
       
   332 	RFile file1,file2;
       
   333 	TInt err=file1.Open(iFsSession, aOutputFile, EFileRead);
       
   334 	if (err!=KErrNone)
       
   335 		ReportErrorL(err,aOutputFile);
       
   336 	CleanupClosePushL(file1);
       
   337 	err=file2.Open(iFsSession, aCompareFile, EFileRead);
       
   338 	if (err==KErrNotFound)//in this case, the input file and output file should be identical
       
   339 		{
       
   340 		err=file2.Open(iFsSession, aInputFile, EFileRead);
       
   341 		if (err!=KErrNone)
       
   342 			ReportErrorL(err,aInputFile);
       
   343 		}
       
   344 	if (err!=KErrNone)
       
   345 		ReportErrorL(err,aCompareFile);
       
   346 	CleanupClosePushL(file2);
       
   347 	RFileReadStream stream1(file1);
       
   348 	RFileReadStream stream2(file2);
       
   349 	CleanupClosePushL(stream1);
       
   350 	CleanupClosePushL(stream2);
       
   351 	TBuf8<0x80> bufO,bufC;
       
   352 	//__ASSERT(err==KErrNone);
       
   353 	TInt line=1;
       
   354 	do {
       
   355 		TRAP(err,stream1.ReadL(bufO,TChar(0xa)));
       
   356 		if (err==KErrNone || err==KErrEof)
       
   357 			TRAP(err,stream2.ReadL(bufC,TChar(0xa)));
       
   358 		if (err!=KErrNone && err!=KErrEof)
       
   359 			User::Leave(err);
       
   360 		TheTest(CompareLines(bufO, bufC));
       
   361 		++line;
       
   362 		} while (err!=KErrEof);
       
   363 	CleanupStack::PopAndDestroy(4,&file1);
       
   364 	}
       
   365 
       
   366 void CTests::CreateFileName(TParserType aType,TFileName& aName,TChar aPrefix,const TDesC& aFile,TInt aPath/*=1*/)
       
   367 	{
       
   368 	_LIT(KPrefix1,"C:\\TestFiles\\");
       
   369 	_LIT(KPrefix2,"C:\\K3Data\\");
       
   370 	_LIT(KvCard,".VCF");
       
   371 	_LIT(KvCal,".VCS");
       
   372 	if (aPath==1)
       
   373 		aName=KPrefix1;
       
   374 	else
       
   375 		aName=KPrefix2;
       
   376 	if (aPrefix!=' ')
       
   377 		aName.Append(aPrefix);
       
   378 	aName.Append(aFile);
       
   379 	if (aType==ETvCal)
       
   380 		aName.Append(KvCal);
       
   381 	else
       
   382 		aName.Append(KvCard);
       
   383 	}
       
   384 
       
   385 void CTests::ExistingFileName(TParserType aType,TFileName& aName,TChar aPrefix,const TDesC& aFile,TInt aPath/*=1*/)
       
   386 	{
       
   387 	_LIT(KePrefix1,"Z:\\TestFiles\\");
       
   388 	_LIT(KePrefix2,"Z:\\K3Data\\");
       
   389 	_LIT(KvCard,".VCF");
       
   390 	_LIT(KvCal,".VCS");
       
   391 	if (aPath==1)
       
   392 		aName=KePrefix1;
       
   393 	else
       
   394 		aName=KePrefix2;
       
   395 	if (aPrefix!=' ')
       
   396 		aName.Append(aPrefix);
       
   397 	aName.Append(aFile);
       
   398 	if (aType==ETvCal)
       
   399 		aName.Append(KvCal);
       
   400 	else
       
   401 		aName.Append(KvCard);
       
   402 	}
       
   403 
       
   404 void CTests::SetTimeFlags(CVersitParser& aParser,TUint aTimeFlags)
       
   405 	{
       
   406 	CArrayPtr<CParserProperty>* propertiesArray=aParser.ArrayOfProperties(EFalse);
       
   407 	TInt count;
       
   408 	TInt ii;
       
   409 	if (propertiesArray)
       
   410 		{
       
   411 		CParserTimePropertyValue* timeValue;
       
   412 		CParserPropertyValue* value;
       
   413 		count=propertiesArray->Count();
       
   414 		TVersitDateTime::TVersitDateTimeFlags timeFlags=REINTERPRET_CAST(TVersitDateTime::TVersitDateTimeFlags&,aTimeFlags);
       
   415 		TUid uid;
       
   416 		uid.iUid = KVersitTimePropertyUid;
       
   417 		for (ii=0; ii<count; ii++)
       
   418 			{
       
   419 			value=(*propertiesArray)[ii]->Value();
       
   420 			if (value && value->SupportsInterface(uid))
       
   421 				{
       
   422 				timeValue=STATIC_CAST(CParserTimePropertyValue*,value);
       
   423 				switch (timeValue->Uid().iUid)
       
   424 					{
       
   425 				case KVCalPropertyAlarmUid:
       
   426 					{
       
   427 					CVersitAlarm* alarm=STATIC_CAST(CParserPropertyValueAlarm*,timeValue)->Value();
       
   428 					if (alarm && alarm->iRunTime)
       
   429 						{
       
   430 						alarm->iRunTime->ClearFlag(TVersitDateTime::EExportTimeZoneDesignator);
       
   431 						alarm->iRunTime->SetFlag(timeFlags);
       
   432 						}
       
   433 					}
       
   434 					break;
       
   435 				case KVersitPropertyDaylightUid:
       
   436 					{
       
   437 					CVersitDaylight* daylight=STATIC_CAST(CParserPropertyValueDaylight*,timeValue)->Value();
       
   438 					if (daylight)
       
   439 						{
       
   440 						if (daylight->iStartTime)
       
   441 							{
       
   442 							daylight->iStartTime->ClearFlag(TVersitDateTime::EExportTimeZoneDesignator);
       
   443 							daylight->iStartTime->SetFlag(timeFlags);
       
   444 							}
       
   445 						if (daylight->iEndTime)
       
   446 							{
       
   447 							daylight->iEndTime->ClearFlag(TVersitDateTime::EExportTimeZoneDesignator);
       
   448 							daylight->iEndTime->SetFlag(timeFlags);
       
   449 							}
       
   450 						}
       
   451 					}
       
   452 					break;
       
   453 				case KVersitPropertyDateTimeUid:
       
   454 					{
       
   455 					TVersitDateTime* dateTime=STATIC_CAST(CParserPropertyValueDateTime*,timeValue)->Value();
       
   456 					if (dateTime)
       
   457 						{
       
   458 						dateTime->ClearFlag(TVersitDateTime::EExportTimeZoneDesignator);
       
   459 						dateTime->SetFlag(timeFlags);
       
   460 						}
       
   461 					}
       
   462 					break;
       
   463 				case KVersitPropertyDateUid:
       
   464 					{
       
   465 					TVersitDateTime* dateTime=STATIC_CAST(CParserPropertyValueDate*,timeValue)->Value();
       
   466 					if (dateTime)
       
   467 						{
       
   468 						dateTime->ClearFlag(TVersitDateTime::EExportTimeZoneDesignator);
       
   469 						dateTime->SetFlag(timeFlags);
       
   470 						}
       
   471 					}
       
   472 					break;
       
   473 				case KVersitPropertyMultiDateTimeUid:
       
   474 					{
       
   475 					CArrayPtr<TVersitDateTime>* values=STATIC_CAST(CParserPropertyValueMultiDateTime*,timeValue)->Value();
       
   476 					if (values)
       
   477 						{
       
   478 						TInt count=values->Count();
       
   479 						for (TInt ii=0;ii<count; ii++)
       
   480 							{
       
   481 							(*values)[ii]->ClearFlag(TVersitDateTime::EExportTimeZoneDesignator);
       
   482 							(*values)[ii]->SetFlag(timeFlags);
       
   483 							}
       
   484 						}
       
   485 					}
       
   486 					break;
       
   487 				case KVCalPropertyRecurrenceUid:
       
   488 					{
       
   489 					CVersitRecurrence* recurrence=STATIC_CAST(CParserPropertyValueRecurrence*,timeValue)->Value();
       
   490 					if (recurrence && recurrence->iEndDate)
       
   491 						{
       
   492 						recurrence->iEndDate->ClearFlag(TVersitDateTime::EExportTimeZoneDesignator);
       
   493 						recurrence->iEndDate->SetFlag(timeFlags);
       
   494 						}
       
   495 					}
       
   496 					break;
       
   497 					}
       
   498 				}
       
   499 			}
       
   500 		}
       
   501 	CArrayPtr<CVersitParser>* entityArray=aParser.ArrayOfEntities(EFalse);
       
   502 	if (entityArray)
       
   503 		{
       
   504 		count=entityArray->Count();
       
   505 		for (ii=0; ii<count; ii++)
       
   506 			SetTimeFlags(*(*entityArray)[ii],aTimeFlags);
       
   507 		}
       
   508 	}
       
   509 
       
   510 void CTests::IntAndExtL(const TFileName& aInputFile,const TFileName& aOutputFile,const TParserSetUp& aSetUp)
       
   511 	{
       
   512 	CVersitParser* vParser;
       
   513 	if ((aSetUp.iType&ETparserType)==ETvCal)
       
   514 		{
       
   515 		vParser=CParserVCal::NewL();
       
   516 		if (aSetUp.iInternaliseFlags)
       
   517 			vParser->SetFlags(aSetUp.iInternaliseFlags);
       
   518 		}
       
   519 	else
       
   520 		vParser=CParserVCard::NewL();
       
   521 	vParser->SetAutoDetect(aSetUp.iAutoDetect);
       
   522 	CleanupStack::PushL(vParser);
       
   523 	InternaliseFileL(*vParser,aInputFile,aSetUp.iType&ETuseBaseParser);
       
   524 	vParser->SetDefaultCharSet(aSetUp.iCharset);
       
   525 	vParser->SetDefaultEncoding(aSetUp.iEncoding);
       
   526 	if (aSetUp.iTimeFlags)
       
   527 		SetTimeFlags(*vParser,aSetUp.iTimeFlags);
       
   528 	ExternaliseFileL(*vParser,aOutputFile);
       
   529 	CleanupStack::PopAndDestroy(vParser);
       
   530 	}
       
   531 
       
   532 void CTests::TestFileL(TUint aType,const TDesC& aTestName,const TDesC& aFile
       
   533 				,Versit::TVersitCharSet aCharset/*=Versit::EUSAsciiCharSet*/,Versit::TVersitEncoding aEncoding/*=Versit::ENoEncoding*/, TBool aCompareFile)
       
   534 	{
       
   535 	User::SetUTCOffset(TTimeIntervalSeconds(0));//make sure it is GMT
       
   536 	TParserSetUp setUp(aType,aCharset,aEncoding);
       
   537 	TestFileL(aTestName,aFile,setUp,aCompareFile);
       
   538 	}
       
   539 
       
   540 void CTests::TestFileL(const TDesC& aTestName,const TDesC& aFile,const TParserSetUp& aSetUp, TBool aCompareFile )
       
   541 	{
       
   542 	TheTest.Next(aTestName);
       
   543 	TParserType type=STATIC_CAST(TParserType,aSetUp.iType&ETparserType);
       
   544 	TFileName inputFile,outputFile,compareFile;
       
   545 	ExistingFileName(type,inputFile,'I',aFile);
       
   546 	CreateFileName(type,outputFile,'O',aFile);
       
   547 	ExistingFileName(type,compareFile,'C',aFile);
       
   548 	IntAndExtL(inputFile,outputFile,aSetUp);
       
   549 	if(aCompareFile)
       
   550 		{
       
   551 		CompareFilesL(outputFile,compareFile,inputFile);
       
   552 		}
       
   553 	}
       
   554 
       
   555 CVersitParser* CTests::CreateParserLC(TParserType aType,const TDesC& aTestName)
       
   556 	{
       
   557 	TheTest.Next(aTestName);
       
   558 	CVersitParser* vParser;
       
   559 	if (aType==ETvCal)
       
   560 		vParser=CParserVCal::NewL();
       
   561 	else
       
   562 		vParser=CParserVCard::NewL();
       
   563 	CleanupStack::PushL(vParser);
       
   564 	return vParser;
       
   565 	}
       
   566 
       
   567 void CTests::DoLeaveTestL(TParserType aType,TInt aLeaveCode,const TDesC& aTestName,const TDesC& aFile)
       
   568 	{
       
   569 	CVersitParser* vParser=CreateParserLC(aType,aTestName);
       
   570 	TFileName inputFile;
       
   571 	ExistingFileName(aType,inputFile,' ',aFile);
       
   572 	TRAPD(err,InternaliseFileL(*vParser,inputFile));
       
   573 	TheTest(err==aLeaveCode);
       
   574 	CleanupStack::PopAndDestroy(vParser);
       
   575 	}
       
   576 
       
   577 #ifdef _DEBUG
       
   578 void CTests::DoOomTestL(TParserType aType,TInt aFailAfter,const TDesC& aTestName,const TDesC& aFile)
       
   579 #else
       
   580 void CTests::DoOomTestL(TParserType aType,TInt /*aFailAfter*/,const TDesC& aTestName,const TDesC& aFile)
       
   581 #endif
       
   582 	{
       
   583 	CVersitParser* vParser=CreateParserLC(aType,aTestName);
       
   584 	TFileName inputFile;
       
   585 	ExistingFileName(aType,inputFile,' ',aFile);
       
   586 	__UHEAP_SETFAIL(RHeap::EDeterministic,aFailAfter);
       
   587 	TRAPD(err,InternaliseFileL(*vParser,inputFile));
       
   588 	__UHEAP_RESET;
       
   589 	//++aFailAfter;
       
   590 	TheTest(err==KErrNoMemory);
       
   591 	CleanupStack::PopAndDestroy(vParser);
       
   592 	}
       
   593 
       
   594 void CTests::DoJapanTestL(const TDesC& aTestName,TInt aTest,TParserType aType/*=ETvCard*/)
       
   595 	{
       
   596 	TheTest.Next(aTestName);
       
   597 	TBuf<16> file;
       
   598 	_LIT(KFile,"Test%02d");
       
   599 	file.Format(KFile,aTest);
       
   600 	TFileName inputFile,outputFile1,storkFile,outputFile2;
       
   601 	ExistingFileName(aType,inputFile,'I',file,2);
       
   602 	CreateFileName(aType,outputFile1,'O',file,2);
       
   603 	ExistingFileName(aType,storkFile,'S',file,2);
       
   604 	CreateFileName(aType,outputFile2,'C',file,2);
       
   605 	TParserSetUp setUp(aType);
       
   606 	IntAndExtL(inputFile,outputFile1,setUp);
       
   607 	IntAndExtL(storkFile,outputFile2,setUp);
       
   608 	CompareFilesL(outputFile1,outputFile2);
       
   609 	}
       
   610 
       
   611 void CTests::DoSyncMLTestL(TTimeIntervalSeconds aUTCOffset,const TDesC& aTestName,const TDesC& aFile)
       
   612 	{
       
   613 	User::SetUTCOffset(aUTCOffset);
       
   614 	
       
   615 	TParserSetUp setUp(TParserSetUp::eSyncMLTest);
       
   616 	TestFileL(aTestName,aFile,setUp);
       
   617 	}
       
   618 
       
   619 void CTests::Test0L(CTests& aSelf)
       
   620 	{
       
   621 	_LIT8(KEscapedText, "BEGIN:VCARD\r\nVERSION:2.1\r\nEMAIL:def\r\nEND:VCARD\r\n");
       
   622 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   623 	CleanupStack::PushL(vCardParser);
       
   624 
       
   625 	RDesReadStream stream(KEscapedText);
       
   626 	vCardParser->InternalizeL(stream);
       
   627 
       
   628 #ifndef TBUGFIX_INCLUDE_OOM
       
   629 	aSelf.iTempFiles->RegisterL(KSimpleFileName());
       
   630 #endif	//TBUGFIX_INCLUDE_OOM
       
   631 
       
   632 	aSelf.ExternaliseFileL(*vCardParser,KSimpleFileName);
       
   633 
       
   634 	CleanupStack::PopAndDestroy(vCardParser);
       
   635 	}
       
   636 
       
   637 void CTests::Test1L(CTests& aSelf)
       
   638 	{
       
   639 	_LIT8(KEscapedText, "BEGIN:VCARD\r\nVERSION:2.1\r\nEMAIL:a\\b\r\nEND:VCARD\r\n");
       
   640 	
       
   641 #ifndef TBUGFIX_INCLUDE_OOM
       
   642 	aSelf.iTempFiles->RegisterL(KOutEscFileName);
       
   643 #endif	//TBUGFIX_INCLUDE_OOM
       
   644 
       
   645 	aSelf.CreateAndExternaliseVCardL(KEscapedText,KOutEscFileName);
       
   646 
       
   647 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   648 	CleanupStack::PushL(vCardParser);
       
   649 
       
   650 	aSelf.InternaliseFileL(*vCardParser,KOutEscFileName);
       
   651 
       
   652 	TUid valueTypeUid = { KVersitPropertyHBufCUid };
       
   653 	CArrayPtr<CParserProperty>* array = vCardParser->PropertyL(_L8("EMAIL"), valueTypeUid, EFalse);
       
   654 	CleanupStack::PushL(array);
       
   655 	TheTest(array->Count() == 1);
       
   656 	CParserPropertyValueHBufC* value = static_cast<CParserPropertyValueHBufC*>(array->At(0)->Value());
       
   657 	TheTest(value->Value() == _L("a\\b"));
       
   658 	CleanupStack::PopAndDestroy(array);
       
   659 
       
   660 	CleanupStack::PopAndDestroy(vCardParser);
       
   661 	}
       
   662 
       
   663 /**
       
   664 @SYMTestCaseID PIM-TBUGFIX-PDEF109115-0001
       
   665 @SYMTestCaseDesc Codebase-Versit: Add test to Quoted Printable encoding of properties with CRLF
       
   666 @SYMTestStatus Implemented
       
   667 @SYMTestPriority High
       
   668 @SYMTestType UT
       
   669 @SYMTestActions
       
   670  1)Save VCard test file
       
   671  2)Create a VCard and export it
       
   672  3) Compare the VCard test file with the exported VCard  file 
       
   673 
       
   674 @SYMTestExpectedResults The address property uses Quoted Printable correctly.
       
   675 @SYMDEF PDEF109115
       
   676 @see DEF093368
       
   677 */
       
   678 void CTests::Test12L(CTests& aSelf)
       
   679 	{
       
   680 
       
   681 #ifndef TBUGFIX_INCLUDE_OOM
       
   682 	aSelf.iTempFiles->RegisterL(KQPFileName);
       
   683 	aSelf.iTempFiles->RegisterL(KOutputQPFileName);
       
   684 #endif	//TBUGFIX_INCLUDE_OOM
       
   685  
       
   686 	//Test VCard file	  
       
   687 	_LIT8(KVCardData,	"BEGIN:VCARD\r\n"
       
   688 						"VERSION:2.1\r\n"
       
   689 						"ADR;HOME;ENCODING=QUOTED-PRINTABLE:;;Address=20line1=0D=0Aaddress=20line2\r\n"
       
   690 						"END:VCARD\r\n");
       
   691 	
       
   692 	//Save the test VCard file
       
   693 	TheTest.Printf(_L("@SYMTestCaseID PIM-TBUGFIX-PDEF109115-0001  Save test Vcard file to be compared with exported vcard file later\n"));					
       
   694 	RFile testFile;
       
   695 	User::LeaveIfError(testFile.Replace(aSelf.iFsSession,KQPFileName,EFileWrite ));
       
   696 	testFile.Write(KVCardData);
       
   697 	testFile.Close();
       
   698 	
       
   699 	
       
   700 	//Create a VCard						
       
   701 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   702 	CleanupStack::PushL(vCardParser);
       
   703 
       
   704 	//Create an address value
       
   705 	_LIT(KAddrValue, "Address line1\r\naddress line2");
       
   706 	CDesCArrayFlat* addrArray = new (ELeave) CDesCArrayFlat(3);
       
   707 	CleanupStack::PushL(addrArray);
       
   708 	addrArray->AppendL(KNullDesC);
       
   709 	addrArray->AppendL(KNullDesC);
       
   710 	addrArray->AppendL(KAddrValue);  
       
   711 	
       
   712 	CParserPropertyValue* addrValue=new (ELeave) CParserPropertyValueCDesCArray(addrArray);
       
   713   	CleanupStack::Pop(addrArray);
       
   714   
       
   715 	CleanupStack::PushL(addrValue);
       
   716 	
       
   717 	// Create a property parameter "HOME"
       
   718 	CArrayPtr<CParserParam>* arrayOfParams = new(ELeave)CArrayPtrFlat<CParserParam>(1);
       
   719 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfParams,arrayOfParams));
       
   720 
       
   721 	CParserParam* parserParam=CParserParam::NewL(_L8("HOME"),KNullDesC);
       
   722 	CleanupStack::PushL(parserParam);
       
   723     arrayOfParams->AppendL(parserParam);
       
   724 	CleanupStack::Pop(parserParam);
       
   725 	
       
   726 	//Create an ADR property 
       
   727 	CParserProperty* property=CParserProperty::NewL(*addrValue,KVersitTokenADR,arrayOfParams);
       
   728 
       
   729 	CleanupStack::Pop(2, addrValue);
       
   730 
       
   731 	//Add the ADR property to the VCard
       
   732 	CleanupStack::PushL(property);
       
   733 	vCardParser->AddPropertyL(property);
       
   734 	CleanupStack::Pop(property);
       
   735 
       
   736 	//Export the VCard
       
   737 	aSelf.ExternaliseFileL(*vCardParser,KOutputQPFileName);
       
   738 
       
   739 	CleanupStack::PopAndDestroy(vCardParser);
       
   740 
       
   741 	//Compare the VCard exported with the earlier saved VCard test file
       
   742 	aSelf.CompareFilesL(KQPFileName, KOutputQPFileName);	
       
   743 }
       
   744 
       
   745 void CTests::Test2L(CTests& aSelf)
       
   746 	{
       
   747 	_LIT8(KVCardData, "BEGIN:VCARD\r\nVERSION:2.1\r\nN;ENCODING=QUOTED-PRINTABLE:=3D=3D=3D\r\nEND:VCARD\r\n");
       
   748 
       
   749 #ifndef TBUGFIX_INCLUDE_OOM
       
   750 	aSelf.iTempFiles->RegisterL(KOutputFileName);
       
   751 #endif	//TBUGFIX_INCLUDE_OOM
       
   752 
       
   753 	aSelf.CreateAndExternaliseVCardL(KVCardData,KOutputFileName);
       
   754 
       
   755 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   756 	CleanupStack::PushL(vCardParser);
       
   757 
       
   758 	aSelf.InternaliseFileL(*vCardParser,KOutputFileName);
       
   759 
       
   760 	const TUid valueTypeUid = { KVersitPropertyCDesCArrayUid };
       
   761 	CArrayPtr<CParserProperty>* array = vCardParser->PropertyL(_L8("N"), valueTypeUid, EFalse);
       
   762 	CleanupStack::PushL(array);
       
   763 	TheTest(array->Count() == 1);
       
   764 	CParserPropertyValueCDesCArray* value = static_cast<CParserPropertyValueCDesCArray*>(array->At(0)->Value());
       
   765 	TheTest(value->Value()->Count() == 1);
       
   766 	const TPtrC pValue(value->Value()->MdcaPoint(0));
       
   767 	TheTest(pValue == _L("==="));
       
   768 	CleanupStack::PopAndDestroy(array);
       
   769 
       
   770 	CleanupStack::PopAndDestroy(vCardParser);
       
   771 	}
       
   772 
       
   773 void CTests::Test3L(CTests& aSelf)
       
   774 	{
       
   775 	_LIT(KFirstName,"\x3046\x3053\x3087"); //hiragana 'ukyo'
       
   776 	_LIT(KSurname,"\x3084\x307e\x3060"); //hiragana 'yamada'
       
   777 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   778 	CleanupStack::PushL(vCardParser);
       
   779 
       
   780 #ifndef TBUGFIX_INCLUDE_OOM
       
   781 	aSelf.iTempFiles->RegisterL(KVCardFileShiftJIS);
       
   782 	aSelf.iTempFiles->RegisterL(KVCardFileJIS);
       
   783 #endif	//TBUGFIX_INCLUDE_OOM
       
   784 
       
   785 	CDesCArrayFlat* desArray = new (ELeave) CDesCArrayFlat(5);
       
   786 	CleanupStack::PushL(desArray);
       
   787 	desArray->AppendL(KSurname);  //family name
       
   788 	desArray->AppendL(KFirstName);//given name
       
   789 	desArray->AppendL(KNullDesC); //additional names
       
   790 	desArray->AppendL(KNullDesC); //prefix
       
   791 	desArray->AppendL(KNullDesC); //suffix
       
   792 	CParserPropertyValue* value=new (ELeave) CParserPropertyValueCDesCArray(desArray);
       
   793   	CleanupStack::Pop(desArray);
       
   794 	CleanupStack::PushL(value);
       
   795 	// add a character set property parameter
       
   796 	CArrayPtr<CParserParam>* arrayOfParams = new(ELeave)CArrayPtrFlat<CParserParam>(5);
       
   797 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfParams,arrayOfParams));
       
   798 	CParserParam* parserParam=CParserParam::NewL(KVersitTokenCHARSET,KVersitTokenShiftJIS);
       
   799 	CleanupStack::PushL(parserParam);
       
   800     arrayOfParams->AppendL(parserParam);
       
   801 	CleanupStack::Pop(parserParam);
       
   802 	CParserGroupedProperty* property=CParserGroupedProperty::NewL(*value,KVersitTokenN,NULL,arrayOfParams);
       
   803 	CleanupStack::Pop(2,value); //value, arrayOfParams
       
   804 	vCardParser->AddPropertyL(property);
       
   805 
       
   806 	vCardParser->SetDefaultCharSet(Versit::EShiftJISCharSet);
       
   807 	aSelf.ExternaliseFileL(*vCardParser,KVCardFileShiftJIS);
       
   808 	vCardParser->SetDefaultCharSet(Versit::EJISCharSet);
       
   809 	aSelf.ExternaliseFileL(*vCardParser,KVCardFileJIS);
       
   810 	CleanupStack::PopAndDestroy(vCardParser);
       
   811 
       
   812 	TInt ii;
       
   813 	for (ii=2;ii>0;--ii)
       
   814 		{
       
   815 		vCardParser=CParserVCard::NewL();
       
   816 		CleanupStack::PushL(vCardParser);
       
   817 		aSelf.InternaliseFileL(*vCardParser,(ii==1? KVCardFileShiftJIS:KVCardFileJIS));
       
   818 		CArrayPtr<CParserProperty>* properties=vCardParser->PropertyL(KVersitTokenN,TUid::Uid(KVersitPropertyCDesCArrayUid));
       
   819   		if (properties)
       
   820 			{
       
   821 			CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfProperties,properties));
       
   822       		CParserProperty* property = (*properties)[0];
       
   823 			CParserPropertyValueCDesCArray* value = STATIC_CAST(CParserPropertyValueCDesCArray*,property->Value());
       
   824 			CDesCArray* array = value->Value();
       
   825 			const TInt count = array->MdcaCount();
       
   826 			TheTest(count>2);
       
   827 			//TPtrC ptr = array->MdcaPoint(0);
       
   828 			TheTest(array->MdcaPoint(0).Compare(KSurname)==0);
       
   829 			TheTest(array->MdcaPoint(1).Compare(KFirstName)==0);
       
   830 			CleanupStack::PopAndDestroy(properties);
       
   831 			}
       
   832 		CleanupStack::PopAndDestroy(vCardParser);
       
   833 		}
       
   834 	}
       
   835 
       
   836 void CTests::Test4L(CTests& aSelf)
       
   837 	{
       
   838 	_LIT8(KVCardData, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Some\\Escaped\\Text\r\nEND:VCARD\r\n\r\n");
       
   839 
       
   840 #ifndef TBUGFIX_INCLUDE_OOM
       
   841 	aSelf.iTempFiles->RegisterL(KBase64FileName);
       
   842 #endif	//TBUGFIX_INCLUDE_OOM
       
   843 
       
   844 	aSelf.CreateAndExternaliseVCardL(KVCardData,KBase64FileName,Versit::EBase64Encoding);
       
   845 
       
   846 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   847 	CleanupStack::PushL(vCardParser);
       
   848 
       
   849 	aSelf.InternaliseFileL(*vCardParser,KBase64FileName);
       
   850 
       
   851 	const TUid valueTypeUid = { KVersitPropertyCDesCArrayUid };
       
   852 	CArrayPtr<CParserProperty>* array = vCardParser->PropertyL(_L8("N"), valueTypeUid, EFalse);
       
   853 	CleanupStack::PushL(array);
       
   854 	TheTest(array->Count() == 1);
       
   855 	CParserPropertyValueCDesCArray* value = static_cast<CParserPropertyValueCDesCArray*>(array->At(0)->Value());
       
   856 	TheTest(value->Value()->Count() == 1);
       
   857 	const TPtrC pValue(value->Value()->MdcaPoint(0));
       
   858 	TheTest(pValue == _L("Some\\Escaped\\Text"));
       
   859 	//
       
   860 	CleanupStack::PopAndDestroy(array);
       
   861 
       
   862 	CleanupStack::PopAndDestroy(vCardParser);
       
   863 	}
       
   864 
       
   865 
       
   866 void CTests::Test5L(CTests& aSelf)
       
   867 	{
       
   868 	_LIT(KInputFileName,"Z:\\testfiles\\Test5_ASCII_Input.vcf");
       
   869 	_LIT(KOutputFileName,"C:\\testfiles\\Test5_Base64_Output.vcf");
       
   870 	_LIT(KCompareFileName,"C:\\testfiles\\Test5_ASCII_Output.vcf");
       
   871 
       
   872 	CParserVCard* vParser=CParserVCard::NewL();
       
   873 	CleanupStack::PushL(vParser);
       
   874 	aSelf.InternaliseFileL(*vParser,KInputFileName);
       
   875 	vParser->SetDefaultEncoding(Versit::EBase64Encoding);
       
   876 	aSelf.ExternaliseFileL(*vParser,KOutputFileName);
       
   877 	vParser->SetDefaultEncoding(Versit::ENoEncoding);
       
   878 	aSelf.ExternaliseFileL(*vParser,KCompareFileName);
       
   879 	CleanupStack::PopAndDestroy(vParser);
       
   880 	aSelf.CompareFilesL(KCompareFileName,KInputFileName,KNullDesC);
       
   881 	}
       
   882 
       
   883 
       
   884 // This test also verifies that PREQ1131 requirements are met:
       
   885 // (1) Comprise one or more lines where one or more of the lines is longer than 76 characters (eg a URL) 
       
   886 // (2) Comprise multiple lines which have been folded without any LWSP characters following the CRLF line break 
       
   887 void CTests::Test6L(CTests& aSelf)
       
   888 	{
       
   889 	//Line wrapping in Ascii
       
   890 	_LIT(KTestAscii,"Line Wrapping (WAG-4Z8D8C)");// bug fix
       
   891 	_LIT(KFileAscii,"AsciiLineFolding");
       
   892 	//compare files to make sure the break at right point
       
   893 	aSelf.TestFileL(ETvCard,KTestAscii,KFileAscii);
       
   894 	_LIT(KFileInputAscii,"C:\\TestFiles\\OAsciiLineFolding.VCF");
       
   895 	//internalise the output and check the property value to make sure the value has been read back right
       
   896 	aSelf.LineWrappingTestL(KFileInputAscii);
       
   897 
       
   898 	//Line wrapping in Base64 encoding
       
   899 	_LIT(KTestBase64,"Line Wrapping in base64");
       
   900 	_LIT(KFileBase64,"Base64LineFolding");
       
   901 	aSelf.TestFileL(ETvCard,KTestBase64,KFileBase64,Versit::EUSAsciiCharSet,Versit::EBase64Encoding);
       
   902 	_LIT(KFileInputBase64,"C:\\TestFiles\\oBase64LineFolding.VCF");
       
   903 	aSelf.LineWrappingTestL(KFileInputBase64);
       
   904 	
       
   905 	//Test line wrapping in Base64 encoding where there are no whitespace at the beginning of each new line in the vcard
       
   906 	//The TestFileL() test is omitted as the generated file will create the whitespace by default
       
   907 	_LIT(KFileInputBase64NoSpace,"Z:\\TestFiles\\cBase64NoSpaceLineFolding.VCF");
       
   908 	aSelf.LineWrappingTestL(KFileInputBase64NoSpace);
       
   909 	
       
   910 	//Line wrapping in QP encoding
       
   911 	_LIT(KTestQP,"Line Wrapping in base64");
       
   912 	_LIT(KFileQP,"QPLineFolding");
       
   913 	aSelf.TestFileL(ETvCard,KTestQP,KFileQP,Versit::EUSAsciiCharSet,Versit::EQuotedPrintableEncoding);
       
   914 	_LIT(KFileInputQP,"C:\\TestFiles\\oQPLineFolding.VCF");
       
   915 	aSelf.LineWrappingTestL(KFileInputQP);
       
   916 	}
       
   917 
       
   918 void CTests::LineWrappingTestL(const TDesC& aFullFileName)
       
   919 	{
       
   920 	//The following line is extracted from the original file "iAsciiLineFolding.vcf"
       
   921 	_LIT(KNoteText,"This is a very long description that exists on along line. Thisisaverylongdescriptionthatexistsonalongline.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaThisisaverylong... It breaks here.");
       
   922 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   923 	CleanupStack::PushL(vCardParser);
       
   924 	InternaliseFileL(*vCardParser,aFullFileName);
       
   925 	CArrayPtr<CParserProperty>* properties=vCardParser->PropertyL(KVersitTokenNOTE,TUid::Uid(KVersitPropertyHBufCUid));
       
   926   	if (properties)
       
   927 		{
       
   928 		CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfProperties,properties));
       
   929        	CParserProperty* property = (*properties)[0];
       
   930 		CParserPropertyValueHBufC* value = STATIC_CAST(CParserPropertyValueHBufC*,property->Value());
       
   931 		TPtrC externalisedNote(value->Value());
       
   932 		TheTest(externalisedNote.Compare(KNoteText)==0);
       
   933 		CleanupStack::PopAndDestroy(properties);
       
   934 		}
       
   935 
       
   936 	CleanupStack::PopAndDestroy(vCardParser);
       
   937 	}
       
   938 
       
   939 void CTests::Test7L(CTests& aSelf)
       
   940 	{
       
   941 	_LIT(KInputFileName,"Z:\\testfiles\\iTest7.vcf");
       
   942 	_LIT(KOutputFileName,"C:\\testfiles\\oTest7.vcf");
       
   943 	CParserVCard* vParser = CParserVCard::NewL();
       
   944 	CleanupStack::PushL(vParser);
       
   945 	aSelf.InternaliseFileL(*vParser,KInputFileName);
       
   946 	aSelf.ExternaliseFileL(*vParser,KOutputFileName);
       
   947 	CleanupStack::PopAndDestroy(vParser);
       
   948 	}
       
   949 
       
   950 void CTests::Test8L(CTests& aSelf)
       
   951 	{
       
   952 	_LIT(KInputFileName,"GroupedProperty");
       
   953 	_LIT8(KPgroupNameA,"A");
       
   954 	_LIT8(KPgroupNameB,"BBBB");
       
   955 
       
   956 	_LIT(KTestGroupProperty,"Test grouped property");
       
   957 	_LIT(KFileName,"GroupedProperty");
       
   958 	aSelf.TestFileL(ETvCard,KTestGroupProperty,KFileName);
       
   959 
       
   960 	CParserVCard* vParser = CParserVCard::NewL();
       
   961 	CleanupStack::PushL(vParser);
       
   962 	TFileName fullFileName;
       
   963 	aSelf.ExistingFileName(ETvCard,fullFileName,'I',KInputFileName);
       
   964 	aSelf.InternaliseFileL(*vParser,fullFileName);
       
   965     CArrayPtr<CParserProperty>* arrayOfGroupedPropertiesA=NULL;
       
   966 	CArrayPtr<CParserProperty>* arrayOfGroupedPropertiesB=NULL;
       
   967 	CParserGroupedProperty* property=NULL;
       
   968 
       
   969 	arrayOfGroupedPropertiesA=vParser->GroupOfPropertiesL(KPgroupNameA);
       
   970 	TInt count=arrayOfGroupedPropertiesA->Count();
       
   971 	TheTest(count==2);
       
   972 
       
   973 	for(TInt i=0;i<count;++i)
       
   974 		{
       
   975 		property=(CParserGroupedProperty*)(*arrayOfGroupedPropertiesA)[i];
       
   976 		TheTest(property->Group(KPgroupNameA));
       
   977 		TheTest(!property->Group(KPgroupNameB));
       
   978 		}
       
   979 	delete arrayOfGroupedPropertiesA;
       
   980 
       
   981 	arrayOfGroupedPropertiesB=vParser->GroupOfPropertiesL(KPgroupNameB);
       
   982 	count=arrayOfGroupedPropertiesB->Count();
       
   983 	TheTest(count==3);
       
   984 	for(TInt j=0;j<count;++j)
       
   985 		{
       
   986 		property=(CParserGroupedProperty*)(*arrayOfGroupedPropertiesB)[j];
       
   987 		TheTest(property->Group(KPgroupNameB));
       
   988 		TheTest(!property->Group(KPgroupNameA));
       
   989 		}
       
   990 	delete arrayOfGroupedPropertiesB;
       
   991 	CleanupStack::PopAndDestroy(vParser);
       
   992 	}
       
   993 
       
   994 void CTests::Test9L(CTests& aSelf)
       
   995 	{
       
   996 	//create a vCard and externalise it
       
   997 	_LIT(KNote,"\x4e79\x4f19\x5032"); //Jis code x3030 x305c x315c
       
   998 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   999 	CleanupStack::PushL(vCardParser);
       
  1000 	CParserPropertyValue* value=CParserPropertyValueHBufC::NewL(KNote);
       
  1001 	CleanupStack::PushL(value);
       
  1002 	// add a character set property parameter
       
  1003 	CArrayPtr<CParserParam>* arrayOfParams = new(ELeave)CArrayPtrFlat<CParserParam>(5);
       
  1004 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfParams,arrayOfParams));
       
  1005 	CParserParam* parserParam=CParserParam::NewL(KVersitTokenCHARSET,KVersitTokenJIS);
       
  1006 	CleanupStack::PushL(parserParam);
       
  1007     arrayOfParams->AppendL(parserParam);
       
  1008 	CleanupStack::Pop(parserParam);
       
  1009 	CParserGroupedProperty* property=CParserGroupedProperty::NewL(*value,KVersitTokenNOTE,NULL,arrayOfParams);
       
  1010 	CleanupStack::Pop(2,value); //value, arrayOfParams
       
  1011 	vCardParser->AddPropertyL(property);
       
  1012 
       
  1013 #ifndef TBUGFIX_INCLUDE_OOM
       
  1014 	aSelf.iTempFiles->RegisterL(KVCardFileJIS);
       
  1015 #endif	//TBUGFIX_INCLUDE_OOM
       
  1016 
       
  1017 	vCardParser->SetDefaultCharSet(Versit::EJISCharSet);
       
  1018 	aSelf.ExternaliseFileL(*vCardParser,KVCardFileJIS);
       
  1019 	CleanupStack::PopAndDestroy(vCardParser);
       
  1020 //internalise the vCard externalised and check the value to see if it is identical
       
  1021 	vCardParser=CParserVCard::NewL();
       
  1022 	CleanupStack::PushL(vCardParser);
       
  1023 	aSelf.InternaliseFileL(*vCardParser,KVCardFileJIS);
       
  1024 	CArrayPtr<CParserProperty>* properties=vCardParser->PropertyL(KVersitTokenNOTE,TUid::Uid(KVersitPropertyHBufCUid));
       
  1025   	if (properties)
       
  1026 		{
       
  1027 		CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfProperties,properties));
       
  1028       	CParserProperty* property = (*properties)[0];
       
  1029 		CParserPropertyValueHBufC* value = STATIC_CAST(CParserPropertyValueHBufC*,property->Value());
       
  1030 		TPtrC note(value->Value());
       
  1031 		TheTest(note.Compare(KNote)==0);
       
  1032 		CleanupStack::PopAndDestroy(properties);
       
  1033 		}
       
  1034 	CleanupStack::PopAndDestroy(vCardParser);
       
  1035 	}
       
  1036 
       
  1037 void CTests::Test10L(CTests& aSelf)
       
  1038 	{
       
  1039 	_LIT(KTest1,"vCard UTF-8");
       
  1040 	_LIT(KFile1,"AutoD");
       
  1041 	TParserSetUp setUp(ETvCard,ETrue);
       
  1042 	aSelf.TestFileL(KTest1,KFile1,setUp);
       
  1043 	_LIT(KTest2,"vCal Shift-JIS");
       
  1044 	_LIT(KFile2,"AutoD2");
       
  1045 	setUp.iType=ETvCal;
       
  1046 	setUp.iCharset=Versit::EShiftJISCharSet;
       
  1047 	aSelf.TestFileL(KTest2,KFile2,setUp);
       
  1048 	}
       
  1049 
       
  1050 
       
  1051 void CTests::Test11L(CTests& aSelf)
       
  1052 	{
       
  1053 	_LIT(KInputFileName,"Z:\\testvcards\\various\\6.vcs");
       
  1054 	CParserVCal* vParser = CParserVCal::NewL();
       
  1055 	CleanupStack::PushL(vParser);
       
  1056 	aSelf.InternaliseFileL(*vParser,KInputFileName);
       
  1057 	CleanupStack::PopAndDestroy(vParser);
       
  1058 	}
       
  1059 
       
  1060 
       
  1061 void CTests::TestHugeVCardL(CTests& aSelf)
       
  1062 	{
       
  1063 	aSelf.iTempFiles->RegisterL(KExportHugeVCardFileName());
       
  1064 	CParserVCard* vCardParser=CParserVCard::NewL();
       
  1065 	CleanupStack::PushL(vCardParser);
       
  1066 
       
  1067 	//Import the vCard
       
  1068 	aSelf.InternaliseFileL(*vCardParser,KHugeVCardFileName);
       
  1069 	
       
  1070 	aSelf.ExternaliseFileL(*vCardParser,KExportHugeVCardFileName);
       
  1071 	CleanupStack::PopAndDestroy(vCardParser);
       
  1072 }
       
  1073 
       
  1074 void CTests::TestNullDateL(CTests& aSelf)
       
  1075 	{
       
  1076 	_LIT(KVcsNullDataFileName,"Z:\\testvcards\\various\\nulldate.vcf");
       
  1077 	RFileReadStream fileReadStream;
       
  1078 	User::LeaveIfError(fileReadStream.Open(aSelf.iFsSession,KVcsNullDataFileName,EFileRead));
       
  1079 	CleanupClosePushL(fileReadStream); //
       
  1080 
       
  1081 	CParserVCard* parser = CParserVCard::NewL();
       
  1082 	CleanupStack::PushL(parser);
       
  1083 	
       
  1084 	//internalize vcf file
       
  1085 	fileReadStream>>(*parser);
       
  1086 	
       
  1087 	//now make sure the parser object contains a birthday property (KVersitTokenBDAY)
       
  1088 	TBool containsBirthday=EFalse;
       
  1089 	CArrayPtr<CParserProperty>* properties=parser->ArrayOfProperties(EFalse);
       
  1090 	for (TInt i=0;i<properties->Count();i++)
       
  1091 		{
       
  1092 		CParserProperty* property=properties->At(i);
       
  1093 		if (property->Name()==KVersitTokenBDAY)
       
  1094 			{
       
  1095 			containsBirthday=ETrue;
       
  1096 			break;
       
  1097 			}
       
  1098 		}
       
  1099 
       
  1100 	TheTest(containsBirthday);
       
  1101 
       
  1102 	CleanupStack::PopAndDestroy(2,&fileReadStream); // vParser
       
  1103 	}
       
  1104 
       
  1105 void CTests::TestJapanL(CTests& aSelf)
       
  1106 	{
       
  1107 	TInt test=0;
       
  1108 	_LIT(KTest1,"QP Output");
       
  1109 	aSelf.DoJapanTestL(KTest1,++test);	//Had to remove a Yen symbol and ";" to stop it hitting another bug.
       
  1110 	_LIT(KTest2,"Folding Long Data");
       
  1111 	aSelf.DoJapanTestL(KTest2,++test);
       
  1112 	_LIT(KTest3,"Alarm Note Field");
       
  1113 	aSelf.DoJapanTestL(KTest3,++test,ETvCal);
       
  1114 	_LIT(KTest4,"Folding Fields");
       
  1115 	aSelf.DoJapanTestL(KTest4,++test);
       
  1116 	_LIT(KTest5,"ShiftJIS Escapes");
       
  1117 	aSelf.DoJapanTestL(KTest5,++test);		//Yen symbol not treated as an escape character
       
  1118 	_LIT(KTest6,"ShiftJIS QP Escape 1");
       
  1119 	aSelf.DoJapanTestL(KTest6,++test);
       
  1120 	_LIT(KTest7,"ShiftJIS QP Escape 2");
       
  1121 	aSelf.DoJapanTestL(KTest7,++test);
       
  1122 	_LIT(KTest8,"QP Line Length");
       
  1123 	aSelf.DoJapanTestL(KTest8,++test);
       
  1124 	_LIT(KTest9,"Encoding ;");
       
  1125 	aSelf.DoJapanTestL(KTest9,++test);
       
  1126 	//_LIT(KTest10,"Truncated Data");
       
  1127 	++test;//DoJapanTestL(KTest10,++test);		//Leaves because of truncated data and it has been tested in expected leave
       
  1128 	//_LIT(KTest11,"Data 11a");
       
  1129 	++test;//DoJapanTestL(KTest11,++test);		//comparing is failed because to externalise the code point 0x5c(escape), it is recongnised as "\" when it is in shiftjis charset, and yen sign when it is in all other charset
       
  1130 	}
       
  1131 
       
  1132 void CTests::LeaveTestsL(CTests& aSelf)
       
  1133 	{
       
  1134 	_LIT(KTest1,"No End");
       
  1135 	_LIT(KFile1,"NoEnd");
       
  1136 	aSelf.DoLeaveTestL(ETvCard,KErrEof,KTest1,KFile1);
       
  1137 	_LIT(KTest2,"Half Line");
       
  1138 	_LIT(KFile2,"HalfLine");
       
  1139 	aSelf.DoLeaveTestL(ETvCard,KErrEof,KTest2,KFile2);
       
  1140 //	_LIT(KTest3,"Non-LeapDay"); This has been changed so that it is an internal leave
       
  1141 //	_LIT(KFile3,"Feb29");
       
  1142 //	DoLeaveTestL(ETvCal,KErrGeneral,KTest3,KFile3);
       
  1143 	_LIT(KTest4,"Entity Name 1");
       
  1144 	_LIT(KFile4,"EnName1");
       
  1145 	aSelf.DoLeaveTestL(ETvCal,KErrNotFound,KTest4,KFile4);
       
  1146 	_LIT(KTest5,"Entity Name 2");
       
  1147 	_LIT(KFile5,"EnName2");
       
  1148 	aSelf.DoLeaveTestL(ETvCal,KErrNotFound,KTest5,KFile5);
       
  1149 	_LIT(KTest6,"Entity Name 3");
       
  1150 	_LIT(KFile6,"EnName3");
       
  1151 	aSelf.DoLeaveTestL(ETvCard,KErrNotFound,KTest6,KFile6);
       
  1152 	_LIT(KTest7,"Entity Name 4");
       
  1153 	_LIT(KFile7,"EnName4");
       
  1154 	aSelf.DoLeaveTestL(ETvCard,KErrNotFound,KTest7,KFile7);
       
  1155 	_LIT(KTest8,"2 Begin's");
       
  1156 	_LIT(KFile8,"Begin2");
       
  1157 	aSelf.DoLeaveTestL(ETvCard,KErrNotSupported,KTest8,KFile8);
       
  1158 	_LIT(KTest9,"2 End's");
       
  1159 	_LIT(KFile9,"End2");
       
  1160 	aSelf.DoLeaveTestL(ETvCard,KErrEof,KTest9,KFile9);
       
  1161 	_LIT(KTest10,"3 Begin's");
       
  1162 	_LIT(KFile10,"Begin3");
       
  1163 	aSelf.DoLeaveTestL(ETvCal,KErrNotFound,KTest10,KFile10);
       
  1164 	_LIT(KTestNoLF,"No Line Feed");
       
  1165 	_LIT(KFileNoLF,"NoLF");
       
  1166 	aSelf.DoLeaveTestL(ETvCal,KErrEof,KTestNoLF,KFileNoLF);
       
  1167 	_LIT(KTestNestedAgent,"Nested Agent");
       
  1168 	_LIT(KFileNestedAgent,"NestedAgent");
       
  1169 	aSelf.DoLeaveTestL(ETvCard,KErrNotSupported,KTestNestedAgent,KFileNestedAgent);
       
  1170 
       
  1171 	#ifdef _DEBUG
       
  1172 	_LIT(KTest11,"OOM Leave1");
       
  1173 	_LIT(KFile3,"Feb29");
       
  1174 	aSelf.DoOomTestL(ETvCard,8,KTest11,KFile1);
       
  1175 	_LIT(KTest12,"OOM Leave2");
       
  1176 	aSelf.DoOomTestL(ETvCard,10,KTest12,KFile2);
       
  1177 	_LIT(KTest13,"OOM Leave3");
       
  1178 	aSelf.DoOomTestL(ETvCal,12,KTest13,KFile3);
       
  1179 	
       
  1180 	#endif
       
  1181 	}
       
  1182 
       
  1183 void CTests::SyncMLTestsL(CTests& aSelf)
       
  1184 	{
       
  1185 	_LIT(KTest1,"Japan");		//9 hours ahead of UTC
       
  1186 	aSelf.DoSyncMLTestL(9*eSecondsPerHour,KTest1,KTest1);
       
  1187 	_LIT(KTest2,"UK");			//Same as UTC
       
  1188 	aSelf.DoSyncMLTestL(0,KTest2,KTest2);
       
  1189 	_LIT(KTest3,"NewYork");		//5 hours behind UTC
       
  1190 	aSelf.DoSyncMLTestL(-5*eSecondsPerHour,KTest3,KTest3);
       
  1191 	}
       
  1192 
       
  1193 void CTests::TestAlarmRepeatCountL(CTests& aSelf)
       
  1194 	{
       
  1195 	_LIT(KAlarmRepeatCount,"Test alarm repeat count");
       
  1196 	_LIT(KFileName,"alarmRepeatCount");
       
  1197 	
       
  1198 	//Compare output file with the input file. They should be identical.
       
  1199 	aSelf.TestFileL(ETvCal,KAlarmRepeatCount,KFileName);
       
  1200 	
       
  1201 	//Internalise the input file again
       
  1202 	CParserVCal* vParser = CParserVCal::NewL();
       
  1203 	CleanupStack::PushL(vParser);
       
  1204 	TFileName fullFileName;
       
  1205 	aSelf.ExistingFileName(ETvCal,fullFileName,'I',KFileName);
       
  1206 	aSelf.InternaliseFileL(*vParser,fullFileName);
       
  1207  
       
  1208     //Check the repeat count of the alarm
       
  1209    	CArrayPtr<CVersitParser>* entities = vParser->ArrayOfEntities(EFalse);
       
  1210    	
       
  1211    	CArrayPtr<CParserProperty>* properties =(*entities)[0]->PropertyL(KVersitTokenAALARM, TUid::Uid(KVCalPropertyAlarmUid), EFalse);
       
  1212 
       
  1213 	CleanupStack::PushL(properties);
       
  1214 	CParserPropertyValueAlarm* alarmProperty = STATIC_CAST(CParserPropertyValueAlarm*, (*properties)[0]->Value()); 
       
  1215 	TheTest(alarmProperty->Value()->iRepeatCount==0);
       
  1216 	CleanupStack::PopAndDestroy(properties);
       
  1217 	
       
  1218     CleanupStack::PopAndDestroy(vParser);
       
  1219 	}
       
  1220 
       
  1221 // This test case had been implemented for defect DEF112543.
       
  1222 // Some car kits don't understand the telephone number if '#' is encoded in QP
       
  1223 void CTests::TestHashSignEncodingL(CTests& aSelf)
       
  1224 	{
       
  1225 #ifndef TBUGFIX_INCLUDE_OOM
       
  1226 	aSelf.iTempFiles->RegisterL(KQPHashFileName);
       
  1227 	aSelf.iTempFiles->RegisterL(KOutputQPHashFileName);
       
  1228 #endif	//TBUGFIX_INCLUDE_OOM
       
  1229 
       
  1230 	//Test VCard file	  
       
  1231 	_LIT8(KVCardData,	"BEGIN:VCARD\r\n"
       
  1232 						"VERSION:2.1\r\n"
       
  1233 						"TEL;HOME:#01#12546\r\n"
       
  1234 						"ADR;HOME;ENCODING=QUOTED-PRINTABLE:;;Address=20line1=0D=0Aaddress=20line2\r\n"
       
  1235 						"END:VCARD\r\n");
       
  1236 	
       
  1237 	//Save the test VCard file
       
  1238 	TheTest.Printf(_L("Save test Vcard file to be compared with exported vcard file later\n"));					
       
  1239 	RFile testFile;
       
  1240 	User::LeaveIfError(testFile.Replace(aSelf.iFsSession,KQPHashFileName,EFileWrite ));
       
  1241 	testFile.Write(KVCardData);
       
  1242 	testFile.Close();
       
  1243 	
       
  1244 	
       
  1245 	//Create a VCard						
       
  1246 	CParserVCard* vCardParser=CParserVCard::NewL();
       
  1247 	CleanupStack::PushL(vCardParser);
       
  1248 	
       
  1249 	//Create a tel value
       
  1250 	_LIT(KTelValue, "#01#12546");
       
  1251 	CDesCArrayFlat* telArray = new (ELeave) CDesCArrayFlat(3);
       
  1252 	CleanupStack::PushL(telArray);
       
  1253 	telArray->AppendL(KTelValue);  
       
  1254 	CParserPropertyValue* telValue=new (ELeave) CParserPropertyValueCDesCArray(telArray);
       
  1255   	CleanupStack::Pop(telArray);  
       
  1256 	CleanupStack::PushL(telValue);
       
  1257 	// Create a property parameter "HOME"
       
  1258 	CArrayPtr<CParserParam>* arrayOfTelParams = new(ELeave)CArrayPtrFlat<CParserParam>(1);
       
  1259 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfParams,arrayOfTelParams));
       
  1260 	CParserParam* homeParam=CParserParam::NewL(_L8("HOME"),KNullDesC);
       
  1261 	CleanupStack::PushL(homeParam);
       
  1262     arrayOfTelParams->AppendL(homeParam);
       
  1263 	CleanupStack::Pop(homeParam);
       
  1264 	//Create a TEL property 
       
  1265 	CParserProperty* telProperty=CParserProperty::NewL(*telValue,KVersitTokenTEL,arrayOfTelParams);
       
  1266 	CleanupStack::Pop(arrayOfTelParams);
       
  1267 	CleanupStack::Pop(telValue);
       
  1268 	//Add the TEL property to the VCard
       
  1269 	CleanupStack::PushL(telProperty);
       
  1270 	vCardParser->AddPropertyL(telProperty);
       
  1271 	CleanupStack::Pop(telProperty);
       
  1272 	
       
  1273 	//Create an address value
       
  1274 	_LIT(KAddrValue, "Address line1\r\naddress line2");
       
  1275 	CDesCArrayFlat* addrArray = new (ELeave) CDesCArrayFlat(3);
       
  1276 	CleanupStack::PushL(addrArray);
       
  1277 	addrArray->AppendL(KNullDesC);
       
  1278 	addrArray->AppendL(KNullDesC);
       
  1279 	addrArray->AppendL(KAddrValue);  
       
  1280 	CParserPropertyValue* addrValue=new (ELeave) CParserPropertyValueCDesCArray(addrArray);
       
  1281   	CleanupStack::Pop(addrArray);
       
  1282   	CleanupStack::PushL(addrValue);
       
  1283 	// Create a property parameter "HOME"
       
  1284 	CArrayPtr<CParserParam>* arrayOfParams = new(ELeave)CArrayPtrFlat<CParserParam>(1);
       
  1285 	CleanupStack::PushL(TCleanupItem(ResetAndDestroyArrayOfParams,arrayOfParams));
       
  1286 	CParserParam* parserParam=CParserParam::NewL(_L8("HOME"),KNullDesC);
       
  1287 	CleanupStack::PushL(parserParam);
       
  1288     arrayOfParams->AppendL(parserParam);
       
  1289 	CleanupStack::Pop(parserParam);
       
  1290 	//Create an ADR property 
       
  1291 	CParserProperty* property=CParserProperty::NewL(*addrValue,KVersitTokenADR,arrayOfParams);
       
  1292 	CleanupStack::Pop(2, addrValue);
       
  1293 	//Add the ADR property to the VCard
       
  1294 	CleanupStack::PushL(property);
       
  1295 	vCardParser->AddPropertyL(property);
       
  1296 	CleanupStack::Pop(property);
       
  1297 
       
  1298 	//Export the VCard
       
  1299 	aSelf.ExternaliseFileL(*vCardParser,KOutputQPHashFileName);
       
  1300 
       
  1301 	CleanupStack::PopAndDestroy(vCardParser);
       
  1302 
       
  1303 	//Compare the VCard exported with the earlier saved VCard test file
       
  1304 	aSelf.CompareFilesL(KQPFileName, KOutputQPFileName);	
       
  1305 	}
       
  1306 
       
  1307 void CTests::TestBase64ExtensionL(CTests& aSelf)
       
  1308 	{
       
  1309 	TBool compareFile = aSelf.iBase64Extension?ETrue:EFalse;//If MVersitPlugInExtensionBase64Ending is not impletmented and set, non-standard base64 data is not internalised correctly. 
       
  1310 	_LIT(KTestVCALBase64vCard,"Base64 vCard Test");
       
  1311 	_LIT(KFileVCALBase64,"newbase64");
       
  1312 	aSelf.TestFileL(ETvCard,KTestVCALBase64vCard,KFileVCALBase64, Versit::EUSAsciiCharSet, Versit::ENoEncoding, compareFile );
       
  1313 	_LIT(KTestVCALBase64vCal,"Base64 vCal Test");
       
  1314 	aSelf.TestFileL(ETvCal,KTestVCALBase64vCal,KFileVCALBase64, Versit::EUSAsciiCharSet, Versit::ENoEncoding, compareFile );// a vCal with some invalid data
       
  1315 	_LIT(KTestVCALBase64vTrigger,"Base64 vTrigger Test");
       
  1316 	_LIT(KFileVCALBase64vTrigger,"vtrigger");
       
  1317 	aSelf.TestFileL(ETvCard,KTestVCALBase64vTrigger,KFileVCALBase64vTrigger, Versit::EUSAsciiCharSet, Versit::ENoEncoding, compareFile );
       
  1318 	}
       
  1319 
       
  1320 void CTests::TestL(CTests& aSelf)
       
  1321 	{
       
  1322 	TRAPD(err, TestBase64ExtensionL(aSelf))
       
  1323 	
       
  1324 	if (aSelf.iBase64Extension)
       
  1325 		{//If MVersitPlugInExtensionBase64Ending is not impletmented and set, non-standard base64 data is not internalised correctly. 
       
  1326 		TheTest(err == KErrNone);
       
  1327 		}
       
  1328 
       
  1329 	_LIT(KTestVCARD,"General vCard Test");
       
  1330 	_LIT(KFileVCARD,"TestVCard");
       
  1331 	aSelf.TestFileL(ETvCard,KTestVCARD,KFileVCARD);//a complete vCard with some invalid data
       
  1332 	_LIT(KTestVCAL,"General vCal Test");
       
  1333 	_LIT(KFileVCAL,"TestVCal");
       
  1334 	aSelf.TestFileL(ETvCal,KTestVCAL,KFileVCAL);// a vCal with some invalid data
       
  1335 	_LIT(KTest1,"Quoted Printable Tabs");
       
  1336 	_LIT(KFile1,"Tabs");
       
  1337 	aSelf.TestFileL(ETvCal,KTest1,KFile1);// Make sure the QP is auto-applied when a tab is included in the text
       
  1338 	_LIT(KTest2,"Shift-JIS with \\ (VAN-4YQGX3)");// bug fix
       
  1339 	_LIT(KFile2,"ShJisEs");
       
  1340 	aSelf.TestFileL(ETvCard,KTest2,KFile2,Versit::EShiftJISCharSet);
       
  1341 	_LIT(KTest3,"Alarm Durations (EVS-522G7D)");// bug fix
       
  1342 	_LIT(KFile3,"TimePer");
       
  1343 	aSelf.TestFileL(ETvCal,KTest3,KFile3);
       
  1344 	_LIT(KTest4,"Dalarm's display string (EVS-4ZUJBC)"); // bug fix
       
  1345 	_LIT(KFile4,"Dalarm");
       
  1346 	aSelf.TestFileL(ETvCal,KTest4,KFile4,Versit::EShiftJISCharSet);
       
  1347 	_LIT(KTest5,"Bad Base64 Data");
       
  1348 	_LIT(KFile5,"Base64");
       
  1349 	aSelf.TestFileL(ETvCard,KTest5,KFile5);
       
  1350 	_LIT(KTest6,"Alarm's and Base64");
       
  1351 	_LIT(KFile6,"Dalarm2");
       
  1352 	aSelf.TestFileL(ETvCal,KTest6,KFile6,Versit::EUSAsciiCharSet,Versit::EBase64Encoding);
       
  1353 	_LIT(KTest7,"Space & Wrapping");
       
  1354 	_LIT(KFile7,"Wrap");
       
  1355 	aSelf.TestFileL(ETvCal,KTest7,KFile7);
       
  1356 	//aSelf.TestFileL(ETvCard,KTest8,KFile8);
       
  1357 	//_LIT(KTest9,"GBK & QuotedPrintable");		//Doesn't work with CharConvn name matching
       
  1358 	//_LIT(KFile9,"GBK");
       
  1359 	//TestFileL(ETvCard,KTest9,KFile9,Versit::EGBKCharSet,Versit::EBase64Encoding);
       
  1360 	_LIT(KTest10,"Shift Jis");
       
  1361 	_LIT(KFile10,"ShiftJis");
       
  1362 	aSelf.TestFileL(ETvCal,KTest10,KFile10,Versit::EShiftJISCharSet);
       
  1363 	_LIT(KTest11,"vCard File");
       
  1364 	_LIT(KFile11,"vCard");
       
  1365 	aSelf.TestFileL(ETvCard,KTest11,KFile11);
       
  1366 	_LIT(KTest12,"vCal File");
       
  1367 	_LIT(KFile12,"vCal");
       
  1368 	aSelf.TestFileL(ETvCal,KTest12,KFile12);
       
  1369 	_LIT(KTest13,"Base64 encoded End");
       
  1370 	_LIT(KFile13,"EndBa64");
       
  1371 	aSelf.TestFileL(ETvCal,KTest13,KFile13);
       
  1372 	_LIT(KTestTimeZone,"Time-zone check");// bug fix
       
  1373 	_LIT(KFile14a,"TimeZoneP");
       
  1374 	_LIT(KFile14b,"TimeZoneN");
       
  1375 	aSelf.TestFileL(ETvCal,KTestTimeZone,KFile14a);
       
  1376 	aSelf.TestFileL(ETvCal,KTestTimeZone,KFile14b);
       
  1377 	_LIT(KTest15,"Wrapping on linelength");
       
  1378 	_LIT(KFile15,"Wrap2");
       
  1379 	aSelf.TestFileL(ETvCal,KTest15,KFile15);
       
  1380 	_LIT(KTest16,"TimeZone and DayLight Adjustment");
       
  1381 	_LIT(KFile16,"TZone");
       
  1382 	aSelf.TestFileL(ETvCal,KTest16,KFile16);
       
  1383 	_LIT(KTest17,"TimeZone and DayLight Syntax");
       
  1384 	_LIT(KFile17,"TZone2");
       
  1385 	aSelf.TestFileL(ETvCal|ETuseBaseParser,KTest17,KFile17);
       
  1386 	_LIT(KTest18,"String ends in '\\'");
       
  1387 	_LIT(KFile18,"ESlash");
       
  1388 	aSelf.TestFileL(ETvCard,KTest18,KFile18);
       
  1389 	_LIT(KTest19,"Null Parameters");
       
  1390 	_LIT(KFile19,"NullPar");
       
  1391 	aSelf.TestFileL(ETvCal,KTest19,KFile19);
       
  1392 	_LIT(KTest20,"ShiftJIS Escape (Yen) 1");
       
  1393 	_LIT(KFile20,"YenEsc1");
       
  1394 	aSelf.TestFileL(ETvCard,KTest20,KFile20);
       
  1395 	_LIT(KTest21,"ShiftJIS Escape (Yen) 2");
       
  1396 	_LIT(KFile21,"YenEsc2");
       
  1397 	aSelf.TestFileL(ETvCard,KTest21,KFile21,Versit::EShiftJISCharSet);
       
  1398 	_LIT(KTest22,"Escaping Parameters");
       
  1399 	_LIT(KFile22,"ParamE");
       
  1400 	aSelf.TestFileL(ETvCard,KTest22,KFile22);
       
  1401 	_LIT(KTest23,"Line Wrap Bug: SVG-58ZECH");
       
  1402 	_LIT(KFile23,"Fred");
       
  1403 	aSelf.TestFileL(ETvCard,KTest23,KFile23);
       
  1404 	_LIT(KTest24,"non-standard agent vCard Bug: HUN_5ELH9C");
       
  1405 	_LIT(KFile24,"NonStandardAgent");
       
  1406 	aSelf.TestFileL(ETvCard,KTest24,KFile24);
       
  1407 	_LIT(KTest25,"RRule defect INC017322");// bug fix
       
  1408 	_LIT(KFile25,"RRule");
       
  1409 	aSelf.TestFileL(ETvCal,KTest25,KFile25);
       
  1410 	_LIT(KTest26,"Blank line defect DEF022279");// bug fix
       
  1411 	_LIT(KFile26,"BlankLines");
       
  1412 	aSelf.TestFileL(ETvCard,KTest26,KFile26);
       
  1413 	_LIT(KTest27,"Defect fix INC021811");
       
  1414 	_LIT(KFile27,"LineFeed");
       
  1415 	aSelf.TestFileL(ETvCal,KTest27,KFile27);//file end with<LF>
       
  1416 	_LIT(KTest28,"Base64 Data with whitespace defect DEF036630");// bug fix
       
  1417 	_LIT(KFile28,"Base64ws");
       
  1418 	aSelf.TestFileL(ETvCard,KTest28,KFile28);
       
  1419 	_LIT(KTest29,"Defect DEF078802 - Ignore junk lines b/w vCal entities");// bug fix
       
  1420 	_LIT(KFile29,"JunkLine");
       
  1421 	aSelf.TestFileL(ETvCal,KTest29,KFile29);
       
  1422 	_LIT(KTest30,"Attachment Test");
       
  1423 	_LIT(KFile30,"attachment");
       
  1424 	aSelf.TestFileL(ETvCal,KTest30,KFile30);// a vCal with some invalid data
       
  1425 
       
  1426 	}
       
  1427 	
       
  1428 void CTests::AllTestsL()
       
  1429 	{
       
  1430 	TheTest.Start(_L("TBugfix general tests"));
       
  1431 	
       
  1432 	TheTest.Next(_L("Simple Write File"));
       
  1433 	Test0L(*this);		//Does not require any data files to be present
       
  1434 	
       
  1435 	TheTest.Next(_L("versit files test"));
       
  1436 	TestL(*this);		//File Tests - externalise a file and compare the resultant with the expecting data
       
  1437 
       
  1438 	iBase64Extension = CTestVersitExtension::NewL();
       
  1439 
       
  1440 	TestL(*this);
       
  1441 	doOOMTest(*this, CTests::TestBase64ExtensionL, 0);
       
  1442 	LeaveTestsL(*this);
       
  1443 
       
  1444 	delete iBase64Extension;
       
  1445 	iBase64Extension = NULL;
       
  1446 	
       
  1447 	TheTest.Start(_L("PlugIn Test"));
       
  1448 	TestPlugInL(iFsSession);		//Test the PlugIn and Observer functionality
       
  1449 	TheTest.End();
       
  1450 	
       
  1451 	TheTest.Next(_L("SyncML Tests"));
       
  1452 	SyncMLTestsL(*this); //Test data got from syncing with a SyncML server - particular to check a timezone bug.
       
  1453 	
       
  1454 	TheTest.Next(_L("ShiftJIS & Othert Tests"));
       
  1455 	TestJapanL(*this);	//Test data produced by K3 to illustrate bugs found in GT6.1 code
       
  1456 	
       
  1457 	TheTest.Next(_L("Leave Tests"));
       
  1458 	LeaveTestsL(*this);	//Internalise a file with bad data and check that you get the right leave code
       
  1459 	
       
  1460 	TheTest.Next(_L("Escaping Test"));//test the escape key "\"
       
  1461 	Test1L(*this);
       
  1462 	
       
  1463 	TheTest.Next(_L("Quoted-Printable Test"));
       
  1464 	Test2L(*this);
       
  1465 	
       
  1466 	//create a vCard, externalise it, then internalise it and compare the property values with the original ones
       
  1467 	TheTest.Next(_L("Encodings Test"));
       
  1468 	Test3L(*this);
       
  1469 	
       
  1470 	// test decoding the text which is base64 encoded
       
  1471 	TheTest.Next(_L("Base64 Encoding"));
       
  1472 	Test4L(*this);
       
  1473 	
       
  1474 	// bug fix
       
  1475 	TheTest.Next(_L("Base64 inconsistent (WAG-4YGCRX)"));
       
  1476 	Test5L(*this);
       
  1477 	
       
  1478 	// bug fix
       
  1479 	TheTest.Next(_L("Line wrapping test"));
       
  1480 	Test6L(*this);//Line wrapping test
       
  1481 	
       
  1482 	TheTest.Next(_L("EXT-54BGZJ"));
       
  1483 	Test7L(*this);
       
  1484 
       
  1485 	TheTest.Next(_L("Monthly-By-Position RRULE with impartial date"));
       
  1486 	Test11L(*this);
       
  1487 
       
  1488 	TheTest.Next(_L("Grouped proterty test"));
       
  1489 	Test8L(*this);		//grouped proterty
       
  1490 	
       
  1491 	TheTest.Next(_L("Jis charset"));//bug fix CHM-53KE5L
       
  1492 	Test9L(*this);
       
  1493 	
       
  1494 	/*PDEF088039 changes to autodetect means that the following test will not work
       
  1495 	there are no comments what this really tests, or why it is trying to test autodetect.
       
  1496 	the use case is contrived as it uses a vcard and then has an alarm property in it!
       
  1497 	the display string represents some garbage outside the ascii range.
       
  1498 	*/
       
  1499 	/*
       
  1500 	_LIT(KTest10,"Auto Detect");
       
  1501 	TheTest.Next(KTest10);
       
  1502 	Test10L();*/  
       
  1503 	TheTest.Next(_L("Quoted-Printable Test Encoding Test"));
       
  1504 	Test12L(*this);
       
  1505 
       
  1506 	TheTest.Next(_L("Testing huge VCard with Random data..."));
       
  1507 	TestHugeVCardL(*this);
       
  1508 
       
  1509 	TheTest.Next(_L("Testing null date..."));
       
  1510 	TestNullDateL(*this);
       
  1511 	
       
  1512 	TheTest.Next(_L("Alarm repeat count"));
       
  1513 	TestAlarmRepeatCountL(*this);
       
  1514 	
       
  1515 	TheTest.Next(_L("Encoding Test for '#'"));
       
  1516 	TestHashSignEncodingL(*this);
       
  1517 
       
  1518 	TheTest.Next(_L("Finished Tests"));
       
  1519 	TheTest.End();
       
  1520 	}
       
  1521 	
       
  1522 void doOOMTest(CTests& aTest, TOOMCallback aCallback, TInt aFailStart)
       
  1523 	{
       
  1524 	TInt ret=KErrNoMemory;
       
  1525 	TInt failAt=aFailStart;
       
  1526 	while (ret!=KErrNone)
       
  1527 		{
       
  1528 		failAt++;
       
  1529 		TBuf<200>indicator;
       
  1530 		indicator.Format(_L("Memory fail at \t%d\x0d\x0a"),failAt);
       
  1531 		if(failAt%100==0)
       
  1532 			TheTest.Printf(indicator);
       
  1533 		__UHEAP_SETFAIL(RHeap::EDeterministic,failAt);
       
  1534 		__UHEAP_MARK;			
       
  1535 		TRAP(ret, aCallback(aTest));
       
  1536 		__UHEAP_MARKEND;
       
  1537 		__UHEAP_RESET;
       
  1538 		if (ret!=KErrNoMemory&&ret!=KErrNone)
       
  1539 			{
       
  1540 			TheTest.Printf(_L("Non standard error: %d\n"),ret);
       
  1541 			}
       
  1542 		}
       
  1543 	}
       
  1544 
       
  1545 void OOMTestsL(CTests& aTest)
       
  1546 	{
       
  1547 	TheTest.Start(_L("TBugfix OOM tests"));
       
  1548 	
       
  1549 	TheTest.Next(_L("OOM on Simple write file"));
       
  1550 	doOOMTest(aTest, CTests::Test0L, 0);
       
  1551 	
       
  1552 	TheTest.Next(_L("OOM on versit files test"));
       
  1553 	doOOMTest(aTest, CTests::TestL, 786);
       
  1554 	
       
  1555 	TheTest.Next(_L("OOM on SyncML Tests"));
       
  1556 	doOOMTest(aTest, CTests::SyncMLTestsL, 0);
       
  1557 	
       
  1558 	TheTest.Next(_L("OOM on ShiftJIS & Othert Tests"));
       
  1559 	doOOMTest(aTest, CTests::TestJapanL, 0);
       
  1560 	
       
  1561 	TheTest.Next(_L("OOM on Escaping Test"));
       
  1562 	doOOMTest(aTest, CTests::Test1L, 0);
       
  1563 	
       
  1564 	TheTest.Next(_L("OOM on Quoted-Printable Test"));
       
  1565 	doOOMTest(aTest, CTests::Test2L, 0);
       
  1566 	
       
  1567 	//create a vCard, externalise it, then internalise it and compare the property values with the original ones
       
  1568 	TheTest.Next(_L("OOM on Encodings Test"));
       
  1569 	doOOMTest(aTest, CTests::Test3L, 0);
       
  1570 	
       
  1571 	// test decoding the text which is base64 encoded
       
  1572 	TheTest.Next(_L("OOM on Base64 Encodings Test"));
       
  1573 	doOOMTest(aTest, CTests::Test4L, 0);
       
  1574 	
       
  1575 	TheTest.Next(_L("OOM on Base64 inconsistent (WAG-4YGCRX)"));
       
  1576 	doOOMTest(aTest, CTests::Test5L, 0);
       
  1577 	
       
  1578 	TheTest.Next(_L("OOM on Line wrapping test"));
       
  1579 	doOOMTest(aTest, CTests::Test6L, 0);
       
  1580 	
       
  1581 	TheTest.Next(_L("OOM on EXT-54BGZJ"));
       
  1582 	doOOMTest(aTest, CTests::Test7L, 0);
       
  1583 
       
  1584 	TheTest.Next(_L("OOM on Monthly-By-Position RRULE with impartial date"));
       
  1585 	doOOMTest(aTest, CTests::Test11L, 0);
       
  1586 
       
  1587 	TheTest.Next(_L("OOM on Grouped proterty test"));
       
  1588 	doOOMTest(aTest, CTests::Test8L, 0);
       
  1589 	
       
  1590 	TheTest.Next(_L("OOM on Jis charset"));
       
  1591 	doOOMTest(aTest, CTests::Test9L, 145);
       
  1592 	
       
  1593 	/*PDEF088039 changes to autodetect means that the following test will not work
       
  1594 	there are no comments what this really tests, or why it is trying to test autodetect.
       
  1595 	the use case is contrived as it uses a vcard and then has an alarm property in it!
       
  1596 	the display string represents some garbage outside the ascii range.
       
  1597 	*/
       
  1598 	/*
       
  1599 	_LIT(KTest10,"Auto Detect");
       
  1600 	TheTest.Next(KTest10);
       
  1601 	Test10L();*/  
       
  1602 	
       
  1603 	TheTest.Next(_L("OOM on testing null date"));
       
  1604 	doOOMTest(aTest, CTests::TestNullDateL, 0);
       
  1605 	
       
  1606 	TheTest.Next(_L("OOM on Alarm repeat count"));
       
  1607 	doOOMTest(aTest, CTests::TestAlarmRepeatCountL, 0);
       
  1608 
       
  1609 	TheTest.Next(_L("Finished OOM Tests"));
       
  1610 	TheTest.End();
       
  1611 	}
       
  1612 
       
  1613 void DoTestsL()
       
  1614 	{
       
  1615 	CTests* testObj = CTests::NewL();
       
  1616 	CleanupStack::PushL(testObj);
       
  1617 	testObj->AllTestsL();
       
  1618 	
       
  1619 #ifdef TBUGFIX_INCLUDE_OOM
       
  1620 	OOMTestsL(*testObj);
       
  1621 #endif	//TBUGFIX_INCLUDE_OOM
       
  1622 
       
  1623 	CleanupStack::PopAndDestroy(testObj);
       
  1624 	}
       
  1625 
       
  1626 GLDEF_C TInt E32Main()
       
  1627 	{
       
  1628 	_LIT(KTest,"Entered Test Code");
       
  1629 	RDebug::Print(KTest);
       
  1630 	
       
  1631 	TTime startTime;
       
  1632 	startTime.UniversalTime();
       
  1633 	
       
  1634 	__UHEAP_MARK;
       
  1635 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1636 	if	(!cleanup)
       
  1637 		return KErrNoMemory;
       
  1638 
       
  1639 	_LIT(KTestName,"Regression Tests");	
       
  1640 	TheTest.Start(KTestName);
       
  1641 	TheTest.Printf(_L("@SYMTestCaseID PIM-TBUGFIX-Versit_Escaping_Test-0001"));
       
  1642 	TRAPD(err,DoTestsL());
       
  1643 
       
  1644 	TheTest.End();
       
  1645 	TheTest(err == KErrNone);
       
  1646 	TheTest.Close();
       
  1647 	delete cleanup;
       
  1648 
       
  1649 	__UHEAP_MARKEND;
       
  1650 	
       
  1651 	TTime finishTime;
       
  1652 	finishTime.UniversalTime();
       
  1653 	TReal elapsed = (TReal)finishTime.MicroSecondsFrom(startTime).Int64();
       
  1654 	TheTest.Printf(_L("Elapsed time: %.4f\n"), elapsed/1000000);
       
  1655 	
       
  1656 	return (KErrNone);
       
  1657 	}