phonebookengines/contactsmodel/tsrc/Integration/TestContactSuite/src/TestUpdateFieldsStep.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 "TestUpdateFieldsStep.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 CTestUpdateFieldsStep::iStorage[]=
       
    25 {
       
    26 KStorageTypeText, KStorageTypeText, KStorageTypeDateTime, KStorageTypeText,KStorageTypeText,KStorageTypeText,KStorageTypeText 		
       
    27 };
       
    28 
       
    29 TUid CTestUpdateFieldsStep::iFieldUid[]=
       
    30 {
       
    31 KUidContactFieldAssistant, KUidContactFieldPhoneNumber, KUidContactFieldAnniversary, KUidContactFieldSpouse,KUidContactFieldChildren,KUidContactFieldClass,KUidContactFieldDepartmentName 		
       
    32 };
       
    33 
       
    34 TUid CTestUpdateFieldsStep::iVcardUid[]=
       
    35 {
       
    36 KUidContactFieldVCardMapAssistant, KUidContactFieldVCardMapAssistantTel, KUidContactFieldVCardMapAnniversary, KUidContactFieldVCardMapSpouse,KUidContactFieldVCardMapChildren,KUidContactFieldVCardMapClass,KUidContactFieldVCardMapDepartment 		
       
    37 };
       
    38 
       
    39 
       
    40 CTestUpdateFieldsStep::~CTestUpdateFieldsStep()
       
    41 /**
       
    42  * Destructor
       
    43  */
       
    44 	{
       
    45 
       
    46 	}
       
    47 
       
    48 CTestUpdateFieldsStep::CTestUpdateFieldsStep()
       
    49 /**
       
    50  * Constructor
       
    51  */
       
    52 	{
       
    53 	// **MUST** call SetTestStepName in the constructor as the controlling
       
    54 	// framework uses the test step name immediately following construction to set
       
    55 	// up the step's unique logging ID.
       
    56 	SetTestStepName(KTestUpdateFieldsStep);
       
    57 	}
       
    58 
       
    59 TVerdict CTestUpdateFieldsStep::doTestStepPreambleL()
       
    60 /**
       
    61  * @return - TVerdict code
       
    62  * Override of base class virtual
       
    63  */
       
    64 	{
       
    65 	iScheduler = new (ELeave) CActiveScheduler;
       
    66 	CActiveScheduler::Install(iScheduler);
       
    67 	SetTestStepResult(EPass);
       
    68 	return TestStepResult();
       
    69 	}
       
    70 
       
    71 TVerdict CTestUpdateFieldsStep::doTestStepL()
       
    72 /**
       
    73  * @return - TVerdict code
       
    74  * Override of base class pure virtual
       
    75  */
       
    76 	{
       
    77 	TPtrC fieldName, fieldVal, fieldTemplate;
       
    78 	_LIT(KTemplate,	"template");
       
    79 	
       
    80 	if (!GetStringFromConfig(ConfigSection(), KIniFieldName, fieldName))
       
    81 		{
       
    82 		ERR_PRINTF1(_L("Unable to read fieldname from ini file"));
       
    83 		SetTestStepResult(EFail);
       
    84 		}
       
    85 	else
       
    86 		{
       
    87 		if(KErrNone == fieldName.Compare(KAssistance))
       
    88 			{
       
    89 			//Get the field value
       
    90 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
    91 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
    92 			
       
    93 			if(KErrNone == fieldTemplate.Compare(KTemplate))
       
    94 				{
       
    95 				UpdateFieldsNewTemplateL(fieldVal, iStorage[0],iFieldUid[0], iVcardUid[0]);
       
    96 				}
       
    97 			else
       
    98 				{
       
    99 				UpdateFieldsL(fieldVal, iStorage[0],iFieldUid[0], iVcardUid[0]);	
       
   100 				}	
       
   101 			}
       
   102 		else if(KErrNone == fieldName.Compare(KAssistanceTel))
       
   103 			{
       
   104 			//Get the field value
       
   105 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   106 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   107 			
       
   108 			if(KErrNone == fieldTemplate.Compare(KTemplate))
       
   109 				{
       
   110 				UpdateFieldsNewTemplateL(fieldVal, iStorage[1],iFieldUid[1], iVcardUid[1]);
       
   111 				}
       
   112 			else
       
   113 				{
       
   114 				UpdateFieldsL(fieldVal, iStorage[1],iFieldUid[1], iVcardUid[1]);
       
   115 				}
       
   116 			}
       
   117 		else if(KErrNone == fieldName.Compare(KAnniversary))
       
   118 			{
       
   119 			//Get the field value 
       
   120 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   121 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   122 			
       
   123 			if(KErrNone == fieldTemplate.Compare(KTemplate))
       
   124 				{
       
   125 				UpdateFieldsNewTemplateL(fieldVal, iStorage[2],iFieldUid[2], iVcardUid[2]);
       
   126 				}
       
   127 			else
       
   128 				{
       
   129 				UpdateFieldsL(fieldVal, iStorage[2],iFieldUid[2], iVcardUid[2]);	
       
   130 				}	
       
   131 			}
       
   132 		else if(KErrNone == fieldName.Compare(KSpouse))
       
   133 			{
       
   134 			//Get the field value
       
   135 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   136 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   137 			
       
   138 			if(KErrNone == fieldTemplate.Compare(KTemplate))
       
   139 				{
       
   140 				UpdateFieldsNewTemplateL(fieldVal, iStorage[3],iFieldUid[3], iVcardUid[3]);
       
   141 				}
       
   142 			else
       
   143 				{
       
   144 				UpdateFieldsL(fieldVal, iStorage[3],iFieldUid[3], iVcardUid[3]);	
       
   145 				}	
       
   146 			}
       
   147 		else if(KErrNone == fieldName.Compare(KChildren))
       
   148 			{
       
   149 			//Get the field value
       
   150 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   151 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   152 			
       
   153 			if(KErrNone == fieldTemplate.Compare(KTemplate))
       
   154 				{
       
   155 				UpdateFieldsNewTemplateL(fieldVal, iStorage[4],iFieldUid[4], iVcardUid[4]);
       
   156 				}
       
   157 			else
       
   158 				{
       
   159 				UpdateFieldsL(fieldVal, iStorage[4],iFieldUid[4], iVcardUid[4]);	
       
   160 				}
       
   161 			}
       
   162 		else if(KErrNone == fieldName.Compare(KClass))
       
   163 			{
       
   164 			//Get the field value
       
   165 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   166 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   167 			
       
   168 			if(KErrNone == fieldTemplate.Compare(KTemplate))
       
   169 				{
       
   170 				UpdateFieldsNewTemplateL(fieldVal, iStorage[5],iFieldUid[5], iVcardUid[5]);
       
   171 				}
       
   172 			else
       
   173 				{
       
   174 				UpdateFieldsL(fieldVal, iStorage[5],iFieldUid[5], iVcardUid[5]);	
       
   175 				}	
       
   176 			}
       
   177 		else if(KErrNone == fieldName.Compare(KDepartment))
       
   178 			{
       
   179 			//Get the field value
       
   180 			GetStringFromConfig(ConfigSection(), KIniFieldVal, fieldVal);
       
   181 			GetStringFromConfig(ConfigSection(), KIniFlagvalue, fieldTemplate);
       
   182 			
       
   183 			if(KErrNone == fieldTemplate.Compare(KTemplate))
       
   184 				{
       
   185 				UpdateFieldsNewTemplateL(fieldVal, iStorage[6],iFieldUid[6], iVcardUid[6]);
       
   186 				}
       
   187 			else
       
   188 				{
       
   189 				UpdateFieldsL(fieldVal, iStorage[6],iFieldUid[6], iVcardUid[6]);	
       
   190 				}	
       
   191 			}
       
   192 		else
       
   193 			{
       
   194 			ERR_PRINTF1(_L("Invalid fieldname"));
       
   195 			SetTestStepResult(EFail);
       
   196 			}
       
   197 		}
       
   198 		return TestStepResult();
       
   199 	}
       
   200 /** Create Contact Item and add field to it.Update the field value and 
       
   201  *	verify the field is being updated
       
   202  *	aValue - field value
       
   203  *  @param aStorageType - Storage type of each field
       
   204  *	@param aContFieldUid - Uid of Contact field
       
   205  *	@param avCardMapUid - Uid of vCard 
       
   206  *	@return - void
       
   207 */		
       
   208 void CTestUpdateFieldsStep::UpdateFieldsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)
       
   209 	{
       
   210 	TPtrC value, updateVal, getUpdateValue;
       
   211 	TInt year, month, day;
       
   212 	
       
   213 	// get the value from ini file
       
   214 	GetIntFromConfig(ConfigSection(), KIniYear, year);
       
   215     GetIntFromConfig(ConfigSection(), KIniMonth, month);
       
   216     GetIntFromConfig(ConfigSection(), KIniDay, day);
       
   217     
       
   218 	//Create contact Item and add field to it.
       
   219 	CContactItem* item = CContactCard::NewLC();
       
   220     CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid);
       
   221     CleanupStack::PushL(field);
       
   222     field->SetMapping(avCardMap);
       
   223     if(aStorageType==KStorageTypeDateTime)
       
   224     	{
       
   225 		TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   226    		field->DateTimeStorage()->SetTime(date);
       
   227     	}
       
   228     else
       
   229     	{
       
   230     	field->TextStorage()->SetTextL(aValue);	
       
   231     	}	
       
   232    	item->AddFieldL(*field);
       
   233 
       
   234    	// Get the value from ini file for update
       
   235    	GetStringFromConfig(ConfigSection(), KIniUpdatedvalue, updateVal);
       
   236 	GetIntFromConfig(ConfigSection(), KIniUpdateYear, year);
       
   237     GetIntFromConfig(ConfigSection(), KIniUpdateMonth, month);
       
   238     GetIntFromConfig(ConfigSection(), KIniUpdateDay, day);
       
   239     
       
   240    	
       
   241 	CContactItemFieldSet& ContactFieldSet = item->CardFields();
       
   242 	TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);
       
   243 	
       
   244 	if(aStorageType==KStorageTypeDateTime)
       
   245     	{
       
   246     	// update the field value
       
   247 		TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   248    		field->DateTimeStorage()->SetTime(date);
       
   249    		ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos);
       
   250    		
       
   251    		// verify the updated field value
       
   252    		TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap);
       
   253    		TDateTime result=ContactFieldSet[upadtePos].DateTimeStorage()->Time().DateTime();
       
   254    		if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
       
   255 				{
       
   256 				SetTestStepResult(EPass);	
       
   257 				}
       
   258 			else
       
   259 				{
       
   260 				SetTestStepResult(EFail);	
       
   261 				}
       
   262     	}
       
   263     else
       
   264     	{
       
   265     	// Update the field value
       
   266 		ContactFieldSet[pos].TextStorage()->SetTextL(updateVal);
       
   267 		ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos);
       
   268 		
       
   269 		// verify the field is being updated 
       
   270 		TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap);
       
   271 		getUpdateValue.Set(ContactFieldSet[upadtePos].TextStorage()->Text());
       
   272 	
       
   273 		//compair the results
       
   274 		if(getUpdateValue.Compare(updateVal)==0 )
       
   275 			{
       
   276 			SetTestStepResult(EPass);
       
   277 			}
       
   278 		else
       
   279 			{
       
   280 			SetTestStepResult(EFail);
       
   281 			}
       
   282     	}
       
   283 
       
   284 	// Cleanup
       
   285 	CleanupStack::Pop(field);
       
   286 	CleanupStack::PopAndDestroy(item);
       
   287 
       
   288 	}
       
   289 
       
   290 TVerdict CTestUpdateFieldsStep::doTestStepPostambleL()
       
   291 /**
       
   292  * @return - TVerdict code
       
   293  * Override of base class virtual
       
   294  */
       
   295 	{
       
   296 	CActiveScheduler::Install(NULL);
       
   297 	delete iScheduler;	
       
   298 	return TestStepResult();
       
   299 	}
       
   300 /** Create Contact user defuned Template add add field to contact item  
       
   301  *	through template. update the contact item and verify the field is being updated
       
   302  *	aValue - field value
       
   303  *  @param aStorageType - Storage type of each field
       
   304  *	@param aContFieldUid - Uid of Contact field
       
   305  *	@param avCardMapUid - Uid of vCard 
       
   306  *	@return - void
       
   307 */	
       
   308 void CTestUpdateFieldsStep::UpdateFieldsNewTemplateL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)
       
   309 	{
       
   310 	TPtrC value, updateVal, getUpdateValue;
       
   311 	TInt year, month, day;
       
   312 	CContactDatabase *base = NULL;
       
   313 	_LIT(KTestDbName, "c:mytemplate1.cdb");
       
   314 	_LIT(KUserDefinedTemplate,"MyTemplate");
       
   315 	
       
   316 	// replace existing database name
       
   317 	base = CContactDatabase::ReplaceL(KTestDbName);
       
   318 	CleanupStack::PushL(base);
       
   319 		
       
   320 	TContactItemId TempId ;
       
   321 	CContactItemField* field = NULL;
       
   322 	
       
   323 	//Create User defined Template
       
   324 	CContactItem* contactTemplate = base->CreateContactCardTemplateLC(KUserDefinedTemplate);
       
   325 	
       
   326 	// Get the ID of Template
       
   327 	TempId = contactTemplate->Id();
       
   328 	
       
   329 	//Add fields to it
       
   330     field = CContactItemField::NewL(aStorageType, aContFieldUid);
       
   331     CleanupStack::PushL(field); 
       
   332     field->SetMapping(avCardMap);
       
   333     contactTemplate->AddFieldL(*field);  
       
   334    	CleanupStack::Pop(field);
       
   335    	
       
   336 	//Allocates and constructs a new contact card.
       
   337 	CContactItem* item = CContactCard::NewLC();
       
   338 	
       
   339 	//Sets the ID of the template on which this contact item is based
       
   340 	item->SetTemplateRefId(TempId);
       
   341 	
       
   342 	//create contact item and add field value to it
       
   343     field = CContactItemField::NewL(aStorageType, aContFieldUid);
       
   344     CleanupStack::PushL(field); 
       
   345     field->SetMapping(avCardMap);
       
   346     if(aStorageType==KStorageTypeDateTime)
       
   347     	{
       
   348     	//Get the int value
       
   349 		TBool res;
       
   350 		res = GetIntFromConfig(ConfigSection(), KIniYear, year);
       
   351 		if(!res)
       
   352 			{
       
   353 			ERR_PRINTF1(_L("Unable to read year val from ini file"));
       
   354 			SetTestStepResult(EFail);
       
   355 			}
       
   356 		res = GetIntFromConfig(ConfigSection(), KIniMonth, month);
       
   357 		if(!res)
       
   358 			{
       
   359 			ERR_PRINTF1(_L("Unable to read month val from ini file"));
       
   360 			SetTestStepResult(EFail);
       
   361 			}
       
   362 		res = GetIntFromConfig(ConfigSection(), KIniDay, day);
       
   363 		if(!res)
       
   364 			{
       
   365 			ERR_PRINTF1(_L("Unable to read day val from ini file"));
       
   366 			SetTestStepResult(EFail);
       
   367 			}
       
   368 		TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   369    		field->DateTimeStorage()->SetTime(date);
       
   370     	}
       
   371     else
       
   372     	{
       
   373     	field->TextStorage()->SetTextL(aValue);	
       
   374     	}	
       
   375    	item->AddFieldL(*field); 
       
   376    	
       
   377    	// Get the value from ini file for update
       
   378    	GetStringFromConfig(ConfigSection(), KIniUpdatedvalue, updateVal);
       
   379 	GetIntFromConfig(ConfigSection(), KIniUpdateYear, year);
       
   380     GetIntFromConfig(ConfigSection(), KIniUpdateMonth, month);
       
   381     GetIntFromConfig(ConfigSection(), KIniUpdateDay, day);
       
   382    
       
   383 	CContactItemFieldSet& ContactFieldSet = item->CardFields();
       
   384 	TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);
       
   385 	
       
   386 	if(aStorageType==KStorageTypeDateTime)
       
   387     	{
       
   388     	// update the field value
       
   389 		TDateTime date(year,(TMonth)month,day,0,0,0,0);
       
   390    		field->DateTimeStorage()->SetTime(date);
       
   391    		ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos);
       
   392    		
       
   393    		// verify the updated field value
       
   394    		TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap);
       
   395    		TDateTime result=ContactFieldSet[upadtePos].DateTimeStorage()->Time().DateTime();
       
   396    		if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
       
   397 				{
       
   398 				SetTestStepResult(EPass);	
       
   399 				}
       
   400 			else
       
   401 				{
       
   402 				SetTestStepResult(EFail);	
       
   403 				}
       
   404     	}
       
   405     else
       
   406     	{
       
   407     	// Update the field value
       
   408 		ContactFieldSet[pos].TextStorage()->SetTextL(updateVal);
       
   409 		ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos);
       
   410 		
       
   411 		// verify the field is being updated 
       
   412 		TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap);
       
   413 		getUpdateValue.Set(ContactFieldSet[upadtePos].TextStorage()->Text());
       
   414 	
       
   415 		//compair the results
       
   416 		if(getUpdateValue.Compare(updateVal)==0 )
       
   417 			{
       
   418 			SetTestStepResult(EPass);
       
   419 			}
       
   420 		else
       
   421 			{
       
   422 			SetTestStepResult(EFail);
       
   423 			}
       
   424     	}
       
   425    	CleanupStack::Pop(field);
       
   426 	CleanupStack::PopAndDestroy(item);
       
   427 	CleanupStack::PopAndDestroy(contactTemplate);
       
   428 	CleanupStack::PopAndDestroy(base);
       
   429 	}