From 006d071bd477768b4685385d15b3385f6d2e834d Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Tue, 30 Apr 2013 17:49:03 -0700 Subject: Apply NANP logic to numbers with a +1 country code Bug 8769688 Change-Id: I4aadd0f9e5495fb1b604910306dfd918d1540136 --- .../dialer/dialpad/SmartDialNameMatcherTest.java | 11 ++++++++++ .../android/dialer/dialpad/SmartDialTrieTest.java | 24 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'tests/src') diff --git a/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java b/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java index 83b856059..eb6f05087 100644 --- a/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java +++ b/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java @@ -201,6 +201,17 @@ public class SmartDialNameMatcherTest extends TestCase { checkMatchesNumber("1-510-333-7596", "5103337596", true, true, 2, 14); checkMatchesNumber("1-510-333-7596", "3337596", true, true, 6, 14); + // An 11 digit number prefixed with +1 should be matched by the 10 digit number, as well as + // the 7 digit number (without area code) + checkMatchesNumber("+1-510-333-7596", "5103337596", true, true, 3, 15); + checkMatchesNumber("+1-510-333-7596", "3337596", true, true, 7, 15); + checkMatchesNumber("+1-510-333-7596", "103337596", false, true, 0, 0); + checkMatchesNumber("+1-510-333-7596", "337596", false, true, 0, 0); + checkMatchesNumber("+1510 3337596", "5103337596", true, true, 2, 13); + checkMatchesNumber("+1510 3337596", "3337596", true, true, 6, 13); + checkMatchesNumber("+1510 3337596", "103337596", false, true, 0, 0); + checkMatchesNumber("+1510 3337596", "37596", false, true, 0, 0); + // Invalid NANP numbers should not be matched checkMatchesNumber("1-510-333-759", "510333759", false, true, 0, 0); checkMatchesNumber("510-333-759", "333759", false, true, 0, 0); diff --git a/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java b/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java index 876e00de7..f0c4cbb46 100644 --- a/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java +++ b/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java @@ -294,7 +294,6 @@ public class SmartDialTrieTest extends TestCase{ // Tests special case handling for NANP numbers public void testPutNumbersNANP() { - final SmartDialTrie trie = new SmartDialTrie(true /* formatNanp */); // Unformatted number with 1 prefix final ContactNumber contactno1 = new ContactNumber(0, "James", "16503337596", "0", 1); @@ -340,6 +339,29 @@ public class SmartDialTrieTest extends TestCase{ // But the NANP special case handling should not work assertFalse(checkContains(trie, contactno6, "123123")); + // Number with +1 prefix and is a NANP number + final ContactNumber contactno7 = new ContactNumber(0, "Mike", "+1-510-284-9170", "0", 1); + trie.put(contactno7); + assertTrue(checkContains(trie, contactno7, "15102849170")); + assertTrue(checkContains(trie, contactno7, "5102849170")); + assertTrue(checkContains(trie, contactno7, "2849170")); + assertFalse(checkContains(trie, contactno7, "849170")); + assertFalse(checkContains(trie, contactno7, "10849170")); + + // Number with +1 prefix but is an invalid NANP number + final ContactNumber contactno8 = new ContactNumber(0, "Invalid", "+1-510-284-917", "0", 1); + trie.put(contactno8); + assertTrue(checkContains(trie, contactno8, "1510284917")); + assertTrue(checkContains(trie, contactno8, "510284917")); + assertFalse(checkContains(trie, contactno8, "2849170")); + + // Number with invalid country code prefix + final ContactNumber contactno9 = new ContactNumber(0, "Inv", "+857-510-284-9170", "0", 1); + trie.put(contactno9); + assertTrue(checkContains(trie, contactno9, "8575102849170")); + assertFalse(checkContains(trie, contactno9, "5102849170")); + assertFalse(checkContains(trie, contactno9, "2849170")); + // If user's region is determined to be not in North America, then the NANP number // workarounds should not be applied final SmartDialTrie trieNonNANP = new SmartDialTrie(); -- cgit v1.2.3