summaryrefslogtreecommitdiffstats
path: root/core/tests/coretests/src/android/database/CursorWindowTest.java
diff options
context:
space:
mode:
authorNeal Nguyen <tommyn@google.com>2010-01-13 10:42:43 -0800
committerNeal Nguyen <tommyn@google.com>2010-01-29 13:35:51 -0800
commit1a44d5dcabc18cd5ef111f732ccff91683a1a093 (patch)
treee370267a65ba54a43e3026ff9b282cc4e3dad869 /core/tests/coretests/src/android/database/CursorWindowTest.java
parent35ec7863e18ce3d242010b76a50df5a8c285325b (diff)
downloadframeworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.zip
frameworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.tar.gz
frameworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.tar.bz2
Phase 2 of test cleanup: moving test files from AndroidTests closer to their sources.
Most of these are file moves; a couple notable exceptions are the changes due to the move, and fixing up test code: - database/DatabaseCursorTest.java - database/DatabaseStatementTest.java - net/UriTest.java
Diffstat (limited to 'core/tests/coretests/src/android/database/CursorWindowTest.java')
-rw-r--r--core/tests/coretests/src/android/database/CursorWindowTest.java173
1 files changed, 173 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/database/CursorWindowTest.java b/core/tests/coretests/src/android/database/CursorWindowTest.java
new file mode 100644
index 0000000..07e75cb
--- /dev/null
+++ b/core/tests/coretests/src/android/database/CursorWindowTest.java
@@ -0,0 +1,173 @@
+/*
+ * 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.database;
+
+import android.database.AbstractCursor;
+import android.test.suitebuilder.annotation.SmallTest;
+import com.android.common.ArrayListCursor;
+import android.database.CursorWindow;
+import android.test.PerformanceTestCase;
+
+import com.google.android.collect.Lists;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+public class CursorWindowTest extends TestCase implements PerformanceTestCase {
+ public boolean isPerformanceOnly() {
+ return false;
+ }
+
+ // These test can only be run once.
+ public int startPerformance(Intermediates intermediates) {
+ return 1;
+ }
+
+ @SmallTest
+ public void testWriteCursorToWindow() throws Exception {
+ // create cursor
+ String[] colNames = new String[]{"name", "number", "profit"};
+ int colsize = colNames.length;
+ ArrayList<ArrayList> list = createTestList(10, colsize);
+ AbstractCursor cursor = new ArrayListCursor(colNames, (ArrayList<ArrayList>) list);
+
+ // fill window
+ CursorWindow window = new CursorWindow(false);
+ cursor.fillWindow(0, window);
+
+ // read from cursor window
+ for (int i = 0; i < list.size(); i++) {
+ ArrayList<Integer> col = list.get(i);
+ for (int j = 0; j < colsize; j++) {
+ String s = window.getString(i, j);
+ int r2 = col.get(j);
+ int r1 = Integer.parseInt(s);
+ assertEquals(r2, r1);
+ }
+ }
+
+ // test cursor window handle startpos != 0
+ window.clear();
+ cursor.fillWindow(1, window);
+ // read from cursor from window
+ for (int i = 1; i < list.size(); i++) {
+ ArrayList<Integer> col = list.get(i);
+ for (int j = 0; j < colsize; j++) {
+ String s = window.getString(i, j);
+ int r2 = col.get(j);
+ int r1 = Integer.parseInt(s);
+ assertEquals(r2, r1);
+ }
+ }
+
+ // Clear the window and make sure it's empty
+ window.clear();
+ assertEquals(0, window.getNumRows());
+ }
+
+ @SmallTest
+ public void testValuesLocalWindow() {
+ doTestValues(new CursorWindow(true));
+ }
+
+ @SmallTest
+ public void testValuesRemoteWindow() {
+ doTestValues(new CursorWindow(false));
+ }
+
+ private void doTestValues(CursorWindow window) {
+ assertTrue(window.setNumColumns(7));
+ assertTrue(window.allocRow());
+ double db1 = 1.26;
+ assertTrue(window.putDouble(db1, 0, 0));
+ double db2 = window.getDouble(0, 0);
+ assertEquals(db1, db2);
+
+ long int1 = Long.MAX_VALUE;
+ assertTrue(window.putLong(int1, 0, 1));
+ long int2 = window.getLong(0, 1);
+ assertEquals(int1, int2);
+
+ assertTrue(window.putString("1198032740000", 0, 3));
+ assertEquals("1198032740000", window.getString(0, 3));
+ assertEquals(1198032740000L, window.getLong(0, 3));
+
+ assertTrue(window.putString(Long.toString(1198032740000L), 0, 3));
+ assertEquals(Long.toString(1198032740000L), window.getString(0, 3));
+ assertEquals(1198032740000L, window.getLong(0, 3));
+
+ assertTrue(window.putString(Double.toString(42.0), 0, 4));
+ assertEquals(Double.toString(42.0), window.getString(0, 4));
+ assertEquals(42.0, window.getDouble(0, 4));
+
+ // put blob
+ byte[] blob = new byte[1000];
+ byte value = 99;
+ Arrays.fill(blob, value);
+ assertTrue(window.putBlob(blob, 0, 6));
+ assertTrue(Arrays.equals(blob, window.getBlob(0, 6)));
+ }
+
+ @SmallTest
+ public void testNull() {
+ CursorWindow window = getOneByOneWindow();
+
+ // Put in a null value and read it back as various types
+ assertTrue(window.putNull(0, 0));
+ assertNull(window.getString(0, 0));
+ assertEquals(0, window.getLong(0, 0));
+ assertEquals(0.0, window.getDouble(0, 0));
+ assertNull(window.getBlob(0, 0));
+ }
+
+ @SmallTest
+ public void testEmptyString() {
+ CursorWindow window = getOneByOneWindow();
+
+ // put size 0 string and read it back as various types
+ assertTrue(window.putString("", 0, 0));
+ assertEquals("", window.getString(0, 0));
+ assertEquals(0, window.getLong(0, 0));
+ assertEquals(0.0, window.getDouble(0, 0));
+ }
+
+ private CursorWindow getOneByOneWindow() {
+ CursorWindow window = new CursorWindow(false);
+ assertTrue(window.setNumColumns(1));
+ assertTrue(window.allocRow());
+ return window;
+ }
+
+ private static ArrayList<ArrayList> createTestList(int rows, int cols) {
+ ArrayList<ArrayList> list = Lists.newArrayList();
+ Random generator = new Random();
+
+ for (int i = 0; i < rows; i++) {
+ ArrayList<Integer> col = Lists.newArrayList();
+ list.add(col);
+ for (int j = 0; j < cols; j++) {
+ // generate random number
+ Integer r = generator.nextInt();
+ col.add(r);
+ }
+ }
+ return list;
+ }
+}