Browse Source

C++: Updated Geocoder documentation and tests

pull/567/head
Cecilia Roes 11 years ago
committed by Mihaela Rosca
parent
commit
300ac447bd
3 changed files with 6 additions and 4 deletions
  1. +1
    -0
      cpp/src/phonenumbers/geocoding/phonenumber_offline_geocoder.h
  2. +3
    -3
      cpp/test/phonenumbers/geocoding/geocoding_test_program.cc
  3. +2
    -1
      cpp/test/phonenumbers/geocoding/phonenumber_offline_geocoder_test.cc

+ 1
- 0
cpp/src/phonenumbers/geocoding/phonenumber_offline_geocoder.h View File

@ -99,6 +99,7 @@ class PhoneNumberOfflineGeocoder {
const Locale& locale) const; const Locale& locale) const;
// As per GetDescriptionForValidNumber(PhoneNumber, Locale, String) but // As per GetDescriptionForValidNumber(PhoneNumber, Locale, String) but
// explicitly checks the validity of the number passed in.
string GetDescriptionForNumber(const PhoneNumber& number, string GetDescriptionForNumber(const PhoneNumber& number,
const Locale& language, const string& user_region) const; const Locale& language, const string& user_region) const;


+ 3
- 3
cpp/test/phonenumbers/geocoding/geocoding_test_program.cc View File

@ -15,10 +15,10 @@
// Sample program using the geocoding functionality. This is used to test that // Sample program using the geocoding functionality. This is used to test that
// the geocoding library is compiled correctly. // the geocoding library is compiled correctly.
#include <cassert>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "phonenumbers/base/logging.h"
#include "phonenumbers/geocoding/phonenumber_offline_geocoder.h" #include "phonenumbers/geocoding/phonenumber_offline_geocoder.h"
#include "phonenumbers/phonenumber.pb.h" #include "phonenumbers/phonenumber.pb.h"
#include "phonenumbers/phonenumberutil.h" #include "phonenumbers/phonenumberutil.h"
@ -32,12 +32,12 @@ int main() {
const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance(); const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
const PhoneNumberUtil::ErrorType status = phone_util.Parse( const PhoneNumberUtil::ErrorType status = phone_util.Parse(
"16502530000", "US", &number); "16502530000", "US", &number);
assert(status == PhoneNumberUtil::NO_PARSING_ERROR);
CHECK_EQ(status, PhoneNumberUtil::NO_PARSING_ERROR);
const std::string description = const std::string description =
PhoneNumberOfflineGeocoder().GetDescriptionForNumber( PhoneNumberOfflineGeocoder().GetDescriptionForNumber(
number, icu::Locale("en", "GB")); number, icu::Locale("en", "GB"));
std::cout << description << std::endl; std::cout << description << std::endl;
assert(description == "Mountain View, CA");
CHECK_EQ(description, "Mountain View, CA");
return 0; return 0;
} }

+ 2
- 1
cpp/test/phonenumbers/geocoding/phonenumber_offline_geocoder_test.cc View File

@ -190,7 +190,8 @@ TEST_F(PhoneNumberOfflineGeocoderTest,
// Invalid number - return an empty string. // Invalid number - return an empty string.
EXPECT_EQ("", EXPECT_EQ("",
geocoder_->GetDescriptionForNumber(US_INVALID_NUMBER, geocoder_->GetDescriptionForNumber(US_INVALID_NUMBER,
kEnglishLocale, "US"));
kEnglishLocale,
"US"));
} }
TEST_F(PhoneNumberOfflineGeocoderTest, TestGetDescriptionForInvalidNumber) { TEST_F(PhoneNumberOfflineGeocoderTest, TestGetDescriptionForInvalidNumber) {


Loading…
Cancel
Save