Merge lp:~renatofilho/address-book-service/compare-phone-numbers into lp:address-book-service

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 162
Merged at revision: 158
Proposed branch: lp:~renatofilho/address-book-service/compare-phone-numbers
Merge into: lp:address-book-service
Diff against target: 534 lines (+371/-9)
12 files modified
CMakeLists.txt (+6/-0)
cmake/modules/FindLibPhoneNumber.cmake (+23/-0)
cmake/modules/LibFindMacros.cmake (+112/-0)
common/CMakeLists.txt (+5/-1)
common/filter.cpp (+133/-1)
common/filter.h (+2/-0)
contacts/CMakeLists.txt (+4/-2)
debian/control (+1/-0)
lib/CMakeLists.txt (+6/-2)
src/CMakeLists.txt (+2/-2)
tests/unittest/CMakeLists.txt (+5/-1)
tests/unittest/clause-test.cpp (+72/-0)
To merge this branch: bzr merge lp:~renatofilho/address-book-service/compare-phone-numbers
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+266286@code.launchpad.net

Commit message

Use libphonenumber to compare phonenumbers.

To post a comment you must log in.
156. By Renato Araujo Oliveira Filho

Added missing build dep.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
157. By Renato Araujo Oliveira Filho

Fixed phone number filter.
Created unit test for phone number filter.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
158. By Renato Araujo Oliveira Filho

Removed unnecessary functions.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
159. By Renato Araujo Oliveira Filho

Fix filter for small numbers.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
160. By Renato Araujo Oliveira Filho

Use MatchEndsWith to check for phones with match SHORT_NSN_MATCH

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
161. By Renato Araujo Oliveira Filho

Fix query for phone numbers.

162. By Renato Araujo Oliveira Filho

Fixed test name.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

Are there any related MPs required for this MP to build/function as expected?
NO

Is your branch in sync with latest trunk?
YES

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
YES

Did you successfully run all tests found in your component's Test Plan on device or emulator?
YES

If you changed the UI, was the change specified/approved by design?
NO UI CHANGED

If you changed UI labels, did you update the pot file?
NO LABEL CHANGED

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
NO PACKAGING CHANGED

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
Yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

