|
|
@ -62,17 +62,6 @@ class PhoneNumberUtilTest : public testing::Test { |
|
|
return phone_util_.GetMetadataForNonGeographicalRegion(country_code); |
|
|
return phone_util_.GetMetadataForNonGeographicalRegion(country_code); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void GetSupportedRegions(set<string>* regions) { |
|
|
|
|
|
phone_util_.GetSupportedRegions(regions); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GetRegionCodesForCountryCallingCode( |
|
|
|
|
|
int country_calling_code, |
|
|
|
|
|
list<string>* regions) { |
|
|
|
|
|
phone_util_.GetRegionCodesForCountryCallingCode(country_calling_code, |
|
|
|
|
|
regions); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ExtractPossibleNumber(const string& number, |
|
|
void ExtractPossibleNumber(const string& number, |
|
|
string* extracted_number) const { |
|
|
string* extracted_number) const { |
|
|
phone_util_.ExtractPossibleNumber(number, extracted_number); |
|
|
phone_util_.ExtractPossibleNumber(number, extracted_number); |
|
|
@ -90,10 +79,6 @@ class PhoneNumberUtilTest : public testing::Test { |
|
|
phone_util_.Normalize(number); |
|
|
phone_util_.Normalize(number); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void NormalizeDiallableCharsOnly(string* number) const { |
|
|
|
|
|
phone_util_.NormalizeDiallableCharsOnly(number); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool IsNumberGeographical(const PhoneNumber& phone_number) const { |
|
|
bool IsNumberGeographical(const PhoneNumber& phone_number) const { |
|
|
return phone_util_.IsNumberGeographical(phone_number); |
|
|
return phone_util_.IsNumberGeographical(phone_number); |
|
|
} |
|
|
} |
|
|
@ -136,14 +121,6 @@ class PhoneNumberUtilTest : public testing::Test { |
|
|
return phone_util_.ContainsOnlyValidDigits(s); |
|
|
return phone_util_.ContainsOnlyValidDigits(s); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void GetNddPrefixForRegion(const string& region, |
|
|
|
|
|
bool strip_non_digits, |
|
|
|
|
|
string* ndd_prefix) const { |
|
|
|
|
|
// For testing purposes, we check this is empty first.
|
|
|
|
|
|
ndd_prefix->clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(region, strip_non_digits, ndd_prefix); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const PhoneNumberUtil& phone_util_; |
|
|
const PhoneNumberUtil& phone_util_; |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
@ -162,7 +139,7 @@ TEST_F(PhoneNumberUtilTest, ContainsOnlyValidDigits) { |
|
|
TEST_F(PhoneNumberUtilTest, GetSupportedRegions) { |
|
|
TEST_F(PhoneNumberUtilTest, GetSupportedRegions) { |
|
|
set<string> regions; |
|
|
set<string> regions; |
|
|
|
|
|
|
|
|
GetSupportedRegions(®ions); |
|
|
|
|
|
|
|
|
phone_util_.GetSupportedRegions(®ions); |
|
|
EXPECT_GT(regions.size(), 0U); |
|
|
EXPECT_GT(regions.size(), 0U); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -183,29 +160,29 @@ TEST_F(PhoneNumberUtilTest, GetSupportedGlobalNetworkCallingCodes) { |
|
|
TEST_F(PhoneNumberUtilTest, GetRegionCodesForCountryCallingCode) { |
|
|
TEST_F(PhoneNumberUtilTest, GetRegionCodesForCountryCallingCode) { |
|
|
list<string> regions; |
|
|
list<string> regions; |
|
|
|
|
|
|
|
|
GetRegionCodesForCountryCallingCode(1, ®ions); |
|
|
|
|
|
|
|
|
phone_util_.GetRegionCodesForCountryCallingCode(1, ®ions); |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::US()) |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::US()) |
|
|
!= regions.end()); |
|
|
!= regions.end()); |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::BS()) |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::BS()) |
|
|
!= regions.end()); |
|
|
!= regions.end()); |
|
|
|
|
|
|
|
|
regions.clear(); |
|
|
regions.clear(); |
|
|
GetRegionCodesForCountryCallingCode(44, ®ions); |
|
|
|
|
|
|
|
|
phone_util_.GetRegionCodesForCountryCallingCode(44, ®ions); |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::GB()) |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::GB()) |
|
|
!= regions.end()); |
|
|
!= regions.end()); |
|
|
|
|
|
|
|
|
regions.clear(); |
|
|
regions.clear(); |
|
|
GetRegionCodesForCountryCallingCode(49, ®ions); |
|
|
|
|
|
|
|
|
phone_util_.GetRegionCodesForCountryCallingCode(49, ®ions); |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::DE()) |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::DE()) |
|
|
!= regions.end()); |
|
|
!= regions.end()); |
|
|
|
|
|
|
|
|
regions.clear(); |
|
|
regions.clear(); |
|
|
GetRegionCodesForCountryCallingCode(800, ®ions); |
|
|
|
|
|
|
|
|
phone_util_.GetRegionCodesForCountryCallingCode(800, ®ions); |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::UN001()) |
|
|
EXPECT_TRUE(find(regions.begin(), regions.end(), RegionCode::UN001()) |
|
|
!= regions.end()); |
|
|
!= regions.end()); |
|
|
|
|
|
|
|
|
regions.clear(); |
|
|
regions.clear(); |
|
|
GetRegionCodesForCountryCallingCode(kInvalidCountryCode, ®ions); |
|
|
|
|
|
|
|
|
phone_util_.GetRegionCodesForCountryCallingCode(kInvalidCountryCode, ®ions); |
|
|
EXPECT_TRUE(regions.empty()); |
|
|
EXPECT_TRUE(regions.empty()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1919,7 +1896,8 @@ TEST_F(PhoneNumberUtilTest, IsNumberGeographical) { |
|
|
|
|
|
|
|
|
number.set_country_code(800); |
|
|
number.set_country_code(800); |
|
|
number.set_national_number(12345678ULL); |
|
|
number.set_national_number(12345678ULL); |
|
|
EXPECT_FALSE(IsNumberGeographical(number)); // Internation toll free number.
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(IsNumberGeographical(number)); // International toll free
|
|
|
|
|
|
// number.
|
|
|
|
|
|
|
|
|
// We test that mobile phone numbers in relevant regions are indeed considered
|
|
|
// We test that mobile phone numbers in relevant regions are indeed considered
|
|
|
// geographical.
|
|
|
// geographical.
|
|
|
@ -2377,33 +2355,40 @@ TEST_F(PhoneNumberUtilTest, GetCountryCodeForRegion) { |
|
|
|
|
|
|
|
|
TEST_F(PhoneNumberUtilTest, GetNationalDiallingPrefixForRegion) { |
|
|
TEST_F(PhoneNumberUtilTest, GetNationalDiallingPrefixForRegion) { |
|
|
string ndd_prefix; |
|
|
string ndd_prefix; |
|
|
GetNddPrefixForRegion(RegionCode::US(), false, &ndd_prefix); |
|
|
|
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::US(), false, &ndd_prefix); |
|
|
EXPECT_EQ("1", ndd_prefix); |
|
|
EXPECT_EQ("1", ndd_prefix); |
|
|
|
|
|
|
|
|
// Test non-main country to see it gets the national dialling prefix for the
|
|
|
// Test non-main country to see it gets the national dialling prefix for the
|
|
|
// main country with that country calling code.
|
|
|
// main country with that country calling code.
|
|
|
GetNddPrefixForRegion(RegionCode::BS(), false, &ndd_prefix); |
|
|
|
|
|
|
|
|
ndd_prefix.clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::BS(), false, &ndd_prefix); |
|
|
EXPECT_EQ("1", ndd_prefix); |
|
|
EXPECT_EQ("1", ndd_prefix); |
|
|
|
|
|
|
|
|
GetNddPrefixForRegion(RegionCode::NZ(), false, &ndd_prefix); |
|
|
|
|
|
|
|
|
ndd_prefix.clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::NZ(), false, &ndd_prefix); |
|
|
EXPECT_EQ("0", ndd_prefix); |
|
|
EXPECT_EQ("0", ndd_prefix); |
|
|
|
|
|
|
|
|
// Test case with non digit in the national prefix.
|
|
|
// Test case with non digit in the national prefix.
|
|
|
GetNddPrefixForRegion(RegionCode::AO(), false, &ndd_prefix); |
|
|
|
|
|
|
|
|
ndd_prefix.clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::AO(), false, &ndd_prefix); |
|
|
EXPECT_EQ("0~0", ndd_prefix); |
|
|
EXPECT_EQ("0~0", ndd_prefix); |
|
|
|
|
|
|
|
|
GetNddPrefixForRegion(RegionCode::AO(), true, &ndd_prefix); |
|
|
|
|
|
|
|
|
ndd_prefix.clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::AO(), true, &ndd_prefix); |
|
|
EXPECT_EQ("00", ndd_prefix); |
|
|
EXPECT_EQ("00", ndd_prefix); |
|
|
|
|
|
|
|
|
// Test cases with invalid regions.
|
|
|
// Test cases with invalid regions.
|
|
|
GetNddPrefixForRegion(RegionCode::GetUnknown(), false, &ndd_prefix); |
|
|
|
|
|
|
|
|
ndd_prefix.clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::GetUnknown(), false, &ndd_prefix); |
|
|
EXPECT_EQ("", ndd_prefix); |
|
|
EXPECT_EQ("", ndd_prefix); |
|
|
|
|
|
|
|
|
GetNddPrefixForRegion(RegionCode::UN001(), false, &ndd_prefix); |
|
|
|
|
|
|
|
|
ndd_prefix.clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::UN001(), false, &ndd_prefix); |
|
|
EXPECT_EQ("", ndd_prefix); |
|
|
EXPECT_EQ("", ndd_prefix); |
|
|
|
|
|
|
|
|
// CS is already deprecated so the library doesn't support it.
|
|
|
// CS is already deprecated so the library doesn't support it.
|
|
|
GetNddPrefixForRegion(RegionCode::CS(), false, &ndd_prefix); |
|
|
|
|
|
|
|
|
ndd_prefix.clear(); |
|
|
|
|
|
phone_util_.GetNddPrefixForRegion(RegionCode::CS(), false, &ndd_prefix); |
|
|
EXPECT_EQ("", ndd_prefix); |
|
|
EXPECT_EQ("", ndd_prefix); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -2496,7 +2481,7 @@ TEST_F(PhoneNumberUtilTest, NormaliseStripAlphaCharacters) { |
|
|
|
|
|
|
|
|
TEST_F(PhoneNumberUtilTest, NormaliseStripNonDiallableCharacters) { |
|
|
TEST_F(PhoneNumberUtilTest, NormaliseStripNonDiallableCharacters) { |
|
|
string input_number("03*4-56&+1a#234"); |
|
|
string input_number("03*4-56&+1a#234"); |
|
|
NormalizeDiallableCharsOnly(&input_number); |
|
|
|
|
|
|
|
|
phone_util_.NormalizeDiallableCharsOnly(&input_number); |
|
|
static const string kExpectedOutput("03*456+1#234"); |
|
|
static const string kExpectedOutput("03*456+1#234"); |
|
|
EXPECT_EQ(kExpectedOutput, input_number) |
|
|
EXPECT_EQ(kExpectedOutput, input_number) |
|
|
<< "Conversion did not correctly remove non-diallable characters"; |
|
|
<< "Conversion did not correctly remove non-diallable characters"; |
|
|
|