//===============================================================================================
// 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
	}
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;	
	}	
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
	}
Ejemplo n.º 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;
	}
Ejemplo n.º 5
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;
	}
Ejemplo n.º 6
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;
	}	
Ejemplo n.º 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);
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
LOCAL_C void CommonIdArrayTestsL(CContactIdArray& aIds,TInt aId)
	{
	TInt index=aIds.Find(aId);
	test(index!=KErrNotFound);
	for (TInt ii=0;ii<5;ii++)
		{
		aIds.MoveL(index,ii);
		test(aIds.Count()==5);
		const TInt newPos=aIds.Find(aId);
		test(newPos==ii);
		aIds.MoveL(newPos,index);
		test(aIds.Count()==5);
		test(aIds.Find(aId)==index);
		}
	aIds.Remove(index);
	test(aIds.Count()==4);
	aIds.InsertL(index,aId);
	test(aIds.Count()==5);
	test(aIds.Find(aId)==index);
	test(aIds[index]==aId);
	}
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;
	}
Ejemplo n.º 12
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);
    }
Ejemplo n.º 13
0
// -----------------------------------------------------------------------------
// 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 );
    }
Ejemplo n.º 14
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);
    }
Ejemplo n.º 15
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);
}
Ejemplo n.º 16
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
    }
Ejemplo n.º 17
0
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);            
            }
        }
    }
Ejemplo n.º 18
0
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);
	 }
Ejemplo n.º 19
0
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 CTestContactsPBAPExport::ExportContactsL()
	{
	TInt err = KErrNone;
	// Retrieve the file name to which contact item is to be exported
   	RFs fsSession;
	RFileWriteStream writeStream;

	// connect to file system
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);

	GetInputFromIni();

   	// Makes one or more directories.
   	fsSession.MkDirAll(iExportTo);

	// Replaces a single file with another
	User::LeaveIfError(writeStream.Replace(fsSession, iExportTo, EFileWrite));

	INFO_PRINTF1(_L("Exporting Contact....."));

	// Existing database
   	TPtrC databaseFile(_L("C:contactDb.cdb"));

	CContactDatabase* dBase = NULL;
	CContactIdArray* idArray = NULL;

	// Open the existing database
	dBase = CContactDatabase::OpenL(databaseFile);
	CleanupStack::PushL(dBase);

	// Create Utility class object, to export the contact from database
	CTestStep* self = static_cast<CTestStep*>(this);
	iExportObj = new(ELeave) CContactsPBAPExportUtilityClass(self);

	SetFilterL();

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

	// Get all the contacts from the database to export
	exportFilter->SetContactFilterTypeCard(ETrue);
	dBase->FilterDatabaseL(*exportFilter);
	idArray = exportFilter->iIds;
	CleanupStack::PushL(idArray);

	if(iDamageDb)
		{
		#ifdef _DEBUG
		#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
		TRAPD(err1,dBase->DamageDatabaseL(0x666));
		if(err1 == KErrNone)
			{
			TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
			INFO_PRINTF2(_L("Err:%d"),err);
			if(err == KErrNotReady)
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			if(dBase->IsDamaged())
				{
				dBase->RecoverL();
				}
			}
		else
			{
			INFO_PRINTF2(_L("Could not damage database Err:"),err1);
			}
		#else
			SetTestStepResult(EPass);
		#endif
		#endif
		}
    else
	    {
	    if(iInvalidFileSystem)
		    {
		    #ifdef _DEBUG
		    fsSession.SetErrorCondition(KErrNotReady);
		    TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
			if(err == KErrNotReady)
				{
				SetTestStepResult(EPass);
				}
			else
				{
				SetTestStepResult(EFail);
				}
			fsSession.SetErrorCondition(KErrNone);
			#endif
			}
	    else
			{
			if(!iSetOOM)
				{
				if(idArray->Count() > 0)
					{
					for(TInt i=0; i<idArray->Count() ; i++)
						{
						TInt dCount = dBase->CountL();
						if(i>=dCount)
							{
							break;
							}

						// temporary array used to export one contact at a time
						CContactIdArray* tempIdArray = CContactIdArray::NewL();
						CleanupStack::PushL(tempIdArray);
						tempIdArray->AddL((*idArray)[i]);
						TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, tempIdArray, writeStream, iContactFilter));

						if(err != KErrNone )
							{
							if(err != KErrNotFound)
								{
								SetTestStepError(err);
								}
							}

						CleanupStack::PopAndDestroy(tempIdArray);
						}
					}
				else
					{
					if(idArray->Count()==0)
						{
						TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));
						if(err != KErrNone)
							{
							SetTestStepError(err);
							}
						}
					}

				}
			else
				{
				TInt tryCount = 1;
				for ( ;; )
					{
					__UHEAP_SETFAIL(RHeap::EDeterministic, tryCount);
					TRAP(err, iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter));

					if ( err == KErrNone )
						{
						__UHEAP_RESET;
						INFO_PRINTF1(_L("OOM testing of CContactDatabase::ExportSelectedContactsL Api is done"));
						break;
						}
					if ( err != KErrNoMemory )
						{
						INFO_PRINTF2(_L("The unexpected error code is:%d"),err);
						SetTestStepResult(EFail);
						break;
						}
					__UHEAP_SETFAIL(RHeap::ENone, 0);
					tryCount++;
					}
				}
			}
	    }

	CleanupStack::Pop(idArray);
	CleanupStack::PopAndDestroy(exportFilter);

	INFO_PRINTF1(_L("Exported Contact"));
	writeStream.CommitL();
	writeStream.Close();

	INFO_PRINTF2(_L("Total number of contacts in database %d "), dBase->CountL());

	// Cleanup
	CleanupStack::PopAndDestroy(dBase);
    CleanupStack::PopAndDestroy(&fsSession);
	}
