Exemplo n.º 1
0
/**
Test: opens contact item, and adds a custom uid to each field, 
then checks if uid was stored correctly
*/
void CCustomLabelUid::TestCustomUidsL( const TContactItemId aCid )
	{
	//open contact	
	CContactItem *contactItem = NULL;
	contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll);
	CleanupStack::PushL(contactItem);
	CContactItemFieldSet *ContactFields = &(contactItem->CardFields());
	
	//add an extra (custom) uid to each fieldtype of this contact
	AddUIDsL(*ContactFields,TestConstants::KInitialUID);

	//populate contact fields
	SetContactFieldsL(*contactItem);
	//update contact
	iContactsDatabase->CommitContactL(*contactItem);
	
	CleanupStack::PopAndDestroy(contactItem);
	CleanupStack::Pop();//lock
	contactItem = NULL;
	
	//read contact item
	contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll);
	ContactFields = &(contactItem->CardFields());
	//check that contact field uids updated correctly
	SINGLECOMPARE( CheckUIDsL(*ContactFields,TestConstants::KInitialUID), 0 ,0 );
	//check that contact fields updated correctly
	SINGLECOMPARE( CheckContactFieldsL(*contactItem), 0, 0 );
	
	CleanupStack::PopAndDestroy(contactItem);
	}
/**
Utility method used to write text and binary blob fields into write streams. The write
streams will be used to persist the blob informations in contact database.
Provides a mechanism to get information from a contact item and store them in the
right blob fields within contact database. Template can be NULL. 

@param		aTextHeader reference to a write stream in which text header will be written
@param		aTextValues reference to a write stream in which text values will be written.
			From the caller point of view this reference should be a reference to a RSqlParamWriteStream instance
@param		aBinaryHeader reference to a write stream in which binary header will be written
@param		aBinaryValues reference to a write stream in which binary values will be written.
@param		aItem Contact item to be filled with information from text blob field.
@param      aSysTemplate System template item.
*/		
void TCntPersistenceUtility::WriteBlobL(CEmbeddedStore& aTextEmbeddedStore, RWriteStream& aTextValues, CEmbeddedStore& aBinaryEmbeddedStore, CEmbeddedStore& aBinaryEmbeddedBlobStore, const CContactItem& aItem, const CContactTemplate* aSysTemplate)
	{
	CContactItemFieldSet& fieldSet = aItem.CardFields();
	CContactItemFieldSet* textFieldSet = CContactItemFieldSet::NewLC();
	CContactItemFieldSet* binaryFieldSet = CContactItemFieldSet::NewLC();
	
	for(TInt i = 0; i < fieldSet.Count(); ++i)
		{
		CContactItemField* item	= CContactItemField::NewL((aItem.CardFields())[i]);
		CleanupStack::PushL(item);
		if(item->StorageType() == KStorageTypeText)
			{
			textFieldSet->AddL(*item);	
			}
		else
			{
			binaryFieldSet->AddL(*item);	
			}	
		CleanupStack::Pop(item);	
		}
	
	TStreamId rootId = textFieldSet->StoreL(aTextEmbeddedStore, aSysTemplate, aTextValues, aBinaryEmbeddedBlobStore, NULL);// *textEmbeddedBlobStore); 
	aTextEmbeddedStore.SetRootL(rootId);
	aTextEmbeddedStore.CommitL();

	rootId = binaryFieldSet->StoreL(aBinaryEmbeddedStore, aSysTemplate, aTextValues, aBinaryEmbeddedBlobStore, NULL); 
	aBinaryEmbeddedStore.SetRootL(rootId);
	aBinaryEmbeddedStore.CommitL();
	aBinaryEmbeddedBlobStore.CommitL();
		
	CleanupStack::PopAndDestroy(2, textFieldSet);  //binaryFieldSet, textFieldSet
	}
