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); }
/** Testcode for Graham's new API These all match 1234567: *#42# 0401234567 p123 *#42# +358401234567 p123 *61 0401234567 *61 +358401234567 +358401234567 +3 +358401234567 p123 */ LOCAL_C void TestNewMatchingL() { ResetDatabaseL(); const TInt KLastThreeDigits =3; //These numbers match 1234567 _LIT(KCntDTMFNumber1,"*#42# 0401234567 p123"); _LIT(KCntDTMFNumber2,"*#42#+358401234567 p123"); _LIT(KCntDTMFNumber3,"*61 0401234567"); _LIT(KCntDTMFNumber4,"*61 +358401234567"); _LIT(KCntDTMFNumber5,"+358401234567 +3"); _LIT(KCntDTMFNumber6,"+358401234567 p123"); _LIT(KCntMatch1to7ExtraCharacters,"mobile 12 345-67"); _LIT(KCntMatch1to7Brackets,"(020) 0123-4567"); _LIT(KCntMatch1to7TooManyNumbers,"123456789012345678901234567"); //These shouldn't match 1234567 _LIT(KCntDTMFNumber7,"*#42# 0401234567#p123");//empty _LIT(KCntDTMFNumber8,"*12345+0401234567"); //matches 12345 _LIT(KCntDTMFNumber9,"*+123+456+++++++++++"); //matches 123 //Graham's possible defects _LIT(KCntPossibleDefect,"70000"); _LIT(KCntZeroAtEnd,"020 5632700"); //Match numbers _LIT(KCntMatch1to7,"1234567"); _LIT(KCntMatch1to3,"123"); _LIT(KCntMatch700,"700"); //Spaces at the start _LIT(KCntSpaceInNumber," 0 2 0 7 1 2 0 5 6 7 8 "); _LIT(KCntSpaceMatch,"02071205678"); _LIT(KCntSpaceInNumberIntl," +44 7447 065 472"); _LIT(KCntSpaceInNumberIntlMatch,"+446447065472"); _LIT(KCntSpaceWorstCase," "); _LIT(KCntNoRealDigitsInNumber,"Lycos SMS"); _LIT(KCntShortNumber1,"789"); _LIT(KCntShortNumber2,"456"); _LIT(KCntEndingByShortNumber1,"+44(0)32465764789"); _LIT(KCntEndingByShortNumber2,"+443216568731456"); _LIT(KCntMatchShortNumber1,"789"); // must not match other number ending with 789 _LIT(KCntMatchShortNumber2,"456"); // must not match other number ending with 456 CreateContactL(KCntName,KCntSurname,KCntShortNumber1,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntShortNumber2,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntEndingByShortNumber1,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntEndingByShortNumber2,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber1,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber2,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber3,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber4,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber5,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber6,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber7,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber8,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntDTMFNumber9,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntPossibleDefect,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntMatch1to7ExtraCharacters,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntMatch1to7Brackets,KNullDesC); CreateContactL(KCntName,KCntSurname,KCntMatch1to7TooManyNumbers,KNullDesC); TContactItemId id = CreateContactL(KCntName,KCntSurname,KCntZeroAtEnd,KNullDesC); CheckPhoneMatchL(KCntMatch1to7,KMatch7Digits,9); CheckPhoneMatchL(KCntMatch1to7,KLastThreeDigits,9); // no contact with 567 as phone number CheckPhoneMatchL(KCntMatch1to7,KMatch7Digits,9); CheckPhoneMatchL(KCntMatch1to7,KLastThreeDigits,9); // no contact with 567 as phone number CheckPhoneMatchL(KCntMatch1to3,KMatch7Digits,1); CheckPhoneMatchL(KCntMatch1to3,KMatch7Digits,1); CheckPhoneMatchL(KCntPossibleDefect,KMatch7Digits,1); CheckPhoneMatchL(KCntZeroAtEnd,KMatch7Digits,1); CheckPhoneMatchL(KCntMatch700,KLastThreeDigits,0); // no contact with 700 as phone number at this point CheckPhoneMatchL(KCntZeroAtEnd,KMatch7Digits,1); CheckPhoneMatchL(KCntNoRealDigitsInNumber,KMatch7Digits,0); CheckPhoneMatchL(KCntMatchShortNumber1,KLastThreeDigits,1); // CheckPhoneMatchL(KCntMatchShortNumber2,KLastThreeDigits,1); // // Simulate a synchronisation (increment the access count) CContactItem* item = CntTest->Db()->OpenContactLX(id); item->IncAccessCount(); CntTest->Db()->CommitContactL(*item); CleanupStack::PopAndDestroy(); //lock record delete item; // Delete the contact and verify that it has been removed from the phone match table CntTest->Db()->DeleteContactL(id); CheckPhoneMatchL(KCntZeroAtEnd,KMatch7Digits,0); CreateContactL(KCntName,KCntSurname,KCntSpaceInNumber,KNullDesC); CheckPhoneMatchL(KCntSpaceMatch,KMatch7Digits,1); CreateContactL(KCntName,KCntSurname,KCntSpaceInNumberIntl,KNullDesC); CheckPhoneMatchL(KCntSpaceInNumberIntlMatch,KMatch7Digits,1); CreateContactL(KCntName,KCntSurname,KCntSpaceWorstCase,KNullDesC); }