TContactItemId CPbTester::AddEntryL()
	{
	_LIT(KForename,"John"); 
	_LIT(KSurname,"Smith"); 
	_LIT(KPhoneNumber,"+441617779700"); 

	// Create a  contact card to contain the data
	CContactCard* newCard = CContactCard::NewLC();

	// Create the firstName field and add the data to it
	CContactItemField* firstName = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
	firstName->TextStorage()->SetTextL(KForename);
	newCard->AddFieldL(*firstName);
	CleanupStack::Pop(firstName);

	// Create the lastName field and add the data to it
	CContactItemField* lastName= CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
	lastName ->TextStorage()->SetTextL(KSurname);
	newCard->AddFieldL(*lastName);
	CleanupStack::Pop(lastName);

	// Create the phoneNo field and add the data to it
	CContactItemField* phoneNumber = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber);
	phoneNumber->SetMapping(KUidContactFieldVCardMapTEL);
	phoneNumber ->TextStorage()->SetTextL(KPhoneNumber);
	newCard->AddFieldL(*phoneNumber);
	CleanupStack::Pop(phoneNumber);

	// Add newCard to the database
	const TContactItemId contactId = ipbDb->AddNewContactL(*newCard);

	CleanupStack::PopAndDestroy(newCard);

	return contactId;
	}
CContactItemField* CFilteredViewTester::CreateFieldLC(const TUid aMappingUId, TFieldType aFieldType, const TDesC &aText)
	{
	CContactItemField * field =CContactItemField::NewLC(KStorageTypeText, aFieldType);
	field->SetMapping(aMappingUId);
	field->TextStorage()->SetTextL(aText);
	return field;
	}
Esempio n. 3
0
QList<CContactItemField *> CntTransformUrl::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactUrl::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to url
	const QContactUrl &url(static_cast<const QContactUrl&>(detail));

	//create new field
	TPtrC fieldText(reinterpret_cast<const TUint16*>(url.url().utf16()));
	if(fieldText.Length()) {
	    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldUrl);
	    newField->TextStorage()->SetTextL(fieldText);
	    newField->SetMapping(KUidContactFieldVCardMapURL);

	    QString subType = url.subType();
	    const QString& subTypeHomePage(QContactUrl::SubTypeHomePage);
	    if (subType.length() != 0 && subType.compare(subTypeHomePage) != 0)
	    {
	        User::LeaveIfError(KErrNotSupported);
	    }

	    //contexts
	    setContextsL(url, *newField);

	    fieldList.append(newField);
	    CleanupStack::Pop(newField);
	}

	return fieldList;
}
/** Create Contact Item and add field to it and 
 *	verify the field is being added
 *	aValue - field value
 *  @param aStorageType - Storage type of each field
 *	@param aContFieldUid - Uid of Contact field
 *	@param avCardMapUid - Uid of vCard 
 *	@return - void
*/	
void CTestAddFieldsStep::AddFieldsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)	
	{
	TPtrC value;
	TInt year, month, day;

	// Create contact Item and add field to it	
	CContactItem* item = CContactCard::NewLC();
    CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid);
    CleanupStack::PushL(field); 
    field->SetMapping(avCardMap);
    if(aStorageType==KStorageTypeDateTime)
    	{
    	GetIntFromConfig(ConfigSection(), KIniYear, year);
    	GetIntFromConfig(ConfigSection(), KIniMonth, month);
    	GetIntFromConfig(ConfigSection(), KIniDay, day);
		TDateTime date(year,(TMonth)month,day,0,0,0,0);
   		field->DateTimeStorage()->SetTime(date);
    	}
    else
    	{
    	field->TextStorage()->SetTextL(aValue);	
    	}	
   	item->AddFieldL(*field);   
  
   	// verify the field is being added    	
	CContactItemFieldSet& ContactFieldSet = item->CardFields();
	TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);	
	if(pos != KErrNotFound)	
		{
		if(aStorageType==KStorageTypeDateTime)
			{
			TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
			//compair the results
			if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
				{
				SetTestStepResult(EPass);	
				}
			else
				{
				SetTestStepResult(EFail);	
				}
			}
		else
			{	
			value.Set(ContactFieldSet[pos].TextStorage()->Text());
			//compair the results
			if(aValue.Compare(value)==0 )
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			}
		}
	CleanupStack::Pop(field);
	CleanupStack::PopAndDestroy(item);
	}
Esempio n. 5
0
void CAccessCountTests::AddAgentFieldL(const TContactItemId aCid)
	{
	_LIT(KAgentName, "ImAnAgent");
	CContactItemField * field = CContactItemField::NewLC(KStorageTypeContactItemId, KUidContactFieldVCardMapAGENT );
	field->SetMapping(KUidContactFieldVCardMapAGENT);
	field->SetLabelL(KAgentName);
	field->AgentStorage()->SetAgentId(aCid);
	iFields->AddL(*field);
	CleanupStack::Pop(field);
	field = NULL;
	}
LOCAL_C void TestUpdateContactL()
{
    test.Next(_L("TestUpdateContactL"));

    SETUP;

    CContactItem* contact = CContactItem::NewLC(KUidContactCard);

    TContactItemId id = cntClient.CreateContactL(*contact);
    CleanupStack::PopAndDestroy(contact);

    // View definition to read image field
    CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldMatchAll);

    contact = cntClient.OpenContactLX(imageViewDef ,id);
    CleanupStack::PushL(contact);

    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
    newField->SetMapping(KUidContactFieldVCardMapUnknown);
    newField->TextStorage()->SetTextL(KSrcImage());
    contact->AddFieldL(*newField); // Takes ownership
    CleanupStack::Pop(newField);

    cntClient.CommitContactL(*contact, EFalse);
    CleanupStack::PopAndDestroy(2);  //  contact, imageViewDef

    // View definition to read image field
    imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldCodImage);

    contact = cntClient.ReadContactL(imageViewDef ,id);

    TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);

    // Test image field found
    test(index != KErrNotFound);

    CContactItemField& field = contact->CardFields()[index];
    TPtrC imagePtr = field.TextStorage()->Text();

    // Image should exist
    test(BaflUtils::FileExists(fs, imagePtr));

    // Test for GUID
    TPtrC guid = contact->Guid();
    test(imagePtr.Find(guid));

    cntClient.CloseContact(id);
    CleanupStack::PopAndDestroy(2);  //  contact, imageViewDef

    TEAR_DOWN;
}
Esempio n. 7
0
/** 
 * Create template card for ICC contact items 
 * @param aDb Contact database
 */
