summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2011-03-08 14:32:35 -0800
committerDaisuke Miyakawa <dmiyakawa@google.com>2011-03-08 17:08:48 -0800
commit677ef21613a9d35053ec098444832ce4125a847e (patch)
treee6973df6dd654043392ac41f4c2b37b34c3d970e
parent7e4e86eb5ad2c8a68ca7005ef4dee64a82ce0198 (diff)
downloadandroid_frameworks_opt_vcard-677ef21613a9d35053ec098444832ce4125a847e.tar.gz
android_frameworks_opt_vcard-677ef21613a9d35053ec098444832ce4125a847e.tar.bz2
android_frameworks_opt_vcard-677ef21613a9d35053ec098444832ce4125a847e.zip
Reorganize codes, especially around vCard composition.
- suppress misc warnings - stop using VCardException in vCard composer which has been used only in test context - add VCardComposer#createOneEntryNew(). I'm planning to replace this with old VCardComposer#createOneEntry() I don't understand why we have callback mechanism for this kind of simple stuff. I could have been better on this. - add some documentation - mark initWithRawContacsEntityUri() (introduced recently) as deprecated. That was not a good idea =( Bug: 4066223 Change-Id: Ib533a435cac3b4e4fa31527d02b0657fc4bd0377
-rw-r--r--java/com/android/vcard/VCardComposer.java106
-rw-r--r--java/com/android/vcard/VCardEntryCounter.java13
-rw-r--r--java/com/android/vcard/VCardInterpreterCollection.java11
-rw-r--r--java/com/android/vcard/VCardParserImpl_V21.java20
-rw-r--r--java/com/android/vcard/VCardSourceDetector.java29
-rw-r--r--tests/src/com/android/vcard/tests/VCardExporterTests.java8
-rw-r--r--tests/src/com/android/vcard/tests/VCardImporterTests.java8
-rw-r--r--tests/src/com/android/vcard/tests/VCardJapanizationTests.java10
-rw-r--r--tests/src/com/android/vcard/tests/VCardTestUtilsTests.java2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ContactEntry.java (renamed from tests/src/com/android/vcard/tests/test_utils/ContactEntry.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ContentValuesBuilder.java (renamed from tests/src/com/android/vcard/tests/test_utils/ContentValuesBuilder.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ContentValuesVerifier.java (renamed from tests/src/com/android/vcard/tests/test_utils/ContentValuesVerifier.java)5
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ContentValuesVerifierElem.java (renamed from tests/src/com/android/vcard/tests/test_utils/ContentValuesVerifierElem.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ExportTestProvider.java (renamed from tests/src/com/android/vcard/tests/test_utils/ExportTestProvider.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ExportTestResolver.java (renamed from tests/src/com/android/vcard/tests/test_utils/ExportTestResolver.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ImportTestProvider.java (renamed from tests/src/com/android/vcard/tests/test_utils/ImportTestProvider.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/ImportTestResolver.java (renamed from tests/src/com/android/vcard/tests/test_utils/ImportTestResolver.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/LineVerifier.java (renamed from tests/src/com/android/vcard/tests/test_utils/LineVerifier.java)19
-rw-r--r--tests/src/com/android/vcard/tests/testutils/LineVerifierElem.java (renamed from tests/src/com/android/vcard/tests/test_utils/LineVerifierElem.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/PropertyNode.java (renamed from tests/src/com/android/vcard/tests/test_utils/PropertyNode.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/PropertyNodesVerifier.java (renamed from tests/src/com/android/vcard/tests/test_utils/PropertyNodesVerifier.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/PropertyNodesVerifierElem.java (renamed from tests/src/com/android/vcard/tests/test_utils/PropertyNodesVerifierElem.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/VCardTestsBase.java (renamed from tests/src/com/android/vcard/tests/test_utils/VCardTestsBase.java)25
-rw-r--r--tests/src/com/android/vcard/tests/testutils/VCardVerifier.java (renamed from tests/src/com/android/vcard/tests/test_utils/VCardVerifier.java)43
-rw-r--r--tests/src/com/android/vcard/tests/testutils/VNode.java (renamed from tests/src/com/android/vcard/tests/test_utils/VNode.java)2
-rw-r--r--tests/src/com/android/vcard/tests/testutils/VNodeBuilder.java (renamed from tests/src/com/android/vcard/tests/test_utils/VNodeBuilder.java)2
26 files changed, 205 insertions, 120 deletions
diff --git a/java/com/android/vcard/VCardComposer.java b/java/com/android/vcard/VCardComposer.java
index d1e0eb6..32f80e0 100644
--- a/java/com/android/vcard/VCardComposer.java
+++ b/java/com/android/vcard/VCardComposer.java
@@ -15,8 +15,6 @@
*/
package com.android.vcard;
-import com.android.vcard.exception.VCardException;
-
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -177,10 +175,6 @@ public class VCardComposer {
try {
// Create one empty entry.
mWriter.write(createOneEntryInternal("-1", null));
- } catch (VCardException e) {
- Log.e(LOG_TAG, "VCardException has been thrown during on Init(): " +
- e.getMessage());
- return false;
} catch (IOException e) {
Log.e(LOG_TAG,
"IOException occurred during exportOneContactData: "
@@ -227,7 +221,7 @@ public class VCardComposer {
private Cursor mCursor;
private boolean mCursorSuppliedFromOutside;
private int mIdColumn;
- private Uri mContentUriForRawContactsEntity = RawContactsEntity.CONTENT_URI;
+ private Uri mContentUriForRawContactsEntity;
private final String mCharset;
private final List<OneEntryHandler> mHandlerList;
@@ -395,10 +389,14 @@ public class VCardComposer {
*
* You can call this method or a variant of this method just once. In other words, you cannot
* reuse this object.
+ *
+ * @deprecated Use {@link #init(Uri, String[], String, String[], String, Uri)} if you really
+ * need to change the default Uri.
*/
+ @Deprecated
public boolean initWithRawContactsEntityUri(Uri contentUriForRawContactsEntity) {
- mContentUriForRawContactsEntity = contentUriForRawContactsEntity;
- return init(null, null);
+ return init(Contacts.CONTENT_URI, sContactsProjection, null, null, null,
+ contentUriForRawContactsEntity);
}
/**
@@ -406,7 +404,8 @@ public class VCardComposer {
* arguments.
*/
public boolean init(final String selection, final String[] selectionArgs) {
- return init(Contacts.CONTENT_URI, sContactsProjection, selection, selectionArgs, null);
+ return init(Contacts.CONTENT_URI, sContactsProjection, selection, selectionArgs,
+ null, null);
}
/**
@@ -414,17 +413,55 @@ public class VCardComposer {
*/
public boolean init(final Uri contentUri, final String selection,
final String[] selectionArgs, final String sortOrder) {
- return init(contentUri, sContactsProjection, selection, selectionArgs, sortOrder);
+ return init(contentUri, sContactsProjection, selection, selectionArgs, sortOrder, null);
}
- private boolean init(final Uri contentUri, final String[] projection,
- final String selection, final String[] selectionArgs, final String sortOrder) {
+ /**
+ * A variant of init(). Currently just for testing. Use other variants for init().
+ *
+ * First we'll create {@link Cursor} for the list of contactId.
+ *
+ * <code>
+ * Cursor cursorForId = mContentResolver.query(
+ * contentUri, projection, selection, selectionArgs, sortOrder);
+ * </code>
+ *
+ * After that, we'll obtain data for each contactId in the list.
+ *
+ * <code>
+ * Cursor cursorForContent = mContentResolver.query(
+ * contentUriForRawContactsEntity, null,
+ * Data.CONTACT_ID + "=?", new String[] {contactId}, null)
+ * </code>
+ *
+ * {@link #createOneEntry()} or its variants let the caller obtain each entry from
+ * <code>cursorForContent</code> above.
+ *
+ * @param contentUri Uri for obtaining the list of contactId. Used with
+ * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+ * @param projection projection used with
+ * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+ * @param selection selection used with
+ * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+ * @param selectionArgs selectionArgs used with
+ * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+ * @param sortOrder sortOrder used with
+ * {@link ContentResolver#query(Uri, String[], String, String[], String)}
+ * @param contentUriForRawContactsEntity Uri for obtaining entries relevant to each
+ * contactId.
+ * @return true when successful
+ *
+ * @hide
+ */
+ public boolean init(final Uri contentUri, final String[] projection,
+ final String selection, final String[] selectionArgs,
+ final String sortOrder, Uri contentUriForRawContactsEntity) {
if (!Contacts.CONTENT_URI.equals(contentUri)) {
if (DEBUG) Log.d(LOG_TAG, "Unexpected contentUri: " + contentUri);
mErrorReason = FAILURE_REASON_UNSUPPORTED_URI;
return false;
}
- if (!initInterFirstPart()) {
+ if (!initInterFirstPart(contentUriForRawContactsEntity)) {
return false;
}
if (!initInterCursorCreationPart(contentUri, projection, selection, selectionArgs,
@@ -442,7 +479,7 @@ public class VCardComposer {
* @hide
*/
public boolean init(Cursor cursor) {
- if (!initInterFirstPart()) {
+ if (!initInterFirstPart(null)) {
return false;
}
mCursorSuppliedFromOutside = true;
@@ -453,7 +490,10 @@ public class VCardComposer {
return initInterLastPart();
}
- private boolean initInterFirstPart() {
+ private boolean initInterFirstPart(Uri contentUriForRawContactsEntity) {
+ mContentUriForRawContactsEntity =
+ (contentUriForRawContactsEntity != null ? contentUriForRawContactsEntity :
+ RawContactsEntity.CONTENT_URI);
if (mInitDone) {
Log.e(LOG_TAG, "init() is already called");
return false;
@@ -510,7 +550,7 @@ public class VCardComposer {
return false;
}
mIdColumn = mCursor.getColumnIndex(Contacts._ID);
- return true;
+ return mIdColumn >= 0;
}
private boolean initInterLastPart() {
@@ -519,11 +559,32 @@ public class VCardComposer {
return true;
}
+ // TODO: replace this with createOneEntryNew(). Also remove OneEntryHandler. init/terminate
+ // capability can be prepared if caller really wants.
public boolean createOneEntry() {
return createOneEntry(null);
}
/**
+ * @return a vCard string.
+ */
+ public String createOneEntryNew() {
+ return createOneEntryNew(null);
+ }
+
+ /**
+ * @hide
+ */
+ public String createOneEntryNew(Method getEntityIteratorMethod) {
+ final String vcard = createOneEntryInternal(mCursor.getString(mIdColumn),
+ getEntityIteratorMethod);
+ if (!mCursor.moveToNext()) {
+ Log.e(LOG_TAG, "Cursor#moveToNext() returned false");
+ }
+ return vcard;
+ }
+
+ /**
* @param getEntityIteratorMethod For Dependency Injection.
* @hide just for testing.
*/
@@ -541,9 +602,6 @@ public class VCardComposer {
Log.e(LOG_TAG, "Incorrect mIdColumn: " + mIdColumn);
return true;
}
- } catch (VCardException e) {
- Log.e(LOG_TAG, "VCardException has been thrown: " + e.getMessage());
- return false;
} catch (OutOfMemoryError error) {
// Maybe some data (e.g. photo) is too big to have in memory. But it
// should be rare.
@@ -552,7 +610,9 @@ public class VCardComposer {
// TODO: should tell users what happened?
return true;
} finally {
- mCursor.moveToNext();
+ if (!mCursor.moveToNext()) {
+ Log.e(LOG_TAG, "Cursor#moveToNext() returned false");
+ }
}
// This function does not care the OutOfMemoryError on the handler side :-P
@@ -574,7 +634,7 @@ public class VCardComposer {
}
private String createOneEntryInternal(final String contactId,
- final Method getEntityIteratorMethod) throws VCardException {
+ final Method getEntityIteratorMethod) {
final Map<String, List<ContentValues>> contentValuesListMap =
new HashMap<String, List<ContentValues>>();
// The resolver may return the entity iterator with no data. It is possible.
@@ -602,7 +662,7 @@ public class VCardComposer {
for (StackTraceElement element : stackTraceElements) {
Log.e(LOG_TAG, " at " + element.toString());
}
- throw new VCardException("InvocationTargetException has been thrown: " +
+ throw new RuntimeException("InvocationTargetException has been thrown: " +
e.getCause().getMessage());
}
} else {
diff --git a/java/com/android/vcard/VCardEntryCounter.java b/java/com/android/vcard/VCardEntryCounter.java
index 7bfe977..230d38b 100644
--- a/java/com/android/vcard/VCardEntryCounter.java
+++ b/java/com/android/vcard/VCardEntryCounter.java
@@ -27,37 +27,48 @@ public class VCardEntryCounter implements VCardInterpreter {
return mCount;
}
+ @Override
public void start() {
}
+ @Override
public void end() {
}
+ @Override
public void startEntry() {
}
+ @Override
public void endEntry() {
mCount++;
}
+ @Override
public void startProperty() {
}
+ @Override
public void endProperty() {
}
+ @Override
public void propertyGroup(String group) {
}
+ @Override
public void propertyName(String name) {
}
+ @Override
public void propertyParamType(String type) {
}
+ @Override
public void propertyParamValue(String value) {
}
+ @Override
public void propertyValues(List<String> values) {
- }
+ }
}
diff --git a/java/com/android/vcard/VCardInterpreterCollection.java b/java/com/android/vcard/VCardInterpreterCollection.java
index adf577e..3c9f36b 100644
--- a/java/com/android/vcard/VCardInterpreterCollection.java
+++ b/java/com/android/vcard/VCardInterpreterCollection.java
@@ -34,66 +34,77 @@ public final class VCardInterpreterCollection implements VCardInterpreter {
return mInterpreterCollection;
}
+ @Override
public void start() {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.start();
}
}
+ @Override
public void end() {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.end();
}
}
+ @Override
public void startEntry() {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.startEntry();
}
}
+ @Override
public void endEntry() {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.endEntry();
}
}
+ @Override
public void startProperty() {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.startProperty();
}
}
+ @Override
public void endProperty() {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.endProperty();
}
}
+ @Override
public void propertyGroup(String group) {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.propertyGroup(group);
}
}
+ @Override
public void propertyName(String name) {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.propertyName(name);
}
}
+ @Override
public void propertyParamType(String type) {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.propertyParamType(type);
}
}
+ @Override
public void propertyParamValue(String value) {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.propertyParamValue(value);
}
}
+ @Override
public void propertyValues(List<String> values) {
for (VCardInterpreter builder : mInterpreterCollection) {
builder.propertyValues(values);
diff --git a/java/com/android/vcard/VCardParserImpl_V21.java b/java/com/android/vcard/VCardParserImpl_V21.java
index 8c058bf..12f64d8 100644
--- a/java/com/android/vcard/VCardParserImpl_V21.java
+++ b/java/com/android/vcard/VCardParserImpl_V21.java
@@ -37,7 +37,7 @@ import java.util.Set;
/**
* <p>
- * Basic implementation achieving vCard parsing. Based on vCard 2.1,
+ * Basic implementation achieving vCard parsing. Based on vCard 2.1.
* </p>
* @hide
*/
@@ -102,9 +102,9 @@ import java.util.Set;
return ret;
}
- long start = System.currentTimeMillis();
+ final long start = System.currentTimeMillis();
final String line = super.readLine();
- long end = System.currentTimeMillis();
+ final long end = System.currentTimeMillis();
mTime += end - start;
return line;
}
@@ -114,9 +114,9 @@ import java.util.Set;
*/
public String peekLine() throws IOException {
if (!mNextLineIsValid) {
- long start = System.currentTimeMillis();
+ final long start = System.currentTimeMillis();
final String line = super.readLine();
- long end = System.currentTimeMillis();
+ final long end = System.currentTimeMillis();
mTime += end - start;
mNextLine = line;
@@ -167,6 +167,9 @@ import java.util.Set;
* Set for storing unkonwn TYPE attributes, which is not acceptable in vCard
* specification, but happens to be seen in real world vCard.
* </p>
+ * <p>
+ * We just accept those invalid types after emitting a warning for each of it.
+ * </p>
*/
protected final Set<String> mUnknownTypeSet = new HashSet<String>();
@@ -175,6 +178,9 @@ import java.util.Set;
* Set for storing unkonwn VALUE attributes, which is not acceptable in
* vCard specification, but happens to be seen in real world vCard.
* </p>
+ * <p>
+ * We just accept those invalid types after emitting a warning for each of it.
+ * </p>
*/
protected final Set<String> mUnknownValueSet = new HashSet<String>();
@@ -368,7 +374,7 @@ import java.util.Set;
* The arguments useCache and allowGarbase are usually true and false
* accordingly when this function is called outside this function itself.
* </p>
- *
+ *
* @param useCache When true, line is obtained from mPreviousline.
* Otherwise, getLine() is used.
* @param allowGarbage When true, ignore non "END:VCARD" line.
@@ -536,7 +542,7 @@ import java.util.Set;
mInterpreter.propertyGroup(groupName);
}
nameIndex = i + 1; // Next should be another group or a property name.
- } else if (ch == ';') { // End of property name and beginneng of parameters.
+ } else if (ch == ';') { // End of property name and beginneng of parameters.
final String propertyName = line.substring(nameIndex, i);
if (propertyName.equalsIgnoreCase("END")) {
mPreviousLine = line;
diff --git a/java/com/android/vcard/VCardSourceDetector.java b/java/com/android/vcard/VCardSourceDetector.java
index c3e8ca8..9566a4b 100644
--- a/java/com/android/vcard/VCardSourceDetector.java
+++ b/java/com/android/vcard/VCardSourceDetector.java
@@ -45,13 +45,13 @@ public class VCardSourceDetector implements VCardInterpreter {
private static Set<String> APPLE_SIGNS = new HashSet<String>(Arrays.asList(
"X-PHONETIC-FIRST-NAME", "X-PHONETIC-MIDDLE-NAME", "X-PHONETIC-LAST-NAME",
"X-ABADR", "X-ABUID"));
-
+
private static Set<String> JAPANESE_MOBILE_PHONE_SIGNS = new HashSet<String>(Arrays.asList(
"X-GNO", "X-GN", "X-REDUCTION"));
-
+
private static Set<String> WINDOWS_MOBILE_PHONE_SIGNS = new HashSet<String>(Arrays.asList(
"X-MICROSOFT-ASST_TEL", "X-MICROSOFT-ASSISTANT", "X-MICROSOFT-OFFICELOC"));
-
+
// Note: these signes appears before the signs of the other type (e.g. "X-GN").
// In other words, Japanese FOMA mobile phones are detected as FOMA, not JAPANESE_MOBILE_PHONES.
private static Set<String> FOMA_SIGNS = new HashSet<String>(Arrays.asList(
@@ -70,7 +70,7 @@ public class VCardSourceDetector implements VCardInterpreter {
private static final int PARSE_TYPE_APPLE = 1;
// For Japanese mobile phones, which are usually using Shift_JIS as a charset.
private static final int PARSE_TYPE_MOBILE_PHONE_JP = 2;
- // For some of mobile phones released from DoCoMo, which use nested vCard.
+ // For some of mobile phones released from DoCoMo, which use nested vCard.
private static final int PARSE_TYPE_DOCOMO_TORELATE_NEST = 3;
// For Japanese Windows Mobel phones. It's version is supposed to be 6.5.
private static final int PARSE_TYPE_WINDOWS_MOBILE_V65_JP = 4;
@@ -83,30 +83,38 @@ public class VCardSourceDetector implements VCardInterpreter {
// Some mobile phones (like FOMA) tells us the charset of the data.
private boolean mNeedToParseCharset;
private String mSpecifiedCharset;
-
+
+ @Override
public void start() {
}
-
+
+ @Override
public void end() {
}
+ @Override
public void startEntry() {
- }
+ }
+ @Override
public void startProperty() {
mNeedToParseCharset = false;
mNeedToParseVersion = false;
}
-
+
+ @Override
public void endProperty() {
}
+ @Override
public void endEntry() {
}
+ @Override
public void propertyGroup(String group) {
}
-
+
+ @Override
public void propertyName(String name) {
if (name.equalsIgnoreCase(VCardConstants.PROPERTY_VERSION)) {
mNeedToParseVersion = true;
@@ -131,12 +139,15 @@ public class VCardSourceDetector implements VCardInterpreter {
}
}
+ @Override
public void propertyParamType(String type) {
}
+ @Override
public void propertyParamValue(String value) {
}
+ @Override
public void propertyValues(List<String> values) {
if (mNeedToParseVersion && values.size() > 0) {
final String versionString = values.get(0);
diff --git a/tests/src/com/android/vcard/tests/VCardExporterTests.java b/tests/src/com/android/vcard/tests/VCardExporterTests.java
index 76bd755..76f4a8f 100644
--- a/tests/src/com/android/vcard/tests/VCardExporterTests.java
+++ b/tests/src/com/android/vcard/tests/VCardExporterTests.java
@@ -17,10 +17,10 @@
package com.android.vcard.tests;
import com.android.vcard.VCardConfig;
-import com.android.vcard.tests.test_utils.ContactEntry;
-import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem;
-import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem.TypeSet;
-import com.android.vcard.tests.test_utils.VCardTestsBase;
+import com.android.vcard.tests.testutils.ContactEntry;
+import com.android.vcard.tests.testutils.PropertyNodesVerifierElem;
+import com.android.vcard.tests.testutils.VCardTestsBase;
+import com.android.vcard.tests.testutils.PropertyNodesVerifierElem.TypeSet;
import android.content.ContentValues;
import android.provider.ContactsContract.CommonDataKinds.Email;
diff --git a/tests/src/com/android/vcard/tests/VCardImporterTests.java b/tests/src/com/android/vcard/tests/VCardImporterTests.java
index 631e8f2..9c677e5 100644
--- a/tests/src/com/android/vcard/tests/VCardImporterTests.java
+++ b/tests/src/com/android/vcard/tests/VCardImporterTests.java
@@ -16,10 +16,10 @@
package com.android.vcard.tests;
import com.android.vcard.VCardConfig;
-import com.android.vcard.tests.test_utils.ContentValuesVerifier;
-import com.android.vcard.tests.test_utils.ContentValuesVerifierElem;
-import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem.TypeSet;
-import com.android.vcard.tests.test_utils.VCardTestsBase;
+import com.android.vcard.tests.testutils.ContentValuesVerifier;
+import com.android.vcard.tests.testutils.ContentValuesVerifierElem;
+import com.android.vcard.tests.testutils.VCardTestsBase;
+import com.android.vcard.tests.testutils.PropertyNodesVerifierElem.TypeSet;
import android.content.ContentValues;
import android.provider.ContactsContract.CommonDataKinds.Email;
diff --git a/tests/src/com/android/vcard/tests/VCardJapanizationTests.java b/tests/src/com/android/vcard/tests/VCardJapanizationTests.java
index f9433de..19f70df 100644
--- a/tests/src/com/android/vcard/tests/VCardJapanizationTests.java
+++ b/tests/src/com/android/vcard/tests/VCardJapanizationTests.java
@@ -23,11 +23,11 @@ import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import com.android.vcard.VCardConfig;
-import com.android.vcard.tests.test_utils.ContactEntry;
-import com.android.vcard.tests.test_utils.ContentValuesBuilder;
-import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem;
-import com.android.vcard.tests.test_utils.PropertyNodesVerifierElem.TypeSet;
-import com.android.vcard.tests.test_utils.VCardTestsBase;
+import com.android.vcard.tests.testutils.ContactEntry;
+import com.android.vcard.tests.testutils.ContentValuesBuilder;
+import com.android.vcard.tests.testutils.PropertyNodesVerifierElem;
+import com.android.vcard.tests.testutils.VCardTestsBase;
+import com.android.vcard.tests.testutils.PropertyNodesVerifierElem.TypeSet;
import java.util.Arrays;
diff --git a/tests/src/com/android/vcard/tests/VCardTestUtilsTests.java b/tests/src/com/android/vcard/tests/VCardTestUtilsTests.java
index fc46561..d747e52 100644
--- a/tests/src/com/android/vcard/tests/VCardTestUtilsTests.java
+++ b/tests/src/com/android/vcard/tests/VCardTestUtilsTests.java
@@ -19,7 +19,7 @@ import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.test.AndroidTestCase;
import com.android.vcard.VCardConfig;
-import com.android.vcard.tests.test_utils.VCardVerifier;
+import com.android.vcard.tests.testutils.VCardVerifier;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
diff --git a/tests/src/com/android/vcard/tests/test_utils/ContactEntry.java b/tests/src/com/android/vcard/tests/testutils/ContactEntry.java
index dff1f05..1f3406a 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ContactEntry.java
+++ b/tests/src/com/android/vcard/tests/testutils/ContactEntry.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentValues;
import android.provider.ContactsContract.Data;
diff --git a/tests/src/com/android/vcard/tests/test_utils/ContentValuesBuilder.java b/tests/src/com/android/vcard/tests/testutils/ContentValuesBuilder.java
index 74cc3e5..67585e4 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ContentValuesBuilder.java
+++ b/tests/src/com/android/vcard/tests/testutils/ContentValuesBuilder.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentValues;
diff --git a/tests/src/com/android/vcard/tests/test_utils/ContentValuesVerifier.java b/tests/src/com/android/vcard/tests/testutils/ContentValuesVerifier.java
index f69ea1b..40f07fb 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ContentValuesVerifier.java
+++ b/tests/src/com/android/vcard/tests/testutils/ContentValuesVerifier.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.test.AndroidTestCase;
@@ -34,18 +34,21 @@ public class ContentValuesVerifier implements VCardEntryHandler {
return elem;
}
+ @Override
public void onStart() {
for (ContentValuesVerifierElem elem : mContentValuesVerifierElemList) {
elem.onParsingStart();
}
}
+ @Override
public void onEntryCreated(VCardEntry entry) {
AndroidTestCase.assertTrue(mIndex < mContentValuesVerifierElemList.size());
mContentValuesVerifierElemList.get(mIndex).onEntryCreated(entry);
mIndex++;
}
+ @Override
public void onEnd() {
for (ContentValuesVerifierElem elem : mContentValuesVerifierElemList) {
elem.onParsingEnd();
diff --git a/tests/src/com/android/vcard/tests/test_utils/ContentValuesVerifierElem.java b/tests/src/com/android/vcard/tests/testutils/ContentValuesVerifierElem.java
index 004ebda..86f2a23 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ContentValuesVerifierElem.java
+++ b/tests/src/com/android/vcard/tests/testutils/ContentValuesVerifierElem.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentValues;
import android.provider.ContactsContract.Data;
diff --git a/tests/src/com/android/vcard/tests/test_utils/ExportTestProvider.java b/tests/src/com/android/vcard/tests/testutils/ExportTestProvider.java
index e1b4bcf..e5b91c8 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ExportTestProvider.java
+++ b/tests/src/com/android/vcard/tests/testutils/ExportTestProvider.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentResolver;
import android.content.ContentValues;
diff --git a/tests/src/com/android/vcard/tests/test_utils/ExportTestResolver.java b/tests/src/com/android/vcard/tests/testutils/ExportTestResolver.java
index 7a8f4b3..9454de2 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ExportTestResolver.java
+++ b/tests/src/com/android/vcard/tests/testutils/ExportTestResolver.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.provider.ContactsContract.RawContacts;
import android.test.AndroidTestCase;
diff --git a/tests/src/com/android/vcard/tests/test_utils/ImportTestProvider.java b/tests/src/com/android/vcard/tests/testutils/ImportTestProvider.java
index ea18e24..eea6cda 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ImportTestProvider.java
+++ b/tests/src/com/android/vcard/tests/testutils/ImportTestProvider.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
diff --git a/tests/src/com/android/vcard/tests/test_utils/ImportTestResolver.java b/tests/src/com/android/vcard/tests/testutils/ImportTestResolver.java
index 725ae1b..2d90b2d 100644
--- a/tests/src/com/android/vcard/tests/test_utils/ImportTestResolver.java
+++ b/tests/src/com/android/vcard/tests/testutils/ImportTestResolver.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
diff --git a/tests/src/com/android/vcard/tests/test_utils/LineVerifier.java b/tests/src/com/android/vcard/tests/testutils/LineVerifier.java
index 9e31d53..88526b3 100644
--- a/tests/src/com/android/vcard/tests/test_utils/LineVerifier.java
+++ b/tests/src/com/android/vcard/tests/testutils/LineVerifier.java
@@ -13,18 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
-import android.content.Context;
import android.test.AndroidTestCase;
-import com.android.vcard.VCardComposer;
-
import junit.framework.TestCase;
import java.util.ArrayList;
-public class LineVerifier implements VCardComposer.OneEntryHandler {
+public class LineVerifier {
private final AndroidTestCase mAndroidTestCase;
private final ArrayList<LineVerifierElem> mLineVerifierElemList;
private int mVCardType;
@@ -52,16 +49,4 @@ public class LineVerifier implements VCardComposer.OneEntryHandler {
index++;
}
-
- public boolean onEntryCreated(String vcard) {
- verify(vcard);
- return true;
- }
-
- public boolean onInit(Context context) {
- return true;
- }
-
- public void onTerminate() {
- }
}
diff --git a/tests/src/com/android/vcard/tests/test_utils/LineVerifierElem.java b/tests/src/com/android/vcard/tests/testutils/LineVerifierElem.java
index f730f1e..8a3c633 100644
--- a/tests/src/com/android/vcard/tests/test_utils/LineVerifierElem.java
+++ b/tests/src/com/android/vcard/tests/testutils/LineVerifierElem.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.test.AndroidTestCase;
import android.text.TextUtils;
diff --git a/tests/src/com/android/vcard/tests/test_utils/PropertyNode.java b/tests/src/com/android/vcard/tests/testutils/PropertyNode.java
index 14c8d6c..5f5833b 100644
--- a/tests/src/com/android/vcard/tests/test_utils/PropertyNode.java
+++ b/tests/src/com/android/vcard/tests/testutils/PropertyNode.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentValues;
diff --git a/tests/src/com/android/vcard/tests/test_utils/PropertyNodesVerifier.java b/tests/src/com/android/vcard/tests/testutils/PropertyNodesVerifier.java
index ce24d04..f5dccd0 100644
--- a/tests/src/com/android/vcard/tests/test_utils/PropertyNodesVerifier.java
+++ b/tests/src/com/android/vcard/tests/testutils/PropertyNodesVerifier.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.test.AndroidTestCase;
diff --git a/tests/src/com/android/vcard/tests/test_utils/PropertyNodesVerifierElem.java b/tests/src/com/android/vcard/tests/testutils/PropertyNodesVerifierElem.java
index 6cf26d5..036aa96 100644
--- a/tests/src/com/android/vcard/tests/test_utils/PropertyNodesVerifierElem.java
+++ b/tests/src/com/android/vcard/tests/testutils/PropertyNodesVerifierElem.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentValues;
import android.test.AndroidTestCase;
diff --git a/tests/src/com/android/vcard/tests/test_utils/VCardTestsBase.java b/tests/src/com/android/vcard/tests/testutils/VCardTestsBase.java
index 8a84e22..ee2a966 100644
--- a/tests/src/com/android/vcard/tests/test_utils/VCardTestsBase.java
+++ b/tests/src/com/android/vcard/tests/testutils/VCardTestsBase.java
@@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentValues;
import android.test.AndroidTestCase;
import com.android.vcard.VCardConfig;
-import com.android.vcard.tests.test_utils.VCardVerifier;
+import com.android.vcard.tests.testutils.VCardVerifier;
/**
* BaseClass for vCard unit tests with utility classes.
* Please do not add each unit test here.
*/
-public class VCardTestsBase extends AndroidTestCase {
+public abstract class VCardTestsBase extends AndroidTestCase {
public static final int V21 = VCardConfig.VCARD_TYPE_V21_GENERIC;
public static final int V30 = VCardConfig.VCARD_TYPE_V30_GENERIC;
public static final int V40 = VCardConfig.VCARD_TYPE_V40_GENERIC;
@@ -40,6 +40,9 @@ public class VCardTestsBase extends AndroidTestCase {
protected final ContentValues mContentValuesForBase64V30;
protected VCardVerifier mVerifier;
+ /**
+ * true when we shouldn't call {@link VCardVerifier#verify()}.
+ */
private boolean mSkipVerification;
public VCardTestsBase() {
@@ -69,18 +72,28 @@ public class VCardTestsBase extends AndroidTestCase {
mSkipVerification = true;
}
+ /**
+ * Calls super's {@link #setUp()} and prepares {@link VCardVerifier}. We call
+ * {@link VCardVerifier#verify()} on {@link #tearDown()}.
+ */
@Override
- public void setUp() throws Exception{
+ public final void setUp() throws Exception{
super.setUp();
mVerifier = new VCardVerifier(this);
mSkipVerification = false;
}
+ /**
+ * Calls super's {@link #tearDown()} and {@link VCardVerifier#verify()}.
+ */
@Override
- public void tearDown() throws Exception {
- super.tearDown();
+ public final void tearDown() throws Exception {
+ // We don't want to forget to call verify() as it makes unit test successful silently even
+ // when it shouldn't be, while each test case tends become so large to manage and sometimes
+ // we had forgotten to call the method. That is why we override setUp()/tearDown() here.
if (!mSkipVerification) {
mVerifier.verify();
}
+ super.tearDown();
}
}
diff --git a/tests/src/com/android/vcard/tests/test_utils/VCardVerifier.java b/tests/src/com/android/vcard/tests/testutils/VCardVerifier.java
index 29fc835..5acd6a3 100644
--- a/tests/src/com/android/vcard/tests/test_utils/VCardVerifier.java
+++ b/tests/src/com/android/vcard/tests/testutils/VCardVerifier.java
@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import com.android.vcard.VCardComposer;
import com.android.vcard.VCardConfig;
@@ -25,11 +25,9 @@ import com.android.vcard.VCardUtils;
import com.android.vcard.exception.VCardException;
import android.content.ContentResolver;
-import android.content.Context;
import android.content.EntityIterator;
import android.database.Cursor;
import android.net.Uri;
-import android.provider.ContactsContract.Contacts;
import android.test.AndroidTestCase;
import android.test.mock.MockContext;
import android.text.TextUtils;
@@ -56,6 +54,7 @@ import java.util.Arrays;
*/
public class VCardVerifier {
private static final String LOG_TAG = "VCardVerifier";
+ private static final boolean DEBUG = false;
/**
* Special URI for testing.
@@ -64,7 +63,7 @@ public class VCardVerifier {
private static final Uri VCARD_TEST_AUTHORITY_URI =
Uri.parse("content://" + VCARD_TEST_AUTHORITY);
/* package */ static final Uri CONTACTS_TEST_CONTENT_URI =
- Uri.withAppendedPath(VCARD_TEST_AUTHORITY_URI, "contacts");
+ Uri.withAppendedPath(VCARD_TEST_AUTHORITY_URI, "contacts");
private static class CustomMockContext extends MockContext {
final ContentResolver mResolver;
@@ -78,23 +77,7 @@ public class VCardVerifier {
}
}
- private class VCardVerifierInternal implements VCardComposer.OneEntryHandler {
- @Override
- public boolean onInit(Context context) {
- return true;
- }
- @Override
- public boolean onEntryCreated(String vcard) {
- verifyOneVCardForExport(vcard);
- return true;
- }
- @Override
- public void onTerminate() {
- }
- }
-
private final AndroidTestCase mAndroidTestCase;
- private final VCardVerifierInternal mVCardVerifierInternal;
private int mVCardType;
private boolean mIsDoCoMo;
@@ -114,7 +97,6 @@ public class VCardVerifier {
// Called by VCardTestsBase
public VCardVerifier(AndroidTestCase androidTestCase) {
mAndroidTestCase = androidTestCase;
- mVCardVerifierInternal = new VCardVerifierInternal();
mExportTestResolver = null;
mInputStream = null;
mInitialized = false;
@@ -153,7 +135,8 @@ public class VCardVerifier {
}
private void setInputResourceId(int resId) {
- InputStream inputStream = mAndroidTestCase.getContext().getResources().openRawResource(resId);
+ final InputStream inputStream =
+ mAndroidTestCase.getContext().getResources().openRawResource(resId);
if (inputStream == null) {
AndroidTestCase.fail("Wrong resId: " + resId);
}
@@ -188,7 +171,7 @@ public class VCardVerifier {
}
return mPropertyNodesVerifier.addPropertyNodesVerifierElem();
}
-
+
public PropertyNodesVerifierElem addPropertyNodesVerifierElem() {
final PropertyNodesVerifierElem elem = addPropertyNodesVerifierElemWithoutVersion();
final String versionString;
@@ -244,7 +227,7 @@ public class VCardVerifier {
}
/**
- * Sets up sub-verifiers correctly and try parse given vCard as InputStream.
+ * Sets up sub-verifiers correctly and tries to parse vCard as {@link InputStream}.
* Errors around InputStream must be handled outside this method.
*
* Used both from {@link #verifyForImportTest()} and from {@link #verifyForExportTest()}.
@@ -280,7 +263,7 @@ public class VCardVerifier {
}
private void verifyOneVCardForExport(final String vcard) {
- Log.d(LOG_TAG, vcard);
+ if (DEBUG) Log.d(LOG_TAG, vcard);
InputStream is = null;
try {
is = new ByteArrayInputStream(vcard.getBytes(mCharset));
@@ -363,8 +346,6 @@ public class VCardVerifier {
final VCardComposer composer = new VCardComposer(context, mVCardType, mCharset);
// projection is ignored.
final Cursor cursor = resolver.query(CONTACTS_TEST_CONTENT_URI, null, null, null, null);
- composer.addHandler(mLineVerifier);
- composer.addHandler(mVCardVerifierInternal);
if (!composer.init(cursor)) {
AndroidTestCase.fail("init() failed. Reason: " + composer.getErrorReason());
}
@@ -374,8 +355,12 @@ public class VCardVerifier {
try {
final Method mockGetEntityIteratorMethod = getMockGetEntityIteratorMethod();
AndroidTestCase.assertNotNull(mockGetEntityIteratorMethod);
- AndroidTestCase.assertTrue(
- composer.createOneEntry(mockGetEntityIteratorMethod));
+ final String vcard = composer.createOneEntryNew(mockGetEntityIteratorMethod);
+ AndroidTestCase.assertNotNull(vcard);
+ if (mLineVerifier != null) {
+ mLineVerifier.verify(vcard);
+ }
+ verifyOneVCardForExport(vcard);
} catch (Exception e) {
e.printStackTrace();
AndroidTestCase.fail(e.toString());
diff --git a/tests/src/com/android/vcard/tests/test_utils/VNode.java b/tests/src/com/android/vcard/tests/testutils/VNode.java
index 2ca762b..9bf5426 100644
--- a/tests/src/com/android/vcard/tests/test_utils/VNode.java
+++ b/tests/src/com/android/vcard/tests/testutils/VNode.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import java.util.ArrayList;
diff --git a/tests/src/com/android/vcard/tests/test_utils/VNodeBuilder.java b/tests/src/com/android/vcard/tests/testutils/VNodeBuilder.java
index c226369..b10c96d 100644
--- a/tests/src/com/android/vcard/tests/test_utils/VNodeBuilder.java
+++ b/tests/src/com/android/vcard/tests/testutils/VNodeBuilder.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.vcard.tests.test_utils;
+package com.android.vcard.tests.testutils;
import android.content.ContentValues;
import android.util.Base64;