1 // Copyright (C) 2014 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <libaddressinput/address_metadata.h>
17 #include <libaddressinput/address_field.h>
19 #include <gtest/gtest.h>
23 using i18n::addressinput::COUNTRY;
24 using i18n::addressinput::ADMIN_AREA;
25 using i18n::addressinput::DEPENDENT_LOCALITY;
27 using i18n::addressinput::IsFieldRequired;
28 using i18n::addressinput::IsFieldUsed;
30 TEST(AddressMetadataTest, IsFieldRequiredCountry) {
31 EXPECT_TRUE(IsFieldRequired(COUNTRY, "US"));
32 EXPECT_TRUE(IsFieldRequired(COUNTRY, "CH"));
33 EXPECT_TRUE(IsFieldRequired(COUNTRY, "rrr"));
36 TEST(AddressMetadataTest, IsUsedRequiredCountry) {
37 EXPECT_TRUE(IsFieldUsed(COUNTRY, "US"));
38 EXPECT_TRUE(IsFieldUsed(COUNTRY, "CH"));
39 EXPECT_TRUE(IsFieldUsed(COUNTRY, "rrr"));
42 TEST(AddressMetadataTest, IsFieldRequiredAdminAreaUS) {
43 EXPECT_TRUE(IsFieldRequired(ADMIN_AREA, "US"));
46 TEST(AddressMetadataTest, IsFieldRequiredAdminAreaAT) {
47 EXPECT_FALSE(IsFieldRequired(ADMIN_AREA, "AT"));
50 TEST(AddressMetadataTest, IsFieldRequiredAdminAreaSU) {
51 // Unsupported region.
52 EXPECT_FALSE(IsFieldRequired(ADMIN_AREA, "SU"));
55 TEST(AddressMetadataTest, IsFieldUsedDependentLocalityUS) {
56 EXPECT_FALSE(IsFieldUsed(DEPENDENT_LOCALITY, "US"));
59 TEST(AddressMetadataTest, IsFieldUsedDependentLocalityCN) {
60 EXPECT_TRUE(IsFieldUsed(DEPENDENT_LOCALITY, "CN"));
63 TEST(AddressMetadataTest, IsFieldUsedDependentLocalitySU) {
64 // Unsupported region.
65 EXPECT_FALSE(IsFieldUsed(DEPENDENT_LOCALITY, "SU"));