Beispiel #1
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;
	}
/**
Searches the contacts database to find any contact items with an exact match on the address supplied.

@param aCommAddr A descriptor containing the address to be found in the database.
@param aAddrType The type of addresses that is being sought.
@return An array of contact IDs which match the supplied address.
*/
CContactIdArray* CPplCommAddrTable::MatchNonPhoneAddrL(const TDesC& aCommAddr, TCommAddrType aAddrType)
	{

	// build statement
	RSqlStatement stmnt;
	CleanupClosePushL(stmnt);
	stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL() );

	const TInt KValueParamIndex(KFirstParam);					// first parameter in query...
	const TInt KTypeParamIndex(KValueParamIndex + 1);	// ...and the second.
	User::LeaveIfError(stmnt.BindText(KValueParamIndex, aCommAddr) );
	User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, aAddrType) );

	// fetch the list of any matching contact ids
	CContactIdArray* idArray = CContactIdArray::NewLC();
	TInt err(KErrNone);
	const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrContactId() ) );
	while ((err = stmnt.Next() ) == KSqlAtRow)
		{
		idArray->AddL(stmnt.ColumnInt(KContactIdIdx) );
		}

	// leave if we didn't complete going through the results properly
	if(err != KSqlAtEnd)
		{
		User::Leave(err);
		}

	CleanupStack::Pop(idArray);
	CleanupStack::PopAndDestroy(&stmnt);

	return idArray;
	}
TBool CPackagerCntComparator::DoCompareCContactIdArray(const CContactIdArray& anArray1, const CContactIdArray& anArray2) const
/** Compares two CContactIdArray items. 

@param anArray1 The first CContactIdArray to be compared.
@param anArray2 The second CContactIdArray to be compared.
@return ETrue if the two items are equal, EFalse otherwise. */
	{// Need to check for NULL  arrays first.
	if((!&anArray1) && (!&anArray2))
		{
		return ETrue;
		}

	if((!&anArray1) || (!&anArray2))
		{
		return EFalse;
		}
			
	// Check if arrays are same length to begin with.
	TInt maxCount = anArray1.Count();
	if(!DoCompareTInt(maxCount, anArray2.Count()))
		{
		return EFalse;
		}

	for(TInt i=0; i<maxCount; ++i)
		{
		if(!DoCompareTContactItemId(anArray1[i], anArray2[i]))
			{
			return EFalse;
			}
		}

	return ETrue;	
	}	
Beispiel #4
0
TLogContactItemId CCntMatchLog::MatchPhoneNumberL(const TDesC& aNumber, TInt aMatchLengthFromRight)
	/** Attempts to find a contact item ID for the contact items which contains
	the specified telephone number in a telephone, fax or SMS type field.
	If more than one contact item contains the telephone number this should be 
	treated the same as no contact found.
	
	@capability ReadUserData
	@param aNumber Phone number string
	@param aMatchLengthFromRight Number of digits from the right of the phone number to use
	@return The contact Id found that contains the phone number. KLogNullContactId if none or more than one is found. */
	{
	CContactIdArray* array = NULL;
	TLogContactItemId contactId=KLogNullContactId;
	
	array = iContactDb->MatchPhoneNumberL(aNumber, aMatchLengthFromRight);
				
	// Only set contactId if we have exactly one match
	if (array->Count() == 1)
		{
		// we have only one match so set the contact id
		contactId = static_cast<TLogContactItemId>((*array)[0]);
		}
	delete array;
	return contactId;
	}
//===============================================================================================
// SEARCHING entries
//===============================================================================================
void TestFindLC(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
	{
	test.Next(_L("Test FindLC"));
	// Successful find of icc entry
	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
	CleanupStack::PushL(fieldDef);
	fieldDef->AppendL(KUidContactFieldFamilyName);
	syncChecker->ResetMethodCallCountsL();
	CContactIdArray* array = aDb.FindLC(KIccName,fieldDef);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aIccId);
	CleanupStack::PopAndDestroy(array);
	array=NULL;

	test.Next(_L("Test searching when ICC locked"));
	// Unsuccessful find of icc entry because icc locked
	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
	syncChecker->ResetMethodCallCountsL();
	TRAPD(err,array = aDb.FindLC(KIccName,fieldDef));
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(err==KErrLocked);
	test(array==NULL);

	// successful find of non-icc entry, even though icc locked
	syncChecker->ResetMethodCallCountsL();
	array = aDb.FindLC(KNonIccName,fieldDef);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aNonIccId);
	CleanupStack::PopAndDestroy(2,fieldDef); // array, fieldDef
	}
