CPP/JAVA: Introducing new public APIs in ShortNumberInfo/short_number_info. Deprecating old methods. Also includes a refactoring change introducing a matcher API.

git-svn-id: http://libphonenumber.googlecode.com/svn/trunk/cpp/test@714 ee073f10-1060-11df-b6a4-87a95322a99c
diff --git a/phonenumbers/shortnumberinfo_test.cc b/phonenumbers/shortnumberinfo_test.cc
index 27a75ab..94df9d3 100644
--- a/phonenumbers/shortnumberinfo_test.cc
+++ b/phonenumbers/shortnumberinfo_test.cc
@@ -22,8 +22,10 @@
 
 #include <gtest/gtest.h>
 
+#include "phonenumbers/base/logging.h"
 #include "phonenumbers/default_logger.h"
 #include "phonenumbers/phonenumberutil.h"
+#include "phonenumbers/stringutil.h"
 #include "phonenumbers/test_util.h"
 
 namespace i18n {
@@ -31,10 +33,19 @@
 
 class ShortNumberInfoTest : public testing::Test {
  protected:
+  PhoneNumber ParseNumberForTesting(const string& number,
+                                    const string& region_code) {
+    PhoneNumber phone_number;
+    CHECK_EQ(phone_util_.Parse(number, region_code, &phone_number),
+             PhoneNumberUtil::NO_PARSING_ERROR);
+    return phone_number;
+  }
+
   ShortNumberInfoTest() : short_info_() {
     PhoneNumberUtil::GetInstance()->SetLogger(new StdoutLogger());
   }
 
+  const PhoneNumberUtil phone_util_;
   const ShortNumberInfo short_info_;
 
  private:
@@ -46,15 +57,13 @@
   possible_number.set_country_code(33);
   possible_number.set_national_number(123456ULL);
   EXPECT_TRUE(short_info_.IsPossibleShortNumber(possible_number));
-  EXPECT_TRUE(short_info_.IsPossibleShortNumberForRegion("123456",
-      RegionCode::FR()));
+  EXPECT_TRUE(short_info_.IsPossibleShortNumberForRegion(
+      ParseNumberForTesting("123456", RegionCode::FR()), RegionCode::FR()));
 
   PhoneNumber impossible_number;
   impossible_number.set_country_code(33);
   impossible_number.set_national_number(9ULL);
   EXPECT_FALSE(short_info_.IsPossibleShortNumber(impossible_number));
-  EXPECT_FALSE(short_info_.IsPossibleShortNumberForRegion("9",
-      RegionCode::FR()));
 
   // Note that GB and GG share the country calling code 44, and that this
   // number is possible but not valid.
@@ -69,15 +78,15 @@
   valid_number.set_country_code(33);
   valid_number.set_national_number(1010ULL);
   EXPECT_TRUE(short_info_.IsValidShortNumber(valid_number));
-  EXPECT_TRUE(short_info_.IsValidShortNumberForRegion("1010",
-      RegionCode::FR()));
+  EXPECT_TRUE(short_info_.IsValidShortNumberForRegion(
+      ParseNumberForTesting("1010", RegionCode::FR()), RegionCode::FR()));
 
   PhoneNumber invalid_number;
   invalid_number.set_country_code(33);
   invalid_number.set_national_number(123456ULL);
   EXPECT_FALSE(short_info_.IsValidShortNumber(invalid_number));
-  EXPECT_FALSE(short_info_.IsValidShortNumberForRegion("123456",
-      RegionCode::FR()));
+  EXPECT_FALSE(short_info_.IsValidShortNumberForRegion(
+      ParseNumberForTesting("123456", RegionCode::FR()), RegionCode::FR()));
 
   // Note that GB and GG share the country calling code 44.
   PhoneNumber shared_number;
@@ -90,71 +99,80 @@
   uint64 national_number;
   const string& premium_rate_example =
       short_info_.GetExampleShortNumberForCost(
-          RegionCode::FR(), ShortNumberInfo::ShortNumberCost::PREMIUM_RATE);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::PREMIUM_RATE,
-      short_info_.GetExpectedCostForRegion(premium_rate_example,
-          RegionCode::FR()));
+          RegionCode::FR(), ShortNumberInfo::PREMIUM_RATE);
+  EXPECT_EQ(ShortNumberInfo::PREMIUM_RATE,
+            short_info_.GetExpectedCostForRegion(
+                ParseNumberForTesting(premium_rate_example, RegionCode::FR()),
+                RegionCode::FR()));
   PhoneNumber premium_rate_number;
   premium_rate_number.set_country_code(33);
   safe_strtou64(premium_rate_example, &national_number);
   premium_rate_number.set_national_number(national_number);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::PREMIUM_RATE,