Ejemplo n.º 21
0
void CGroupViewTester::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent)
	{
	//LOGGING///////////////////////////////////////////////////////////////////////////////////
				if(&aView == iLocalView)
					test.Printf(_L("LocalView "));
				else if(&aView == iGroupViewOne)
					test.Printf(_L("GroupViewOne "));
				else if(&aView == iGroupViewOneByName)
					test.Printf(_L("GroupViewOneByName "));
				else if(&aView == iGroupViewOneNotInGroup)
					test.Printf(_L("GroupViewOneNotInGroup "));
				else if(&aView == iGroupViewUnfiled)
					test.Printf(_L("GroupViewUnfiled "));
				else
					test.Printf(_L("Er, none of the known views... "));

				switch (aEvent.iEventType)
					{
					case TContactViewEvent::EUnavailable:
						test.Printf(_L("EUnavailable\n"));
						break;
					case TContactViewEvent::EReady:
						test.Printf(_L("EReady\n"));
						break;
					case TContactViewEvent::ESortOrderChanged:
						test.Printf(_L("ESortOrderChanged\n"));
						break;
					case TContactViewEvent::ESortError:
						test.Printf(_L("ESortError\n"));
						break;
					case TContactViewEvent::EServerError:
						test.Printf(_L("EServerError\n"));
						break;
					case TContactViewEvent::EIndexingError:
						test.Printf(_L("EIndexingError\n"));
						break;
					case TContactViewEvent::EItemAdded:
						test.Printf(_L("EItemAdded\n"));
						break;
					case TContactViewEvent::EItemRemoved:
						test.Printf(_L("EItemRemoved\n"));
						break;
					case TContactViewEvent::EGroupChanged:
						test.Printf(_L("EGroupChanged\n"));
						break;
					default:
						test.Printf(_L("Er, none of the known event types... "));
						break;
					}
	////////////////////////////////////////////////////////////////////////////////////////////
	
	switch (iCurrentTest)
		{
		case ECreateLocalView:
			test(iLocalView==&aView);
			test(aEvent.iEventType==TContactViewEvent::EReady);
			break;
		case EExerciseLocalView:
			test(ETrue);
			break;
		case ECreateGroupOneView:
			test(iGroupViewOne==&aView);
			test(aEvent.iEventType==TContactViewEvent::EReady);
			break;
		case ETestGroupOneView:
			test(EFalse);
			break;
		case ECreateGroupOneViewByName:
			test(iGroupViewOneByName==&aView);
			test(aEvent.iEventType==TContactViewEvent::EReady);
			break;
		case ETestGroupOneViewByName:
			test(EFalse);
			break;
		case ECreateGroupOneViewNotInGroup:
			test(iGroupViewOneNotInGroup==&aView);
			test(aEvent.iEventType==TContactViewEvent::EReady);
			break;
		case ETestGroupOneViewNotInGroup:
			test(EFalse);
			break;
		case EAllViewsOutOfBoundsAccess:
			test(EFalse);
			break;
		case ECreateUnfiledGroupView:
			test(iGroupViewUnfiled==&aView);
			test(aEvent.iEventType==TContactViewEvent::EReady);
			break;
		case ETestUnfiledGroupView:
			break;
		case ETestUnfiledGroupAddition:
			{
			// No point testing for each and every notification: the test will
			// pass for all notifications.
			if (iNumNotificationExpected > 1)
				{
				break;
				}
			// Test that adding contact which formed part of iGroupViewUnfiled
			// to iGroupOne caused update of iGroupViewUnfiled such that the
			// contact no longer forms part of iGroupViewUnfiled (i.e. by adding
			// the contact to the group it is no longer unfiled is not a member
			// of the unfiled view).
			TInt ret(KErrNone);
			TRAPD(err1, ret = iGroupViewUnfiled->FindL(KNumContacts) );
			test(err1 == KErrNone && ret == KErrNotFound);
			// Double check - make sure the number of items in the unfiled
			// group view agrees with the number of unfiled items reported by
			// the database.
			TInt groupViewUnfiledCount(0);
			TRAPD(err2, groupViewUnfiledCount = iGroupViewUnfiled->CountL() );
			CContactIdArray* dbUnfiled = NULL;
			TRAPD(err3, dbUnfiled = iDb.UnfiledContactsL() );
			test(err2 == KErrNone && err3 == KErrNone && groupViewUnfiledCount==dbUnfiled->Count() );
			delete dbUnfiled;
			}
			break;
		case ENumTests:
		default:
			test(EFalse);
			break;
		}
	if (--iNumNotificationExpected <= 0)
		{
		iNumNotificationExpected=0;
		NextTest();
		}
	}
