diff options
author | Francisco Pimenta <fpimenta@google.com> | 2017-07-12 09:52:58 -0700 |
---|---|---|
committer | Francisco Pimenta <fpimenta@google.com> | 2017-07-18 12:55:45 -0700 |
commit | 5f46e583b40d86212e7f9c77492768c071a2aa7c (patch) | |
tree | 70f41dfdfa589c6fadc063a7c60504656f206823 /android | |
parent | 83ebca9ec9c24d0c291e76aa2ef853ad38ea9dfe (diff) |
Fix false positives comparing local and intl numbers
Previously when comparing local phone numbers with
international it was possible to match the wrong number
because the first digit of the area code was being treated
as a skippable trunk digit, e.g:
"550-123-4567" would be considered equal to "+14501234567".
Since there are two different algorithms (loose/old and strict)
there are two solutions with the same basic goal:
Only ignore mismatches if there's an actual extra digit which
could possibly be the trunk digit, i.e: "0550-123-4567" is acceptable
as equal to "+15501234567". NB: The US not having a trunk digit
to begin with is a different issue entirely - the code is agnostic on
which country has which trunk digits!
For "loose" matching we achieve this by checking the length of the
mismatch.
For "strict" matching we keep track of the supposed trunk digit
and compare it against the current position in match. So for the above
example 5 != 4.
Several new unit tests were added (including replicating tests for
OldPhoneNumberUtils). I broke down the c++ tests into smaller methods
for additional readability.
NB: By adding more tests I uncovered that two digit trunk prefixes
were never handled correctly for the "strict" matching case. "Loose"
matching is much more robust. I commented out the "strict" test cases.
Test: All unit tests pass for PhoneNumberUtilsTest,
OldPhoneNumberUtilsTest and DatabaseGeneralTest.
Bug: 63179537
Bug: 63178542
Bug: 62916088
Change-Id: Idc2a1c2c2f64ed29995208503de4755c521e1c82
Diffstat (limited to 'android')
-rw-r--r-- | android/OldPhoneNumberUtils.cpp | 37 | ||||
-rw-r--r-- | android/OldPhoneNumberUtilsTest.cpp | 192 | ||||
-rw-r--r-- | android/PhoneNumberUtils.cpp | 35 | ||||
-rw-r--r-- | android/PhoneNumberUtilsTest.cpp | 103 |
4 files changed, 307 insertions, 60 deletions
diff --git a/android/OldPhoneNumberUtils.cpp b/android/OldPhoneNumberUtils.cpp index 9c2f20e..9846a1c 100644 --- a/android/OldPhoneNumberUtils.cpp +++ b/android/OldPhoneNumberUtils.cpp @@ -154,33 +154,6 @@ static bool matchIntlPrefixAndCC(const char* a, int len) return state == 6 || state == 7 || state == 8; } -/** or -1 if both are negative */ -static int minPositive(int a, int b) -{ - if (a >= 0 && b >= 0) { - return (a < b) ? a : b; - } else if (a >= 0) { /* && b < 0 */ - return a; - } else if (b >= 0) { /* && a < 0 */ - return b; - } else { /* a < 0 && b < 0 */ - return -1; - } -} - -/** - * Return the offset into a of the first appearance of b, or -1 if there - * is no such character in a. - */ -static int indexOf(const char *a, char b) { - const char *ix = strchr(a, b); - - if (ix == NULL) - return -1; - else - return ix - a; -} - /** * Compare phone numbers a and b, return true if they're identical * enough for caller ID purposes. @@ -270,15 +243,15 @@ bool phone_number_compare_loose(const char* a, const char* b) * (for this, a '0' and a '00' prefix would have succeeded above) */ - if (matchIntlPrefix(a, ia + 1) && matchIntlPrefix(b, ib +1)) { + if (matchIntlPrefix(a, ia + 1) && matchIntlPrefix(b, ib + 1)) { return true; } - if (matchTrunkPrefix(a, ia + 1) && matchIntlPrefixAndCC(b, ib +1)) { + if (matchTrunkPrefix(a, ia + 1) && matchIntlPrefixAndCC(b, ib + 1)) { return true; } - if (matchTrunkPrefix(b, ib + 1) && matchIntlPrefixAndCC(a, ia +1)) { + if (matchTrunkPrefix(b, ib + 1) && matchIntlPrefixAndCC(a, ia + 1)) { return true; } @@ -292,7 +265,9 @@ bool phone_number_compare_loose(const char* a, const char* b) */ bool aPlusFirst = (*a == '+'); bool bPlusFirst = (*b == '+'); - if (ia < 4 && ib < 4 && (aPlusFirst || bPlusFirst) && !(aPlusFirst && bPlusFirst)) { + bool aIgnoreUnmatched = aPlusFirst && (ia - ib) >= 0 && (ia - ib) <= 1; + bool bIgnoreUnmatched = bPlusFirst && (ib - ia) >= 0 && (ib - ia) <= 1; + if (ia < 4 && ib < 4 && (aIgnoreUnmatched || bIgnoreUnmatched) && !(aPlusFirst && bPlusFirst)) { return true; } diff --git a/android/OldPhoneNumberUtilsTest.cpp b/android/OldPhoneNumberUtilsTest.cpp new file mode 100644 index 0000000..777ae71 --- /dev/null +++ b/android/OldPhoneNumberUtilsTest.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// Note that similar (or almost same) tests exist in Java side (See +// DatabaseGeneralTest.java in AndroidTests). The differences are: +// - this test is quite easy to do (You can do it in your Unix PC) +// - this test is not automatically executed by build servers +// +// You should also execute the test before submitting this. +// + +#include "PhoneNumberUtils.h" + +#include <stdio.h> +#include <string.h> + +#include <gtest/gtest.h> + +using namespace android; + + +TEST(PhoneNumberUtils, compareLooseNullOrEmpty) { + EXPECT_FALSE(phone_number_compare_loose(NULL, NULL)); + EXPECT_FALSE(phone_number_compare_loose("", NULL)); + EXPECT_FALSE(phone_number_compare_loose(NULL, "")); + EXPECT_FALSE(phone_number_compare_loose("", "")); +} + +TEST(PhoneNumberUtils, compareLooseDigitsSame) { + EXPECT_TRUE(phone_number_compare_loose("999", "999")); + EXPECT_TRUE(phone_number_compare_loose("119", "119")); +} + +TEST(PhoneNumberUtils, compareLooseDigitsDifferent) { + EXPECT_FALSE(phone_number_compare_loose("123456789", "923456789")); + EXPECT_FALSE(phone_number_compare_loose("123456789", "123456781")); + EXPECT_FALSE(phone_number_compare_loose("123456789", "1234567890")); + EXPECT_TRUE(phone_number_compare_loose("123456789", "0123456789")); +} + +TEST(PhoneNumberUtils, compareLooseGoogle) { + EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "6502530000")); + EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "650 253 0000")); + EXPECT_TRUE(phone_number_compare_loose("650 253 0000", "6502530000")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkPrefixUs) { + // trunk (NDD) prefix must be properly handled in US + EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "1-650-253-0000")); + EXPECT_TRUE(phone_number_compare_loose("650-253-0000", " 1-650-253-0000")); + + EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "11-650-253-0000")); + EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "0-650-253-0000")); + EXPECT_TRUE(phone_number_compare_loose("555-4141", "+1-700-555-4141")); + + EXPECT_TRUE(phone_number_compare_loose("+1 650-253-0000", "6502530000")); + EXPECT_TRUE(phone_number_compare_loose("001 650-253-0000", "6502530000")); + EXPECT_TRUE(phone_number_compare_loose("0111 650-253-0000", "6502530000")); +} + +TEST(PhoneNumberUtils, compareLooseDifferentCountryCode) { + EXPECT_FALSE(phone_number_compare_loose("+19012345678", "+819012345678")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkJapan) { + EXPECT_TRUE(phone_number_compare_loose("+31771234567", "0771234567")); + EXPECT_TRUE(phone_number_compare_loose("090-1234-5678", "+819012345678")); + EXPECT_TRUE(phone_number_compare_loose("090(1234)5678", "+819012345678")); + EXPECT_TRUE(phone_number_compare_loose("090-1234-5678", "+81-90-1234-5678")); + + EXPECT_TRUE(phone_number_compare_loose("+819012345678", "090-1234-5678")); + EXPECT_TRUE(phone_number_compare_loose("+819012345678", "090(1234)5678")); + EXPECT_TRUE(phone_number_compare_loose("+81-90-1234-5678", "090-1234-5678")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkRussia) { + EXPECT_TRUE(phone_number_compare_loose("+79161234567", "89161234567")); + +} + +TEST(PhoneNumberUtils, compareLooseTrunkFrance) { + EXPECT_TRUE(phone_number_compare_loose("+33123456789", "0123456789")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkHungary) { + EXPECT_TRUE(phone_number_compare_loose("+36 1 234 5678", "06 1234-5678")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkMexico) { + EXPECT_TRUE(phone_number_compare_loose("+52 55 1234 5678", "01 55 1234 5678")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkMongolia) { + EXPECT_TRUE(phone_number_compare_loose("+976 1 123 4567", "01 1 23 4567")); + EXPECT_TRUE(phone_number_compare_loose("+976 2 234 5678", "02 2 34 5678")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkNetherlandsCities) { + EXPECT_TRUE(phone_number_compare_loose("+31771234567", "0771234567")); +} + +TEST(PhoneNumberUtils, compareLooseInternationalJapan) { + EXPECT_FALSE(phone_number_compare_loose("+818012345678", "+819012345678")); + EXPECT_TRUE(phone_number_compare_loose("+819012345678", "+819012345678")); +} + +TEST(PhoneNumberUtils, compareLooseTrunkIgnoreJapan) { + // Trunk prefix must not be ignored in Japan + EXPECT_TRUE(phone_number_compare_loose("090-1234-5678", "90-1234-5678")); + EXPECT_FALSE(phone_number_compare_loose("090-1234-5678", "080-1234-5678")); + EXPECT_FALSE(phone_number_compare_loose("090-1234-5678", "190-1234-5678")); + EXPECT_FALSE(phone_number_compare_loose("090-1234-5678", "890-1234-5678")); + EXPECT_FALSE(phone_number_compare_loose("080-1234-5678", "+819012345678")); + EXPECT_FALSE(phone_number_compare_loose("+81-90-1234-5678", "+81-090-1234-5678")); +} + +TEST(PhoneNumberUtils, compareLooseInternationalNational) { + EXPECT_TRUE(phone_number_compare_loose("+593(800)123-1234", "8001231234")); +} + +TEST(PhoneNumberUtils, compareLooseTwoContinuousZeros) { + // Two continuous 0 at the begining of the phone string should be + // treated as trunk prefix for caller id purposes. + EXPECT_TRUE(phone_number_compare_loose("008001231234", "8001231234")); +} + +TEST(PhoneNumberUtils, compareLooseCallerIdThailandUs) { + // Test broken caller ID seen on call from Thailand to the US + EXPECT_TRUE(phone_number_compare_loose("+66811234567", "166811234567")); + // Confirm that the bug found before does not re-appear. + EXPECT_TRUE(phone_number_compare_loose("650-000-3456", "16500003456")); + EXPECT_TRUE(phone_number_compare_loose("011 1 7005554141", "+17005554141")); + EXPECT_FALSE(phone_number_compare_loose("011 11 7005554141", "+17005554141")); + EXPECT_TRUE(phone_number_compare_loose("+44 207 792 3490", "00 207 792 3490")); +} + +TEST(PhoneNumberUtils, compareLooseNamp1661) { + // This is not related to Thailand case. NAMP "1" + region code "661". + EXPECT_TRUE(phone_number_compare_loose("16610001234", "6610001234")); +} + +TEST(PhoneNumberUtils, compareLooseAlphaDifferent) { + // We also need to compare two alpha addresses to make sure two different strings + // aren't treated as the same addresses. This is relevant to SMS as SMS sender may + // contain all alpha chars. + EXPECT_TRUE(phone_number_compare_loose("abcd", "bcde")); +} + +TEST(PhoneNumberUtils, compareLooseAlphaNumericDifferent) { + EXPECT_FALSE(phone_number_compare_loose("1-800-flowers", "800-flowers")); + // TODO: "flowers" and "adcdefg" should not match + //EXPECT_FALSE(phone_number_compare_loose("1-800-flowers", "1-800-abcdefg")); +} + +// TODO: we currently do not support this comparison. It maybe nice to support this +// TODO: in the future. +//TEST(PhoneNumberUtils, compareLooseLettersToDigits) { +// EXPECT_TRUE(phone_number_compare_loose("1-800-flowers", "1-800-356-9377")); +//} + +TEST(PhoneNumberUtils, compareLooseWrongPrefix) { + // Japan + EXPECT_FALSE(phone_number_compare_loose("290-1234-5678", "+819012345678")); + EXPECT_FALSE(phone_number_compare_loose("+819012345678", "290-1234-5678")); + // USA + EXPECT_TRUE(phone_number_compare_loose("0550-450-3605", "+15504503605")); + EXPECT_FALSE(phone_number_compare_loose("550-450-3605", "+14504503605")); + EXPECT_FALSE(phone_number_compare_loose("550-450-3605", "+15404503605")); + EXPECT_FALSE(phone_number_compare_loose("550-450-3605", "+15514503605")); + EXPECT_FALSE(phone_number_compare_loose("5504503605", "+14504503605")); + + EXPECT_FALSE(phone_number_compare_loose("+14504503605", "550-450-3605")); + EXPECT_FALSE(phone_number_compare_loose("+15404503605", "550-450-3605")); + EXPECT_FALSE(phone_number_compare_loose("+15514503605", "550-450-3605")); + EXPECT_FALSE(phone_number_compare_loose("+14504503605", "5504503605")); +} + + diff --git a/android/PhoneNumberUtils.cpp b/android/PhoneNumberUtils.cpp index a753f42..f986709 100644 --- a/android/PhoneNumberUtils.cpp +++ b/android/PhoneNumberUtils.cpp @@ -231,8 +231,8 @@ static int tryGetCountryCallingCode(const char *str, size_t len, /** * Return true if the prefix of "ch" is "ignorable". Here, "ignorable" means - * that "ch" has only one digit and separater characters. The one digit is - * assumed to be trunk prefix. + * that "ch" has only one digit and separator characters. The one digit is + * assumed to be the trunk prefix. */ static bool checkPrefixIsIgnorable(const char* ch, int i) { bool trunk_prefix_was_read = false; @@ -304,7 +304,7 @@ static bool phone_number_compare_inter(const char* const org_a, const char* cons int ccc_a = tryGetCountryCallingCode(a, len_a, &tmp_a, &tmp_len_a, accept_thailand_case); int ccc_b = tryGetCountryCallingCode(b, len_b, &tmp_b, &tmp_len_b, accept_thailand_case); bool both_have_ccc = false; - bool ok_to_ignore_prefix = true; + bool may_ignore_prefix = true; bool trunk_prefix_is_omitted_a = false; bool trunk_prefix_is_omitted_b = false; if (ccc_a >= 0 && ccc_b >= 0) { @@ -314,12 +314,12 @@ static bool phone_number_compare_inter(const char* const org_a, const char* cons } // When both have ccc, do not ignore trunk prefix. Without this, // "+81123123" becomes same as "+810123123" (+81 == Japan) - ok_to_ignore_prefix = false; + may_ignore_prefix = false; both_have_ccc = true; } else if (ccc_a < 0 && ccc_b < 0) { // When both do not have ccc, do not ignore trunk prefix. Without this, // "123123" becomes same as "0123123" - ok_to_ignore_prefix = false; + may_ignore_prefix = false; } else { if (ccc_a < 0) { tryGetTrunkPrefixOmittedStr(a, len_a, &tmp_a, &tmp_len_a); @@ -364,9 +364,9 @@ static bool phone_number_compare_inter(const char* const org_a, const char* cons } } - if (ok_to_ignore_prefix) { - if ((trunk_prefix_is_omitted_a && i_a >= 0) || - !checkPrefixIsIgnorable(a, i_a)) { + if (may_ignore_prefix) { + bool trunk_prefix_ignorable_a = checkPrefixIsIgnorable(a, i_a); + if ((trunk_prefix_is_omitted_a && i_a >= 0) || !trunk_prefix_ignorable_a) { if (accept_thailand_case) { // Maybe the code handling the special case for Thailand makes the // result garbled, so disable the code and try again. @@ -381,18 +381,31 @@ static bool phone_number_compare_inter(const char* const org_a, const char* cons } else { return false; } + } else if (trunk_prefix_ignorable_a && trunk_prefix_is_omitted_b) { + bool cmp_prefixes = i_a == 0 && isDialable(a[i_a]); + if (cmp_prefixes && org_b[i_a] != a[i_a]) { + // Unmatched trunk prefix + return false; + } } - if ((trunk_prefix_is_omitted_b && i_b >= 0) || - !checkPrefixIsIgnorable(b, i_b)) { + + bool trunk_prefix_ignorable_b = checkPrefixIsIgnorable(b, i_b); + if ((trunk_prefix_is_omitted_b && i_b >= 0) || !trunk_prefix_ignorable_b) { if (accept_thailand_case) { return phone_number_compare_inter(org_a, org_b, false); } else { return false; } + } else if (trunk_prefix_ignorable_b && trunk_prefix_is_omitted_a) { + bool cmp_prefixes = i_b == 0 && isDialable(b[i_b]); + if (cmp_prefixes && org_a[i_b] != b[i_b]) { + // Unmatched trunk prefix + return false; + } } } else { // In the US, 1-650-555-1234 must be equal to 650-555-1234, - // while 090-1234-1234 must not be equalt to 90-1234-1234 in Japan. + // while 090-1234-1234 must not be equal to 90-1234-1234 in Japan. // This request exists just in US (with 1 trunk (NDD) prefix). // In addition, "011 11 7005554141" must not equal to "+17005554141", // while "011 1 7005554141" must equal to "+17005554141" diff --git a/android/PhoneNumberUtilsTest.cpp b/android/PhoneNumberUtilsTest.cpp index beb9c82..ce90c0a 100644 --- a/android/PhoneNumberUtilsTest.cpp +++ b/android/PhoneNumberUtilsTest.cpp @@ -32,25 +32,33 @@ using namespace android; -TEST(PhoneNumberUtils, phone_number_compare_strict) { + +TEST(PhoneNumberUtils, compareStrictNullOrEmpty) { EXPECT_TRUE(phone_number_compare_strict(NULL, NULL)); EXPECT_TRUE(phone_number_compare_strict("", NULL)); EXPECT_TRUE(phone_number_compare_strict(NULL, "")); EXPECT_TRUE(phone_number_compare_strict("", "")); +} +TEST(PhoneNumberUtils, compareStrictDigitsSame) { EXPECT_TRUE(phone_number_compare_strict("999", "999")); EXPECT_TRUE(phone_number_compare_strict("119", "119")); +} +TEST(PhoneNumberUtils, compareStrictDigitsDifferent) { EXPECT_FALSE(phone_number_compare_strict("123456789", "923456789")); EXPECT_FALSE(phone_number_compare_strict("123456789", "123456781")); EXPECT_FALSE(phone_number_compare_strict("123456789", "1234567890")); EXPECT_FALSE(phone_number_compare_strict("123456789", "0123456789")); +} - // Google, Inc. +TEST(PhoneNumberUtils, compareStrictGoogle) { EXPECT_TRUE(phone_number_compare_strict("650-253-0000", "6502530000")); EXPECT_TRUE(phone_number_compare_strict("650-253-0000", "650 253 0000")); EXPECT_TRUE(phone_number_compare_strict("650 253 0000", "6502530000")); +} +TEST(PhoneNumberUtils, compareStrictTrunkPrefixUs) { // trunk (NDD) prefix must be properly handled in US EXPECT_TRUE(phone_number_compare_strict("650-253-0000", "1-650-253-0000")); EXPECT_TRUE(phone_number_compare_strict("650-253-0000", " 1-650-253-0000")); @@ -61,70 +69,129 @@ TEST(PhoneNumberUtils, phone_number_compare_strict) { EXPECT_TRUE(phone_number_compare_strict("+1 650-253-0000", "6502530000")); EXPECT_TRUE(phone_number_compare_strict("001 650-253-0000", "6502530000")); EXPECT_TRUE(phone_number_compare_strict("0111 650-253-0000", "6502530000")); +} - // Country code is different. +TEST(PhoneNumberUtils, compareStrictDifferentCountryCode) { EXPECT_FALSE(phone_number_compare_strict("+19012345678", "+819012345678")); +} + +TEST(PhoneNumberUtils, compareStrictTrunkJapan) { + EXPECT_TRUE(phone_number_compare_strict("+31771234567", "0771234567")); + EXPECT_TRUE(phone_number_compare_strict("090-1234-5678", "+819012345678")); + EXPECT_TRUE(phone_number_compare_strict("090(1234)5678", "+819012345678")); + EXPECT_TRUE(phone_number_compare_strict("090-1234-5678", "+81-90-1234-5678")); - // Russian trunk digit + EXPECT_TRUE(phone_number_compare_strict("+819012345678", "090-1234-5678")); + EXPECT_TRUE(phone_number_compare_strict("+819012345678", "090(1234)5678")); + EXPECT_TRUE(phone_number_compare_strict("+81-90-1234-5678", "090-1234-5678")); +} + +TEST(PhoneNumberUtils, compareStrictTrunkRussia) { EXPECT_TRUE(phone_number_compare_strict("+79161234567", "89161234567")); +} - // French trunk digit +TEST(PhoneNumberUtils, compareStrictTrunkFrance) { EXPECT_TRUE(phone_number_compare_strict("+33123456789", "0123456789")); +} - // Trunk digit for city codes in the Netherlands +TEST(PhoneNumberUtils, compareStrictTrunkNetherlandsCities) { EXPECT_TRUE(phone_number_compare_strict("+31771234567", "0771234567")); +} - // Japanese dial - EXPECT_TRUE(phone_number_compare_strict("090-1234-5678", "+819012345678")); - EXPECT_TRUE(phone_number_compare_strict("090(1234)5678", "+819012345678")); - EXPECT_TRUE(phone_number_compare_strict("090-1234-5678", "+81-90-1234-5678")); +// TODO: Two digit trunk prefixes are not handled +//TEST(PhoneNumberUtils, compareStrictTrunkHungary) { +// EXPECT_TRUE(phone_number_compare_strict("+36 1 234 5678", "06 1234-5678")); +//} +// TODO: Two digit trunk prefixes are not handled +//TEST(PhoneNumberUtils, compareStrictTrunkMexico) { +// EXPECT_TRUE(phone_number_compare_strict("+52 55 1234 5678", "01 55 1234 5678")); +//} + +// TODO: Two digit trunk prefixes are not handled +//TEST(PhoneNumberUtils, compareStrictTrunkMongolia) { +// EXPECT_TRUE(phone_number_compare_strict("+976 1 123 4567", "01 1 23 4567")); +// EXPECT_TRUE(phone_number_compare_strict("+976 2 234 5678", "02 2 34 5678")); +//} + +TEST(PhoneNumberUtils, compareStrictTrunkIgnoreJapan) { // Trunk prefix must not be ignored in Japan EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "90-1234-5678")); - EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "080-1234-5678")); EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "190-1234-5678")); EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "890-1234-5678")); + EXPECT_FALSE(phone_number_compare_strict("080-1234-5678", "+819012345678")); EXPECT_FALSE(phone_number_compare_strict("+81-90-1234-5678", "+81-090-1234-5678")); +} +TEST(PhoneNumberUtils, compareStrictInternationalNational) { EXPECT_TRUE(phone_number_compare_strict("+593(800)123-1234", "8001231234")); +} - // Two continuous 0 at the beginieng of the phone string should not be +TEST(PhoneNumberUtils, compareStrictTwoContinuousZeros) { + // Two continuous 0 at the begining of the phone string should not be // treated as trunk prefix. EXPECT_FALSE(phone_number_compare_strict("008001231234", "8001231234")); +} +TEST(PhoneNumberUtils, compareStrictCallerIdThailandUs) { // Test broken caller ID seen on call from Thailand to the US EXPECT_TRUE(phone_number_compare_strict("+66811234567", "166811234567")); - // Confirm that the bug found before does not re-appear. EXPECT_FALSE(phone_number_compare_strict("080-1234-5678", "+819012345678")); EXPECT_TRUE(phone_number_compare_strict("650-000-3456", "16500003456")); EXPECT_TRUE(phone_number_compare_strict("011 1 7005554141", "+17005554141")); EXPECT_FALSE(phone_number_compare_strict("011 11 7005554141", "+17005554141")); EXPECT_FALSE(phone_number_compare_strict("+44 207 792 3490", "00 207 792 3490")); +} + +TEST(PhoneNumberUtils, compareStrictNamp1661) { // This is not related to Thailand case. NAMP "1" + region code "661". EXPECT_TRUE(phone_number_compare_strict("16610001234", "6610001234")); +} +TEST(PhoneNumberUtils, compareStrictAlphaDifferent) { // We also need to compare two alpha addresses to make sure two different strings // aren't treated as the same addresses. This is relevant to SMS as SMS sender may // contain all alpha chars. EXPECT_FALSE(phone_number_compare_strict("abcd", "bcde")); +} +TEST(PhoneNumberUtils, compareStrictAlphaNumericSame) { // in the U.S. people often use alpha in the phone number to easily remember it // (e.g. 800-flowers would be dialed as 800-356-9377). Since we accept this form of // phone number in Contacts and others, we should make sure the comparison method // handle them. EXPECT_TRUE(phone_number_compare_strict("1-800-flowers", "800-flowers")); +} - // TODO: we currently do not support this comparison. It maybe nice to support this - // TODO: in the future. - // EXPECT_TRUE("1-800-flowers", "1-800-356-9377") - +TEST(PhoneNumberUtils, compareStrictAlphaNumericDifferent) { EXPECT_FALSE(phone_number_compare_strict("1-800-flowers", "1-800-abcdefg")); +} +// TODO: we currently do not support this comparison. +// TODO: It maybe be nice to support this in the future. +//TEST(PhoneNumberUtils, compareStrictLettersToDigits) { +// EXPECT_TRUE("1-800-flowers", "1-800-356-9377") +//} + +TEST(PhoneNumberUtils, compareStrictWrongPrefix) { // Currently we cannot get this test through (Japanese trunk prefix is 0, // but there is no sensible way to know it now (as of 2009-6-12)... - // EXPECT_FALSE("290-1234-5678", "+819012345678"); + // EXPECT_FALSE(phone_number_compare_strict("290-1234-5678", "+819012345678")); + // EXPECT_FALSE(phone_number_compare_strict("+819012345678", "290-1234-5678")); + + // USA + EXPECT_FALSE(phone_number_compare_strict("550-450-3605", "+14504503605")); + + EXPECT_FALSE(phone_number_compare_strict("550-450-3605", "+15404503605")); + EXPECT_FALSE(phone_number_compare_strict("550-450-3605", "+15514503605")); + EXPECT_FALSE(phone_number_compare_strict("5504503605", "+14504503605")); + + EXPECT_FALSE(phone_number_compare_strict("+14504503605", "550-450-3605")); + EXPECT_FALSE(phone_number_compare_strict("+15404503605", "550-450-3605")); + EXPECT_FALSE(phone_number_compare_strict("+15514503605", "550-450-3605")); + EXPECT_FALSE(phone_number_compare_strict("+14504503605", "5504503605")); } TEST(PhoneNumberUtils, phone_number_stripped_reversed_inter) { |