/**
Utility method used to read text blob fields from contacts database. Provides a mechanism to
fill a contact item with informations stored in text blobs within contact database.
A reference to the contact item to be fill has to be provided. A template has to be provided
if the contact item is based on a template. Template can be NULL. Also a view definition can
be provided to filter which fields are read from blob fields.

@param 		aTextHeader reference to a read stream from which header values will be read
@param 		aTextValues reference to a descriptor from which text values will be read
@param		aItem Contact item to be filled with information from text blob field.
@param		aView View definition specifying what item fields should be read from text blob field
@param		aTemplate Contact item representing a template based on which aItem should be read. Can be NULL
@leave		KErrNotFound if the specified contact item does not exist any more in contact database
*/	
void TCntPersistenceUtility::ReadTextBlobL(CEmbeddedStore& aTextHeaderStore, TPtrC& aTextValues, CContactItem& aItem, const CContactItemViewDef& aView, const CContactItem* aTemplate)
	{
	HBufC* textFieldsBuf = aTextValues.AllocLC();
	
	if (aTemplate) 
		{
		// If a system template is provided, we create a new CContactItemFieldSet object
		// and restore it based on provided template (CContactItemField objects composing
		// template). CContactItem object will be set with the newly created CContactItemFieldSet.
		CContactItemFieldSet* original = CContactItemFieldSet::NewLC();
		RestoreTextL(*original, aTextHeaderStore, aTextHeaderStore.Root(), textFieldsBuf, aView, aTemplate);
		
		for(TInt loop = 0;loop < original->Count();loop++)
			{
			CContactItemField* additionalField = CContactItemField::NewLC((*original)[loop]);
			aItem.CardFields().AddL(*additionalField);
			CleanupStack::Pop(additionalField);
			}
		CleanupStack::PopAndDestroy(original);
		}
	else
		{
		// If there is no template provided, we will fill the CContactItemField set provided
		// in the curent CContactItem object
		RestoreTextL(aItem.CardFields(), aTextHeaderStore, aTextHeaderStore.Root(), textFieldsBuf, aView, NULL);
		}
	
	CleanupStack::PopAndDestroy(textFieldsBuf); 
	}
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;
}
Exemplo n.º 5
0
EXPORT_C void CCntItemModifier::SetTextFieldL(TFieldType aFieldType, const TDesC& aText, CContactItem& aContactItem)
{
    CContactItemFieldSet& fields = aContactItem.CardFields();
    TInt fieldIndex = aContactItem.CardFields().Find(aFieldType);

    if (fieldIndex > KErrNotFound)
    {
        CContactItemField& field = fields[ fieldIndex ];
        ASSERT(field.StorageType() == KStorageTypeText);

        STATIC_CAST(CContactTextField*, field.Storage())->SetText(aText.AllocL());
    }
Exemplo n.º 6
0
/**
this function encompasses two tests
Test1(!aNewFields) opens contact item, and adds a custom uid to each field, changes lable to custom label
then checks if uid and label were stored correctly
Test2(aNewFields) opens contact item and adds ten new fields, and adds a custom uid to 
each field(new and old), changes lable to custom label then checks if uid and 
label were stored correctly. also checks both uids of new fields
*/
void CCustomLabelUid::TestCustomUidLabelsL( const TContactItemId aCid, const TBool aNewFields )
	{
	CContactItem *contactItem = NULL;
	//open contact
	contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll);
	CleanupStack::PushL(contactItem);
	CContactItemFieldSet *ContactFields = &(contactItem->CardFields());
		
	if(aNewFields)
		{
		TInt length = 10;//add 10 new custom fields
		for(TInt i = 0, uids = TestConstants::KAltUID; i < length; i++, uids++)
			{
			AddNewFieldL( *ContactFields, TestConstants::KShortString, TFieldType::Uid(uids) );
			}
		}
	//set custom labels for contact fields	
	SetContactLabelsL(*contactItem);
	//set custom uids for contact fields
	AddUIDsL(*ContactFields,TestConstants::KInitialUID);
	//populate contact fields and update
	SetContactFieldsL(*contactItem);
	iContactsDatabase->CommitContactL(*contactItem);
	
	CleanupStack::PopAndDestroy(contactItem);
	CleanupStack::Pop();//lock
	
	//read contact
	contactItem = NULL;
	contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll);
	ContactFields = &(contactItem->CardFields());
	
	//check uids were update correctly
	SINGLECOMPARE( CheckUIDsL(*ContactFields,TestConstants::KInitialUID),0,0 );
	//check labels were update correctly
	SINGLECOMPARE( CheckContactLabelsL(*contactItem),0,0 );
	//check fields were populated correctly
	SINGLECOMPARE( CheckContactFieldsL(*contactItem),0,0 );
	
	if(aNewFields)
		{
		//check that new fields contain the correct uids(2), initial and updated custom values
		TInt length = ContactFields->Count();
		TInt i = ContactFields->Find( TFieldType::Uid(TestConstants::KAltUID) );
		for(TInt uids = TestConstants::KAltUID; i < length; i++, uids++)
			{
			SINGLECOMPARE( CheckNewFieldL( *ContactFields, i, TFieldType::Uid(uids) ), i, 0);
			}
		}		
	CleanupStack::PopAndDestroy(contactItem);
	}