/**
exports all contacts items in db to vcard file, if aDelete, cleans database afterwards
*/
void CPerformanceFunctionalityBase::ExportVcardL(const TBool aDelete, const TDesC &aVCard)
	{
	iIterate->Reset();
	CContactIdArray *ids = CContactIdArray::NewLC();
	TInt i = 0;
	for(; i < iContacts; ++i)
		{
		ids->AddL( iIterate->NextL() );
		}

	RFileWriteStream rfws;
	CleanupClosePushL(rfws);
	User::LeaveIfError( rfws.Replace( iParent->Fs(),aVCard , EFileWrite | EFileShareAny ) );

	iContactsDatabase->ExportSelectedContactsL(	TUid::Uid(KUidVCardConvDefaultImpl), *ids, rfws,
										CContactDatabase::EIncludeX | CContactDatabase::ETTFormat );

	CleanupStack::PopAndDestroy(&rfws);
	if( aDelete )
		{
		CLEAR( iContactsDatabase );
		iContactsDatabase = CContactDatabase::ReplaceL();
		}
	CleanupStack::PopAndDestroy(ids);
	}
Beispiel #7
0
LOCAL_C void TestFilteringL()
{
    _LIT(KProgressIndicator,".");
    test.Printf(KProgressIndicator);

    CCntFilter* filter = CCntFilter::NewL();
    CleanupStack::PushL(filter);

    filter->SetContactFilterTypeCard(ETrue);
    TTime time;
    time.UniversalTime();
    time-=TTimeIntervalMinutes(20); // changes in the last 20 mins
    filter->SetFilterDateTime(time);
    filter->SetIncludeNewContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==KTotalNumRecords);

// modified contact
    User::After(4000000);	// Let time pass to distinguish between mod  / new
    // this may still fail if the device is running too slow (e.g. under a heavy load)

    filter->Reset();
    time.UniversalTime();
    filter->SetFilterDateTime(time);
    filter->SetIncludeModifiedContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==0);

    CContactItem* contact = CntTest->Db()->OpenContactLX(5);
    CleanupStack::PushL(contact);
    contact->IncAccessCount();
    CntTest->Db()->CommitContactL(*contact);
    CleanupStack::PopAndDestroy(contact);
    CleanupStack::Pop(); // contact.Close()

    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==1);

// deleted contact
    filter->Reset();
    filter->SetFilterDateTime(time); // same time as for modified
    filter->SetIncludeDeletedContacts(ETrue);
    CntTest->Db()->FilterDatabaseL(*filter);
    test(filter->iIds->Count()==0);

    CntTest->Db()->DeleteContactL(5);
    CntTest->Db()->FilterDatabaseL(*filter);
    TInt deletedContactCount = filter->iIds->Count();
    test(deletedContactCount ==1);

#ifdef _DEBUG
    CContactIdArray* deletedCntArray = CntTest->Db()->DeletedContactsLC();
    test(deletedCntArray->Count()==deletedContactCount);
    CleanupStack::PopAndDestroy(deletedCntArray );
#endif

    CleanupStack::PopAndDestroy(filter);
}
void TestFindInTextDefLC(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
	{
	test.Next(_L("Test FindInTextDefLC"));
	// Successful find of icc entry
	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrNone);
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);

	TCallBack callBack(findWordSplitterL);
	CContactTextDef* textDef=CContactTextDef::NewLC();
	textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
	CDesCArray* desArray = new(ELeave) CDesCArrayFlat(5);
	desArray->AppendL(_L("icc"));
	syncChecker->ResetMethodCallCountsL();
	CContactIdArray* array = aDb.FindInTextDefLC(*desArray,textDef,callBack);
	//test(syncChecker->ValidateMethodCallCountL() == 3);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aIccId);
	CleanupStack::PopAndDestroy(array);
	array=NULL;

	test.Next(_L("Test searching when ICC locked"));
	// Unsuccessful find of icc entry because icc locked
	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
	syncChecker->ResetMethodCallCountsL();
	TRAPD(err,array = aDb.FindInTextDefLC(*desArray,textDef,callBack));
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(err==KErrLocked);
	test(array==NULL);
	desArray->Delete(0);
	delete desArray;

	// successful find of non-icc entry, even though icc locked
	CDesCArray* desArray2 = new(ELeave) CDesCArrayFlat(5);
	desArray2->AppendL(_L("non-icc"));
	syncChecker->ResetMethodCallCountsL();
	array = aDb.FindInTextDefLC(*desArray2,textDef,callBack);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aNonIccId);

	// both the icc and non-icc entry should match the search criteria, but only the
	// non-icc entry should be returned since icc is locked
	SetNameField(aDb,aIccId,KNonIccName);
	syncChecker->ResetMethodCallCountsL();
	TRAP(err,array = aDb.FindInTextDefLC(*desArray2,textDef,callBack));
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(err==KErrLocked);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aNonIccId);
	desArray2->Delete(0);
	delete desArray2;
	SetNameField(aDb,aIccId,KIccName);
	CleanupStack::PopAndDestroy(2,textDef); // array, textDef
	}
