summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2013-03-12 20:13:21 (GMT)
committerGeorge Mount <mount@google.com>2013-03-12 20:51:01 (GMT)
commit9bd3f529ee0dc79c9c9c5c9aa89309336e232a49 (patch)
treedc48b6fb3ce2ed276ed4a0f004137bd66e593c86 /tests
parent05a480847362eb9dbf57f73c83092e6a67f919f4 (diff)
downloadandroid_packages_apps_Snap-9bd3f529ee0dc79c9c9c5c9aa89309336e232a49.zip
android_packages_apps_Snap-9bd3f529ee0dc79c9c9c5c9aa89309336e232a49.tar.gz
android_packages_apps_Snap-9bd3f529ee0dc79c9c9c5c9aa89309336e232a49.tar.bz2
Add delete cascade for Accounts.
Change-Id: I962c7cb657643c3eddbbeb6a691b26de5553d4df
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/photos/data/PhotoDatabaseUtils.java5
-rw-r--r--tests/src/com/android/photos/data/PhotoProviderTest.java36
2 files changed, 39 insertions, 2 deletions
diff --git a/tests/src/com/android/photos/data/PhotoDatabaseUtils.java b/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
index 97db8bf..f7a46d4 100644
--- a/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
+++ b/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
@@ -65,6 +65,7 @@ public class PhotoDatabaseUtils {
private static String SELECTION_ALBUM_PARENT_ID = Albums.PARENT_ID + " = ?";
private static String SELECTION_PHOTO_ALBUM_ID = Photos.ALBUM_ID + " = ?";
+ private static String SELECTION_ACCOUNT_ID = Accounts.ACCOUNT_NAME + " = ?";
public static long queryAlbumIdFromParentId(SQLiteDatabase db, long parentId) {
return queryId(db, Albums.TABLE, PROJECTION_ALBUMS, SELECTION_ALBUM_PARENT_ID, parentId);
@@ -74,6 +75,10 @@ public class PhotoDatabaseUtils {
return queryId(db, Photos.TABLE, PROJECTION_PHOTOS, SELECTION_PHOTO_ALBUM_ID, albumId);
}
+ public static long queryAccountIdFromName(SQLiteDatabase db, String accountName) {
+ return queryId(db, Accounts.TABLE, PROJECTION_ACCOUNTS, SELECTION_ACCOUNT_ID, accountName);
+ }
+
public static long queryId(SQLiteDatabase db, String table, String[] projection,
String selection, Object parameter) {
String paramString = parameter == null ? null : parameter.toString();
diff --git a/tests/src/com/android/photos/data/PhotoProviderTest.java b/tests/src/com/android/photos/data/PhotoProviderTest.java
index 39abff4..685946e 100644
--- a/tests/src/com/android/photos/data/PhotoProviderTest.java
+++ b/tests/src/com/android/photos/data/PhotoProviderTest.java
@@ -28,6 +28,7 @@ import android.os.RemoteException;
import android.provider.BaseColumns;
import android.test.ProviderTestCase2;
+import com.android.photos.data.PhotoProvider.Accounts;
import com.android.photos.data.PhotoProvider.Albums;
import com.android.photos.data.PhotoProvider.Metadata;
import com.android.photos.data.PhotoProvider.Photos;
@@ -43,6 +44,7 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
private static final long ALBUM_PARENT_ID = 100;
private static final String META_KEY = "mykey";
private static final String META_VALUE = "myvalue";
+ private static final String ACCOUNT_NAME = "foo@bar.com";
private static final Uri NO_TABLE_URI = PhotoProvider.BASE_CONTENT_URI;
private static final Uri BAD_TABLE_URI = Uri.withAppendedPath(PhotoProvider.BASE_CONTENT_URI,
@@ -55,6 +57,7 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
private long mAlbumId;
private long mPhotoId;
private long mMetadataId;
+ private long mAccountId;
private SQLiteOpenHelper mDBHelper;
private ContentResolver mResolver;
@@ -74,11 +77,13 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
SQLiteDatabase db = mDBHelper.getWritableDatabase();
db.beginTransaction();
try {
+ PhotoDatabaseUtils.insertAccount(db, ACCOUNT_NAME);
+ mAccountId = PhotoDatabaseUtils.queryAccountIdFromName(db, ACCOUNT_NAME);
PhotoDatabaseUtils.insertAlbum(db, ALBUM_PARENT_ID, ALBUM_TITLE,
- Albums.VISIBILITY_PRIVATE, 100L);
+ Albums.VISIBILITY_PRIVATE, mAccountId);
mAlbumId = PhotoDatabaseUtils.queryAlbumIdFromParentId(db, ALBUM_PARENT_ID);
PhotoDatabaseUtils.insertPhoto(db, 100, 100, System.currentTimeMillis(), mAlbumId,
- MIME_TYPE, 100L);
+ MIME_TYPE, mAccountId);
mPhotoId = PhotoDatabaseUtils.queryPhotoIdFromAlbumId(db, mAlbumId);
PhotoDatabaseUtils.insertMetadata(db, mPhotoId, META_KEY, META_VALUE);
String[] projection = {
@@ -180,6 +185,33 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
cursor.close();
}
+ public void testDeleteAccountCascade() {
+ Uri accountUri = ContentUris.withAppendedId(Accounts.CONTENT_URI, mAccountId);
+ SQLiteDatabase db = mDBHelper.getWritableDatabase();
+ db.beginTransaction();
+ PhotoDatabaseUtils.insertPhoto(db, 100, 100, System.currentTimeMillis(), null,
+ "image/jpeg", mAccountId);
+ PhotoDatabaseUtils.insertPhoto(db, 100, 100, System.currentTimeMillis(), null,
+ "image/jpeg", 0L);
+ PhotoDatabaseUtils.insertAlbum(db, null, "title", Albums.VISIBILITY_PRIVATE, 10630L);
+ db.setTransactionSuccessful();
+ db.endTransaction();
+ // ensure all pictures are there:
+ Cursor cursor = mResolver.query(Photos.CONTENT_URI, null, null, null, null);
+ assertEquals(3, cursor.getCount());
+ cursor.close();
+ // delete the account
+ assertEquals(1, mResolver.delete(accountUri, null, null));
+ // now ensure that all associated photos were deleted
+ cursor = mResolver.query(Photos.CONTENT_URI, null, null, null, null);
+ assertEquals(1, cursor.getCount());
+ cursor.close();
+ // now ensure all associated albums were deleted.
+ cursor = mResolver.query(Albums.CONTENT_URI, null, null, null, null);
+ assertEquals(1, cursor.getCount());
+ cursor.close();
+ }
+
public void testGetType() {
// We don't return types for albums
assertNull(mResolver.getType(Albums.CONTENT_URI));