C++: Updated Geocoder documentation and tests
[platform/upstream/libphonenumber.git] / cpp / test / phonenumbers / geocoding / geocoding_test_program.cc
1 // Copyright (C) 2012 The Libphonenumber Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Sample program using the geocoding functionality. This is used to test that
16 // the geocoding library is compiled correctly.
17
18 #include <iostream>
19 #include <string>
20
21 #include "phonenumbers/base/logging.h"
22 #include "phonenumbers/geocoding/phonenumber_offline_geocoder.h"
23 #include "phonenumbers/phonenumber.pb.h"
24 #include "phonenumbers/phonenumberutil.h"
25
26 using i18n::phonenumbers::PhoneNumber;
27 using i18n::phonenumbers::PhoneNumberOfflineGeocoder;
28 using i18n::phonenumbers::PhoneNumberUtil;
29
30 int main() {
31   PhoneNumber number;
32   const PhoneNumberUtil& phone_util = *PhoneNumberUtil::GetInstance();
33   const PhoneNumberUtil::ErrorType status = phone_util.Parse(
34       "16502530000", "US", &number);
35   CHECK_EQ(status, PhoneNumberUtil::NO_PARSING_ERROR);
36
37   const std::string description =
38       PhoneNumberOfflineGeocoder().GetDescriptionForNumber(
39           number, icu::Locale("en", "GB"));
40   std::cout << description << std::endl;
41   CHECK_EQ(description, "Mountain View, CA");
42   return 0;
43 }