diff options
author | prashanth grandhi <prashanth.2.grandhi@nokia.com> | 2010-08-31 16:27:02 +0300 |
---|---|---|
committer | prashanth grandhi <prashanth.2.grandhi@nokia.com> | 2010-08-31 16:27:02 +0300 |
commit | ceee8875686b77535b357eca44cffb7da9121843 (patch) | |
tree | 6591d13170aceeba7a41f4f7e3fc5c51853d15dd | |
parent | d047056878b5e3db36f2c5179a3d42dde57bd861 (diff) |
Updated best matching phonenumbers in symbian backend
6 files changed, 732 insertions, 357 deletions
diff --git a/plugins/contacts/symbian/plugin/inc/filtering/cntfilterdetail.h b/plugins/contacts/symbian/plugin/inc/filtering/cntfilterdetail.h index 5c2f91a719..72fed619aa 100644 --- a/plugins/contacts/symbian/plugin/inc/filtering/cntfilterdetail.h +++ b/plugins/contacts/symbian/plugin/inc/filtering/cntfilterdetail.h @@ -50,8 +50,6 @@ QTM_USE_NAMESPACE -enum TNumberType { ENotInitialized, EUnknown, EDigit, EPlus, EOneZero, ETwoZeros }; - class CntFilterDetail : public CntAbstractContactFilter { private: @@ -65,10 +63,6 @@ private: static void stripOutNonDigitChars(TDes& text); static TInt32 padOutPhoneMatchNumber(TInt32& phoneNumber, TInt padOutLength); - static TBool validateBestMatchingRulesL(const TDesC& phoneNumber, const TDesC& matchNumber); - static TBool checkBestMatchingRules(const TDesC& numberA, TNumberType numberAType, - const TDesC& numberB, TNumberType numberBType); - static TInt formatAndCheckNumberType(TDes& number); public: TInt32 iLowerSevenDigits; TInt32 iUpperDigits; @@ -95,6 +89,10 @@ public: void createMatchPhoneNumberQuery(const QContactFilter& filter, QString& sqlQuery, QContactManager::Error* error); + void bestMatchPhoneNumberQuery(const QContactFilter& filter, + QString& sqlQuery, + QContactManager::Error* error); + bool bestMatchingEnabled(); #ifdef PBK_UNIT_TEST void emulateBestMatching(); #endif //PBK_UNIT_TEST @@ -115,11 +113,6 @@ private: TInt upperMatchLength, QContactManager::Error* error); bool getMatchLengthL(TInt& matchLength); - bool bestMatchingEnabled(); - QList<QContactLocalId> getBestMatchPhoneNumbersL(const QString number, - const QList<QContactLocalId>& idList, - QContactManager::Error* error); - protected: CContactDatabase& m_contactdatabase; diff --git a/plugins/contacts/symbian/plugin/src/filtering/cntfilterdetail.cpp b/plugins/contacts/symbian/plugin/src/filtering/cntfilterdetail.cpp index 5c23b6ee80..c17c34f8f8 100644 --- a/plugins/contacts/symbian/plugin/src/filtering/cntfilterdetail.cpp +++ b/plugins/contacts/symbian/plugin/src/filtering/cntfilterdetail.cpp @@ -88,7 +88,12 @@ QList<QContactLocalId> CntFilterDetail::contacts( if ( (detailFilter.detailDefinitionName() == QContactPhoneNumber::DefinitionName ) && (detailFilter.detailFieldName() != QContactPhoneNumber::FieldSubTypes)) { //Handle phonenumber ... - createMatchPhoneNumberQuery(filter,sqlQuery,error); + if(bestMatchingEnabled()) { + bestMatchPhoneNumberQuery(filter,sqlQuery,error); + } + else { + createMatchPhoneNumberQuery(filter,sqlQuery,error); + } if (*error == QContactManager::NoError) { //fetch the contacts idList = m_srvConnection.searchContacts(sqlQuery,error); @@ -386,6 +391,7 @@ void CntFilterDetail::createMatchPhoneNumberQuery( } else { *error = QContactManager::UnspecifiedError; + return; } } // Recreate query to fetch all match ids @@ -397,34 +403,96 @@ void CntFilterDetail::createMatchPhoneNumberQuery( sqlQuery += ids; sqlQuery += ')'; } - - // refine search - if (bestMatchingEnabled()) { - QList<QContactLocalId> list = m_srvConnection.searchContacts(sqlQuery,error); - QList<QContactLocalId> bestMatchingIds; - if (*error == QContactManager::NoError) { - TRAP_IGNORE( - bestMatchingIds = getBestMatchPhoneNumbersL(number, list, error); - ) - if (bestMatchingIds.count()>0) { - // recreate query - QString selectQuery = " SELECT contact_id FROM comm_addr WHERE contact_id in ("; - QString ids = QString("%1").arg(bestMatchingIds.at(0)); - for(int i=1; i<bestMatchingIds.count(); ++i) { - ids += QString(" ,%1").arg(bestMatchingIds.at(i)); + } +} + +/* + * Returns an sql query to fetch 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 createMatchPhoneNumberQuery 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 length of shorter number. + */ +void CntFilterDetail::bestMatchPhoneNumberQuery(const QContactFilter& filter, + QString& sqlQuery, + QContactManager::Error* error) + { + if (!filterSupported(filter) ) { + *error = QContactManager::NotSupportedError; + return; + } + + QContactDetailFilter detailFilter(filter); + QString number((detailFilter.value()).toString()); + TPtrC numberPtr(reinterpret_cast<const TUint16*>(number.utf16())); + + const TInt KUpperMaxLength = KMaxPhoneMatchLength - KLowerSevenDigits; + TMatch phoneDigits = createPaddedPhoneDigits(numberPtr, KLowerSevenDigits, KUpperMaxLength, error); + + if (*error == QContactManager::NoError) { + // select fields for contacts that match phone lookup + // SELECT contact_id, extra_value FROM comm_addr + // WHERE value = [value string] AND type = [type value]; + // + QString type = QString(" type = %1").arg(CntDbInfo::EPhoneNumber); + QString value = QString(" value = %1").arg(phoneDigits.iLowerSevenDigits); + QString whereClause = " WHERE" + value + " AND" + type; + sqlQuery = "SELECT contact_id, extra_value FROM comm_addr" + whereClause; + + QList<QPair<QContactLocalId, QString> > contactMatches = m_srvConnection.searchPhoneNumbers(sqlQuery, error); + + // Check if search query was successful + if (*error != QContactManager::NoError) { + return; + } + + QStringList list; + for (int i=0; i<contactMatches.count(); ++i) { + // Check the upper digits... + TInt32 number = phoneDigits.iUpperDigits; + QString extraValue = contactMatches.at(i).second; + TPtrC extValString(reinterpret_cast<const TUint16*>(extraValue.utf16())); + + TInt32 storedUpperDigits(0); + if (TLex(extValString).Val(storedUpperDigits) == KErrNone) { + + 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; } - selectQuery += ids + ')'; - sqlQuery = selectQuery; + number /= 10; + stored /= 10; } - else { - // empty list - QString selectQuery = " SELECT contact_id FROM comm_addr WHERE contact_id in (null)"; - sqlQuery = selectQuery; + + if ((phoneDigits.iUpperDigits == 0) || (storedUpperDigits == 0) || + (number == stored)) { + list.append(QString("%1").arg(contactMatches.at(i).first)); } } + else { + *error = QContactManager::UnspecifiedError; + return; + } + } + // Recreate query to fetch all match ids + // SELECT DISTINCT contact_id FROM contact WHERE contact_id in ( + // .. + // ) + QString ids = list.join(" ,"); + sqlQuery = "SELECT DISTINCT contact_id FROM contact WHERE contact_id in ("; + sqlQuery += ids; + sqlQuery += ')'; } } -} #ifdef PBK_UNIT_TEST void CntFilterDetail::emulateBestMatching() @@ -560,49 +628,6 @@ CntFilterDetail::TMatch CntFilterDetail::createPhoneMatchNumber( return phoneNumber; } -QList<QContactLocalId> CntFilterDetail::getBestMatchPhoneNumbersL( - const QString number, - const QList<QContactLocalId>& idList, - QContactManager::Error* error) - -{ - TPtrC numberPtr(reinterpret_cast<const TUint16*>(number.utf16())); - RBuf matchNumber; - matchNumber.CleanupClosePushL(); - matchNumber.CreateL(numberPtr); - - QList<QContactLocalId> bestMatchingIds; - for (int i=0; i<idList.count(); i++) { - QContact contact = m_dbInfo.engine()->contact(idList.at(i), QContactFetchHint(), error); - QList<QContactPhoneNumber> details = contact.details<QContactPhoneNumber>(); - CntTransformContactData* transformPhoneNumber = new CntTransformPhoneNumber(); - - bool matchFound(false); - for (int j = 0;j < details.count(); j++) { - QList<CContactItemField *> fields = transformPhoneNumber->transformDetailL(details.at(j)); - for (int k = 0;k < details.count() && !matchFound; k++) { - CContactTextField* storage = fields.at(k)->TextStorage(); - RBuf phoneNumber; - phoneNumber.CleanupClosePushL(); - phoneNumber.CreateL(storage->Text()); - if (TMatch::validateBestMatchingRulesL(phoneNumber,matchNumber)) { - matchFound = true; - } - // phoneNumber - CleanupStack::PopAndDestroy(); - } - if (matchFound) { - bestMatchingIds.append(idList.at(i)); - break; - } - } - delete transformPhoneNumber; - } - // matchNumber - CleanupStack::PopAndDestroy(); - return bestMatchingIds; -} - //CntFilterDetail::TMatch constructor. CntFilterDetail::TMatch::TMatch() : @@ -672,191 +697,3 @@ TInt32 CntFilterDetail::TMatch::padOutPhoneMatchNumber(TInt32& phoneNumber, phoneNumber = result; return result; } - -// Removes non-digit chars except plus form the beginning -// Checks if number matches to one of defined types -// -TInt CntFilterDetail::TMatch::formatAndCheckNumberType(TDes& number) - { - _LIT( KOneZeroPattern, "0*" ); - _LIT( KTwoZerosPattern, "00*" ); - _LIT( KPlusPattern, "+*" ); - const TChar KPlus = TChar('+'); - const TChar KZero = TChar('0'); - const TChar KAsterisk = TChar('*'); - const TChar KHash = TChar('#'); - - for( TInt pos = 0; pos < number.Length(); ++pos ) { - TChar chr = number[pos]; - if ( !chr.IsDigit() && !( pos == 0 && chr == KPlus ) - && !( chr == KAsterisk ) && !( chr == KHash ) ) { - number.Delete( pos, 1 ); - --pos; - } - } - - TInt format; - - if (!number.Match(KTwoZerosPattern) && number.Length() > 2 && number[2] != KZero) { - format = ETwoZeros; - } - else if (!number.Match(KOneZeroPattern)&& number.Length() > 1 && number[1] != KZero) { - format = EOneZero; - } - else if (!number.Match(KPlusPattern) && number.Length() > 1 && number[1] != KZero) { - format = EPlus; - } - else if (number.Length() > 0 && number[0] != KZero && ( ( TChar ) number[0] ).IsDigit()) { - format = EDigit; - } - else { - format = EUnknown; - } - - return format; - } - -TBool CntFilterDetail::TMatch::validateBestMatchingRulesL(const TDesC& phoneNumber, const TDesC& matchNumber) - { - RBuf numberA; - numberA.CleanupClosePushL(); - numberA.CreateL(matchNumber); - TNumberType numberAType = (TNumberType) TMatch::formatAndCheckNumberType(numberA); - - RBuf numberB; - numberB.CleanupClosePushL(); - numberB.CreateL(phoneNumber); - TNumberType numberBType = (TNumberType) TMatch::formatAndCheckNumberType(numberB); - - TBool match = (!numberB.Compare(numberA) || - TMatch::checkBestMatchingRules(numberA, numberAType, numberB, numberBType) || - TMatch::checkBestMatchingRules(numberB, numberBType, numberA, numberAType)); - - // cleanup - CleanupStack::PopAndDestroy(2); - return match; - } - -TBool CntFilterDetail::TMatch::checkBestMatchingRules( - const TDesC& numberA, TNumberType numberAType, - const TDesC& numberB, TNumberType numberBType ) - { - TBool result = EFalse; - - // Rules for matching not identical numbers - // Rules details are presented in Best_Number_Matching_Algorithm_Description.doc - - // rule International-International 1 - if (!result && numberAType == EPlus && numberBType == ETwoZeros) { - TPtrC numberAPtr = numberA.Right(numberA.Length() - 1); - TPtrC numberBPtr = numberB.Right(numberB.Length() - 2); - result = !(numberAPtr.Compare(numberBPtr)); - if (result) { - return result; - } - } - - // rule International-International 2 - if (numberAType == EPlus && numberBType == EDigit) { - TPtrC numberAPtr = numberA.Right( numberA.Length() - 1 ); - if (numberAPtr.Length() < numberB.Length()) { - TPtrC numberBPtr = numberB.Right( numberAPtr.Length() ); - result = !(numberAPtr.Compare(numberBPtr)); - if (result) { - return result; - } - } - } - - // rule International-International 3 - if (numberAType == ETwoZeros && numberBType == EDigit) { - TPtrC numberAPtr = numberA.Right(numberA.Length() - 2); - if (numberAPtr.Length() < numberB.Length()) { - TPtrC numberBPtr = numberB.Right(numberAPtr.Length()); - result = !(numberAPtr.Compare(numberBPtr)); - if (result) { - return result; - } - } - } - - // rule International-Operator 1 - if (numberAType == EOneZero && numberBType == EPlus - || numberAType == EDigit && numberBType == EPlus) { - TPtrC numberAPtr; - if (numberAType == EOneZero) { - numberAPtr.Set(numberA.Right(numberA.Length() - 1)); - } - else { - numberAPtr.Set(numberA); - } - if (numberAPtr.Length() < numberB.Length() - 1) { - TPtrC numberBPtr = numberB.Right(numberAPtr.Length()); - result = !(numberAPtr.Compare(numberBPtr)); - if (result) { - return result; - } - } - } - - // rule International-Operator 2 - if (numberAType == EOneZero && numberBType == ETwoZeros - || numberAType == EDigit && numberBType == ETwoZeros) { - TPtrC numberAPtr; - if (numberAType == EOneZero) { - numberAPtr.Set(numberA.Right(numberA.Length() - 1)); - } - else { - numberAPtr.Set(numberA); - } - if (numberAPtr.Length() < numberB.Length() - 2) { - TPtrC numberBPtr = numberB.Right(numberAPtr.Length()); - result = !(numberAPtr.Compare(numberBPtr)); - if (result) { - return result; - } - } - } - - // rule International-Operator 3 - if (numberAType == EOneZero && numberBType == EDigit - || numberAType == EDigit && numberBType == EDigit) { - TPtrC numberAPtr; - if (numberAType == EOneZero) { - numberAPtr.Set(numberA.Right( numberA.Length() - 1)); - } - else { - numberAPtr.Set(numberA); - } - if (numberAPtr.Length() < numberB.Length()) { - TPtrC numberBPtr = numberB.Right(numberAPtr.Length()); - result = !(numberAPtr.Compare(numberBPtr)); - if (result) { - return result; - } - } - } - - // rule Operator-Operator 1 - if (numberAType == EOneZero && numberBType == EDigit) { - TPtrC numberAPtr = numberA.Right(numberA.Length() - 1); - result = !(numberAPtr.Compare(numberB)); - if (result) { - return result; - } - } - - // rule North America Numbering Plan 1 - if (numberAType == EDigit && numberBType == EPlus) { - TPtrC numberBPtr = numberB.Right(numberB.Length() - 1); - result = !(numberA.Compare(numberBPtr)); - if (result) { - return result; - } - } - - // More exceptional acceptance rules can be added here - // Keep rules updated in the document Best_Number_Matching_Algorithm_Description.doc - - return result; - } diff --git a/plugins/contacts/symbian/plugin/src/filtering/cntfilterintersection.cpp b/plugins/contacts/symbian/plugin/src/filtering/cntfilterintersection.cpp index 985642e306..b1238d6cbb 100644 --- a/plugins/contacts/symbian/plugin/src/filtering/cntfilterintersection.cpp +++ b/plugins/contacts/symbian/plugin/src/filtering/cntfilterintersection.cpp @@ -138,7 +138,10 @@ void CntFilterIntersection::getSelectQueryforFilter(const QContactFilter& filter dtlfltr.emulateBestMatching(); } #endif - dtlfltr.createMatchPhoneNumberQuery(filter,sqlSelectQuery,error); + if (dtlfltr.bestMatchingEnabled()) + dtlfltr.bestMatchPhoneNumberQuery(filter,sqlSelectQuery,error); + else + dtlfltr.createMatchPhoneNumberQuery(filter,sqlSelectQuery,error); } else { CntFilterDetail dtlfltr(m_contactdatabase,m_srvConnection,m_dbInfo); diff --git a/plugins/contacts/symbian/plugin/src/filtering/cntfilterunion.cpp b/plugins/contacts/symbian/plugin/src/filtering/cntfilterunion.cpp index 71e29729b9..a90433fa67 100644 --- a/plugins/contacts/symbian/plugin/src/filtering/cntfilterunion.cpp +++ b/plugins/contacts/symbian/plugin/src/filtering/cntfilterunion.cpp @@ -139,7 +139,10 @@ void CntFilterUnion::getSelectQueryforFilter(const QContactFilter& filter, dtlfltr.emulateBestMatching(); } #endif - dtlfltr.createMatchPhoneNumberQuery(filter,sqlSelectQuery,error); + if (dtlfltr.bestMatchingEnabled()) + dtlfltr.bestMatchPhoneNumberQuery(filter,sqlSelectQuery,error); + else + dtlfltr.createMatchPhoneNumberQuery(filter,sqlSelectQuery,error); } else { CntFilterDetail dtlfltr(m_contactdatabase,m_srvConnection,m_dbInfo); diff --git a/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.cpp b/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.cpp index ee25eb107a..8f36f98fb5 100644 --- a/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.cpp +++ b/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.cpp @@ -59,9 +59,9 @@ const TUid KCRUidTelConfiguration = {0x102828B8}; const TUint32 KTelMatchDigits = 0x00000001; const QString DB1_FIRSTNAME1 = "A"; -const QString DB1_LASTNAME1 = "9"; -const QString DB1_FIRSTNAME2 = "D"; -const QString DB1_LASTNAME2 = "6"; +const QString DB1_LASTNAME1 = "Jo"; +const QString DB1_FIRSTNAME2 = "Di"; +const QString DB1_LASTNAME2 = "Jo"; void TestMatchPhoneNumber::initTestCase() @@ -106,65 +106,197 @@ void TestMatchPhoneNumber::cleanupContactsDb() void TestMatchPhoneNumber::setupBestMatchingContactsDb1() { cleanupContactsDb(); - - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "00358401234561" ) ); - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "99533358401234562" ) ); - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "99533358401234563" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "+358401234564" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "00358401234565" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "99533358401234566" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "0561234567" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "0561234568" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "061234569" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "34567" ) ); QContactManager::Error err; QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); int j = cnt_ids.count(); - QVERIFY(9 == j); + QVERIFY(1 == j); } void TestMatchPhoneNumber::setupBestMatchingContactsDb2() { cleanupContactsDb(); - - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "+358401234561" ) ); - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "+358401234562" ) ); - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "00358401234563" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "0401234564" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "0401234565" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "0401234566" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "061234567" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "+8261234568" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "+82561234569" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "358401234567" ) ); QContactManager::Error err; QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); int j = cnt_ids.count(); - QVERIFY(9 == j); + QVERIFY(1 == j); } void TestMatchPhoneNumber::setupBestMatchingContactsDb3() { cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "3560 0123456" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb4() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "1234567" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb5() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "0000 0123456" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb6() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "020 7700 9001" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "20 7700 90012" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "020 7700 9081" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "120 7700 9081" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "9120 7700 9081" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(5 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb7() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "9999 9990 0999 999" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "9000 0000 0000 000" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "0000 0000 0000 000" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "0000 0000 0000 009" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "9 9000 000" ) ); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "9000 000" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(6 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb8() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "443049607" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb9() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "0443049607" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb10() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "358443049607" ) ); - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "1234561" ) ); - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "401234561" ) ); - addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "00358401234563" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "0401234564" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "+358401234565" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "16101234566" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "4567" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "1234567" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "221234567" ) ); + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb11() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "443049607" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "4566" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "*4566" ) ); - addContact( DB1_FIRSTNAME2, DB1_LASTNAME2, QString( "*55*0705#" ) ); + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb12() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "0443049607" ) ); QContactManager::Error err; QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); int j = cnt_ids.count(); - QVERIFY(12 == j); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb13() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "3049607" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb14() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "03049607" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb15() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "4443049607" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb16() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "584443049607" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); +} + +void TestMatchPhoneNumber::setupBestMatchingContactsDb17() +{ + cleanupContactsDb(); + addContact( DB1_FIRSTNAME1, DB1_LASTNAME1, QString( "401234567" ) ); + + QContactManager::Error err; + QList<QContactLocalId> cnt_ids = m_engine->contactIds(QContactFilter(),QList<QContactSortOrder>(), &err); + int j = cnt_ids.count(); + QVERIFY(1 == j); } void TestMatchPhoneNumber::addContact(QString firstname,QString lastname,QString phonenumber) @@ -191,14 +323,29 @@ void TestMatchPhoneNumber::addContact(QString firstname,QString lastname,QString void TestMatchPhoneNumber::testMatchPhoneNumber() { - testBestMatchingStrategy1(); - testBestMatchingStrategy2(); - testBestMatchingStrategy3(); + testBestMatching1(); + testBestMatching2(); + testBestMatching3(); + testBestMatching4(); + testBestMatching5(); + testBestMatching6(); + testBestMatching7(); + testBestMatching8(); + testBestMatching9(); + testBestMatching10(); + testBestMatching11(); + testBestMatching12(); + testBestMatching13(); + testBestMatching14(); + testBestMatching15(); + testBestMatching16(); + testBestMatching17(); + testBestMatchingWithUnionFilter(); testBestMatchingWithIntersectionFilter(); } -void TestMatchPhoneNumber::testBestMatchingStrategy1() +void TestMatchPhoneNumber::testBestMatching1() { setupBestMatchingContactsDb1(); @@ -221,18 +368,37 @@ void TestMatchPhoneNumber::testBestMatchingStrategy1() cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =1; + expectedCount =0; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("+358401234562"); + detailFilter.setValue("34567"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching2() +{ + setupBestMatchingContactsDb2(); - detailFilter.setValue("00358401234563"); + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("358401234567"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -240,7 +406,34 @@ void TestMatchPhoneNumber::testBestMatchingStrategy1() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("0401234564"); + detailFilter.setValue("34567"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =0; + QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching3() +{ + setupBestMatchingContactsDb3(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("0000 0123456"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -248,15 +441,34 @@ void TestMatchPhoneNumber::testBestMatchingStrategy1() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("0401234565"); + detailFilter.setValue("123456"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching4() +{ + setupBestMatchingContactsDb4(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); - detailFilter.setValue("0401234566"); + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("358401234567"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -264,33 +476,60 @@ void TestMatchPhoneNumber::testBestMatchingStrategy1() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("061234567"); + detailFilter.setValue("34567"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =0; QVERIFY(expectedCount == seachedcontactcount); +} +void TestMatchPhoneNumber::testBestMatching5() +{ + setupBestMatchingContactsDb5(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; - detailFilter.setValue("+8261234568"); + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("0123456"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =0; + expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("+82561234569"); + detailFilter.setValue("123456"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); + + detailFilter.setValue("3456"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =0; + QVERIFY(expectedCount == seachedcontactcount); } -void TestMatchPhoneNumber::testBestMatchingStrategy2() + +void TestMatchPhoneNumber::testBestMatching6() { - setupBestMatchingContactsDb2(); + setupBestMatchingContactsDb6(); CntSymbianSrvConnection srvConnection(m_engine); CntDbInfo dbInfo(m_engine); @@ -306,7 +545,7 @@ void TestMatchPhoneNumber::testBestMatchingStrategy2() CntFilterDetail filter(*m_database,srvConnection,dbInfo); filter.emulateBestMatching(); - detailFilter.setValue("00358401234561"); + detailFilter.setValue("020 7700 9001"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -314,7 +553,7 @@ void TestMatchPhoneNumber::testBestMatchingStrategy2() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("99533358401234562"); + detailFilter.setValue("20 7700 90012"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -322,23 +561,65 @@ void TestMatchPhoneNumber::testBestMatchingStrategy2() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("99533358401234563"); + detailFilter.setValue("020 7700 9081"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =1; + expectedCount =3; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("+358401234564"); + detailFilter.setValue("120 7700 9081"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =1; + expectedCount =3; + QVERIFY(expectedCount == seachedcontactcount); + + detailFilter.setValue("9120 7700 9081"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =3; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("00358401234565"); + detailFilter.setValue("20 7700 9081"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =3; + QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching7() +{ + setupBestMatchingContactsDb7(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("9999 9990 0999 999"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =1; + QVERIFY(expectedCount == seachedcontactcount); + detailFilter.setValue("9999 9990 0999 999"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -346,7 +627,23 @@ void TestMatchPhoneNumber::testBestMatchingStrategy2() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("99533358401234566"); + detailFilter.setValue("9000 0000 0000 000"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =2; + QVERIFY(expectedCount == seachedcontactcount); + + detailFilter.setValue("0000 0000 0000 000"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =2; + QVERIFY(expectedCount == seachedcontactcount); + + detailFilter.setValue("0000 0000 0000 009"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -354,23 +651,50 @@ void TestMatchPhoneNumber::testBestMatchingStrategy2() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("0561234567"); + detailFilter.setValue("9 9000 000"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =0; + expectedCount =2; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("0561234568"); + detailFilter.setValue("9000 000"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =0; + expectedCount =2; + QVERIFY(expectedCount == seachedcontactcount); + + detailFilter.setValue("0000 000"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =2; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching8() +{ + setupBestMatchingContactsDb8(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); - detailFilter.setValue("061234569"); + detailFilter.setValue("358443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -379,9 +703,9 @@ void TestMatchPhoneNumber::testBestMatchingStrategy2() QVERIFY(expectedCount == seachedcontactcount); } -void TestMatchPhoneNumber::testBestMatchingStrategy3() +void TestMatchPhoneNumber::testBestMatching9() { - setupBestMatchingContactsDb3(); + setupBestMatchingContactsDb9(); CntSymbianSrvConnection srvConnection(m_engine); CntDbInfo dbInfo(m_engine); @@ -397,47 +721,166 @@ void TestMatchPhoneNumber::testBestMatchingStrategy3() CntFilterDetail filter(*m_database,srvConnection,dbInfo); filter.emulateBestMatching(); - detailFilter.setValue("1234561"); + detailFilter.setValue("358443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =2; + expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching10() +{ + setupBestMatchingContactsDb10(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; - detailFilter.setValue("401234561"); + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =2; + expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("358401234563"); + detailFilter.setValue("0443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); - expectedCount =0; + expectedCount =1; + QVERIFY(expectedCount == seachedcontactcount); + + detailFilter.setValue("3049607"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =1; + QVERIFY(expectedCount == seachedcontactcount); + + detailFilter.setValue("03049607"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =1; + QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching11() +{ + setupBestMatchingContactsDb11(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("0443049607"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching12() +{ + setupBestMatchingContactsDb12(); - detailFilter.setValue("401234564"); + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching13() +{ + setupBestMatchingContactsDb13(); - detailFilter.setValue("+358401234565"); + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("358443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching14() +{ + setupBestMatchingContactsDb14(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); - detailFilter.setValue("+16101234566"); + detailFilter.setValue("358443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -445,23 +888,87 @@ void TestMatchPhoneNumber::testBestMatchingStrategy3() expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); - detailFilter.setValue("4567"); + detailFilter.setValue("0358443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching15() +{ + setupBestMatchingContactsDb15(); - detailFilter.setValue("*4566"); + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("3584443049607"); + error = QContactManager::NoError; + cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); + // check counts + seachedcontactcount = cnt_ids.count(); + expectedCount =1; + QVERIFY(expectedCount == seachedcontactcount); +} + +void TestMatchPhoneNumber::testBestMatching16() +{ + setupBestMatchingContactsDb16(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; + + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("4443049607"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts seachedcontactcount = cnt_ids.count(); expectedCount =1; QVERIFY(expectedCount == seachedcontactcount); +} +void TestMatchPhoneNumber::testBestMatching17() +{ + setupBestMatchingContactsDb17(); + + CntSymbianSrvConnection srvConnection(m_engine); + CntDbInfo dbInfo(m_engine); + bool filterSupported(true); + + QContactDetailFilter detailFilter; + detailFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); + QList<QContactLocalId> cnt_ids; + QContactManager::Error error; + int seachedcontactcount; + int expectedCount; - detailFilter.setValue("*55*0705#"); + CntFilterDetail filter(*m_database,srvConnection,dbInfo); + filter.emulateBestMatching(); + + detailFilter.setValue("2041234567"); error = QContactManager::NoError; cnt_ids = filter.contacts(detailFilter, QContactSortOrder(), filterSupported, &error); // check counts @@ -470,9 +977,10 @@ void TestMatchPhoneNumber::testBestMatchingStrategy3() QVERIFY(expectedCount == seachedcontactcount); } + void TestMatchPhoneNumber::testBestMatchingWithUnionFilter() { - setupBestMatchingContactsDb2(); + setupBestMatchingContactsDb6(); CntSymbianSrvConnection srvConnection(m_engine); CntDbInfo dbInfo(m_engine); @@ -482,11 +990,11 @@ void TestMatchPhoneNumber::testBestMatchingWithUnionFilter() //Create first filter QContactDetailFilter f1; f1.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); - f1.setValue("1234561"); + f1.setValue("02077009001"); //Create second filter QContactDetailFilter f2; f2.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); - f2.setValue("1234562"); + f2.setValue("02077009081"); //Create an union filter with the above created filters QList<QContactLocalId> cnt_ids; @@ -501,7 +1009,7 @@ void TestMatchPhoneNumber::testBestMatchingWithUnionFilter() cnt_ids = unionFilter.contacts(qfilter, QContactSortOrder(), filterSupported, &error); // check counts int seachedcontactcount = cnt_ids.count(); - int expectedCount =2; + int expectedCount =4; QVERIFY(expectedCount == seachedcontactcount); } @@ -517,11 +1025,11 @@ void TestMatchPhoneNumber::testBestMatchingWithIntersectionFilter() //Create first filter QContactDetailFilter f1; f1.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); - f1.setValue("00358401234561"); + f1.setValue("358401234567"); //Create second filter QContactDetailFilter f2; f2.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); - f2.setValue("99533358401234561"); + f2.setValue("1234567"); //Create an intersection filter with the above created filters QList<QContactLocalId> cnt_ids; diff --git a/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.h b/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.h index d53fc0ee5e..274afe54ec 100644 --- a/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.h +++ b/plugins/contacts/symbian/plugin/tsrc/ut_symbian/ut_matchphonenumber.h @@ -62,10 +62,41 @@ private: void setupBestMatchingContactsDb1(); void setupBestMatchingContactsDb2(); void setupBestMatchingContactsDb3(); + void setupBestMatchingContactsDb4(); + void setupBestMatchingContactsDb5(); + void setupBestMatchingContactsDb6(); + void setupBestMatchingContactsDb7(); + void setupBestMatchingContactsDb8(); + void setupBestMatchingContactsDb9(); + void setupBestMatchingContactsDb10(); + void setupBestMatchingContactsDb11(); + void setupBestMatchingContactsDb12(); + void setupBestMatchingContactsDb13(); + void setupBestMatchingContactsDb14(); + void setupBestMatchingContactsDb15(); + void setupBestMatchingContactsDb16(); + void setupBestMatchingContactsDb17(); + void addContact(QString firstname,QString lastname,QString phonenumber); - void testBestMatchingStrategy1(); - void testBestMatchingStrategy2(); - void testBestMatchingStrategy3(); + + void testBestMatching1(); + void testBestMatching2(); + void testBestMatching3(); + void testBestMatching4(); + void testBestMatching5(); + void testBestMatching6(); + void testBestMatching7(); + void testBestMatching8(); + void testBestMatching9(); + void testBestMatching10(); + void testBestMatching11(); + void testBestMatching12(); + void testBestMatching13(); + void testBestMatching14(); + void testBestMatching15(); + void testBestMatching16(); + void testBestMatching17(); + void testBestMatchingWithUnionFilter(); void testBestMatchingWithIntersectionFilter(); private slots: // Test cases |