+  EXPECT_EQ(ShortNumberInfo::PREMIUM_RATE,
      short_info_.GetExpectedCost(premium_rate_number));
 
   const string& standard_rate_example =
       short_info_.GetExampleShortNumberForCost(
-          RegionCode::FR(), ShortNumberInfo::ShortNumberCost::STANDARD_RATE);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::STANDARD_RATE,
-      short_info_.GetExpectedCostForRegion(standard_rate_example,
-          RegionCode::FR()));
+          RegionCode::FR(), ShortNumberInfo::STANDARD_RATE);
+  EXPECT_EQ(ShortNumberInfo::STANDARD_RATE,
+            short_info_.GetExpectedCostForRegion(
+                ParseNumberForTesting(standard_rate_example, RegionCode::FR()),
+                RegionCode::FR()));
   PhoneNumber standard_rate_number;
   standard_rate_number.set_country_code(33);
   safe_strtou64(standard_rate_example, &national_number);
   standard_rate_number.set_national_number(national_number);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::STANDARD_RATE,
+  EXPECT_EQ(ShortNumberInfo::STANDARD_RATE,
      short_info_.GetExpectedCost(standard_rate_number));
 
   const string& toll_free_example =
       short_info_.GetExampleShortNumberForCost(
-          RegionCode::FR(), ShortNumberInfo::ShortNumberCost::TOLL_FREE);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
-      short_info_.GetExpectedCostForRegion(toll_free_example,
-          RegionCode::FR()));
+          RegionCode::FR(), ShortNumberInfo::TOLL_FREE);
+  EXPECT_EQ(ShortNumberInfo::TOLL_FREE,
+            short_info_.GetExpectedCostForRegion(
+                ParseNumberForTesting(toll_free_example, RegionCode::FR()),
+                RegionCode::FR()));
   PhoneNumber toll_free_number;
   toll_free_number.set_country_code(33);
   safe_strtou64(toll_free_example, &national_number);
   toll_free_number.set_national_number(national_number);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
+  EXPECT_EQ(ShortNumberInfo::TOLL_FREE,
      short_info_.GetExpectedCost(toll_free_number));
 
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
-      short_info_.GetExpectedCostForRegion("12345", RegionCode::FR()));
+  EXPECT_EQ(
+      ShortNumberInfo::UNKNOWN_COST,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("12345", RegionCode::FR()), RegionCode::FR()));
   PhoneNumber unknown_cost_number;
   unknown_cost_number.set_country_code(33);
   unknown_cost_number.set_national_number(12345ULL);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
+  EXPECT_EQ(ShortNumberInfo::UNKNOWN_COST,
      short_info_.GetExpectedCost(unknown_cost_number));
 
   // Test that an invalid number may nevertheless have a cost other than
   // UNKNOWN_COST.
-  EXPECT_FALSE(short_info_.IsValidShortNumberForRegion("116123",
-      RegionCode::FR()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
-      short_info_.GetExpectedCostForRegion("116123", RegionCode::FR()));
+  EXPECT_FALSE(short_info_.IsValidShortNumberForRegion(
+      ParseNumberForTesting("116123", RegionCode::FR()), RegionCode::FR()));
+  EXPECT_EQ(
+      ShortNumberInfo::TOLL_FREE,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("116123", RegionCode::FR()), RegionCode::FR()));
   PhoneNumber invalid_number;
   invalid_number.set_country_code(33);
   invalid_number.set_national_number(116123ULL);
   EXPECT_FALSE(short_info_.IsValidShortNumber(invalid_number));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
+  EXPECT_EQ(ShortNumberInfo::TOLL_FREE,
       short_info_.GetExpectedCost(invalid_number));
 
   // Test a nonexistent country code.
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
-      short_info_.GetExpectedCostForRegion("911", RegionCode::ZZ()));
+  EXPECT_EQ(
+      ShortNumberInfo::UNKNOWN_COST,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("911", RegionCode::US()), RegionCode::ZZ()));
   unknown_cost_number.Clear();
   unknown_cost_number.set_country_code(123);
   unknown_cost_number.set_national_number(911ULL);
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
+  EXPECT_EQ(ShortNumberInfo::UNKNOWN_COST,
       short_info_.GetExpectedCost(unknown_cost_number));
 }
 
