aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRouslan Solomakhin <rouslan@chromium.org>2014-08-21 18:11:36 +0000
committerFredrik Roubert <roubert@google.com>2014-09-01 19:20:51 +0200
commit34e47fe60c733b3d18a0ccc148ba2b2c0dec31c0 (patch)
treef622b759469b3a9d97b0ce2412987bd6729d5677
parent29b4ddc6e41b736a8ddf72d2dd72bed10ac510c6 (diff)
downloadsrc-34e47fe60c733b3d18a0ccc148ba2b2c0dec31c0.tar.gz
Add back the organization field.
Add back the field for organization, company, firm, or institution. This field is necessary for Chrome Autofill. TBR=lararennie@google.com,roubert@google.com Review URL: https://codereview.appspot.com/121620043
-rw-r--r--cpp/include/libaddressinput/address_data.h4
-rw-r--r--cpp/include/libaddressinput/address_field.h1
-rw-r--r--cpp/res/messages.grdp7
-rw-r--r--cpp/src/address_data.cc7
-rw-r--r--cpp/src/address_field.cc1
-rw-r--r--cpp/src/address_field_util.cc1
-rw-r--r--cpp/src/address_ui.cc3
-rw-r--r--cpp/src/validation_task.cc4
-rw-r--r--cpp/test/address_data_test.cc10
-rw-r--r--cpp/test/address_field_util_test.cc10
-rw-r--r--cpp/test/address_ui_test.cc20
-rw-r--r--cpp/test/localization_test.cc21
-rw-r--r--cpp/test/validation_task_test.cc3
13 files changed, 77 insertions, 15 deletions
diff --git a/cpp/include/libaddressinput/address_data.h b/cpp/include/libaddressinput/address_data.h
index e2d057a..89d3273 100644
--- a/cpp/include/libaddressinput/address_data.h
+++ b/cpp/include/libaddressinput/address_data.h
@@ -55,6 +55,10 @@ struct AddressData {
// Language code of the address. Should be in BCP-47 format.
std::string language_code;
+ // The organization, firm, company, or institution at this address. This
+ // corresponds to the FirmName sub-element of the xAL FirmType element.
+ std::string organization;
+
// Name of recipient or contact person. Not present in xAL.
std::string recipient;
diff --git a/cpp/include/libaddressinput/address_field.h b/cpp/include/libaddressinput/address_field.h
index 1adc97b..8f2ee05 100644
--- a/cpp/include/libaddressinput/address_field.h
+++ b/cpp/include/libaddressinput/address_field.h
@@ -31,6 +31,7 @@ enum AddressField {
SORTING_CODE, // Sorting code.
POSTAL_CODE, // Zip or postal code.
STREET_ADDRESS, // Street address lines.
+ ORGANIZATION, // Organization, company, firm, institution, etc.
RECIPIENT // Name.
};
diff --git a/cpp/res/messages.grdp b/cpp/res/messages.grdp
index c04449a..7ca2000 100644
--- a/cpp/res/messages.grdp
+++ b/cpp/res/messages.grdp
@@ -113,6 +113,13 @@ limitations under the License.
State
</message>
<message
+ name="IDS_LIBADDRESSINPUT_ORGANIZATION_LABEL"
+ desc="Label for the field of organization, firm, company, or institution
+ in an address. Examples of values in this field: Google,
+ Department of Transportation, University of Cambridge.">
+ Organization
+ </message>
+ <message
name="IDS_LIBADDRESSINPUT_RECIPIENT_LABEL"
desc="Label for the field for a person's name in an address.">
Name
diff --git a/cpp/src/address_data.cc b/cpp/src/address_data.cc
index 644000e..40d3ee7 100644
--- a/cpp/src/address_data.cc
+++ b/cpp/src/address_data.cc
@@ -41,6 +41,7 @@ std::string AddressData::*kStringField[] = {
&AddressData::sorting_code,
&AddressData::postal_code,
NULL,
+ &AddressData::organization,
&AddressData::recipient
};
@@ -53,6 +54,7 @@ const std::vector<std::string> AddressData::*kVectorStringField[] = {
NULL,
NULL,
&AddressData::address_line,
+ NULL,
NULL
};
@@ -111,7 +113,9 @@ bool AddressData::operator==(const AddressData& other) const {
dependent_locality == other.dependent_locality &&
postal_code == other.postal_code &&
sorting_code == other.sorting_code &&
- language_code == other.language_code && recipient == other.recipient;
+ language_code == other.language_code &&
+ organization == other.organization &&
+ recipient == other.recipient;
}
// static
@@ -142,6 +146,7 @@ std::ostream& operator<<(std::ostream& o,
}
o << "language_code: \"" << address.language_code << "\"\n"
+ "organization: \"" << address.organization << "\"\n"
"recipient: \"" << address.recipient << "\"\n";
return o;
diff --git a/cpp/src/address_field.cc b/cpp/src/address_field.cc
index 7d57e06..c5c96d8 100644
--- a/cpp/src/address_field.cc
+++ b/cpp/src/address_field.cc
@@ -32,6 +32,7 @@ std::ostream& operator<<(std::ostream& o, AddressField field) {
"SORTING_CODE",
"POSTAL_CODE",
"STREET_ADDRESS",
+ "ORGANIZATION",
"RECIPIENT"
};
COMPILE_ASSERT(COUNTRY == 0, bad_base);
diff --git a/cpp/src/address_field_util.cc b/cpp/src/address_field_util.cc
index 1cac289..26de3c0 100644
--- a/cpp/src/address_field_util.cc
+++ b/cpp/src/address_field_util.cc
@@ -40,6 +40,7 @@ std::map<char, AddressField> InitFields() {
fields.insert(std::make_pair('X', SORTING_CODE));
fields.insert(std::make_pair('Z', POSTAL_CODE));
fields.insert(std::make_pair('A', STREET_ADDRESS));
+ fields.insert(std::make_pair('O', ORGANIZATION));
fields.insert(std::make_pair('N', RECIPIENT));
return fields;
}
diff --git a/cpp/src/address_ui.cc b/cpp/src/address_ui.cc
index bf76cfd..33f0797 100644
--- a/cpp/src/address_ui.cc
+++ b/cpp/src/address_ui.cc
@@ -63,6 +63,9 @@ std::string GetLabelForField(const Localization& localization,
case STREET_ADDRESS:
messageId = IDS_LIBADDRESSINPUT_ADDRESS_LINE_1_LABEL;
break;
+ case ORGANIZATION:
+ messageId = IDS_LIBADDRESSINPUT_ORGANIZATION_LABEL;
+ break;
case RECIPIENT:
messageId = IDS_LIBADDRESSINPUT_RECIPIENT_LABEL;
break;
diff --git a/cpp/src/validation_task.cc b/cpp/src/validation_task.cc
index 727de6a..1e7911a 100644
--- a/cpp/src/validation_task.cc
+++ b/cpp/src/validation_task.cc
@@ -110,6 +110,7 @@ void ValidationTask::CheckUnexpectedField(
SORTING_CODE,
POSTAL_CODE,
STREET_ADDRESS,
+ ORGANIZATION,
RECIPIENT
};
@@ -132,7 +133,8 @@ void ValidationTask::CheckMissingRequiredField(
DEPENDENT_LOCALITY,
SORTING_CODE,
POSTAL_CODE,
- STREET_ADDRESS,
+ STREET_ADDRESS
+ // ORGANIZATION is never required.
// RECIPIENT is handled separately.
};
diff --git a/cpp/test/address_data_test.cc b/cpp/test/address_data_test.cc
index 8ba0f4b..46491c9 100644
--- a/cpp/test/address_data_test.cc
+++ b/cpp/test/address_data_test.cc
@@ -32,6 +32,7 @@ using i18n::addressinput::DEPENDENT_LOCALITY;
using i18n::addressinput::SORTING_CODE;
using i18n::addressinput::POSTAL_CODE;
using i18n::addressinput::STREET_ADDRESS;
+using i18n::addressinput::ORGANIZATION;
using i18n::addressinput::RECIPIENT;
TEST(AddressDataTest, GetFieldValue) {
@@ -42,6 +43,7 @@ TEST(AddressDataTest, GetFieldValue) {
address.dependent_locality = "ddd";
address.sorting_code = "xxx";
address.postal_code = "zzz";
+ address.organization = "ooo";
address.recipient = "nnn";
EXPECT_EQ(address.region_code,
@@ -56,6 +58,8 @@ TEST(AddressDataTest, GetFieldValue) {
address.GetFieldValue(SORTING_CODE));
EXPECT_EQ(address.postal_code,
address.GetFieldValue(POSTAL_CODE));
+ EXPECT_EQ(address.organization,
+ address.GetFieldValue(ORGANIZATION));
EXPECT_EQ(address.recipient,
address.GetFieldValue(RECIPIENT));
}
@@ -78,6 +82,7 @@ TEST(AddressDataTest, IsFieldEmpty) {
EXPECT_TRUE(address.IsFieldEmpty(SORTING_CODE));
EXPECT_TRUE(address.IsFieldEmpty(POSTAL_CODE));
EXPECT_TRUE(address.IsFieldEmpty(STREET_ADDRESS));
+ EXPECT_TRUE(address.IsFieldEmpty(ORGANIZATION));
EXPECT_TRUE(address.IsFieldEmpty(RECIPIENT));
address.region_code = "rrr";
@@ -87,6 +92,7 @@ TEST(AddressDataTest, IsFieldEmpty) {
address.sorting_code = "xxx";
address.postal_code = "zzz";
address.address_line.push_back("aaa");
+ address.organization = "ooo";
address.recipient = "nnn";
EXPECT_FALSE(address.IsFieldEmpty(COUNTRY));
@@ -96,6 +102,7 @@ TEST(AddressDataTest, IsFieldEmpty) {
EXPECT_FALSE(address.IsFieldEmpty(SORTING_CODE));
EXPECT_FALSE(address.IsFieldEmpty(POSTAL_CODE));
EXPECT_FALSE(address.IsFieldEmpty(STREET_ADDRESS));
+ EXPECT_FALSE(address.IsFieldEmpty(ORGANIZATION));
EXPECT_FALSE(address.IsFieldEmpty(RECIPIENT));
}
@@ -149,6 +156,7 @@ TEST(AddressDataTest, StreamFunction) {
address.dependent_locality = "D";
address.sorting_code = "X";
address.language_code = "zh-Hant";
+ address.organization = "O";
oss << address;
EXPECT_EQ("region_code: \"R\"\n"
"administrative_area: \"S\"\n"
@@ -159,6 +167,7 @@ TEST(AddressDataTest, StreamFunction) {
"address_line: \"Line 1\"\n"
"address_line: \"Line 2\"\n"
"language_code: \"zh-Hant\"\n"
+ "organization: \"O\"\n"
"recipient: \"N\"\n", oss.str());
}
@@ -173,6 +182,7 @@ TEST(AddressDataTest, TestEquals) {
address.locality = "C";
address.dependent_locality = "D";
address.sorting_code = "X";
+ address.organization = "O";
address.language_code = "zh-Hant";
AddressData clone = address;
diff --git a/cpp/test/address_field_util_test.cc b/cpp/test/address_field_util_test.cc
index 0db6bf5..0cde367 100644
--- a/cpp/test/address_field_util_test.cc
+++ b/cpp/test/address_field_util_test.cc
@@ -26,20 +26,22 @@
namespace {
using i18n::addressinput::AddressField;
-using i18n::addressinput::COUNTRY;
using i18n::addressinput::FormatElement;
-using i18n::addressinput::LOCALITY;
using i18n::addressinput::ParseFormatRule;
+
+using i18n::addressinput::COUNTRY;
+using i18n::addressinput::LOCALITY;
using i18n::addressinput::POSTAL_CODE;
-using i18n::addressinput::RECIPIENT;
using i18n::addressinput::STREET_ADDRESS;
+using i18n::addressinput::ORGANIZATION;
+using i18n::addressinput::RECIPIENT;
TEST(AddressFieldUtilTest, FormatParseNewline) {
std::vector<FormatElement> actual;
ParseFormatRule("%O%n%N%n%A%nAX-%Z %C%n\xC3\x85LAND", &actual); /* "Ă…LAND" */
std::vector<FormatElement> expected;
- // Organization is skipped.
+ expected.push_back(FormatElement(ORGANIZATION));
expected.push_back(FormatElement());
expected.push_back(FormatElement(RECIPIENT));
expected.push_back(FormatElement());
diff --git a/cpp/test/address_ui_test.cc b/cpp/test/address_ui_test.cc
index 805d1de..d2e512f 100644
--- a/cpp/test/address_ui_test.cc
+++ b/cpp/test/address_ui_test.cc
@@ -29,14 +29,16 @@ namespace {
using i18n::addressinput::AddressField;
using i18n::addressinput::AddressUiComponent;
-using i18n::addressinput::ADMIN_AREA;
using i18n::addressinput::BuildComponents;
-using i18n::addressinput::COUNTRY;
using i18n::addressinput::GetRegionCodes;
using i18n::addressinput::Localization;
+
+using i18n::addressinput::COUNTRY;
+using i18n::addressinput::ADMIN_AREA;
using i18n::addressinput::POSTAL_CODE;
-using i18n::addressinput::RECIPIENT;
using i18n::addressinput::STREET_ADDRESS;
+using i18n::addressinput::ORGANIZATION;
+using i18n::addressinput::RECIPIENT;
static const char kUiLanguageTag[] = "en";
@@ -219,12 +221,12 @@ INSTANTIATE_TEST_CASE_P(
LanguageTestCase("MO", "en", "zh-Latn", RECIPIENT),
// Switzerland supports de, fr, and it.
- LanguageTestCase("CH", "de", "de", RECIPIENT),
- LanguageTestCase("CH", "de-DE", "de", RECIPIENT),
- LanguageTestCase("CH", "de-Latn-DE", "de", RECIPIENT),
- LanguageTestCase("CH", "fr", "fr", RECIPIENT),
- LanguageTestCase("CH", "it", "it", RECIPIENT),
- LanguageTestCase("CH", "en", "de", RECIPIENT),
+ LanguageTestCase("CH", "de", "de", ORGANIZATION),
+ LanguageTestCase("CH", "de-DE", "de", ORGANIZATION),
+ LanguageTestCase("CH", "de-Latn-DE", "de", ORGANIZATION),
+ LanguageTestCase("CH", "fr", "fr", ORGANIZATION),
+ LanguageTestCase("CH", "it", "it", ORGANIZATION),
+ LanguageTestCase("CH", "en", "de", ORGANIZATION),
// Antarctica does not have language information.
LanguageTestCase("AQ", "en", "en", RECIPIENT),
diff --git a/cpp/test/localization_test.cc b/cpp/test/localization_test.cc
index 2c620c4..1eba5b8 100644
--- a/cpp/test/localization_test.cc
+++ b/cpp/test/localization_test.cc
@@ -41,6 +41,7 @@ using i18n::addressinput::DEPENDENT_LOCALITY;
using i18n::addressinput::SORTING_CODE;
using i18n::addressinput::POSTAL_CODE;
using i18n::addressinput::STREET_ADDRESS;
+using i18n::addressinput::ORGANIZATION;
using i18n::addressinput::RECIPIENT;
using i18n::addressinput::MISSING_REQUIRED_FIELD;
@@ -103,6 +104,7 @@ INSTANTIATE_TEST_CASE_P(
IDS_LIBADDRESSINPUT_PREFECTURE,
IDS_LIBADDRESSINPUT_PROVINCE,
IDS_LIBADDRESSINPUT_STATE,
+ IDS_LIBADDRESSINPUT_ORGANIZATION_LABEL,
IDS_LIBADDRESSINPUT_RECIPIENT_LABEL,
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_FIELD,
IDS_LIBADDRESSINPUT_MISSING_REQUIRED_POSTAL_CODE_EXAMPLE_AND_URL,
@@ -181,6 +183,7 @@ TEST(LocalizationGetErrorMessageTest, MissingRequiredOtherFields) {
other_fields.push_back(DEPENDENT_LOCALITY);
other_fields.push_back(SORTING_CODE);
other_fields.push_back(STREET_ADDRESS);
+ other_fields.push_back(ORGANIZATION);
other_fields.push_back(RECIPIENT);
for (std::vector<AddressField>::iterator it = other_fields.begin();
it != other_fields.end(); it++) {
@@ -211,6 +214,7 @@ TEST(LocalizationGetErrorMessageTest, UnknownValueOtherFields) {
address_line.push_back("bad address line 1");
address_line.push_back("bad address line 2");
address.address_line = address_line;
+ address.organization = "bad organization";
address.recipient = "bad recipient";
EXPECT_EQ("US "
"is not recognized as a known value for this field.",
@@ -308,6 +312,22 @@ TEST(LocalizationGetErrorMessageTest, UnknownValueOtherFields) {
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
address, STREET_ADDRESS, UNKNOWN_VALUE, false, true));
+ EXPECT_EQ("bad organization "
+ "is not recognized as a known value for this field.",
+ localization.GetErrorMessage(
+ address, ORGANIZATION, UNKNOWN_VALUE, true, true));
+ EXPECT_EQ("bad organization "
+ "is not recognized as a known value for this field.",
+ localization.GetErrorMessage(
+ address, ORGANIZATION, UNKNOWN_VALUE, true, false));
+ EXPECT_EQ("bad organization "
+ "is not recognized as a known value for this field.",
+ localization.GetErrorMessage(
+ address, ORGANIZATION, UNKNOWN_VALUE, false, false));
+ EXPECT_EQ("bad organization "
+ "is not recognized as a known value for this field.",
+ localization.GetErrorMessage(
+ address, ORGANIZATION, UNKNOWN_VALUE, false, true));
EXPECT_EQ("bad recipient "
"is not recognized as a known value for this field.",
localization.GetErrorMessage(
@@ -439,6 +459,7 @@ TEST(LocalizationGetErrorMessageTest, UsesPOBoxOtherFields) {
other_fields.push_back(DEPENDENT_LOCALITY);
other_fields.push_back(SORTING_CODE);
other_fields.push_back(STREET_ADDRESS);
+ other_fields.push_back(ORGANIZATION);
other_fields.push_back(RECIPIENT);
for (std::vector<AddressField>::iterator it = other_fields.begin();
it != other_fields.end(); it++) {
diff --git a/cpp/test/validation_task_test.cc b/cpp/test/validation_task_test.cc
index a092ff7..9caf996 100644
--- a/cpp/test/validation_task_test.cc
+++ b/cpp/test/validation_task_test.cc
@@ -57,6 +57,7 @@ class ValidationTaskTest : public testing::Test {
SORTING_CODE,
POSTAL_CODE,
STREET_ADDRESS,
+ ORGANIZATION,
RECIPIENT
};
@@ -213,12 +214,14 @@ TEST_F(ValidationTaskTest, MissingNoRequiredFieldsUS) {
address_.locality = "ccc";
address_.postal_code = "zzz";
address_.address_line.push_back("aaa");
+ address_.organization = "ooo";
address_.recipient = "nnn";
filter_.insert(std::make_pair(ADMIN_AREA, MISSING_REQUIRED_FIELD));
filter_.insert(std::make_pair(LOCALITY, MISSING_REQUIRED_FIELD));
filter_.insert(std::make_pair(POSTAL_CODE, MISSING_REQUIRED_FIELD));
filter_.insert(std::make_pair(STREET_ADDRESS, MISSING_REQUIRED_FIELD));
+ filter_.insert(std::make_pair(ORGANIZATION, MISSING_REQUIRED_FIELD));
ASSERT_NO_FATAL_FAILURE(Validate());
ASSERT_TRUE(called_);