Beispiel #9
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);
}
Beispiel #10
0
/**
add agent field to contact b. set value of agent to contact a.
export contacts a & b. check access count for a & b(should be 0), 
check value of agent(should equal b) open contact b, delete all fields.
commit. import contacts a and b. check that agent field is not imported.
*/
void CAccessCountTests::AgentExportImportAccessTestL()
	{
	const TContactItemId KFirstContactId = iIterate->NextL();//contact a
	const TContactItemId KSecondContactId = iIterate->NextL();//contact b
	
	//open contact a and populate all fields
	OpenL(KFirstContactId, *iViewAll);
	SetContactFieldsL(*iContactItem);
	CommitL();
	
	//open contact b
	OpenL(KSecondContactId,*iViewAll);
	//populate all fields
	SetContactFieldsL(*iContactItem);
	//add contact a id as an agent field value
	AddAgentFieldL(KFirstContactId);
	CommitL();
	
	CContactIdArray *ArrayOfExportedContactIds = CContactIdArray::NewLC();
	//set contact a and b to be export
	ArrayOfExportedContactIds->AddL(KFirstContactId);
	ArrayOfExportedContactIds->AddL(KSecondContactId);
	
	//export contact a & b
	ExportVcardL(*ArrayOfExportedContactIds);
	
	const TInt KFirstContactAccessCountAfterExport = GetAccessCountL(KFirstContactId);
	const TInt KSecondContactAccessCountAfterExport = GetAccessCountL(KSecondContactId);
	const TInt KSecondContactAgentFieldAfterExport = GetAgentFieldL(KSecondContactId);
	CleanupStack::PopAndDestroy(ArrayOfExportedContactIds);
	
	//delete all fields from contact b
	OpenL(KSecondContactId,*iViewAll);
	iFields->Reset();
	CommitL();
	
	//import exported contacts
	ImportVcardL();
	
	const TInt KFirstContactAccessCountAfterImport = GetAccessCountL(KFirstContactId);
	const TInt KSecondContactAccessCountAfterImport = GetAccessCountL(KSecondContactId);
	const TContactItemId KSecondContactAgentFieldAfterImport = GetAgentFieldL(KSecondContactId);
	
	//importing & exporting contacts should not affect the access count
	INTCOMPARE( KFirstContactAccessCountAfterExport , ==,  0, 0, 0 ); 
	INTCOMPARE( KSecondContactAccessCountAfterExport , ==,  0, 0, 0 ); 
	INTCOMPARE( KFirstContactAccessCountAfterExport , ==,  KFirstContactAccessCountAfterImport, 0, 0 );
	INTCOMPARE( KSecondContactAccessCountAfterExport , ==,  KSecondContactAccessCountAfterImport, 0, 0 );
	
	//agent field values should not be exported/imported
	INTCOMPARE( KFirstContactId , ==,  KSecondContactAgentFieldAfterImport, 0, 0 ); 
	//exporting contacts should not affect the internal state of the contacts agent field
	INTCOMPARE( KSecondContactAgentFieldAfterExport , ==,  KFirstContactId, 0, 0 );
	
	iParent->Fs().Delete(KVcardFile);//cleanup of exported vcard file
	}
Beispiel #11
0
/*
 * Private implementation for updating the buffer containing the members of all
 * groups.
 */
void CntSymbianDatabase::updateGroupMembershipsL()
{
    CContactIdArray *groupIds = m_contactDatabase->GetGroupIdListL();
    for (TInt i(0); i < groupIds->Count(); ++i) {
        QContactLocalId id = (*groupIds)[i];
        QSet<QContactLocalId> dummySet;
        updateGroupMembershipsL(id, dummySet, dummySet);
    }
    delete groupIds;
}
LOCAL_C void DoTestsL()
	{
    CleanupClosePushL(test);
	test.Start(_L("@SYMTESTCaseID:PIM-T-TEMPLATECACHE-0001 ----------- State Tests ----------"));


   	__UHEAP_MARK;

	RCntModel cntClient; 
	cntClient.ConnectL();
	cntClient.OpenDatabase();
	
	CCntTemplateCache* templateCache = CCntTemplateCache::NewL(cntClient);
	CleanupStack::PushL(templateCache);
	
	CContactIdArray* cardTemplateIds = CContactIdArray::NewLC();
	// Add 15 templates
	CContactTemplate* contactTemplate = NULL;
	TInt ii = 0;
	for (; ii < 15; ++ii)
		{
		contactTemplate = CContactTemplate::NewLC();
		cardTemplateIds->AddL(cntClient.CreateContactL(*contactTemplate));
		CleanupStack::PopAndDestroy(); // contactTemplate
		}
		
	// Create a contactItem
	CCntItemBuilder* cntItemBldr = CCntItemBuilder::NewLC(static_cast<CContactTemplate&>(templateCache->SystemTemplateL()));
	CContactItem* cntItem 		 = cntItemBldr->GetCntItemLC();
	/*TContactItemId cntId  		 = */cntClient.CreateContactL(*cntItem);

	ii = 0;
	for (; ii < 15; ++ii)
		{
		cntItem->SetTemplateRefId((*cardTemplateIds)[ii]);
		templateCache->MergeWithTemplateL(*cntItem);
		// Merge a second time... the template should now be cached
		templateCache->MergeWithTemplateL(*cntItem);
		}
	
	
	CleanupStack::PopAndDestroy(cntItem);
	CleanupStack::PopAndDestroy(cntItemBldr);
	CleanupStack::PopAndDestroy(cardTemplateIds);
	CleanupStack::PopAndDestroy(templateCache);
	cntClient.Close();
	
	__UHEAP_MARKEND;

  	test.Next(_L("---- All Tests Completed OK ----"));


	test.End();
    CleanupStack::PopAndDestroy(1); // test.Close
	}
