Home | History | Annotate | Download | only in phone
      1 /*
      2  * Copyright (C) 2009 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 // Need to be in this package to access package methods.
     18 package com.android.phone;
     19 import android.content.Context;
     20 import android.test.AndroidTestCase;
     21 import android.test.suitebuilder.annotation.SmallTest;
     22 import android.util.Log;
     23 import com.android.internal.telephony.CallerInfo;
     24 import com.android.phone.PhoneUtils;
     25 import static com.android.internal.telephony.PhoneConstants.PRESENTATION_ALLOWED;
     26 import static com.android.internal.telephony.PhoneConstants.PRESENTATION_PAYPHONE;
     27 import static com.android.internal.telephony.PhoneConstants.PRESENTATION_RESTRICTED;
     28 import static com.android.internal.telephony.PhoneConstants.PRESENTATION_UNKNOWN;
     29 
     30 // Test suite for the Caller Name Presentation (CNAP) handling.
     31 // See AndroidManifest.xml how to run these tests.
     32 public class CnapTest extends AndroidTestCase {
     33     private static final String TAG = "CnapTest";
     34     private Context mContext;
     35     private CallerInfo mCallerInfo;
     36     // TODO: This string should be loaded from the phone package and
     37     // not hardcoded.
     38     private String mUnknown = "Unknown";
     39 
     40     @Override
     41     protected void setUp() throws Exception {
     42         super.setUp();
     43         mContext = getContext();
     44         mCallerInfo = new CallerInfo();
     45     }
     46 
     47     // Checks the cnap 'ABSENT NUMBER' is mapped to the unknown presentation.
     48     @SmallTest
     49     public void testAbsentNumberIsMappedToUnknown() throws Exception {
     50         String num = modifyForSpecialCnapCases("ABSENT NUMBER", PRESENTATION_ALLOWED);
     51         assertIsUnknown(num);
     52     }
     53 
     54     // HELPERS
     55 
     56     /**
     57      * Checks the number and CallerInfo structure indicate the number
     58      * is unknown.
     59      */
     60     private void assertIsUnknown(String number) {
     61         assertEquals(mUnknown, number);
     62         assertEquals(PRESENTATION_UNKNOWN, mCallerInfo.numberPresentation);
     63         // TODO: cnapName and name presentation should be set to
     64         // unknown. At least I cannot see why it shouldn't be the case
     65         // assertEquals(mUnknown, mCallerInfo.cnapName);
     66         // assertEquals(PRESENTATION_UNKNOWN, mCallerInfo.namePresentation);
     67     }
     68 
     69     /**
     70      * Shorthand for PhoneUtils.modifyForSpecialCnapCases(mContext, mCallerInfo, ...)
     71      */
     72     private String modifyForSpecialCnapCases(String number, int presentation) {
     73         return PhoneUtils.modifyForSpecialCnapCases(
     74             mContext, mCallerInfo, number, presentation);
     75     }
     76 }
     77