am d0ad67ad: Merge "Fix the test breakage in vCard tests." into gingerbread
Merge commit 'd0ad67ad84e254cdf34963ad4152ca7158df5eab' into gingerbread-plus-aosp * commit 'd0ad67ad84e254cdf34963ad4152ca7158df5eab': Fix the test breakage in vCard tests.
This commit is contained in:
@@ -24,6 +24,7 @@ import android.net.Uri;
|
||||
import android.provider.ContactsContract.Contacts;
|
||||
import android.provider.ContactsContract.Data;
|
||||
import android.provider.ContactsContract.RawContacts;
|
||||
import android.test.mock.MockContentProvider;
|
||||
import android.test.mock.MockContentResolver;
|
||||
import android.test.mock.MockCursor;
|
||||
|
||||
@@ -44,6 +45,10 @@ import java.util.List;
|
||||
public ContactEntry addInputContactEntry() {
|
||||
return mProvider.buildInputEntry();
|
||||
}
|
||||
|
||||
public ExportTestProvider getProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ class MockEntityIterator implements EntityIterator {
|
||||
|
||||
@@ -19,8 +19,6 @@ import android.content.ContentProviderOperation;
|
||||
import android.content.ContentProviderResult;
|
||||
import android.content.ContentValues;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract.Data;
|
||||
import android.provider.ContactsContract.RawContacts;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Email;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Event;
|
||||
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
|
||||
@@ -34,6 +32,9 @@ import android.provider.ContactsContract.CommonDataKinds.Relation;
|
||||
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
|
||||
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Website;
|
||||
import android.provider.ContactsContract.Data;
|
||||
import android.provider.ContactsContract.RawContacts;
|
||||
import android.test.mock.MockContentProvider;
|
||||
import android.test.mock.MockContentResolver;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -45,10 +46,10 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/* package */ class ImportTestResolver extends MockContentResolver {
|
||||
final ImportTestProvider mProvider;
|
||||
|
||||
@@ -438,14 +438,26 @@ public class VCardExporterTests extends VCardTestsBase {
|
||||
.put(Phone.TYPE, Phone.TYPE_CUSTOM)
|
||||
.put(Phone.LABEL, "invalid");
|
||||
PropertyNodesVerifierElem elem = mVerifier.addPropertyNodesVerifierElemWithEmptyName();
|
||||
elem.addExpectedNode("TEL", "1", new TypeSet("MODEM"))
|
||||
.addExpectedNode("TEL", "2", new TypeSet("MSG"))
|
||||
.addExpectedNode("TEL", "3", new TypeSet("BBS"))
|
||||
.addExpectedNode("TEL", "4", new TypeSet("VIDEO"))
|
||||
.addExpectedNode("TEL", "5", new TypeSet("VOICE"))
|
||||
.addExpectedNode("TEL", "6", new TypeSet("CELL"))
|
||||
.addExpectedNode("TEL", "7", new TypeSet("CELL"))
|
||||
.addExpectedNode("TEL", "8", new TypeSet("X-invalid"));
|
||||
if (VCardConfig.isV30(vcardType)) {
|
||||
// vCard 3.0 accepts "invalid". Also stop using toUpper()
|
||||
elem.addExpectedNode("TEL", "1", new TypeSet("Modem"))
|
||||
.addExpectedNode("TEL", "2", new TypeSet("MSG"))
|
||||
.addExpectedNode("TEL", "3", new TypeSet("BBS"))
|
||||
.addExpectedNode("TEL", "4", new TypeSet("VIDEO"))
|
||||
.addExpectedNode("TEL", "5", new TypeSet("VOICE"))
|
||||
.addExpectedNode("TEL", "6", new TypeSet("CELL"))
|
||||
.addExpectedNode("TEL", "7", new TypeSet("CELL"))
|
||||
.addExpectedNode("TEL", "8", new TypeSet("invalid"));
|
||||
} else {
|
||||
elem.addExpectedNode("TEL", "1", new TypeSet("MODEM"))
|
||||
.addExpectedNode("TEL", "2", new TypeSet("MSG"))
|
||||
.addExpectedNode("TEL", "3", new TypeSet("BBS"))
|
||||
.addExpectedNode("TEL", "4", new TypeSet("VIDEO"))
|
||||
.addExpectedNode("TEL", "5", new TypeSet("VOICE"))
|
||||
.addExpectedNode("TEL", "6", new TypeSet("CELL"))
|
||||
.addExpectedNode("TEL", "7", new TypeSet("CELL"))
|
||||
.addExpectedNode("TEL", "8", new TypeSet("X-invalid"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testPhoneTypeHandlingV21() {
|
||||
|
||||
@@ -16,95 +16,8 @@
|
||||
|
||||
package android.pim.vcard;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentProviderResult;
|
||||
import android.content.ContentValues;
|
||||
import android.content.EntityIterator;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.database.Cursor;
|
||||
import android.database.CursorWindow;
|
||||
import android.database.IBulkCursor;
|
||||
import android.database.IContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.pim.vcard.VCardConfig;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Almost a dead copy of android.test.mock.MockContentProvider, but different in that this
|
||||
* class extends ContentProvider, not implementing IContentProvider,
|
||||
* so that MockContentResolver is able to accept this class :(
|
||||
*/
|
||||
class MockContentProvider extends ContentProvider {
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bulkInsert(Uri url, ContentValues[] initialValues) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public IBulkCursor bulkQuery(Uri url, String[] projection, String selection,
|
||||
String[] selectionArgs, String sortOrder, IContentObserver observer,
|
||||
CursorWindow window) throws RemoteException {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
public int delete(Uri url, String selection, String[] selectionArgs) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri url) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri url, ContentValues initialValues) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor openFile(Uri url, String mode) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssetFileDescriptor openAssetFile(Uri uri, String mode) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs,
|
||||
String sortOrder) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri url, ContentValues values, String selection, String[] selectionArgs) {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
|
||||
public IBinder asBinder() {
|
||||
throw new UnsupportedOperationException("unimplemented mock method");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BaseClass for vCard unit tests with utility classes.
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.pim.vcard.VCardParser_V30;
|
||||
import android.pim.vcard.exception.VCardException;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.mock.MockContext;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -51,6 +52,8 @@ import java.util.Arrays;
|
||||
}
|
||||
|
||||
/* package */ class VCardVerifier {
|
||||
private static final String LOG_TAG = "VCardVerifier";
|
||||
|
||||
private class VCardVerifierInternal implements VCardComposer.OneEntryHandler {
|
||||
public boolean onInit(Context context) {
|
||||
return true;
|
||||
@@ -267,10 +270,13 @@ import java.util.Arrays;
|
||||
final ContentResolver resolver,
|
||||
final Uri uri, final String selection,
|
||||
final String[] selectionArgs, final String sortOrder) {
|
||||
final ContentProvider provider =
|
||||
resolver.acquireContentProviderClient(uri).getLocalContentProvider();
|
||||
return ((ExportTestProvider)provider).queryEntities(
|
||||
uri, selection, selectionArgs, sortOrder);
|
||||
if (ExportTestResolver.class.equals(resolver.getClass())) {
|
||||
return ((ExportTestResolver)resolver).getProvider().queryEntities(
|
||||
uri, selection, selectionArgs, sortOrder);
|
||||
}
|
||||
|
||||
Log.e(LOG_TAG, "Unexpected provider given.");
|
||||
return null;
|
||||
}
|
||||
|
||||
private Method getMockGetEntityIteratorMethod()
|
||||
@@ -285,18 +291,19 @@ import java.util.Arrays;
|
||||
composer.addHandler(mLineVerifier);
|
||||
composer.addHandler(mVCardVerifierInternal);
|
||||
if (!composer.init(VCardComposer.CONTACTS_TEST_CONTENT_URI, null, null, null)) {
|
||||
mTestCase.fail("init() failed. Reason: " + composer.getErrorReason());
|
||||
AndroidTestCase.fail("init() failed. Reason: " + composer.getErrorReason());
|
||||
}
|
||||
mTestCase.assertFalse(composer.isAfterLast());
|
||||
AndroidTestCase.assertFalse(composer.isAfterLast());
|
||||
try {
|
||||
while (!composer.isAfterLast()) {
|
||||
try {
|
||||
final Method mockGetEntityIteratorMethod = getMockGetEntityIteratorMethod();
|
||||
mTestCase.assertTrue(
|
||||
composer.createOneEntry(getMockGetEntityIteratorMethod()));
|
||||
AndroidTestCase.assertNotNull(mockGetEntityIteratorMethod);
|
||||
AndroidTestCase.assertTrue(
|
||||
composer.createOneEntry(mockGetEntityIteratorMethod));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
mTestCase.fail();
|
||||
AndroidTestCase.fail();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user