/**
 * Create a new template and add it to the database
 * @param aDb Contact database
 * @param aTemplateName Name for the template
 * @param aFieldSet Array of fields which should are added to the template
 * @return TContactItemId Id of the newly created template
 */
TContactItemId CreatePhonebookTemplateL(CContactDatabase& aDb, const TDesC& aTemplateName, RArray<TFieldEntry>& aFieldSet)
	{
	CContactItem* temp = aDb.CreateContactCardTemplateLC(aTemplateName);
	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);

	// Add each of the required fields to the template
	for (TInt j=0; j<aFieldSet.Count(); ++j)
		{
		TFieldEntry fieldEntry=aFieldSet[j];

		CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,fieldEntry.iField);
		if (fieldEntry.iFieldType!=KNullUid)
			field->AddFieldTypeL(fieldEntry.iFieldType);
		temp->AddFieldL(*field);
		CleanupStack::Pop(field);
		}

	aDb.CommitContactL(*temp);
	CleanupStack::PopAndDestroy(2); // temp, close template
	
	return templateId;
	}
Exemplo n.º 8
0
/**
Parse through contact fields and find the image field. Copy the image
pointed by the path to an internal folder and update the contact fields.
This function is used internally by contacts model when saving/updating
a contact that has an image. It is a synchronous function

@param aItem Contact containing fields to be processed. Once the image
is resized and copied into the new location, this parameter will contain
the image field with the new path. If failures occur while resizing, the
image field content is not updated
*/
void CImageRescaler::ProcessImageFieldL(CContactItem& aItem)
    {
    // If there is no images dir do not do anything
    if (!iImagesDirPath.Length())
        {
        return;
        }
    CContactItemFieldSet& fieldSet = aItem.CardFields();
    // Check if there is any image field before
    TInt index = fieldSet.Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);
    
    // Update the image path field if found and the private image does not exists
    if (index != KErrNotFound )
        {
        // Get a copy of fields set
        // Image path field from list of contact fields
        CContactItemField& imageField = fieldSet[index];
        TPtrC oldImagePath = imageField.TextStorage()->Text();
        
        // Do not resize if old image is stored in private folder
        if ( oldImagePath.Length() && !ExistsInImagesDirectory(oldImagePath) )
            {
            // Resize image if needed
            TPath newImagePath;
            newImagePath = ResizeAndCopyImage(oldImagePath, aItem);
            TCntImageRescaleUtility::StoreImageFieldL( aItem, newImagePath );
            }
        }
    }
/**
 * Deleting the 1000 contact item
 * with all new fields
 * @return - void
 */
