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
26using i18n::phonenumbers::PhoneNumber;
27using i18n::phonenumbers::PhoneNumberOfflineGeocoder;
28using i18n::phonenumbers::PhoneNumberUtil;
29
30int 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  IGNORE_UNUSED(status);
37
38  const std::string description =
39      PhoneNumberOfflineGeocoder().GetDescriptionForNumber(
40          number, icu::Locale("en", "GB"));
41  std::cout << description << std::endl;
42  CHECK_EQ(description, "Mountain View, CA");
43  return 0;
44}
45