TContactItemId CreateICCTemplateL(CContactDatabase& aDb)
	{
	CContactItem* temp = aDb.CreateContactCardTemplateLC(KTemplateName);
	TContactItemId templateId = temp->Id();
	CleanupStack::PopAndDestroy(temp);
	temp=NULL;

	//Remove all the unnecessary fields
	temp = aDb.OpenContactLX(templateId);
	CleanupStack::PushL(temp);	
	const TInt fieldCount = temp->CardFields().Count();
	for(TInt i=fieldCount-1;i>=0;i--)
		temp->RemoveField(i);
		
	CContactItemField* name = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldFamilyName);
	name->SetMapping(KUidContactFieldVCardMapUnusedN);
	temp->AddFieldL(*name);
	CleanupStack::Pop(name);

	CContactItemField* number = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
	number->SetMapping(KUidContactFieldVCardMapTEL);
	temp->AddFieldL(*number);
	CleanupStack::Pop(number);
				
	CContactItemField* slotnum = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldICCSlot);
	temp->AddFieldL(*slotnum);
	CleanupStack::Pop(slotnum);

	CContactItemField* phonebook = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldICCPhonebook);
	temp->AddFieldL(*phonebook);
	CleanupStack::Pop(phonebook);

	aDb.CommitContactL(*temp);
	CleanupStack::PopAndDestroy(2);	// temp, close template	
	
	return templateId;
	}
Esempio n. 8
0
/**Utility function for adding agent to a contact item*/
void CAgentTest::MakeAgentL(TContactItemId aMainContactId, TContactItemId aAgentId)
	{
	CContactItem* mainItem = NULL;
	CContactItemField* field = NULL;

	mainItem = iDb->OpenContactL(aMainContactId);
	CleanupStack::PushL(mainItem);
	field = CContactItemField::NewLC(KStorageTypeContactItemId, KUidContactFieldVCardMapAGENT );
	field->SetMapping(KUidContactFieldVCardMapAGENT);
	field->AgentStorage()->SetAgentId(aAgentId);
	mainItem->AddFieldL(*field);
	CleanupStack::Pop();

	iDb->CommitContactL(*mainItem);
	CleanupStack::PopAndDestroy();
	}
void CPbTester::EditEntryL(TContactItemId itemId)
	{
	_LIT(KEmailAddress,"*****@*****.**"); 
	CContactItem *item = ipbDb->OpenContactL(itemId);
	CContactCard* card = NULL;
	CleanupStack::PushL(item);

	card = (CContactCard*)item;
	// Create the emailAddress field and add the data to it
	CContactItemField* emailAddr = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldEMail);
	emailAddr->SetMapping(KUidContactFieldVCardMapEMAILINTERNET);
	emailAddr ->TextStorage()->SetTextL(KEmailAddress);
	card->AddFieldL(*emailAddr);
	CleanupStack::Pop(emailAddr);

	ipbDb->CommitContactL(*item);
	CleanupStack::PopAndDestroy(item);
	}
LOCAL_C void TestDeleteContactL()
{
    test.Next(_L("TestDeleteContactL"));

    SETUP;

    CContactItem* contact = CContactItem::NewLC(KUidContactCard);

    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
    newField->SetMapping(KUidContactFieldVCardMapUnknown);
    newField->TextStorage()->SetTextL(KSrcImage());
    contact->AddFieldL(*newField); // Takes ownership
    CleanupStack::Pop(newField);

    TContactItemId id = cntClient.CreateContactL(*contact);
    CleanupStack::PopAndDestroy(contact);

    // View definition to read image field
    CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldCodImage);

    contact = cntClient.ReadContactL(imageViewDef ,id);
    CleanupStack::PopAndDestroy(imageViewDef);  //  imageViewDef

    TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);

    // Test image field found
    test(index != KErrNotFound);

    CContactItemField& field = contact->CardFields()[index];
    TPtrC imagePtr = field.TextStorage()->Text();

    test(BaflUtils::FileExists(fs, imagePtr));

    cntClient.DeleteContactL(id, EDeferEvent, ETrue);

    test(!BaflUtils::FileExists(fs, imagePtr));

    cntClient.CloseContact(id);
    delete contact;

    TEAR_DOWN;
}
Esempio n. 11
0
void CLowDiskSpaceTest::AddContactToDatabaseL()
	{
	_LIT(KXChar, "x");
	CContactItem* item = CContactCard::NewLC();
	CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCompanyName);
	field->SetMapping(KUidContactFieldVCardMapORG);
	field->TextStorage()->SetTextL(KXChar() );
	item->AddFieldL(*field);
	CleanupStack::Pop(); // field
	field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
	field->SetMapping(KUidContactFieldVCardMapTEL);
	field->TextStorage()->SetTextL(KXChar() );
	item->AddFieldL(*field);
	CleanupStack::Pop(); // field
	field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
 	field->SetMapping(KUidContactFieldVCardMapTEL);
	field->TextStorage()->SetTextL(KXChar() );
	item->AddFieldL(*field);
	CleanupStack::Pop(); // field
	field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
 	field->SetMapping(KUidContactFieldVCardMapTEL);
	field->TextStorage()->SetTextL(KXChar() );
	item->AddFieldL(*field);
	CleanupStack::Pop(); // field
	field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
	field->SetMapping(KUidContactFieldVCardMapTEL);
 	field->SetHidden(ETrue);
	field->TextStorage()->SetTextL(KXChar() );
	item->AddFieldL(*field);
	CleanupStack::Pop(); // field
	field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldSuffixName);
	field->SetMapping(KUidContactFieldVCardMapUnusedN);
	field->TextStorage()->SetTextL(KXChar() );
 	item->AddFieldL(*field);
	CleanupStack::Pop(); // field
	field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPrefixName);
	field->SetMapping(KUidContactFieldVCardMapUnusedN);
	field->TextStorage()->SetTextL(KXChar() );
 	item->AddFieldL(*field);
	CleanupStack::Pop(); // field

	iContactDatabase->AddNewContactL(*item);
	CleanupStack::PopAndDestroy(); // item
	}