// Creates a few test contacts.
void CTestResources::CreateTestContactsL()
    {
    TContactItemId id;
    id = CreateTestContactL(*iDb, _L("Hakkinen"), _L("Mika"), _L("McLaren"));
    iContacts->AddL(id);
    id = CreateTestContactL(*iDb, _L("Coulthard"), _L("David"), _L("McLaren"));
    iContacts->AddL(id);
    id = CreateTestContactL(*iDb, _L("Schumacher"), _L("Michael"), _L("Ferrari"));
    iContacts->AddL(id);
    id = CreateTestContactL(*iDb, _L("Raikkonen"), _L("Kimi"), _L("Sauber"));
    iContacts->AddL(id);
    }
/**
GetListForItemL has a dual nature. If aIsGroup is ETrue, a list of contact items belonging to
specified group is returned. Otherwise a list of group ids to which contact id belongs is returned.

@param aItemId contact item id
@param aIsGroup ETrue if the method will fill a group.
*/
CContactIdArray* CPplGroupsTable::GetListForItemL(TContactItemId aItemId, TBool aIsGroup)
	{
	/*
	// Check if group membership information was not requested or if the item
	// is not derived from CContactItemPlusGroup.
	if (!(aType == KUidContactGroup	  || aType == KUidContactCard ||
		  aType == KUidContactOwnCard || aType == KUidContactICCEntry) )
		{
		return NULL; 
		}
	*/	

	// build the RSqlStatement
	RSqlStatement stmnt;
	CleanupClosePushL(stmnt);
	TInt idIndex;

	// build the CCntSqlStatement statement
	const TInt KWhereParamIndex(KFirstIndex); // only one parameter in the query
	if (aIsGroup)
		{
		// group -> select members
		stmnt.PrepareL(iDatabase, iSelectMembersStmnt->SqlStringL() );
		User::LeaveIfError(stmnt.BindInt(KWhereParamIndex, aItemId ) );
		idIndex = stmnt.ColumnIndex(KGroupContactGroupMemberId() );
		}
	else
		{
		// member -> select groups
		stmnt.PrepareL(iDatabase, iSelectGroupsStmnt->SqlStringL() );
		User::LeaveIfError(stmnt.BindInt(KWhereParamIndex, aItemId ) );
		idIndex = stmnt.ColumnIndex(KGroupContactGroupId() );
		}
	User::LeaveIfError(idIndex);
	// fetch the list of any matching ids
	CContactIdArray* items = CContactIdArray::NewLC();
	TInt err(KErrNone);
	while ((err = stmnt.Next() ) == KSqlAtRow)
		{
		items->AddL(stmnt.ColumnInt(idIndex) );
		}

	// leave if we didn't complete going through the results properly
	if(err != KSqlAtEnd)
		{
		User::Leave(err);
		}
	
	CleanupStack::Pop(items);
	CleanupStack::PopAndDestroy(&stmnt);
	return items;
	}
CContactIdArray* CPackagerCntFactory::doCreateDefaultCContactIdArrayL() const
/** Implementation method for constructing a new default CContactIdArray object. 

@return a Pointer to the CContactIdArray object. */
	{
	CContactIdArray* theArray = CContactIdArray::NewL();
	CleanupStack::PushL(theArray);
	theArray->AddL(KId1);
	theArray->AddL(KId2);
	theArray->AddL(KId3);
	theArray->AddL(KId4);
	theArray->AddL(KId5);
	CleanupStack::Pop(theArray);
	return theArray;
	}	
Beispiel #16
0
LOCAL_C void TestSetOwnCardL(CContactDatabase* aDb)
    {
    CContactIdArray* idArray = aDb->ContactsChangedSinceL(TTime(0));
    CleanupStack::PushL(idArray);
    TInt count = idArray->Count();
    if (count > 0)
        {
        TInt someIndex(0); //Make the first contact own contact           
        TContactItemId id = (*idArray)[someIndex];
        CContactItem* item = aDb->ReadContactLC(id); // take ownership of item
        aDb->SetOwnCardL(*item);
        CleanupStack::PopAndDestroy(item);
        }        
    CleanupStack::PopAndDestroy(idArray);
    }
void CFilteredViewTester::AddContactsL(TInt aCount)
	{
	for (TInt i = 0; i < aCount; ++i)
		{		
		iIdArray->AddL(DoAddContactL(i));
		}    
	}
