Merge lp:~tiagosh/telepathy-ofono/fix-1462090 into lp:telepathy-ofono

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 144
Merged at revision: 144
Proposed branch: lp:~tiagosh/telepathy-ofono/fix-1462090
Merge into: lp:telepathy-ofono
Diff against target: 71 lines (+34/-2)
2 files modified
phoneutils.cpp (+2/-2)
tests/CallTest.cpp (+32/-0)
To merge this branch: bzr merge lp:~tiagosh/telepathy-ofono/fix-1462090
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+262270@code.launchpad.net

Commit message

Improve phone number normalization.

Description of the change

Improve phone number normalization.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'phoneutils.cpp'
2--- phoneutils.cpp 2013-11-11 15:10:00 +0000
3+++ phoneutils.cpp 2015-06-17 20:21:04 +0000
4@@ -39,7 +39,7 @@
5
6 bool PhoneUtils::isPhoneNumber(const QString &identifier) {
7 // remove all non diable digits
8- QString finalNumber = QString(identifier).replace(QRegExp("[p+*#(),;-]"),"");
9+ QString finalNumber = QString(identifier).replace(QRegExp("[p+*#/(),;-]"),"");
10 finalNumber = finalNumber.replace(QRegExp("(\\s+)"), "");
11 // if empty, the number is invalid
12 if (finalNumber.isEmpty())
13@@ -58,7 +58,7 @@
14 }
15 QRegExp regexp = QRegExp("(\\s+)");
16 QString finalNumber = QString(identifier).replace(regexp,"");
17- finalNumber = finalNumber.replace(QRegExp("[()-]"),"");
18+ finalNumber = finalNumber.replace(QRegExp("[()/-]"),"");
19 return finalNumber;
20 }
21
22
23=== modified file 'tests/CallTest.cpp'
24--- tests/CallTest.cpp 2014-09-22 21:08:53 +0000
25+++ tests/CallTest.cpp 2015-06-17 20:21:04 +0000
26@@ -48,6 +48,8 @@
27 void testCallIncoming();
28 void testCallIncomingPrivateNumber();
29 void testCallIncomingUnknownNumber();
30+ void testNumberNormalization_data();
31+ void testNumberNormalization();
32 void testCallOutgoing();
33 void testCallHold();
34 void testCallDTMF();
35@@ -159,6 +161,36 @@
36 QTRY_COMPARE(channel->callState(), Tp::CallStateEnded);
37 }
38
39+void CallTest::testNumberNormalization_data()
40+{
41+ QTest::addColumn<QString>("number");
42+ QTest::addColumn<QString>("expectedNumber");
43+
44+ QTest::newRow("simple number") << "12345678" << "12345678";
45+ QTest::newRow("number with dash") << "1234-5678" << "12345678";
46+ QTest::newRow("number with area code") << "(123)12345678" << "12312345678";
47+ QTest::newRow("number with slash") << "+421 2/123 456 78" << "+421212345678";
48+}
49+
50+void CallTest::testNumberNormalization()
51+{
52+ QFETCH(QString, number);
53+ QFETCH(QString, expectedNumber);
54+
55+ Tp::AccountPtr account = TelepathyHelper::instance()->account();
56+ QSignalSpy spy(this, SIGNAL(contactsReceived(QList<Tp::ContactPtr>)));
57+
58+ connect(account->connection()->contactManager()->contactsForIdentifiers(QStringList() << number),
59+ SIGNAL(finished(Tp::PendingOperation*)),
60+ SLOT(onPendingContactsFinished(Tp::PendingOperation*)));
61+
62+ QTRY_COMPARE(spy.count(), 1);
63+
64+ QList<Tp::ContactPtr> contacts = spy.first().first().value<QList<Tp::ContactPtr> >();
65+ QCOMPARE(contacts.count(), 1);
66+ QCOMPARE(contacts.first()->id(), QString(expectedNumber));
67+}
68+
69 void CallTest::testCallOutgoing()
70 {
71 // Request the contact to start chatting to

Subscribers

People subscribed via source and target branches