QList<CContactItemField *> CntTransformBirthday::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactBirthday::DefinitionName)
       User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to birthday
	const QContactBirthday &birthday(static_cast<const QContactUrl&>(detail));

	//create new field
	TDateTime dateTime(birthday.date().year(), TMonth(birthday.date().month() - 1), birthday.date().day() - 1, 0, 0, 0, 0);
	CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldBirthday);
 	newField->DateTimeStorage()->SetTime(dateTime);
	newField->SetMapping(KUidContactFieldVCardMapBDAY);

	fieldList.append(newField);
	CleanupStack::Pop(newField);

	return fieldList;
}
QList<CContactItemField *> CntTransformAvatar::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactAvatar::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

    //cast to avatar
    const QContactAvatar &avatar(static_cast<const QContactAvatar&>(detail));

    //create new field
    QString urlString = avatar.imageUrl().toString();
    TPtrC fieldText(reinterpret_cast<const TUint16*>(urlString.utf16()));

    //copy filename and replace slash with a backslash
    TFileName filename;
    for(TInt i(0); i < fieldText.Length(); ++i) {
        if(i >= filename.MaxLength())
            User::Leave(KErrTooBig);
        if(fieldText[i] == '/') {
            filename.Append('\\');
        } else {
            filename.Append(fieldText[i]);
        }
    }

    if(filename.Length()) {
        TUid uid(KUidContactFieldCodImage);

        CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, uid);

        newField->SetMapping(KUidContactFieldVCardMapUnknown);
        newField->TextStorage()->SetTextL(filename);

        fieldList.append(newField);
        CleanupStack::Pop(newField);
    }

    return fieldList;
}
QList<CContactItemField *> CntTransformAnniversarySimple::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactAnniversary::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

    //cast to anniversary
    const QContactAnniversary &anniversary(static_cast<const QContactAnniversary&>(detail));

    //create new field
    TDateTime dateTime(anniversary.originalDate().year(),
                       TMonth(anniversary.originalDate().month() - 1),
                       anniversary.originalDate().day() - 1, 0, 0, 0, 0);
    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeDateTime, KUidContactFieldAnniversary);
    newField->DateTimeStorage()->SetTime(dateTime);
    newField->SetMapping(KUidContactFieldVCardMapAnniversary);

    fieldList.append(newField);
    CleanupStack::Pop(newField);

    return fieldList;
}
/** Create Multiple Contact Item with field and Add all contact
 *	Item to Contact database. verify field is 
 *	being added 
 *	aValue - field value
 *  @param aStorageType - Storage type of each field
 *	@param aContFieldUid - Uid of Contact field
 *	@param avCardMapUid - Uid of vCard 
 *	@return - void
*/		
void CTestAddMultipleContactsStep::AddMultipleContactsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)	
	{
	TPtrC value;
   _LIT(KTestDbName, "c:contactmultiple.cdb");
   	TInt year, month, day,noOfCI;	
   	RArray <TInt> idArray;
	CleanupClosePushL(idArray); 
	
	//replace existing database name
	database = CContactDatabase::ReplaceL(KTestDbName); 
	 
	//Get the number of contact item from ini file
	GetIntFromConfig(ConfigSection(), KNoOfContactItem, noOfCI);
	
	//Get the int value
	GetIntFromConfig(ConfigSection(), KIniYear, year);
	GetIntFromConfig(ConfigSection(), KIniMonth, month);
	GetIntFromConfig(ConfigSection(), KIniDay, day);
	
    // Create contact item and add field to it
    for(TInt range=0;range<noOfCI;range++)
    	{
		CContactItem* item = CContactCard::NewLC();
		CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid);
		CleanupStack::PushL(field); 
		field->SetMapping(avCardMap);
		if(aStorageType==KStorageTypeDateTime)
			{
			TDateTime date(year,(TMonth)month,day,0,0,0,0);
			field->DateTimeStorage()->SetTime(date);
			}
			else
			{
			field->TextStorage()->SetTextL(aValue);	
			}	
			item->AddFieldL(*field);  
			CleanupStack::Pop(field);
			
		// add contact item to database  
		id = database->AddNewContactL(*item);
		
		//append the id in array
		idArray.Append(id);
		
		//Cleanup
		CleanupStack::PopAndDestroy(item);	
    	}
    database->CloseContactL(id);
    
    // verify for multiple contact item with field is being created
    CContactItem *readItem = NULL;
    for(TInt readContact=0;readContact<noOfCI;readContact++)
    	{
    	readItem = database->ReadContactL(idArray[readContact]);
    	CleanupStack::PushL(readItem);
    	CContactItemFieldSet& ContactFieldSet = readItem->CardFields();
		TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);	
		if(pos != KErrNotFound)	
			{
			if(aStorageType==KStorageTypeDateTime)
				{
				TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
				if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
					{
					SetTestStepResult(EPass);	
					}
				else
					{
					SetTestStepResult(EFail);	
					}
				}
			else
				{	
				value.Set(ContactFieldSet[pos].TextStorage()->Text());
				//compare the results
				if(aValue.Compare(value)==0 )
					{
					SetTestStepResult(EPass);
					}
				else
					{
					SetTestStepResult(EFail);
					}
				}
			}
		CleanupStack::PopAndDestroy(readItem);		
    	}
    // Cleanup
    CleanupStack::PopAndDestroy(&idArray);
  	delete database;	
	}
Esempio n. 16
0
/** Create Contact user defuned Template add add field to contact item  
 *	through template and verify the field is being added
 *	aValue - field value
 *  @param aStorageType - Storage type of each field
 *	@param aContFieldUid - Uid of Contact field
 *	@param avCardMapUid - Uid of vCard 
 *	@return - void
*/	
void CTestAddFieldsStep::AddFieldsNewTemplateL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)	
	{
	TPtrC value;
	TInt year, month, day;
	CContactDatabase *base = NULL;
	_LIT(KTestDbName, "c:mytemplate.cdb");
	_LIT(KUserDefinedTemplate,"MyTemplate");
	
	// replace existing database name
	base = CContactDatabase::ReplaceL(KTestDbName);
	CleanupStack::PushL(base);
		
	TContactItemId TempId ;
	CContactItemField* field = NULL;
	
	//Create User defined Template
	CContactItem* contactTemplate = base->CreateContactCardTemplateLC(KUserDefinedTemplate);
	
	// Get the ID of Template
	TempId = contactTemplate->Id();
	
	//Add fields to it
    field = CContactItemField::NewL(aStorageType, aContFieldUid);
    CleanupStack::PushL(field); 
    field->SetMapping(avCardMap);
    contactTemplate->AddFieldL(*field);  
   	CleanupStack::Pop(field);
   	
	//Allocates and constructs a new contact card.
	CContactItem* item = CContactCard::NewLC();
	
	//Sets the ID of the template on which this contact item is based
	item->SetTemplateRefId(TempId);
	
	//create contact item and add field value to it
    field = CContactItemField::NewL(aStorageType, aContFieldUid);
    CleanupStack::PushL(field); 
    field->SetMapping(avCardMap);
    if(aStorageType==KStorageTypeDateTime)
    	{
    	//Get the int value
		TBool res;
		res = GetIntFromConfig(ConfigSection(), KIniYear, year);
		if(!res)
			{
			ERR_PRINTF1(_L("Unable to read year val from ini file"));
			SetTestStepResult(EFail);
			}
		res = GetIntFromConfig(ConfigSection(), KIniMonth, month);
		if(!res)
			{
			ERR_PRINTF1(_L("Unable to read month val from ini file"));
			SetTestStepResult(EFail);
			}
		res = GetIntFromConfig(ConfigSection(), KIniDay, day);
		if(!res)
			{
			ERR_PRINTF1(_L("Unable to read day val from ini file"));
			SetTestStepResult(EFail);
			}
		TDateTime date(year,(TMonth)month,day,0,0,0,0);
   		field->DateTimeStorage()->SetTime(date);
    	}
    else
    	{
    	field->TextStorage()->SetTextL(aValue);	
    	}	
   	item->AddFieldL(*field); 

   	// verify the field is being added to the user defined template    	
	CContactItemFieldSet& ContactFieldSet = item->CardFields();
	TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);	
	if(pos != KErrNotFound)	
		{
		if(aStorageType==KStorageTypeDateTime)
			{
			TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
			//compair the results
			if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
				{
				SetTestStepResult(EPass);	
				}
			else
				{
				SetTestStepResult(EFail);	
				}
			}
		else
			{	
			value.Set(ContactFieldSet[pos].TextStorage()->Text());
			//compair the results
			if(aValue.Compare(value)==0 )
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			}
		}
	CleanupStack::Pop(field);
	CleanupStack::PopAndDestroy(item);
	CleanupStack::PopAndDestroy(contactTemplate);
	CleanupStack::PopAndDestroy(base);
	}
