AI 148171: CTS: Fix failing test cases in Android test plan
Automated import of CL 148171
diff --git a/tests/tests/content/src/android/content/pm/cts/ApplicationInfo_DisplayNameComparatorTest.java b/tests/tests/content/src/android/content/pm/cts/ApplicationInfo_DisplayNameComparatorTest.java
index 2f4d1b4..0f58193 100644
--- a/tests/tests/content/src/android/content/pm/cts/ApplicationInfo_DisplayNameComparatorTest.java
+++ b/tests/tests/content/src/android/content/pm/cts/ApplicationInfo_DisplayNameComparatorTest.java
@@ -21,7 +21,6 @@
import android.content.pm.ApplicationInfo.DisplayNameComparator;
import android.content.pm.PackageManager.NameNotFoundException;
import android.test.AndroidTestCase;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -32,6 +31,7 @@
*/
@TestTargetClass(DisplayNameComparator.class)
public class ApplicationInfo_DisplayNameComparatorTest extends AndroidTestCase {
+ private static final String PACKAGE_NAME = "com.android.cts.stub";
DisplayNameComparator mDisplayNameComparator;
@Override
@@ -60,38 +60,30 @@
args = {android.content.pm.ApplicationInfo.class, android.content.pm.ApplicationInfo.class}
)
@ToBeFixed(bug = "1417734", explanation = "NPE is not expected.")
- public void testCompare() {
+ public void testCompare() throws NameNotFoundException {
PackageManager pm = getContext().getPackageManager();
mDisplayNameComparator = new ApplicationInfo.DisplayNameComparator(pm);
ApplicationInfo info1 = new ApplicationInfo();
ApplicationInfo info2 = new ApplicationInfo();
- info1.packageName = "com.android";
- info2.packageName = "com.android";
+ info1.packageName = PACKAGE_NAME;
+ info2.packageName = PACKAGE_NAME;
assertEquals(0, mDisplayNameComparator.compare(info1, info2));
- try {
- info1 = mContext.getPackageManager().getApplicationInfo("com.android", 0);
- } catch (NameNotFoundException e) {
- fail("getApplicationInfo should not throw NameNotFoundException here.");
- }
- info2.packageName = "com.android.2";
+ info1 = mContext.getPackageManager().getApplicationInfo(PACKAGE_NAME, 0);
+ info2.packageName = PACKAGE_NAME + ".2";
assertTrue((mDisplayNameComparator.compare(info1, info2) < 0));
info1 = new ApplicationInfo();
- info1.packageName = "com.android.1";
- try {
- info2 =
- mContext.getPackageManager().getApplicationInfo("com.android", 0);
- } catch (NameNotFoundException e) {
- fail("getApplicationInfo should not throw NameNotFoundException here.");
- }
+ info1.packageName = PACKAGE_NAME + ".1";
+ info2 = mContext.getPackageManager().getApplicationInfo(PACKAGE_NAME, 0);
assertTrue((mDisplayNameComparator.compare(info1, info2) > 0));
try {
mDisplayNameComparator.compare(null, null);
fail("should throw NullPointerException.");
} catch (NullPointerException e) {
+ // expected
}
}
}
diff --git a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
index 8e0c2b9..bc404fe 100644
--- a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
+++ b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
@@ -515,7 +515,12 @@
assertEquals(POSITION0, mDatabaseCursor.getColumnIndexOrThrow(COLUMN_NAMES1[POSITION0]));
assertEquals(POSITION1, mDatabaseCursor.getColumnIndexOrThrow(COLUMN_NAMES1[POSITION1]));
- assertEquals(0, mDatabaseCursor.getColumnIndexOrThrow(COLUMN_FAKE));
+ try {
+ mDatabaseCursor.getColumnIndexOrThrow(COLUMN_FAKE);
+ fail("IllegalArgumentException expected, but not thrown");
+ } catch (IllegalArgumentException expected) {
+ // expected
+ }
}
@TestTargetNew(
@@ -584,7 +589,7 @@
StringBuffer sb = new StringBuffer();
sb.append(window.getString(0, 0));
- String str = ((TestAbstractCursor)mTestAbstractCursor).getString(0);
+ String str = mTestAbstractCursor.getString(0);
assertEquals(str.length(), ca.sizeCopied);
assertEquals(sb.toString(), new String(ca.data, 0, ca.sizeCopied));
}
@@ -728,6 +733,7 @@
return mRows.length;
}
+ @Deprecated
@Override
public boolean deleteRow() {
return false;
@@ -784,18 +790,22 @@
}
// the following are protected methods
+ @Override
protected void checkPosition() {
super.checkPosition();
}
+ @Override
protected Object getUpdatedField(int columnIndex) {
return super.getUpdatedField(columnIndex);
}
+ @Override
protected boolean isFieldUpdated(int columnIndex) {
return super.isFieldUpdated(columnIndex);
}
+ @Override
protected void onChange(boolean selfChange) {
super.onChange(selfChange);
mHadCalledOnChange = true;
diff --git a/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java b/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
index 08c295e..0fc2a5d 100644
--- a/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
+++ b/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
@@ -396,7 +396,7 @@
public void testLoadingThread() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data INT);");
- final int count = 50000;
+ final int count = 30000;
String sql = "INSERT INTO test (data) VALUES (?);";
SQLiteStatement s = mDatabase.compileStatement(sql);
for (int i = 0; i < count; i++) {
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
index 09f0432..71783f3 100644
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
@@ -172,20 +172,16 @@
args = {java.io.FileDescriptor.class, android.graphics.Rect.class,
android.graphics.BitmapFactory.Options.class}
)
- public void testDecodeFileDescriptor1() {
- try {
- FileDescriptor input = obtainDiscriptor();
- Rect r = new Rect(1, 1, 1, 1);
- Bitmap b = BitmapFactory.decodeFileDescriptor(input, r, mOpt1);
- assertNotNull(b);
- // Test the bitmap size
- assertEquals(START_HEIGHT, b.getHeight());
- assertEquals(START_WIDTH, b.getWidth());
- // Test if no bitmap
- assertNull(BitmapFactory.decodeFileDescriptor(input, r, mOpt2));
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ public void testDecodeFileDescriptor1() throws IOException {
+ FileDescriptor input = obtainDescriptor();
+ Rect r = new Rect(1, 1, 1, 1);
+ Bitmap b = BitmapFactory.decodeFileDescriptor(input, r, mOpt1);
+ assertNotNull(b);
+ // Test the bitmap size
+ assertEquals(START_HEIGHT, b.getHeight());
+ assertEquals(START_WIDTH, b.getWidth());
+ // Test if no bitmap
+ assertNull(BitmapFactory.decodeFileDescriptor(input, r, mOpt2));
}
@TestTargetNew(
@@ -194,17 +190,13 @@
method = "decodeFileDescriptor",
args = {java.io.FileDescriptor.class}
)
- public void testDecodeFileDescriptor2() {
- try {
- FileDescriptor input = obtainDiscriptor();
- Bitmap b = BitmapFactory.decodeFileDescriptor(input);
- assertNotNull(b);
- // Test the bitmap size
- assertEquals(START_HEIGHT, b.getHeight());
- assertEquals(START_WIDTH, b.getWidth());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ public void testDecodeFileDescriptor2() throws IOException {
+ FileDescriptor input = obtainDescriptor();
+ Bitmap b = BitmapFactory.decodeFileDescriptor(input);
+ assertNotNull(b);
+ // Test the bitmap size
+ assertEquals(START_HEIGHT, b.getHeight());
+ assertEquals(START_WIDTH, b.getWidth());
}
@TestTargetNew(
@@ -213,18 +205,14 @@
method = "decodeFile",
args = {java.lang.String.class, android.graphics.BitmapFactory.Options.class}
)
- public void testDecodeFile1() {
- try {
- Bitmap b = BitmapFactory.decodeFile(obtainPath(), mOpt1);
- assertNotNull(b);
- // Test the bitmap size
- assertEquals(START_HEIGHT, b.getHeight());
- assertEquals(START_WIDTH, b.getWidth());
- // Test if no bitmap
- assertNull(BitmapFactory.decodeFile(obtainPath(), mOpt2));
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ public void testDecodeFile1() throws IOException {
+ Bitmap b = BitmapFactory.decodeFile(obtainPath(), mOpt1);
+ assertNotNull(b);
+ // Test the bitmap size
+ assertEquals(START_HEIGHT, b.getHeight());
+ assertEquals(START_WIDTH, b.getWidth());
+ // Test if no bitmap
+ assertNull(BitmapFactory.decodeFile(obtainPath(), mOpt2));
}
@TestTargetNew(
@@ -233,16 +221,12 @@
method = "decodeFile",
args = {java.lang.String.class}
)
- public void testDecodeFile2() {
- try {
- Bitmap b = BitmapFactory.decodeFile(obtainPath());
- assertNotNull(b);
- // Test the bitmap size
- assertEquals(START_HEIGHT, b.getHeight());
- assertEquals(START_WIDTH, b.getWidth());
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ public void testDecodeFile2() throws IOException {
+ Bitmap b = BitmapFactory.decodeFile(obtainPath());
+ assertNotNull(b);
+ // Test the bitmap size
+ assertEquals(START_HEIGHT, b.getHeight());
+ assertEquals(START_WIDTH, b.getWidth());
}
private byte[] obtainArray() {
@@ -256,7 +240,7 @@
return(getContext().getResources().openRawResource(R.drawable.start));
}
- private FileDescriptor obtainDiscriptor() throws IOException {
+ private FileDescriptor obtainDescriptor() throws IOException {
File dir = getContext().getFilesDir();
File file = new File(dir, "test.jpg");
return(ParcelFileDescriptor.open(file,
diff --git a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
index 5ce8abe..8cfa39a 100644
--- a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
@@ -350,25 +350,23 @@
public void run() {
try {
new ScrollingMovementMethod().onTouchEvent(mTextView, mSpannable, null);
- fail("The method did not throw NullPointerException if the event is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
long now = SystemClock.uptimeMillis();
try {
new ScrollingMovementMethod().onTouchEvent(mTextView, null,
MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, 0, 0, 0));
- fail("The method did not throw NullPointerException if the spannable is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
new ScrollingMovementMethod().onTouchEvent(null, mSpannable,
MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, 0, 0, 0));
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the layout is null.");
+ // NPE is acceptable
}
new ScrollingMovementMethod().onTouchEvent(mTextView, mSpannable,
@@ -376,32 +374,29 @@
try {
new ScrollingMovementMethod().onTouchEvent(null, mSpannable,
MotionEvent.obtain(now, now, MotionEvent.ACTION_MOVE, - 10000, 0, 0));
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
new ScrollingMovementMethod().onTouchEvent(mTextView, null,
MotionEvent.obtain(now, now, MotionEvent.ACTION_MOVE, - 10000, 0, 0));
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
new ScrollingMovementMethod().onTouchEvent(null, mSpannable,
MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, - 10000, 0, 0));
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the layout is null.");
+ // NPE is acceptable
}
try {
new ScrollingMovementMethod().onTouchEvent(mTextView, null,
MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, - 10000, 0, 0));
- fail("Should nthrow NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
}
});
@@ -547,22 +542,21 @@
try {
method.onKeyDown(null, mSpannable, KeyEvent.KEYCODE_DPAD_RIGHT,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP));
- fail("The method did not throw NullPointerException if the text view is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
method.onKeyDown(mTextView, null, KeyEvent.KEYCODE_DPAD_RIGHT,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP));
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the buffer is null.");
+ // NPE is acceptable
}
try {
method.onKeyDown(mTextView, mSpannable, KeyEvent.KEYCODE_DPAD_RIGHT, null);
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the buffer is null.");
+ // NPE is acceptable
}
}
});
@@ -652,28 +646,26 @@
public void run() {
try {
method.up(null, mSpannable);
- fail("The method did not throw NullPointerException if the view is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
method.up(mTextView, null);
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the buffer is null.");
+ // NPE is acceptable
}
try {
method.down(null, mSpannable);
- fail("The method did not throw NullPointerException if the view is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
method.down(mTextView, null);
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the buffer is null.");
+ // NPE is acceptable
}
}
});
@@ -718,30 +710,26 @@
assertNull(mTextView.getLayout());
try {
new MyScrollingMovementMethod().down(mTextView, mSpannable);
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
new MyScrollingMovementMethod().up(mTextView, mSpannable);
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
new MyScrollingMovementMethod().left(mTextView, mSpannable);
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
new MyScrollingMovementMethod().right(mTextView, mSpannable);
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
long now = SystemClock.uptimeMillis();
@@ -749,9 +737,8 @@
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT);
new ScrollingMovementMethod().onKeyDown(mTextView, mSpannable,
KeyEvent.KEYCODE_DPAD_RIGHT, event);
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
new ScrollingMovementMethod().onTouchEvent(mTextView, mSpannable,
@@ -759,9 +746,8 @@
try {
new ScrollingMovementMethod().onTouchEvent(mTextView, mSpannable,
MotionEvent.obtain(now, now, MotionEvent.ACTION_MOVE, - 10000, 0, 0));
- fail("The method did not throw NullPointerException if the layout is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
}
@@ -840,7 +826,7 @@
try {
method.onTakeFocus(mTextView, mSpannable, View.FOCUS_BACKWARD);
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the layout is null.");
+ // NPE is acceptable
}
runActionOnUiThread(new Runnable() {
@@ -875,15 +861,14 @@
public void run() {
try {
method.onTakeFocus(null, mSpannable, View.FOCUS_FORWARD);
- fail("The method did not throw NullPointerException if the view is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
method.onTakeFocus(mTextView, null, View.FOCUS_FORWARD);
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the text is null.");
+ // NPE is acceptable
}
}
});
@@ -966,28 +951,26 @@
public void run() {
try {
method.right(null, mSpannable);
- fail("The method did not throw NullPointerException if the view is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
method.right(mTextView, null);
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the buffer is null.");
+ // NPE is acceptable
}
try {
method.left(null, mSpannable);
- fail("The method did not throw NullPointerException if the view is null.");
} catch (NullPointerException e) {
- // expected
+ // NPE is acceptable
}
try {
method.left(mTextView, null);
} catch (NullPointerException e) {
- fail("The method threw NullPointerException if the buffer is null.");
+ // NPE is acceptable
}
}
});