1 /* 2 * Copyright (C) 2017 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, compareLooseNullOrEmpty) { 37 EXPECT_FALSE(phone_number_compare_loose(NULL, NULL)); 38 EXPECT_FALSE(phone_number_compare_loose("", NULL)); 39 EXPECT_FALSE(phone_number_compare_loose(NULL, "")); 40 EXPECT_FALSE(phone_number_compare_loose("", "")); 41 } 42 43 TEST(PhoneNumberUtils, compareLooseDigitsSame) { 44 EXPECT_TRUE(phone_number_compare_loose("999", "999")); 45 EXPECT_TRUE(phone_number_compare_loose("119", "119")); 46 } 47 48 TEST(PhoneNumberUtils, compareLooseDigitsDifferent) { 49 EXPECT_FALSE(phone_number_compare_loose("123456789", "923456789")); 50 EXPECT_FALSE(phone_number_compare_loose("123456789", "123456781")); 51 EXPECT_FALSE(phone_number_compare_loose("123456789", "1234567890")); 52 EXPECT_TRUE(phone_number_compare_loose("123456789", "0123456789")); 53 } 54 55 TEST(PhoneNumberUtils, compareLooseGoogle) { 56 EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "6502530000")); 57 EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "650 253 0000")); 58 EXPECT_TRUE(phone_number_compare_loose("650 253 0000", "6502530000")); 59 } 60 61 TEST(PhoneNumberUtils, compareLooseTrunkPrefixUs) { 62 // trunk (NDD) prefix must be properly handled in US 63 EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "1-650-253-0000")); 64 EXPECT_TRUE(phone_number_compare_loose("650-253-0000", " 1-650-253-0000")); 65 66 EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "11-650-253-0000")); 67 EXPECT_TRUE(phone_number_compare_loose("650-253-0000", "0-650-253-0000")); 68 EXPECT_TRUE(phone_number_compare_loose("555-4141", "+1-700-555-4141")); 69 70 EXPECT_TRUE(phone_number_compare_loose("+1 650-253-0000", "6502530000")); 71 EXPECT_TRUE(phone_number_compare_loose("001 650-253-0000", "6502530000")); 72 EXPECT_TRUE(phone_number_compare_loose("0111 650-253-0000", "6502530000")); 73 } 74 75 TEST(PhoneNumberUtils, compareLooseDifferentCountryCode) { 76 EXPECT_FALSE(phone_number_compare_loose("+19012345678", "+819012345678")); 77 } 78 79 TEST(PhoneNumberUtils, compareLooseTrunkJapan) { 80 EXPECT_TRUE(phone_number_compare_loose("+31771234567", "0771234567")); 81 EXPECT_TRUE(phone_number_compare_loose("090-1234-5678", "+819012345678")); 82 EXPECT_TRUE(phone_number_compare_loose("090(1234)5678", "+819012345678")); 83 EXPECT_TRUE(phone_number_compare_loose("090-1234-5678", "+81-90-1234-5678")); 84 85 EXPECT_TRUE(phone_number_compare_loose("+819012345678", "090-1234-5678")); 86 EXPECT_TRUE(phone_number_compare_loose("+819012345678", "090(1234)5678")); 87 EXPECT_TRUE(phone_number_compare_loose("+81-90-1234-5678", "090-1234-5678")); 88 } 89 90 TEST(PhoneNumberUtils, compareLooseTrunkRussia) { 91 EXPECT_TRUE(phone_number_compare_loose("+79161234567", "89161234567")); 92 93 } 94 95 TEST(PhoneNumberUtils, compareLooseTrunkFrance) { 96 EXPECT_TRUE(phone_number_compare_loose("+33123456789", "0123456789")); 97 } 98 99 TEST(PhoneNumberUtils, compareLooseTrunkHungary) { 100 EXPECT_TRUE(phone_number_compare_loose("+36 1 234 5678", "06 1234-5678")); 101 } 102 103 TEST(PhoneNumberUtils, compareLooseTrunkMexico) { 104 EXPECT_TRUE(phone_number_compare_loose("+52 55 1234 5678", "01 55 1234 5678")); 105 } 106 107 TEST(PhoneNumberUtils, compareLooseTrunkMongolia) { 108 EXPECT_TRUE(phone_number_compare_loose("+976 1 123 4567", "01 1 23 4567")); 109 EXPECT_TRUE(phone_number_compare_loose("+976 2 234 5678", "02 2 34 5678")); 110 } 111 112 TEST(PhoneNumberUtils, compareLooseTrunkNetherlandsCities) { 113 EXPECT_TRUE(phone_number_compare_loose("+31771234567", "0771234567")); 114 } 115 116 TEST(PhoneNumberUtils, compareLooseInternationalJapan) { 117 EXPECT_FALSE(phone_number_compare_loose("+818012345678", "+819012345678")); 118 EXPECT_TRUE(phone_number_compare_loose("+819012345678", "+819012345678")); 119 } 120 121 TEST(PhoneNumberUtils, compareLooseTrunkIgnoreJapan) { 122 // Trunk prefix must not be ignored in Japan 123 EXPECT_TRUE(phone_number_compare_loose("090-1234-5678", "90-1234-5678")); 124 EXPECT_FALSE(phone_number_compare_loose("090-1234-5678", "080-1234-5678")); 125 EXPECT_FALSE(phone_number_compare_loose("090-1234-5678", "190-1234-5678")); 126 EXPECT_FALSE(phone_number_compare_loose("090-1234-5678", "890-1234-5678")); 127 EXPECT_FALSE(phone_number_compare_loose("080-1234-5678", "+819012345678")); 128 EXPECT_FALSE(phone_number_compare_loose("+81-90-1234-5678", "+81-090-1234-5678")); 129 } 130 131 TEST(PhoneNumberUtils, compareLooseInternationalNational) { 132 EXPECT_TRUE(phone_number_compare_loose("+593(800)123-1234", "8001231234")); 133 } 134 135 TEST(PhoneNumberUtils, compareLooseTwoContinuousZeros) { 136 // Two continuous 0 at the begining of the phone string should be 137 // treated as trunk prefix for caller id purposes. 138 EXPECT_TRUE(phone_number_compare_loose("008001231234", "8001231234")); 139 } 140 141 TEST(PhoneNumberUtils, compareLooseCallerIdThailandUs) { 142 // Test broken caller ID seen on call from Thailand to the US 143 EXPECT_TRUE(phone_number_compare_loose("+66811234567", "166811234567")); 144 // Confirm that the bug found before does not re-appear. 145 EXPECT_TRUE(phone_number_compare_loose("650-000-3456", "16500003456")); 146 EXPECT_TRUE(phone_number_compare_loose("011 1 7005554141", "+17005554141")); 147 EXPECT_FALSE(phone_number_compare_loose("011 11 7005554141", "+17005554141")); 148 EXPECT_TRUE(phone_number_compare_loose("+44 207 792 3490", "00 207 792 3490")); 149 } 150 151 TEST(PhoneNumberUtils, compareLooseNamp1661) { 152 // This is not related to Thailand case. NAMP "1" + region code "661". 153 EXPECT_TRUE(phone_number_compare_loose("16610001234", "6610001234")); 154 } 155 156 TEST(PhoneNumberUtils, compareLooseAlphaDifferent) { 157 // We also need to compare two alpha addresses to make sure two different strings 158 // aren't treated as the same addresses. This is relevant to SMS as SMS sender may 159 // contain all alpha chars. 160 EXPECT_TRUE(phone_number_compare_loose("abcd", "bcde")); 161 } 162 163 TEST(PhoneNumberUtils, compareLooseAlphaNumericDifferent) { 164 EXPECT_FALSE(phone_number_compare_loose("1-800-flowers", "800-flowers")); 165 // TODO: "flowers" and "adcdefg" should not match 166 //EXPECT_FALSE(phone_number_compare_loose("1-800-flowers", "1-800-abcdefg")); 167 } 168 169 // TODO: we currently do not support this comparison. It maybe nice to support this 170 // TODO: in the future. 171 //TEST(PhoneNumberUtils, compareLooseLettersToDigits) { 172 // EXPECT_TRUE(phone_number_compare_loose("1-800-flowers", "1-800-356-9377")); 173 //} 174 175 TEST(PhoneNumberUtils, compareLooseWrongPrefix) { 176 // Japan 177 EXPECT_FALSE(phone_number_compare_loose("290-1234-5678", "+819012345678")); 178 EXPECT_FALSE(phone_number_compare_loose("+819012345678", "290-1234-5678")); 179 // USA 180 EXPECT_TRUE(phone_number_compare_loose("0550-450-3605", "+15504503605")); 181 EXPECT_FALSE(phone_number_compare_loose("550-450-3605", "+14504503605")); 182 EXPECT_FALSE(phone_number_compare_loose("550-450-3605", "+15404503605")); 183 EXPECT_FALSE(phone_number_compare_loose("550-450-3605", "+15514503605")); 184 EXPECT_FALSE(phone_number_compare_loose("5504503605", "+14504503605")); 185 186 EXPECT_FALSE(phone_number_compare_loose("+14504503605", "550-450-3605")); 187 EXPECT_FALSE(phone_number_compare_loose("+15404503605", "550-450-3605")); 188 EXPECT_FALSE(phone_number_compare_loose("+15514503605", "550-450-3605")); 189 EXPECT_FALSE(phone_number_compare_loose("+14504503605", "5504503605")); 190 } 191 192 193