// -----------------------------------------------------------------------------
// TSnapshotItem::CreateHashL
// Create hash value from group content
// -----------------------------------------------------------------------------
void TSnapshotItem::CreateHashL( CContactGroup& aGroup )
    {
    CMessageDigest* hash = CMessageDigestFactory::NewDigestLC( CMessageDigest::EMD5 );
    
    if ( aGroup.HasItemLabelField() )
        {
        TPtrC label = aGroup.GetGroupLabelL();
        HBufC8* tempBuf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( label );
        CleanupStack::PushL( tempBuf );
        hash->Update( tempBuf->Des() );
        CleanupStack::PopAndDestroy( tempBuf );
        }
    
    // Create text field from items on group
    CContactIdArray* contactsIdArray = aGroup.ItemsContainedLC();
    const TInt idBufferMaxSize( 400 );
    HBufC8* tempIdBuf = HBufC8::NewLC( idBufferMaxSize );
    TPtr8 tempId = tempIdBuf->Des();
    const TInt KMaxNumLength(5);
    if ( contactsIdArray ) // this is NULL if there are no objects
        {
        tempId.AppendNum( contactsIdArray->Count(), EHex );
        for (TInt i=0; i< contactsIdArray->Count(); i++ )
            {
            if ( tempId.Length()+KMaxNumLength > tempId.MaxLength() )
                {
                // buffer is almost full, don't add any new items
                LOGGER_WRITE("buffer full");
                break;
                }
            // add item id
            tempId.AppendNum( (*contactsIdArray)[i] , EHex );
            }
        }
    else
        {
        tempId.AppendNum( 0 );
        }
    // update hash
    hash->Update( tempId );
    
    iHash.Copy( hash->Final() );
    
    CleanupStack::PopAndDestroy( tempIdBuf );
    CleanupStack::PopAndDestroy( contactsIdArray );
    CleanupStack::PopAndDestroy( hash );
    }
/*
	Creates a random array of numbers corresponding to the Contacts Id in the 
	Contacts model.  No Contact Id is repeated  
*/
void CDeleteMany::CreateRandomIdArrayL(CContactIdArray& aUids, TInt aNumIds, TInt aNumEntriesInDb)
	{
	TTime now;
	now.UniversalTime();
	TInt64 KRandomSeed = now.DateTime().MicroSecond();

	TInt uid(0);
	for(TInt i = 0; i < aNumIds; ++i)
		{
		uid = (Math::Rand(KRandomSeed) % aNumEntriesInDb) + 1;
		while(aUids.Find(uid) != KErrNotFound)
			{
			uid = (Math::Rand(KRandomSeed) % aNumEntriesInDb) + 1;
			}
		aUids.AddL(uid);		
		}
	}
Beispiel #20
0
LOCAL_C void DeleteBasicContactGroups()
	{
	test.Next(_L("Delete Basic Groups"));
	TInt groupCount = CntTest->Db()->GroupCount();
	__ASSERT_ALWAYS(groupCount==2,Panic(KErrGeneral));
	CContactIdArray* groupIdList = CntTest->Db()->GetGroupIdListL();
	CleanupStack::PushL(groupIdList);
	test(groupIdList->Count()==2);
//
	for (TInt ii=0; ii< groupIdList->Count();ii++)
		CntTest->Db()->DeleteContactL((*groupIdList)[ii]);
	test(CntTest->Db()->CountL()==0); //own card
	CContactIdArray* newGroupIdList = CntTest->Db()->GetGroupIdListL();
	test(newGroupIdList->Count()==0);
	delete newGroupIdList;
	CleanupStack::PopAndDestroy(); //groupIdList;
	}	
Beispiel #21
0
void CTestContactOperations::DeleteContactsL()
	{
	// existing database
   	TPtrC databaseFile(_L("C:contactDB.cdb"));
   	
   	TContactItemId itemId = KErrNotFound;
	CContactDatabase* dBase = NULL;
	CContactIdArray* idArray = NULL;
	
	dBase = CContactDatabase::OpenL(databaseFile);
	CleanupStack::PushL(dBase);
	
	// Set the filter to select all the contact items in the database
	CCntFilter* exportFilter = CCntFilter::NewL();
	CleanupStack::PushL(exportFilter);
	exportFilter->SetContactFilterTypeCard(ETrue);
	dBase->FilterDatabaseL(*exportFilter);
	idArray = exportFilter->iIds;	
	CleanupStack::PushL(idArray);
	
	TInt numberOfContacts;
   	GetIntFromConfig(ConfigSection(), KNumberOfCont, numberOfContacts);
	
	INFO_PRINTF1(_L("Deleting Contacts....."));

	// Delete the contacts one at a time
	for(TInt i=(idArray->Count()-1);i>=0;i--)
		{
		dBase->DeleteContactL((*idArray)[i]);
		}
			
	_LIT(KCount, "The number of contacts in the database is %d \n");
	INFO_PRINTF2(KCount, dBase->CountL());
	
	// Close the contacts
    dBase->CloseContactL(itemId);
	
	// Cleanup
	CleanupStack::Pop(idArray);
    CleanupStack::PopAndDestroy(exportFilter);
    CleanupStack::PopAndDestroy(dBase);
    }