void CTestAddMultipleContactsStep::OpenExistingContactL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)
	{
	TPtrC value,fielddel;
   _LIT(KTestDbName, "c:contactexist.cdb");
   _LIT(KExistDelete, "exist");
   	TInt year, month, day;	
   	
    // Create contact item and add field to it
	CContactItem* item = CContactCard::NewLC();
    CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid);
    CleanupStack::PushL(field); 
    field->SetMapping(avCardMap);
    if(aStorageType==KStorageTypeDateTime)
    	{
    	GetIntFromConfig(ConfigSection(), KIniYear, year);
    	GetIntFromConfig(ConfigSection(), KIniMonth, month);
    	GetIntFromConfig(ConfigSection(), KIniDay, day);
		TDateTime date(year,(TMonth)month,day,0,0,0,0);
   		field->DateTimeStorage()->SetTime(date);
    	}
    else
    	{
    	field->TextStorage()->SetTextL(aValue);	
    	}	
   	item->AddFieldL(*field);  
   	CleanupStack::Pop(field);
   
   	//replace existing database name
   	database = CContactDatabase::ReplaceL(KTestDbName);  
   	
   	// add contact item to database  
  	id = database->AddNewContactL(*item);
  	CleanupStack::PopAndDestroy(item);
  
  	//reopen the contact
  	CContactItem *openItem = database->OpenContactL(id);
  	CleanupStack::PushL(openItem);
  	
  	//create contactitem field and add to it.
  	CContactItemField* newField = CContactItemField::NewL(aStorageType, aContFieldUid);
    CleanupStack::PushL(newField); 
    newField->SetMapping(avCardMap);
    if(aStorageType==KStorageTypeDateTime)
    	{
    	GetIntFromConfig(ConfigSection(), KIniYear, year);
    	GetIntFromConfig(ConfigSection(), KIniMonth, month);
    	GetIntFromConfig(ConfigSection(), KIniDay, day);
		TDateTime date(year,(TMonth)month,day,0,0,0,0);
   		newField->DateTimeStorage()->SetTime(date);
    	}
    else
    	{
    	newField->TextStorage()->SetTextL(aValue);	
    	}	
   	openItem->AddFieldL(*newField);  
   	CleanupStack::Pop(newField);
  
   	// verify the field is being added   
   	CContactItemFieldSet& ContactFieldSetOpen = openItem->CardFields();
   	TInt startPos=0;
   	for(TInt check=0; check<2; check++)
   		{
		TInt pos = ContactFieldSetOpen.FindNext(aContFieldUid, avCardMap, startPos);
		TInt noOfFields = ContactFieldSetOpen.Count();	
		if(pos != KErrNotFound)	
			{
			if(aStorageType==KStorageTypeDateTime)
				{
				TDateTime result=ContactFieldSetOpen[pos].DateTimeStorage()->Time().DateTime();
				startPos=startPos+1;
				if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
					{
					SetTestStepResult(EPass);	
					}
				else
					{
					SetTestStepResult(EFail);	
					}
				}
			else
				{	
				value.Set(ContactFieldSetOpen[pos].TextStorage()->Text());
				startPos=startPos+1;
				//compare the results
				if(aValue.Compare(value)==0 )
					{
					SetTestStepResult(EPass);
					}
				else
					{
					SetTestStepResult(EFail);
					}
				}
			}
   		}
	GetStringFromConfig(ConfigSection(), KIniFlagDelete, fielddel);
  	if(KErrNone == fielddel.Compare(KExistDelete))
		{
		TRAPD(ret, DeleteExistContactL(aContFieldUid, avCardMap));
		if(ret!=KErrNone)
			{
			database->CloseContactL(id);
  			delete database;
  			return;
			}
		}
	database->CloseContactL(id);
	CleanupStack::PopAndDestroy(openItem);
  	delete database;		
	}
Esempio n. 18
0
/** Create Contact Item and add couple of same fields to it and 
 *	verify the field is being added
 *	aValue - field value
 *  @param aStorageType - Storage type of each field
 *	@param aContFieldUid - Uid of Contact field
 *	@param avCardMapUid - Uid of vCard 
 *	@return - void
*/		
void CTestAddFieldsStep::AddCoupleFieldsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)	
	{
	TPtrC value;
	TInt year, month, day;
	CContactItemField* field;
	
	// Get the value form ini file
	GetIntFromConfig(ConfigSection(), KIniYear, year);
    GetIntFromConfig(ConfigSection(), KIniMonth, month);
    GetIntFromConfig(ConfigSection(), KIniDay, day);
    
	// Create contact Item and add same field twice to it
	CContactItem* item = CContactCard::NewLC();
	for(TInt x=0; x<2; x++)
		{
    	field = CContactItemField::NewL(aStorageType, aContFieldUid);
    	CleanupStack::PushL(field); 
    	field->SetMapping(avCardMap);
    	if(aStorageType==KStorageTypeDateTime)
    		{
			TDateTime date(year,(TMonth)month,day,0,0,0,0);
   			field->DateTimeStorage()->SetTime(date);
    		}
    	else
    		{
    		field->TextStorage()->SetTextL(aValue);	
    		}	
   		item->AddFieldL(*field);  
   		CleanupStack::Pop(field);
		}  
	CContactItemFieldSet& ContactFieldSetOpen = item->CardFields();	
	
   	// verify the field is being added 
   	TInt startPos=0;
   	for(TInt check=0; check<2; check++)
   		{
		TInt pos = ContactFieldSetOpen.FindNext(aContFieldUid, avCardMap,startPos);	
		if(pos != KErrNotFound)	
			{
			if(aStorageType==KStorageTypeDateTime)
				{
				TDateTime result=ContactFieldSetOpen[pos].DateTimeStorage()->Time().DateTime();
				startPos=startPos+1;
				if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
					{
					SetTestStepResult(EPass);	
					}
				else
					{
					SetTestStepResult(EFail);	
					}
				}
			else
				{	
				value.Set(ContactFieldSetOpen[pos].TextStorage()->Text());
				startPos=startPos+1;
				//compair the results
				if(aValue.Compare(value)==0 )
					{
					SetTestStepResult(EPass);
					}
				else
					{
					SetTestStepResult(EFail);
					}
				}
			}
   	}	
	CleanupStack::PopAndDestroy(item);	
	}