void CTestContactPerformanceStep::DeletePerformanceL()
{
    // delete multiple contact item field
    CContactItem *readItem = NULL;

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

    for(TInt readContact=0; readContact<iNoOfCI; readContact++)
    {
        readItem = dBase->ReadContactLC(idArray[readContact]);
        CContactItemFieldSet& ContactFieldSet = readItem->CardFields();
        for(TInt del=0; del<7; del++)
        {
            TInt pos = ContactFieldSet.Find(iFieldUid[del], iVcardUid[del]);
            if(pos != KErrNotFound)
            {
                ContactFieldSet.Remove(pos);
                SetTestStepResult(EPass);
            }
            else
            {
                ERR_PRINTF1(_L("field not deleted"));
                SetTestStepResult(EFail);
            }
        }
        CleanupStack::PopAndDestroy(readItem);
    }
    INFO_PRINTF1(_L("Fields deleted successfully"));
}
Exemplo n.º 10
0
/** Set the contents of a text field */
LOCAL_C void SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName)
{
    CContactItemFieldSet& fieldSet=aItem.CardFields();
    const TInt pos=fieldSet.Find(aType);
    if (pos!=KErrNotFound)
        fieldSet[pos].TextStorage()->SetTextL(aName);
}
Exemplo n.º 11
0
void AssignSpeedDialL( TInt aContact, TInt aSpeedDialID, CContactDatabase& database )
	{
	CContactItem* item = NULL;
	item = database.OpenContactL( aContact );
	
	CleanupStack::PushL( item );

	if ( ContactIsASpeedDial( *item ) )
		{
		g_test.Printf( _L("Contact is a speed dial !!! \n") );
		}
	else
		{
		g_test.Printf( _L("Contact is NOT A SPEED DIAL \n") );
		}

	CContactItemFieldSet &fieldSet = item->CardFields();
    for(TInt index = fieldSet.Count() - 1; index > 0; --index)
        {
        if(fieldSet[index].StorageType() == KStorageTypeText)
            {
            //set the last text field from the fieldset as speeddial field.
        	database.SetFieldAsSpeedDialL(*item, index, aSpeedDialID );
            break;
            }
        }
        
	g_test.Next( _L("Contact changed to speed dial") );
	g_test(ContactIsASpeedDial( *item ));

	CleanupStack::PopAndDestroy( item );
	}
void CntThumbnailCreator::initializeThumbnailFieldL()
{
    // Assume the golden template is not changed run-time and fetch it only
    // when initializeThumbnailFieldL is called for the first time during the
    // life-time of the CntThumbnailCreator object (requires the instance to
    // live longer than one thumbnail create operation to be effective,
    // otherwise we would end up opening contact database and reading the
    // system template every time a thumbnail is stored for a contact).
    if(!m_thumbnailFieldFromTemplate) {
        CContactDatabase *contactDatabase = CContactDatabase::OpenL();
        CleanupStack::PushL(contactDatabase);
        CContactItem *goldenTemplate = contactDatabase->ReadContactLC(KGoldenTemplateId);
        const CContactItemFieldSet& cardFields = goldenTemplate->CardFields();

        // Check if thumbnail field type is KUidContactFieldPictureValue
        TInt pictureFieldIndex = cardFields.Find(KUidContactFieldPicture, KUidContactFieldVCardMapPHOTO);

        // Check if thumbnail field type is KUidContactFieldVCardMapJPEG
        if(pictureFieldIndex == KErrNotFound) {
            pictureFieldIndex = cardFields.Find(KUidContactFieldVCardMapJPEG, KUidContactFieldVCardMapPHOTO);
        }

        if(pictureFieldIndex == KErrNotFound) {
            // Either KUidContactFieldPictureValue or KUidContactFieldVCardMapJPEG
            // thumbnail field types should be in the template
            User::Leave(KErrNotFound);
        }

        m_thumbnailFieldFromTemplate = CContactItemField::NewL(cardFields[pictureFieldIndex]);
        CleanupStack::PopAndDestroy(goldenTemplate);
        CleanupStack::PopAndDestroy(contactDatabase);
    }
}
Exemplo n.º 13
0
/**
Merging pure (minimal) contact with the template should be out of scope of the
Persistence Layer.  The only reason to have this functions in the test interface
is that CContactItem::RestoreTemplateFieldsL() is not exported.
*/
void CLplTester::MergeContactWithTemplateL(CContactItem& aContact, const CContactItem& aTempl, const CContactItemViewDef& aView) const
	{	
	if (aContact.TemplateRefId()!=KNullContactId &&  aContact.Type() != KUidContactCardTemplate)
		{
		aContact.RestoreTemplateFieldsL(iProps.SystemTemplateL().CardFields(), aTempl.CardFields(), aView);
		}
	}
/**
 * Set the phone number field of the contact with id aId to contain the number aNumber
 * @param aDb Contact database
 * @param aId Contact item id
 * @param aNumber A telephone number
 */
