示例#1
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);
}
/**
	Main test routine.  Calls and times CContactDatabase::DeleteContactsL
*/
void CDeleteMany::DelDataL(TInt aEntryCount, TInt aNumEntriesInDb, TInt aNumMsToGet20ItemsFromView)
	{
	TInt dbSizeBefore = iDb->FileSize();
	
	CContactIdArray* idArray = CContactIdArray::NewLC();
	
	// create an array of random, non-repeating contact ids
	CreateRandomIdArrayL(*idArray, aEntryCount, aNumEntriesInDb);	

	TCntPerfTimer timer;
	timer.StartTimer();
	iDb->DeleteContactsL(*idArray);
	timer.StopTimer();

	CleanupStack::PopAndDestroy(); // idArray
	
	const TInt KTransactionSize(50); // num records deleted in a transaction

 	// add in number of screen updates need in UI: (time to fetch 20 view items) * number of transactions
 	TInt result = timer.Result() +
 		(aNumMsToGet20ItemsFromView * ( (aEntryCount / KTransactionSize) + (aEntryCount % 20 ? 1 : 0) ) );


	TBuf<64> formattable;
	formattable.Format(KOutputFormat, aEntryCount, aNumEntriesInDb, result / 1000000, (result / 1000) % 1000);
	iTest->Printf(formattable);
    formattable.Format(KOutputFormat2, dbSizeBefore, iDb->FileSize());
	iTest->Printf(formattable);
	}
示例#3
0
/**
	Perform CRUD operations with 1 item in the database.
*/
void CCrudOperations::DoCrudTestsL()
{
    // chosen because they have a photo field
    const TContactItemId K901stContactItemId(901);
    const TContactItemId K973rdContactItemId(973);
    const TContactItemId K926thContactItemId(926);

    _LIT(KCRUDTestTitle, "\nBeginning CRUD Operations on 1 Contact (with photo) testing ...\n");
    _LIT(KCRUDTestNote, "[Figures for each write operation include time to fetch first 20 items in view.]\n");
    iTest->Printf(KCRUDTestTitle);
    iTest->Printf(KCRUDTestNote);

    TCntPerfTimer timer;

    // fetch a contact item to seed a new one
    CContactItem* temp = iDb->OpenContactL(K901stContactItemId);
    CleanupStack::PushL(temp);
    CContactItem* item = CContactCard::NewL(temp);
    CleanupStack::PopAndDestroy(temp);
    CleanupStack::PushL(item);

    // Create (add) a contact with a photo
    timer.StartTimer();
    iDb->AddNewContactL(*item);
    timer.StopTimer();
    TInt createResult = timer.Result() + iNumMsToGet20ItemsFromView; // add the time to fetch 20 items from view.
    timer.ResetTimer();
    CleanupStack::PopAndDestroy(item);
    item = NULL;

    // Read a contact with a photo
    timer.StartTimer();
    item = iDb->OpenContactLX(K973rdContactItemId); // lock object put on the CleanupStack
    CleanupStack::PushL(item);
    timer.StopTimer();
    TInt readResult = timer.Result();
    timer.ResetTimer();

    // Update the contact in the database
    timer.StartTimer();
    iDb->CommitContactL(*item);
    timer.StopTimer();
    TInt updateResult = timer.Result() + iNumMsToGet20ItemsFromView; // add the time to fetch 20 items from view.
    timer.ResetTimer();
    CleanupStack::PopAndDestroy(item);
    item = NULL;
    CleanupStack::PopAndDestroy(); // lock object

    // Delete a contact with a photo
    timer.StartTimer();
    iDb->DeleteContactL(K926thContactItemId);
    timer.StopTimer();
    TInt deleteResult = timer.Result() + iNumMsToGet20ItemsFromView; // add the time to fetch 20 items from view.
    timer.ResetTimer();

    // output timing result
    _LIT(KCreateOutputFormat,"Creating (adding) 1 contact took: %d s %03d\n");
    iTest->Printf(KCreateOutputFormat, createResult / 1000000, (createResult / 1000) % 1000);

    _LIT(KReadOutputFormat,"Reading 1 contact took: %d s %03d\n");
    iTest->Printf(KReadOutputFormat, readResult / 1000000, (readResult / 1000) % 1000);

    _LIT(KUpdateOutputFormat,"Updating 1 contact took: %d s %03d\n");
    iTest->Printf(KUpdateOutputFormat, updateResult / 1000000, (updateResult / 1000) % 1000);

    _LIT(KDeleteOutputFormat,"Deleting 1 contact took: %d s %03d\n");
    iTest->Printf(KDeleteOutputFormat, deleteResult / 1000000, (deleteResult / 1000) % 1000);
}
示例#4
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);
}