~ken-vandine/+junk/libphonenumber

« back to all changes in this revision

Viewing changes to cpp/test/phonenumbers/phonenumberutil_test.cc

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2015-09-25 13:20:24 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20150925132024-jhc5afks3lirr982
Tags: 7.0.11-2
* Split libgeocoding out into a separate package.
* Make library packages Multi-Arch: same
* Rename -dev package to not include the version - this means that
  our reverse build-deps don't need to have source changes whenever we bump
  the ABI version.
* debian/patches/0001-Boost-build-fix.patch: Make sure to install all the
  headers.
* debian/patches/0002-C-symbols-map.patch: Control our exported symbols to
  not leak those of libraries we depend on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
namespace i18n {
40
40
namespace phonenumbers {
41
41
 
42
 
using std::endl;
43
42
using std::find;
44
 
using std::make_pair;
45
43
using std::ostream;
46
44
 
47
45
using google::protobuf::RepeatedPtrField;
173
171
  EXPECT_GT(regions.size(), 0U);
174
172
}
175
173
 
 
174
TEST_F(PhoneNumberUtilTest, GetSupportedGlobalNetworkCallingCodes) {
 
175
  set<int> calling_codes;
 
176
 
 
177
  phone_util_.GetSupportedGlobalNetworkCallingCodes(&calling_codes);
 
178
  EXPECT_GT(calling_codes.size(), 0U);
 
179
  for (set<int>::const_iterator it = calling_codes.begin();
 
180
       it != calling_codes.end(); ++it) {
 
181
    EXPECT_GT(*it, 0);
 
182
    string region_code;
 
183
    phone_util_.GetRegionCodeForCountryCode(*it, &region_code);
 
184
    EXPECT_EQ(RegionCode::UN001(), region_code);
 
185
  }
 
186
}
 
187
 
176
188
TEST_F(PhoneNumberUtilTest, GetRegionCodesForCountryCallingCode) {
177
189
  list<string> regions;
178
190
 
1110
1122
  // numbers are always output in international format, but short numbers are
1111
1123
  // in national format.
1112
1124
  test_number.set_country_code(1);
1113
 
  test_number.set_national_number(6502530000L);
 
1125
  test_number.set_national_number(6502530000LL);
1114
1126
  phone_util_.FormatNumberForMobileDialing(
1115
1127
      test_number, RegionCode::US(), false, &formatted_number);
1116
1128
  EXPECT_EQ("+16502530000", formatted_number);
1728
1740
  number.set_national_number(123456789ULL);
1729
1741
  EXPECT_EQ(PhoneNumberUtil::TOO_LONG,
1730
1742
            phone_util_.IsPossibleNumberWithReason(number));
1731
 
 
1732
 
  // Try with number that we don't have metadata for.
1733
 
  PhoneNumber ad_number;
1734
 
  ad_number.set_country_code(376);
1735
 
  ad_number.set_national_number(12345ULL);
1736
 
  EXPECT_EQ(PhoneNumberUtil::IS_POSSIBLE,
1737
 
            phone_util_.IsPossibleNumberWithReason(ad_number));
1738
 
  ad_number.set_country_code(376);
1739
 
  ad_number.set_national_number(1ULL);
1740
 
  EXPECT_EQ(PhoneNumberUtil::TOO_SHORT,
1741
 
            phone_util_.IsPossibleNumberWithReason(ad_number));
1742
 
  ad_number.set_country_code(376);
1743
 
  ad_number.set_national_number(123456789012345678ULL);
1744
 
  EXPECT_EQ(PhoneNumberUtil::TOO_LONG,
1745
 
            phone_util_.IsPossibleNumberWithReason(ad_number));
1746
1743
}
1747
1744
 
1748
1745
TEST_F(PhoneNumberUtilTest, IsNotPossibleNumber) {
2685
2682
  phone_util_.Format(ad_number, PhoneNumberUtil::NATIONAL, &formatted_number);
2686
2683
  EXPECT_EQ("12345", formatted_number);
2687
2684
  EXPECT_EQ(PhoneNumberUtil::UNKNOWN, phone_util_.GetNumberType(ad_number));
2688
 
  EXPECT_TRUE(phone_util_.IsValidNumber(ad_number));
 
2685
  EXPECT_FALSE(phone_util_.IsValidNumber(ad_number));
2689
2686
 
2690
2687
  // Test dialing a US number from within Andorra.
2691
2688
  PhoneNumber us_number;