void SetPhoneNumberField(CContactDatabase& aDb,TContactItemId aId,const TDesC& aNumber)
	{
	syncChecker->ResetMethodCallCountsL();
	CContactItem* item = aDb.OpenContactLX(aId);
	CleanupStack::PushL(item);
	if (item->Type() == KUidContactICCEntry)
		{
		test(syncChecker->ValidateMethodCallCountL() == 2);
		}
	else
		{
		test(syncChecker->ValidateMethodCallCountL() == 0);
		}
	CContactItemFieldSet& fieldset = item->CardFields();
	TInt pos = fieldset.Find(KUidContactFieldPhoneNumber);
	test(pos!=KErrNotFound);
	
	CContactItemField& field = fieldset[pos];
	CContactTextField* textfield = field.TextStorage();
	textfield->SetTextL(aNumber);

	syncChecker->ResetMethodCallCountsL();
	aDb.CommitContactL(*item);
	if (item->Type() == KUidContactICCEntry)
		{
		test(syncChecker->ValidateMethodCallCountL() == 2);
		}
	else
		{
		test(syncChecker->ValidateMethodCallCountL() == 0);
		}
	CleanupStack::PopAndDestroy(2); // item, lock record
	}
Exemplo n.º 15
0
void TestPhoneMatchingL(CContactDatabase& aDb)
	{
	test.Next(_L("Test phone match"));

	CContactIdArray* array = aDb.MatchPhoneNumberL(KTelephoneNum,KMaxPhoneMatchLength);	
	test(array->Count() == 4);
	delete array;

	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
	syncChecker->SetValidateResponseL(MContactSynchroniser::EEdit, KErrNone);
	syncChecker->SetValidateWriteResponseL(KErrNone);
	aDb.SetDbViewContactType(KUidContactICCEntry);
	TContactItemId id = (*aDb.SortedItemsL())[0];
	CContactItem* item = aDb.OpenContactLX(id);
	CleanupStack::PushL(item);
	CContactItemFieldSet& fieldset = item->CardFields();
	const TInt pos = fieldset.Find(KUidContactFieldPhoneNumber);	
	CContactItemField& field = fieldset[pos];
	CContactTextField* textfield = field.TextStorage();
	textfield->SetTextL(KTelephoneNumModified);
	aDb.CommitContactL(*item);
	CleanupStack::PopAndDestroy(2); //item, lock record

	CContactIdArray* array2 = aDb.MatchPhoneNumberL(KTelephoneNumModified,KMaxPhoneMatchLength);	
	test(array2->Count() == 1);
	delete array2;
	}
Exemplo n.º 16
0
/** 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);
	}
TBool CPackagerCntComparator::Compare(const CContactItem& anItem1, const CContactItem& anItem2) const
/** Compares two CContactItem items. 

@param anItem1 The first CContactItem to be compared.
@param anItem2 The second CContactItem to be compared.
@return ETrue if the two items are equal, EFalse otherwise. */
	{
	return (DoCompareCContactItemType(anItem1, anItem2) 							&
		DoCompareCContactItemFieldSet(anItem1.CardFields(), anItem2.CardFields())	&
		DoCompareCContactItemAttribute(anItem1, anItem2)							&
		DoCompareTContactItemId(anItem1.Id(), anItem2.Id())							&
		DoCompareTContactItemId(anItem1.TemplateRefId(), anItem2.TemplateRefId())	&
		DoCompareTTime(anItem1.LastModified(), anItem2.LastModified())				&
		DoCompareTTime(anItem1.iCreationDate, anItem2.iCreationDate)				&
		DoCompareTInt(anItem1.AccessCount(), anItem2.AccessCount())					&
		DoCompareTPtrC(const_cast<CContactItem&>(anItem1).Guid(), const_cast<CContactItem&>(anItem2).Guid()));

	}