Esempio n. 19
0
/** Create Contact Item and add all fields to it and 
 *	verify the field is being added
 *	@return - void
*/	
void CTestAddFieldsStep::AddAllFieldsL()	
	{
	RArray<TPtrC> readValues;
	CleanupClosePushL(readValues);
	TPtrC temp, value;
	TInt year, month, day,readPos=0;
	
	// get string value from ini file.
	if(!GetStringFromConfig(ConfigSection(), KIniFieldAsstVal, temp))
		{
		ERR_PRINTF1(_L("Unable to read val from ini file"));
		SetTestStepResult(EFail);
		}
	else
		{
		readValues.Append(temp);
		}	
	if(!GetStringFromConfig(ConfigSection(), KIniFieldAsstTelVal, temp))
		{
		ERR_PRINTF1(_L("Unable to read val from ini file"));
		SetTestStepResult(EFail);
		}
	else
		{
		readValues.Append(temp);
		}
	if(!GetStringFromConfig(ConfigSection(), KIniFieldSpouseVal, temp))
		{
		ERR_PRINTF1(_L("Unable to read val from ini file"));
		SetTestStepResult(EFail);
		}
	else
		{
		readValues.Append(temp);
		}	
	if(!GetStringFromConfig(ConfigSection(), KIniFieldChildVel, temp))
		{
		ERR_PRINTF1(_L("Unable to read val from ini file"));
		SetTestStepResult(EFail);
		}
	else
		{
		readValues.Append(temp);	
		}	
	if(!GetStringFromConfig(ConfigSection(), KIniFieldClassVal, temp))
		{
		ERR_PRINTF1(_L("Unable to read val from ini file"));
		SetTestStepResult(EFail);
		}
	else
		{
		readValues.Append(temp);	
		}
	if(!GetStringFromConfig(ConfigSection(), KIniFieldDeptVal, temp))
		{
		ERR_PRINTF1(_L("Unable to read val from ini file"));
		SetTestStepResult(EFail);
		}
	else
		{
		readValues.Append(temp);	
		}	
	
	// get int val from ini file
	GetIntFromConfig(ConfigSection(), KIniYear, year);
    GetIntFromConfig(ConfigSection(), KIniMonth, month);
    GetIntFromConfig(ConfigSection(), KIniDay, day);
    	
	CContactItemField* field = NULL;
	// Create contact Item and add all fields to it
	CContactItem* item = CContactCard::NewLC();
	for(TInt x=0; x<7; x++)
		{
    	field = CContactItemField::NewL(iStorage[x], iFieldUid[x]);
    	CleanupStack::PushL(field); 
    	field->SetMapping(iVcardUid[x]);
    	if(iStorage[x]==KStorageTypeDateTime)
    		{
			TDateTime date(year,(TMonth)month,day,0,0,0,0);
   			field->DateTimeStorage()->SetTime(date);
    		}
    	else
    		{
    		field->TextStorage()->SetTextL(readValues[readPos++]);	
    		}	
   		item->AddFieldL(*field);  
   		CleanupStack::Pop(field);
		}   
	readPos=0;
	// verify the field is being added    
	for(TInt x=0; x<7; x++)	
	{	
		CContactItemFieldSet& ContactFieldSet = item->CardFields();
		TInt pos = ContactFieldSet.Find(iFieldUid[x], iVcardUid[x]);	
		if(pos != KErrNotFound)	
			{
			if(iStorage[x]==KStorageTypeDateTime)
				{
				TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
				if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
					{
					SetTestStepResult(EPass);	
					}
				else
					{
					SetTestStepResult(EFail);	
					}
				}
			else
				{
				value.Set(ContactFieldSet[pos].TextStorage()->Text());
				if(value.Compare(readValues[readPos++])==0 )
					{
					SetTestStepResult(EPass);
					}
				else
					{
					SetTestStepResult(EFail);
					}
				}	
					
			}
	}
	
	//Cleanup stack
	CleanupStack::PopAndDestroy(item);
	CleanupStack::PopAndDestroy(&readValues);
	}
Esempio n. 20
0
QList<CContactItemField *> CntTransformPhoneNumber::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactPhoneNumber::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to phonenumber
	const QContactPhoneNumber &phoneNumber(static_cast<const QContactPhoneNumber&>(detail));

	//get the subType
	QStringList subTypes = phoneNumber.subTypes();

	//create new field
	TPtrC fieldText(reinterpret_cast<const TUint16*>(phoneNumber.number().utf16()));
	if(fieldText.Length()) {
	    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText);
	    newField->TextStorage()->SetTextL(fieldText);

	    //no subtype
	    if(!subTypes.count())
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	    }

	    //landline
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeLandline))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapVOICE);
	    }

	    //mobile
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeMobile))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapCELL);
	    }

	    //fax
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeFax))
	    {
	        newField->AddFieldTypeL(KUidContactFieldFax);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapFAX);
	    }

	    //pager
	    else if (subTypes.contains(QContactPhoneNumber::SubTypePager))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapPAGER);
	    }

	    //bbs
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeBulletinBoardSystem))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapBBS);
	    }

	    //car
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeCar))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapTEL);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapCAR);
	    }

	    //DTMF
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeDtmfMenu))
	    {
	        newField->AddFieldTypeL(KUidContactFieldDTMF);
	        newField->SetMapping(KUidContactFieldVCardMapUnknown);
	    }

	    // assistant number
	    else if (subTypes.contains(QContactPhoneNumber::SubTypeAssistant))
	    {
	        newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
	        newField->SetMapping(KUidContactFieldVCardMapAssistantTel);
	    }
        
	    // video calls
        else if (subTypes.contains(QContactPhoneNumber::SubTypeVideo))
        {
            newField->AddFieldTypeL(KUidContactFieldPhoneNumber);
            newField->SetMapping(KUidContactFieldVCardMapTEL);
            newField->AddFieldTypeL(KUidContactFieldVCardMapVIDEO);
        }
	    else
	    {
	        User::LeaveIfError(KErrNotSupported);
	    }

	    //contexts
	    setContextsL(phoneNumber, *newField);

	    fieldList.append(newField);
	    CleanupStack::Pop(newField);
	}

	return fieldList;
}
LOCAL_C void TestCreateContactWithoutImagesFoldeL()
{
    test.Next(_L("TestCreateContactWithoutImagesFoldeL"));

    SETUP;

    // Delete the images folder and all contents
    TInt drive;

#ifdef __WINS__
    TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive);
