summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2013-03-06 11:49:10 -0800
committerGeorge Mount <mount@google.com>2013-03-06 15:41:07 -0800
commitf73f725d0b5d771b77041349fbad6e9f02023f87 (patch)
tree829d7f9937efc7952abe605e5acdc7d354144a0e /tests/src
parent1bf3f3238727cc73a156e3eb61a2d2343ac3bdc0 (diff)
downloadandroid_packages_apps_Snap-f73f725d0b5d771b77041349fbad6e9f02023f87.zip
android_packages_apps_Snap-f73f725d0b5d771b77041349fbad6e9f02023f87.tar.gz
android_packages_apps_Snap-f73f725d0b5d771b77041349fbad6e9f02023f87.tar.bz2
Add required fields to PhotoProvider.
Change-Id: I1e830702412d4431ba3b01fe4945a4818385b6cd
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/photos/data/PhotoDatabaseTest.java83
-rw-r--r--tests/src/com/android/photos/data/PhotoDatabaseUtils.java48
-rw-r--r--tests/src/com/android/photos/data/PhotoProviderTest.java15
3 files changed, 88 insertions, 58 deletions
diff --git a/tests/src/com/android/photos/data/PhotoDatabaseTest.java b/tests/src/com/android/photos/data/PhotoDatabaseTest.java
index d8c5e42..70edee2 100644
--- a/tests/src/com/android/photos/data/PhotoDatabaseTest.java
+++ b/tests/src/com/android/photos/data/PhotoDatabaseTest.java
@@ -31,6 +31,8 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
private PhotoDatabase mDBHelper;
private static final String DB_NAME = "dummy.db";
+ private static final long PARENT_ID1 = 100;
+ private static final long PARENT_ID2 = 101;
@Override
protected void setUp() throws Exception {
@@ -68,45 +70,38 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
SQLiteDatabase db = getWriteableDB();
db.beginTransaction();
try {
+ long accountId = 100;
// Test NOT NULL constraint on name
- assertFalse(PhotoDatabaseUtils
- .insertAlbum(db, null, null, Albums.VISIBILITY_PRIVATE, null));
+ assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, null, Albums.VISIBILITY_PRIVATE,
+ accountId));
// test NOT NULL constraint on privacy
- assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "hello", null, null));
+ assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "hello", null, accountId));
- // Normal insert
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, null, "hello", Albums.VISIBILITY_PRIVATE,
- 100L));
-
- // Test server id uniqueness
- assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "world", Albums.VISIBILITY_PRIVATE,
- 100L));
-
- // Different server id allowed
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, null, "world", Albums.VISIBILITY_PRIVATE,
- 101L));
-
- // Allow null server id
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, null, "hello world",
+ // test NOT NULL constraint on account_id
+ assertFalse(PhotoDatabaseUtils.insertAlbum(db, null, "hello",
Albums.VISIBILITY_PRIVATE, null));
- long albumId = PhotoDatabaseUtils.queryAlbumIdFromServerId(db, 100);
+ // Normal insert
+ assertTrue(PhotoDatabaseUtils.insertAlbum(db, PARENT_ID1, "hello",
+ Albums.VISIBILITY_PRIVATE, accountId));
+
+ long albumId = PhotoDatabaseUtils.queryAlbumIdFromParentId(db, PARENT_ID1);
// Assign a valid child
- assertTrue(PhotoDatabaseUtils.insertAlbum(db, albumId, "hello", Albums.VISIBILITY_PRIVATE,
- null));
+ assertTrue(PhotoDatabaseUtils.insertAlbum(db, PARENT_ID2, "hello",
+ Albums.VISIBILITY_PRIVATE, accountId));
- long otherAlbumId = PhotoDatabaseUtils.queryAlbumIdFromServerId(db, 101);
+ long otherAlbumId = PhotoDatabaseUtils.queryAlbumIdFromParentId(db, PARENT_ID2);
assertNotSame(albumId, otherAlbumId);
// This is a valid child of another album.
assertTrue(PhotoDatabaseUtils.insertAlbum(db, otherAlbumId, "hello",
- Albums.VISIBILITY_PRIVATE, null));
+ Albums.VISIBILITY_PRIVATE, accountId));
// This isn't allowed due to uniqueness constraint (parent_id/name)
assertFalse(PhotoDatabaseUtils.insertAlbum(db, otherAlbumId, "hello",
- Albums.VISIBILITY_PRIVATE, null));
+ Albums.VISIBILITY_PRIVATE, accountId));
} finally {
db.endTransaction();
}
@@ -120,26 +115,31 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
int height = 100;
long dateTaken = System.currentTimeMillis();
String mimeType = "test/test";
+ long accountId = 100;
// Test NOT NULL mime-type
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, width, height, dateTaken, null,
- null));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, height, dateTaken, null, null,
+ accountId));
// Test NOT NULL width
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, null, height, dateTaken, null,
- mimeType));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, height, dateTaken, null, mimeType,
+ accountId));
// Test NOT NULL height
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, width, null, dateTaken, null,
- mimeType));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, null, dateTaken, null, mimeType,
+ accountId));
// Test NOT NULL dateTaken
- assertFalse(PhotoDatabaseUtils.insertPhoto(db, null, width, height, null, null,
- mimeType));
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, height, null, null, mimeType,
+ accountId));
+
+ // Test NOT NULL accountId
+ assertFalse(PhotoDatabaseUtils.insertPhoto(db, width, height, dateTaken, null,
+ mimeType, null));
// Test normal insert
- assertTrue(PhotoDatabaseUtils.insertPhoto(db, null, width, height, dateTaken, null,
- mimeType));
+ assertTrue(PhotoDatabaseUtils.insertPhoto(db, width, height, dateTaken, null, mimeType,
+ accountId));
} finally {
db.endTransaction();
}
@@ -150,9 +150,8 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
db.beginTransaction();
try {
final String mimeType = "test/test";
- long photoServerId = 100;
- PhotoDatabaseUtils.insertPhoto(db, photoServerId, 100, 100, 100L, null, mimeType);
- long photoId = PhotoDatabaseUtils.queryPhotoIdFromServerId(db, photoServerId);
+ PhotoDatabaseUtils.insertPhoto(db, 100, 100, 100L, PARENT_ID1, mimeType, 100L);
+ long photoId = PhotoDatabaseUtils.queryPhotoIdFromAlbumId(db, PARENT_ID1);
// Test NOT NULL PHOTO_ID constraint.
assertFalse(PhotoDatabaseUtils.insertMetadata(db, null, "foo", "bar"));
@@ -167,6 +166,18 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
}
}
+ public void testAccountsConstraints() {
+ SQLiteDatabase db = getWriteableDB();
+ db.beginTransaction();
+ try {
+ assertFalse(PhotoDatabaseUtils.insertAccount(db, null));
+ assertTrue(PhotoDatabaseUtils.insertAccount(db, "hello"));
+ assertTrue(PhotoDatabaseUtils.insertAccount(db, "hello"));
+ } finally {
+ db.endTransaction();
+ }
+ }
+
private SQLiteDatabase getReadableDB() {
return mDBHelper.getReadableDatabase();
}
diff --git a/tests/src/com/android/photos/data/PhotoDatabaseUtils.java b/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
index 73a6c78..1840eb1 100644
--- a/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
+++ b/tests/src/com/android/photos/data/PhotoDatabaseUtils.java
@@ -19,6 +19,7 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+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;
@@ -28,10 +29,15 @@ import junit.framework.AssertionFailedError;
public class PhotoDatabaseUtils {
public static String[] PROJECTION_ALBUMS = {
Albums._ID,
+ Albums.ACCOUNT_ID,
Albums.PARENT_ID,
- Albums.VISIBILITY,
Albums.NAME,
- Albums.SERVER_ID,
+ Albums.VISIBILITY,
+ Albums.LOCATION_STRING,
+ Albums.TITLE,
+ Albums.SUMMARY,
+ Albums.DATE_PUBLISHED,
+ Albums.DATE_MODIFIED,
};
public static String[] PROJECTION_METADATA = {
@@ -42,23 +48,31 @@ public class PhotoDatabaseUtils {
public static String[] PROJECTION_PHOTOS = {
Photos._ID,
- Photos.SERVER_ID,
+ Photos.ACCOUNT_ID,
Photos.WIDTH,
Photos.HEIGHT,
Photos.DATE_TAKEN,
Photos.ALBUM_ID,
Photos.MIME_TYPE,
+ Photos.TITLE,
+ Photos.DATE_MODIFIED,
+ Photos.ROTATION,
+ };
+
+ public static String[] PROJECTION_ACCOUNTS = {
+ Accounts._ID,
+ Accounts.ACCOUNT_NAME,
};
- private static String SELECTION_ALBUM_SERVER_ID = Albums.SERVER_ID + " = ?";
- private static String SELECTION_PHOTO_SERVER_ID = Photos.SERVER_ID + " = ?";
+ private static String SELECTION_ALBUM_PARENT_ID = Albums.PARENT_ID + " = ?";
+ private static String SELECTION_PHOTO_ALBUM_ID = Photos.ALBUM_ID + " = ?";
- public static long queryAlbumIdFromServerId(SQLiteDatabase db, long serverId) {
- return queryId(db, Albums.TABLE, PROJECTION_ALBUMS, SELECTION_ALBUM_SERVER_ID, serverId);
+ public static long queryAlbumIdFromParentId(SQLiteDatabase db, long parentId) {
+ return queryId(db, Albums.TABLE, PROJECTION_ALBUMS, SELECTION_ALBUM_PARENT_ID, parentId);
}
- public static long queryPhotoIdFromServerId(SQLiteDatabase db, long serverId) {
- return queryId(db, Photos.TABLE, PROJECTION_PHOTOS, SELECTION_PHOTO_SERVER_ID, serverId);
+ public static long queryPhotoIdFromAlbumId(SQLiteDatabase db, long albumId) {
+ return queryId(db, Photos.TABLE, PROJECTION_PHOTOS, SELECTION_PHOTO_ALBUM_ID, albumId);
}
public static long queryId(SQLiteDatabase db, String table, String[] projection,
@@ -79,25 +93,25 @@ public class PhotoDatabaseUtils {
}
}
- public static boolean insertPhoto(SQLiteDatabase db, Long serverId, Integer width,
- Integer height, Long dateTaken, Long albumId, String mimeType) {
+ public static boolean insertPhoto(SQLiteDatabase db, Integer width, Integer height,
+ Long dateTaken, Long albumId, String mimeType, Long accountId) {
ContentValues values = new ContentValues();
- values.put(Photos.SERVER_ID, serverId);
values.put(Photos.WIDTH, width);
values.put(Photos.HEIGHT, height);
values.put(Photos.DATE_TAKEN, dateTaken);
values.put(Photos.ALBUM_ID, albumId);
values.put(Photos.MIME_TYPE, mimeType);
+ values.put(Photos.ACCOUNT_ID, accountId);
return db.insert(Photos.TABLE, null, values) != -1;
}
public static boolean insertAlbum(SQLiteDatabase db, Long parentId, String name,
- Integer privacy, Long serverId) {
+ Integer privacy, Long accountId) {
ContentValues values = new ContentValues();
values.put(Albums.PARENT_ID, parentId);
values.put(Albums.NAME, name);
values.put(Albums.VISIBILITY, privacy);
- values.put(Albums.SERVER_ID, serverId);
+ values.put(Albums.ACCOUNT_ID, accountId);
return db.insert(Albums.TABLE, null, values) != -1;
}
@@ -108,4 +122,10 @@ public class PhotoDatabaseUtils {
values.put(Metadata.VALUE, value);
return db.insert(Metadata.TABLE, null, values) != -1;
}
+
+ public static boolean insertAccount(SQLiteDatabase db, String name) {
+ ContentValues values = new ContentValues();
+ values.put(Accounts.ACCOUNT_NAME, name);
+ return db.insert(Accounts.TABLE, null, values) != -1;
+ }
}
diff --git a/tests/src/com/android/photos/data/PhotoProviderTest.java b/tests/src/com/android/photos/data/PhotoProviderTest.java
index 525abec..2e644a3 100644
--- a/tests/src/com/android/photos/data/PhotoProviderTest.java
+++ b/tests/src/com/android/photos/data/PhotoProviderTest.java
@@ -35,8 +35,7 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
private static final String MIME_TYPE = "test/test";
private static final String ALBUM_NAME = "My Album";
- private static final long ALBUM_SERVER_ID = 100;
- private static final long PHOTO_SERVER_ID = 50;
+ private static final long ALBUM_PARENT_ID = 100;
private static final String META_KEY = "mykey";
private static final String META_VALUE = "myvalue";
@@ -70,12 +69,12 @@ public class PhotoProviderTest extends ProviderTestCase2<PhotoProvider> {
SQLiteDatabase db = mDBHelper.getWritableDatabase();
db.beginTransaction();
try {
- PhotoDatabaseUtils.insertAlbum(db, null, ALBUM_NAME, Albums.VISIBILITY_PRIVATE,
- ALBUM_SERVER_ID);
- mAlbumId = PhotoDatabaseUtils.queryAlbumIdFromServerId(db, ALBUM_SERVER_ID);
- PhotoDatabaseUtils.insertPhoto(db, PHOTO_SERVER_ID, 100, 100,
- System.currentTimeMillis(), mAlbumId, MIME_TYPE);
- mPhotoId = PhotoDatabaseUtils.queryPhotoIdFromServerId(db, PHOTO_SERVER_ID);
+ PhotoDatabaseUtils.insertAlbum(db, ALBUM_PARENT_ID, ALBUM_NAME,
+ Albums.VISIBILITY_PRIVATE, 100L);
+ mAlbumId = PhotoDatabaseUtils.queryAlbumIdFromParentId(db, ALBUM_PARENT_ID);
+ PhotoDatabaseUtils.insertPhoto(db, 100, 100, System.currentTimeMillis(), mAlbumId,
+ MIME_TYPE, 100L);
+ mPhotoId = PhotoDatabaseUtils.queryPhotoIdFromAlbumId(db, mAlbumId);
PhotoDatabaseUtils.insertMetadata(db, mPhotoId, META_KEY, META_VALUE);
String[] projection = {
BaseColumns._ID,