summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android/providers/contacts/PostalSplitterTest.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2009-09-01 20:08:34 -0700
committerJeff Sharkey <jsharkey@android.com>2009-09-02 22:19:30 -0700
commit622e0a2f00b3de248926ec9e89b11a6425919819 (patch)
tree1236fc99ff4a3f175d060424e1c2a20c85cecbfd /tests/src/com/android/providers/contacts/PostalSplitterTest.java
parentb3ce7aaa2390698c9424d17df4d2979dcd902cfd (diff)
downloadpackages_providers_ContactsProvider-622e0a2f00b3de248926ec9e89b11a6425919819.zip
packages_providers_ContactsProvider-622e0a2f00b3de248926ec9e89b11a6425919819.tar.gz
packages_providers_ContactsProvider-622e0a2f00b3de248926ec9e89b11a6425919819.tar.bz2
Relaxed type and label checking, structured consistency.
For CommonDataKinds rows, we strictly require that TYPE be set when LABEL appears. Previously we had enforced that LABEL could only exist under TYPE_CUSTOM, but this doesn't hold true for providers that want to allow additional TYPE values to have labels. This fixes http://b/2089080 and http://b/2065904 This change also helps maintain consistency between structured and unstructured fields for StructuredPostal and StructuredName. That is, when an update updates one without also updating the other, we provide the additional values required to keep them consistent. If the client specifies both sets, we let them pass through. Fixes http://b/2087358 Also adds unit tests, including fixing broken ones.
Diffstat (limited to 'tests/src/com/android/providers/contacts/PostalSplitterTest.java')
-rw-r--r--tests/src/com/android/providers/contacts/PostalSplitterTest.java119
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/src/com/android/providers/contacts/PostalSplitterTest.java b/tests/src/com/android/providers/contacts/PostalSplitterTest.java
new file mode 100644
index 0000000..be9aa35
--- /dev/null
+++ b/tests/src/com/android/providers/contacts/PostalSplitterTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.providers.contacts;
+
+import com.android.providers.contacts.PostalSplitter.Postal;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link NameSplitter}.
+ */
+@SmallTest
+public class PostalSplitterTest extends TestCase {
+ private PostalSplitter mPostalSplitter;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mPostalSplitter = new PostalSplitter(Locale.US);
+ }
+
+ public void testNull() {
+ assertSplitPostal(null, null, null, null, null, null, null, null);
+ assertJoinedPostal(null, null, null, null, null, null, null, null);
+ }
+
+ public void testEmpty() {
+ assertSplitPostal("", null, null, null, null, null, null, null);
+ assertJoinedPostal(null, null, null, null, null, null, null, null);
+ }
+
+ public void testSpaces() {
+ assertSplitPostal(" ", " ", null, null, null, null, null, null);
+ assertJoinedPostal(" ", " ", null, null, null, null, null, null);
+ }
+
+ public void testPobox() {
+ assertJoinedPostal("PO Box 2600\nImaginationland", null, "PO Box 2600", null,
+ "Imaginationland", null, null, null);
+ }
+
+ public void testNormal() {
+ assertJoinedPostal("1600 Amphitheatre Parkway\nMountain View, CA 94043",
+ "1600 Amphitheatre Parkway", null, null, "Mountain View", "CA", "94043", null);
+ }
+
+ public void testMissingRegion() {
+ assertJoinedPostal("1600 Amphitheatre Parkway\nMountain View 94043",
+ "1600 Amphitheatre Parkway", null, null, "Mountain View", null, "94043", null);
+
+ assertJoinedPostal("1600 Amphitheatre Parkway\n94043",
+ "1600 Amphitheatre Parkway", null, null, null, null, "94043", null);
+
+ assertJoinedPostal("1600 Amphitheatre Parkway\n94043\nUSA",
+ "1600 Amphitheatre Parkway", null, null, null, null, "94043", "USA");
+ }
+
+ public void testMissingPostcode() {
+ assertJoinedPostal("1600 Amphitheatre Parkway\nMountain View, CA",
+ "1600 Amphitheatre Parkway", null, null, "Mountain View", "CA", null, null);
+
+ assertJoinedPostal("1600 Amphitheatre Parkway\nMountain View, CA\nUSA",
+ "1600 Amphitheatre Parkway", null, null, "Mountain View", "CA", null, "USA");
+
+ assertJoinedPostal("1600 Amphitheatre Parkway\nUSA",
+ "1600 Amphitheatre Parkway", null, null, null, null, null, "USA");
+ }
+
+ public void testMissingStreet() {
+ assertJoinedPostal("Mr. Rogers\nUSA", null, null, "Mr. Rogers", null, null, null, "USA");
+ }
+
+ private void assertSplitPostal(String formattedPostal, String street, String pobox,
+ String neighborhood, String city, String region, String postcode, String country) {
+ final Postal postal = new Postal();
+ mPostalSplitter.split(postal, formattedPostal);
+ assertEquals(street, postal.street);
+ assertEquals(pobox, postal.pobox);
+ assertEquals(neighborhood, postal.neighborhood);
+ assertEquals(city, postal.city);
+ assertEquals(region, postal.region);
+ assertEquals(postcode, postal.postcode);
+ assertEquals(country, postal.country);
+ }
+
+ private void assertJoinedPostal(String formattedPostal, String street, String pobox,
+ String neighborhood, String city, String region, String postcode, String country) {
+ final Postal postal = new Postal();
+ postal.street = street;
+ postal.pobox = pobox;
+ postal.neighborhood = neighborhood;
+ postal.city = city;
+ postal.region = region;
+ postal.postcode = postcode;
+ postal.country = country;
+
+ final String joined = mPostalSplitter.join(postal);
+ assertEquals(formattedPostal, joined);
+ }
+}