Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / libaddressinput / src / java / test / com / android / i18n / addressinput / AddressVerificationDataTest.java
1 /*
2  * Copyright (C) 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.i18n.addressinput;
18
19 import com.android.i18n.addressinput.testing.AddressDataMapLoader;
20
21 import junit.framework.TestCase;
22
23 /**
24  * Tests to ensure that {@code AddressVerificationData} can parse all the default data.
25  */
26 public class AddressVerificationDataTest extends TestCase {
27
28   private static final AddressVerificationData ADDRESS_DATA =
29       new AddressVerificationData(AddressDataMapLoader.DATA);
30
31   public void testParseAllData() {
32     for (String key : ADDRESS_DATA.keys()) {
33       AddressVerificationNodeData nodeData = ADDRESS_DATA.get(key);
34       assertNotNull(key + " maps to null value.", nodeData);
35       assertNotNull("Id is required", nodeData.get(AddressDataKey.ID));
36     }
37   }
38
39   public void testLoadingCountries() {
40     AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data");
41     String[] countries = nodeData.get(AddressDataKey.COUNTRIES).split("~");
42     assertTrue(countries.length > 0);
43   }
44
45   public void testUsData() {
46     AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/US");
47     assertEquals("data/US", nodeData.get(AddressDataKey.ID));
48     assertNotNull(nodeData.get(AddressDataKey.SUB_KEYS));
49     assertNotNull(nodeData.get(AddressDataKey.SUB_NAMES));
50     assertEquals("en", nodeData.get(AddressDataKey.LANG));
51   }
52
53   public void testCaData() {
54     AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/CA");
55     String names = nodeData.get(AddressDataKey.SUB_NAMES);
56     String keys = nodeData.get(AddressDataKey.SUB_KEYS);
57
58     assertEquals("data/CA", nodeData.get(AddressDataKey.ID));
59     assertEquals("en", nodeData.get(AddressDataKey.LANG));
60
61     assertEquals("AB~BC~MB~NB~NL~NT~NS~NU~ON~PE~QC~SK~YT", keys);
62     assertEquals("Alberta~British Columbia~Manitoba~New Brunswick" +
63         "~Newfoundland and Labrador~Northwest Territories~Nova Scotia~Nunavut" +
64         "~Ontario~Prince Edward Island~Quebec~Saskatchewan~Yukon",
65         names);
66   }
67
68   public void testCaFrenchData() {
69     AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data/CA--fr");
70     String names = nodeData.get(AddressDataKey.SUB_NAMES);
71     String keys = nodeData.get(AddressDataKey.SUB_KEYS);
72
73     assertEquals("data/CA--fr", nodeData.get(AddressDataKey.ID));
74     assertEquals("fr", nodeData.get(AddressDataKey.LANG));
75     assertEquals("AB~BC~PE~MB~NB~NS~NU~ON~QC~SK~NL~NT~YT", keys);
76     assertTrue(names.contains("Colombie"));
77   }
78
79   public void testBackSlashUnEscaped() {
80     for (String lookupKey : ADDRESS_DATA.keys()) {
81       AddressVerificationNodeData nodeData = ADDRESS_DATA.get(lookupKey);
82       for (AddressDataKey dataKey : AddressDataKey.values()) {
83         String val = nodeData.get(dataKey);
84         if (val != null) {
85           assertFalse("Backslashes need to be unescaped: " + val, val.contains("\\\\"));
86         }
87       }
88     }
89
90     // Spot check.
91     assertEquals("Kazhakstan's postal code pattern mismatched", "\\d{6}",
92         ADDRESS_DATA.get("data/KZ").get(AddressDataKey.ZIP));
93   }
94
95   public void testExampleData() {
96     assertNotNull("Expects example data.", AddressDataMapLoader.DATA.get("examples"));
97     assertNotNull("Expects example US address.",
98         AddressDataMapLoader.DATA.get("examples/US/local/en"));
99     assertEquals("'examples/TW/local/zh_Hant' and 'examples/TW/local/_default' should " +
100         "return same value.",
101         AddressDataMapLoader.DATA.get("examples/TW/local/zh_Hant"),
102         AddressDataMapLoader.DATA.get("examples/TW/local/_default"));
103   }
104 }