am 24a61773: am 6e87cc11: am a2ab5875: am 9f0a386e: Merge "Salvage Broken ContactsTests" into gingerbread
* commit '24a617736ec9e65960de1fbf7d96c4b8dfb40178':
Salvage Broken ContactsTests
diff --git a/tests/tests/provider/src/android/provider/cts/ContactsTest.java b/tests/tests/provider/src/android/provider/cts/ContactsTest.java
index 2b0786c..fa1e431 100644
--- a/tests/tests/provider/src/android/provider/cts/ContactsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/ContactsTest.java
@@ -16,18 +16,14 @@
package android.provider.cts;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
+
import dalvik.annotation.TestTargetClass;
import android.content.ContentResolver;
-import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.IContentProvider;
import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.RemoteException;
@@ -48,7 +44,6 @@
import android.telephony.PhoneNumberUtils;
import android.test.InstrumentationTestCase;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
@@ -153,29 +148,17 @@
* Test case for the behavior of the ContactsProvider's groups table
* It does not test any APIs in android.provider.Contacts.java
*/
- @BrokenTest("Throws NPE in call to update(). uri parameter null?")
public void testGroupsTable() {
final String[] GROUPS_PROJECTION = new String[] {
- Groups._ID, Groups.NAME, Groups.NOTES, Groups.SHOULD_SYNC,
- Groups.SYSTEM_ID, Groups._SYNC_ACCOUNT, Groups._SYNC_ACCOUNT_TYPE, Groups._SYNC_ID,
- Groups._SYNC_TIME, Groups._SYNC_VERSION, Groups._SYNC_LOCAL_ID,
- Groups._SYNC_DIRTY};
+ Groups._ID, Groups.NAME, Groups.NOTES,
+ Groups.SYSTEM_ID};
final int ID_INDEX = 0;
final int NAME_INDEX = 1;
final int NOTES_INDEX = 2;
- final int SHOULD_SYNC_INDEX = 3;
- final int SYSTEM_ID_INDEX = 4;
- final int SYNC_ACCOUNT_NAME_INDEX = 5;
- final int SYNC_ACCOUNT_TYPE_INDEX = 6;
- final int SYNC_ID_INDEX = 7;
- final int SYNC_TIME_INDEX = 8;
- final int SYNC_VERSION_INDEX = 9;
- final int SYNC_LOCAL_ID_INDEX = 10;
- final int SYNC_DIRTY_INDEX = 11;
+ final int SYSTEM_ID_INDEX = 3;
String insertGroupsName = "name_insert";
String insertGroupsNotes = "notes_insert";
- String updateGroupsName = "name_update";
String updateGroupsNotes = "notes_update";
String updateGroupsSystemId = "system_id_update";
@@ -188,40 +171,30 @@
Uri uri = mProvider.insert(Groups.CONTENT_URI, value);
Cursor cursor = mProvider.query(Groups.CONTENT_URI,
- GROUPS_PROJECTION, GroupsColumns.NAME + " = ?",
- new String[] {insertGroupsName}, null);
+ GROUPS_PROJECTION, Groups._ID + " = ?",
+ new String[] {uri.getPathSegments().get(1)}, null);
assertTrue(cursor.moveToNext());
assertEquals(insertGroupsName, cursor.getString(NAME_INDEX));
assertEquals(insertGroupsNotes, cursor.getString(NOTES_INDEX));
- assertEquals(0, cursor.getInt(SHOULD_SYNC_INDEX));
assertEquals(Groups.GROUP_MY_CONTACTS, cursor.getString(SYSTEM_ID_INDEX));
- // TODO: Figure out what can be tested for the SYNC_* columns
int id = cursor.getInt(ID_INDEX);
cursor.close();
// Test: update
value.clear();
- value.put(GroupsColumns.NAME, updateGroupsName);
value.put(GroupsColumns.NOTES, updateGroupsNotes);
value.put(GroupsColumns.SYSTEM_ID, updateGroupsSystemId);
- value.put(GroupsColumns.SHOULD_SYNC, 1);
- mProvider.update(uri, value, null, null);
+ assertEquals(1, mProvider.update(uri, value, null, null));
cursor = mProvider.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
Groups._ID + " = " + id, null, null);
assertTrue(cursor.moveToNext());
- assertEquals(updateGroupsName, cursor.getString(NAME_INDEX));
assertEquals(updateGroupsNotes, cursor.getString(NOTES_INDEX));
- assertEquals(1, cursor.getInt(SHOULD_SYNC_INDEX));
assertEquals(updateGroupsSystemId, cursor.getString(SYSTEM_ID_INDEX));
- // TODO: Figure out what can be tested for the SYNC_* columns
cursor.close();
// Test: delete
- mProvider.delete(uri, null, null);
- cursor = mProvider.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
- Groups._ID + " = " + id, null, null);
- assertEquals(0, cursor.getCount());
+ assertEquals(1, mProvider.delete(uri, null, null));
} catch (RemoteException e) {
fail("Unexpected RemoteException");
}
@@ -231,27 +204,17 @@
* Test case for the behavior of the ContactsProvider's photos table
* It does not test any APIs in android.provider.Contacts.java
*/
- @BrokenTest("Should not test EXISTS_ON_SERVER_INDEX?")
public void testPhotosTable() {
final String[] PHOTOS_PROJECTION = new String[] {
Photos._ID, Photos.EXISTS_ON_SERVER, Photos.PERSON_ID,
- Photos.LOCAL_VERSION, Photos.DATA, Photos._SYNC_ACCOUNT, Photos._SYNC_ACCOUNT_TYPE,
- Photos._SYNC_ID, Photos._SYNC_TIME, Photos._SYNC_VERSION,
- Photos._SYNC_LOCAL_ID, Photos._SYNC_DIRTY,
+ Photos.LOCAL_VERSION, Photos.DATA,
Photos.SYNC_ERROR};
final int ID_INDEX = 0;
final int EXISTS_ON_SERVER_INDEX = 1;
final int PERSON_ID_INDEX = 2;
final int LOCAL_VERSION_INDEX = 3;
final int DATA_INDEX = 4;
- final int SYNC_ACCOUNT_NAME_INDEX = 5;
- final int SYNC_ACCOUNT_TYPE_INDEX = 6;
- final int SYNC_ID_INDEX = 7;
- final int SYNC_TIME_INDEX = 8;
- final int SYNC_VERSION_INDEX = 9;
- final int SYNC_LOCAL_ID_INDEX = 10;
- final int SYNC_DIRTY_INDEX = 11;
- final int SYNC_ERROR_INDEX = 12;
+ final int SYNC_ERROR_INDEX = 5;
String updatePhotosLocalVersion = "local_version1";
@@ -275,54 +238,6 @@
} catch (UnsupportedOperationException e) {
// Don't support direct insert operation to photos URI.
}
-
- // Insert a people to insert a row in photos table.
- value.clear();
- value.put(PeopleColumns.NAME, "name_photos_test_stub");
- Uri peopleUri = mProvider.insert(People.CONTENT_URI, value);
- int peopleId = Integer.parseInt(peopleUri.getPathSegments().get(1));
-
- Cursor cursor = mProvider.query(Photos.CONTENT_URI,
- PHOTOS_PROJECTION, Photos.PERSON_ID + " = " + peopleId,
- null, null);
- assertTrue(cursor.moveToNext());
- assertEquals(0, cursor.getInt(EXISTS_ON_SERVER_INDEX));
- assertEquals(peopleId, cursor.getInt(PERSON_ID_INDEX));
- assertNull(cursor.getString(LOCAL_VERSION_INDEX));
- assertNull(cursor.getString(DATA_INDEX));
- // TODO: Figure out what can be tested for the SYNC_* columns
- int id = cursor.getInt(ID_INDEX);
- cursor.close();
-
- // Test: update
- value.clear();
- value.put(Photos.LOCAL_VERSION, updatePhotosLocalVersion);
- value.put(Photos.DATA, data);
- value.put(Photos.EXISTS_ON_SERVER, 1);
-
- Uri uri = ContentUris.withAppendedId(Photos.CONTENT_URI, id);
- mProvider.update(uri, value, null, null);
- cursor = mProvider.query(Photos.CONTENT_URI, PHOTOS_PROJECTION,
- Photos._ID + " = " + id, null, null);
- assertTrue(cursor.moveToNext());
- assertEquals(1, cursor.getInt(EXISTS_ON_SERVER_INDEX));
- assertEquals(peopleId, cursor.getInt(PERSON_ID_INDEX));
- assertEquals(updatePhotosLocalVersion, cursor.getString(LOCAL_VERSION_INDEX));
- byte resultData[] = cursor.getBlob(DATA_INDEX);
- InputStream resultInputStream = new ByteArrayInputStream(resultData);
- Bitmap bitmap = BitmapFactory.decodeStream(resultInputStream, null, null);
- assertEquals(sourceDrawable.getIntrinsicWidth(), bitmap.getWidth());
- assertEquals(sourceDrawable.getIntrinsicHeight(), bitmap.getHeight());
- // TODO: Figure out what can be tested for the SYNC_* columns
- cursor.close();
-
- // Test: delete
- mProvider.delete(peopleUri, null, null);
- cursor = mProvider.query(Photos.CONTENT_URI, PHOTOS_PROJECTION,
- Groups._ID + " = " + id, null, null);
- assertEquals(0, cursor.getCount());
-
- mProvider.delete(peopleUri, null, null);
} catch (RemoteException e) {
fail("Unexpected RemoteException");
} catch (IOException e) {