1// Copyright (C) 2014 Google Inc.
2//
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
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
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.
14
15#include <libaddressinput/address_metadata.h>
16
17#include <libaddressinput/address_field.h>
18
19#include <gtest/gtest.h>
20
21namespace {
22
23using i18n::addressinput::IsFieldRequired;
24using i18n::addressinput::IsFieldUsed;
25
26using i18n::addressinput::COUNTRY;
27using i18n::addressinput::ADMIN_AREA;
28using i18n::addressinput::DEPENDENT_LOCALITY;
29
30TEST(AddressMetadataTest, IsFieldRequiredCountry) {
31  EXPECT_TRUE(IsFieldRequired(COUNTRY, "US"));
32  EXPECT_TRUE(IsFieldRequired(COUNTRY, "CH"));
33  EXPECT_TRUE(IsFieldRequired(COUNTRY, "rrr"));
34}
35
36TEST(AddressMetadataTest, IsUsedRequiredCountry) {
37  EXPECT_TRUE(IsFieldUsed(COUNTRY, "US"));
38  EXPECT_TRUE(IsFieldUsed(COUNTRY, "CH"));
39  EXPECT_TRUE(IsFieldUsed(COUNTRY, "rrr"));
40}
41
42TEST(AddressMetadataTest, IsFieldRequiredAdminAreaUS) {
43  EXPECT_TRUE(IsFieldRequired(ADMIN_AREA, "US"));
44}
45
46TEST(AddressMetadataTest, IsFieldRequiredAdminAreaAT) {
47  EXPECT_FALSE(IsFieldRequired(ADMIN_AREA, "AT"));
48}
49
50TEST(AddressMetadataTest, IsFieldRequiredAdminAreaSU) {
51  // Unsupported region.
52  EXPECT_FALSE(IsFieldRequired(ADMIN_AREA, "SU"));
53}
54
55TEST(AddressMetadataTest, IsFieldUsedDependentLocalityUS) {
56  EXPECT_FALSE(IsFieldUsed(DEPENDENT_LOCALITY, "US"));
57}
58
59TEST(AddressMetadataTest, IsFieldUsedDependentLocalityCN) {
60  EXPECT_TRUE(IsFieldUsed(DEPENDENT_LOCALITY, "CN"));
61}
62
63TEST(AddressMetadataTest, IsFieldUsedDependentLocalitySU) {
64  // Unsupported region.
65  EXPECT_FALSE(IsFieldUsed(DEPENDENT_LOCALITY, "SU"));
66}
67
68}  // namespace
69