Exemplo n.º 18
0
/**
	Try to match the phone number given with existing numbers in the database.
*/
void CCrudOperations::MatchContactsByPhoneNumL()
{
    _LIT(KPass, "Pass");
    _LIT(KFail, "Fail");
    _LIT(KMatchOutputFormat1, "Number of phone numbers matched: %d -- %s\n");
    _LIT(KMatchOutputFormat2, "Phone number lookup took: %d s %03d\n");
    _LIT(KMatchOutputFormat3, "The contact's first name: %S\n");

    _LIT(KPhoneNumberToFind, "241867306233253164487125"); // this number belongs to the 1000th
    // contact item in the database, which
    // has a photo.

    const TInt KMatchLengthFromRight(7); // match on the number without the dialling code prefix
    // to avoid differences like +447876... and 07876...
    _LIT(KPhoneNumberTestTitle, "\nBeginning Phone Number Match testing...\n");


    iTest->Printf(KPhoneNumberTestTitle);
    TCntPerfTimer timer;
    timer.StartTimer();

    // Search the database...
    CContactIdArray* idArray = iDb->MatchPhoneNumberL(KPhoneNumberToFind, KMatchLengthFromRight);
    CleanupStack::PushL(idArray);
    TInt numMatches = idArray->Count();
    iTest->Printf(KMatchOutputFormat1, numMatches, numMatches ? KPass().Ptr() : KFail().Ptr());

    if (numMatches)
    {
        //fetch first contact item in array
        CContactItem* item = iDb->ReadContactLC((*idArray)[0]);
        timer.StopTimer();
        CContactItemFieldSet& fieldSet = item->CardFields();
        TInt firstNameFieldId = fieldSet.Find(KUidContactFieldGivenName);
        if (firstNameFieldId == KErrNotFound)
        {
            User::Leave(KErrNotFound);
        }
        CContactItemField& firstNameField = fieldSet[firstNameFieldId];
        CContactTextField* firstNameText = firstNameField.TextStorage();
        TPtrC firstName(firstNameText->Text());
        iTest->Printf(KMatchOutputFormat3, &firstName);

        CleanupStack::PopAndDestroy(item);
    }
    else
    {
        timer.StopTimer();
    }

    CleanupStack::PopAndDestroy(idArray);

    TInt result = timer.Result();
    TBuf<64> formattable;
    formattable.Format(KMatchOutputFormat2, result / 1000000, (result / 1000) % 1000);
    iTest->Printf(formattable);
}
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;
}
CContentType* CPackagerCntFactory::doCreateDefaultCContentTypeL() const
/** Implementation method for constructing a new default CContentType object. 

@return a Pointer to the CContentType object. */
	{
	CContactItem* theItem = doCreateDefaultCContactItemL();
	CleanupStack::PushL(theItem);
	CContentType* theContent = CContentType::NewL(theItem->CardFields()[0].ContentType());
	CleanupStack::PopAndDestroy(theItem);
	return theContent;
	}	
Exemplo n.º 21
0
/** 
 * Verify that the template was correctly added 
 * @param aTemplate CContactCardTemplate template item
 */
void CheckTemplateL(CContactItem& aTemplate)
	{
	test(aTemplate.Type() == KUidContactCardTemplate);
	test(aTemplate.TemplateRefId() == KNullContactId);
	test(static_cast<CContactCardTemplate&>(aTemplate).GetTemplateLabelL() == KTemplateName);
	CContactItemFieldSet& fieldset = aTemplate.CardFields();
	TInt pos = fieldset.Find(KUidContactFieldTemplateLabel);
	test(pos!=KErrNotFound);
	TInt count = fieldset.Count();
	test(count==5); //label, name, number, ICC slot, phonebook
	}
Exemplo n.º 22
0
LOCAL_C void SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName)
//
// Set the contents of a text field, creating the field if required
//
	{
	CContactItemFieldSet& fieldSet=aItem.CardFields();
	const TInt pos=fieldSet.Find(aType);
	if (pos!=KErrNotFound)
		fieldSet[pos].TextStorage()->SetTextL(aName);
	else
		Panic(KErrGeneral);
	}
