void CSqlSearcher::DoSearchL(const TDesC& aString, TUid aFieldId)
	{
    CContactItemFieldDef* fieldsToSearch = new (ELeave) CContactItemFieldDef;
    CleanupStack::PushL(fieldsToSearch);

    fieldsToSearch->AppendL(aFieldId);

    CIdleFinder* idleFinder = iDb->FindAsyncL(aString, fieldsToSearch, this);
    CleanupStack::PushL(idleFinder);

    CActiveScheduler::Start();

	CleanupStack::PopAndDestroy(idleFinder);

    CleanupStack::PopAndDestroy(fieldsToSearch);
	}
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);
	 }
Exemple #3
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);
}