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 import android.test.AndroidTestCase; 23 24 /** 25 * Test cases for {@link com.android.providers.contacts.DefaultCallLogInsertionHelper}. 26 */ 27 public class CallLogInsertionHelperTest extends AndroidTestCase { 28 29 /** 30 * The default insertion helper under test. 31 */ 32 private CallLogInsertionHelper mInsertionHelper = 33 DefaultCallLogInsertionHelper.getInstance(this.getContext()); 34 35 /** 36 * Tests cases where valid, normalizable phone numbers are provided. 37 */ 38 public void testValidNumber() { 39 checkNormalization("650-555-1212", "+16505551212"); 40 checkNormalization("1-650-555-1212", "+16505551212"); 41 checkNormalization("+16505551212", "+16505551212"); 42 checkNormalization("011-81-3-6384-9000", "+81363849000"); 43 } 44 45 /** 46 * Test cases where invalid unformatted numbers are entered. 47 */ 48 public void testInvalidNumber() { 49 checkNormalization("", null); 50 // Invalid area code. 51 checkNormalization("663-555-1212", null); 52 // No area code. 53 checkNormalization("555-1212", null); 54 // Number as it should be dialed from Japan. 55 checkNormalization("03-6384-9000", null); 56 // SIP address 57 checkNormalization("test (at) sip.org", null); 58 } 59 60 /** 61 * Runs the DefaultCallLogInsertionHelper to determine if it produces the correct normalized 62 * phone number. 63 * 64 * @param number The unformatted phone number. 65 * @param expectedNormalized The expected normalized number. 66 */ 67 private void checkNormalization(String number, String expectedNormalized) { 68 ContentValues values = new ContentValues(); 69 values.put(Calls.NUMBER, number); 70 mInsertionHelper.addComputedValues(values); 71 72 assertEquals(expectedNormalized, values.getAsString(Calls.CACHED_NORMALIZED_NUMBER)); 73 } 74 } 75