summaryrefslogtreecommitdiffstats
path: root/tests/AndroidTests/src/com/android/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/AndroidTests/src/com/android/unit_tests')
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNodesVerifier.java12
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/VCardImporterTests.java32
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java10
3 files changed, 53 insertions, 1 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNodesVerifier.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNodesVerifier.java
index 917b18e..a9775fa 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNodesVerifier.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/PropertyNodesVerifier.java
@@ -23,7 +23,6 @@ import android.pim.vcard.VCardParser_V21;
import android.pim.vcard.VCardParser_V30;
import android.pim.vcard.exception.VCardException;
import android.test.AndroidTestCase;
-import android.util.Log;
import junit.framework.TestCase;
@@ -56,6 +55,12 @@ public class PropertyNodesVerifier extends VNodeBuilder {
verify(mAndroidTestCase.getContext().getResources().openRawResource(resId), vCardType);
}
+ public void verify(int resId, int vCardType, final VCardParser vCardParser)
+ throws IOException, VCardException {
+ verify(mAndroidTestCase.getContext().getResources().openRawResource(resId),
+ vCardType, vCardParser);
+ }
+
public void verify(InputStream is, int vCardType) throws IOException, VCardException {
final VCardParser vCardParser;
if (VCardConfig.isV30(vCardType)) {
@@ -63,6 +68,11 @@ public class PropertyNodesVerifier extends VNodeBuilder {
} else {
vCardParser = new VCardParser_V21();
}
+ verify(is, vCardType, vCardParser);
+ }
+
+ public void verify(InputStream is, int vCardType, final VCardParser vCardParser)
+ throws IOException, VCardException {
try {
vCardParser.parse(is, this);
} finally {
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardImporterTests.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardImporterTests.java
index 169ea71..b1fccaa 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardImporterTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardImporterTests.java
@@ -16,7 +16,10 @@
package com.android.unit_tests.vcard;
+import android.content.ContentValues;
import android.pim.vcard.VCardConfig;
+import android.pim.vcard.VCardParser;
+import android.pim.vcard.VCardParser_V21;
import android.pim.vcard.exception.VCardException;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Email;
@@ -999,6 +1002,35 @@ public class VCardImporterTests extends VCardTestsBase {
verifier.verify(R.raw.v21_multiple_entry, VCardConfig.VCARD_TYPE_V21_JAPANESE_SJIS);
}
+ public void testIgnoreAgentV21_Parse() throws IOException, VCardException {
+ PropertyNodesVerifier verifier = new PropertyNodesVerifier(this);
+ ContentValues contentValuesForValue = new ContentValues();
+ contentValuesForValue.put("VALUE", "DATE");
+ verifier.addPropertyNodesVerifierElem()
+ .addNodeWithOrder("VERSION", "2.1")
+ .addNodeWithOrder("N", Arrays.asList("Example", "", "", "", ""))
+ .addNodeWithOrder("FN", "Example")
+ .addNodeWithOrder("ANNIVERSARY", "20091010", contentValuesForValue)
+ .addNodeWithOrder("AGENT", "")
+ .addNodeWithOrder("X-CLASS", "PUBLIC")
+ .addNodeWithOrder("X-REDUCTION", "")
+ .addNodeWithOrder("X-NO", "");
+
+ // Only scan mode lets vCard parser accepts invalid AGENT lines like above.
+ verifier.verify(R.raw.v21_winmo_65, V21,
+ new VCardParser_V21(VCardParser.PARSER_MODE_SCAN));
+ }
+
+ public void testIgnoreAgentV21() throws IOException, VCardException {
+ ImportVerifier verifier = new ImportVerifier();
+ ImportVerifierElem elem = verifier.addImportVerifierElem();
+ elem.addExpected(StructuredName.CONTENT_ITEM_TYPE)
+ .put(StructuredName.FAMILY_NAME, "Example")
+ .put(StructuredName.DISPLAY_NAME, "Example");
+ verifier.verify(R.raw.v21_winmo_65, V21,
+ new VCardParser_V21(VCardParser.PARSER_MODE_SCAN));
+ }
+
public void testPagerV30_Parse() throws IOException, VCardException {
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this);
verifier.addPropertyNodesVerifierElem()
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 bd4d13a..6176f5c 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardTestsBase.java
@@ -455,6 +455,11 @@ class CustomMockContext extends MockContext {
verify(getContext().getResources().openRawResource(resId), vCardType);
}
+ public void verify(int resId, int vCardType, final VCardParser vCardParser)
+ throws IOException, VCardException {
+ verify(getContext().getResources().openRawResource(resId), vCardType, vCardParser);
+ }
+
public void verify(InputStream is, int vCardType) throws IOException, VCardException {
final VCardParser vCardParser;
if (VCardConfig.isV30(vCardType)) {
@@ -462,6 +467,11 @@ class CustomMockContext extends MockContext {
} else {
vCardParser = new VCardParser_V21();
}
+ verify(is, vCardType, vCardParser);
+ }
+
+ public void verify(InputStream is, int vCardType, final VCardParser vCardParser)
+ throws IOException, VCardException {
VCardDataBuilder builder =
new VCardDataBuilder(null, null, false, vCardType, null);
builder.addEntryHandler(this);