Home | History | Annotate | Download | only in phonenumbers
      1 /*
      2  * Copyright (C) 2011 The Libphonenumber Authors
      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.i18n.phonenumbers;
     18 
     19 /**
     20  * Unit tests for ShortNumberUtil.java
     21  *
     22  * @author Shaopeng Jia
     23  */
     24 public class ShortNumberUtilTest extends TestMetadataTestCase {
     25   private ShortNumberUtil shortUtil;
     26 
     27   public ShortNumberUtilTest() {
     28     shortUtil = new ShortNumberUtil(phoneUtil);
     29   }
     30 
     31   public void testConnectsToEmergencyNumber_US() {
     32     assertTrue(shortUtil.connectsToEmergencyNumber("911", RegionCode.US));
     33     assertTrue(shortUtil.connectsToEmergencyNumber("119", RegionCode.US));
     34     assertFalse(shortUtil.connectsToEmergencyNumber("999", RegionCode.US));
     35   }
     36 
     37   public void testConnectsToEmergencyNumberLongNumber_US() {
     38     assertTrue(shortUtil.connectsToEmergencyNumber("9116666666", RegionCode.US));
     39     assertTrue(shortUtil.connectsToEmergencyNumber("1196666666", RegionCode.US));
     40     assertFalse(shortUtil.connectsToEmergencyNumber("9996666666", RegionCode.US));
     41   }
     42 
     43   public void testConnectsToEmergencyNumberWithFormatting_US() {
     44     assertTrue(shortUtil.connectsToEmergencyNumber("9-1-1", RegionCode.US));
     45     assertTrue(shortUtil.connectsToEmergencyNumber("1-1-9", RegionCode.US));
     46     assertFalse(shortUtil.connectsToEmergencyNumber("9-9-9", RegionCode.US));
     47   }
     48 
     49   public void testConnectsToEmergencyNumberWithPlusSign_US() {
     50     assertFalse(shortUtil.connectsToEmergencyNumber("+911", RegionCode.US));
     51     assertFalse(shortUtil.connectsToEmergencyNumber("\uFF0B911", RegionCode.US));
     52     assertFalse(shortUtil.connectsToEmergencyNumber(" +911", RegionCode.US));
     53     assertFalse(shortUtil.connectsToEmergencyNumber("+119", RegionCode.US));
     54     assertFalse(shortUtil.connectsToEmergencyNumber("+999", RegionCode.US));
     55   }
     56 
     57   public void testConnectsToEmergencyNumber_BR() {
     58     assertTrue(shortUtil.connectsToEmergencyNumber("911", RegionCode.BR));
     59     assertTrue(shortUtil.connectsToEmergencyNumber("190", RegionCode.BR));
     60     assertFalse(shortUtil.connectsToEmergencyNumber("999", RegionCode.BR));
     61   }
     62 
     63   public void testConnectsToEmergencyNumberLongNumber_BR() {
     64     // Brazilian emergency numbers don't work when additional digits are appended.
     65     assertFalse(shortUtil.connectsToEmergencyNumber("9111", RegionCode.BR));
     66     assertFalse(shortUtil.connectsToEmergencyNumber("1900", RegionCode.BR));
     67     assertFalse(shortUtil.connectsToEmergencyNumber("9996", RegionCode.BR));
     68   }
     69 
     70   public void testConnectsToEmergencyNumber_AO() {
     71     // Angola doesn't have any metadata for emergency numbers in the test metadata.
     72     assertFalse(shortUtil.connectsToEmergencyNumber("911", RegionCode.AO));
     73     assertFalse(shortUtil.connectsToEmergencyNumber("222123456", RegionCode.AO));
     74     assertFalse(shortUtil.connectsToEmergencyNumber("923123456", RegionCode.AO));
     75   }
     76 
     77   public void testConnectsToEmergencyNumber_ZW() {
     78     // Zimbabwe doesn't have any metadata in the test metadata.
     79     assertFalse(shortUtil.connectsToEmergencyNumber("911", RegionCode.ZW));
     80     assertFalse(shortUtil.connectsToEmergencyNumber("01312345", RegionCode.ZW));
     81     assertFalse(shortUtil.connectsToEmergencyNumber("0711234567", RegionCode.ZW));
     82   }
     83 
     84   public void testIsEmergencyNumber_US() {
     85     assertTrue(shortUtil.isEmergencyNumber("911", RegionCode.US));
     86     assertTrue(shortUtil.isEmergencyNumber("119", RegionCode.US));
     87     assertFalse(shortUtil.isEmergencyNumber("999", RegionCode.US));
     88   }
     89 
     90   public void testIsEmergencyNumberLongNumber_US() {
     91     assertFalse(shortUtil.isEmergencyNumber("9116666666", RegionCode.US));
     92     assertFalse(shortUtil.isEmergencyNumber("1196666666", RegionCode.US));
     93     assertFalse(shortUtil.isEmergencyNumber("9996666666", RegionCode.US));
     94   }
     95 
     96   public void testIsEmergencyNumberWithFormatting_US() {
     97     assertTrue(shortUtil.isEmergencyNumber("9-1-1", RegionCode.US));
     98     assertTrue(shortUtil.isEmergencyNumber("*911", RegionCode.US));
     99     assertTrue(shortUtil.isEmergencyNumber("1-1-9", RegionCode.US));
    100     assertTrue(shortUtil.isEmergencyNumber("*119", RegionCode.US));
    101     assertFalse(shortUtil.isEmergencyNumber("9-9-9", RegionCode.US));
    102     assertFalse(shortUtil.isEmergencyNumber("*999", RegionCode.US));
    103   }
    104 
    105   public void testIsEmergencyNumberWithPlusSign_US() {
    106     assertFalse(shortUtil.isEmergencyNumber("+911", RegionCode.US));
    107     assertFalse(shortUtil.isEmergencyNumber("\uFF0B911", RegionCode.US));
    108     assertFalse(shortUtil.isEmergencyNumber(" +911", RegionCode.US));
    109     assertFalse(shortUtil.isEmergencyNumber("+119", RegionCode.US));
    110     assertFalse(shortUtil.isEmergencyNumber("+999", RegionCode.US));
    111   }
    112 
    113   public void testIsEmergencyNumber_BR() {
    114     assertTrue(shortUtil.isEmergencyNumber("911", RegionCode.BR));
    115     assertTrue(shortUtil.isEmergencyNumber("190", RegionCode.BR));
    116     assertFalse(shortUtil.isEmergencyNumber("999", RegionCode.BR));
    117   }
    118 
    119   public void testIsEmergencyNumberLongNumber_BR() {
    120     assertFalse(shortUtil.isEmergencyNumber("9111", RegionCode.BR));
    121     assertFalse(shortUtil.isEmergencyNumber("1900", RegionCode.BR));
    122     assertFalse(shortUtil.isEmergencyNumber("9996", RegionCode.BR));
    123   }
    124 
    125   public void testIsEmergencyNumber_AO() {
    126     // Angola doesn't have any metadata for emergency numbers in the test metadata.
    127     assertFalse(shortUtil.isEmergencyNumber("911", RegionCode.AO));
    128     assertFalse(shortUtil.isEmergencyNumber("222123456", RegionCode.AO));
    129     assertFalse(shortUtil.isEmergencyNumber("923123456", RegionCode.AO));
    130   }
    131 
    132   public void testIsEmergencyNumber_ZW() {
    133     // Zimbabwe doesn't have any metadata in the test metadata.
    134     assertFalse(shortUtil.isEmergencyNumber("911", RegionCode.ZW));
    135     assertFalse(shortUtil.isEmergencyNumber("01312345", RegionCode.ZW));
    136     assertFalse(shortUtil.isEmergencyNumber("0711234567", RegionCode.ZW));
    137   }
    138 }
    139