Merge "Clean Up Properly in Database Tests" into eclair
diff --git a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
index bc404fe..14462a0 100644
--- a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
+++ b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
@@ -67,6 +67,15 @@
         mTestAbstractCursor = new TestAbstractCursor(COLUMN_NAMES, list);
     }
 
+    @Override
+    protected void tearDown() throws Exception {
+        mDatabase.close();
+        if (mDatabaseFile.exists()) {
+            mDatabaseFile.delete();
+        }
+        super.tearDown();
+    }
+
     @TestTargetNew(
         level = TestLevel.COMPLETE,
         method = "AbstractCursor",
diff --git a/tests/tests/database/src/android/database/cts/CursorWrapperTest.java b/tests/tests/database/src/android/database/cts/CursorWrapperTest.java
index c32cd89..507b2a3 100644
--- a/tests/tests/database/src/android/database/cts/CursorWrapperTest.java
+++ b/tests/tests/database/src/android/database/cts/CursorWrapperTest.java
@@ -19,6 +19,8 @@
 import java.io.File;
 import java.util.Arrays;
 
+import junit.framework.TestCase;
+
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.IContentProvider;
@@ -39,7 +41,7 @@
 import dalvik.annotation.TestTargetClass;
 
 @TestTargetClass(android.database.CursorWrapper.class)
-public class CursorWrapperTest extends DatabaseCursorTest {
+public class CursorWrapperTest extends TestCase {
 
     private static final String FIRST_NUMBER = "123";
     private static final String SECOND_NUMBER = "5555";
@@ -61,7 +63,6 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        setupTestType(TYPE_CURSORWRAPPER);
         setupDatabase();
     }
 
diff --git a/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java b/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java
index 0791bcd..bc351f5 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java
@@ -454,17 +454,26 @@
     })
     @ToBeFixed(bug = "1676383", explanation = "setPageSize does not work as javadoc declares.")
     public void testAccessPageSize() {
-        mDatabaseFile = new File(mDatabaseDir, "database.db");
-        if (mDatabaseFile.exists()) {
-            mDatabaseFile.delete();
+        File databaseFile = new File(mDatabaseDir, "database.db");
+        if (databaseFile.exists()) {
+            databaseFile.delete();
         }
-        mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
+        SQLiteDatabase database = null;
+        try {
+            database = SQLiteDatabase.openOrCreateDatabase(databaseFile.getPath(), null);
 
-        long initialValue = mDatabase.getPageSize();
-        // check that this does not throw an exception
-        // setting a different page size may not be supported after the DB has been created
-        mDatabase.setPageSize(initialValue);
-        assertEquals(initialValue, mDatabase.getPageSize());
+            long initialValue = database.getPageSize();
+            // check that this does not throw an exception
+            // setting a different page size may not be supported after the DB has been created
+            database.setPageSize(initialValue);
+            assertEquals(initialValue, database.getPageSize());
+
+        } finally {
+            if (database != null) {
+                database.close();
+                databaseFile.delete();
+            }
+        }
     }
 
     @TestTargetNew(
@@ -827,9 +836,16 @@
     public void testIsReadOnly() {
         assertFalse(mDatabase.isReadOnly());
 
-        mDatabase = SQLiteDatabase.openDatabase(mDatabaseFilePath, null,
-                SQLiteDatabase.OPEN_READONLY);
-        assertTrue(mDatabase.isReadOnly());
+        SQLiteDatabase database = null;
+        try {
+            database = SQLiteDatabase.openDatabase(mDatabaseFilePath, null,
+                    SQLiteDatabase.OPEN_READONLY);
+            assertTrue(database.isReadOnly());
+        } finally {
+            if (database != null) {
+                database.close();
+            }
+        }
     }
 
     @TestTargetNew(