Beispiel #22
0
LOCAL_C void CheckPhoneMatchL(const TDesC& aPhoneNumberToMatch, TInt aNumberOfMatchDigits, TInt aExpectedNumOfMatches)
{
    TBuf<256> testCase;
    _LIT(KFormat,"Checking %d matches to %S, matching %d digits");
    testCase.Format(KFormat, aExpectedNumOfMatches, &aPhoneNumberToMatch, aNumberOfMatchDigits);
    test.Next(_L(" "));

    CContactDatabase& db = *(CntTest->Db());
    CContactIdArray* array = db.MatchPhoneNumberL(aPhoneNumberToMatch,aNumberOfMatchDigits);
    CleanupStack::PushL(array);
    const TInt numberOfMatches = array->Count();
    CleanupStack::PopAndDestroy(array);


    TInt sfd = db.MachineId();
    // OverrideMachineUniqueId


    test(numberOfMatches==aExpectedNumOfMatches);
}
Beispiel #23
0
void VersitExportContactL(const TDesC& aExportFileName)
{
    RFileWriteStream writeStream;
    User::LeaveIfError(writeStream.Replace(fsSession, aExportFileName, EFileWrite));
    CleanupClosePushL(writeStream);
    
    CContactIdArray* idArray = CContactIdArray::NewLC();
    TInt count = CntTest->Db()->CountL();
	test(count == 1);
    TContactItemId contactId = CntTest->Db()->GetCurrentItem();
    
    idArray->InsertL(0, contactId);
    
    CntTest->Db()->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl), *idArray, writeStream,0);
    writeStream.Close();
    
	CleanupStack::PopAndDestroy(2); //idArray, writeStream
	                                                                     
    	
}
Beispiel #24
0
/**
Convert between view indexes and contact ids.
This method makes the request to the server.
@capability ReadUserData
 */
void RContactRemoteView::GetContactIdsL(const CArrayFix<TInt>& aIndexes, CContactIdArray& aContactIds)
    {
    CBufBase* buffer = CBufFlat::NewL(32);
    CleanupStack::PushL(buffer);
    RBufWriteStream writeStream(*buffer);
    CleanupClosePushL(writeStream);

    const TInt count = aIndexes.Count();
    writeStream.WriteUint32L(count);
    for (TInt i=0; i<count; ++i)
        {
        writeStream.WriteUint32L(aIndexes[i]);
        }
    writeStream.CommitL();
    CleanupStack::PopAndDestroy(&writeStream); //writeStream.Close()


    TPtr8 indexes(buffer->Ptr(0));
    const TInt bufferSize = buffer->Size();
    TPckg<TInt> size(bufferSize);
    
    HBufC8* buf=HBufC8::NewLC(bufferSize);
    TPtr8 ids(buf->Des());
    
    TIpcArgs args(&size, &indexes, &ids);
    User::LeaveIfError(SendReceive(ECntGetContactIds,args));


    RDesReadStream readStream(ids);
    CleanupClosePushL(readStream);
    CContactIdArray* array = CContactIdArray::NewLC();
    readStream >> *array;

    const TInt arrayCount = array->Count();
    for(TInt loop=0;loop<arrayCount;loop++)
        aContactIds.AddL((*array)[loop]);

    CleanupStack::PopAndDestroy(4,buffer); //array, &readStream, buf, buffer
    }
void CTestResources::CreateTestContactsL()
    {
    const TInt KContacts = 4;
    TInt i;
    iContacts = CContactIdArray::NewL();

    // Create contacts
    for (i=1; i <= KContacts; ++i)
        {
        CContactCard* card = CContactCard::NewLC();
        CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
        TBuf<30> name;
        name.Format(_L("Contact%02d"), i);
        field->TextStorage()->SetTextL(name);
        card->AddFieldL(*field);
        CleanupStack::Pop(field);
        const TContactItemId contactId = iDb->AddNewContactL(*card);
        iContacts->AddL(contactId);
        CleanupStack::PopAndDestroy(card);
        // Eat away contact db events
        TContactDbObserverEvent event;
        test(iDbEventQueue->ListenForEvent(10,event));
        }

    // Create a group
    CContactItem* group = iDb->CreateContactGroupLC(_L("TestGroup"));
    iGroupId = group->Id();
    CleanupStack::PopAndDestroy(group);

    // Connect half of the contacts to the group
    for (i=0; i < iContacts->Count(); ++i)
        {
        if (i%2 == 0)
            {
            iDb->AddContactToGroupL((*iContacts)[i], iGroupId);            
            }
        }
    }
