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