@@ -181,43 +199,64 @@
   EXPECT_TRUE(short_info_.IsValidShortNumber(ambiguous_toll_free_number));
 
   EXPECT_TRUE(short_info_.IsValidShortNumberForRegion(
-      ambiguous_premium_rate_string, RegionCode::AU()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::PREMIUM_RATE,
-      short_info_.GetExpectedCostForRegion(ambiguous_premium_rate_string,
-          RegionCode::AU()));
+      ParseNumberForTesting(ambiguous_premium_rate_string, RegionCode::AU()),
+      RegionCode::AU()));
+  EXPECT_EQ(ShortNumberInfo::PREMIUM_RATE,
+            short_info_.GetExpectedCostForRegion(
+                ParseNumberForTesting(ambiguous_premium_rate_string,
+                                      RegionCode::AU()),
+                RegionCode::AU()));
+
   EXPECT_FALSE(short_info_.IsValidShortNumberForRegion(
-      ambiguous_premium_rate_string, RegionCode::CX()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
-      short_info_.GetExpectedCostForRegion(ambiguous_premium_rate_string,
-          RegionCode::CX()));
+      ParseNumberForTesting(ambiguous_premium_rate_string, RegionCode::CX()),
+      RegionCode::CX()));
+  EXPECT_EQ(ShortNumberInfo::UNKNOWN_COST,
+            short_info_.GetExpectedCostForRegion(
+                ParseNumberForTesting(ambiguous_premium_rate_string,
+                                      RegionCode::CX()),
+                RegionCode::CX()));
   // PREMIUM_RATE takes precedence over UNKNOWN_COST.
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::PREMIUM_RATE,
+  EXPECT_EQ(ShortNumberInfo::PREMIUM_RATE,
       short_info_.GetExpectedCost(ambiguous_premium_rate_number));
 
   EXPECT_TRUE(short_info_.IsValidShortNumberForRegion(
-      ambiguous_standard_rate_string, RegionCode::AU()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::STANDARD_RATE,
-      short_info_.GetExpectedCostForRegion(ambiguous_standard_rate_string,
-          RegionCode::AU()));
+      ParseNumberForTesting(ambiguous_standard_rate_string, RegionCode::AU()),
+      RegionCode::AU()));
+  EXPECT_EQ(ShortNumberInfo::STANDARD_RATE,
+            short_info_.GetExpectedCostForRegion(
+                ParseNumberForTesting(ambiguous_standard_rate_string,
+                                      RegionCode::AU()),
+                RegionCode::AU()));
+
   EXPECT_FALSE(short_info_.IsValidShortNumberForRegion(
-      ambiguous_standard_rate_string, RegionCode::CX()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
-      short_info_.GetExpectedCostForRegion(ambiguous_standard_rate_string,
-          RegionCode::CX()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
+      ParseNumberForTesting(ambiguous_standard_rate_string, RegionCode::CX()),
+      RegionCode::CX()));
+  EXPECT_EQ(ShortNumberInfo::UNKNOWN_COST,
+            short_info_.GetExpectedCostForRegion(
+                ParseNumberForTesting(ambiguous_standard_rate_string,
+                                      RegionCode::CX()),
+                RegionCode::CX()));
+  EXPECT_EQ(ShortNumberInfo::UNKNOWN_COST,
       short_info_.GetExpectedCost(ambiguous_standard_rate_number));
 
   EXPECT_TRUE(short_info_.IsValidShortNumberForRegion(
-      ambiguous_toll_free_string, RegionCode::AU()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
-      short_info_.GetExpectedCostForRegion(ambiguous_toll_free_string,
+      ParseNumberForTesting(ambiguous_toll_free_string, RegionCode::AU()),
+      RegionCode::AU()));
+  EXPECT_EQ(
+      ShortNumberInfo::TOLL_FREE,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting(ambiguous_toll_free_string, RegionCode::AU()),
           RegionCode::AU()));
+
   EXPECT_FALSE(short_info_.IsValidShortNumberForRegion(
-      ambiguous_toll_free_string, RegionCode::CX()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
-      short_info_.GetExpectedCostForRegion(ambiguous_toll_free_string,
+      ParseNumberForTesting(ambiguous_toll_free_string, RegionCode::CX()),
+      RegionCode::CX()));
+  EXPECT_EQ(
+      ShortNumberInfo::UNKNOWN_COST,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting(ambiguous_toll_free_string, RegionCode::CX()),
           RegionCode::CX()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
+  EXPECT_EQ(ShortNumberInfo::UNKNOWN_COST,
       short_info_.GetExpectedCost(ambiguous_toll_free_number));
 }
 
@@ -231,15 +270,15 @@
 TEST_F(ShortNumberInfoTest, GetExampleShortNumberForCost) {
   EXPECT_EQ("3010",
       short_info_.GetExampleShortNumberForCost(RegionCode::FR(),
-      ShortNumberInfo::ShortNumberCost::TOLL_FREE));
+      ShortNumberInfo::TOLL_FREE));
   EXPECT_EQ("1023",
       short_info_.GetExampleShortNumberForCost(RegionCode::FR(),
-      ShortNumberInfo::ShortNumberCost::STANDARD_RATE));
+      ShortNumberInfo::STANDARD_RATE));
   EXPECT_EQ("42000",
       short_info_.GetExampleShortNumberForCost(RegionCode::FR(),
-      ShortNumberInfo::ShortNumberCost::PREMIUM_RATE));
+      ShortNumberInfo::PREMIUM_RATE));
   EXPECT_EQ("", short_info_.GetExampleShortNumberForCost(RegionCode::FR(),
-      ShortNumberInfo::ShortNumberCost::UNKNOWN_COST));
+      ShortNumberInfo::UNKNOWN_COST));
 }
 
 TEST_F(ShortNumberInfoTest, ConnectsToEmergencyNumber_US) {
@@ -380,18 +419,26 @@
   // Test the emergency number 112, which is valid in both Australia and the
   // Christmas Islands.
   EXPECT_TRUE(short_info_.IsEmergencyNumber("112", RegionCode::AU()));
-  EXPECT_TRUE(short_info_.IsValidShortNumberForRegion("112", RegionCode::AU()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
-      short_info_.GetExpectedCostForRegion("112", RegionCode::AU()));
+  EXPECT_TRUE(short_info_.IsValidShortNumberForRegion(
+      ParseNumberForTesting("112", RegionCode::AU()), RegionCode::AU()));
+  EXPECT_EQ(
+      ShortNumberInfo::TOLL_FREE,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("112", RegionCode::AU()), RegionCode::AU()));
+
   EXPECT_TRUE(short_info_.IsEmergencyNumber("112", RegionCode::CX()));
-  EXPECT_TRUE(short_info_.IsValidShortNumberForRegion("112", RegionCode::CX()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
-      short_info_.GetExpectedCostForRegion("112", RegionCode::CX()));
+  EXPECT_TRUE(short_info_.IsValidShortNumberForRegion(
+      ParseNumberForTesting("112", RegionCode::CX()), RegionCode::CX()));
+  EXPECT_EQ(
+      ShortNumberInfo::TOLL_FREE,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("112", RegionCode::CX()), RegionCode::CX()));
+
   PhoneNumber shared_emergency_number;
   shared_emergency_number.set_country_code(61);
   shared_emergency_number.set_national_number(112ULL);
   EXPECT_TRUE(short_info_.IsValidShortNumber(shared_emergency_number));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
+  EXPECT_EQ(ShortNumberInfo::TOLL_FREE,
       short_info_.GetExpectedCost(shared_emergency_number));
 }
 