#else
    TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive);
#endif

    // Do not leave with this error. The phone does not have to have this support
    if (err == KErrNone)
    {
        // Get the root path in this drive to create
        // to create the images directory
        TPath dir;
        User::LeaveIfError(PathInfo::GetRootPath(dir, drive));
        dir.Append(KImagesFolder);

        CFileMan* fileMan = CFileMan::NewL(fs);
        err = fileMan->RmDir(dir); // err not used
        delete fileMan;
    }
    else
    {
        test.Printf(_L("Could not remove the images folder\n"));
        return;
    }

    // Create an image and store an image without the images dir available
    CContactItem *contact = CContactItem::NewLC(KUidContactCard);

    CContactItemField *newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
    newField->SetMapping(KUidContactFieldVCardMapUnknown);
    newField->TextStorage()->SetTextL(KSrcImage());
    contact->AddFieldL(*newField); // Takes ownership
    CleanupStack::Pop(newField);

    TContactItemId id = cntClient.CreateContactL(*contact);
    CleanupStack::PopAndDestroy(contact);

    // View definition to read image field
    CContactItemViewDef *imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldCodImage);

    contact = cntClient.ReadContactL(imageViewDef ,id);
    CleanupStack::PopAndDestroy(imageViewDef);  //  imageViewDef

    TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);

    // Test image field found
    test(index != KErrNotFound);

    CContactItemField& field = contact->CardFields()[index];
    TPtrC imagePtr = field.TextStorage()->Text();

    // Image path should not change
    test(imagePtr.Compare(KSrcImage()) == 0);

    cntClient.CloseContact(id);
    delete contact;

    TEAR_DOWN;
}
/**
 * Creating 1000 contact item with all new fields
 * @return - void
 */
