2 * Copyright (C) 2010 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.i18n.addressinput;
19 import com.android.i18n.addressinput.testing.AddressDataMapLoader;
21 import junit.framework.TestCase;
24 * Tests to ensure that {@code AddressVerificationData} can parse all the default data.
26 public class AddressVerificationDataTest extends TestCase {
28 private static final AddressVerificationData ADDRESS_DATA =
29 new AddressVerificationData(AddressDataMapLoader.DATA);
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));
39 public void testLoadingCountries() {
40 AddressVerificationNodeData nodeData = ADDRESS_DATA.get("data");
41 String[] countries = nodeData.get(AddressDataKey.COUNTRIES).split("~");
42 assertTrue(countries.length > 0);
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));
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);
58 assertEquals("data/CA", nodeData.get(AddressDataKey.ID));
59 assertEquals("en", nodeData.get(AddressDataKey.LANG));
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",
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);
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"));
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);
85 assertFalse("Backslashes need to be unescaped: " + val, val.contains("\\\\"));
91 assertEquals("Kazhakstan's postal code pattern mismatched", "\\d{6}",
92 ADDRESS_DATA.get("data/KZ").get(AddressDataKey.ZIP));
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"));