From 53ebe98c4936262c944a0fb31ed24b4ccf14e618 Mon Sep 17 00:00:00 2001 From: Lara Scheidegger Date: Fri, 17 Jun 2011 13:12:22 +0000 Subject: [PATCH] CPP: Small code tidy-ups (adding includes etc). --- cpp/src/phonenumberutil.cc | 12 +++++++++--- cpp/src/phonenumberutil_test.cc | 9 ++++----- cpp/src/regexp_adapter.h | 3 ++- cpp/src/regexp_adapter_test.cc | 3 ++- cpp/src/regexp_cache_test.cc | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/cpp/src/phonenumberutil.cc b/cpp/src/phonenumberutil.cc index a333f9270..dde9a1c72 100644 --- a/cpp/src/phonenumberutil.cc +++ b/cpp/src/phonenumberutil.cc @@ -18,10 +18,14 @@ #include "phonenumberutil.h" #include +#include +#include #include #include +#include #include #include +#include #include #include @@ -786,11 +790,13 @@ bool PhoneNumberUtil::IsValidRegionCode(const string& region_code) const { } bool PhoneNumberUtil::HasValidRegionCode(const string& region_code, - int country_code, + int country_calling_code, const string& number) const { if (!IsValidRegionCode(region_code)) { logger->Info(string("Number ") + number + - " has invalid or missing country code (" + country_code + ")"); + " has invalid or missing country code (" + + country_calling_code + + ")"); return false; } return true; @@ -1237,7 +1243,7 @@ void PhoneNumberUtil::GetRegionCodeForCountryCode( list region_codes; GetRegionCodesForCountryCallingCode(country_calling_code, ®ion_codes); - *region_code = region_codes.size() != 0 ? region_codes.front() : "ZZ"; + *region_code = (region_codes.size() > 0) ? region_codes.front() : "ZZ"; } void PhoneNumberUtil::GetRegionCodeForNumber(const PhoneNumber& number, diff --git a/cpp/src/phonenumberutil_test.cc b/cpp/src/phonenumberutil_test.cc index f1d4dacca..969f4ae52 100644 --- a/cpp/src/phonenumberutil_test.cc +++ b/cpp/src/phonenumberutil_test.cc @@ -142,6 +142,9 @@ class RegionCode { class PhoneNumberUtilTest : public testing::Test { protected: + PhoneNumberUtilTest() : phone_util_(*PhoneNumberUtil::GetInstance()) { + } + // Wrapper functions for private functions that we want to test. const PhoneMetadata* GetPhoneMetadata(const string& region_code) const { return phone_util_.GetMetadataForRegion(region_code); @@ -211,7 +214,7 @@ class PhoneNumberUtilTest : public testing::Test { return ExactlySameAs(expected_number, actual_number); } - PhoneNumberUtil phone_util_; + const PhoneNumberUtil& phone_util_; }; // Provides PhoneNumber comparison operators to support the use of EXPECT_EQ and @@ -248,10 +251,6 @@ ostream& operator<<(ostream& os, const PhoneNumber& number) { return os; } -TEST_F(PhoneNumberUtilTest, GetInstance) { - EXPECT_FALSE(PhoneNumberUtil::GetInstance() == NULL); -} - TEST_F(PhoneNumberUtilTest, GetSupportedRegions) { set regions; diff --git a/cpp/src/regexp_adapter.h b/cpp/src/regexp_adapter.h index 761e02e63..35681526f 100644 --- a/cpp/src/regexp_adapter.h +++ b/cpp/src/regexp_adapter.h @@ -14,7 +14,7 @@ // Author: George Yakovlev // Philippe Liard - +// // Regexp adapter to allow a pluggable regexp engine. It has been introduced // during the integration of the open-source version of this library into // Chromium to be able to use the ICU Regex engine instead of RE2, which is not @@ -25,6 +25,7 @@ #ifndef I18N_PHONENUMBERS_REGEXP_ADAPTER_H_ #define I18N_PHONENUMBERS_REGEXP_ADAPTER_H_ +#include #include namespace i18n { diff --git a/cpp/src/regexp_adapter_test.cc b/cpp/src/regexp_adapter_test.cc index eb3b6f727..190e37bf3 100644 --- a/cpp/src/regexp_adapter_test.cc +++ b/cpp/src/regexp_adapter_test.cc @@ -15,12 +15,13 @@ // Author: George Yakovlev // Philippe Liard +#include "regexp_adapter.h" + #include #include #include "base/scoped_ptr.h" -#include "regexp_adapter.h" namespace i18n { namespace phonenumbers { diff --git a/cpp/src/regexp_cache_test.cc b/cpp/src/regexp_cache_test.cc index 4296b060e..329ccf645 100644 --- a/cpp/src/regexp_cache_test.cc +++ b/cpp/src/regexp_cache_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Author: Fredrik Roubert +// Author: Fredrik Roubert #include #include