summaryrefslogtreecommitdiffstats
path: root/test-runner/src/android/test/DatabaseTestUtils.java
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-02-18 17:56:11 -0800
committerBrett Chabot <brettchabot@android.com>2010-02-19 09:58:29 -0800
commit12093976a4842a795491cfd2b1d3b71e18503f2d (patch)
tree04d06cdfe57151ca3856eab6c405f260583cf1fa /test-runner/src/android/test/DatabaseTestUtils.java
parent5df3a9017eaac2aef2ad360ce8f298b2d60b5536 (diff)
downloadframeworks_base-12093976a4842a795491cfd2b1d3b71e18503f2d.zip
frameworks_base-12093976a4842a795491cfd2b1d3b71e18503f2d.tar.gz
frameworks_base-12093976a4842a795491cfd2b1d3b71e18503f2d.tar.bz2
Move framework test-runner unit tests to be closer to their source.
Move the test-runner source into a separate src folder to accommodate the test move.
Diffstat (limited to 'test-runner/src/android/test/DatabaseTestUtils.java')
-rw-r--r--test-runner/src/android/test/DatabaseTestUtils.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/test-runner/src/android/test/DatabaseTestUtils.java b/test-runner/src/android/test/DatabaseTestUtils.java
new file mode 100644
index 0000000..23e0aba
--- /dev/null
+++ b/test-runner/src/android/test/DatabaseTestUtils.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test;
+
+import com.google.android.collect.Sets;
+
+import android.database.sqlite.SQLiteDatabase;
+import android.database.Cursor;
+
+import java.util.Set;
+
+/**
+ * A collection of utilities for writing unit tests for database code.
+ * @hide pending API council approval
+ */
+public class DatabaseTestUtils {
+
+ /**
+ * Compares the schema of two databases and asserts that they are equal.
+ * @param expectedDb the db that is known to have the correct schema
+ * @param db the db whose schema should be checked
+ */
+ public static void assertSchemaEquals(SQLiteDatabase expectedDb, SQLiteDatabase db) {
+ Set<String> expectedSchema = getSchemaSet(expectedDb);
+ Set<String> schema = getSchemaSet(db);
+ MoreAsserts.assertEquals(expectedSchema, schema);
+ }
+
+ private static Set<String> getSchemaSet(SQLiteDatabase db) {
+ Set<String> schemaSet = Sets.newHashSet();
+
+ Cursor entityCursor = db.rawQuery("SELECT sql FROM sqlite_master", null);
+ try {
+ while (entityCursor.moveToNext()) {
+ String sql = entityCursor.getString(0);
+ schemaSet.add(sql);
+ }
+ } finally {
+ entityCursor.close();
+ }
+ return schemaSet;
+ }
+}