Commit df4f58a1 authored by rouslan@chromium.org's avatar rouslan@chromium.org

Remove libaddressinput_util.h

This patch removes libaddressinput_util.h, which was left over after a
bad merge. This file is identical to addressinput_util.h.

TBR=estade@chromium.org
BUG=393587

Review URL: https://codereview.chromium.org/392633002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282961 0039d316-1c4b-4281-b951-d872f2087c98
parent f5273e53
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "third_party/libaddressinput/chromium/addressinput_util.h"
#include "third_party/libaddressinput/chromium/input_suggester.h" #include "third_party/libaddressinput/chromium/input_suggester.h"
#include "third_party/libaddressinput/chromium/libaddressinput_util.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.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_field.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_normalizer.h" #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_normalizer.h"
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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/libaddressinput_util.h"
#include <algorithm>
#include "base/logging.h"
#include "base/macros.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_metadata.h"
namespace autofill {
namespace addressinput {
namespace {
using ::i18n::addressinput::AddressData;
using ::i18n::addressinput::AddressField;
using ::i18n::addressinput::AddressProblem;
using ::i18n::addressinput::IsFieldRequired;
using ::i18n::addressinput::MISSING_REQUIRED_FIELD;
// Based on ::i18n::addressinput::ValidationTask::ShouldReport().
bool ShouldReport(const std::multimap<AddressField, AddressProblem>* filter,
AddressField field,
AddressProblem problem) {
return filter == NULL || filter->empty() ||
std::find(filter->begin(),
filter->end(),
std::multimap<AddressField, AddressProblem>::value_type(
field, problem)) != filter->end();
}
} // namespace
bool HasAllRequiredFields(const AddressData& address_to_check) {
std::multimap<AddressField, AddressProblem> problems;
ValidateRequiredFields(address_to_check, NULL, &problems);
return problems.empty();
}
void ValidateRequiredFields(
const AddressData& address_to_check,
const std::multimap<AddressField, AddressProblem>* filter,
std::multimap<AddressField, AddressProblem>* problems) {
DCHECK(problems);
static const AddressField kFields[] = {
::i18n::addressinput::COUNTRY,
::i18n::addressinput::ADMIN_AREA,
::i18n::addressinput::LOCALITY,
::i18n::addressinput::DEPENDENT_LOCALITY,
::i18n::addressinput::SORTING_CODE,
::i18n::addressinput::POSTAL_CODE,
::i18n::addressinput::STREET_ADDRESS,
::i18n::addressinput::RECIPIENT};
for (size_t i = 0; i < arraysize(kFields); ++i) {
AddressField field = kFields[i];
if (address_to_check.IsFieldEmpty(field) &&
IsFieldRequired(field, address_to_check.region_code) &&
ShouldReport(filter, field, MISSING_REQUIRED_FIELD)) {
problems->insert(std::make_pair(field, MISSING_REQUIRED_FIELD));
}
}
}
} // namespace addressinput
} // namespace autofill
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_LIBADDRESSINPUT_UTIL_H_
#define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_LIBADDRESSINPUT_UTIL_H_
#include <map>
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_problem.h"
namespace i18n {
namespace addressinput {
struct AddressData;
}
}
namespace autofill {
namespace addressinput {
// Returns true if |address_to_check| has all of its required fields.
bool HasAllRequiredFields(
const ::i18n::addressinput::AddressData& address_to_check);
// Validates required fields in |address_to_check| without loading rules from
// the server. The |problems| parameter cannot be NULL. Does not take ownership
// of its parameters.
//
// See documentation of ::i18n::addressinput::AddressValidator::Validate() for
// description of |filter| and |problems|.
void ValidateRequiredFields(
const ::i18n::addressinput::AddressData& address_to_check,
const std::multimap< ::i18n::addressinput::AddressField,
::i18n::addressinput::AddressProblem>* filter,
std::multimap< ::i18n::addressinput::AddressField,
::i18n::addressinput::AddressProblem>* problems);
} // namespace addressinput
} // namespace autofill
#endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_LIBADDRESSINPUT_UTIL_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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/libaddressinput_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
namespace autofill {
namespace addressinput {
using ::i18n::addressinput::AddressData;
TEST(RequiredFieldsTest, AddressRequiresRegionCode) {
AddressData address;
EXPECT_FALSE(HasAllRequiredFields(address));
}
TEST(RequiredFieldsTest, UsRequiresState) {
AddressData address;
address.region_code = "US";
address.postal_code = "90291";
// Leave state empty.
address.locality = "Los Angeles";
address.address_line.push_back("340 Main St.");
EXPECT_FALSE(HasAllRequiredFields(address));
}
TEST(RequiredFieldsTest, CompleteAddressReturnsTrue) {
AddressData address;
address.region_code = "US";
address.postal_code = "90291";
address.administrative_area = "CA";
address.locality = "Los Angeles";
address.address_line.push_back("340 Main St.");
EXPECT_TRUE(HasAllRequiredFields(address));
}
} // namespace addressinput
} // namespace autofill
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment