Skip to content

Commit 5a05c23

Browse files
author
Jeff Brown
committed
Clean up database tests a little bit.
Change-Id: Ib05c699bf59187cb51627b5f352c2a15ad2c28bb
1 parent 38e9075 commit 5a05c23

File tree

10 files changed

+47
-74
lines changed

10 files changed

+47
-74
lines changed

core/java/android/database/CursorWindow.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ private static native void nativeCopyStringToBuffer(int windowPtr, int row, int
9898
*/
9999
public CursorWindow(String name) {
100100
mStartPos = 0;
101-
mName = name;
102-
mWindowPtr = nativeCreate(name, sCursorWindowSize);
101+
mName = name != null && name.length() != 0 ? name : "<unnamed>";
102+
mWindowPtr = nativeCreate(mName, sCursorWindowSize);
103103
if (mWindowPtr == 0) {
104104
throw new CursorWindowAllocationException("Cursor window allocation of " +
105105
(sCursorWindowSize / 1024) + " kb failed. " + printStats());
@@ -161,7 +161,7 @@ private void dispose() {
161161
}
162162

163163
/**
164-
* Gets the name of this cursor window.
164+
* Gets the name of this cursor window, never null.
165165
* @hide
166166
*/
167167
public String getName() {

core/jni/android_database_CursorWindow.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ static void throwUnknownTypeException(JNIEnv * env, jint type) {
5959

6060
static jint nativeCreate(JNIEnv* env, jclass clazz, jstring nameObj, jint cursorWindowSize) {
6161
String8 name;
62-
if (nameObj) {
63-
const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
64-
name.setTo(nameStr);
65-
env->ReleaseStringUTFChars(nameObj, nameStr);
66-
}
67-
if (name.size() == 0) {
68-
name.setTo("<unnamed>");
69-
}
62+
const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
63+
name.setTo(nameStr);
64+
env->ReleaseStringUTFChars(nameObj, nameStr);
7065

7166
CursorWindow* window;
7267
status_t status = CursorWindow::create(name, cursorWindowSize, &window);

core/tests/coretests/src/android/database/CursorWindowTest.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,45 @@ public int startPerformance(Intermediates intermediates) {
3535
}
3636

3737
@SmallTest
38-
public void testValuesLocalWindow() {
39-
doTestValues(new CursorWindow(true));
38+
public void testConstructor_WithName() {
39+
CursorWindow window = new CursorWindow("MyWindow");
40+
assertEquals("MyWindow", window.getName());
41+
assertEquals(0, window.getStartPosition());
42+
window.close();
4043
}
41-
44+
45+
@SmallTest
46+
public void testConstructorWithEmptyName() {
47+
CursorWindow window = new CursorWindow("");
48+
assertEquals("<unnamed>", window.getName());
49+
assertEquals(0, window.getStartPosition());
50+
window.close();
51+
}
52+
4253
@SmallTest
43-
public void testValuesRemoteWindow() {
44-
doTestValues(new CursorWindow(false));
54+
public void testConstructorWithNullName() {
55+
CursorWindow window = new CursorWindow(null);
56+
assertEquals("<unnamed>", window.getName());
57+
assertEquals(0, window.getStartPosition());
58+
window.close();
4559
}
46-
60+
61+
@SmallTest
62+
public void testDeprecatedConstructor() {
63+
@SuppressWarnings("deprecation")
64+
CursorWindow window = new CursorWindow(true /*this argument is ignored*/);
65+
assertEquals("<unnamed>", window.getName());
66+
assertEquals(0, window.getStartPosition());
67+
window.close();
68+
}
69+
70+
@SmallTest
71+
public void testValues() {
72+
CursorWindow window = new CursorWindow("MyWindow");
73+
doTestValues(window);
74+
window.close();
75+
}
76+
4777
private void doTestValues(CursorWindow window) {
4878
assertTrue(window.setNumColumns(7));
4979
assertTrue(window.allocRow());

core/tests/coretests/src/android/database/DatabaseCursorTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package android.database;
1818

19-
import dalvik.annotation.BrokenTest;
2019
import android.content.ContentValues;
2120
import android.content.Context;
2221
import android.database.Cursor;
@@ -27,13 +26,11 @@
2726
import android.database.sqlite.SQLiteCursorDriver;
2827
import android.database.sqlite.SQLiteDatabase;
2928
import android.database.sqlite.SQLiteQuery;
30-
import android.database.sqlite.SQLiteStatement;
3129
import android.os.Looper;
3230
import android.test.AndroidTestCase;
3331
import android.test.PerformanceTestCase;
3432
import android.test.suitebuilder.annotation.LargeTest;
3533
import android.test.suitebuilder.annotation.MediumTest;
36-
import android.test.suitebuilder.annotation.Suppress;
3734
import android.util.Log;
3835

3936
import java.io.File;

core/tests/coretests/src/android/database/DatabaseErrorHandlerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import android.database.sqlite.SQLiteDiskIOException;
2222
import android.database.sqlite.SQLiteException;
2323
import android.test.AndroidTestCase;
24-
import android.test.suitebuilder.annotation.Suppress;
2524
import android.util.Log;
2625

2726
import java.io.BufferedWriter;

core/tests/coretests/src/android/database/DatabaseGeneralTest.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -410,40 +410,6 @@ public void testSchemaChange3() throws Exception {
410410
}
411411
}
412412

413-
private class ChangeObserver extends ContentObserver {
414-
private int mCursorNotificationCount = 0;
415-
private int mNotificationCount = 0;
416-
417-
public int getCursorNotificationCount() {
418-
return mCursorNotificationCount;
419-
}
420-
421-
public int getNotificationCount() {
422-
return mNotificationCount;
423-
}
424-
425-
public ChangeObserver(boolean cursor) {
426-
super(new Handler());
427-
mCursor = cursor;
428-
}
429-
430-
@Override
431-
public boolean deliverSelfNotifications() {
432-
return true;
433-
}
434-
435-
@Override
436-
public void onChange(boolean selfChange) {
437-
if (mCursor) {
438-
mCursorNotificationCount++;
439-
} else {
440-
mNotificationCount++;
441-
}
442-
}
443-
444-
boolean mCursor;
445-
}
446-
447413
@MediumTest
448414
public void testSelectionArgs() throws Exception {
449415
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");

core/tests/coretests/src/android/database/DatabaseLockTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@
1616

1717
package android.database;
1818

19-
import android.app.Activity;
20-
import android.content.Context;
2119
import android.database.sqlite.SQLiteDatabase;
22-
import android.test.suitebuilder.annotation.LargeTest;
2320
import android.test.suitebuilder.annotation.Suppress;
2421
import android.util.Log;
2522
import java.io.File;
2623
import java.util.concurrent.atomic.AtomicInteger;
2724
import android.test.AndroidTestCase;
2825

29-
import junit.framework.TestCase;
30-
3126
/*
3227
* This is a series of unit tests for database locks.
3328
*
@@ -104,9 +99,9 @@ private class DatabaseFairnessThread extends Thread {
10499
public void run() {
105100
for (int i = 0; i < NUM_ITERATIONS; i++) {
106101
mDatabase.beginTransaction();
107-
int val = mCounter.incrementAndGet();
102+
mCounter.incrementAndGet();
108103
try {
109-
Thread.currentThread().sleep(SLEEP_TIME);
104+
Thread.sleep(SLEEP_TIME);
110105
} catch (InterruptedException e) {
111106
// ignore
112107
}
@@ -124,7 +119,6 @@ public void run() {
124119
@Suppress
125120
public void testLockLatency() {
126121
startDatabaseLatencyThread();
127-
int previous = 0;
128122
long sumTime = 0;
129123
long maxTime = 0;
130124
for (int i = 0; i < NUM_ITERATIONS; i++) {
@@ -137,7 +131,7 @@ public void testLockLatency() {
137131
}
138132
sumTime += elapsedTime;
139133
try {
140-
Thread.currentThread().sleep(SLEEP_TIME);
134+
Thread.sleep(SLEEP_TIME);
141135
} catch (InterruptedException e) {
142136
// ignore
143137
}
@@ -164,7 +158,7 @@ public void run() {
164158
{
165159
mDatabase.beginTransaction();
166160
try {
167-
Thread.currentThread().sleep(SLEEP_TIME);
161+
Thread.sleep(SLEEP_TIME);
168162
} catch (InterruptedException e) {
169163
// ignore
170164
}

core/tests/coretests/src/android/database/DatabasePerformanceTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*
3636
*/
3737

38+
@SuppressWarnings("deprecation")
3839
public class DatabasePerformanceTests {
3940

4041
public static String[] children() {

core/tests/coretests/src/android/database/DatabaseStatementTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import android.test.AndroidTestCase;
2626
import android.test.PerformanceTestCase;
2727
import android.test.suitebuilder.annotation.MediumTest;
28-
import android.test.suitebuilder.annotation.SmallTest;
29-
import junit.framework.TestCase;
3028

3129
import java.io.File;
3230

core/tests/coretests/src/android/database/NewDatabasePerformanceTests.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import android.database.sqlite.SQLiteDatabase;
2121
import android.test.PerformanceTestCase;
2222

23-
import junit.framework.Assert;
2423
import junit.framework.TestCase;
2524

2625
import java.io.File;
@@ -493,8 +492,6 @@ public static class SelectInteger100 extends PerformanceBase {
493492
private static final int SIZE = 1 * kMultiplier;
494493
private static final String[] COLUMNS = {"b"};
495494

496-
private String[] where = new String[SIZE];
497-
498495
@Override
499496
public void setUp() {
500497
super.setUp();
@@ -526,8 +523,6 @@ public static class SelectString100 extends PerformanceBase {
526523
private static final int SIZE = 1 * kMultiplier;
527524
private static final String[] COLUMNS = {"c"};
528525

529-
private String[] where = new String[SIZE];
530-
531526
@Override
532527
public void setUp() {
533528
super.setUp();
@@ -661,7 +656,6 @@ public void testRun() {
661656

662657
public static class DeleteIndexed1000 extends PerformanceBase {
663658
private static final int SIZE = 10 * kMultiplier;
664-
private static final String[] COLUMNS = {"c"};
665659

666660
@Override
667661
public void setUp() {
@@ -693,7 +687,6 @@ public void testRun() {
693687

694688
public static class Delete1000 extends PerformanceBase {
695689
private static final int SIZE = 10 * kMultiplier;
696-
private static final String[] COLUMNS = {"c"};
697690

698691
@Override
699692
public void setUp() {

0 commit comments

Comments
 (0)