diff options
author | Makoto Onuki <omakoto@google.com> | 2016-09-30 10:28:41 -0700 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2016-10-03 12:12:01 -0700 |
commit | 68c0db255a381d0fdf4ef613f4ac0429ee14a829 (patch) | |
tree | 3edf7896eda74f1ba822ba6c936c8e6f616489c3 /tests | |
parent | fc4fd51e2f5ac74d632fe9089e43239b223bc11d (diff) | |
download | ContactsProvider-68c0db255a381d0fdf4ef613f4ac0429ee14a829.tar.gz |
Add secondary tests that run on separate process
- Test all URIs that are supported, and make sure they can be queried.
- Removed the URLs that were actually not implemented.
- Fix a bug in ProfileAwareUriMatcher
Test: run-all-tests.sh
Change-Id: I5a898ac44b3a7b22b404f764ae40f00f16d44340
Diffstat (limited to 'tests')
9 files changed, 3 insertions, 704 deletions
diff --git a/tests/Android.mk b/tests/Android.mk index d2f99861..89fb2b53 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -5,6 +5,7 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := tests LOCAL_STATIC_JAVA_LIBRARIES := \ + ContactsProviderTestUtils \ android-support-test \ mockito-target-minus-junit4 diff --git a/tests/src/com/android/providers/contacts/ContactMetadataProviderTest.java b/tests/src/com/android/providers/contacts/ContactMetadataProviderTest.java index 8c2a754f..1d0d24af 100644 --- a/tests/src/com/android/providers/contacts/ContactMetadataProviderTest.java +++ b/tests/src/com/android/providers/contacts/ContactMetadataProviderTest.java @@ -93,7 +93,6 @@ public class ContactMetadataProviderTest extends BaseContactsProvider2Test { "' AND " + MetadataSync.DATA_SET + "='" + TEST_DATA_SET2 + "'"; private ContactMetadataProvider mContactMetadataProvider; - private AccountWithDataSet mTestAccount; private ContentValues defaultValues; @Override @@ -175,7 +174,7 @@ public class ContactMetadataProviderTest extends BaseContactsProvider2Test { // Create a raw contact with backupId. String backupId = "backupId10001"; long rawContactId = RawContactUtil.createRawContactWithAccountDataSet( - mResolver, mTestAccount); + mResolver, TEST_ACCOUNT_NAME1, TEST_ACCOUNT_TYPE1, TEST_DATA_SET1); Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); ContentValues values = new ContentValues(); values.put(RawContacts.BACKUP_ID, backupId); @@ -521,10 +520,8 @@ public class ContactMetadataProviderTest extends BaseContactsProvider2Test { } private void setupData() { - mTestAccount = new AccountWithDataSet(TEST_ACCOUNT_NAME1, TEST_ACCOUNT_TYPE1, - TEST_DATA_SET1); long rawContactId1 = RawContactUtil.createRawContactWithAccountDataSet( - mResolver, mTestAccount); + mResolver, TEST_ACCOUNT_NAME1, TEST_ACCOUNT_TYPE1, TEST_DATA_SET1); createAccount(TEST_ACCOUNT_NAME1, TEST_ACCOUNT_TYPE1, TEST_DATA_SET1); insertMetadata(getDefaultValues()); insertMetadataSyncState(TEST_ACCOUNT_NAME1, TEST_ACCOUNT_TYPE1, TEST_DATA_SET1, diff --git a/tests/src/com/android/providers/contacts/testutil/CommonDatabaseUtils.java b/tests/src/com/android/providers/contacts/testutil/CommonDatabaseUtils.java deleted file mode 100644 index cb78a1b6..00000000 --- a/tests/src/com/android/providers/contacts/testutil/CommonDatabaseUtils.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2013 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.testutil; - -import android.content.ContentProviderOperation; -import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.OperationApplicationException; -import android.database.Cursor; -import android.os.RemoteException; -import android.provider.ContactsContract; -import android.util.Log; - -import java.util.ArrayList; -import java.util.List; - -/** - * Common database methods. - */ -public class CommonDatabaseUtils { - public static final String TAG = CommonDatabaseUtils.class.getSimpleName(); - - // primitive value used when record is not found. - public static final long NOT_FOUND = -1; - - public static String[] singleRecordToArray(Cursor cursor) { - String[] result = null; - try { - if (cursor.moveToNext()) { - result = new String[cursor.getColumnCount()]; - fillArray(cursor, result); - } - } finally { - closeQuietly(cursor); - } - return result; - } - - public static List<String[]> multiRecordToArray(Cursor cursor) { - ArrayList<String[]> result = new ArrayList<String[]>(); - try { - while (cursor.moveToNext()) { - String[] record = new String[cursor.getColumnCount()]; - fillArray(cursor, record); - result.add(record); - } - } finally { - closeQuietly(cursor); - } - return result; - } - - private static void fillArray(Cursor cursor, String[] array) { - for (int i = 0; i < array.length; i++) { - array[i] = cursor.getString(i); - } - } - - public static void closeQuietly(Cursor cursor) { - if (cursor != null) { - cursor.close(); - } - } - - public static void extrasVarArgsToValues(ContentValues values, String... extras) { - for (int i = 0; i < extras.length; ) { - values.put(extras[i], extras[i + 1]); - i += 2; - } - } - - public static void applyBatch(ContentResolver resolver, - ArrayList<ContentProviderOperation> operations) { - try { - resolver.applyBatch(ContactsContract.AUTHORITY, operations); - } catch (OperationApplicationException e) { - Log.wtf(TAG, "ContentResolver batch operation failed."); - } catch (RemoteException e) { - Log.wtf(TAG, "Remote exception when performing batch operation."); - } - } - - /** - * Returns an array of values extracted from a {@link ContentValues}, based on the order of - * the provided projection. - * @param values {@link ContentValues} object containing the values to convert into an array - * @param projection array of column names - * - * @return array of values, in the correct order as defined by the projection - */ - public static Object[] getArrayFromContentValues(ContentValues values, String[] projection) { - final Object[] result = new Object[projection.length]; - for (int i = 0; i < projection.length; i++) { - result[i] = values.get(projection[i]); - } - return result; - } -} diff --git a/tests/src/com/android/providers/contacts/testutil/ContactUtil.java b/tests/src/com/android/providers/contacts/testutil/ContactUtil.java deleted file mode 100644 index 442c5e71..00000000 --- a/tests/src/com/android/providers/contacts/testutil/ContactUtil.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2013 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.testutil; - -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; -import android.provider.ContactsContract; - -/** - * Convenience methods for operating on the Contacts table. - */ -public class ContactUtil { - - private static final Uri URI = ContactsContract.Contacts.CONTENT_URI; - - public static void update(ContentResolver resolver, long contactId, - ContentValues values) { - Uri uri = ContentUris.withAppendedId(URI, contactId); - resolver.update(uri, values, null, null); - } - - public static void delete(ContentResolver resolver, long contactId) { - Uri uri = ContentUris.withAppendedId(URI, contactId); - resolver.delete(uri, null, null); - } - - public static boolean recordExistsForContactId(ContentResolver resolver, long contactId) { - String[] projection = new String[]{ - ContactsContract.Contacts._ID - }; - Uri uri = ContentUris.withAppendedId(URI, contactId); - Cursor cursor = resolver.query(uri, projection, null, null, null); - if (cursor.moveToNext()) { - return true; - } - return false; - } - - public static long queryContactLastUpdatedTimestamp(ContentResolver resolver, long contactId) { - String[] projection = new String[]{ - ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP - }; - - Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); - Cursor cursor = resolver.query(uri, projection, null, null, null); - try { - if (cursor.moveToNext()) { - return cursor.getLong(0); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return CommonDatabaseUtils.NOT_FOUND; - } -} diff --git a/tests/src/com/android/providers/contacts/testutil/DataUtil.java b/tests/src/com/android/providers/contacts/testutil/DataUtil.java deleted file mode 100644 index 2afd5674..00000000 --- a/tests/src/com/android/providers/contacts/testutil/DataUtil.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2013 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.testutil; - -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.net.Uri; -import android.provider.ContactsContract; -import android.provider.ContactsContract.CommonDataKinds.StructuredName; -import android.provider.ContactsContract.Data; -import android.test.mock.MockContentResolver; - -/** - * Convenience methods for operating on the Data table. - */ -public class DataUtil { - - private static final Uri URI = ContactsContract.Data.CONTENT_URI; - - public static void delete(ContentResolver resolver, long dataId) { - Uri uri = ContentUris.withAppendedId(URI, dataId); - resolver.delete(uri, null, null); - } - - public static void update(ContentResolver resolver, long dataId, ContentValues values) { - Uri uri = ContentUris.withAppendedId(URI, dataId); - resolver.update(uri, values, null, null); - } - - public static Uri insertStructuredName(ContentResolver resolver, long rawContactId, - ContentValues values) { - values.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId); - values.put(ContactsContract.Data.MIMETYPE, - ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); - Uri resultUri = resolver.insert(ContactsContract.Data.CONTENT_URI, values); - return resultUri; - } - - public static Uri insertStructuredName(ContentResolver resolver, long rawContactId, - String givenName, String familyName) { - return insertStructuredName(resolver, rawContactId, givenName, familyName, - /* phonetic given =*/ null); - } - - public static Uri insertStructuredName( - ContentResolver resolver, long rawContactId, String givenName, String familyName, - String phoneticFamily) { - return insertStructuredName(resolver, rawContactId, givenName, familyName, phoneticFamily, - /* isSuperPrimary = true */ false); - } - - public static Uri insertStructuredName( - ContentResolver resolver, long rawContactId, String givenName, String familyName, - String phoneticFamily, boolean isSuperPrimary) { - ContentValues values = new ContentValues(); - StringBuilder sb = new StringBuilder(); - if (givenName != null) { - sb.append(givenName); - } - if (givenName != null && familyName != null) { - sb.append(" "); - } - if (familyName != null) { - sb.append(familyName); - } - if (sb.length() == 0 && phoneticFamily != null) { - sb.append(phoneticFamily); - } - values.put(StructuredName.DISPLAY_NAME, sb.toString()); - values.put(StructuredName.GIVEN_NAME, givenName); - values.put(StructuredName.FAMILY_NAME, familyName); - if (phoneticFamily != null) { - // When creating phonetic names, be careful to use PHONETIC_FAMILY_NAME instead of - // PHONETIC_GIVEN_NAME, to work around b/19612393. - values.put(StructuredName.PHONETIC_FAMILY_NAME, phoneticFamily); - } - if (isSuperPrimary) { - values.put(Data.IS_PRIMARY, 1); - values.put(Data.IS_SUPER_PRIMARY, 1); - } - - return insertStructuredName(resolver, rawContactId, values); - } - - public static Uri insertPhoneticName(ContentResolver resolver, long rawContactId, - String phoneticFamilyName) { - ContentValues values = new ContentValues(); - // When creating phonetic names, be careful to use PHONETIC_FAMILY_NAME instead of - // PHONETIC_GIVEN_NAME, to work around b/19612393. - values.put(StructuredName.PHONETIC_FAMILY_NAME, phoneticFamilyName); - return insertStructuredName(resolver, rawContactId, values); - } -}
\ No newline at end of file diff --git a/tests/src/com/android/providers/contacts/testutil/DatabaseAsserts.java b/tests/src/com/android/providers/contacts/testutil/DatabaseAsserts.java deleted file mode 100644 index 2af98299..00000000 --- a/tests/src/com/android/providers/contacts/testutil/DatabaseAsserts.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2013 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.testutil; - -import android.content.ContentResolver; -import android.content.ContentValues; -import android.net.Uri; -import android.test.MoreAsserts; - -import junit.framework.Assert; - -/** - * Common methods for asserting database related operations. - */ -public class DatabaseAsserts { - - public static void assertDeleteIsUnsupported(ContentResolver resolver, Uri uri) { - try { - resolver.delete(uri, null, null); - Assert.fail("delete operation should have failed with UnsupportedOperationException on" - + uri); - } catch (UnsupportedOperationException e) { - // pass - } - } - - public static void assertInsertIsUnsupported(ContentResolver resolver, Uri uri) { - try { - ContentValues values = new ContentValues(); - resolver.insert(uri, values); - Assert.fail("insert operation should have failed with UnsupportedOperationException on" - + uri); - } catch (UnsupportedOperationException e) { - // pass - } - } - - /** - * Create a contact and assert that the record exists. - * - * @return The created contact id pair. - */ - public static ContactIdPair assertAndCreateContact(ContentResolver resolver) { - long rawContactId = RawContactUtil.createRawContactWithName(resolver); - - long contactId = RawContactUtil.queryContactIdByRawContactId(resolver, rawContactId); - MoreAsserts.assertNotEqual(CommonDatabaseUtils.NOT_FOUND, contactId); - - return new ContactIdPair(contactId, rawContactId); - } - - /** - * Create a contact with name and assert that the record exists. - * - * @return The created contact id pair. - */ - public static ContactIdPair assertAndCreateContactWithName(ContentResolver resolver, - String firstName, String lastName) { - long rawContactId = RawContactUtil.createRawContactWithName(resolver, firstName, lastName); - - long contactId = RawContactUtil.queryContactIdByRawContactId(resolver, rawContactId); - MoreAsserts.assertNotEqual(CommonDatabaseUtils.NOT_FOUND, contactId); - - return new ContactIdPair(contactId, rawContactId); - } - - /** - * Asserts that a contact id was deleted, has a delete log, and that log has a timestamp greater - * than the given timestamp. - * - * @param contactId The contact id to check. - * @param start The timestamp that the delete log should be greater than. - */ - public static void assertHasDeleteLogGreaterThan(ContentResolver resolver, long contactId, - long start) { - Assert.assertFalse(ContactUtil.recordExistsForContactId(resolver, contactId)); - - long deletedTimestamp = DeletedContactUtil.queryDeletedTimestampForContactId(resolver, - contactId); - MoreAsserts.assertNotEqual(CommonDatabaseUtils.NOT_FOUND, deletedTimestamp); - Assert.assertTrue(deletedTimestamp > start); - } - - /** - * Holds a single contact id and raw contact id relationship. - */ - public static class ContactIdPair { - public long mContactId; - public long mRawContactId; - - public ContactIdPair(long contactId, long rawContactId) { - this.mContactId = contactId; - this.mRawContactId = rawContactId; - } - } -} diff --git a/tests/src/com/android/providers/contacts/testutil/DeletedContactUtil.java b/tests/src/com/android/providers/contacts/testutil/DeletedContactUtil.java deleted file mode 100644 index 2dab7f90..00000000 --- a/tests/src/com/android/providers/contacts/testutil/DeletedContactUtil.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2013 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.testutil; - -import static android.provider.ContactsContract.DeletedContacts; - -import android.content.ContentResolver; -import android.content.ContentUris; -import android.database.Cursor; -import android.net.Uri; - -import java.util.List; - -/** - * Convenience methods for operating on the DeletedContacts table. - */ -public class DeletedContactUtil { - - private static final Uri URI = DeletedContacts.CONTENT_URI; - - public static long queryDeletedTimestampForContactId(ContentResolver resolver, long contactId) { - String[] projection = new String[]{ - DeletedContacts.CONTACT_DELETED_TIMESTAMP - }; - Uri uri = ContentUris.withAppendedId(URI, contactId); - Cursor cursor = resolver.query(uri, projection, null, null, null); - if (cursor.moveToNext()) { - return cursor.getLong(0); - } - return CommonDatabaseUtils.NOT_FOUND; - } - - public static long getCount(ContentResolver resolver) { - String[] projection = new String[] { - DeletedContacts.CONTACT_ID - }; - Cursor cursor = resolver.query(URI, projection, null, null, null); - try { - return cursor.getCount(); - } finally { - CommonDatabaseUtils.closeQuietly(cursor); - } - } - - /** - * Queries all records. - * - * @return A list of records. Where each record is represented as an array of strings. - */ - public static List<String[]> query(ContentResolver resolver, String[] projection) { - Cursor cursor = resolver.query(URI, projection, null, null, null); - return CommonDatabaseUtils.multiRecordToArray(cursor); - } - - /** - * Queries all records after a given timestamp. - * - * @return A list of records. Where each record is represented as an array of strings. - */ - public static List<String[]> querySinceTimestamp(ContentResolver resolver, String[] projection, - long timestamp) { - String selection = DeletedContacts.CONTACT_DELETED_TIMESTAMP + ">?"; - String[] args = new String[] {timestamp + ""}; - Cursor cursor = resolver.query(URI, projection, selection, args, null); - return CommonDatabaseUtils.multiRecordToArray(cursor); - } -} diff --git a/tests/src/com/android/providers/contacts/testutil/RawContactUtil.java b/tests/src/com/android/providers/contacts/testutil/RawContactUtil.java deleted file mode 100644 index f24875b7..00000000 --- a/tests/src/com/android/providers/contacts/testutil/RawContactUtil.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2013 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.testutil; - -import android.accounts.Account; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; -import android.provider.ContactsContract; -import android.test.mock.MockContentResolver; -import com.android.providers.contacts.AccountWithDataSet; - -import java.util.List; - -/** - * Convenience methods for operating on the RawContacts table. - */ -public class RawContactUtil { - - private static final Uri URI = ContactsContract.RawContacts.CONTENT_URI; - - public static void update(ContentResolver resolver, long rawContactId, - ContentValues values) { - Uri uri = ContentUris.withAppendedId(URI, rawContactId); - resolver.update(uri, values, null, null); - } - - public static String[] queryByRawContactId(ContentResolver resolver, - long rawContactId, String[] projection) { - Uri uri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, - rawContactId); - Cursor cursor = resolver.query(uri, projection, null, null, null); - return CommonDatabaseUtils.singleRecordToArray(cursor); - } - - /** - * Returns a list of raw contact records. - * - * @return A list of records. Where each record is represented as an array of strings. - */ - public static List<String[]> queryByContactId(ContentResolver resolver, long contactId, - String[] projection) { - Uri uri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, contactId); - Cursor cursor = resolver.query(uri, projection, null, null, null); - return CommonDatabaseUtils.multiRecordToArray(cursor); - } - - public static void delete(ContentResolver resolver, long rawContactId, - boolean isSyncAdapter) { - Uri uri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawContactId) - .buildUpon() - .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, isSyncAdapter + "") - .build(); - resolver.delete(uri, null, null); - } - - public static long queryContactIdByRawContactId(ContentResolver resolver, long rawContactid) { - String[] projection = new String[]{ - ContactsContract.RawContacts.CONTACT_ID - }; - String[] result = RawContactUtil.queryByRawContactId(resolver, rawContactid, - projection); - if (result == null) { - return CommonDatabaseUtils.NOT_FOUND; - } - return Long.parseLong(result[0]); - } - - public static boolean rawContactExistsById(ContentResolver resolver, long rawContactid) { - long contactId = queryContactIdByRawContactId(resolver, rawContactid); - return contactId != CommonDatabaseUtils.NOT_FOUND; - } - - public static long createRawContact(ContentResolver resolver, Account account, - String... extras) { - ContentValues values = new ContentValues(); - CommonDatabaseUtils.extrasVarArgsToValues(values, extras); - final Uri uri = TestUtil.maybeAddAccountQueryParameters( - ContactsContract.RawContacts.CONTENT_URI, account); - Uri contactUri = resolver.insert(uri, values); - return ContentUris.parseId(contactUri); - } - - public static long createRawContactWithAccountDataSet(ContentResolver resolver, - AccountWithDataSet accountWithDataSet, String... extras) { - ContentValues values = new ContentValues(); - CommonDatabaseUtils.extrasVarArgsToValues(values, extras); - final Uri uri = TestUtil.maybeAddAccountWithDataSetQueryParameters( - ContactsContract.RawContacts.CONTENT_URI, accountWithDataSet); - Uri contactUri = resolver.insert(uri, values); - return ContentUris.parseId(contactUri); - } - - public static long createRawContactWithName(ContentResolver resolver) { - return createRawContactWithName(resolver, null); - } - - public static long createRawContactWithName(ContentResolver resolver, Account account) { - return createRawContactWithName(resolver, "John", "Doe", account); - } - - public static long createRawContactWithName(ContentResolver resolver, String firstName, - String lastName) { - return createRawContactWithName(resolver, firstName, lastName, null); - } - - public static long createRawContactWithName(ContentResolver resolver, String firstName, - String lastName, Account account) { - long rawContactId = createRawContact(resolver, account); - DataUtil.insertStructuredName(resolver, rawContactId, firstName, lastName); - return rawContactId; - } - - public static long createRawContact(ContentResolver resolver) { - return createRawContact(resolver, null); - } - - public static long createRawContactWithBackupId(ContentResolver resolver, String backupId, - Account account) { - ContentValues values = new ContentValues(); - values.put(ContactsContract.RawContacts.BACKUP_ID, backupId); - final Uri uri = ContactsContract.RawContacts.CONTENT_URI - .buildUpon() - .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, - account.name) - .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, - account.type) - .build(); - Uri contactUri = resolver.insert(uri, values); - return ContentUris.parseId(contactUri); - } -} diff --git a/tests/src/com/android/providers/contacts/testutil/TestUtil.java b/tests/src/com/android/providers/contacts/testutil/TestUtil.java deleted file mode 100644 index 05ff61d1..00000000 --- a/tests/src/com/android/providers/contacts/testutil/TestUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2013 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.testutil; - -import android.accounts.Account; -import android.net.Uri; -import android.provider.ContactsContract.RawContacts; -import android.util.Log; -import com.android.providers.contacts.AccountWithDataSet; - -/** - * Common methods used for testing. - */ -public class TestUtil { - private static String TAG = TestUtil.class.getSimpleName(); - - public static final Account ACCOUNT_1 = new Account("account_name_1", "account_type_1"); - public static final Account ACCOUNT_2 = new Account("account_name_2", "account_type_2"); - - /** - * Sleep for 1ms. - */ - public static void sleep() { - try { - Thread.sleep(1); - } catch (InterruptedException e) { - Log.w(TAG, "Sleep interrupted."); - } - } - - public static Uri maybeAddAccountQueryParameters(Uri uri, Account account) { - if (account == null) { - return uri; - } - return uri.buildUpon() - .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) - .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type) - .build(); - } - - public static Uri maybeAddAccountWithDataSetQueryParameters(Uri uri, - AccountWithDataSet account) { - if (account == null) { - return uri; - } - return uri.buildUpon() - .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.getAccountName()) - .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.getAccountType()) - .appendQueryParameter(RawContacts.DATA_SET, account.getDataSet()) - .build(); - } -} |