Exemplo n.º 23
0
// Check that the speed dial at position aSpeedDialPosition matches the aExpectedId
// and the contents of the field with aFieldId is the same in the speed dial.
//
LOCAL_C void CheckSpeedDialL(TInt aSpeedDialPosition, CContactItem& aContact, TInt aFieldId)
{
    HBufC* buf=HBufC::NewLC(100);
    TPtr fieldContents=buf->Des();

    TContactItemId id = CntTest->Db()->GetSpeedDialFieldL(aSpeedDialPosition, fieldContents);
    TPtrC actualContents =(aContact.CardFields()[aFieldId].TextStorage()->Text());
    test(id==aContact.Id());
    test(actualContents==fieldContents);

    CleanupStack::PopAndDestroy(); //buf
}
Exemplo n.º 24
0
LOCAL_C void LongNumSpeedDialTestsL()
    {
	_LIT(KLongNumSpeedDialTest, "Long Phone Number Speed Dial Test");
	g_test.Start(KLongNumSpeedDialTest);

	// create default, empty database
	CContactDatabase* db = CContactDatabase::ReplaceL(KLongNumSpeedDialDbName);
	CleanupStack::PushL(db);
	
	// create a contact and add it to the db
	CContactItem* contact = CContactCard::NewLC();
	CContactItemField* fname = CContactItemField::NewLC(KStorageTypeText, 
			KUidContactFieldGivenName);
	_LIT(KFname, "James");
	fname->TextStorage()->SetTextL(KFname() );
	contact->AddFieldL(*fname);
	CleanupStack::Pop(fname);
	CContactItemField* phone = CContactItemField::NewLC(KStorageTypeText,
			KUidContactFieldPhoneNumber);
	_LIT(KPhoneNum,	"01234567890123456789012345678901234567890123456789012345678901234567890123456789"); // 80 chars
	phone->TextStorage()->SetTextL(KPhoneNum() );
	contact->AddFieldL(*phone);
	CleanupStack::Pop(phone);
	const TContactItemId KContactId = db->AddNewContactL(*contact);
	CleanupStack::PopAndDestroy(contact);
	contact = NULL;

	// retrieve contact and assign its number to speed dial #1
	contact = db->OpenContactL(KContactId);
	CleanupStack::PushL(contact);
	const TInt KSpeedDial1(1);
	const TInt KPhoneNumIndex = contact->CardFields().Find(KUidContactFieldPhoneNumber);
	db->SetFieldAsSpeedDialL(*contact, KPhoneNumIndex, KSpeedDial1);
	TBuf<100> speedDialNumberText;
	TContactItemId speedDialId = db->GetSpeedDialFieldL(KSpeedDial1, speedDialNumberText);
	_LIT(KOutputFormat, "retrieved speed dial id: %d;\nretrieved speed dial phone number: ...\n%S\n");
	g_test.Printf(KOutputFormat, speedDialId, &speedDialNumberText);
	db->CloseContactL(KContactId);
	
	// cleanup
	CleanupStack::PopAndDestroy(2, db);	// and contact
	CContactDatabase::DeleteDatabaseL(KLongNumSpeedDialDbName);

	// Since PDEF121954, long phone numbers set as speed dial are truncated to 
	// the length of KSpeedDialPhoneLength. So, we need to get the truncated 
	// version of the phone number for comparison with the speed dial value.
	TPtrC phoneNum(KPhoneNum().Mid(0, KSpeedDialPhoneLength));
	g_test(speedDialId == KContactId && speedDialNumberText.CompareC(phoneNum) == 0);
	g_test.End();
	g_test.Close();
    }
Exemplo n.º 25
0
//
// Set the contents of a text field, creating the field if required
//
LOCAL_D void SetNameL(CContactItem& aItem,const TUid& aType,const TDesC& aName, TBool aAddField)
	{
	CContactItemFieldSet& fieldSet=aItem.CardFields();
	const TInt pos=fieldSet.Find(aType);
	if (!aAddField && pos!=KErrNotFound)
		fieldSet[pos].TextStorage()->SetTextL(aName);
	else
		{
		CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,aType);
   		field->SetMapping(KUidContactFieldVCardMapUnusedN);
		field->TextStorage()->SetTextL(aName);
		aItem.AddFieldL(*field);
		CleanupStack::Pop(); // field
		}
	}