void CTestContactPerformanceStep::FieldPerformanceL()
{
    TPtrC value, temp;
    _LIT(KTestDbName, "c:contactmultiple.cdb");
    TInt readPos=0;
    TContactItemId id = 0;
    _LIT(KUpdate,	"update");
    _LIT(KDelete,	"delete");
    CleanupClosePushL(idArray);
    RArray<TPtrC> readValues;
    CleanupClosePushL(readValues);

    // get string value from ini file.
    GetStringFromConfig(ConfigSection(), KIniFieldAsstVal, temp);
    readValues.Append(temp);
    GetStringFromConfig(ConfigSection(), KIniFieldAsstTelVal, temp);
    readValues.Append(temp);
    GetStringFromConfig(ConfigSection(), KIniFieldSpouseVal, temp);
    readValues.Append(temp);
    GetStringFromConfig(ConfigSection(), KIniFieldChildVel, temp);
    readValues.Append(temp);
    GetStringFromConfig(ConfigSection(), KIniFieldClassVal, temp);
    readValues.Append(temp);
    GetStringFromConfig(ConfigSection(), KIniFieldDeptVal, temp);
    readValues.Append(temp);

    // get int val from ini file
    GetIntFromConfig(ConfigSection(), KIniYear, iYear);
    GetIntFromConfig(ConfigSection(), KIniMonth, iMonth);
    GetIntFromConfig(ConfigSection(), KIniDay, iDay);

    //replace existing database name
    dBase = CContactDatabase::ReplaceL(KTestDbName);

    //Get the number of contact item from ini file
    GetIntFromConfig(ConfigSection(), KNoOfContactItem, iNoOfCI);

    // Create contact item and add all fields to it
    for(TInt range=0; range<iNoOfCI; range++)
    {
        CContactItem* item = CContactCard::NewLC();
        for(TInt noOfFields=0; noOfFields<7; noOfFields++)
        {
            CContactItemField* field = CContactItemField::NewL(iStorage[noOfFields], iFieldUid[noOfFields]);
            CleanupStack::PushL(field);
            field->SetMapping(iVcardUid[noOfFields]);
            if(iStorage[noOfFields]==KStorageTypeDateTime)
            {
                TDateTime date(iYear,(TMonth)iMonth,iDay,0,0,0,0);
                field->DateTimeStorage()->SetTime(date);
            }
            else
            {
                field->TextStorage()->SetTextL(readValues[readPos++]);
            }
            item->AddFieldL(*field);
            CleanupStack::Pop(field);
        }

        // add contact item to database
        id = dBase->AddNewContactL(*item);

        //Append the id into array
        idArray.Append(id);
        readPos=0;

        // Cleanup
        CleanupStack::PopAndDestroy(item);
    }
    dBase->CloseContactL(id);

    // verify for multiple contact item with all fields is being added
    readPos=0;
    CContactItem *readItem = NULL;
    for(TInt readContact=0; readContact<iNoOfCI; readContact++)
    {
        readItem = dBase->ReadContactLC(idArray[readContact]);
        for(TInt check=0; check<7; check++)
        {
            CContactItemFieldSet& ContactFieldSet = readItem->CardFields();
            TInt pos = ContactFieldSet.Find(iFieldUid[check], iVcardUid[check]);
            if(pos != KErrNotFound)
            {
                if(iStorage[check]==KStorageTypeDateTime)
                {
                    TDateTime result=ContactFieldSet[pos].DateTimeStorage()->Time().DateTime();
                    //compare the results
                    if((result.Year() == iYear) && (result.Month() == (TMonth)iMonth) && (result.Day() == iDay))
                    {
                        SetTestStepResult(EPass);
                    }
                    else
                    {
                        SetTestStepResult(EFail);
                    }
                }
                else
                {
                    value.Set(ContactFieldSet[pos].TextStorage()->Text());
                    //compare the results
                    if(value.Compare(readValues[readPos++])==0 )
                    {
                        SetTestStepResult(EPass);
                    }
                    else
                    {
                        SetTestStepResult(EFail);
                    }
                }
            }
        }
        readPos=0;
        CleanupStack::PopAndDestroy(readItem);
    }
    CleanupStack::PopAndDestroy(&readValues);
    GetStringFromConfig(ConfigSection(), KIniFlagvalue, temp);
    if(KErrNone == temp.Compare(KUpdate))
    {
        UpdatePerformanceL();
    }
    else if(KErrNone == temp.Compare(KDelete))
    {
        DeletePerformanceL();
    }
    CleanupStack::PopAndDestroy(&idArray);
    delete dBase;
}
Esempio n. 23
0
void T_CntImageRescaler::testRescaleUtility()
{
    // delete the possible image directory, it must not leave
    // even if the folder was not found. 
    TRAPD( err, TCntImageRescaleUtility::DeleteImageDirectoryL() );
    test( err == KErrNone );
    
    // path for image directory, existense of the directory is not
    // checked
    TPath path = TCntImageRescaleUtility::ImageDirectoryL();
    test( path.Length() > 0 );
    test( path.Find(KImagesFolder) != KErrNotFound );
    
    TPath dir = TCntImageRescaleUtility::CreateImageDirectoryL();
    test( dir.Length() > 0 );
    test( dir.Find( KImagesFolder) != KErrNotFound );
  
    // make a test image file (empty file) 
    RFs fs;
    CleanupClosePushL( fs );
    User::LeaveIfError( fs.Connect() );
    
    TPath imagePath;
    imagePath.Append( dir );
    imagePath.Append( KImageName );
    
    RFile file;
    CleanupClosePushL(file);
    User::LeaveIfError(file.Create( fs, imagePath, EFileWrite ));
    CleanupStack::PopAndDestroy();
    
    CContactItem* item  = CContactItem::NewLC(KUidContactCard);
    CContactItemField* field = CContactItemField::NewL( KStorageTypeText, KUidContactFieldCodImage );
    field->SetMapping( KUidContactFieldVCardMapUnknown );
    item->AddFieldL( *field );

    // add image without GUID
    TRAPD( err2, TCntImageRescaleUtility::StoreImageFieldL( *item, imagePath ) );
    test( err2 == KErrNone );
    
    // then update with GUID value
    _LIT(KGuid, "guid");
    TBufC<4> buffer ( KGuid );
    item->SetUidStringL( buffer );
    
    TRAPD( err3, TCntImageRescaleUtility::UpdateImageNameL( *item ) );
    test( err3 == KErrNone );
    
    CContactItemFieldSet& fields = item->CardFields();
    TInt privateImageIndex = fields.Find( KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown );
    test( privateImageIndex != KErrNotFound );
    
    TPtrC fieldText = fields[privateImageIndex].TextStorage()->Text();
    
    // how it should look like
    TPath newPath;
    newPath.Append( TCntImageRescaleUtility::ImageDirectoryL() );
    newPath.Append( buffer );
    newPath.Append( KImageName );
    RDebug::Print( _L("%S"), &newPath );
    RDebug::Print( _L("%S"), &fieldText );
    
    test( newPath.Compare(fieldText) == 0 );
    BaflUtils::DeleteFile( fs, newPath );
    CleanupStack::PopAndDestroy(2); // item, RFs
}
QList<CContactItemField *> CntTransformOnlineAccount::transformDetailL(const QContactDetail &detail)
{
    if(detail.definitionName() != QContactOnlineAccount::DefinitionName)
        User::Leave(KErrArgument);

    QList<CContactItemField *> fieldList;

	//cast to phonenumber
	const QContactOnlineAccount &onlineAccount(static_cast<const QContactOnlineAccount&>(detail));

	//get the subType
	QStringList subTypes = onlineAccount.subTypes();

	//create new field
	TPtrC fieldText(reinterpret_cast<const TUint16*>(onlineAccount.accountUri().utf16()));
	if(fieldText.Length()) {
        HBufC* detailCount = HBufC::NewLC(KMaxDetailCounterLength);
        detailCount->Des().AppendNum(m_detailCounter);
	
	    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText);
	    newField->TextStorage()->SetTextL(fieldText);

	    //no subtype
	    if(!subTypes.count())
	    {
	        User::LeaveIfError(KErrArgument);
	    }

	    // online account
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeImpp))
	    {
	        newField->AddFieldTypeL(KUidContactFieldIMPP);
	        newField->SetMapping(KUidContactFieldVCardMapUnknown);
	    }

	    //internet
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeSipVoip))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapVOIP);
	    }

	    //share video
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeVideoShare))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapSWIS);
	    }

	    //sip
	    else if (subTypes.contains(QContactOnlineAccount::SubTypeSip))
	    {
	        newField->AddFieldTypeL(KUidContactFieldSIPID);
	        newField->SetMapping(KUidContactFieldVCardMapSIPID);
	        newField->AddFieldTypeL(KUidContactFieldVCardMapSIPID);
	    }

	    else
	    {
	        User::LeaveIfError(KErrNotSupported);
	    }

	    //contexts
	    setContextsL(onlineAccount, *newField);

	    newField->SetLabelL(*detailCount);
	    fieldList.append(newField);
	    CleanupStack::Pop(newField);
	    
        // Transform Service Provider Text
	    TPtrC ServiceProviderText(reinterpret_cast<const TUint16*>(onlineAccount.serviceProvider().utf16()));
	    if(ServiceProviderText.Length()) {
            CContactItemField* serviceProviderField = CContactItemField::NewLC(KStorageTypeText);
	        serviceProviderField->TextStorage()->SetTextL(ServiceProviderText);
	        serviceProviderField->AddFieldTypeL(KUidContactFieldServiceProvider);
	        serviceProviderField->SetLabelL(*detailCount);
	        fieldList.append(serviceProviderField);
	        CleanupStack::Pop(serviceProviderField);
	    }
	    CleanupStack::PopAndDestroy(detailCount);
	}

	if(fieldList.count() > 0) {
        m_detailCounter++;
	}
	    
	return fieldList;
}
/** Create Contact Item and add field to it.Update the field value and 
 *	verify the field is being updated
 *	aValue - field value
 *  @param aStorageType - Storage type of each field
 *	@param aContFieldUid - Uid of Contact field
 *	@param avCardMapUid - Uid of vCard 
 *	@return - void
*/		
void CTestUpdateFieldsStep::UpdateFieldsL(TPtrC aValue, TInt aStorageType,TUid aContFieldUid, TUid avCardMap)
	{
	TPtrC value, updateVal, getUpdateValue;
	TInt year, month, day;
	
	// get the value from ini file
	GetIntFromConfig(ConfigSection(), KIniYear, year);
    GetIntFromConfig(ConfigSection(), KIniMonth, month);
    GetIntFromConfig(ConfigSection(), KIniDay, day);
    
	//Create contact Item and add field to it.
	CContactItem* item = CContactCard::NewLC();
    CContactItemField* field = CContactItemField::NewL(aStorageType, aContFieldUid);
    CleanupStack::PushL(field);
    field->SetMapping(avCardMap);
    if(aStorageType==KStorageTypeDateTime)
    	{
		TDateTime date(year,(TMonth)month,day,0,0,0,0);
   		field->DateTimeStorage()->SetTime(date);
    	}
    else
    	{
    	field->TextStorage()->SetTextL(aValue);	
    	}	
   	item->AddFieldL(*field);

   	// Get the value from ini file for update
   	GetStringFromConfig(ConfigSection(), KIniUpdatedvalue, updateVal);
	GetIntFromConfig(ConfigSection(), KIniUpdateYear, year);
    GetIntFromConfig(ConfigSection(), KIniUpdateMonth, month);
    GetIntFromConfig(ConfigSection(), KIniUpdateDay, day);
    
   	
	CContactItemFieldSet& ContactFieldSet = item->CardFields();
	TInt pos = ContactFieldSet.Find(aContFieldUid, avCardMap);
	
	if(aStorageType==KStorageTypeDateTime)
    	{
    	// update the field value
		TDateTime date(year,(TMonth)month,day,0,0,0,0);
   		field->DateTimeStorage()->SetTime(date);
   		ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos);
   		
   		// verify the updated field value
   		TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap);
   		TDateTime result=ContactFieldSet[upadtePos].DateTimeStorage()->Time().DateTime();
   		if((result.Year() == year) && (result.Month() == (TMonth)month) && (result.Day() == day)) 
				{
				SetTestStepResult(EPass);	
				}
			else
				{
				SetTestStepResult(EFail);	
				}
    	}
    else
    	{
    	// Update the field value
		ContactFieldSet[pos].TextStorage()->SetTextL(updateVal);
		ContactFieldSet.UpdateFieldL(ContactFieldSet[pos],pos);
		
		// verify the field is being updated 
		TInt upadtePos = ContactFieldSet.Find(aContFieldUid, avCardMap);
		getUpdateValue.Set(ContactFieldSet[upadtePos].TextStorage()->Text());
	
		//compair the results
		if(getUpdateValue.Compare(updateVal)==0 )
			{
			SetTestStepResult(EPass);
			}
		else
			{
			SetTestStepResult(EFail);
			}
    	}

	// Cleanup
	CleanupStack::Pop(field);
	CleanupStack::PopAndDestroy(item);

	}
