• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.providers.contacts;
18 
19 import android.content.ContentValues;
20 import android.provider.CallLog.Calls;
21 
22 /**
23  * Test cases for {@link com.android.providers.contacts.DefaultCallLogInsertionHelper}.
24  */
25 public class CallLogInsertionHelperTest extends FixedAndroidTestCase {
26 
27     /**
28      * The default insertion helper under test.
29      */
30     private CallLogInsertionHelper mInsertionHelper =
31             DefaultCallLogInsertionHelper.getInstance(this.getContext());
32 
33     /**
34      * Tests cases where valid, normalizable phone numbers are provided.
35      */
testValidNumber()36     public void testValidNumber() {
37         checkNormalization("650-555-1212", "+16505551212");
38         checkNormalization("1-650-555-1212", "+16505551212");
39         checkNormalization("+16505551212", "+16505551212");
40         checkNormalization("011-81-3-6384-9000", "+81363849000");
41     }
42 
43     /**
44      * Test cases where invalid unformatted numbers are entered.
45      */
testInvalidNumber()46     public void testInvalidNumber() {
47         checkNormalization("", null);
48         // Invalid area code.
49         checkNormalization("663-555-1212", null);
50         // No area code.
51         checkNormalization("555-1212", null);
52         // Number as it should be dialed from Japan.
53         checkNormalization("03-6384-9000", null);
54         // SIP address
55         checkNormalization("test@sip.org", null);
56     }
57 
58     /**
59      * Runs the DefaultCallLogInsertionHelper to determine if it produces the correct normalized
60      * phone number.
61      *
62      * @param number The unformatted phone number.
63      * @param expectedNormalized The expected normalized number.
64      */
checkNormalization(String number, String expectedNormalized)65     private void checkNormalization(String number, String expectedNormalized) {
66         ContentValues values = new ContentValues();
67         values.put(Calls.NUMBER, number);
68         mInsertionHelper.addComputedValues(values);
69 
70         assertEquals(expectedNormalized, values.getAsString(Calls.CACHED_NORMALIZED_NUMBER));
71     }
72 }
73