Ejemplo n.º 22
0
void CGroupViewTester::RunL()
	{
	switch (iCurrentTest)
		{
		case ECreateLocalView:
			iLog.LogLine(_L("=== Create local view"));
			iLocalView=CContactLocalView::NewL(*this,iDb,iSortOrder_1,EContactAndGroups/*EContactsOnly*/);
			break;
		case EExerciseLocalView:
			iLog.LogLine(_L("=== Exercise local view"));			
			ExceriseViewL(*iLocalView);
			NextTest();
			break;
		case ECreateGroupOneView:
			{
			iLog.LogLine(_L("=== GroupOneView"));
			iGroupViewOne=CContactGroupView::NewL(iDb,*iLocalView,*this,iGroupOne->Id(),CContactGroupView::EShowContactsInGroup);
			}
			break;
		case ETestGroupOneView:
			{
			iLog.LogLine(_L("==== Exercise ETestGroupOneView"));
			TInt groupCount = iGroupOne->ItemsContained()->Count();
			test(iGroupViewOne->CountL()==groupCount);
			const CContactIdArray* array= iGroupOne->ItemsContained();
			for (TInt ii=0;ii<groupCount;ii++)
				{
				test(iGroupViewOne->FindL((*array)[ii])!=KErrNotFound);
				}
			TestGroupViewSortOrderL(*iGroupViewOne);
			NextTest();
			}
			break;
		case ECreateGroupOneViewByName:
			{
			iLog.LogLine(_L("=== Create GroupOneView By Name"));
			iGroupViewOneByName=CContactGroupView::NewL(iDb,*iLocalView,*this,KGroupOneName,CContactGroupView::EShowContactsInGroup);
			}
			break;
		case ETestGroupOneViewByName:
			{
			iLog.LogLine(_L("==== Exercise ETestGroupOneView By Name"));
			TInt groupCount = iGroupOne->ItemsContained()->Count();
			test(iGroupViewOneByName->CountL()==groupCount);
			const CContactIdArray* array= iGroupOne->ItemsContained();
			for (TInt ii=0;ii<groupCount;ii++)
				{
				test(iGroupViewOneByName->FindL((*array)[ii])!=KErrNotFound);
				}
			TestGroupViewSortOrderL(*iGroupViewOneByName);
			NextTest();
			break;
			}
		case ECreateGroupOneViewNotInGroup:
			{
			iLog.LogLine(_L("=== Create GroupOneViewNotInGroup By Name"));
			iGroupViewOneNotInGroup=CContactGroupView::NewL(iDb,*iLocalView,*this,KGroupOneName,CContactGroupView::EShowContactsNotInGroup);
			}
			break;
		case ETestGroupOneViewNotInGroup:
			{
			iLog.LogLine(_L("==== Exercise GroupOneViewNotInGroup By Name"));
			TInt totalContacts = iLocalView->CountL();
			TInt totalNotInGroup =  totalContacts - KNumContactsInGroupOne;
			test(iGroupViewOneNotInGroup->CountL()==totalNotInGroup);
			const CContactIdArray* array= iGroupOne->ItemsContained();
			TInt groupCount = array->Count();
			for (TInt ii=0;ii<groupCount;ii++)
				{
				test(iGroupViewOneNotInGroup->FindL((*array)[ii])==KErrNotFound);
				}
			TestGroupViewSortOrderL(*iGroupViewOneNotInGroup);
			NextTest();
			break;
			}
		case EAllViewsOutOfBoundsAccess:
			{
			//Views depend on their underlying views being in a good state, however
			//as some base views are potentially in other processes they must be resistant
			//to out of date views accessesing out of bound members, views, should not
			//panic but should leave with KErrNotFound;
			//local view
			TInt err=0;
			iLog.LogLine(_L("=== Test views for out of bounds access"));
			TInt outCount = iGroupViewOneByName->CountL();
			TRAP(err,iGroupViewOneByName->AtL(outCount));
			test(err==KErrNotFound);
			TRAP(err,iGroupViewOneByName->ContactAtL(outCount));
			test(err==KErrNotFound);
			NextTest();
			}
			break;
		case ECreateUnfiledGroupView:
			{
			iLog.LogLine(_L("=== Create Unfiled group view"));
			iGroupViewUnfiled=CContactGroupView::NewL(iDb,*iLocalView,*this,KNullContactId,CContactGroupView::EShowContactsNotInAnyGroup);
			}
			break;
		case ETestUnfiledGroupView:
			{
			iLog.LogLine(_L("==== Exercise Unfiled group"));
			const TInt totalContacts = iLocalView->CountL();
			const TInt totalUnfiled =  totalContacts - KNumContactsInGroupOne - KNumGroups;
			test(iGroupViewUnfiled->CountL()==totalUnfiled);			
			test(iGroupViewUnfiled->FindL(iGroupOneId));
			TestGroupViewSortOrderL(*iGroupViewUnfiled);

			CRandomContactGenerator* generator = CRandomContactGenerator::NewL();
			CleanupStack::PushL(generator);
			generator->SetDbL(iDb);
			generator->AddTypicalRandomContactL();
			CleanupStack::PopAndDestroy(generator);
			iNumNotificationExpected=5;
			}
			break;
		case ETestUnfiledGroupAddition:
			{
			iLog.LogLine(_L("==== Exercise Unfiled group addition"));
			TInt revisedCount = iGroupViewUnfiled->CountL();
			CContactIdArray* unfiled = iDb.UnfiledContactsL();
			test(revisedCount == unfiled->Count());
			delete unfiled;
			ExceriseViewL(*iGroupViewUnfiled);
			// Test that adding contact which currently forms part of
			// iGroupViewUnfiled to iGroupOne causes update of
			// iGroupViewUnfiled such that the contact no longer forms
			// part of iGroupViewUnfiled (i.e. by adding the contact to the
			// group it is no longer unfiled and should not appear in the
			// unfiled view).  The update to iGroupViewUnfiled will not take
			// place until the view receives the change event so wait until the
			// view observer method HandleContactViewEvent() is called before
			// testing that the expected change to iGroupViewUnfiled has taken
			// place.
			iDb.AddContactToGroupL(KNumContacts,iGroupOne->Id());
			// Expect (ESortOrderChanged x 4) + EGroupChanged + (EItemRemoved x
			// 4) + (EItemAdded x 4).
			iNumNotificationExpected=13;
			}
			break;
		case ENumTests:
			iLog.LogLine(_L("==== Group View Tests Finished, All Passed...\n"));
			CActiveScheduler::Stop();
			delete this;
			break;
		default:
			ASSERT(EFalse);
			break;
		}   
	}       
