summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2013-03-15 18:16:08 (GMT)
committerGeorge Mount <mount@google.com>2013-03-15 18:16:50 (GMT)
commit4fc93d01548b8b67cb4cdd4a9e540ea0e004df49 (patch)
tree8ea4fbdf94c483b5e0cc4ac1ec7423cb8b4fd3bd /tests
parentb7cc5e99563bc695ec871f897914eb2cb797ad53 (diff)
downloadandroid_packages_apps_Snap-4fc93d01548b8b67cb4cdd4a9e540ea0e004df49.zip
android_packages_apps_Snap-4fc93d01548b8b67cb4cdd4a9e540ea0e004df49.tar.gz
android_packages_apps_Snap-4fc93d01548b8b67cb4cdd4a9e540ea0e004df49.tar.bz2
Delete and recreate database on upgrade.
Change-Id: I0125697dd673568ddfee7be8d7d0d693018b61d5
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/photos/data/PhotoDatabaseTest.java38
1 files changed, 33 insertions, 5 deletions
diff --git a/tests/src/com/android/photos/data/PhotoDatabaseTest.java b/tests/src/com/android/photos/data/PhotoDatabaseTest.java
index 70edee2..e7c1689 100644
--- a/tests/src/com/android/photos/data/PhotoDatabaseTest.java
+++ b/tests/src/com/android/photos/data/PhotoDatabaseTest.java
@@ -17,9 +17,11 @@ package com.android.photos.data;
import android.content.Context;
import android.database.Cursor;
+import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.test.InstrumentationTestCase;
+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;
@@ -67,7 +69,7 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
}
public void testAlbumsConstraints() {
- SQLiteDatabase db = getWriteableDB();
+ SQLiteDatabase db = getWritableDB();
db.beginTransaction();
try {
long accountId = 100;
@@ -108,7 +110,7 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
}
public void testPhotosConstraints() {
- SQLiteDatabase db = getWriteableDB();
+ SQLiteDatabase db = getWritableDB();
db.beginTransaction();
try {
int width = 100;
@@ -146,7 +148,7 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
}
public void testMetadataConstraints() {
- SQLiteDatabase db = getWriteableDB();
+ SQLiteDatabase db = getWritableDB();
db.beginTransaction();
try {
final String mimeType = "test/test";
@@ -167,7 +169,7 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
}
public void testAccountsConstraints() {
- SQLiteDatabase db = getWriteableDB();
+ SQLiteDatabase db = getWritableDB();
db.beginTransaction();
try {
assertFalse(PhotoDatabaseUtils.insertAccount(db, null));
@@ -178,11 +180,37 @@ public class PhotoDatabaseTest extends InstrumentationTestCase {
}
}
+ public void testUpgrade() {
+ SQLiteDatabase db = getWritableDB();
+ db.beginTransaction();
+ try {
+ assertTrue(PhotoDatabaseUtils.insertAccount(db, "Hello"));
+ assertTrue(PhotoDatabaseUtils.insertAlbum(db, PARENT_ID1, "hello",
+ Albums.VISIBILITY_PRIVATE, 100L));
+ final String mimeType = "test/test";
+ assertTrue(PhotoDatabaseUtils.insertPhoto(db, 100, 100, 100L, PARENT_ID1, mimeType,
+ 100L));
+ // Normal insert.
+ assertTrue(PhotoDatabaseUtils.insertMetadata(db, 100L, "foo", "bar"));
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ mDBHelper.close();
+ Context context = getInstrumentation().getTargetContext();
+ mDBHelper = new PhotoDatabase(context, DB_NAME, PhotoDatabase.DB_VERSION + 1);
+ db = getReadableDB();
+ assertEquals(0, DatabaseUtils.queryNumEntries(db, Accounts.TABLE));
+ assertEquals(0, DatabaseUtils.queryNumEntries(db, Photos.TABLE));
+ assertEquals(0, DatabaseUtils.queryNumEntries(db, Albums.TABLE));
+ assertEquals(0, DatabaseUtils.queryNumEntries(db, Metadata.TABLE));
+ }
+
private SQLiteDatabase getReadableDB() {
return mDBHelper.getReadableDatabase();
}
- private SQLiteDatabase getWriteableDB() {
+ private SQLiteDatabase getWritableDB() {
return mDBHelper.getWritableDatabase();
}