Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc

Issue 386873002: Reland "Use upstream libaddressinput in Chrome." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix iOS compile. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc
diff --git a/third_party/libaddressinput/chromium/preload_address_validator_unittest.cc b/third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc
similarity index 55%
rename from third_party/libaddressinput/chromium/preload_address_validator_unittest.cc
rename to third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc
index 1cc7aafe7bff1277e7cd7173152205f9cf266595..906d0a65eff7fa1b23b618914555245fa83e4e87 100644
--- a/third_party/libaddressinput/chromium/preload_address_validator_unittest.cc
+++ b/third_party/libaddressinput/chromium/chrome_address_validator_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "third_party/libaddressinput/chromium/chrome_address_validator.h"
+
#include <cstddef>
#include <string>
#include <vector>
@@ -10,31 +12,30 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
-
-#define I18N_ADDRESSINPUT_UTIL_BASICTYPES_H_
-#include "third_party/libaddressinput/chromium/preload_address_validator.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_problem.h"
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_validator.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/downloader.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/null_storage.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h"
-#include "third_party/libaddressinput/src/cpp/src/region_data_constants.h"
#include "third_party/libaddressinput/src/cpp/test/fake_downloader.h"
namespace {
-using ::autofill::PreloadAddressValidator;
+using ::autofill::AddressValidator;
+using ::autofill::LoadRulesListener;
using ::i18n::addressinput::AddressData;
using ::i18n::addressinput::AddressField;
+using ::i18n::addressinput::AddressProblem;
using ::i18n::addressinput::BuildCallback;
using ::i18n::addressinput::Downloader;
using ::i18n::addressinput::FakeDownloader;
using ::i18n::addressinput::FieldProblemMap;
+using ::i18n::addressinput::GetRegionCodes;
using ::i18n::addressinput::NullStorage;
-using ::i18n::addressinput::RegionDataConstants;
using ::i18n::addressinput::Storage;
using ::i18n::addressinput::COUNTRY;
@@ -46,69 +47,113 @@ using ::i18n::addressinput::POSTAL_CODE;
using ::i18n::addressinput::STREET_ADDRESS;
using ::i18n::addressinput::RECIPIENT;
-using ::i18n::addressinput::UNKNOWN_VALUE;
using ::i18n::addressinput::INVALID_FORMAT;
using ::i18n::addressinput::MISMATCHING_VALUE;
+using ::i18n::addressinput::MISSING_REQUIRED_FIELD;
+using ::i18n::addressinput::UNEXPECTED_FIELD;
+using ::i18n::addressinput::UNKNOWN_VALUE;
+using ::i18n::addressinput::USES_P_O_BOX;
-class PreloadAddressValidatorTest : public testing::Test {
+class AddressValidatorTest : public testing::Test, LoadRulesListener {
protected:
- PreloadAddressValidatorTest()
+ AddressValidatorTest()
: validator_(
- new PreloadAddressValidator(
- FakeDownloader::kFakeAggregateDataUrl,
- scoped_ptr<Downloader>(new FakeDownloader),
- scoped_ptr<Storage>(new NullStorage))),
- loaded_(BuildCallback(this, &PreloadAddressValidatorTest::Loaded)) {
- validator_->LoadRules("US", *loaded_);
+ new AddressValidator(FakeDownloader::kFakeAggregateDataUrl,
+ scoped_ptr<Downloader>(new FakeDownloader),
+ scoped_ptr<Storage>(new NullStorage),
+ this)) {
+ validator_->LoadRules("US");
}
- virtual ~PreloadAddressValidatorTest() {}
+ virtual ~AddressValidatorTest() {}
- const scoped_ptr<PreloadAddressValidator> validator_;
- const scoped_ptr<PreloadAddressValidator::Callback> loaded_;
+ const scoped_ptr<AddressValidator> validator_;
private:
- void Loaded(bool success,
- const std::string& region_code,
- const int& rule_count) {
+ // LoadRulesListener implementation.
+ virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
+ bool success) OVERRIDE {
AddressData address_data;
- address_data.region_code = region_code;
+ address_data.region_code = country_code;
FieldProblemMap dummy;
- PreloadAddressValidator::Status status =
- validator_->Validate(address_data, NULL, &dummy);
- ASSERT_EQ(success, status == PreloadAddressValidator::SUCCESS);
+ AddressValidator::Status status =
+ validator_->ValidateAddress(address_data, NULL, &dummy);
+ ASSERT_EQ(success, status == AddressValidator::SUCCESS);
}
- DISALLOW_COPY_AND_ASSIGN(PreloadAddressValidatorTest);
+ DISALLOW_COPY_AND_ASSIGN(AddressValidatorTest);
+};
+
+// Use this text fixture if you're going to use a region with a large set of
+// validation rules. All rules should be loaded in SetUpTestCase().
+class LargeAddressValidatorTest : public testing::Test {
+ protected:
+ LargeAddressValidatorTest() {}
+ virtual ~LargeAddressValidatorTest() {}
+
+ static void SetUpTestCase() {
+ validator_ =
+ new AddressValidator(FakeDownloader::kFakeAggregateDataUrl,
+ scoped_ptr<Downloader>(new FakeDownloader),
+ scoped_ptr<Storage>(new NullStorage),
+ NULL);
+ validator_->LoadRules("CN");
+ validator_->LoadRules("KR");
+ validator_->LoadRules("TW");
+ }
+
+ static void TearDownTestcase() {
+ delete validator_;
+ validator_ = NULL;
+ }
+
+ // Owned shared instance of validator with large sets validation rules.
+ static AddressValidator* validator_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LargeAddressValidatorTest);
};
-TEST_F(PreloadAddressValidatorTest, RegionHasRules) {
- const std::vector<std::string>& region_codes =
- RegionDataConstants::GetRegionCodes();
+AddressValidator* LargeAddressValidatorTest::validator_ = NULL;
+
+TEST_F(AddressValidatorTest, RegionHasRules) {
+ const std::vector<std::string>& region_codes = GetRegionCodes();
AddressData address;
for (size_t i = 0; i < region_codes.size(); ++i) {
SCOPED_TRACE("For region: " + region_codes[i]);
- validator_->LoadRules(region_codes[i], *loaded_);
+ validator_->LoadRules(region_codes[i]);
address.region_code = region_codes[i];
FieldProblemMap dummy;
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &dummy));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &dummy));
}
}
-TEST_F(PreloadAddressValidatorTest, EmptyAddressNoFatalFailure) {
+TEST_F(AddressValidatorTest, EmptyAddressNoFatalFailure) {
AddressData address;
address.region_code = "US";
FieldProblemMap dummy;
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &dummy));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &dummy));
}
-TEST_F(PreloadAddressValidatorTest, USZipCode) {
+TEST_F(AddressValidatorTest, UsStateNamesAreValidEntries) {
AddressData address;
+ address.region_code = "US";
+ address.administrative_area = "California";
+
+ FieldProblemMap filter;
+ filter.insert(std::make_pair(ADMIN_AREA, UNKNOWN_VALUE));
+ FieldProblemMap problems;
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, &filter, &problems));
+ EXPECT_TRUE(problems.empty());
+}
+
+TEST_F(AddressValidatorTest, USZipCode) {
+ AddressData address;
+ address.recipient = "Mr. Smith";
address.address_line.push_back("340 Main St.");
address.locality = "Venice";
address.administrative_area = "CA";
@@ -117,27 +162,24 @@ TEST_F(PreloadAddressValidatorTest, USZipCode) {
// Valid Californian zip code.
address.postal_code = "90291";
FieldProblemMap problems;
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_TRUE(problems.empty());
problems.clear();
// An extended, valid Californian zip code.
address.postal_code = "90210-1234";
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_TRUE(problems.empty());
problems.clear();
// New York zip code (which is invalid for California).
address.postal_code = "12345";
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_EQ(1U, problems.size());
EXPECT_EQ(problems.begin()->first, POSTAL_CODE);
EXPECT_EQ(problems.begin()->second, MISMATCHING_VALUE);
@@ -146,9 +188,8 @@ TEST_F(PreloadAddressValidatorTest, USZipCode) {
// A zip code with a "90" in the middle.
address.postal_code = "12903";
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_EQ(1U, problems.size());
EXPECT_EQ(problems.begin()->first, POSTAL_CODE);
EXPECT_EQ(problems.begin()->second, MISMATCHING_VALUE);
@@ -157,9 +198,8 @@ TEST_F(PreloadAddressValidatorTest, USZipCode) {
// Invalid zip code (too many digits).
address.postal_code = "902911";
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_EQ(1U, problems.size());
EXPECT_EQ(problems.begin()->first, POSTAL_CODE);
EXPECT_EQ(problems.begin()->second, INVALID_FORMAT);
@@ -168,19 +208,16 @@ TEST_F(PreloadAddressValidatorTest, USZipCode) {
// Invalid zip code (too few digits).
address.postal_code = "9029";
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_EQ(1U, problems.size());
EXPECT_EQ(problems.begin()->first, POSTAL_CODE);
EXPECT_EQ(problems.begin()->second, INVALID_FORMAT);
}
-// Test case disabled because libaddressinput address validation doesn't do
-// those kinds of normalizations that this test case expects. TODO: Something.
-TEST_F(PreloadAddressValidatorTest, DISABLED_BasicValidation) {
+TEST_F(AddressValidatorTest, BasicValidation) {
// US rules should always be available, even though this load call fails.
- validator_->LoadRules("US", *loaded_);
+ validator_->LoadRules("US");
AddressData address;
address.region_code = "US";
address.language_code = "en";
@@ -188,48 +225,44 @@ TEST_F(PreloadAddressValidatorTest, DISABLED_BasicValidation) {
address.locality = "Paris";
address.postal_code = "75461";
address.address_line.push_back("123 Main St");
+ address.recipient = "Mr. Smith";
FieldProblemMap problems;
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_TRUE(problems.empty());
// The display name works as well as the key.
address.administrative_area = "Texas";
problems.clear();
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_TRUE(problems.empty());
// Ignore capitalization.
address.administrative_area = "tx";
problems.clear();
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_TRUE(problems.empty());
// Ignore capitalization.
address.administrative_area = "teXas";
problems.clear();
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_TRUE(problems.empty());
// Ignore diacriticals.
address.administrative_area = "T\u00E9xas";
problems.clear();
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
EXPECT_TRUE(problems.empty());
}
-TEST_F(PreloadAddressValidatorTest, BasicValidationFailure) {
+TEST_F(AddressValidatorTest, BasicValidationFailure) {
// US rules should always be available, even though this load call fails.
- validator_->LoadRules("US", *loaded_);
+ validator_->LoadRules("US");
AddressData address;
address.region_code = "US";
address.language_code = "en";
@@ -237,45 +270,45 @@ TEST_F(PreloadAddressValidatorTest, BasicValidationFailure) {
address.locality = "Paris";
address.postal_code = "75461";
address.address_line.push_back("123 Main St");
+ address.recipient = "Mr. Smith";
FieldProblemMap problems;
- EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
- validator_->Validate(address, NULL, &problems));
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(address, NULL, &problems));
ASSERT_EQ(1U, problems.size());
EXPECT_EQ(UNKNOWN_VALUE, problems.begin()->second);
EXPECT_EQ(ADMIN_AREA, problems.begin()->first);
}
-TEST_F(PreloadAddressValidatorTest, NoNullSuggestionsCrash) {
+TEST_F(AddressValidatorTest, NoNullSuggestionsCrash) {
AddressData address;
address.region_code = "US";
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, COUNTRY, 1, NULL));
}
-TEST_F(PreloadAddressValidatorTest, SuggestAdminAreaForPostalCode) {
+TEST_F(AddressValidatorTest, SuggestAdminAreaForPostalCode) {
AddressData address;
address.region_code = "US";
address.postal_code = "90291";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("CA", suggestions[0].administrative_area);
EXPECT_EQ("90291", suggestions[0].postal_code);
}
-TEST_F(PreloadAddressValidatorTest, SuggestLocalityForPostalCodeWithAdminArea) {
- validator_->LoadRules("TW", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestLocalityForPostalCodeWithAdminArea) {
AddressData address;
address.region_code = "TW";
address.postal_code = "515";
address.administrative_area = "Changhua";
+ address.language_code = "zh-Latn";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("Dacun Township", suggestions[0].locality);
@@ -283,15 +316,15 @@ TEST_F(PreloadAddressValidatorTest, SuggestLocalityForPostalCodeWithAdminArea) {
EXPECT_EQ("515", suggestions[0].postal_code);
}
-TEST_F(PreloadAddressValidatorTest, SuggestAdminAreaForPostalCodeWithLocality) {
- validator_->LoadRules("TW", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestAdminAreaForPostalCodeWithLocality) {
AddressData address;
address.region_code = "TW";
address.postal_code = "515";
address.locality = "Dacun";
+ address.language_code = "zh-Latn";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("Dacun Township", suggestions[0].locality);
@@ -299,149 +332,149 @@ TEST_F(PreloadAddressValidatorTest, SuggestAdminAreaForPostalCodeWithLocality) {
EXPECT_EQ("515", suggestions[0].postal_code);
}
-TEST_F(PreloadAddressValidatorTest, NoSuggestForPostalCodeWithWrongAdminArea) {
+TEST_F(AddressValidatorTest, NoSuggestForPostalCodeWithWrongAdminArea) {
AddressData address;
address.region_code = "US";
address.postal_code = "90066";
address.postal_code = "TX";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
EXPECT_TRUE(suggestions.empty());
}
-TEST_F(PreloadAddressValidatorTest, SuggestForLocality) {
- validator_->LoadRules("CN", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestForLocality) {
AddressData address;
address.region_code = "CN";
address.locality = "Anqin";
+ address.language_code = "zh-Latn";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, LOCALITY, 10, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("Anqing Shi", suggestions[0].locality);
- EXPECT_EQ("ANHUI SHENG", suggestions[0].administrative_area);
+ EXPECT_EQ("Anhui Sheng", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, SuggestForLocalityAndAdminArea) {
- validator_->LoadRules("CN", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestForLocalityAndAdminArea) {
AddressData address;
address.region_code = "CN";
address.locality = "Anqing";
address.administrative_area = "Anhui";
+ address.language_code = "zh-Latn";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, LOCALITY, 10, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_TRUE(suggestions[0].dependent_locality.empty());
EXPECT_EQ("Anqing Shi", suggestions[0].locality);
- EXPECT_EQ("ANHUI SHENG", suggestions[0].administrative_area);
+ EXPECT_EQ("Anhui Sheng", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, SuggestForAdminAreaAndLocality) {
- validator_->LoadRules("CN", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestForAdminAreaAndLocality) {
AddressData address;
address.region_code = "CN";
address.locality = "Anqing";
address.administrative_area = "Anhui";
+ address.language_code = "zh-Latn";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, ADMIN_AREA, 10, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_TRUE(suggestions[0].dependent_locality.empty());
EXPECT_TRUE(suggestions[0].locality.empty());
- EXPECT_EQ("ANHUI SHENG", suggestions[0].administrative_area);
+ EXPECT_EQ("Anhui Sheng", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, SuggestForDependentLocality) {
- validator_->LoadRules("CN", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestForDependentLocality) {
AddressData address;
address.region_code = "CN";
address.dependent_locality = "Zongyang";
+ address.language_code = "zh-Latn";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(
address, DEPENDENT_LOCALITY, 10, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("Zongyang Xian", suggestions[0].dependent_locality);
EXPECT_EQ("Anqing Shi", suggestions[0].locality);
- EXPECT_EQ("ANHUI SHENG", suggestions[0].administrative_area);
+ EXPECT_EQ("Anhui Sheng", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest,
+TEST_F(LargeAddressValidatorTest,
NoSuggestForDependentLocalityWithWrongAdminArea) {
- validator_->LoadRules("CN", *loaded_);
AddressData address;
address.region_code = "CN";
address.dependent_locality = "Zongyang";
address.administrative_area = "Sichuan Sheng";
+ address.language_code = "zh-Latn";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(
address, DEPENDENT_LOCALITY, 10, &suggestions));
EXPECT_TRUE(suggestions.empty());
}
-TEST_F(PreloadAddressValidatorTest, EmptySuggestionsOverLimit) {
+TEST_F(AddressValidatorTest, EmptySuggestionsOverLimit) {
AddressData address;
address.region_code = "US";
address.administrative_area = "A";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, ADMIN_AREA, 1, &suggestions));
EXPECT_TRUE(suggestions.empty());
}
-TEST_F(PreloadAddressValidatorTest, PreferShortSuggestions) {
+TEST_F(AddressValidatorTest, PreferShortSuggestions) {
AddressData address;
address.region_code = "US";
address.administrative_area = "CA";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, ADMIN_AREA, 10, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("CA", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, SuggestTheSingleMatchForFullMatchName) {
+TEST_F(AddressValidatorTest, SuggestTheSingleMatchForFullMatchName) {
AddressData address;
address.region_code = "US";
address.administrative_area = "Texas";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, ADMIN_AREA, 10, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("Texas", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, SuggestAdminArea) {
+TEST_F(AddressValidatorTest, SuggestAdminArea) {
AddressData address;
address.region_code = "US";
address.administrative_area = "Cali";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, ADMIN_AREA, 10, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("California", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, MultipleSuggestions) {
+TEST_F(AddressValidatorTest, MultipleSuggestions) {
AddressData address;
address.region_code = "US";
address.administrative_area = "MA";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, ADMIN_AREA, 10, &suggestions));
EXPECT_LT(1U, suggestions.size());
@@ -453,96 +486,104 @@ TEST_F(PreloadAddressValidatorTest, MultipleSuggestions) {
expected_suggestions.insert("Marshall Islands");
expected_suggestions.insert("Maryland");
for (std::vector<AddressData>::const_iterator it = suggestions.begin();
- it != suggestions.end(); ++it) {
+ it != suggestions.end();
+ ++it) {
expected_suggestions.erase(it->administrative_area);
}
EXPECT_TRUE(expected_suggestions.empty());
}
-TEST_F(PreloadAddressValidatorTest, SuggestNonLatinKeyWhenLanguageMatches) {
- validator_->LoadRules("KR", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestNonLatinKeyWhenLanguageMatches) {
AddressData address;
address.language_code = "ko";
address.region_code = "KR";
address.postal_code = "210-210";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("강원도", suggestions[0].administrative_area);
EXPECT_EQ("210-210", suggestions[0].postal_code);
}
-TEST_F(PreloadAddressValidatorTest, SuggestNonLatinKeyWhenUserInputIsNotLatin) {
- validator_->LoadRules("KR", *loaded_);
+TEST_F(LargeAddressValidatorTest, SuggestNonLatinKeyWhenUserInputIsNotLatin) {
AddressData address;
address.language_code = "en";
address.region_code = "KR";
address.administrative_area = "강원";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, ADMIN_AREA, 1, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("강원도", suggestions[0].administrative_area);
}
-TEST_F(PreloadAddressValidatorTest,
+TEST_F(LargeAddressValidatorTest,
SuggestLatinNameWhenLanguageDiffersAndLatinNameAvailable) {
- validator_->LoadRules("KR", *loaded_);
AddressData address;
- address.language_code = "en";
+ address.language_code = "ko-Latn";
address.region_code = "KR";
address.postal_code = "210-210";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
ASSERT_EQ(1U, suggestions.size());
EXPECT_EQ("Gangwon", suggestions[0].administrative_area);
EXPECT_EQ("210-210", suggestions[0].postal_code);
}
-TEST_F(PreloadAddressValidatorTest, SuggestLatinNameWhenUserInputIsLatin) {
- validator_->LoadRules("KR", *loaded_);
+TEST_F(AddressValidatorTest, NoSuggestionsForEmptyAddress) {
AddressData address;
- address.language_code = "ko";
- address.region_code = "KR";
- address.administrative_area = "Gang";
+ address.region_code = "US";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
- validator_->GetSuggestions(address, ADMIN_AREA, 1, &suggestions));
+ EXPECT_EQ(
+ AddressValidator::SUCCESS,
+ validator_->GetSuggestions(address, POSTAL_CODE, 999, &suggestions));
+ EXPECT_TRUE(suggestions.empty());
+}
+
+TEST_F(AddressValidatorTest, SuggestionIncludesCountry) {
+ AddressData address;
+ address.region_code = "US";
+ address.postal_code = "90291";
+
+ std::vector<AddressData> suggestions;
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
ASSERT_EQ(1U, suggestions.size());
- EXPECT_EQ("Gangwon", suggestions[0].administrative_area);
+ EXPECT_EQ("US", suggestions[0].region_code);
}
-TEST_F(PreloadAddressValidatorTest, NoSuggestionsForEmptyAddress) {
+TEST_F(AddressValidatorTest, InvalidPostalCodeNoSuggestions) {
AddressData address;
address.region_code = "US";
+ address.postal_code = "0";
std::vector<AddressData> suggestions;
EXPECT_EQ(
- PreloadAddressValidator::SUCCESS,
+ AddressValidator::SUCCESS,
validator_->GetSuggestions(address, POSTAL_CODE, 999, &suggestions));
EXPECT_TRUE(suggestions.empty());
}
-TEST_F(PreloadAddressValidatorTest, SuggestionIncludesCountry) {
+TEST_F(AddressValidatorTest, MismatchedPostalCodeNoSuggestions) {
AddressData address;
address.region_code = "US";
+ address.administrative_area = "TX";
address.postal_code = "90291";
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
- validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
- ASSERT_EQ(1U, suggestions.size());
- EXPECT_EQ("US", suggestions[0].region_code);
+ EXPECT_EQ(
+ AddressValidator::SUCCESS,
+ validator_->GetSuggestions(address, POSTAL_CODE, 999, &suggestions));
+ EXPECT_TRUE(suggestions.empty());
}
-TEST_F(PreloadAddressValidatorTest,
- SuggestOnlyForAdministrativeAreasAndPostalCode) {
+TEST_F(AddressValidatorTest, SuggestOnlyForAdministrativeAreasAndPostalCode) {
AddressData address;
address.region_code = "US";
address.administrative_area = "CA";
@@ -568,14 +609,24 @@ TEST_F(PreloadAddressValidatorTest,
for (size_t i = 0; i < kNumNoSuggestFields; ++i) {
std::vector<AddressData> suggestions;
- EXPECT_EQ(PreloadAddressValidator::SUCCESS,
+ EXPECT_EQ(AddressValidator::SUCCESS,
validator_->GetSuggestions(
address, kNoSugestFields[i], 999, &suggestions));
EXPECT_TRUE(suggestions.empty());
}
}
-TEST_F(PreloadAddressValidatorTest, CanonicalizeUsAdminAreaName) {
+TEST_F(AddressValidatorTest, SuggestionsAreCleared) {
+ AddressData address;
+ address.region_code = "US";
+
+ std::vector<AddressData> suggestions(1, address);
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->GetSuggestions(address, POSTAL_CODE, 1, &suggestions));
+ EXPECT_TRUE(suggestions.empty());
+}
+
+TEST_F(AddressValidatorTest, CanonicalizeUsAdminAreaName) {
AddressData address;
address.region_code = "US";
address.administrative_area = "cALIFORNIa";
@@ -583,7 +634,7 @@ TEST_F(PreloadAddressValidatorTest, CanonicalizeUsAdminAreaName) {
EXPECT_EQ("CA", address.administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, CanonicalizeUsAdminAreaKey) {
+TEST_F(AddressValidatorTest, CanonicalizeUsAdminAreaKey) {
AddressData address;
address.region_code = "US";
address.administrative_area = "CA";
@@ -591,8 +642,8 @@ TEST_F(PreloadAddressValidatorTest, CanonicalizeUsAdminAreaKey) {
EXPECT_EQ("CA", address.administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, CanonicalizeJpAdminAreaKey) {
- validator_->LoadRules("JP", *loaded_);
+TEST_F(AddressValidatorTest, CanonicalizeJpAdminAreaKey) {
+ validator_->LoadRules("JP");
AddressData address;
address.region_code = "JP";
address.administrative_area = "東京都";
@@ -600,8 +651,8 @@ TEST_F(PreloadAddressValidatorTest, CanonicalizeJpAdminAreaKey) {
EXPECT_EQ("東京都", address.administrative_area);
}
-TEST_F(PreloadAddressValidatorTest, CanonicalizeJpAdminAreaLatinName) {
- validator_->LoadRules("JP", *loaded_);
+TEST_F(AddressValidatorTest, CanonicalizeJpAdminAreaLatinName) {
+ validator_->LoadRules("JP");
AddressData address;
address.region_code = "JP";
address.administrative_area = "tOKYo";
@@ -609,4 +660,81 @@ TEST_F(PreloadAddressValidatorTest, CanonicalizeJpAdminAreaLatinName) {
EXPECT_EQ("TOKYO", address.administrative_area);
}
+TEST_F(AddressValidatorTest, TokushimaSuggestionIsValid) {
+ validator_->LoadRules("JP");
+ AddressData address;
+ address.region_code = "JP";
+ address.administrative_area = "Toku";
+ address.language_code = "ja-Latn";
+
+ std::vector<AddressData> suggestions;
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->GetSuggestions(address, ADMIN_AREA, 1, &suggestions));
+ ASSERT_EQ(1U, suggestions.size());
+ EXPECT_EQ("TOKUSHIMA", suggestions[0].administrative_area);
+
+ FieldProblemMap filter;
+ for (int i = UNEXPECTED_FIELD; i <= USES_P_O_BOX; ++i)
+ filter.insert(std::make_pair(ADMIN_AREA, static_cast<AddressProblem>(i)));
+
+ FieldProblemMap problems;
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->ValidateAddress(suggestions[0], &filter, &problems));
+ EXPECT_TRUE(problems.empty());
+}
+
+TEST_F(AddressValidatorTest, ValidPostalCodeInSuggestion) {
+ validator_->LoadRules("US");
+ AddressData address;
+ address.region_code = "US";
+ address.administrative_area = "New";
+ address.postal_code = "13699";
+
+ std::vector<AddressData> suggestions;
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->GetSuggestions(address, ADMIN_AREA, 999, &suggestions));
+ ASSERT_EQ(1U, suggestions.size());
+ EXPECT_EQ("New York", suggestions[0].administrative_area);
+
+ address.administrative_area = "New";
+ address.postal_code = "03755";
+
+ EXPECT_EQ(AddressValidator::SUCCESS,
+ validator_->GetSuggestions(address, ADMIN_AREA, 999, &suggestions));
+ ASSERT_EQ(1U, suggestions.size());
+ EXPECT_EQ("New Hampshire", suggestions[0].administrative_area);
+}
+
+TEST_F(AddressValidatorTest, ValidateRequiredFieldsWithoutRules) {
+ // Do not load the rules for JP.
+ AddressData address;
+ address.region_code = "JP";
+
+ FieldProblemMap problems;
+ EXPECT_EQ(AddressValidator::RULES_UNAVAILABLE,
+ validator_->ValidateAddress(address, NULL, &problems));
+ EXPECT_FALSE(problems.empty());
+
+ for (FieldProblemMap::const_iterator it = problems.begin();
+ it != problems.end();
+ ++it) {
+ EXPECT_EQ(MISSING_REQUIRED_FIELD, it->second);
+ }
+}
+
+TEST_F(AddressValidatorTest,
+ DoNotValidateRequiredFieldsWithoutRulesWhenErorrIsFiltered) {
+ // Do not load the rules for JP.
+ AddressData address;
+ address.region_code = "JP";
+
+ FieldProblemMap filter;
+ filter.insert(std::make_pair(COUNTRY, UNKNOWN_VALUE));
+
+ FieldProblemMap problems;
+ EXPECT_EQ(AddressValidator::RULES_UNAVAILABLE,
+ validator_->ValidateAddress(address, &filter, &problems));
+ EXPECT_TRUE(problems.empty());
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698