phonebookengines_old/contactsmodel/tsrc/T_secondname.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2003-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 // This test code tests the contacts model and vCard import / export functionality 
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "T_secondname.h"
       
    19 #include <vutil.h>
       
    20 
       
    21 _LIT(KTestTitle,"T_SecondName - CNTVCARD tests for new contact fields");
       
    22 RTest test(KTestTitle);
       
    23 
       
    24 const TPtrC KDatabaseName=_L("C:secondname.cdb");
       
    25 
       
    26 const TPtrC KTestFile1=_L("C:\\Test1.vcf");
       
    27 const TPtrC KTestFile2=_L("C:\\Test2.vcf");
       
    28 
       
    29 void CleanUpResetAndDestroy(TAny *aArray)
       
    30 	{
       
    31 	if (aArray)
       
    32 		{
       
    33 		CArrayPtr<CContactItem>* array=(CArrayPtr<CContactItem>*)aArray;
       
    34 		array->ResetAndDestroy();
       
    35 		delete array;
       
    36 		}
       
    37 	}
       
    38 
       
    39 
       
    40 TTestData::TTestData(const TDesC8& aImportVCard,
       
    41 	const TDesC8& aUpdateVCard,
       
    42 	const TDesC8& aVersitToken,
       
    43 	const TUid aFieldUid,
       
    44 	const TDesC& aFieldContent,const TDesC& aUpdatedFieldContent,
       
    45 	const TDesC& aImportFilename,
       
    46 	const TDesC& aExportFilename)
       
    47 	: iImportVCard(aImportVCard), iUpdateVCard(aUpdateVCard), iVersitToken(aVersitToken),
       
    48 	iFieldUid(aFieldUid),iFieldContent(aFieldContent),iUpdatedFieldContent(aUpdatedFieldContent), iImportFilename(aImportFilename),
       
    49 	iExportFilename(aExportFilename), iVCardMapping(TUid::Null())
       
    50 	{
       
    51 	}
       
    52 
       
    53 void TTestData::SetVCardMapping(TUid aVCardMapping)
       
    54 	{
       
    55 	iVCardMapping=aVCardMapping;
       
    56 	}
       
    57 
       
    58 CNewFieldTestBase::CNewFieldTestBase(RTest& aTest, RFs& aFs) : iTest(aTest), iFs(aFs)
       
    59 	{
       
    60 	}
       
    61 
       
    62 void CNewFieldTestBase::BaseConstructL()
       
    63 	{
       
    64 	iDb = CContactDatabase::ReplaceL(KDatabaseName);
       
    65 	}
       
    66 
       
    67 CNewFieldTestBase::~CNewFieldTestBase()
       
    68 	{
       
    69 	delete iDb;
       
    70     TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KDatabaseName));
       
    71     iFs.Delete(KTestFile1); //ignore return value
       
    72     iFs.Delete(KTestFile2); //ignore return value
       
    73 	}
       
    74 
       
    75 
       
    76 // ---------------- Utility Methods
       
    77 
       
    78 // Using a text string, create a vCard. Return the pointer to the newly created instance
       
    79 // The caller will take ownership of it.
       
    80 
       
    81 CParserVCard* CNewFieldTestBase::CreateVCardLC(const TDesC8& aContents)
       
    82 	{
       
    83 	CParserVCard* vCardParser=CParserVCard::NewL();
       
    84 	CleanupStack::PushL(vCardParser);
       
    85 
       
    86 	RDesReadStream stream(aContents);
       
    87 	stream.PushL();
       
    88 	vCardParser->InternalizeL(stream);
       
    89 	CleanupStack::PopAndDestroy(); // stream
       
    90 	return vCardParser;
       
    91 	}
       
    92 
       
    93 // Externalise the VCard to the file. If the file does not exist it is created, if the
       
    94 // file already exists it is overwritted.
       
    95 void CNewFieldTestBase::WriteVCardL(const TDesC& aFileName, CParserVCard& aVCard)
       
    96 	{
       
    97 	RFileWriteStream vCardWrite;
       
    98 	vCardWrite.PushL();
       
    99 	User::LeaveIfError(vCardWrite.Replace(iFs,aFileName,EFileWrite));
       
   100 	aVCard.ExternalizeL(vCardWrite);
       
   101 	vCardWrite.CommitL();
       
   102 	CleanupStack::PopAndDestroy(); //vCardWrite
       
   103 	}
       
   104 
       
   105 // Find a field value of type aFieldType and return true if it matches the aExpected value.
       
   106 TBool CNewFieldTestBase::CheckSingleFieldValue(CContactItemFieldSet& aFieldSet, TTestData& aTd, const TDesC& aExpectedValue)
       
   107 	{
       
   108 	TBool correctValue = EFalse;
       
   109 
       
   110 	TInt pos = aFieldSet.Find(aTd.iFieldUid);
       
   111 	while ((pos != KErrNotFound) && !correctValue)
       
   112 		{
       
   113 		// Verify
       
   114 		CContactItemField& field = aFieldSet[pos];
       
   115 		const CContentType& type = field.ContentType();
       
   116 
       
   117 		if (type.ContainsFieldType(aTd.iVCardMapping))
       
   118 			{
       
   119 			CContactTextField* storage = field.TextStorage();
       
   120 			correctValue = (storage->Text().CompareF(aExpectedValue) == 0);
       
   121 			}
       
   122 		pos = aFieldSet.FindNext(aTd.iFieldUid, pos+1);
       
   123 		}
       
   124 	//
       
   125 	return correctValue;
       
   126 	}
       
   127 
       
   128 // Create a contact entry in the Contact Database and return the ID
       
   129 
       
   130 TContactItemId CNewFieldTestBase::CreateContactL()
       
   131 	{
       
   132 	const TContactItemId templateId = iDb->TemplateId();
       
   133 	CContactItem* templateCard = iDb->ReadContactLC(templateId);
       
   134 	CContactCard* card = CContactCard::NewL(templateCard);
       
   135 	CleanupStack::PushL(card);
       
   136 	//
       
   137 	CContactItemFieldSet& cardFields=card->CardFields();
       
   138 	// Set the telephone number
       
   139 	TInt pos=cardFields.Find(KUidContactFieldPhoneNumber);
       
   140 	if (pos!=KErrNotFound)
       
   141 		{
       
   142 		cardFields[pos].SetMapping(KUidContactFieldVCardMapTEL);
       
   143 		cardFields[pos].TextStorage()->SetTextL(_L("1234"));
       
   144 		}
       
   145 	// Set the label
       
   146 	pos=cardFields.Find(KUidContactFieldNote);
       
   147 	if (pos!=KErrNotFound)
       
   148 		{
       
   149 		cardFields[pos].SetMapping(KUidContactFieldVCardMapLABEL);
       
   150 		cardFields[pos].TextStorage()->SetTextL(_L(" "));
       
   151 		}
       
   152 	//
       
   153 	const TContactItemId id = iDb->AddNewContactL(*card);
       
   154 	CleanupStack::PopAndDestroy(2, templateCard);
       
   155 	return id;
       
   156 	}
       
   157 
       
   158 
       
   159 // Read in the file and parse it using Versit
       
   160 CParserVCard* CNewFieldTestBase::ParseVCardLC(const TDesC& aFilename)
       
   161 	{
       
   162 	CParserVCard* vCardParser=CParserVCard::NewL();
       
   163 	CleanupStack::PushL(vCardParser);
       
   164 	//
       
   165 	RFile readFile;
       
   166 	const TInt error = readFile.Open(iFs, aFilename, EFileRead);
       
   167 	User::LeaveIfError(error);
       
   168 	CleanupClosePushL(readFile);
       
   169 	//
       
   170 	RFileReadStream stream(readFile);
       
   171 	stream.PushL();
       
   172 	vCardParser->InternalizeL(stream);
       
   173 	CleanupStack::PopAndDestroy(); // stream
       
   174 	CleanupStack::PopAndDestroy(); // readFile
       
   175 	return vCardParser;
       
   176 	}
       
   177 
       
   178 
       
   179 CArrayPtr<CContactItem>* CNewFieldTestBase::ImportVCardLC(const TDesC& aFilename, TBool aConnectWhitespaceOption)
       
   180 	{
       
   181 	CArrayPtr<CContactItem>* contactItems;
       
   182 	RFileReadStream vCardRead;
       
   183 	TBool importOK;
       
   184 
       
   185 	vCardRead.PushL();
       
   186 	User::LeaveIfError(vCardRead.Open(iFs,aFilename,EFileRead));
       
   187 	// Just a precaution. This array must be empty before we go and add more data
       
   188 	if (aConnectWhitespaceOption)
       
   189 		{
       
   190 		contactItems = iDb->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl),vCardRead,importOK,(CContactVCardConverter::EImportSingleContact | CContactVCardConverter::EConnectWhitespace));
       
   191 		}
       
   192 	else
       
   193 		{
       
   194 		contactItems = iDb->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl),vCardRead,importOK,(CContactVCardConverter::EImportSingleContact));
       
   195 		}
       
   196 	CleanupStack::PopAndDestroy(); // vCardRead
       
   197 	CleanupStack::PushL(contactItems);
       
   198 	return contactItems;
       
   199 	}
       
   200 
       
   201 void CNewFieldTestBase::ExportVCardL(const TDesC& aFilename, CArrayPtr<CContactItem>* aContactArray)
       
   202 	{
       
   203 	RFileWriteStream vCardWrite;
       
   204 	CContactIdArray* idArray = CContactIdArray::NewLC();
       
   205 
       
   206 	for (TInt i = 0; i < aContactArray->Count(); i++)
       
   207 		{
       
   208 		idArray->AddL(aContactArray->At(i)->Id());
       
   209 		}
       
   210 
       
   211 	vCardWrite.PushL();
       
   212 	User::LeaveIfError(vCardWrite.Replace(iFs,aFilename,EFileWrite));
       
   213 	iDb->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl),*idArray,vCardWrite,0);
       
   214 	vCardWrite.CommitL();
       
   215 	CleanupStack::PopAndDestroy(); //vCardWrite
       
   216 	CleanupStack::PopAndDestroy(idArray);
       
   217 	}
       
   218 
       
   219 /** Tests vCard import for the new field.
       
   220 This test creates a vCard from the supplied test data and imports it.
       
   221 The contact field content is checked against the test data and the
       
   222 contact is exported ready for the next test.
       
   223 */
       
   224 void CNewFieldTestBase::TestImportL(TTestData& aTd)
       
   225 	{
       
   226 	iTest.Printf(_L("Creating test vCard Files\n"));
       
   227 	CParserVCard* vCard = CreateVCardLC(aTd.iImportVCard);
       
   228 	WriteVCardL(aTd.iImportFilename,*vCard);
       
   229 	CleanupStack::PopAndDestroy(vCard);
       
   230 
       
   231 	iTest.Printf(_L("Importing vCard files to contacts\n"));
       
   232 	iTest.Printf(_L("New File\n"));
       
   233 	CArrayPtr<CContactItem>* contactItems = ImportVCardLC(aTd.iImportFilename);
       
   234 	iTest(contactItems->Count() == 1);
       
   235 	CContactItem* cItem = iDb->ReadContactLC(contactItems->At(0)->Id());
       
   236 	iTest(CheckSingleFieldValue(cItem->CardFields(),aTd,aTd.iFieldContent));
       
   237 
       
   238 	ExportVCardL(aTd.iExportFilename,contactItems);
       
   239 	contactItems->ResetAndDestroy();
       
   240 	CleanupStack::PopAndDestroy(cItem);
       
   241 	CleanupStack::PopAndDestroy(contactItems);
       
   242 	iTest.Printf(_L("Behaviour correct\n"));
       
   243 	}
       
   244 
       
   245 /** Tests vCard export for the new field.
       
   246 This test checks that the exported vCard contains the correct
       
   247 field and field content.
       
   248 */
       
   249 void CNewFieldTestBase::TestExportL(TTestData& aTd)
       
   250 	{
       
   251 	CParserVCard* cardParser = CParserVCard::NewL();
       
   252 	CleanupStack::PushL(cardParser);
       
   253 	RFileReadStream vCardRead;
       
   254 	vCardRead.PushL();
       
   255 	User::LeaveIfError(vCardRead.Open(iFs,aTd.iImportFilename,EFileRead));
       
   256 	cardParser->InternalizeL(vCardRead);
       
   257 	CArrayPtr<CParserProperty>* arrayOfProperties = cardParser->ArrayOfProperties();
       
   258 	CleanupStack::PushL(TCleanupItem(CleanUpResetAndDestroy, arrayOfProperties));
       
   259 	TBool FieldFound = EFalse;
       
   260 	TInt Counter = 0;
       
   261 	TInt Max = arrayOfProperties->Count();
       
   262 	CParserProperty* aProperty = NULL;
       
   263 	while (!FieldFound && (Counter < Max))
       
   264 		{
       
   265 		aProperty = (*arrayOfProperties)[Counter];
       
   266 		if (aProperty->Name() == aTd.iVersitToken)
       
   267 			{
       
   268 			FieldFound = ETrue;
       
   269 			}
       
   270 		++Counter;
       
   271 		}
       
   272 	iTest.Printf(_L("Checking Field is present in the vCard\n"));
       
   273 	iTest(FieldFound);
       
   274 	iTest.Printf(_L("Present. Checking Value\n"));
       
   275 	CParserPropertyValueHBufC* propertyValueWrapper = static_cast<CParserPropertyValueHBufC*>(aProperty->Value());
       
   276 	const TPtrC propertyValue(propertyValueWrapper->Value());
       
   277 	iTest(propertyValue.CompareF(aTd.iFieldContent) == 0);
       
   278 	iTest.Printf(_L("Value Correct\n"));
       
   279 	arrayOfProperties->ResetAndDestroy();
       
   280 	CleanupStack::PopAndDestroy(arrayOfProperties);
       
   281 	CleanupStack::PopAndDestroy(); // vCardRead
       
   282 	CleanupStack::PopAndDestroy(cardParser);
       
   283 	}
       
   284 
       
   285 /** Tests vCard update for the new field.
       
   286 This test modifies the contact by importing new vCard test data
       
   287 and checking the field is correctly updated.
       
   288 */
       
   289 void CNewFieldTestBase::TestUpdateL(TTestData& aTd)
       
   290 	{
       
   291 	iTest.Printf(_L("Updating vCard\n"));
       
   292 	CParserVCard* vCard = CreateVCardLC(aTd.iUpdateVCard);
       
   293 	WriteVCardL(KTestFile1,*vCard);
       
   294 	CleanupStack::PopAndDestroy(vCard);
       
   295 	iTest.Printf(_L("Importing vCard files to contacts\n"));
       
   296 	CArrayPtr<CContactItem>* contactItems = ImportVCardLC(aTd.iImportFilename);
       
   297 	iTest(contactItems->Count() == 1);
       
   298 	CContactItem* cItem = iDb->ReadContactLC(contactItems->At(0)->Id());
       
   299 	iTest(CheckSingleFieldValue(cItem->CardFields(),aTd,aTd.iUpdatedFieldContent));
       
   300 	contactItems->ResetAndDestroy();
       
   301 	CleanupStack::PopAndDestroy(cItem);
       
   302 	CleanupStack::PopAndDestroy(contactItems);
       
   303 	iTest.Printf(_L("Behaviour correct\n"));
       
   304 	}
       
   305 
       
   306 
       
   307 CSecondNameTest::CSecondNameTest(RTest& aTest, RFs& aFs) : CNewFieldTestBase(aTest,aFs)
       
   308 	{
       
   309 	}
       
   310 
       
   311 CSecondNameTest::~CSecondNameTest()
       
   312 	{
       
   313 	}
       
   314 
       
   315 CSecondNameTest* CSecondNameTest::NewLC(RTest& aTest, RFs& aFs)
       
   316 	{
       
   317 	CSecondNameTest* self=new(ELeave) CSecondNameTest(aTest, aFs);
       
   318 	CleanupStack::PushL(self);
       
   319 	self->ConstructL();
       
   320 	return(self);
       
   321 	}
       
   322 
       
   323 void CSecondNameTest::ConstructL()
       
   324 	{
       
   325 	BaseConstructL();
       
   326 	};
       
   327 
       
   328 void CSecondNameTest::RunTestsL()
       
   329 	{
       
   330 	_LIT(KSecondNameTestDescription,"Second Name Tests Starting\n");
       
   331 	iTest.Next(KSecondNameTestDescription);
       
   332 
       
   333 	_LIT8(KImportVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:1\r\nX-EPOCSECONDNAME:test\r\nEND:VCARD\r\n");
       
   334 	_LIT8(KUpdateVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:1\r\nX-EPOCSECONDNAME:change\r\nEND:VCARD\r\n");
       
   335 	_LIT(KFieldContent, "test");
       
   336 	_LIT(KUpdatedFieldContent,"change");
       
   337 	TTestData t(KImportVCard,KUpdateVCard,KVersitTokenSECONDNAME,KUidContactFieldSecondName,KFieldContent,KUpdatedFieldContent,KTestFile1,KTestFile2);
       
   338 	t.SetVCardMapping(KUidContactFieldVCardMapSECONDNAME);
       
   339 	TestImportL(t);
       
   340 	TestExportL(t);
       
   341 	TestUpdateL(t);
       
   342 	}
       
   343 
       
   344 
       
   345 CSipIdTest::CSipIdTest(RTest& aTest, RFs& aFs) : CNewFieldTestBase(aTest,aFs)
       
   346 	{
       
   347 	}
       
   348 
       
   349 CSipIdTest::~CSipIdTest()
       
   350 	{
       
   351 	}
       
   352 
       
   353 CSipIdTest* CSipIdTest::NewLC(RTest& aTest, RFs& aFs)
       
   354 	{
       
   355 	CSipIdTest* self=new(ELeave) CSipIdTest(aTest, aFs);
       
   356 	CleanupStack::PushL(self);
       
   357 	self->ConstructL();
       
   358 	return(self);
       
   359 	}
       
   360 
       
   361 void CSipIdTest::ConstructL()
       
   362 	{
       
   363 	BaseConstructL();
       
   364 	};
       
   365 
       
   366 
       
   367 void CSipIdTest::RunTestsL()
       
   368 	{
       
   369 	_LIT(KSipTestDescription,"SIP Identity Field Tests starting\n");
       
   370 	iTest.Next(KSipTestDescription);
       
   371 
       
   372 
       
   373 	// Test X-SIP:
       
   374 	_LIT8(KImportVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:1\r\nX-SIP:sip:namet@symbianfoundation.com\r\nEND:VCARD\r\n");
       
   375 	_LIT8(KUpdateVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:1\r\nX-SIP:sip:tes@example.com\r\nEND:VCARD\r\n");
       
   376 	RunTestCaseL(KImportVCard,KUpdateVCard,KUidContactFieldVCardMapSIPID);
       
   377 
       
   378 	// Test X-SIP;POC:
       
   379 	_LIT8(KImportVCardPOC, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:2\r\nX-SIP;POC:sip:namet@symbianfoundation.com\r\nEND:VCARD\r\n");
       
   380 	_LIT8(KUpdateVCardPOC, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:2\r\nX-SIP;POC:sip:tes@example.com\r\nEND:VCARD\r\n");
       
   381 	RunTestCaseL(KImportVCardPOC,KUpdateVCardPOC,KUidContactFieldVCardMapPOC);
       
   382 
       
   383 	// Test X-SIP;SWIS:
       
   384 	_LIT8(KImportVCardSWIS, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:3\r\nX-SIP;SWIS:sip:namet@symbianfoundation.com\r\nEND:VCARD\r\n");
       
   385 	_LIT8(KUpdateVCardSWIS, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:3\r\nX-SIP;SWIS:sip:tes@example.com\r\nEND:VCARD\r\n");
       
   386 	RunTestCaseL(KImportVCardSWIS,KUpdateVCardSWIS,KUidContactFieldVCardMapSWIS);
       
   387 
       
   388 	// Test X-SIP;VOIP:
       
   389 	_LIT8(KImportVCardVOIP, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:4\r\nX-SIP;VOIP:sip:namet@symbianfoundation.com\r\nEND:VCARD\r\n");
       
   390 	_LIT8(KUpdateVCardVOIP, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:4\r\nX-SIP;VOIP:sip:tes@example.com\r\nEND:VCARD\r\n");
       
   391 	RunTestCaseL(KImportVCardVOIP,KUpdateVCardVOIP,KUidContactFieldVCardMapVOIP);
       
   392 
       
   393 	// Test alternative representation - X-SIP;TYPE=POC:
       
   394 	_LIT8(KImportVCardAltPOCImport, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:5\r\nX-SIP;TYPE=POC:sip:namet@symbianfoundation.com\r\nEND:VCARD\r\n");
       
   395 	_LIT8(KUpdateVCardAltPOCUpdate, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:5\r\nX-SIP;TYPE=POC:sip:tes@example.com\r\nEND:VCARD\r\n");
       
   396 	RunTestCaseL(KImportVCardAltPOCImport,KUpdateVCardAltPOCUpdate,KUidContactFieldVCardMapPOC);
       
   397 
       
   398 	// Test alternative representation - X-SIP;TYPE=SWIS:
       
   399 	_LIT8(KImportVCardAltSWISImport, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:6\r\nX-SIP;TYPE=SWIS:sip:namet@symbianfoundation.com\r\nEND:VCARD\r\n");
       
   400 	_LIT8(KUpdateVCardAltSWISUpdate, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:6\r\nX-SIP;TYPE=SWIS:sip:tes@example.com\r\nEND:VCARD\r\n");
       
   401 	RunTestCaseL(KImportVCardAltSWISImport,KUpdateVCardAltSWISUpdate,KUidContactFieldVCardMapSWIS);
       
   402 
       
   403 	// Test alternative representation - X-SIP;TYPE=VOIP:
       
   404 	_LIT8(KImportVCardAltVOIPImport, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:7\r\nX-SIP;TYPE=VOIP:sip:namet@symbianfoundation.com\r\nEND:VCARD\r\n");
       
   405 	_LIT8(KUpdateVCardAltVOIPUpdate, "BEGIN:VCARD\r\nVERSION:2.1\r\nUID:7\r\nX-SIP;TYPE=VOIP:sip:tes@example.com\r\nEND:VCARD\r\n");
       
   406 	RunTestCaseL(KImportVCardAltVOIPImport,KUpdateVCardAltVOIPUpdate,KUidContactFieldVCardMapVOIP);
       
   407 	}
       
   408 
       
   409 void CSipIdTest::RunTestCaseL(const TDesC8& aImportVCard, const TDesC8& aUpdateVCard, TUid aVCardMapping)
       
   410 	{
       
   411 	_LIT(KFieldContent, "sip:namet@symbianfoundation.com");
       
   412 	_LIT(KUpdatedFieldContent, "sip:tes@example.com");
       
   413 	_LIT8(KVersitTokenSIPID,"X-SIP");
       
   414 
       
   415 	TTestData t(aImportVCard,aUpdateVCard,KVersitTokenSIPID,KUidContactFieldSIPID,KFieldContent,KUpdatedFieldContent,KTestFile1,KTestFile2);
       
   416 	t.SetVCardMapping(aVCardMapping);
       
   417 	TestImportL(t);
       
   418 	TestExportL(t);
       
   419 	TestUpdateL(t);
       
   420 	}
       
   421 
       
   422 
       
   423 CWvIdTest::CWvIdTest(RTest& aTest, RFs& aFs) : CNewFieldTestBase(aTest,aFs)
       
   424 	{
       
   425 	}
       
   426 
       
   427 CWvIdTest::~CWvIdTest()
       
   428 	{
       
   429 	}
       
   430 
       
   431 CWvIdTest* CWvIdTest::NewLC(RTest& aTest, RFs& aFs)
       
   432 	{
       
   433 	CWvIdTest* self=new(ELeave) CWvIdTest(aTest, aFs);
       
   434 	CleanupStack::PushL(self);
       
   435 	self->ConstructL();
       
   436 	return(self);
       
   437 	}
       
   438 
       
   439 void CWvIdTest::ConstructL()
       
   440 	{
       
   441 	BaseConstructL();
       
   442 	};
       
   443 
       
   444 /**
       
   445 @SYMTestCaseID     PIM-T-SECONDNAME-0002
       
   446 @SYMTestType UT
       
   447 @SYMTestPriority Urgent
       
   448 @SYMDEF INC063619
       
   449 @SYMTestCaseDesc To verify that the vCard "X-WV-ID" property added to address
       
   450 the problem described in INC063619 works as expected.
       
   451 @SYMTestActions The vCard KImportVCard is imported and tested as per the
       
   452 description of the method CNewFieldTestBase::TestImportL().  Next, the vCard
       
   453 exported by this method is tested as per the description of the method
       
   454 CNewFieldTestBase::TestExportL().  Finally, the vCard KUpdateVCard is imported
       
   455 and tested as per description of the method CNewFieldTestBase::TestUpdateL().
       
   456 @SYMTestExpectedResults See the descriptions of the methods mentioned above.
       
   457 */
       
   458 
       
   459 void CWvIdTest::RunTestsL()
       
   460 	{
       
   461 	_LIT(KWvidTestDescription,"@SYMTESTCaseID:PIM-T-SECONDNAME-0002 Wireless Village Identity Field Tests starting\n");
       
   462 	iTest.Next(KWvidTestDescription);
       
   463 
       
   464 
       
   465 	_LIT8(KImportVCard,"BEGIN:VCARD\r\nVERSION:2.1\r\nUID:1\r\nX-WV-ID:test\r\nEND:VCARD\r\n");
       
   466 	_LIT8(KUpdateVCard,"BEGIN:VCARD\r\nVERSION:2.1\r\nUID:1\r\nX-WV-ID:change\r\nEND:VCARD\r\n");
       
   467 	_LIT(KFieldContent,"test");
       
   468 	_LIT(KUpdatedFieldContent,"change");
       
   469 	_LIT8(KVersitTokenWVID,"X-WV-ID");
       
   470 
       
   471 	TTestData t(KImportVCard,KUpdateVCard,KVersitTokenWVID,KUidContactFieldIMAddress,KFieldContent,KUpdatedFieldContent,KTestFile1,KTestFile2);
       
   472 
       
   473 	t.SetVCardMapping(KUidContactFieldVCardMapWV);
       
   474 
       
   475 	TestImportL(t);
       
   476 	TestExportL(t);
       
   477 	TestUpdateL(t);
       
   478 	}
       
   479 
       
   480 CFieldLimitationTest::CFieldLimitationTest(RTest& aTest, RFs& aFs) : CNewFieldTestBase(aTest,aFs)
       
   481 	{
       
   482 	}
       
   483 
       
   484 CFieldLimitationTest::~CFieldLimitationTest()
       
   485 	{
       
   486 	}
       
   487 
       
   488 CFieldLimitationTest* CFieldLimitationTest::NewLC(RTest& aTest, RFs& aFs)
       
   489 	{
       
   490 	CFieldLimitationTest* self=new(ELeave) CFieldLimitationTest(aTest, aFs);
       
   491 	CleanupStack::PushL(self);
       
   492 	self->ConstructL();
       
   493 	return(self);
       
   494 	}
       
   495 
       
   496 void CFieldLimitationTest::ConstructL()
       
   497 	{
       
   498 	BaseConstructL();
       
   499 	};
       
   500 
       
   501 void CFieldLimitationTest::RunTestsL()
       
   502 	{
       
   503 	_LIT(KNameTestDescription,"Field limitation Tests Starting\n");
       
   504 	iTest.Next(KNameTestDescription);
       
   505 
       
   506 
       
   507 	iTest.Printf(_L("Test if name is truncated or not at import"));
       
   508 	_LIT8(KImportNameVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;;;\r\nFN:John Smith\r\nTEL;CELL:0123456789\r\nADR;HOME:;;;;;;\r\nADR;WORK:;;;;;;\r\nEND:VCARD");
       
   509 	_LIT(KFieldNameExpectedContent, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
       
   510 	RunTestCaseL(KImportNameVCard, KVersitTokenFN, KUidContactFieldFamilyName, KFieldNameExpectedContent);
       
   511 
       
   512 	iTest.Printf(_L("Test if company name is truncated or not at import"));
       
   513 	_LIT8(KImportOrgVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Name Testa;;;\r\nFN:Name Testa\r\nORG:12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\nTEL;CELL:0123456789\r\nADR;HOME:;;;;;;\r\nADR;WORK:;;;;;;\r\nEND:VCARD");
       
   514 	_LIT(KFieldOrgExpectedContent, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
       
   515 	RunTestCaseL(KImportOrgVCard, KVersitTokenORG, KUidContactFieldCompanyName, KFieldOrgExpectedContent);
       
   516 
       
   517 	iTest.Printf(_L("Test if email is truncated or not at import"));
       
   518 	_LIT8(KImportEmailVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Name Testa;;;\r\nFN:Name Testa\r\nEMAIL:12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\nTEL;CELL:0123456789\r\nADR;HOME:;;;;;;\r\nADR;WORK:;;;;;;\r\nEND:VCARD");
       
   519 	_LIT(KFieldEmailExpectedContent, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
       
   520 	RunTestCaseL(KImportEmailVCard, KVersitTokenEMAIL, KUidContactFieldEMail, KFieldEmailExpectedContent);
       
   521 
       
   522 	iTest.Printf(_L("Test if note is truncated or not at import"));
       
   523 	_LIT8(KImportNoteVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Smith;John;;;\r\nFN:Name Testa\r\nNOTE:12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\nTEL;CELL:0123456789\r\nADR;HOME:;;;;;;\r\nADR;WORK:;;;;;;\r\nEND:VCARD");
       
   524 	_LIT(KFieldNoteExpectedContent, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
       
   525 	RunTestCaseL(KImportNoteVCard, KVersitTokenNOTE, KUidContactFieldVCardMapNOTE, KFieldNoteExpectedContent);
       
   526 	}
       
   527 
       
   528 void CFieldLimitationTest::RunTestCaseL(const TDesC8& aImportVCard, const TDesC8& aVersitToken, TUid aCardMapping, const TDesC16& aExpectedValue)
       
   529 	{
       
   530 	_LIT8(KUpdateVCard, ""); //empty - we do not test the update
       
   531 	_LIT(KUpdatedFieldContent,""); //empty - we do not test the update
       
   532 	TTestData t(aImportVCard,KUpdateVCard,aVersitToken,aCardMapping,aExpectedValue,KUpdatedFieldContent,KTestFile1,KTestFile2);
       
   533 	t.SetVCardMapping(aCardMapping);
       
   534 	TestImportL(t);
       
   535 	}
       
   536 
       
   537 void DoTestsL()
       
   538 	{
       
   539 	CActiveScheduler::Install(new(ELeave) CActiveScheduler);
       
   540 	RFs fs;
       
   541 	User::LeaveIfError(fs.Connect());
       
   542 	CleanupClosePushL(fs);
       
   543 
       
   544 	CSecondNameTest* secondNameTests = CSecondNameTest::NewLC(test,fs);
       
   545 	secondNameTests->RunTestsL();
       
   546 	CleanupStack::PopAndDestroy(secondNameTests);
       
   547 
       
   548 	CSipIdTest* sipIdTests = CSipIdTest::NewLC(test,fs);
       
   549 	sipIdTests->RunTestsL();
       
   550 	CleanupStack::PopAndDestroy(sipIdTests);
       
   551 
       
   552 	CWvIdTest* wvIdTests = CWvIdTest::NewLC(test,fs);
       
   553 	wvIdTests->RunTestsL();
       
   554 	CleanupStack::PopAndDestroy(wvIdTests);
       
   555 
       
   556 	CFieldLimitationTest* fieldLimitationTest = CFieldLimitationTest::NewLC(test,fs);
       
   557 	fieldLimitationTest->RunTestsL();
       
   558 	CleanupStack::PopAndDestroy(fieldLimitationTest);
       
   559 
       
   560 	CleanupStack::PopAndDestroy(&fs);
       
   561 	delete CActiveScheduler::Current();
       
   562 	}
       
   563 
       
   564 /**
       
   565 
       
   566 @SYMTestCaseID     PIM-T-SECONDNAME-0001
       
   567 
       
   568 */
       
   569 
       
   570 GLDEF_C TInt E32Main()
       
   571 	{
       
   572 	__UHEAP_MARK;
       
   573 	test.Title();
       
   574 	test.Start(_L("@SYMTESTCaseID:PIM-T-SECONDNAME-0001 T_SecondName - CNTVCARD tests for new contact fields"));
       
   575 
       
   576 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   577 	if (!theCleanup)
       
   578 		return KErrNoMemory;
       
   579 	TRAPD(ret, DoTestsL());
       
   580 	test(ret == KErrNone);
       
   581 	delete theCleanup;
       
   582 	test.End();
       
   583 	test.Close();
       
   584 	__UHEAP_MARKEND;
       
   585 	return(0);
       
   586 	}