@@ -399,14 +446,22 @@
   // 211 is an emergency number in Barbados, while it is a toll-free
   // information line in Canada and the USA.
   EXPECT_TRUE(short_info_.IsEmergencyNumber("211", RegionCode::BB()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::TOLL_FREE,
-      short_info_.GetExpectedCostForRegion("211", RegionCode::BB()));
+  EXPECT_EQ(
+      ShortNumberInfo::TOLL_FREE,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("211", RegionCode::BB()), RegionCode::BB()));
+
   EXPECT_FALSE(short_info_.IsEmergencyNumber("211", RegionCode::US()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
-      short_info_.GetExpectedCostForRegion("211", RegionCode::US()));
+  EXPECT_EQ(
+      ShortNumberInfo::UNKNOWN_COST,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("211", RegionCode::US()), RegionCode::US()));
+
   EXPECT_FALSE(short_info_.IsEmergencyNumber("211", RegionCode::CA()));
-  EXPECT_EQ(ShortNumberInfo::ShortNumberCost::UNKNOWN_COST,
-      short_info_.GetExpectedCostForRegion("211", RegionCode::CA()));
+  EXPECT_EQ(
+      ShortNumberInfo::UNKNOWN_COST,
+      short_info_.GetExpectedCostForRegion(
+          ParseNumberForTesting("211", RegionCode::CA()), RegionCode::CA()));
 }
 
 }  // namespace phonenumbers
diff --git a/phonenumbers/test_util.h b/phonenumbers/test_util.h
index 717f27f..a155313 100644
--- a/phonenumbers/test_util.h
+++ b/phonenumbers/test_util.h
@@ -57,6 +57,10 @@
     return "AE";
   }
 
+  static const char* AM() {
+    return "AM";
+  }
+
   static const char* AO() {
     return "AO";
   }
@@ -73,6 +77,10 @@
     return "AU";
   }
 
+  static const char* BB() {
+    return "BB";
+  }
+
   static const char* BR() {
     return "BR";
   }
@@ -105,6 +113,10 @@
     return "CS";
   }
 
+  static const char* CX() {
+    return "CX";
+  }
+
   static const char* DE() {
     return "DE";
   }