Esempio n. 26
0
static void PhonebookWriteReqL(PktBuf &in, PktBuf &out)
{
	TUint16 memtype, ns, type, subtype;
	TUint32 location;
	CContactItem *item;
	CContactItemFieldSet *fieldset;
	CContactItemField *field;
	TBuf<64> name;
	TPtrC family_name, given_name;
	int i, s;

	g->InitPhoneBookL();

	in >> memtype;
	in >> location;

	if (memtype != GN_MT_ME) {
		out << (TUint16)GNAPPLET_MSG_PHONEBOOK_WRITE_RESP;
		out << (TUint16)GN_ERR_INVALIDMEMORYTYPE;
		return;
	}

	fieldset = CContactItemFieldSet::NewLC();
	in >> ns;
	for (i = 0; i < ns; i++) {
		in >> type >> subtype >> name;
		switch (type) {
		case GN_PHONEBOOK_ENTRY_Name:
			for (s = 0; s < name.Length() && name[s] != ' '; s++) ;
			if (s >= 1 && s < name.Length()) {
				family_name.Set(name.Ptr(), s);
				given_name.Set(name.Ptr() + s + 1, name.Length() - s - 1);
			} else {
				family_name.Set(name);
			}
			if (family_name.Length() > 0) {
				field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldFamilyName);
				//field->SetLabelL(_L("alma"));
				field->SetMapping(KUidContactFieldVCardMapUnusedN);
				field->TextStorage()->SetTextL(family_name);
				fieldset->AddL(*field);
			}
			if (given_name.Length() > 0) {
				field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldGivenName);
				//field->SetLabelL(_L("alma"));
				field->SetMapping(KUidContactFieldVCardMapUnusedN);
				field->TextStorage()->SetTextL(given_name);
				fieldset->AddL(*field);
			}
			break;
		case GN_PHONEBOOK_ENTRY_Email:
			field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldEMail);
			field->SetMapping(KUidContactFieldVCardMapEMAILINTERNET);
			field->TextStorage()->SetTextL(name);
			fieldset->AddL(*field);
			break;
		case GN_PHONEBOOK_ENTRY_Note:
			field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldNote);
			field->SetMapping(KUidContactFieldVCardMapNOTE);
			field->TextStorage()->SetTextL(name);
			fieldset->AddL(*field);
			break;
		case GN_PHONEBOOK_ENTRY_Number:
			if (subtype == GN_PHONEBOOK_NUMBER_Fax) {
				field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldFax);
				field->SetMapping(KUidContactFieldVCardMapTEL);
				field->AddFieldTypeL(KUidContactFieldVCardMapFAX);
			} else {
				field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldPhoneNumber);
				field->SetMapping(KUidContactFieldVCardMapTEL);
				switch (subtype) {
				case GN_PHONEBOOK_NUMBER_Home:
					field->AddFieldTypeL(KUidContactFieldVCardMapHOME);
					break;
				case GN_PHONEBOOK_NUMBER_Mobile:
					field->AddFieldTypeL(KUidContactFieldVCardMapCELL);
					break;
				case GN_PHONEBOOK_NUMBER_Work:
					field->AddFieldTypeL(KUidContactFieldVCardMapWORK);
					break;
				}
			}
			field->TextStorage()->SetTextL(name);
			fieldset->AddL(*field);
			break;
		case GN_PHONEBOOK_ENTRY_Ringtone:
			//field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldRingTone);
			//field->TextStorage()->SetTextL(name);
			//fieldset->AddL(*field);
			break;
		case GN_PHONEBOOK_ENTRY_Group:
			//field = CContactItemField::NewL(KStorageTypeText,
			//field->TextStorage()->SetTextL(name);
			//fieldset->AddL(*field);
			break;
		case GN_PHONEBOOK_ENTRY_URL:
			field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldUrl);
			field->SetMapping(KUidContactFieldVCardMapURL);
			field->TextStorage()->SetTextL(name);
			fieldset->AddL(*field);
			break;
		default:
			break;
		}
	}
	in.FinishL();

	TRAPD(error, item = g->cdb->OpenContactL(location));
	if (error == KErrNone) {
		item->UpdateFieldSet(fieldset);
		CleanupStack::Pop(fieldset);
		CleanupStack::PushL(item);
		g->cdb->CommitContactL(*item);
	} else {
		item = CContactCard::NewL();
		item->UpdateFieldSet(fieldset);
		CleanupStack::Pop(fieldset);
		CleanupStack::PushL(item);
		location = g->cdb->AddNewContactL(*item);
	}
	CleanupStack::Pop(item);

	out << (TUint16)GNAPPLET_MSG_PHONEBOOK_WRITE_RESP;
	out << (TUint16)GN_ERR_NONE;
	out << memtype;
	out << location;
	cons->Printf(_L("write: %d\n"), location);
}