void  CTestResources::CheckFoundL(TInt i)
	{
	if(i<0 || i>GNumberOfFieldNames)
		{
		User::Leave(KErrNotSupported);
		}
	iFindFields->Reset();
	if(i==GNumberOfFieldNames)
		{
		for(TInt k =0; k<i; k++)
			{
			iFindFields->AppendL(TUid::Uid(GFieldNames[k]));
			}
		}
	else
		{
		iFindFields->AppendL(TUid::Uid(GFieldNames[i]));
		}
	CContactIdArray* ids = iDb->FindLC(KStringToFind, iFindFields);
	TInt count = ids->Count();
	test(count == GNumberOfFinds[i]);
	CleanupStack::PopAndDestroy(ids);
	 }
void TestMatchPhoneNumberL(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
	{
	// The synchroniser is not called to validate the IDs at for this method because 
	// phone number resolution needs to be as quick as possible. 
	// Instead, validation is done when the client attempts to read the items.
	test.Next(_L("Test MatchPhoneNumberL"));
	// Successful find of icc entry phone number
	syncChecker->ResetMethodCallCountsL();
	CContactIdArray* array = aDb.MatchPhoneNumberL(KIccNumber,KMaxPhoneMatchLength);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aIccId);
	delete array;
	array=NULL;

	test.Next(_L("Test searching when ICC locked"));
	// successful find when icc locked - validation done when entry read
	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
	syncChecker->ResetMethodCallCountsL();
	TRAPD(err,array = aDb.MatchPhoneNumberL(KIccNumber,KMaxPhoneMatchLength));
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(array!=NULL);
	test(err==KErrNone);
	test((*array)[0]==aIccId);
	delete array;
	array=NULL;
	syncChecker->ResetMethodCallCountsL();
	array = aDb.MatchPhoneNumberL(KNonIccNumber,KMaxPhoneMatchLength);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aNonIccId);
	delete array;
	array=NULL;
	}
void CFilteredViewTester::HandleContactViewEvent(const CContactViewBase& aView, const TContactViewEvent& aEvent)
	{	
	switch (aEvent.iEventType)
		{
		case TContactViewEvent::EReady:
			{
			if (&aView == iBaseView)
				{
				iBaseReady = ETrue;
				}
			else if (&aView == iFilteredView)
				{
				iFilteredReady = ETrue;
				}

			if (iFilteredReady && iBaseReady && iState == ECreateView)
				{
				iState = EAddContacts;
				TRAPD(err, NextTestStepL() );
				test(err == KErrNone);
				}
			break;
			}

		case TContactViewEvent::EItemAdded:
			{
			if (&aView == iBaseView)
				{
				test.Printf(_L("Add event received: Base view\r\n"));
				iBaseContactsCount++;
				}
			else if (&aView == iFilteredView)
				{
				iPosition.AppendL(aEvent.iInt);
				test.Printf(_L("Add event received: Filtered view\r\n"));
				iFilteredContactsCount++;
				}
			if (iBaseContactsCount == KNumOfContacts && iFilteredContactsCount == KNumOfContacts && iState == EAddContacts)
				{
				iState = EDeleteContacts;
				NextTestStepL();
				}
			break;
			}

		case TContactViewEvent::EItemRemoved:
			{
			if (&aView == iBaseView)
				{
				test.Printf(_L("Remove event received: Base view\r\n"));
				iBaseContactsCount--;
				}
			else if (&aView == iFilteredView)
				{
				test.Printf(_L("Remove event received: Filtered view\r\n"));
				iFilteredContactsCount--;
				//Verify that deleted contact is the one present in the event received.
				//The order is not important. 
				TBool found = EFalse;
				TInt count = iIdArray->Count();
				for(TInt loop = 0; loop < count;++loop)
					{
					if(aEvent.iContactId == (*iIdArray)[loop])
						{
						found = ETrue;
						break;
						}
					} 
				test(found);
				//test that the underlying position is within the range of total number of contacts.				
				found = EFalse;
				count = iPosition.Count();
				for(TInt loop = 0; loop < count;++loop)
					{
					if(aEvent.iInt == iPosition[loop])
						{
						found = ETrue;
						break;
						}
					} 
				test(found);				
				}

			if (iBaseContactsCount == 0 && iFilteredContactsCount == 0 && iState == EDeleteContacts)
				{
				iState = ETestComplete;
				NextTestStepL();
				}
			break;
			}

		default:
			{
			// do nothing...
			break;
			}
		}	
	}