Code looks good and works as expected!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-07-21 19:34:05 +0000
3+++ CMakeLists.txt 2015-08-07 14:35:42 +0000
4@@ -1,12 +1,18 @@
5 project(contatos)
6
7 cmake_minimum_required(VERSION 2.8.9)
8+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
9
10 include(FindPkgConfig)
11 # Standard install paths
12 include(GNUInstallDirs)
13
14 find_package(Qt5Core REQUIRED)
15+find_package(Qt5DBus REQUIRED)
16+find_package(Qt5Versit REQUIRED)
17+find_package(Qt5Contacts REQUIRED)
18+find_package(LibPhoneNumber REQUIRED)
19+
20 find_program(DBUS_RUNNER dbus-test-runner)
21
22 add_definitions(-DQT_NO_KEYWORDS)
23
24=== added directory 'cmake/modules'
25=== added file 'cmake/modules/FindLibPhoneNumber.cmake'
26--- cmake/modules/FindLibPhoneNumber.cmake 1970-01-01 00:00:00 +0000
27+++ cmake/modules/FindLibPhoneNumber.cmake 2015-08-07 14:35:42 +0000
28@@ -0,0 +1,23 @@
29+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
30+
31+include(GNUInstallDirs)
32+include(LibFindMacros)
33+
34+# Include dir
35+find_path(LibPhoneNumber_INCLUDE_DIR
36+ NAMES phonenumberutil.h
37+ PATHS "/usr/local/${CMAKE_INSTALL_INCLUDEDIR}" ${CMAKE_INSTALL_FULL_INCLUDEDIR}
38+ PATH_SUFFIXES "phonenumbers"
39+)
40+
41+# library itself
42+find_library(LibPhoneNumber_LIBRARY
43+ NAMES phonenumber
44+ PATHS "/usr/local/${CMAKE_INSTALL_LIBDIR}" ${CMAKE_INSTALL_FULL_LIBDIR}
45+)
46+
47+# Set the include dir variables and the libraries and let libfind_process do the rest.
48+# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
49+set(LibPhoneNumber_PROCESS_INCLUDES LibPhoneNumber_INCLUDE_DIR)
50+set(LibPhoneNumber_PROCESS_LIBS LibPhoneNumber_LIBRARY)
51+libfind_process(LibPhoneNumber)
52
53=== added file 'cmake/modules/LibFindMacros.cmake'
54--- cmake/modules/LibFindMacros.cmake 1970-01-01 00:00:00 +0000
55+++ cmake/modules/LibFindMacros.cmake 2015-08-07 14:35:42 +0000
56@@ -0,0 +1,112 @@
57+# Version 1.0 (2013-04-12)
58+# Public Domain, originally written by Lasse Kärkkäinen <tronic@zi.fi>
59+# Published at http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries
60+
61+# If you improve the script, please modify the forementioned wiki page because
62+# I no longer maintain my scripts (hosted as static files at zi.fi). Feel free
63+# to remove this entire header if you use real version control instead.
64+
65+# Changelog:
66+# 2013-04-12 Added version number (1.0) and this header, no other changes
67+# 2009-10-08 Originally published
68+
69+
70+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
71+# used for the current package. For this to work, the first parameter must be the
72+# prefix of the current package, then the prefix of the new package etc, which are
73+# passed to find_package.
74+macro (libfind_package PREFIX)
75+ set (LIBFIND_PACKAGE_ARGS ${ARGN})
76+ if (${PREFIX}_FIND_QUIETLY)
77+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
78+ endif (${PREFIX}_FIND_QUIETLY)
79+ if (${PREFIX}_FIND_REQUIRED)
80+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
81+ endif (${PREFIX}_FIND_REQUIRED)
82+ find_package(${LIBFIND_PACKAGE_ARGS})
83+endmacro (libfind_package)
84+
85+# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
86+# where they added pkg_check_modules. Consequently I need to support both in my scripts
87+# to avoid those deprecated warnings. Here's a helper that does just that.
88+# Works identically to pkg_check_modules, except that no checks are needed prior to use.
89+macro (libfind_pkg_check_modules PREFIX PKGNAME)
90+ if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
91+ include(UsePkgConfig)
92+ pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
93+ else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
94+ find_package(PkgConfig)
95+ if (PKG_CONFIG_FOUND)
96+ pkg_check_modules(${PREFIX} ${PKGNAME})
97+ endif (PKG_CONFIG_FOUND)
98+ endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
99+endmacro (libfind_pkg_check_modules)
100+
101+# Do the final processing once the paths have been detected.
102+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
103+# all the variables, each of which contain one include directory.
104+# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
105+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
106+# Also handles errors in case library detection was required, etc.
107+macro (libfind_process PREFIX)
108+ # Skip processing if already processed during this run
109+ if (NOT ${PREFIX}_FOUND)
110+ # Start with the assumption that the library was found
111+ set (${PREFIX}_FOUND TRUE)
112+
113+ # Process all includes and set _FOUND to false if any are missing
114+ foreach (i ${${PREFIX}_PROCESS_INCLUDES})
115+ if (${i})
116+ set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
117+ mark_as_advanced(${i})
118+ else (${i})
119+ set (${PREFIX}_FOUND FALSE)
120+ endif (${i})
121+ endforeach (i)
122+
123+ # Process all libraries and set _FOUND to false if any are missing
124+ foreach (i ${${PREFIX}_PROCESS_LIBS})
125+ if (${i})
126+ set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
127+ mark_as_advanced(${i})
128+ else (${i})
129+ set (${PREFIX}_FOUND FALSE)
130+ endif (${i})
131+ endforeach (i)
132+
133+ # Print message and/or exit on fatal error
134+ if (${PREFIX}_FOUND)
135+ if (NOT ${PREFIX}_FIND_QUIETLY)
136+ message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
137+ endif (NOT ${PREFIX}_FIND_QUIETLY)
138+ else (${PREFIX}_FOUND)
139+ if (${PREFIX}_FIND_REQUIRED)
140+ foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
141+ message("${i}=${${i}}")
142+ endforeach (i)
143+ message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
144+ endif (${PREFIX}_FIND_REQUIRED)
145+ endif (${PREFIX}_FOUND)
146+ endif (NOT ${PREFIX}_FOUND)
147+endmacro (libfind_process)
148+
149+macro(libfind_library PREFIX basename)
150+ set(TMP "")
151+ if(MSVC80)
152+ set(TMP -vc80)
153+ endif(MSVC80)
154+ if(MSVC90)
155+ set(TMP -vc90)
156+ endif(MSVC90)
157+ set(${PREFIX}_LIBNAMES ${basename}${TMP})
158+ if(${ARGC} GREATER 2)
159+ set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
160+ string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
161+ set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
162+ endif(${ARGC} GREATER 2)
163+ find_library(${PREFIX}_LIBRARY
164+ NAMES ${${PREFIX}_LIBNAMES}
165+ PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
166+ )
167+endmacro(libfind_library)
168+
169
170=== modified file 'common/CMakeLists.txt'
171--- common/CMakeLists.txt 2014-03-05 18:43:32 +0000
172+++ common/CMakeLists.txt 2015-08-07 14:35:42 +0000
173@@ -22,4 +22,8 @@
174 ${GALERA_COMMON_LIB_HEADERS}
175 )
176
177-qt5_use_modules(${GALERA_COMMON_LIB} Core Versit Contacts)
178+target_link_libraries(${GALERA_COMMON_LIB}
179+ Qt5::Core
180+ Qt5::Versit
181+ Qt5::Contacts
182+)
183
184=== modified file 'common/filter.cpp'
185--- common/filter.cpp 2014-05-19 14:12:09 +0000
186+++ common/filter.cpp 2015-08-07 14:35:42 +0000
187@@ -21,12 +21,19 @@
188 #include <QtCore/QDataStream>
189 #include <QtCore/QByteArray>
190 #include <QtCore/QString>
191+#include <QtCore/QLocale>
192+#include <QtCore/QDebug>
193+
194 #include <QtContacts/QContactGuid>
195 #include <QtContacts/QContactIdFilter>
196 #include <QtContacts/QContactDetailFilter>
197 #include <QtContacts/QContactUnionFilter>
198 #include <QtContacts/QContactIntersectionFilter>
199 #include <QtContacts/QContactManagerEngine>
200+#include <QtContacts/QContactDetailRangeFilter>
201+#include <QtContacts/QContactRelationshipFilter>
202+
203+#include <phonenumbers/phonenumberutil.h>
204
205 using namespace QtContacts;
206
207@@ -55,7 +62,132 @@
208
209 bool Filter::test(const QContact &contact) const
210 {
211- return QContactManagerEngine::testFilter(m_filter, contact);
212+ return testFilter(m_filter, contact);
213+}
214+
215+bool Filter::comparePhoneNumbers(const QString &input, const QString &value, QContactFilter::MatchFlags flags)
216+{
217+ static i18n::phonenumbers::PhoneNumberUtil *phonenumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
218+
219+ std::string stdPreprocessedInput(input.toStdString());
220+ std::string stdProcessedValue(value.toStdString());
221+
222+ phonenumberUtil->NormalizeDiallableCharsOnly(&stdPreprocessedInput);
223+ phonenumberUtil->NormalizeDiallableCharsOnly(&stdProcessedValue);
224+
225+ QString preprocessedInput = QString::fromStdString(stdPreprocessedInput);
226+ QString preprocessedValue = QString::fromStdString(stdProcessedValue);
227+
228+ // if one of they does not contain digits return false
229+ if (preprocessedInput.isEmpty() || preprocessedValue.isEmpty()) {
230+ return false;
231+ }
232+
233+ bool mc = flags & QContactFilter::MatchContains;
234+ bool msw = flags & QContactFilter::MatchStartsWith;
235+ bool mew = flags & QContactFilter::MatchEndsWith;
236+ bool me = flags & QContactFilter::MatchExactly;
237+ if (!mc && !msw && !mew && !me &&
238+ ((preprocessedInput.length() < 6) || (preprocessedValue.length() < 6))) {
239+ return preprocessedInput == preprocessedValue;
240+ }
241+
242+ if (mc) {
243+ return preprocessedValue.contains(preprocessedInput);
244+ } else if (msw) {
245+ return preprocessedValue.startsWith(preprocessedInput);
246+ } else if (mew) {
247+ return preprocessedValue.endsWith(preprocessedInput);
248+ } else {
249+ i18n::phonenumbers::PhoneNumberUtil::MatchType match =
250+ phonenumberUtil->IsNumberMatchWithTwoStrings(input.toStdString(),
251+ value.toStdString());
252+ if (me) {
253+ return match == i18n::phonenumbers::PhoneNumberUtil::EXACT_MATCH;
254+ } else {
255+ return match > i18n::phonenumbers::PhoneNumberUtil::NO_MATCH;
256+ }
257+ }
258+ return false;
259+}
260+
261+bool Filter::testFilter(const QContactFilter& filter, const QContact &contact)
262+{
263+ switch(filter.type()) {
264+ case QContactFilter::ContactDetailFilter:
265+ {
266+ const QContactDetailFilter cdf(filter);
267+ if (cdf.detailType() == QContactDetail::TypeUndefined)
268+ return false;
269+
270+ /* See if this contact has one of these details in it */
271+ const QList<QContactDetail>& details = contact.details(cdf.detailType());
272+
273+ if (details.count() == 0)
274+ return false; /* can't match */
275+
276+ /* See if we need to check the values */
277+ if (cdf.detailField() == -1)
278+ return true; /* just testing for the presence of a detail of the specified type */
279+
280+ if (cdf.matchFlags() & QContactFilter::MatchPhoneNumber) {
281+ /* Doing phone number filtering. We hand roll an implementation here, backends will obviously want to override this. */
282+ QString input = cdf.value().toString();
283+
284+ /* Look at every detail in the set of details and compare */
285+ for (int j = 0; j < details.count(); j++) {
286+ const QContactDetail& detail = details.at(j);
287+ const QString& valueString = detail.value(cdf.detailField()).toString();
288+
289+ if (comparePhoneNumbers(input, valueString, cdf.matchFlags())) {
290+ return true;
291+ }
292+ }
293+ } else if (QContactManagerEngine::testFilter(filter, contact)) {
294+ return true;
295+ }
296+ }
297+ break;
298+ case QContactFilter::IntersectionFilter:
299+ {
300+ /* XXX In theory we could reorder the terms to put the native tests first */
301+ const QContactIntersectionFilter bf(filter);
302+ const QList<QContactFilter>& terms = bf.filters();
303+ if (terms.count() > 0) {
304+ for(int j = 0; j < terms.count(); j++) {
305+ if (!testFilter(terms.at(j), contact)) {
306+ return false;
307+ }
308+ }
309+ return true;
310+ }
311+ // Fall through to end
312+ }
313+ break;
314+
315+ case QContactFilter::UnionFilter:
316+ {
317+ /* XXX In theory we could reorder the terms to put the native tests first */
318+ const QContactUnionFilter bf(filter);
319+ const QList<QContactFilter>& terms = bf.filters();
320+ if (terms.count() > 0) {
321+ for(int j = 0; j < terms.count(); j++) {
322+ if (testFilter(terms.at(j), contact)) {
323+ return true;
324+ }
325+ }
326+ return false;
327+ }
328+ // Fall through to end
329+ }
330+ break;
331+ default:
332+ if (QContactManagerEngine::testFilter(filter, contact)) {
333+ return true;
334+ }
335+ break;
336+ }
337+ return false;
338 }
339
340 bool Filter::checkIsValid(const QList<QContactFilter> filters) const
341
342=== modified file 'common/filter.h'
343--- common/filter.h 2014-05-13 22:38:50 +0000
344+++ common/filter.h 2015-08-07 14:35:42 +0000
345@@ -55,6 +55,8 @@
346 static QtContacts::QContactFilter parseIdFilter(const QtContacts::QContactFilter &filter);
347 static QtContacts::QContactFilter parseUnionFilter(const QtContacts::QContactFilter &filter);
348 static QtContacts::QContactFilter parseIntersectionFilter(const QtContacts::QContactFilter &filter);
349+ static bool testFilter(const QtContacts::QContactFilter& filter, const QtContacts::QContact &contact);
350+ static bool comparePhoneNumbers(const QString &phoneNumberA, const QString &phoneNumberB, QtContacts::QContactFilter::MatchFlags flags);
351 };
352
353 }
354
355=== modified file 'contacts/CMakeLists.txt'
356--- contacts/CMakeLists.txt 2014-09-23 22:51:39 +0000
357+++ contacts/CMakeLists.txt 2015-08-07 14:35:42 +0000
358@@ -35,10 +35,12 @@
359
360 target_link_libraries(${QCONTACTS_BACKEND}
361 galera-common
362+ Qt5::Core
363+ Qt5::Contacts
364+ Qt5::DBus
365+ Qt5::Versit
366 )
367
368-qt5_use_modules(${QCONTACTS_BACKEND} Core Contacts DBus Versit)
369-
370 add_definitions(-std=gnu++11)
371
372 execute_process(
373
374=== modified file 'debian/control'
375--- debian/control 2015-07-21 19:34:05 +0000
376+++ debian/control 2015-08-07 14:35:42 +0000
377@@ -9,6 +9,7 @@
378 libfolks-dev,
379 libfolks-eds-dev,
380 libgee-0.8-dev (>= 0.8.4),
381+ libphonenumber-dev,
382 qt5-default,
383 qt5-qmake,
384 qtbase5-dev,
385
386=== modified file 'lib/CMakeLists.txt'
387--- lib/CMakeLists.txt 2014-04-28 14:31:09 +0000
388+++ lib/CMakeLists.txt 2015-08-07 14:35:42 +0000
389@@ -41,10 +41,13 @@
390 ${GIO_LIBRARIES}
391 ${FOLKS_LIBRARIES}
392 ${FOLKS_EDS_LIBRARIES}
393+ ${LibPhoneNumber_LIBRARIES}
394+ Qt5::Core
395+ Qt5::Contacts
396+ Qt5::DBus
397+ Qt5::Versit
398 )
399
400-qt5_use_modules(${CONTACTS_SERVICE_LIB} Core Contacts DBus Versit)
401-
402 include_directories(
403 ${CMAKE_SOURCE_DIR}
404 ${CMAKE_BINARY_DIR}
405@@ -52,4 +55,5 @@
406 ${GIO_INCLUDE_DIRS}
407 ${FOLKS_INCLUDE_DIRS}
408 ${FOLKS_EDS_INCLUDE_DIRS}
409+ ${LibPhoneNumber_INCLUDE_DIRS}
410 )
411
412=== modified file 'src/CMakeLists.txt'
413--- src/CMakeLists.txt 2013-11-01 12:22:52 +0000
414+++ src/CMakeLists.txt 2015-08-07 14:35:42 +0000
415@@ -15,10 +15,10 @@
416 ${GLIB_LIBRARIES}
417 ${GIO_LIBRARIES}
418 ${FOLKS_LIBRARIES}
419+ Qt5::Core
420+ Qt5::Contacts
421 )
422
423-qt5_use_modules(${CONTACTS_SERVICE_BIN} Core Contacts)
424-
425 include_directories(
426 ${CMAKE_SOURCE_DIR}
427 ${CMAKE_BINARY_DIR}
428
429=== modified file 'tests/unittest/CMakeLists.txt'
430--- tests/unittest/CMakeLists.txt 2014-12-11 18:49:50 +0000
431+++ tests/unittest/CMakeLists.txt 2015-08-07 14:35:42 +0000
432@@ -3,7 +3,6 @@
433 ${ARGN}
434 ${TESTNAME}.cpp
435 )
436- qt5_use_modules(${TESTNAME} Core Contacts Versit Test DBus)
437
438 if(TEST_XML_OUTPUT)
439 set(TEST_ARGS -p -xunitxml -p -o -p test_${testname}.xml)
440@@ -18,6 +17,11 @@
441 ${GLIB_LIBRARIES}
442 ${GIO_LIBRARIES}
443 ${FOLKS_LIBRARIES}
444+ Qt5::Core
445+ Qt5::Contacts
446+ Qt5::Versit
447+ Qt5::Test
448+ Qt5::DBus
449 )
450
451 if(${RUN_SERVER} STREQUAL "True")
452
453=== modified file 'tests/unittest/clause-test.cpp'
454--- tests/unittest/clause-test.cpp 2014-05-15 20:19:03 +0000
455+++ tests/unittest/clause-test.cpp 2015-08-07 14:35:42 +0000
456@@ -192,6 +192,78 @@
457 QVERIFY(!filter2.isEmpty());
458 QVERIFY(filter2.isValid());
459 }
460+
461+ void testPhoneNumberFilter_data()
462+ {
463+ QTest::addColumn<QString>("phoneNumber");
464+ QTest::addColumn<QString>("query");
465+ QTest::addColumn<bool>("match"); // if they are the same phone number
466+ QTest::addColumn<bool>("matchContains"); // if the phoneNumber contains query
467+ QTest::addColumn<bool>("matchStartsWith"); // if the phoneNumber starts with query
468+ QTest::addColumn<bool>("matchEndsWith"); // if the phoneNumber ends with the query
469+ QTest::addColumn<bool>("matchExactly"); // if the phoneNumber exacly match query
470+
471+ QTest::newRow("string equal") << "12345678" << "12345678" << true << true << true << true << true;
472+ QTest::newRow("number with dash") << "1234-5678" << "12345678" << true << true << true << true << true;;
473+ QTest::newRow("number with country code") << "+55(81)87042155" << "(81)87042155" << true << true << false << true << false;
474+ QTest::newRow("number with and without country code") << "+55(81)87042155" << "(81)87042155" << true << true << false << true << false;
475+ QTest::newRow("number with and without area code") << "(81)87042155" << "87042155" << true << true << false << true << false;
476+ QTest::newRow("number with extension") << "12345678#123" << "12345678" << true << true << true << false << false;
477+ QTest::newRow("both numbers with extension") << "(123)12345678#1" << "12345678#1" << true << true << false << true << false;
478+ QTest::newRow("numbers with different extension") << "1234567#1" << "1234567#2" << false << false << false << false << false;
479+ QTest::newRow("short/emergency numbers") << "190" << "190" << true << true << true << true << true;
480+ QTest::newRow("different short/emergency numbers") << "911" << "11" << false << true << false << true << false;
481+ QTest::newRow("different numbers") << "12345678" << "1234567" << false << true << true << false << false;
482+ QTest::newRow("both non phone numbers") << "abcdefg" << "abcdefg" << false << false << false << false << false;
483+ QTest::newRow("different non phone numbers") << "abcdefg" << "bcdefg" << false << false << false << false << false;
484+ QTest::newRow("phone number and custom string") << "abc12345678" << "12345678" << true << true << true << true << false;
485+ QTest::newRow("Not match") << "+352 661 123456" << "+352 691 123456" << false << false << false << false << false;
486+ QTest::newRow("Phone number and small value") << "32634146" << "146" << false << true << false << true << false;
487+ QTest::newRow("Small phone numbers numbers") << "32634911" << "911" << false << true << false << true << false;
488+ QTest::newRow("Phone number and small number") << "32634911" << "+146" << false << false << false << false << false;
489+ }
490+
491+ void testPhoneNumberFilter()
492+ {
493+ QFETCH(QString, phoneNumber);
494+ QFETCH(QString, query);
495+ QFETCH(bool, match);
496+ QFETCH(bool, matchContains);
497+ QFETCH(bool, matchStartsWith);
498+ QFETCH(bool, matchEndsWith);
499+ QFETCH(bool, matchExactly);
500+
501+ QContact c;
502+ QContactPhoneNumber p;
503+ p.setNumber(phoneNumber);
504+ c.saveDetail(&p);
505+
506+ // if they are the same phone number
507+ QContactDetailFilter f = QContactPhoneNumber::match(query);
508+ Filter myFilter(f);
509+ QCOMPARE(myFilter.test(c), match);
510+
511+ // if the phoneNumber contains query
512+ f.setMatchFlags(QContactFilter::MatchPhoneNumber | QContactFilter::MatchContains);
513+ myFilter = Filter(f);
514+ QCOMPARE(myFilter.test(c), matchContains);
515+
516+ // if the phoneNumber starts with query
517+ f.setMatchFlags(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith);
518+ myFilter = Filter(f);
519+ QCOMPARE(myFilter.test(c), matchStartsWith);
520+
521+ // if the phoneNumber ends with the query
522+ f.setMatchFlags(QContactFilter::MatchPhoneNumber | QContactFilter::MatchEndsWith);
523+ myFilter = Filter(f);
524+ QCOMPARE(myFilter.test(c), matchEndsWith);
525+
526+ // Exactly the same number
527+ f.setMatchFlags(QContactFilter::MatchPhoneNumber | QContactFilter::MatchExactly);
528+ myFilter = Filter(f);
529+ // Failing due the MatchFlag problem check: https://bugreports.qt.io/browse/QTBUG-47546
530+ //QCOMPARE(myFilter.test(c), matchExactly);
531+ }
532 };
533
534 QTEST_MAIN(ClauseParseTest)

Subscribers

People subscribed via source and target branches