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 // 18 // Note that similar (or almost same) tests exist in Java side (See 19 // DatabaseGeneralTest.java in AndroidTests). The differences are: 20 // - this test is quite easy to do (You can do it in your Unix PC) 21 // - this test is not automatically executed by build servers 22 // 23 // You should also execute the test before submitting this. 24 // 25 26 #include "PhoneNumberUtils.h" 27 28 #include <stdio.h> 29 #include <string.h> 30 31 #include <gtest/gtest.h> 32 33 using namespace android; 34 35 36 TEST(PhoneNumberUtils, compareStrictNullOrEmpty) { 37 EXPECT_TRUE(phone_number_compare_strict(NULL, NULL)); 38 EXPECT_TRUE(phone_number_compare_strict("", NULL)); 39 EXPECT_TRUE(phone_number_compare_strict(NULL, "")); 40 EXPECT_TRUE(phone_number_compare_strict("", "")); 41 } 42 43 TEST(PhoneNumberUtils, compareStrictDigitsSame) { 44 EXPECT_TRUE(phone_number_compare_strict("999", "999")); 45 EXPECT_TRUE(phone_number_compare_strict("119", "119")); 46 } 47 48 TEST(PhoneNumberUtils, compareStrictDigitsDifferent) { 49 EXPECT_FALSE(phone_number_compare_strict("123456789", "923456789")); 50 EXPECT_FALSE(phone_number_compare_strict("123456789", "123456781")); 51 EXPECT_FALSE(phone_number_compare_strict("123456789", "1234567890")); 52 EXPECT_FALSE(phone_number_compare_strict("123456789", "0123456789")); 53 } 54 55 TEST(PhoneNumberUtils, compareStrictGoogle) { 56 EXPECT_TRUE(phone_number_compare_strict("650-253-0000", "6502530000")); 57 EXPECT_TRUE(phone_number_compare_strict("650-253-0000", "650 253 0000")); 58 EXPECT_TRUE(phone_number_compare_strict("650 253 0000", "6502530000")); 59 } 60 61 TEST(PhoneNumberUtils, compareStrictTrunkPrefixUs) { 62 // trunk (NDD) prefix must be properly handled in US 63 EXPECT_TRUE(phone_number_compare_strict("650-253-0000", "1-650-253-0000")); 64 EXPECT_TRUE(phone_number_compare_strict("650-253-0000", " 1-650-253-0000")); 65 EXPECT_FALSE(phone_number_compare_strict("650-253-0000", "11-650-253-0000")); 66 EXPECT_FALSE(phone_number_compare_strict("650-253-0000", "0-650-253-0000")); 67 EXPECT_FALSE(phone_number_compare_strict("555-4141", "+1-700-555-4141")); 68 69 EXPECT_TRUE(phone_number_compare_strict("+1 650-253-0000", "6502530000")); 70 EXPECT_TRUE(phone_number_compare_strict("001 650-253-0000", "6502530000")); 71 EXPECT_TRUE(phone_number_compare_strict("0111 650-253-0000", "6502530000")); 72 } 73 74 TEST(PhoneNumberUtils, compareStrictDifferentCountryCode) { 75 EXPECT_FALSE(phone_number_compare_strict("+19012345678", "+819012345678")); 76 } 77 78 TEST(PhoneNumberUtils, compareStrictTrunkJapan) { 79 EXPECT_TRUE(phone_number_compare_strict("+31771234567", "0771234567")); 80 EXPECT_TRUE(phone_number_compare_strict("090-1234-5678", "+819012345678")); 81 EXPECT_TRUE(phone_number_compare_strict("090(1234)5678", "+819012345678")); 82 EXPECT_TRUE(phone_number_compare_strict("090-1234-5678", "+81-90-1234-5678")); 83 84 EXPECT_TRUE(phone_number_compare_strict("+819012345678", "090-1234-5678")); 85 EXPECT_TRUE(phone_number_compare_strict("+819012345678", "090(1234)5678")); 86 EXPECT_TRUE(phone_number_compare_strict("+81-90-1234-5678", "090-1234-5678")); 87 } 88 89 TEST(PhoneNumberUtils, compareStrictTrunkRussia) { 90 EXPECT_TRUE(phone_number_compare_strict("+79161234567", "89161234567")); 91 } 92 93 TEST(PhoneNumberUtils, compareStrictTrunkFrance) { 94 EXPECT_TRUE(phone_number_compare_strict("+33123456789", "0123456789")); 95 } 96 97 TEST(PhoneNumberUtils, compareStrictTrunkNetherlandsCities) { 98 EXPECT_TRUE(phone_number_compare_strict("+31771234567", "0771234567")); 99 } 100 101 // TODO: Two digit trunk prefixes are not handled 102 //TEST(PhoneNumberUtils, compareStrictTrunkHungary) { 103 // EXPECT_TRUE(phone_number_compare_strict("+36 1 234 5678", "06 1234-5678")); 104 //} 105 106 // TODO: Two digit trunk prefixes are not handled 107 //TEST(PhoneNumberUtils, compareStrictTrunkMexico) { 108 // EXPECT_TRUE(phone_number_compare_strict("+52 55 1234 5678", "01 55 1234 5678")); 109 //} 110 111 // TODO: Two digit trunk prefixes are not handled 112 //TEST(PhoneNumberUtils, compareStrictTrunkMongolia) { 113 // EXPECT_TRUE(phone_number_compare_strict("+976 1 123 4567", "01 1 23 4567")); 114 // EXPECT_TRUE(phone_number_compare_strict("+976 2 234 5678", "02 2 34 5678")); 115 //} 116 117 TEST(PhoneNumberUtils, compareStrictTrunkIgnoreJapan) { 118 // Trunk prefix must not be ignored in Japan 119 EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "90-1234-5678")); 120 EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "080-1234-5678")); 121 EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "190-1234-5678")); 122 EXPECT_FALSE(phone_number_compare_strict("090-1234-5678", "890-1234-5678")); 123 EXPECT_FALSE(phone_number_compare_strict("080-1234-5678", "+819012345678")); 124 EXPECT_FALSE(phone_number_compare_strict("+81-90-1234-5678", "+81-090-1234-5678")); 125 } 126 127 TEST(PhoneNumberUtils, compareStrictInternationalNational) { 128 EXPECT_TRUE(phone_number_compare_strict("+593(800)123-1234", "8001231234")); 129 } 130 131 TEST(PhoneNumberUtils, compareStrictTwoContinuousZeros) { 132 // Two continuous 0 at the begining of the phone string should not be 133 // treated as trunk prefix. 134 EXPECT_FALSE(phone_number_compare_strict("008001231234", "8001231234")); 135 } 136 137 TEST(PhoneNumberUtils, compareStrictCallerIdThailandUs) { 138 // Test broken caller ID seen on call from Thailand to the US 139 EXPECT_TRUE(phone_number_compare_strict("+66811234567", "166811234567")); 140 // Confirm that the bug found before does not re-appear. 141 EXPECT_FALSE(phone_number_compare_strict("080-1234-5678", "+819012345678")); 142 EXPECT_TRUE(phone_number_compare_strict("650-000-3456", "16500003456")); 143 EXPECT_TRUE(phone_number_compare_strict("011 1 7005554141", "+17005554141")); 144 EXPECT_FALSE(phone_number_compare_strict("011 11 7005554141", "+17005554141")); 145 EXPECT_FALSE(phone_number_compare_strict("+44 207 792 3490", "00 207 792 3490")); 146 } 147 148 TEST(PhoneNumberUtils, compareStrictNamp1661) { 149 // This is not related to Thailand case. NAMP "1" + region code "661". 150 EXPECT_TRUE(phone_number_compare_strict("16610001234", "6610001234")); 151 } 152 153 TEST(PhoneNumberUtils, compareStrictAlphaDifferent) { 154 // We also need to compare two alpha addresses to make sure two different strings 155 // aren't treated as the same addresses. This is relevant to SMS as SMS sender may 156 // contain all alpha chars. 157 EXPECT_FALSE(phone_number_compare_strict("abcd", "bcde")); 158 } 159 160 TEST(PhoneNumberUtils, compareStrictAlphaNumericSame) { 161 // in the U.S. people often use alpha in the phone number to easily remember it 162 // (e.g. 800-flowers would be dialed as 800-356-9377). Since we accept this form of 163 // phone number in Contacts and others, we should make sure the comparison method 164 // handle them. 165 EXPECT_TRUE(phone_number_compare_strict("1-800-flowers", "800-flowers")); 166 } 167 168 TEST(PhoneNumberUtils, compareStrictAlphaNumericDifferent) { 169 EXPECT_FALSE(phone_number_compare_strict("1-800-flowers", "1-800-abcdefg")); 170 } 171 172 // TODO: we currently do not support this comparison. 173 // TODO: It maybe be nice to support this in the future. 174 //TEST(PhoneNumberUtils, compareStrictLettersToDigits) { 175 // EXPECT_TRUE("1-800-flowers", "1-800-356-9377") 176 //} 177 178 TEST(PhoneNumberUtils, compareStrictWrongPrefix) { 179 // Currently we cannot get this test through (Japanese trunk prefix is 0, 180 // but there is no sensible way to know it now (as of 2009-6-12)... 181 // EXPECT_FALSE(phone_number_compare_strict("290-1234-5678", "+819012345678")); 182 // EXPECT_FALSE(phone_number_compare_strict("+819012345678", "290-1234-5678")); 183 184 // USA 185 EXPECT_FALSE(phone_number_compare_strict("550-450-3605", "+14504503605")); 186 187 EXPECT_FALSE(phone_number_compare_strict("550-450-3605", "+15404503605")); 188 EXPECT_FALSE(phone_number_compare_strict("550-450-3605", "+15514503605")); 189 EXPECT_FALSE(phone_number_compare_strict("5504503605", "+14504503605")); 190 191 EXPECT_FALSE(phone_number_compare_strict("+14504503605", "550-450-3605")); 192 EXPECT_FALSE(phone_number_compare_strict("+15404503605", "550-450-3605")); 193 EXPECT_FALSE(phone_number_compare_strict("+15514503605", "550-450-3605")); 194 EXPECT_FALSE(phone_number_compare_strict("+14504503605", "5504503605")); 195 } 196 197 TEST(PhoneNumberUtils, phone_number_stripped_reversed_inter) { 198 char out[6]; 199 int outlen; 200 201 #define ASSERT_STRIPPED_REVERSE(input, expected) \ 202 phone_number_stripped_reversed_inter((input), out, sizeof(out), &outlen); \ 203 out[outlen] = 0; \ 204 ASSERT_STREQ((expected), (out)); \ 205 206 ASSERT_STRIPPED_REVERSE("", ""); 207 208 ASSERT_STRIPPED_REVERSE("123", "321"); 209 ASSERT_STRIPPED_REVERSE("123*N#", "#N*321"); 210 211 // Buffer overflow 212 ASSERT_STRIPPED_REVERSE("1234567890", "098765"); 213 214 // Only one plus is copied 215 ASSERT_STRIPPED_REVERSE("1+2+", "+21"); 216 217 // Pause/wait in the phone number 218 ASSERT_STRIPPED_REVERSE("12;34", "21"); 219 220 // Ignoring non-dialable 221 ASSERT_STRIPPED_REVERSE("1A2 3?4", "4321"); 222 } 223