phonebookengines/contactsmodel/tsrc/Integration/TestContactSuite/src/TestAddFieldsStep.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "TestAddFieldsStep.h"
       
    17 #include "TestContactSuiteServer.h"
       
    18 #include <cntitem.h>
       
    19 #include <cntfield.h>
       
    20 #include <cntfldst.h> 
       
    21 #include <cntdef.h> 
       
    22 #include <cntdb.h> 
       
    23 
       
    24 TInt CTestAddFieldsStep::iStorage[]=
       
    25 {
       
    26 KStorageTypeText, KStorageTypeText, KStorageTypeDateTime, KStorageTypeText,KStorageTypeText,KStorageTypeText,KStorageTypeText 		
       
    27 };
       
    28 
       
    29 TUid CTestAddFieldsStep::iFieldUid[]=
       
    30 {
       
    31 KUidContactFieldAssistant, KUidContactFieldPhoneNumber, KUidContactFieldAnniversary,KUidContactFieldSpouse,KUidContactFieldChildren,KUidContactFieldClass,KUidContactFieldDepartmentName 		
       
    32 };
       
    33 
       
    34 TUid CTestAddFieldsStep::iVcardUid[]=
       
    35 {
       
    36 KUidContactFieldVCardMapAssistant, KUidContactFieldVCardMapAssistantTel, KUidContactFieldVCardMapAnniversary, KUidContactFieldVCardMapSpouse,KUidContactFieldVCardMapChildren,KUidContactFieldVCardMapClass,KUidContactFieldVCardMapDepartment 		
       
    37 };
       
    38 
       
    39 CTestAddFieldsStep::~CTestAddFieldsStep()
       
    40 /**
       
    41  * Destructor
       
    42  */
       
    43 	{
       
    44 
       
    45 	}
       
    46 
       
    47 CTestAddFieldsStep::CTestAddFieldsStep()
       
    48 /**
       
    49  * Constructor
       
    50  */
       
    51 	{
       
    52 	// **MUST** call SetTestStepName in the constructor as the controlling
       
    53 	// framework uses the test step name immediately following construction to set
       
    54 	// up the step's unique logging ID.
       
    55 	SetTestStepName(KTestAddFieldsStep);
       
    56 	}
       
    57 
       
    58 TVerdict CTestAddFieldsStep::doTestStepPreambleL()
       
    59 /**
       
    60  * @return - TVerdict code
       
    61  * Override of base class virtual
       
    62  */
       
    63 	{
       
    64 	iScheduler = new (ELeave) CActiveScheduler;
       
    65 	
       
    66 	CActiveScheduler::Install(iScheduler);
       
    67 	SetTestStepResult(EPass);
       
    68 	return TestStepResult();
       
    69 	
       
    70 	}
       
    71 
       
    72 TVerdict CTestAddFieldsStep::doTestStepL()
       
    73 /**
       
    74  * @return - TVerdict code
       
    75  * Override of base class pure virtual
       
    76  */
       
    77 	{
       
    78 	TPtrC fieldName, fieldVal, fieldCouple, allFields, fieldTemplate;  
       
    79 	_LIT(KCouple,	"couple");
       
    80 	_LIT(KAll,		"all");
       
    81 	_LIT(KTemplate,	"template");
       
    82 	
       
    83 	GetStringFromConfig(ConfigSection(), KIniFlagvalue, allFields);
       
    84 	if(KErrNone==allFields.Compare(KAll))	
       
    85 		{
       
    86 		AddAllFieldsL();
       
    87 		}
       
    88 	else if (!GetStringFromConfig(ConfigSection(), KIniFieldName, fieldName))
       
    89 		{
       
    90 		ERR_PRINTF1(_L("Unable to read fieldname from ini file"));
       
    91 		SetTestStepResult(EFail);
       
    92 		}
       
    93 		
       
    94 	else
       
    95 		{
       
    96 		if(KErrNone == fieldName.Compare(KAssistance))
       
    97 			{
       
    98 			// Get the value from ini file
       
    99 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   100 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldCouple);
       
   101 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   102 			
       
   103 			if(fieldCouple.Compare(KCouple)==0)
       
   104 				{
       
   105 				AddCoupleFieldsL(fieldVal, iStorage[0],iFieldUid[0], iVcardUid[0]);
       
   106 				}
       
   107 			else if(fieldTemplate.Compare(KTemplate)==0)
       
   108 				{
       
   109 				AddFieldsNewTemplateL(fieldVal, iStorage[0],iFieldUid[0], iVcardUid[0]);	
       
   110 				}	
       
   111 			else
       
   112 				{
       
   113 				AddFieldsL(fieldVal, iStorage[0],iFieldUid[0], iVcardUid[0]);
       
   114 				}	
       
   115 			}
       
   116 		else if(KErrNone == fieldName.Compare(KAssistanceTel))	
       
   117 			{
       
   118 			// Get the value from ini file
       
   119 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   120 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldCouple);
       
   121 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   122 			
       
   123 			if(fieldCouple.Compare(KCouple) == 0)
       
   124 				{
       
   125 				AddCoupleFieldsL(fieldVal, iStorage[1],iFieldUid[1], iVcardUid[1]);
       
   126 				}
       
   127 			else if(fieldTemplate.Compare(KTemplate) == 0)
       
   128 				{
       
   129 				AddFieldsNewTemplateL(fieldVal, iStorage[1],iFieldUid[1], iVcardUid[1]);	
       
   130 				}	
       
   131 			else
       
   132 				{
       
   133 				AddFieldsL(fieldVal, iStorage[1],iFieldUid[1], iVcardUid[1]);
       
   134 				}	
       
   135 			}
       
   136 		else if(KErrNone == fieldName.Compare(KAnniversary))	
       
   137 			{
       
   138 			// Get the value from ini file
       
   139 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   140 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldCouple);
       
   141 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   142 			
       
   143 			if(fieldCouple.Compare(KCouple)==0)
       
   144 				{
       
   145 				AddCoupleFieldsL(fieldVal, iStorage[2],iFieldUid[2], iVcardUid[2]);
       
   146 				}
       
   147 			else if(fieldTemplate.Compare(KTemplate)==0)
       
   148 				{
       
   149 				AddFieldsNewTemplateL(fieldVal, iStorage[2],iFieldUid[2], iVcardUid[2]);	
       
   150 				}	
       
   151 			else
       
   152 				{
       
   153 				AddFieldsL(fieldVal, iStorage[2],iFieldUid[2], iVcardUid[2]);
       
   154 				}
       
   155 			
       
   156 			}
       
   157 		else if(KErrNone == fieldName.Compare(KSpouse))	
       
   158 			{
       
   159 			// Get the value from ini file
       
   160 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   161 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldCouple);
       
   162 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   163 			
       
   164 			if(fieldCouple.Compare(KCouple)==0)
       
   165 				{
       
   166 				AddCoupleFieldsL(fieldVal, iStorage[3],iFieldUid[3], iVcardUid[3]);
       
   167 				}
       
   168 			else if(fieldTemplate.Compare(KTemplate)==0)
       
   169 				{
       
   170 				AddFieldsNewTemplateL(fieldVal, iStorage[3],iFieldUid[3], iVcardUid[3]);	
       
   171 				}	
       
   172 			else
       
   173 				{
       
   174 				AddFieldsL(fieldVal, iStorage[3],iFieldUid[3], iVcardUid[3]);
       
   175 				}
       
   176 			}
       
   177 		else if(KErrNone == fieldName.Compare(KChildren))	
       
   178 			{
       
   179 			// Get the value from ini file
       
   180 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   181 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldCouple);
       
   182 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   183 			
       
   184 			if(fieldCouple.Compare(KCouple)==0)
       
   185 				{
       
   186 				AddCoupleFieldsL(fieldVal, iStorage[4],iFieldUid[4], iVcardUid[4]);
       
   187 				}
       
   188 			else if(fieldTemplate.Compare(KTemplate)==0)
       
   189 				{
       
   190 				AddFieldsNewTemplateL(fieldVal, iStorage[4],iFieldUid[4], iVcardUid[4]);	
       
   191 				}	
       
   192 			else
       
   193 				{
       
   194 				AddFieldsL(fieldVal, iStorage[4],iFieldUid[4], iVcardUid[4]);
       
   195 				}
       
   196 			}
       
   197 		else if(KErrNone == fieldName.Compare(KClass))	
       
   198 			{
       
   199 			// Get the value from ini file
       
   200 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   201 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldCouple);
       
   202 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   203 			
       
   204 			if(fieldCouple.Compare(KCouple)==0)
       
   205 				{
       
   206 				AddCoupleFieldsL(fieldVal, iStorage[5],iFieldUid[5], iVcardUid[5]);
       
   207 				}
       
   208 			else if(fieldTemplate.Compare(KTemplate)==0)
       
   209 				{
       
   210 				AddFieldsNewTemplateL(fieldVal, iStorage[5],iFieldUid[5], iVcardUid[5]);	
       
   211 				}	
       
   212 			else
       
   213 				{
       
   214 				AddFieldsL(fieldVal, iStorage[5],iFieldUid[5], iVcardUid[5]);
       
   215 				}
       
   216 			}	
       
   217 		else if(KErrNone == fieldName.Compare(KDepartment))	
       
   218 			{
       
   219 			// Get the value from ini file
       
   220 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   221 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldCouple);
       
   222 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   223 			
       
   224 			if(fieldCouple.Compare(KCouple)==0)
       
   225 				{
       
   226 				AddCoupleFieldsL(fieldVal, iStorage[6],iFieldUid[6], iVcardUid[6]);
       
   227 				}
       
   228 			else if(fieldTemplate.Compare(KTemplate)==0)
       
   229 				{
       
   230 				AddFieldsNewTemplateL(fieldVal, iStorage[6],iFieldUid[6], iVcardUid[6]);	
       
   231 				}	
       
   232 			else
       
   233 				{
       
   234 				AddFieldsL(fieldVal, iStorage[6],iFieldUid[6], iVcardUid[6]);
       
   235 				}	
       
   236 			}	
       
   237 		else
       
   238 			{
       
   239 			ERR_PRINTF1(_L("Invalid fieldname"));
       
   240 			SetTestStepResult(EFail);
       
   241 			}
       
   242 		}
       
   243 		return TestStepResult();
       
   244 	}
       
   245 /** Create Contact Item and add field to it and 
       
   246  *	verify the field is being added
       
   247  *	aValue - field value
       
   248  *  @param aStorageType - Storage type of each field
       
   249  *	@param aContFieldUid - Uid of Contact field
       
   250  *	@param avCardMapUid - Uid of vCard 
       
   251  *	@return - void
       
   252 */	
       
   253 void CTestAddFieldsStep::AddFieldsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)	
       
   254 	{
       
   255 	TPtrC value;
       
   256 	TInt year, month, day;
       
   257 
       
   258 	// Create contact Item and add field to it	
       
   259 	CContactItem* item = CContactCard::NewLC();
       
   260     CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid);
       
   261     CleanupStack::PushL(field); 
       
   262     field->SetMapping(avCardMap);
       
   263     if(aStorageType==KStorageTypeDateTime)
       
   264     	{
       
   265     	GetIntFromConfig(ConfigSection(), KIniYear, year);
       
   266     	GetIntFromConfig(ConfigSection(), KIniMonth, month);
       
   267     	GetIntFromConfig(ConfigSection(), KIniDay, day);
       
   268 		TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   269    		field->DateTimeStorage()->SetTime(date);
       
   270     	}
       
   271     else
       
   272     	{
       
   273     	field->TextStorage()->SetTextL(aValue);	
       
   274     	}	
       
   275    	item->AddFieldL(*field);   
       
   276   
       
   277    	// verify the field is being added    	
       
   278 	CContactItemFieldSet& ContactFieldSet = item->CardFields();
       
   279 	TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);	
       
   280 	if(pos != KErrNotFound)	
       
   281 		{
       
   282 		if(aStorageType==KStorageTypeDateTime)
       
   283 			{
       
   284 			TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
       
   285 			//compair the results
       
   286 			if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
       
   287 				{
       
   288 				SetTestStepResult(EPass);	
       
   289 				}
       
   290 			else
       
   291 				{
       
   292 				SetTestStepResult(EFail);	
       
   293 				}
       
   294 			}
       
   295 		else
       
   296 			{	
       
   297 			value.Set(ContactFieldSet[pos].TextStorage()->Text());
       
   298 			//compair the results
       
   299 			if(aValue.Compare(value)==0 )
       
   300 				{
       
   301 				SetTestStepResult(EPass);
       
   302 				}
       
   303 			else
       
   304 				{
       
   305 				SetTestStepResult(EFail);
       
   306 				}
       
   307 			}
       
   308 		}
       
   309 	CleanupStack::Pop(field);
       
   310 	CleanupStack::PopAndDestroy(item);
       
   311 	}
       
   312 /** Create Contact Item and add couple of same fields to it and 
       
   313  *	verify the field is being added
       
   314  *	aValue - field value
       
   315  *  @param aStorageType - Storage type of each field
       
   316  *	@param aContFieldUid - Uid of Contact field
       
   317  *	@param avCardMapUid - Uid of vCard 
       
   318  *	@return - void
       
   319 */		
       
   320 void CTestAddFieldsStep::AddCoupleFieldsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)	
       
   321 	{
       
   322 	TPtrC value;
       
   323 	TInt year, month, day;
       
   324 	CContactItemField* field;
       
   325 	
       
   326 	// Get the value form ini file
       
   327 	GetIntFromConfig(ConfigSection(), KIniYear, year);
       
   328     GetIntFromConfig(ConfigSection(), KIniMonth, month);
       
   329     GetIntFromConfig(ConfigSection(), KIniDay, day);
       
   330     
       
   331 	// Create contact Item and add same field twice to it
       
   332 	CContactItem* item = CContactCard::NewLC();
       
   333 	for(TInt x=0; x<2; x++)
       
   334 		{
       
   335     	field = CContactItemField::NewL(aStorageType, aContFieldUid);
       
   336     	CleanupStack::PushL(field); 
       
   337     	field->SetMapping(avCardMap);
       
   338     	if(aStorageType==KStorageTypeDateTime)
       
   339     		{
       
   340 			TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   341    			field->DateTimeStorage()->SetTime(date);
       
   342     		}
       
   343     	else
       
   344     		{
       
   345     		field->TextStorage()->SetTextL(aValue);	
       
   346     		}	
       
   347    		item->AddFieldL(*field);  
       
   348    		CleanupStack::Pop(field);
       
   349 		}  
       
   350 	CContactItemFieldSet& ContactFieldSetOpen = item->CardFields();	
       
   351 	
       
   352    	// verify the field is being added 
       
   353    	TInt startPos=0;
       
   354    	for(TInt check=0; check<2; check++)
       
   355    		{
       
   356 		TInt pos = ContactFieldSetOpen.FindNext(aContFieldUid, avCardMap,startPos);	
       
   357 		if(pos != KErrNotFound)	
       
   358 			{
       
   359 			if(aStorageType==KStorageTypeDateTime)
       
   360 				{
       
   361 				TDateTime result=ContactFieldSetOpen[pos].DateTimeStorage()->Time().DateTime();
       
   362 				startPos=startPos+1;
       
   363 				if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
       
   364 					{
       
   365 					SetTestStepResult(EPass);	
       
   366 					}
       
   367 				else
       
   368 					{
       
   369 					SetTestStepResult(EFail);	
       
   370 					}
       
   371 				}
       
   372 			else
       
   373 				{	
       
   374 				value.Set(ContactFieldSetOpen[pos].TextStorage()->Text());
       
   375 				startPos=startPos+1;
       
   376 				//compair the results
       
   377 				if(aValue.Compare(value)==0 )
       
   378 					{
       
   379 					SetTestStepResult(EPass);
       
   380 					}
       
   381 				else
       
   382 					{
       
   383 					SetTestStepResult(EFail);
       
   384 					}
       
   385 				}
       
   386 			}
       
   387    	}	
       
   388 	CleanupStack::PopAndDestroy(item);	
       
   389 	}
       
   390 /** Create Contact Item and add all fields to it and 
       
   391  *	verify the field is being added
       
   392  *	@return - void
       
   393 */	
       
   394 void CTestAddFieldsStep::AddAllFieldsL()	
       
   395 	{
       
   396 	RArray<TPtrC> readValues;
       
   397 	CleanupClosePushL(readValues);
       
   398 	TPtrC temp, value;
       
   399 	TInt year, month, day,readPos=0;
       
   400 	
       
   401 	// get string value from ini file.
       
   402 	if(!GetStringFromConfig(ConfigSection(), KIniFieldAsstVal, temp))
       
   403 		{
       
   404 		ERR_PRINTF1(_L("Unable to read val from ini file"));
       
   405 		SetTestStepResult(EFail);
       
   406 		}
       
   407 	else
       
   408 		{
       
   409 		readValues.Append(temp);
       
   410 		}	
       
   411 	if(!GetStringFromConfig(ConfigSection(), KIniFieldAsstTelVal, temp))
       
   412 		{
       
   413 		ERR_PRINTF1(_L("Unable to read val from ini file"));
       
   414 		SetTestStepResult(EFail);
       
   415 		}
       
   416 	else
       
   417 		{
       
   418 		readValues.Append(temp);
       
   419 		}
       
   420 	if(!GetStringFromConfig(ConfigSection(), KIniFieldSpouseVal, temp))
       
   421 		{
       
   422 		ERR_PRINTF1(_L("Unable to read val from ini file"));
       
   423 		SetTestStepResult(EFail);
       
   424 		}
       
   425 	else
       
   426 		{
       
   427 		readValues.Append(temp);
       
   428 		}	
       
   429 	if(!GetStringFromConfig(ConfigSection(), KIniFieldChildVel, temp))
       
   430 		{
       
   431 		ERR_PRINTF1(_L("Unable to read val from ini file"));
       
   432 		SetTestStepResult(EFail);
       
   433 		}
       
   434 	else
       
   435 		{
       
   436 		readValues.Append(temp);	
       
   437 		}	
       
   438 	if(!GetStringFromConfig(ConfigSection(), KIniFieldClassVal, temp))
       
   439 		{
       
   440 		ERR_PRINTF1(_L("Unable to read val from ini file"));
       
   441 		SetTestStepResult(EFail);
       
   442 		}
       
   443 	else
       
   444 		{
       
   445 		readValues.Append(temp);	
       
   446 		}
       
   447 	if(!GetStringFromConfig(ConfigSection(), KIniFieldDeptVal, temp))
       
   448 		{
       
   449 		ERR_PRINTF1(_L("Unable to read val from ini file"));
       
   450 		SetTestStepResult(EFail);
       
   451 		}
       
   452 	else
       
   453 		{
       
   454 		readValues.Append(temp);	
       
   455 		}	
       
   456 	
       
   457 	// get int val from ini file
       
   458 	GetIntFromConfig(ConfigSection(), KIniYear, year);
       
   459     GetIntFromConfig(ConfigSection(), KIniMonth, month);
       
   460     GetIntFromConfig(ConfigSection(), KIniDay, day);
       
   461     	
       
   462 	CContactItemField* field = NULL;
       
   463 	// Create contact Item and add all fields to it
       
   464 	CContactItem* item = CContactCard::NewLC();
       
   465 	for(TInt x=0; x<7; x++)
       
   466 		{
       
   467     	field = CContactItemField::NewL(iStorage[x], iFieldUid[x]);
       
   468     	CleanupStack::PushL(field); 
       
   469     	field->SetMapping(iVcardUid[x]);
       
   470     	if(iStorage[x]==KStorageTypeDateTime)
       
   471     		{
       
   472 			TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   473    			field->DateTimeStorage()->SetTime(date);
       
   474     		}
       
   475     	else
       
   476     		{
       
   477     		field->TextStorage()->SetTextL(readValues[readPos++]);	
       
   478     		}	
       
   479    		item->AddFieldL(*field);  
       
   480    		CleanupStack::Pop(field);
       
   481 		}   
       
   482 	readPos=0;
       
   483 	// verify the field is being added    
       
   484 	for(TInt x=0; x<7; x++)	
       
   485 	{	
       
   486 		CContactItemFieldSet& ContactFieldSet = item->CardFields();
       
   487 		TInt pos = ContactFieldSet.Find(iFieldUid[x], iVcardUid[x]);	
       
   488 		if(pos != KErrNotFound)	
       
   489 			{
       
   490 			if(iStorage[x]==KStorageTypeDateTime)
       
   491 				{
       
   492 				TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
       
   493 				if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
       
   494 					{
       
   495 					SetTestStepResult(EPass);	
       
   496 					}
       
   497 				else
       
   498 					{
       
   499 					SetTestStepResult(EFail);	
       
   500 					}
       
   501 				}
       
   502 			else
       
   503 				{
       
   504 				value.Set(ContactFieldSet[pos].TextStorage()->Text());
       
   505 				if(value.Compare(readValues[readPos++])==0 )
       
   506 					{
       
   507 					SetTestStepResult(EPass);
       
   508 					}
       
   509 				else
       
   510 					{
       
   511 					SetTestStepResult(EFail);
       
   512 					}
       
   513 				}	
       
   514 					
       
   515 			}
       
   516 	}
       
   517 	
       
   518 	//Cleanup stack
       
   519 	CleanupStack::PopAndDestroy(item);
       
   520 	CleanupStack::PopAndDestroy(&readValues);
       
   521 	}
       
   522 TVerdict CTestAddFieldsStep::doTestStepPostambleL()
       
   523 /**
       
   524  * @return - TVerdict code
       
   525  * Override of base class virtual
       
   526  */
       
   527 	{
       
   528 	CActiveScheduler::Install(NULL);
       
   529 	delete iScheduler;
       
   530 	return TestStepResult();
       
   531 	}
       
   532 /** Create Contact user defuned Template add add field to contact item  
       
   533  *	through template and verify the field is being added
       
   534  *	aValue - field value
       
   535  *  @param aStorageType - Storage type of each field
       
   536  *	@param aContFieldUid - Uid of Contact field
       
   537  *	@param avCardMapUid - Uid of vCard 
       
   538  *	@return - void
       
   539 */	
       
   540 void CTestAddFieldsStep::AddFieldsNewTemplateL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)	
       
   541 	{
       
   542 	TPtrC value;
       
   543 	TInt year, month, day;
       
   544 	CContactDatabase *base = NULL;
       
   545 	_LIT(KTestDbName, "c:mytemplate.cdb");
       
   546 	_LIT(KUserDefinedTemplate,"MyTemplate");
       
   547 	
       
   548 	// replace existing database name
       
   549 	base = CContactDatabase::ReplaceL(KTestDbName);
       
   550 	CleanupStack::PushL(base);
       
   551 		
       
   552 	TContactItemId TempId ;
       
   553 	CContactItemField* field = NULL;
       
   554 	
       
   555 	//Create User defined Template
       
   556 	CContactItem* contactTemplate = base->CreateContactCardTemplateLC(KUserDefinedTemplate);
       
   557 	
       
   558 	// Get the ID of Template
       
   559 	TempId = contactTemplate->Id();
       
   560 	
       
   561 	//Add fields to it
       
   562     field = CContactItemField::NewL(aStorageType, aContFieldUid);
       
   563     CleanupStack::PushL(field); 
       
   564     field->SetMapping(avCardMap);
       
   565     contactTemplate->AddFieldL(*field);  
       
   566    	CleanupStack::Pop(field);
       
   567    	
       
   568 	//Allocates and constructs a new contact card.
       
   569 	CContactItem* item = CContactCard::NewLC();
       
   570 	
       
   571 	//Sets the ID of the template on which this contact item is based
       
   572 	item->SetTemplateRefId(TempId);
       
   573 	
       
   574 	//create contact item and add field value to it
       
   575     field = CContactItemField::NewL(aStorageType, aContFieldUid);
       
   576     CleanupStack::PushL(field); 
       
   577     field->SetMapping(avCardMap);
       
   578     if(aStorageType==KStorageTypeDateTime)
       
   579     	{
       
   580     	//Get the int value
       
   581 		TBool res;
       
   582 		res = GetIntFromConfig(ConfigSection(), KIniYear, year);
       
   583 		if(!res)
       
   584 			{
       
   585 			ERR_PRINTF1(_L("Unable to read year val from ini file"));
       
   586 			SetTestStepResult(EFail);
       
   587 			}
       
   588 		res = GetIntFromConfig(ConfigSection(), KIniMonth, month);
       
   589 		if(!res)
       
   590 			{
       
   591 			ERR_PRINTF1(_L("Unable to read month val from ini file"));
       
   592 			SetTestStepResult(EFail);
       
   593 			}
       
   594 		res = GetIntFromConfig(ConfigSection(), KIniDay, day);
       
   595 		if(!res)
       
   596 			{
       
   597 			ERR_PRINTF1(_L("Unable to read day val from ini file"));
       
   598 			SetTestStepResult(EFail);
       
   599 			}
       
   600 		TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   601    		field->DateTimeStorage()->SetTime(date);
       
   602     	}
       
   603     else
       
   604     	{
       
   605     	field->TextStorage()->SetTextL(aValue);	
       
   606     	}	
       
   607    	item->AddFieldL(*field); 
       
   608 
       
   609    	// verify the field is being added to the user defined template    	
       
   610 	CContactItemFieldSet& ContactFieldSet = item->CardFields();
       
   611 	TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);	
       
   612 	if(pos != KErrNotFound)	
       
   613 		{
       
   614 		if(aStorageType==KStorageTypeDateTime)
       
   615 			{
       
   616 			TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
       
   617 			//compair the results
       
   618 			if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
       
   619 				{
       
   620 				SetTestStepResult(EPass);	
       
   621 				}
       
   622 			else
       
   623 				{
       
   624 				SetTestStepResult(EFail);	
       
   625 				}
       
   626 			}
       
   627 		else
       
   628 			{	
       
   629 			value.Set(ContactFieldSet[pos].TextStorage()->Text());
       
   630 			//compair the results
       
   631 			if(aValue.Compare(value)==0 )
       
   632 				{
       
   633 				SetTestStepResult(EPass);
       
   634 				}
       
   635 			else
       
   636 				{
       
   637 				SetTestStepResult(EFail);
       
   638 				}
       
   639 			}
       
   640 		}
       
   641 	CleanupStack::Pop(field);
       
   642 	CleanupStack::PopAndDestroy(item);
       
   643 	CleanupStack::PopAndDestroy(contactTemplate);
       
   644 	CleanupStack::PopAndDestroy(base);
       
   645 	}