void CTestImpExvCardSuiteStepBase::ExportItemL(TBuf<80> aPath, TBool aAddBDay)
	{
	OpenDBL();
	
	TContactItemId itemId;
	RFs fsSession;
	RFileWriteStream fileStream;

	CContactIdArray* idArray = NULL;
	CContactCard* contactAdded = NULL;
	TTime now;
	
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);
	
	idArray = CContactIdArray::NewL();

	CleanupStack::PushL(idArray);   // idArray

	fsSession.MkDirAll(aPath);
	User::LeaveIfError(fileStream.Replace(fsSession, aPath, EFileWrite));

	contactAdded = CContactCard::NewL();

	CleanupStack::PushL(contactAdded);   // contactAdded
	
	contactAdded->IncAccessCount();
	
	// ADD BDAY
	if (aAddBDay)
		{
		CContactItemFieldSet& fieldSet=contactAdded->CardFields();
		const TInt pos=fieldSet.Find(KUidContactFieldBirthday);
	
		if (pos!=KErrNotFound)
			{
			fieldSet[pos].DateTimeStorage()->SetTime(iBDayLocal);
			}
		else
			{
			CContactItemField* field=CContactItemField::NewLC(KStorageTypeDateTime,KUidContactFieldBirthday);
   			field->SetMapping(KUidContactFieldVCardMapBDAY);
			field->DateTimeStorage()->SetTime(iBDayLocal);
			contactAdded->AddFieldL(*field);
	
			CleanupStack::Pop(); // field
			}
		}
	
	SetNameL(*contactAdded, KUidContactFieldGivenName, _L("toby"), ETrue);
	SetNameL(*contactAdded, KUidContactFieldPhoneNumber, _L("6041233214"), ETrue);

	User::After(3000000);

	// There is no need to call SetLastModifed because
	// That function will be call by ExportSelectedContactsL below
	now.UniversalTime();
	iRecordedTime = now;
	
	INFO_PRINTF1(_L("Adding contact to Database....."));
	itemId = iDb->AddNewContactL(*contactAdded);
	INFO_PRINTF1(_L("Contact Added to Database"));
	CleanupStack::PopAndDestroy(contactAdded);  // contactAdded
	contactAdded = NULL;

	idArray->InsertL(0, itemId);

	INFO_PRINTF1(_L("Exporting Contact....."));
	iDb->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl), *idArray, fileStream, CContactVCardConverter::EDefault, ETrue);
	INFO_PRINTF1(_L("Exported Contact"));
	fileStream.CommitL();
	fileStream.Close();
	
	CleanupStack::PopAndDestroy(idArray);  // idArray
	fsSession.Close();
	CleanupStack::PopAndDestroy();  // fsSession
	CloseDB();
	}
/**
Returns an array of contact item IDs for all the contact items which may contain
the specified telephone number in a telephone, fax or SMS type field.

This is improved version of MatchPhoneNumberL method.
The number is compared starting from the right side of the number and 
the method returns an array of candidate matches.  
Punctuation (e.g. spaces) and other alphabetic characters are ignored
when comparing. Leading zeros are removed. Digits are compared up to 
the lenght of shorter number.

@param aNumber Phone number string.
@return Array of contact IDs which are candidate matches.
*/
CContactIdArray* CPplCommAddrTable::BestMatchingPhoneNumberL(const TDesC& aNumber)
    {
    const TInt KUpperMaxLength = KMaxPhoneMatchLength - KLowerSevenDigits;

    CContactIdArray* phoneMatchArray = CContactIdArray::NewLC();

    TMatch phoneDigits = CreatePaddedPhoneDigitsL(aNumber, KLowerSevenDigits, KUpperMaxLength);

    if (phoneDigits.iNumLowerDigits + phoneDigits.iNumUpperDigits > 0)
        {
        // build statement
        RSqlStatement stmnt;
        CleanupClosePushL(stmnt);
        stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL());

        const TInt KValueParamIndex(KFirstParam); // first parameter in query...
        const TInt KTypeParamIndex(KValueParamIndex + 1); // ...and the second.

        User::LeaveIfError(stmnt.BindInt(KValueParamIndex,
                phoneDigits.iLowerSevenDigits));
        User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, EPhoneNumber));

        // fetch the list of any matching contact ids
        TInt err(KErrNone);
        const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex( KCommAddrContactId()));
        const TInt KExtraValueIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrExtraValue()));
        while ((err = stmnt.Next()) == KSqlAtRow)
            {
            // Check the upper digits...
            TInt32 number = phoneDigits.iUpperDigits;
            TPtrC extValString = stmnt.ColumnTextL(KExtraValueIdx);
            TInt32 storedUpperDigits;
            User::LeaveIfError(TLex(extValString).Val(storedUpperDigits));
            TInt32 stored = storedUpperDigits;

            TBool nonZeroInStoredFound = EFalse;
            TBool nonZeroInNumberFound = EFalse;
            while ((number != 0) && (stored != 0))
                {
                nonZeroInNumberFound |= (number % 10 != 0);
                nonZeroInStoredFound |= (stored % 10 != 0);
                if (nonZeroInStoredFound && nonZeroInNumberFound)
                    {
                    break;
                    }
                number /= 10;
                stored /= 10;
                }

            if ( (phoneDigits.iUpperDigits == 0) || (storedUpperDigits == 0) ||
                 (number == stored) )
                {
                phoneMatchArray->AddL(stmnt.ColumnInt(KContactIdIdx));
                }
            }

        // leave if we didn't complete going through the results properly
        if (err != KSqlAtEnd)
            {
            User::Leave(err);
            }
        CleanupStack::PopAndDestroy(&stmnt);
        }

    CleanupStack::Pop(phoneMatchArray);
    return phoneMatchArray;
    }