Ejemplo n.º 23
0
/**
	Try to match the phone number given with existing numbers in the database.
*/
void CCrudOperations::MatchContactsByEmailAndSipL()
{
    _LIT(KPass, "Pass");
    _LIT(KFail, "Fail");
    _LIT(KEmailMatchOutputFormat1,"Number of email addresses matched: %d -- %s\n");
    _LIT(KEmailMatchOutputFormat2,"Email address lookup took: %d s %03d\n");
    _LIT(KMatchOutputFormat3, "The contact's first name: %S\n");

    // Test Email address matching

    // this address belongs to the 1000th contact item in the database, which has a photo.
    _LIT(KEmailAddressToFind, "*****@*****.**");
    _LIT(KEmailTestTitle, "\nBeginning Email Address Match testing...\n");

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

    // Search the database...
    CContactItemFieldDef* fieldsToSearch = new (ELeave) CContactItemFieldDef();
    CleanupStack::PushL(fieldsToSearch);
    fieldsToSearch->AppendL(KUidContactFieldEMail);
    CContactIdArray* idArray = iDb->FindLC(KEmailAddressToFind, fieldsToSearch);
    TInt numMatches = idArray->Count();
    iTest->Printf(KEmailMatchOutputFormat1, numMatches, numMatches ? KPass().Ptr() : KFail().Ptr());

    if (numMatches)
    {
        //fetch first contact item in array
        CContactItem* item = iDb->ReadContactLC((*idArray)[0]);
        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);
    }

    timer.StopTimer();
    CleanupStack::PopAndDestroy(2, fieldsToSearch); // and idArray


    TInt result = timer.Result();
    TBuf<64> formattable;
    formattable.Format(KEmailMatchOutputFormat2, result / 1000000, (result / 1000) % 1000);
    iTest->Printf(formattable);

    // reset variables
    fieldsToSearch = NULL;
    idArray = NULL;
    numMatches = 0;
    timer.ResetTimer();
    result = 0;
    formattable.Zero();


    // Test SIP address matching

    // this address belongs to the 1000th contact item in the database, which has a photo.
    _LIT(KSipAddressToFind, "sip:[email protected]");
    _LIT(KSipTestTitle, "\nBeginning SIP Address Match testing...\n");
    _LIT(KSipMatchOutputFormat1,"Number of SIP addresses matched: %d -- %s\n");
    _LIT(KSipMatchOutputFormat2,"SIP address lookup took: %d s %03d\n");

    iTest->Printf(KSipTestTitle);
    timer.StartTimer();

    // Search the database...
    fieldsToSearch = new (ELeave) CContactItemFieldDef();
    CleanupStack::PushL(fieldsToSearch);
    fieldsToSearch->AppendL(KUidContactFieldSIPID);
    idArray = iDb->FindLC(KSipAddressToFind, fieldsToSearch);
    numMatches = idArray->Count();
    iTest->Printf(KSipMatchOutputFormat1, numMatches, numMatches ? KPass().Ptr() : KFail().Ptr());

    if (numMatches)
    {
        //fetch first contact item in array
        CContactItem* item = iDb->ReadContactLC((*idArray)[0]);
        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);
    }

    timer.StopTimer();
    CleanupStack::PopAndDestroy(2, fieldsToSearch); // and idArray

    result = timer.Result();
    formattable.Format(KSipMatchOutputFormat2, result / 1000000, (result / 1000) % 1000);
    iTest->Printf(formattable);
}