summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2009-11-18 10:25:09 +0900
committerDaisuke Miyakawa <dmiyakawa@google.com>2009-11-18 10:35:39 +0900
commit839c036444c8a5335cc557e174acc7ee28baafc4 (patch)
tree024d7233da2e5d6e4b768cc2519e84a9b5f62c05 /tests
parent2c7664989f7388c0c6cf0ec7d80ffa2704c8c2be (diff)
downloadframeworks_base-839c036444c8a5335cc557e174acc7ee28baafc4.zip
frameworks_base-839c036444c8a5335cc557e174acc7ee28baafc4.tar.gz
frameworks_base-839c036444c8a5335cc557e174acc7ee28baafc4.tar.bz2
Add unit tests.
Internal issue number: 2195990
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNode.java14
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java55
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java3
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/VCardUtilsTests.java77
4 files changed, 139 insertions, 10 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNode.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNode.java
index 89134a1..14a789a 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNode.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNode.java
@@ -122,21 +122,17 @@ public class PropertyNode {
if (propName == null || !propName.equals(node.propName)) {
return false;
- } else if (!paramMap.equals(node.paramMap)) {
+ } else if (!paramMap_TYPE.equals(node.paramMap_TYPE)) {
return false;
- } else if (!(paramMap_TYPE.size() == node.paramMap_TYPE.size()) &&
- !paramMap_TYPE.equals(node.paramMap_TYPE)) {
- Log.d("@@@", "paramMap_Type: " + paramMap_TYPE.size() + ", "
- + node.paramMap_TYPE.size());
+ } else if (!paramMap_TYPE.equals(node.paramMap_TYPE)) {
return false;
} else if (!propGroupSet.equals(node.propGroupSet)) {
return false;
}
-
+
if (propValue_bytes != null && Arrays.equals(propValue_bytes, node.propValue_bytes)) {
return true;
} else {
- // Log.d("@@@", propValue + ", " + node.propValue);
if (!propValue.equals(node.propValue)) {
return false;
}
@@ -173,6 +169,7 @@ public class PropertyNode {
builder.append("]");
if (!propGroupSet.isEmpty()) {
builder.append(", propGroupSet: [");
+ first = true;
for (String elem : propGroupSet) {
if (first) {
first = false;
@@ -193,8 +190,9 @@ public class PropertyNode {
builder.append(", propValue_bytes size: ");
builder.append(propValue_bytes.length);
}
- builder.append(", propValue: ");
+ builder.append(", propValue: \"");
builder.append(propValue);
+ builder.append("\"");
return builder.toString();
}
}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java
index faafb99..0522867 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardJapanizationTests.java
@@ -18,10 +18,14 @@ package com.android.unit_tests.vcard;
import android.content.ContentValues;
import android.pim.vcard.VCardConfig;
+import android.provider.ContactsContract.CommonDataKinds.Note;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import com.android.unit_tests.vcard.PropertyNodesVerifierElem.TypeSet;
+import com.android.unit_tests.vcard.VCardTestsBase.ContactEntry;
+import com.android.unit_tests.vcard.VCardTestsBase.VCardVerifier;
import java.util.Arrays;
@@ -317,4 +321,53 @@ public class VCardJapanizationTests extends VCardTestsBase {
Arrays.asList("3", "", "", "", "", "", ""), new TypeSet("HOME"));
verifier.verify();
}
-} \ No newline at end of file
+
+ private void testJapanesePhoneNumberCommon(int vcardType) {
+ VCardVerifier verifier = new VCardVerifier(vcardType);
+ ContactEntry entry = verifier.addInputEntry();
+ entry.buildData(Phone.CONTENT_ITEM_TYPE)
+ .put(Phone.NUMBER, "0312341234")
+ .put(Phone.TYPE, Phone.TYPE_HOME);
+ entry.buildData(Phone.CONTENT_ITEM_TYPE)
+ .put(Phone.NUMBER, "09012341234")
+ .put(Phone.TYPE, Phone.TYPE_MOBILE);
+ verifier.addPropertyNodesVerifierElemWithEmptyName()
+ .addNodeWithoutOrder("TEL", "03-1234-1234", new TypeSet("HOME"))
+ .addNodeWithoutOrder("TEL", "090-1234-1234", new TypeSet("WORK"));
+ }
+
+ public void testJapanesePhoneNumberV21_1() {
+ testJapanesePhoneNumberCommon(VCardConfig.VCARD_TYPE_V21_JAPANESE_UTF8);
+ }
+
+ public void testJapanesePhoneNumberDoCoMo() {
+ testJapanesePhoneNumberCommon(VCardConfig.VCARD_TYPE_DOCOMO);
+ }
+
+ public void testJapanesePhoneNumberV30() {
+ testJapanesePhoneNumberCommon(VCardConfig.VCARD_TYPE_V30_JAPANESE_UTF8);
+ }
+
+ public void testNoteDoCoMo() {
+ VCardVerifier verifier = new VCardVerifier(VCardConfig.VCARD_TYPE_DOCOMO);
+ ContactEntry entry = verifier.addInputEntry();
+ entry.buildData(Note.CONTENT_ITEM_TYPE)
+ .put(Note.NOTE, "note1");
+ entry.buildData(Note.CONTENT_ITEM_TYPE)
+ .put(Note.NOTE, "note2");
+ entry.buildData(Note.CONTENT_ITEM_TYPE)
+ .put(Note.NOTE, "note3");
+
+ // More than one note fields must be aggregated into one note.
+ verifier.addPropertyNodesVerifierElemWithEmptyName()
+ .addNodeWithoutOrder("TEL", "", new TypeSet("HOME"))
+ .addNodeWithoutOrder("EMAIL", "", new TypeSet("HOME"))
+ .addNodeWithoutOrder("X-CLASS", "PUBLIC")
+ .addNodeWithoutOrder("X-REDUCTION", "")
+ .addNodeWithoutOrder("X-NO", "")
+ .addNodeWithoutOrder("X-DCM-HMN-MODE", "")
+ .addNodeWithoutOrder("ADR", "", new TypeSet("HOME"))
+ .addNodeWithoutOrder("NOTE", "note1\nnote2\nnote3", mContentValuesForQP);
+ verifier.verify();
+ }
+}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java
index 00debb5..7b5f216 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java
@@ -957,8 +957,9 @@ class CustomMockContext extends MockContext {
final String value = entry.getValue();
builder.append(' ');
builder.append(key);
- builder.append('=');
+ builder.append("=\"");
builder.append(value);
+ builder.append('"');
}
return builder.toString();
}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardUtilsTests.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardUtilsTests.java
new file mode 100644
index 0000000..6202bdb
--- /dev/null
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardUtilsTests.java
@@ -0,0 +1,77 @@
+/*
+ * 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.unit_tests.vcard;
+
+import android.pim.vcard.VCardUtils;
+
+import junit.framework.TestCase;
+
+public class VCardUtilsTests extends TestCase {
+ public void testContainsOnlyPrintableAscii() {
+ assertTrue(VCardUtils.containsOnlyPrintableAscii(null));
+ assertTrue(VCardUtils.containsOnlyPrintableAscii(""));
+ assertTrue(VCardUtils.containsOnlyPrintableAscii("abcdefghijklmnopqrstuvwxyz"));
+ assertTrue(VCardUtils.containsOnlyPrintableAscii("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0x20; i < 0x7F; i++) {
+ builder.append((char)i);
+ }
+ assertTrue(VCardUtils.containsOnlyPrintableAscii(builder.toString()));
+ assertTrue(VCardUtils.containsOnlyPrintableAscii("\r\n"));
+ assertFalse(VCardUtils.containsOnlyPrintableAscii("\u0019"));
+ assertFalse(VCardUtils.containsOnlyPrintableAscii("\u007F"));
+ }
+
+ public void testContainsOnlyNonCrLfPrintableAscii() {
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii(null));
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii(""));
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("abcdefghijklmnopqrstuvwxyz"));
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0x20; i < 0x7F; i++) {
+ builder.append((char)i);
+ }
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii(builder.toString()));
+ assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\u0019"));
+ assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\u007F"));
+ assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\r"));
+ assertFalse(VCardUtils.containsOnlyNonCrLfPrintableAscii("\n"));
+ }
+
+ public void testContainsOnlyAlphaDigitHyphen() {
+ assertTrue(VCardUtils.containsOnlyAlphaDigitHyphen(null));
+ assertTrue(VCardUtils.containsOnlyAlphaDigitHyphen(""));
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("abcdefghijklmnopqrstuvwxyz"));
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
+ assertTrue(VCardUtils.containsOnlyNonCrLfPrintableAscii("0123456789-"));
+ for (int i = 0; i < 0x30; i++) {
+ if (i == 0x2D) { // -
+ continue;
+ }
+ assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
+ }
+ for (int i = 0x3A; i < 0x41; i++) {
+ assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
+ }
+ for (int i = 0x5B; i < 0x61; i++) {
+ assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
+ }
+ for (int i = 0x7B; i < 0x100; i++) {
+ assertFalse(VCardUtils.containsOnlyAlphaDigitHyphen(String.valueOf((char)i)));
+ }
+ }
+}