Exemplo n.º 26
0
///////////////////////////////////////////////////////////////////////////////
// Function Implementation
///////////////////////////////////////////////////////////////////////////////
TBool ContactIsASpeedDial(const CContactItem& aItem)
	{
	TBool retval = EFalse;
	CContactItemFieldSet& fields = aItem.CardFields();
	const TInt max = fields.Count();
	TInt counter = 0;

	for (counter = 0; counter < max; counter++)
		{
		retval = fields[counter].IsSpeedDial();
		if (retval) break;
		}

	return retval;
	}
void CTestImpExvCardSuiteStepBase::ImportBDAYCardL(RReadStream& aReadStream)
	{
	INFO_PRINTF1(_L("Importing vCard....."));
	

	CVCardToContactsAppConverter* converter=new(ELeave)	CVCardToContactsAppConverter;
	CleanupStack::PushL(converter); // converter

	CParserVCard* vCard= CParserVCard::NewL();
	CleanupStack::PushL(vCard);
	TInt err = KErrNone;
	TRAP(err, vCard->InternalizeL(aReadStream));
	User::LeaveIfError(err);
	
	CContactItem* contactItem = NULL;
	
	// set to local time
	contactItem = converter->GetVCardAsContactItemLC(*vCard, CVCardToContactsAppConverter::EPreserveAllProperties, CContactVCardConverter::ELocalTime);
	
	CContactItemFieldSet& cardFields = contactItem->CardFields();
	
	INFO_PRINTF1(_L("Looking for Birthday field in Contact entry....."));
	TInt pos = cardFields.Find(KUidContactFieldBirthday);
	
	if (pos==KErrNotFound)
		{
		INFO_PRINTF1(_L("Birthday field not found in Contact entry"));
		iBDayFromImport = NULL;
		}
	else
		{
		INFO_PRINTF1(_L("Birthday field found in Contact entry"));
		CContactItemField& itemField = cardFields[pos];
	
		CContactDateField* dateTimeField = itemField.DateTimeStorage();
		CleanupStack::PushL(dateTimeField);
	
		iBDayFromImport = dateTimeField->Time();
		
		CleanupStack::Pop();
		}
	
	INFO_PRINTF1(_L("Imported to Contact Entry"));
		
	CleanupStack::PopAndDestroy(3); 
	}
Exemplo n.º 28
0
/**Utility function to remove any specified contact field from a specified contact item*/
TBool CAgentTest::RemoveFieldFromContactL(TContactItemId aContactId, TUid aContactField)
	{
	CContactItem* mainItem = NULL;
	CContactItemFieldSet* fields = NULL;
	mainItem = iDb->OpenContactL(aContactId);
	CleanupStack::PushL(mainItem);
	fields = &mainItem->CardFields();
	TInt pos = 0;
	pos = fields->Find(aContactField);
	if (pos != KErrNotFound)
		{
		fields->Remove(pos);	
		}
	iDb->CommitContactL(*mainItem);
	CleanupStack::PopAndDestroy();	
	return pos;	
	}
Exemplo n.º 29
0
EXPORT_C void CTestUtils::SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName, TBool aAddField)
//
// Set the contents of a text field, creating the field if required
//
	{
	CContactItemFieldSet& fieldSet=aItem.CardFields();
	const TInt pos=fieldSet.Find(aType);
	if (!aAddField && pos!=KErrNotFound)
		fieldSet[pos].TextStorage()->SetTextL(aName);
	else
		{
		CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,aType);
   		field->SetMapping(KUidContactFieldVCardMapUnusedN);
		field->TextStorage()->SetTextL(aName);
		aItem.AddFieldL(*field);
		CleanupStack::Pop(); // field
		}
	}
Exemplo n.º 30
0
EXPORT_C TBool CContactItemViewDef::Contains(const CContactItem& aItem)
/** Tests whether a contact item complies with the view definition.

This indicates whether or not the item will be included in the view. 

@param aItem The contact item to test.
@return ETrue if any of the item's fields are contained in the view definition 
(so that the item will be included in the view), EFalse if none of the item's 
fields are contained in the view definition (so that the item will not be 
included in the view). */
	{
	CContactItemFieldSet& fieldSet=aItem.CardFields();
	const TInt count=fieldSet.Count();
	for (TInt ii=0;ii<count;ii++)
		if (Find(iFieldTypes[ii])!=KErrNotFound)
			return ETrue;
	return EFalse;
	}