Merge "Adjust cts tests to ddms testrunner IOException API change."
diff --git a/tests/SignatureTest/src/android/tests/sigtest/SignatureTest.java b/tests/SignatureTest/src/android/tests/sigtest/SignatureTest.java
index a2acefe..8001130 100644
--- a/tests/SignatureTest/src/android/tests/sigtest/SignatureTest.java
+++ b/tests/SignatureTest/src/android/tests/sigtest/SignatureTest.java
@@ -77,7 +77,7 @@
TAG_PACKAGE, TAG_CLASS, TAG_INTERFACE, TAG_IMPLEMENTS, TAG_CONSTRUCTOR,
TAG_METHOD, TAG_PARAM, TAG_EXCEPTION, TAG_FIELD }));
}
-
+
public static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException
{
int type;
@@ -87,7 +87,7 @@
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
-
+
if (!parser.getName().equals(firstElementName)) {
throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() +
", expected " + firstElementName);
@@ -109,7 +109,7 @@
while ((type=parser.next()) != XmlPullParser.START_TAG
&& type != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.END_TAG) {
-
+
}
if (type == XmlPullParser.END_TAG) {
@@ -144,14 +144,14 @@
currentClass.addConstructor(constructor);
currentMethod = constructor;
} else if (tagname.equals(TAG_METHOD)) {
- currentMethod = loadMethodInfo(parser);
+ currentMethod = loadMethodInfo(currentClass.getClassName(), parser);
currentClass.addMethod(currentMethod);
} else if (tagname.equals(TAG_PARAM)) {
currentMethod.addParam(parser.getAttributeValue(null, ATTRIBUTE_TYPE));
} else if (tagname.equals(TAG_EXCEPTION)) {
currentMethod.addException(parser.getAttributeValue(null, ATTRIBUTE_TYPE));
} else if (tagname.equals(TAG_FIELD)) {
- JDiffField field = loadFieldInfo(parser);
+ JDiffField field = loadFieldInfo(currentClass.getClassName(), parser);
currentClass.addField(field);
} else {
throw new RuntimeException(
@@ -179,25 +179,28 @@
/**
* Load field information from xml to memory.
*
+ * @param className of the class being examined which will be shown in error messages
+ * @param parser The XmlPullParser which carries the xml information.
* @return the new field
*/
- private JDiffField loadFieldInfo(XmlPullParser parser) {
+ private JDiffField loadFieldInfo(String className, XmlPullParser parser) {
String fieldName = parser.getAttributeValue(null, ATTRIBUTE_NAME);
String fieldType = parser.getAttributeValue(null, ATTRIBUTE_TYPE);
- int modifier = jdiffModifierToReflectionFormat(parser);
+ int modifier = jdiffModifierToReflectionFormat(className, parser);
return new JDiffField(fieldName, fieldType, modifier);
}
/**
* Load method information from xml to memory.
*
+ * @param className of the class being examined which will be shown in error messages
* @param parser The XmlPullParser which carries the xml information.
* @return the newly loaded method.
*/
- private JDiffMethod loadMethodInfo(XmlPullParser parser) {
+ private JDiffMethod loadMethodInfo(String className, XmlPullParser parser) {
String methodName = parser.getAttributeValue(null, ATTRIBUTE_NAME);
String returnType = parser.getAttributeValue(null, ATTRIBUTE_RETURN);
- int modifier = jdiffModifierToReflectionFormat(parser);
+ int modifier = jdiffModifierToReflectionFormat(className, parser);
return new JDiffMethod(methodName, modifier, returnType);
}
@@ -210,10 +213,9 @@
*/
private JDiffConstructor loadConstructorInfo(XmlPullParser parser,
JDiffClassDescription currentClass) {
- int modifier = jdiffModifierToReflectionFormat(parser);
- JDiffConstructor constructor = new JDiffConstructor(currentClass.getClassName(), modifier);
-
- return constructor;
+ String name = currentClass.getClassName();
+ int modifier = jdiffModifierToReflectionFormat(name, parser);
+ return new JDiffConstructor(name, modifier);
}
/**
@@ -231,7 +233,7 @@
JDiffClassDescription currentClass = new JDiffClassDescription(pkg,
className,
resultObserver);
- currentClass.setModifier(jdiffModifierToReflectionFormat(parser));
+ currentClass.setModifier(jdiffModifierToReflectionFormat(className, parser));
currentClass.setType(isInterface ? JDiffClassDescription.JDiffType.INTERFACE :
JDiffClassDescription.JDiffType.CLASS);
currentClass.setExtendsClass(parser.getAttributeValue(null, ATTRIBUTE_EXTENDS));
@@ -241,11 +243,12 @@
/**
* Convert string modifier to int modifier.
*
+ * @param name of the class/method/field being examined which will be shown in error messages
* @param key modifier name
* @param value modifier value
* @return converted modifier value
*/
- private static int modifierDescriptionToReflectedType(String key, String value){
+ private static int modifierDescriptionToReflectedType(String name, String key, String value) {
if (key.equals(MODIFIER_ABSTRACT)) {
return value.equals("true") ? Modifier.ABSTRACT : 0;
} else if (key.equals(MODIFIER_FINAL)) {
@@ -262,8 +265,7 @@
return value.equals("true") ? Modifier.VOLATILE : 0;
} else if (key.equals(MODIFIER_VISIBILITY)) {
if (value.equals(MODIFIER_PRIVATE)) {
- throw new RuntimeException(
- "should not be private method/field here");
+ throw new RuntimeException("Private visibility found in API spec: " + name);
} else if (value.equals(MODIFIER_PROTECTED)) {
return Modifier.PROTECTED;
} else if (value.equals(MODIFIER_PUBLIC)) {
@@ -273,8 +275,7 @@
// which is package private. We should return 0 for this modifier.
return 0;
} else {
- throw new RuntimeException(
- "Unknow modifier:" + value);
+ throw new RuntimeException("Unknown modifier found in API spec: " + value);
}
}
return 0;
@@ -283,13 +284,14 @@
/**
* Transfer string modifier to int one.
*
+ * @param name of the class/method/field being examined which will be shown in error messages
* @param parser XML resource parser
* @return converted modifier
*/
- private static int jdiffModifierToReflectionFormat(XmlPullParser parser){
+ private static int jdiffModifierToReflectionFormat(String name, XmlPullParser parser){
int modifier = 0;
for (int i = 0;i < parser.getAttributeCount();i++) {
- modifier |= modifierDescriptionToReflectedType(parser.getAttributeName(i),
+ modifier |= modifierDescriptionToReflectedType(name, parser.getAttributeName(i),
parser.getAttributeValue(i));
}
return modifier;
diff --git a/tests/SignatureTest/src/android/tests/sigtest/SignatureTestActivity.java b/tests/SignatureTest/src/android/tests/sigtest/SignatureTestActivity.java
index 90b08b8..9c81cef 100644
--- a/tests/SignatureTest/src/android/tests/sigtest/SignatureTestActivity.java
+++ b/tests/SignatureTest/src/android/tests/sigtest/SignatureTestActivity.java
@@ -111,16 +111,9 @@
if (!excludeSet.contains(f.getName())) {
try {
sigTest.start(r.getXml(f.getInt(rClass)));
- } catch (NotFoundException e) {
- throw new RuntimeException(e);
- } catch (IllegalArgumentException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (XmlPullParserException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
+ } catch (Exception e) {
+ mResultObserver.notifyFailure(FAILURE_TYPE.CAUGHT_EXCEPTION, e.getMessage(),
+ e.getMessage());
}
}
}
diff --git a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
index e20bee1..2927a13 100644
--- a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
+++ b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
@@ -409,7 +409,6 @@
)
})
public void testGetWindow() {
- assertNull(mDatabaseCursor.getWindow());
CursorWindow window = new CursorWindow(false);
assertEquals(0, window.getNumRows());
// fill window from position 0
diff --git a/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java b/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
index 9000972..f60638a 100644
--- a/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
+++ b/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
@@ -474,7 +474,7 @@
public void testManyRowsLong() throws Exception {
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data INT);");
- final int count = 36799;
+ final int count = 9000;
for (int i = 0; i < count; i++) {
mDatabase.execSQL("INSERT INTO test (data) VALUES (" + i + ");");
}
diff --git a/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java b/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java
index ac72141..ae5b9d4 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java
@@ -200,12 +200,11 @@
final String DELETE_1 = DELETE + "1;";
final String DELETE_2 = DELETE + "2;";
+ mDatabase.execSQL(DELETE_1);
+ // when cursor is created, it refreshes CursorWindow and populates cursor count
SQLiteCursor cursor = getCursor();
MockObserver observer = new MockObserver();
cursor.registerDataSetObserver(observer);
-
- mDatabase.execSQL(DELETE_1);
- // first time run getCount, it will refresh CursorWindow.
assertEquals(TEST_COUNT - 1, cursor.getCount());
assertFalse(observer.hasChanged());
diff --git a/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java b/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java
index 74eda03..13be1d5 100644
--- a/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java
@@ -47,7 +47,6 @@
)
@ToBeFixed(bug = "2034547",
explanation = "AvoidXfermode does not work as expected with tolerance 0.")
- @KnownFailure(value="bug 2136225")
public void testAvoidXfermode() {
Paint greenPaint;
Paint redAvoidingGreenPaint;
diff --git a/tests/tests/graphics/src/android/graphics/cts/ColorMatrixTest.java b/tests/tests/graphics/src/android/graphics/cts/ColorMatrixTest.java
index e92e1ec..7f55ddb 100644
--- a/tests/tests/graphics/src/android/graphics/cts/ColorMatrixTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/ColorMatrixTest.java
@@ -33,6 +33,8 @@
15, 16, 17, 18, 19
};
+ private static final float TOLERANCE = 0.0000001f;
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -199,22 +201,22 @@
mColorMatrix.setRotate(0, 180);
float[] ret = mColorMatrix.getArray();
- assertEquals(-1.0f, ret[6]);
- assertEquals(-1.0f, ret[12]);
- assertEquals(-8.742278E-8f, ret[7]);
- assertEquals(8.742278E-8f, ret[11]);
+ assertEquals(-1.0f, ret[6], TOLERANCE);
+ assertEquals(-1.0f, ret[12], TOLERANCE);
+ assertEquals(0, ret[7], TOLERANCE);
+ assertEquals(0, ret[11], TOLERANCE);
mColorMatrix.setRotate(1, 180);
- assertEquals(-1.0f, ret[0]);
- assertEquals(-1.0f, ret[17]);
- assertEquals(-8.742278E-8f, ret[2]);
- assertEquals(8.742278E-8f, ret[15]);
+ assertEquals(-1.0f, ret[0], TOLERANCE);
+ assertEquals(-1.0f, ret[12], TOLERANCE);
+ assertEquals(0, ret[2], TOLERANCE);
+ assertEquals(0, ret[10], TOLERANCE);
mColorMatrix.setRotate(2, 180);
- assertEquals(-1.0f, ret[0]);
- assertEquals(-1.0f, ret[6]);
- assertEquals(-8.742278E-8f, ret[1]);
- assertEquals(8.742278E-8f, ret[5]);
+ assertEquals(-1.0f, ret[0], TOLERANCE);
+ assertEquals(-1.0f, ret[6], TOLERANCE);
+ assertEquals(0, ret[1], TOLERANCE);
+ assertEquals(0, ret[5], TOLERANCE);
}
@TestTargets({
diff --git a/tests/tests/hardware/Android.mk b/tests/tests/hardware/Android.mk
index 7baf40a..dd3b72f 100644
--- a/tests/tests/hardware/Android.mk
+++ b/tests/tests/hardware/Android.mk
@@ -16,10 +16,7 @@
include $(CLEAR_VARS)
-# don't include this package in any target
-LOCAL_MODULE_TAGS := optional
-# and when built explicitly put it in the data partition
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+LOCAL_MODULE_TAGS := tests
LOCAL_JAVA_LIBRARIES := android.test.runner
diff --git a/tests/tests/hardware/AndroidManifest.xml b/tests/tests/hardware/AndroidManifest.xml
index 940511b..2293f8f 100644
--- a/tests/tests/hardware/AndroidManifest.xml
+++ b/tests/tests/hardware/AndroidManifest.xml
@@ -22,7 +22,7 @@
<uses-library android:name="android.test.runner" />
</application>
- <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.android.cts.stub"
android:label="CTS tests of android.hardware"/>
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
index 979d24c..44b645d 100644
--- a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
@@ -31,25 +31,28 @@
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.PreviewCallback;
-import android.hardware.Camera.Size;
import android.hardware.Camera.ShutterCallback;
+import android.hardware.Camera.Size;
import android.media.ExifInterface;
import android.media.MediaRecorder;
import android.os.ConditionVariable;
import android.os.Environment;
import android.os.Looper;
import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
import android.view.SurfaceHolder;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
/**
* This test case must run with hardware. It can't be tested in emulator
*/
+@LargeTest
@TestTargetClass(Camera.class)
public class CameraTest extends ActivityInstrumentationTestCase2<CameraStubActivity> {
private String TAG = "CameraTest";
@@ -127,8 +130,14 @@
/*
* Terminates the message looper thread.
*/
- private void terminateMessageLooper() {
+ private void terminateMessageLooper() throws Exception {
mLooper.quit();
+ // Looper.quit() is asynchronous. The looper may still has some
+ // preview callbacks in the queue after quit is called. The preview
+ // callback still uses the camera object (setHasPreviewCallback).
+ // After camera is released, RuntimeException will be thrown from
+ // the method. So we need to join the looper thread here.
+ mLooper.getThread().join();
mCamera.release();
}
@@ -610,8 +619,6 @@
assertTrue(paramActual.getPreviewFrameRate() > 0);
checkExposureCompensation(parameters);
-
- checkZoom(parameters);
}
private void checkExposureCompensation(Parameters parameters) {
@@ -628,21 +635,6 @@
assertTrue(min <= 0);
}
- private void checkZoom(Parameters parameters) {
- if (!parameters.isZoomSupported()) return;
- assertEquals(parameters.getZoom(), 0);
- int maxZoom = parameters.getMaxZoom();
- assertTrue(maxZoom >= 0);
- if (maxZoom > 0) {
- List<Integer> ratios = parameters.getZoomRatios();
- assertEquals(ratios.size(), maxZoom + 1);
- assertEquals(ratios.get(0).intValue(), 100);
- for (int i = 0; i < ratios.size() - 1; i++) {
- assertTrue(ratios.get(i) < ratios.get(i + 1));
- }
- }
- }
-
private boolean isValidPixelFormat(int format) {
return (format == ImageFormat.RGB_565) || (format == ImageFormat.NV21)
|| (format == ImageFormat.JPEG) || (format == ImageFormat.YUY2);
@@ -884,4 +876,166 @@
}
}
}
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "startSmoothZoom",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "stopSmoothZoom",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setZoomCallback",
+ args = {android.hardware.Camera.ZoomCallback.class}
+ )
+ })
+ public void testZoom() throws Exception {
+ initializeMessageLooper();
+ testImmediateZoom();
+ testSmoothZoom();
+ terminateMessageLooper();
+ }
+
+ private void testImmediateZoom() throws Exception {
+ Parameters parameters = mCamera.getParameters();
+ if (!parameters.isZoomSupported()) return;
+
+ // Test the zoom parameters.
+ assertEquals(parameters.getZoom(), 0); // default zoom should be 0.
+ int maxZoom = parameters.getMaxZoom();
+ assertTrue(maxZoom >= 0);
+ if (maxZoom > 0) {
+ // Zoom ratios should be sorted from small to large.
+ List<Integer> ratios = parameters.getZoomRatios();
+ assertEquals(ratios.size(), maxZoom + 1);
+ assertEquals(ratios.get(0).intValue(), 100);
+ for (int i = 0; i < ratios.size() - 1; i++) {
+ assertTrue(ratios.get(i) < ratios.get(i + 1));
+ }
+ }
+ SurfaceHolder mSurfaceHolder;
+ mSurfaceHolder = CameraStubActivity.mSurfaceView.getHolder();
+ mCamera.setPreviewDisplay(mSurfaceHolder);
+ mCamera.startPreview();
+ waitForPreviewDone();
+
+ // Test each zoom step.
+ for (int i = 0; i <= maxZoom; i++) {
+ parameters.setZoom(i);
+ mCamera.setParameters(parameters);
+ assertEquals(i, parameters.getZoom());
+ }
+
+ // It should throw exception if an invalid value is passed.
+ try {
+ parameters.setZoom(maxZoom + 1);
+ mCamera.setParameters(parameters);
+ fail("setZoom should throw exception.");
+ } catch (RuntimeException e) {
+ // expected
+ }
+ parameters = mCamera.getParameters();
+ assertEquals(maxZoom, parameters.getZoom());
+
+ mCamera.takePicture(mShutterCallback, mRawPictureCallback, mJpegPictureCallback);
+ waitForSnapshotDone();
+ }
+
+ private void testSmoothZoom() throws Exception {
+ Parameters parameters = mCamera.getParameters();
+ if (!parameters.isSmoothZoomSupported()) return;
+ assertTrue(parameters.isZoomSupported());
+
+ SurfaceHolder mSurfaceHolder;
+ mSurfaceHolder = CameraStubActivity.mSurfaceView.getHolder();
+ ZoomCallback zoomCallback = new ZoomCallback();
+ mCamera.setPreviewDisplay(mSurfaceHolder);
+ mCamera.setZoomCallback(zoomCallback);
+ mCamera.startPreview();
+ waitForPreviewDone();
+
+ // Immediate zoom should not generate callbacks.
+ int maxZoom = parameters.getMaxZoom();
+ parameters.setZoom(maxZoom);
+ mCamera.setParameters(parameters);
+ parameters.setZoom(0);
+ mCamera.setParameters(parameters);
+ assertFalse(zoomCallback.mZoomDone.block(500));
+
+ // Nothing will happen if zoom is not moving.
+ mCamera.stopSmoothZoom();
+
+ // It should not generate callbacks if zoom value is not changed.
+ mCamera.startSmoothZoom(0);
+ assertFalse(zoomCallback.mZoomDone.block(500));
+
+ // Test startSmoothZoom.
+ mCamera.startSmoothZoom(maxZoom);
+ assertEquals(true, zoomCallback.mZoomDone.block(5000));
+ assertEquals(maxZoom, zoomCallback.mValues.size());
+ for(int i = 0; i < maxZoom; i++) {
+ // Make sure we get all the callbacks in order.
+ assertEquals(i + 1, zoomCallback.mValues.get(i).intValue());
+ }
+
+ // Test startSmoothZoom. Make sure we get all the callbacks.
+ if (maxZoom > 1) {
+ zoomCallback.mValues = new ArrayList<Integer>();
+ zoomCallback.mStopped = false;
+ Log.e(TAG, "zoomCallback.mStopped = " + zoomCallback.mStopped);
+ zoomCallback.mZoomDone.close();
+ mCamera.startSmoothZoom(maxZoom / 2);
+ assertEquals(true, zoomCallback.mZoomDone.block(5000));
+ assertEquals(maxZoom - (maxZoom / 2), zoomCallback.mValues.size());
+ int i = maxZoom - 1;
+ for(Integer value: zoomCallback.mValues) {
+ assertEquals(i, value.intValue());
+ i--;
+ }
+ }
+
+ // It should throw exception if an invalid value is passed.
+ try {
+ mCamera.startSmoothZoom(maxZoom + 1);
+ fail("startSmoothZoom should throw exception.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ // Test stopSmoothZoom.
+ zoomCallback.mValues = new ArrayList<Integer>();
+ zoomCallback.mStopped = false;
+ zoomCallback.mZoomDone.close();
+ parameters.setZoom(0);
+ mCamera.setParameters(parameters);
+ mCamera.startSmoothZoom(maxZoom);
+ mCamera.stopSmoothZoom();
+ assertTrue(zoomCallback.mZoomDone.block(5000));
+ for(int i = 0; i < zoomCallback.mValues.size() - 1; i++) {
+ // Make sure we get all the callbacks in order (except the last).
+ assertEquals(i + 1, zoomCallback.mValues.get(i).intValue());
+ }
+ }
+
+ private final class ZoomCallback
+ implements android.hardware.Camera.ZoomCallback {
+ public ArrayList<Integer> mValues = new ArrayList<Integer>();
+ public boolean mStopped;
+ public final ConditionVariable mZoomDone = new ConditionVariable();
+
+ public void onZoomUpdate(int value, boolean stopped, Camera camera) {
+ mValues.add(value);
+ assertEquals(value, camera.getParameters().getZoom());
+ assertEquals(false, mStopped);
+ mStopped = stopped;
+ if (stopped) {
+ mZoomDone.open();
+ }
+ }
+ }
}
diff --git a/tests/tests/hardware/src/android/hardware/cts/Camera_SizeTest.java b/tests/tests/hardware/src/android/hardware/cts/Camera_SizeTest.java
index 5d01e59..028b819 100644
--- a/tests/tests/hardware/src/android/hardware/cts/Camera_SizeTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/Camera_SizeTest.java
@@ -16,14 +16,18 @@
package android.hardware.cts;
-import junit.framework.TestCase;
-import android.hardware.Camera;
-import android.hardware.Camera.Parameters;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
+import android.hardware.Camera;
+import android.hardware.Camera.Parameters;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import junit.framework.TestCase;
+
@TestTargetClass(Camera.Size.class)
+@LargeTest
public class Camera_SizeTest extends TestCase {
private final int HEIGHT1 = 320;
diff --git a/tests/tests/media/res/raw/john_cage.ogg b/tests/tests/media/res/raw/john_cage.ogg
new file mode 100644
index 0000000..62d2335
--- /dev/null
+++ b/tests/tests/media/res/raw/john_cage.ogg
Binary files differ
diff --git a/tests/tests/media/src/android/media/cts/AudioManagerTest.java b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
index 01ca1d2..6b1f24c 100644
--- a/tests/tests/media/src/android/media/cts/AudioManagerTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
@@ -553,18 +553,19 @@
assertEquals(k - 1, mAudioManager.getStreamVolume(streams[i]));
}
- mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
- assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
+ mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
+ assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
if (streams[i] == AudioManager.STREAM_RING) {
mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
// adjusting the volume to zero should result in either silent or vibrate mode
assertTrue(mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE ||
mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
- mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_SHOW_UI);
+ mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
+ assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
} else {
mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
diff --git a/tests/tests/media/src/android/media/cts/RingtoneManagerTest.java b/tests/tests/media/src/android/media/cts/RingtoneManagerTest.java
index 0bece06..daa2645 100644
--- a/tests/tests/media/src/android/media/cts/RingtoneManagerTest.java
+++ b/tests/tests/media/src/android/media/cts/RingtoneManagerTest.java
@@ -238,7 +238,8 @@
mRingtoneManager.setStopPreviousRingtone(true);
assertTrue(mRingtoneManager.getStopPreviousRingtone());
- Ringtone ringtone = mRingtoneManager.getRingtone(0);
+ Uri uri = Uri.parse("android.resource://android.media.cts/raw/John_Cage.ogg");
+ Ringtone ringtone = RingtoneManager.getRingtone(mContext, uri);
ringtone.play();
assertTrue(ringtone.isPlaying());
Ringtone newRingtone = mRingtoneManager.getRingtone(0);
@@ -248,4 +249,4 @@
mRingtoneManager.stopPreviousRingtone();
assertFalse(newRingtone.isPlaying());
}
-}
\ No newline at end of file
+}
diff --git a/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java b/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java
index b7caac3..578cca3 100644
--- a/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java
+++ b/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java
@@ -131,16 +131,6 @@
assertTrue(System.putString(cr, stringField, stringValue));
System.setShowGTalkServiceStatus(cr, true);
- // backup fontScale
- Configuration cfg = new Configuration();
- System.getConfiguration(cr, cfg);
- float store = cfg.fontScale;
-
- // update fontScale row
- cfg = new Configuration();
- cfg.fontScale = 10.0f;
- assertTrue(System.putConfiguration(cr, cfg));
-
c = cr.query(System.CONTENT_URI, null, null, null, null);
assertNotNull(c);
assertEquals(origCount + 5, c.getCount());
@@ -154,13 +144,6 @@
assertEquals(stringValue, System.getString(cr, stringField));
assertTrue(System.getShowGTalkServiceStatus(cr));
- System.getConfiguration(cr, cfg);
- assertEquals(10.0f, cfg.fontScale);
-
- // restore the fontScale
- cfg.fontScale = store;
- assertTrue(System.putConfiguration(cr, cfg));
-
// delete these rows
String selection = System.NAME + "=\"" + intField + "\"";
cr.delete(System.CONTENT_URI, selection, null);
@@ -180,6 +163,23 @@
c = cr.query(System.CONTENT_URI, null, null, null, null);
assertNotNull(c);
assertEquals(origCount, c.getCount());
+
+ // backup fontScale
+ Configuration cfg = new Configuration();
+ System.getConfiguration(cr, cfg);
+ float store = cfg.fontScale;
+
+ // update fontScale row
+ cfg = new Configuration();
+ cfg.fontScale = 10.0f;
+ assertTrue(System.putConfiguration(cr, cfg));
+
+ System.getConfiguration(cr, cfg);
+ assertEquals(10.0f, cfg.fontScale);
+
+ // restore the fontScale
+ cfg.fontScale = store;
+ assertTrue(System.putConfiguration(cr, cfg));
} finally {
// TODO should clean up more better
c.close();
diff --git a/tests/tests/view/src/android/view/cts/ViewStubTest.java b/tests/tests/view/src/android/view/cts/ViewStubTest.java
index ca846e0..388e8e9 100644
--- a/tests/tests/view/src/android/view/cts/ViewStubTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewStubTest.java
@@ -84,9 +84,6 @@
args = {android.content.Context.class, int.class}
)
})
- @ToBeFixed(bug="1371108", explanation="constructor ViewStub#ViewStub(Context, AttributeSet)" +
- "and ViewStub#ViewStub(Context, AttributeSet, int)" +
- " should check whether the input Context is null")
public void testConstructor() {
XmlPullParser parser = mActivity.getResources().getXml(R.layout.viewstub_layout);
AttributeSet attrs = Xml.asAttributeSet(parser);
@@ -99,23 +96,6 @@
new ViewStub(mContext, attrs);
new ViewStub(mContext, attrs, 30);
-
- // test the exceptional conditions
- new ViewStub(null, -1);
-
- new ViewStub(null);
-
- try {
- new ViewStub(null, null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- }
-
- try {
- new ViewStub(null, null, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- }
}
@TestTargetNew(
@@ -133,23 +113,10 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link ViewStub#dispatchDraw(Canvas)}",
- method = "dispatchDraw",
- args = {android.graphics.Canvas.class}
- )
- @ToBeFixed(bug="1391590", explanation=" ViewStub is final class and dispatchDraw(Canvas)" +
- " is protected method, we can not do unit test for this method")
- public void testDispatchDraw() {
- // empty method
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
notes = "Test {@link ViewStub#setVisibility(int)}",
method = "setVisibility",
args = {int.class}
)
- @KnownFailure(value="bug 2323459, fixed in future release")
@UiThreadTest
public void testSetVisibility() {
final ViewStub viewStub1 = (ViewStub) mActivity.findViewById(R.id.viewstub);
diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java
index af7bf97..0054ebb 100644
--- a/tests/tests/view/src/android/view/cts/ViewTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTest.java
@@ -88,7 +88,7 @@
@TestTargetClass(View.class)
public class ViewTest extends ActivityInstrumentationTestCase2<ViewTestStubActivity> {
public ViewTest() {
- super("com.android.cts.stub", ViewTestStubActivity.class);
+ super(ViewTestStubActivity.class);
}
private Resources mResources;
@@ -123,13 +123,9 @@
args = {android.content.Context.class, android.util.AttributeSet.class, int.class}
)
})
- @ToBeFixed(bug = "1695243", explanation = "the javadoc for constructors is incomplete." +
- "1. not clear what is supposed to happen if context is null.")
public void testConstructor() {
new View(mActivity);
- new View(null);
-
final XmlResourceParser parser = mResources.getLayout(R.layout.view_layout);
final AttributeSet attrs = Xml.asAttributeSet(parser);
new View(mActivity, attrs);
@@ -161,9 +157,6 @@
public void testGetContext() {
View view = new View(mActivity);
assertSame(mActivity, view.getContext());
-
- view = new View(null);
- assertNull(view.getContext());
}
@TestTargetNew(
@@ -174,9 +167,6 @@
public void testGetResources() {
View view = new View(mActivity);
assertSame(mResources, view.getResources());
-
- view = new View(null);
- assertNull(view.getResources());
}
@TestTargetNew(
diff --git a/tests/tests/view/src/android/view/cts/View_AnimationTest.java b/tests/tests/view/src/android/view/cts/View_AnimationTest.java
index 7a22a3b..06763f5 100644
--- a/tests/tests/view/src/android/view/cts/View_AnimationTest.java
+++ b/tests/tests/view/src/android/view/cts/View_AnimationTest.java
@@ -151,6 +151,7 @@
runTestOnUiThread(new Runnable() {
public void run() {
view.startAnimation(mAnimation);
+ assertNotNull(view.getAnimation());
}
});
@@ -164,6 +165,7 @@
view.clearAnimation();
Thread.sleep(TIME_OUT);
assertTrue(mAnimation.hasStarted());
- assertFalse(mAnimation.hasEnded());
+ assertTrue(mAnimation.hasEnded());
+ assertNull(view.getAnimation());
}
}
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index 7c1f850..40c6c93 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -179,7 +179,7 @@
return webChromeClient.hadOnCreateWindow();
}
}.run();
- assertTrue(webChromeClient.hadOnRequestFocus());
+ assertFalse(webChromeClient.hadOnRequestFocus());
new DelayedCheck(TEST_TIMEOUT) {
@Override
protected boolean check() {
@@ -449,6 +449,8 @@
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture,
Message resultMsg) {
WebView childView = new WebView(getActivity());
+ final WebSettings settings = childView.getSettings();
+ settings.setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
index 9cb753f..79a112b 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
@@ -91,7 +91,9 @@
Log.i(LOG_TAG, String.format("Trying to match pattern %s", patternString));
final Pattern userAgentExpr = Pattern.compile(patternString);
Matcher patternMatcher = userAgentExpr.matcher(actualUserAgentString);
- assertTrue("User agent string did not match expected pattern", patternMatcher.find());
+ assertTrue(String.format("User agent string did not match expected pattern. \nExpected " +
+ "pattern:\n%s\nActual:\n%s", patternString, actualUserAgentString),
+ patternMatcher.find());
assertEquals(Build.VERSION.RELEASE, patternMatcher.group(1));
Locale currentLocale = Locale.getDefault();
assertEquals(currentLocale.getLanguage().toLowerCase(), patternMatcher.group(2));
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index bd805a3..ef7fb19 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -268,7 +268,7 @@
currScale = mWebView.getScale();
}
- // can not zoom out further
+ // can not zoom out furtherholiday
assertFalse(mWebView.zoomOut());
previousScale = currScale;
currScale = mWebView.getScale();
@@ -885,7 +885,7 @@
// check that image was retrieved from the server
assertTrue(mWebServer.getLastRequestUrl().endsWith(imgUrl));
// no history item saved, URL is still the last one
- assertEquals(failUrl, mWebView.getUrl());
+ assertEquals("about:blank", mWebView.getUrl());
}
@TestTargetNew(
@@ -2175,9 +2175,13 @@
}
}
+ // Find b1 inside b2
private boolean checkBitmapInsideAnother(Bitmap b1, Bitmap b2) {
- for (int i = 0; i < b2.getWidth(); i++) {
- for (int j = 0; j < b2.getHeight(); j++) {
+ int w = b1.getWidth();
+ int h = b1.getHeight();
+
+ for (int i = 0; i < (b2.getWidth()-w+1); i++) {
+ for (int j = 0; j < (b2.getHeight()-h+1); j++) {
if (checkBitmapInsideAnother(b1, b2, i, j))
return true;
}
@@ -2185,16 +2189,31 @@
return false;
}
- private boolean checkBitmapInsideAnother(Bitmap b1, Bitmap b2, int x, int y) {
- int w = b1.getWidth();
- int h = b1.getHeight();
-
- if ((x + w > b2.getWidth()) || (x + h > b2.getHeight())) {
+ private boolean comparePixel(int p1, int p2, int maxError) {
+ int err;
+ err = Math.abs(((p1&0xff000000)>>>24) - ((p2&0xff000000)>>>24));
+ if (err > maxError)
return false;
- }
- for (int i = 0; i < w; i++)
- for (int j = 0; j < h; j++) {
- if (b1.getPixel(i, j) != b2.getPixel(x + i, y + j)) {
+
+ err = Math.abs(((p1&0x00ff0000)>>>16) - ((p2&0x00ff0000)>>>16));
+ if (err > maxError)
+ return false;
+
+ err = Math.abs(((p1&0x0000ff00)>>>8) - ((p2&0x0000ff00)>>>8));
+ if (err > maxError)
+ return false;
+
+ err = Math.abs(((p1&0x000000ff)>>>0) - ((p2&0x000000ff)>>>0));
+ if (err > maxError)
+ return false;
+
+ return true;
+ }
+
+ private boolean checkBitmapInsideAnother(Bitmap b1, Bitmap b2, int x, int y) {
+ for (int i = 0; i < b1.getWidth(); i++)
+ for (int j = 0; j < b1.getHeight(); j++) {
+ if (!comparePixel(b1.getPixel(i, j), b2.getPixel(x + i, y + j), 10)) {
return false;
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java b/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java
index e1db2ca..e5569c4 100644
--- a/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java
@@ -93,21 +93,6 @@
new AbsoluteLayout(mActivity);
new AbsoluteLayout(mActivity, attrs);
new AbsoluteLayout(mActivity, attrs, 0);
-
- new AbsoluteLayout(null);
-
- try {
- new AbsoluteLayout(null, attrs);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- }
-
- try {
- new AbsoluteLayout(null, attrs, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- }
-
new AbsoluteLayout(mActivity, null, 1);
new AbsoluteLayout(mActivity, attrs, -1);
}
diff --git a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
index 5bfce3a..a8c9ae0 100644
--- a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
@@ -685,35 +685,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "onWindowFocusChanged",
- args = {boolean.class}
- )
- @UiThreadTest
- public void testOnWindowFocusChanged() {
- mAutoCompleteTextView.setText(STRING_TEST);
- windowfocusChange(true);
- assertEquals(STRING_VALIDATED, mAutoCompleteTextView.getText().toString());
- assertTrue(mAutoCompleteTextView.isPopupShowing());
- mAutoCompleteTextView.setValidator(null);
-
- // If hasWindowFocus has been set as false, popup window will be closed.
- windowfocusChange(false);
- assertEquals(STRING_VALIDATED, mAutoCompleteTextView.getText().toString());
- mAutoCompleteTextView.setValidator(null);
- assertFalse(mAutoCompleteTextView.isPopupShowing());
- }
-
- @UiThreadTest
- private void windowfocusChange(final Boolean hasWindowFocus) {
- mAutoCompleteTextView.setValidator(mValidator);
- mAutoCompleteTextView.setAdapter((ArrayAdapter<String>) null);
- mAutoCompleteTextView.showDropDown();
- mAutoCompleteTextView.setText(STRING_TEST);
- mAutoCompleteTextView.onWindowFocusChanged(hasWindowFocus);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "performValidation",
args = {}
)
diff --git a/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java b/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
index f95057a..76de651 100644
--- a/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
@@ -81,14 +81,6 @@
new DialerFilter(mActivity);
new DialerFilter(mActivity, attrs);
-
- new DialerFilter(null);
- try {
- new DialerFilter(null, null);
- fail("There should be a NullPointerException thrown out.");
- } catch (final NullPointerException e) {
- // expected, test success
- }
}
@TestTargetNew(
diff --git a/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java b/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java
index 8fecc39..af420b4 100644
--- a/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java
@@ -16,6 +16,14 @@
package android.widget.cts;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
import org.xmlpull.v1.XmlPullParser;
import android.content.Context;
@@ -36,16 +44,6 @@
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
-import android.widget.ExpandableListView.OnGroupCollapseListener;
-import android.widget.ExpandableListView.OnGroupExpandListener;
-
-import com.android.cts.stub.R;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
@TestTargetClass(ExpandableListView.class)
public class ExpandableListViewTest extends AndroidTestCase {
@@ -334,9 +332,19 @@
expandableListView.setAdapter(new MockExpandableListAdapter());
assertEquals(0, expandableListView.getExpandableListPosition(0));
- assertEquals(1L<<32, expandableListView.getExpandableListPosition(1));
- assertEquals(2L<<32, expandableListView.getExpandableListPosition(2));
- assertEquals(3L<<32, expandableListView.getExpandableListPosition(3));
+
+ // Group 0 is not expanded, position 1 is invalid
+ assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL,
+ expandableListView.getExpandableListPosition(1));
+
+ // Position 1 becomes valid when group 0 is expanded
+ expandableListView.expandGroup(0);
+ assertEquals(ExpandableListView.getPackedPositionForChild(0, 0),
+ expandableListView.getExpandableListPosition(1));
+
+ // Position 2 is still invalid (only one child).
+ assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL,
+ expandableListView.getExpandableListPosition(2));
}
@TestTargetNew(
@@ -780,6 +788,7 @@
super(context, attrs, defStyle);
}
+ @Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
}
diff --git a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
index 1d5d925..1f8cd23 100644
--- a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
+++ b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
@@ -94,22 +94,6 @@
new FrameLayout(mActivity);
new FrameLayout(mActivity, attrs);
new FrameLayout(mActivity, attrs, 0);
-
- new FrameLayout(null);
-
- try {
- new FrameLayout(null, null);
- fail("did not throw NullPointerException when context and attrs are null.");
- } catch (NullPointerException e) {
- // expected, test success
- }
-
- try {
- new FrameLayout(null, null, -1);
- fail("did not throw NullPointerException when context and attrs are null.");
- } catch (NullPointerException e) {
- // expected, test success
- }
}
@TestTargets({
diff --git a/tests/tests/widget/src/android/widget/cts/GalleryTest.java b/tests/tests/widget/src/android/widget/cts/GalleryTest.java
index 9923ec8..e95deb7 100644
--- a/tests/tests/widget/src/android/widget/cts/GalleryTest.java
+++ b/tests/tests/widget/src/android/widget/cts/GalleryTest.java
@@ -349,37 +349,6 @@
@TestTargetNew(
level = TestLevel.NOT_FEASIBLE,
- method = "dispatchSetSelected",
- args = {boolean.class}
- )
- @ToBeFixed(bug = "1695243", explanation = "Android API javadocs are not right, "
- + "dispatchSetSelected() does not dispatch setSelected to all child views.")
- public void testDispatchSetSelected() {
- int count = mGallery.getChildCount();
-
- mGallery.dispatchSetSelected(false);
- for (int i = 0; i < count; i++) {
- // the child view should not be selected, but a item still is selected.
- if (i == mGallery.getSelectedItemPosition()) {
- assertTrue(mGallery.getChildAt(i).isSelected());
- } else {
- assertFalse(mGallery.getChildAt(i).isSelected());
- }
- }
-
- mGallery.dispatchSetSelected(true);
- for (int i = 0; i < count; i++) {
- // the child view should be selected, but some items still are selected.
- if (i == mGallery.getSelectedItemPosition()) {
- assertTrue(mGallery.getChildAt(i).isSelected());
- } else {
- assertFalse(mGallery.getChildAt(i).isSelected());
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
method = "showContextMenuForChild",
args = {android.view.View.class}
)
diff --git a/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java b/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java
index a0f0df6..9a7672e 100644
--- a/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java
@@ -39,12 +39,10 @@
*/
@TestTargetClass(HeaderViewListAdapter.class)
public class HeaderViewListAdapterTest extends AndroidTestCase {
- HeaderViewListAdapter mHeaderViewListAdapter;
@Override
protected void setUp() throws Exception {
super.setUp();
- mHeaderViewListAdapter = null;
}
@TestTargetNew(
@@ -68,14 +66,14 @@
args = {}
)
public void testGetHeadersCount() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertEquals(0, mHeaderViewListAdapter.getHeadersCount());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertEquals(0, headerViewListAdapter.getHeadersCount());
ListView lv = new ListView(getContext());
ArrayList<ListView.FixedViewInfo> header = new ArrayList<ListView.FixedViewInfo>(4);
header.add(lv.new FixedViewInfo());
- mHeaderViewListAdapter = new HeaderViewListAdapter(header, null, null);
- assertEquals(1, mHeaderViewListAdapter.getHeadersCount());
+ headerViewListAdapter = new HeaderViewListAdapter(header, null, null);
+ assertEquals(1, headerViewListAdapter.getHeadersCount());
}
@TestTargetNew(
@@ -85,14 +83,14 @@
args = {}
)
public void testGetFootersCount() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertEquals(0, mHeaderViewListAdapter.getFootersCount());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertEquals(0, headerViewListAdapter.getFootersCount());
ListView lv = new ListView(getContext());
ArrayList<ListView.FixedViewInfo> footer = new ArrayList<ListView.FixedViewInfo>(4);
footer.add(lv.new FixedViewInfo());
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, footer, null);
- assertEquals(1, mHeaderViewListAdapter.getFootersCount());
+ headerViewListAdapter = new HeaderViewListAdapter(null, footer, null);
+ assertEquals(1, headerViewListAdapter.getFootersCount());
}
@TestTargetNew(
@@ -102,16 +100,16 @@
args = {}
)
public void testIsEmpty() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertTrue(mHeaderViewListAdapter.isEmpty());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertTrue(headerViewListAdapter.isEmpty());
HeaderViewEmptyAdapter emptyAdapter = new HeaderViewEmptyAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, emptyAdapter);
- assertTrue(mHeaderViewListAdapter.isEmpty());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, emptyAdapter);
+ assertTrue(headerViewListAdapter.isEmpty());
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
- assertFalse(mHeaderViewListAdapter.isEmpty());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ assertFalse(headerViewListAdapter.isEmpty());
}
@TestTargetNew(
@@ -132,15 +130,16 @@
info2.view = lv2;
header.add(info1);
header.add(info2);
- mHeaderViewListAdapter = new HeaderViewListAdapter(header, null, null);
- assertEquals(2, mHeaderViewListAdapter.getHeadersCount());
- assertFalse(mHeaderViewListAdapter.removeHeader(new ListView(getContext())));
- assertTrue(mHeaderViewListAdapter.removeHeader(lv1));
- assertEquals(1, mHeaderViewListAdapter.getHeadersCount());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(header, null, null);
+ assertEquals(2, headerViewListAdapter.getHeadersCount());
+ assertFalse(headerViewListAdapter.removeHeader(new ListView(getContext())));
+ assertTrue(headerViewListAdapter.removeHeader(lv1));
+ assertEquals(1, headerViewListAdapter.getHeadersCount());
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
try {
- mHeaderViewListAdapter.removeHeader(null);
+ headerViewListAdapter.removeHeader(null);
+ //fail("Removing from null header should result in NullPointerException");
} catch (NullPointerException e) {
// expected.
}
@@ -164,15 +163,16 @@
info2.view = lv2;
footer.add(info1);
footer.add(info2);
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, footer, null);
- assertEquals(2, mHeaderViewListAdapter.getFootersCount());
- assertFalse(mHeaderViewListAdapter.removeFooter(new ListView(getContext())));
- assertTrue(mHeaderViewListAdapter.removeFooter(lv1));
- assertEquals(1, mHeaderViewListAdapter.getFootersCount());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, footer, null);
+ assertEquals(2, headerViewListAdapter.getFootersCount());
+ assertFalse(headerViewListAdapter.removeFooter(new ListView(getContext())));
+ assertTrue(headerViewListAdapter.removeFooter(lv1));
+ assertEquals(1, headerViewListAdapter.getFootersCount());
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
try {
- mHeaderViewListAdapter.removeFooter(null);
+ headerViewListAdapter.removeFooter(null);
+ //fail("Removing from null footer should result in NullPointerException");
} catch (NullPointerException e) {
// expected.
}
@@ -185,8 +185,8 @@
args = {}
)
public void testGetCount() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertEquals(0, mHeaderViewListAdapter.getCount());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertEquals(0, headerViewListAdapter.getCount());
ListView lv = new ListView(getContext());
ArrayList<ListView.FixedViewInfo> header = new ArrayList<ListView.FixedViewInfo>(4);
@@ -209,14 +209,14 @@
footer.add(info4);
HeaderViewEmptyAdapter emptyAdapter = new HeaderViewEmptyAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(header, footer, emptyAdapter);
+ headerViewListAdapter = new HeaderViewListAdapter(header, footer, emptyAdapter);
// 4 is header's count + footer's count + emptyAdapter's count
- assertEquals(4, mHeaderViewListAdapter.getCount());
+ assertEquals(4, headerViewListAdapter.getCount());
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(header, footer, fullAdapter);
+ headerViewListAdapter = new HeaderViewListAdapter(header, footer, fullAdapter);
// 5 is header's count + footer's count + fullAdapter's count
- assertEquals(5, mHeaderViewListAdapter.getCount());
+ assertEquals(5, headerViewListAdapter.getCount());
}
@TestTargetNew(
@@ -226,16 +226,16 @@
args = {}
)
public void testAreAllItemsEnabled() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertTrue(mHeaderViewListAdapter.areAllItemsEnabled());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertTrue(headerViewListAdapter.areAllItemsEnabled());
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
- assertTrue(mHeaderViewListAdapter.areAllItemsEnabled());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ assertTrue(headerViewListAdapter.areAllItemsEnabled());
HeaderViewEmptyAdapter emptyAdapter = new HeaderViewEmptyAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, emptyAdapter);
- assertFalse(mHeaderViewListAdapter.areAllItemsEnabled());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, emptyAdapter);
+ assertFalse(headerViewListAdapter.areAllItemsEnabled());
}
@TestTargetNew(
@@ -245,13 +245,31 @@
args = {int.class}
)
public void testIsEnabled() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertTrue(mHeaderViewListAdapter.isEnabled(0));
- assertTrue(mHeaderViewListAdapter.isEnabled(-1));
+ HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
+ HeaderViewListAdapter headerViewListAdapter =
+ new HeaderViewListAdapter(null, null, fullAdapter);
+ assertTrue(headerViewListAdapter.isEnabled(0));
+
+ ListView lv = new ListView(getContext());
+ ArrayList<ListView.FixedViewInfo> header = new ArrayList<ListView.FixedViewInfo>(4);
+ header.add(lv.new FixedViewInfo());
+ headerViewListAdapter = new HeaderViewListAdapter(header, null, fullAdapter);
+ assertFalse(headerViewListAdapter.isEnabled(0));
+ assertTrue(headerViewListAdapter.isEnabled(1));
- HeaderViewEmptyAdapter headerViewListAdapter = new HeaderViewEmptyAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, headerViewListAdapter);
- assertFalse(mHeaderViewListAdapter.isEnabled(1));
+ ArrayList<ListView.FixedViewInfo> footer = new ArrayList<ListView.FixedViewInfo>(4);
+ footer.add(lv.new FixedViewInfo());
+ footer.add(lv.new FixedViewInfo());
+ headerViewListAdapter = new HeaderViewListAdapter(header, footer, fullAdapter);
+ assertFalse(headerViewListAdapter.isEnabled(0));
+ assertTrue(headerViewListAdapter.isEnabled(1));
+ assertFalse(headerViewListAdapter.isEnabled(2));
+ assertFalse(headerViewListAdapter.isEnabled(3));
+
+ headerViewListAdapter = new HeaderViewListAdapter(null, footer, fullAdapter);
+ assertTrue(headerViewListAdapter.isEnabled(0));
+ assertFalse(headerViewListAdapter.isEnabled(1));
+ assertFalse(headerViewListAdapter.isEnabled(2));
}
@TestTargetNew(
@@ -261,10 +279,6 @@
args = {int.class}
)
public void testGetItem() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertNull(mHeaderViewListAdapter.getItem(0));
- assertNull(mHeaderViewListAdapter.getItem(-1));
-
ListView lv = new ListView(getContext());
ArrayList<ListView.FixedViewInfo> header = new ArrayList<ListView.FixedViewInfo>(4);
Object data1 = new Object();
@@ -286,9 +300,13 @@
footer.add(info4);
HeaderViewFullAdapter headerViewFullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(header, footer, headerViewFullAdapter);
- assertSame(data3, mHeaderViewListAdapter.getItem(3));
- assertSame(data1, mHeaderViewListAdapter.getItem(0));
+ HeaderViewListAdapter headerViewListAdapter =
+ new HeaderViewListAdapter(header, footer, headerViewFullAdapter);
+ assertSame(data1, headerViewListAdapter.getItem(0));
+ assertSame(data2, headerViewListAdapter.getItem(1));
+ assertSame(headerViewFullAdapter.getItem(0), headerViewListAdapter.getItem(2));
+ assertSame(data3, headerViewListAdapter.getItem(3));
+ assertSame(data4, headerViewListAdapter.getItem(4));
}
@TestTargetNew(
@@ -298,10 +316,6 @@
args = {int.class}
)
public void testGetItemId() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertEquals(-1, mHeaderViewListAdapter.getItemId(0));
- assertEquals(-1, mHeaderViewListAdapter.getItemId(-1));
-
ListView lv = new ListView(getContext());
ArrayList<ListView.FixedViewInfo> header = new ArrayList<ListView.FixedViewInfo>(4);
ListView lv1 = new ListView(getContext());
@@ -314,9 +328,10 @@
header.add(info2);
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(header, null, fullAdapter);
- assertEquals(-1, mHeaderViewListAdapter.getItemId(0));
- assertEquals(fullAdapter.getItemId(0), mHeaderViewListAdapter.getItemId(2));
+ HeaderViewListAdapter headerViewListAdapter =
+ new HeaderViewListAdapter(header, null, fullAdapter);
+ assertEquals(-1, headerViewListAdapter.getItemId(0));
+ assertEquals(fullAdapter.getItemId(0), headerViewListAdapter.getItemId(2));
}
@TestTargetNew(
@@ -326,12 +341,12 @@
args = {}
)
public void testHasStableIds() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertFalse(mHeaderViewListAdapter.hasStableIds());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertFalse(headerViewListAdapter.hasStableIds());
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
- assertTrue(mHeaderViewListAdapter.hasStableIds());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ assertTrue(headerViewListAdapter.hasStableIds());
}
@TestTargetNew(
@@ -343,9 +358,6 @@
@ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete, " +
"should add @throw into javadoc.")
public void testGetView() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertNull(mHeaderViewListAdapter.getView(0, null, null));
-
ListView lv = new ListView(getContext());
ArrayList<ListView.FixedViewInfo> header = new ArrayList<ListView.FixedViewInfo>(4);
ListView lv1 = new ListView(getContext());
@@ -356,18 +368,23 @@
info2.view = lv2;
header.add(info1);
header.add(info2);
- mHeaderViewListAdapter = new HeaderViewListAdapter(header, null, null);
- assertSame(lv2, mHeaderViewListAdapter.getView(1, null, null));
+ // No adapter, just header
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(header, null, null);
+ assertSame(lv1, headerViewListAdapter.getView(0, null, null));
+ assertSame(lv2, headerViewListAdapter.getView(1, null, null));
+
+ // Adapter only
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ View expected = fullAdapter.getView(0, null, null);
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ assertSame(expected, headerViewListAdapter.getView(0, null, null));
- try {
- mHeaderViewListAdapter.getView(-1, null, null);
- fail("should throw NullPointerException.");
- } catch (NullPointerException e) {
- // expected.
- }
+ // Header and adapter
+ headerViewListAdapter = new HeaderViewListAdapter(header, null, fullAdapter);
+ assertSame(lv1, headerViewListAdapter.getView(0, null, null));
+ assertSame(lv2, headerViewListAdapter.getView(1, null, null));
+ assertSame(expected, headerViewListAdapter.getView(2, null, null));
}
@TestTargetNew(
@@ -377,17 +394,17 @@
args = {int.class}
)
public void testGetItemViewType() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
assertEquals(AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER,
- mHeaderViewListAdapter.getItemViewType(0));
+ headerViewListAdapter.getItemViewType(0));
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
assertEquals(AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER,
- mHeaderViewListAdapter.getItemViewType(-1));
- assertEquals(0, mHeaderViewListAdapter.getItemViewType(0));
+ headerViewListAdapter.getItemViewType(-1));
+ assertEquals(0, headerViewListAdapter.getItemViewType(0));
assertEquals(AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER,
- mHeaderViewListAdapter.getItemViewType(2));
+ headerViewListAdapter.getItemViewType(2));
}
@TestTargetNew(
@@ -397,12 +414,12 @@
args = {}
)
public void testGetViewTypeCount() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertEquals(1, mHeaderViewListAdapter.getViewTypeCount());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertEquals(1, headerViewListAdapter.getViewTypeCount());
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
- assertEquals(fullAdapter.getViewTypeCount(), mHeaderViewListAdapter.getViewTypeCount());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ assertEquals(fullAdapter.getViewTypeCount(), headerViewListAdapter.getViewTypeCount());
}
@TestTargetNew(
@@ -413,9 +430,10 @@
)
public void testRegisterDataSetObserver() {
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ HeaderViewListAdapter headerViewListAdapter =
+ new HeaderViewListAdapter(null, null, fullAdapter);
DataSetObserver observer = new HeaderViewDataSetObserver();
- mHeaderViewListAdapter.registerDataSetObserver(observer);
+ headerViewListAdapter.registerDataSetObserver(observer);
assertSame(observer, fullAdapter.getDataSetObserver());
}
@@ -427,13 +445,14 @@
)
public void testUnregisterDataSetObserver() {
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ HeaderViewListAdapter headerViewListAdapter =
+ new HeaderViewListAdapter(null, null, fullAdapter);
DataSetObserver observer = new HeaderViewDataSetObserver();
- mHeaderViewListAdapter.registerDataSetObserver(observer);
+ headerViewListAdapter.registerDataSetObserver(observer);
- mHeaderViewListAdapter.unregisterDataSetObserver(null);
+ headerViewListAdapter.unregisterDataSetObserver(null);
assertSame(observer, fullAdapter.getDataSetObserver());
- mHeaderViewListAdapter.unregisterDataSetObserver(observer);
+ headerViewListAdapter.unregisterDataSetObserver(observer);
assertNull(fullAdapter.getDataSetObserver());
}
@@ -444,16 +463,16 @@
args = {}
)
public void testGetFilter() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertNull(mHeaderViewListAdapter.getFilter());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertNull(headerViewListAdapter.getFilter());
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
- assertNull(mHeaderViewListAdapter.getFilter());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ assertNull(headerViewListAdapter.getFilter());
HeaderViewEmptyAdapter emptyAdapter = new HeaderViewEmptyAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, emptyAdapter);
- assertSame(emptyAdapter.getFilter(), mHeaderViewListAdapter.getFilter());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, emptyAdapter);
+ assertSame(emptyAdapter.getFilter(), headerViewListAdapter.getFilter());
}
@TestTargetNew(
@@ -463,16 +482,16 @@
args = {}
)
public void testGetWrappedAdapter() {
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, null);
- assertNull(mHeaderViewListAdapter.getWrappedAdapter());
+ HeaderViewListAdapter headerViewListAdapter = new HeaderViewListAdapter(null, null, null);
+ assertNull(headerViewListAdapter.getWrappedAdapter());
HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
- mHeaderViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
- assertSame(fullAdapter, mHeaderViewListAdapter.getWrappedAdapter());
+ headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
+ assertSame(fullAdapter, headerViewListAdapter.getWrappedAdapter());
}
private class HeaderViewEmptyAdapter implements ListAdapter, Filterable {
- private HeaderViewFilterTest mFilter;
+ private final HeaderViewFilterTest mFilter;
public HeaderViewEmptyAdapter() {
mFilter = new HeaderViewFilterTest();
@@ -483,7 +502,7 @@
}
public boolean isEnabled(int position) {
- return false;
+ return true;
}
public void registerDataSetObserver(DataSetObserver observer) {
@@ -530,21 +549,18 @@
private class HeaderViewFullAdapter implements ListAdapter {
private DataSetObserver mObserver;
private Object mItem;
+ private final View mView = new View(getContext());
public DataSetObserver getDataSetObserver() {
return mObserver;
}
- public Object getItem() {
- return mItem;
- }
-
public boolean areAllItemsEnabled() {
return true;
}
public boolean isEnabled(int position) {
- return false;
+ return true;
}
public void registerDataSetObserver(DataSetObserver observer) {
@@ -577,7 +593,7 @@
}
public View getView(int position, View convertView, ViewGroup parent) {
- return null;
+ return mView;
}
public int getItemViewType(int position) {
@@ -585,7 +601,7 @@
}
public int getViewTypeCount() {
- return 2;
+ return 1;
}
public boolean isEmpty() {
diff --git a/tests/tests/widget/src/android/widget/cts/ImageViewTest.java b/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
index 2bf064c..5214b50 100644
--- a/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
@@ -478,10 +478,10 @@
public void testClearColorFilter() {
MockDrawable drawable = new MockDrawable();
ColorFilter cf = new ColorFilter();
- drawable.setColorFilter(cf);
ImageView imageView = new ImageView(mActivity);
imageView.setImageDrawable(drawable);
+ imageView.setColorFilter(cf);
imageView.clearColorFilter();
assertNull(drawable.getColorFilter());
diff --git a/tests/tests/widget/src/android/widget/cts/RatingBarTest.java b/tests/tests/widget/src/android/widget/cts/RatingBarTest.java
index 373e8e4..ab91129 100644
--- a/tests/tests/widget/src/android/widget/cts/RatingBarTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RatingBarTest.java
@@ -22,13 +22,10 @@
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
-import dalvik.annotation.ToBeFixed;
import android.content.Context;
-import android.graphics.drawable.Drawable;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
-import android.view.View.MeasureSpec;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
@@ -287,40 +284,6 @@
assertEquals(currentStepSize, ratingBar.getStepSize());
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test onMeasure(int widthMeasureSpec, int heightMeasureSpec)",
- method = "onMeasure",
- args = {int.class, int.class}
- )
- @ToBeFixed( bug = "1400249", explanation = "hard to test call back in unit test," +
- " will be tested by functional test.")
- public void testOnMeasure() {
- MockRatingBar mRatingBar = new MockRatingBar(mContext);
-
- mRatingBar.onMeasure(MeasureSpec.EXACTLY, MeasureSpec.EXACTLY);
- assertEquals(MeasureSpec.getSize(MeasureSpec.EXACTLY),
- mRatingBar.getMeasuredWidth());
- assertEquals(MeasureSpec.getSize(MeasureSpec.EXACTLY),
- mRatingBar.getMeasuredHeight());
-
- Drawable d = getActivity().getResources().getDrawable(R.drawable.blue);
- mRatingBar.setIndeterminateDrawable(d);
- mRatingBar.onMeasure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
-
- // TODO: this line appears to fail when density < 1. Need a cleaner way to handle this
- if (getActivity().getResources().getDisplayMetrics().density >= 1) {
- WidgetTestUtils.assertScaledPixels(285, mRatingBar.getMeasuredWidth(), getActivity());
- } else {
- assertEquals(285, mRatingBar.getMeasuredWidth());
- }
- assertEquals(57, mRatingBar.getMeasuredHeight());
-
- mRatingBar.onMeasure(MeasureSpec.AT_MOST, MeasureSpec.AT_MOST);
- assertEquals(0, mRatingBar.getMeasuredWidth());
- assertEquals(0, mRatingBar.getMeasuredHeight());
- }
-
/**
* The listener interface for receiving OnRatingBarChangeListener events.
* The class that is interested in processing a OnRatingBarChangeListener
diff --git a/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java b/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
index 10a63af..b852e5b 100644
--- a/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
@@ -546,8 +546,9 @@
mScrollView.smoothScrollBy(mScrollRight, mScrollBottom);
}
});
- delayedCheckSmoothScrolling(0, mScrollRight, 0, mScrollBottom);
- assertEquals(mScrollRight, mScrollView.getScrollX());
+ // smoothScrollBy doesn't scroll in X
+ delayedCheckSmoothScrolling(0, 0, 0, mScrollBottom);
+ assertEquals(0, mScrollView.getScrollX());
assertEquals(mScrollBottom, mScrollView.getScrollY());
runTestOnUiThread(new Runnable() {
@@ -574,8 +575,9 @@
mScrollView.smoothScrollTo(mScrollRight, mScrollBottom);
}
});
- delayedCheckSmoothScrolling(0, mScrollRight, 0, mScrollBottom);
- assertEquals(mScrollRight, mScrollView.getScrollX());
+ // smoothScrollTo doesn't scroll in X
+ delayedCheckSmoothScrolling(0, 0, 0, mScrollBottom);
+ assertEquals(0, mScrollView.getScrollX());
assertEquals(mScrollBottom, mScrollView.getScrollY());
runTestOnUiThread(new Runnable() {
@@ -583,8 +585,8 @@
mScrollView.smoothScrollTo(mPageWidth, mPageHeight);
}
});
- delayedCheckSmoothScrolling(mScrollRight, mPageWidth, mScrollBottom, mPageHeight);
- assertEquals(mPageWidth, mScrollView.getScrollX());
+ delayedCheckSmoothScrolling(0, 0, mScrollBottom, mPageHeight);
+ assertEquals(0, mScrollView.getScrollX());
assertEquals(mPageHeight, mScrollView.getScrollY());
}
diff --git a/tests/tests/widget/src/android/widget/cts/ScrollerTest.java b/tests/tests/widget/src/android/widget/cts/ScrollerTest.java
index dfd3c05..ecf1166 100644
--- a/tests/tests/widget/src/android/widget/cts/ScrollerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ScrollerTest.java
@@ -102,7 +102,7 @@
mScroller = new Scroller(mTargetContext);
assertEquals(0, mScroller.getDuration());
- mScroller.fling(0, 0, 3000, 4000, 0, 0, 0, 0);
+ mScroller.fling(0, 0, 10, 4000, 0, 100, 0, 0);
// the exact duration depends on implementation
assertTrue(mScroller.getDuration() > 0);
}
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index dcd2b05..4377785 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -82,7 +82,6 @@
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
-import android.view.WindowManager;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnLongClickListener;
@@ -974,9 +973,6 @@
setMinHeight(-1);
assertEquals(originalHeight, mTextView.getHeight());
- setMinHeight(Integer.MAX_VALUE);
- assertEquals(Integer.MAX_VALUE, mTextView.getHeight());
-
setMinHeight(0);
setMaxHeight(Integer.MAX_VALUE);
@@ -994,47 +990,23 @@
assertEquals(originalWidth >> 3, mTextView.getWidth());
- setMaxWidth(Integer.MAX_VALUE); // MAX
- assertEquals(1, mTextView.getLineCount());
- assertEquals(originalWidth, mTextView.getWidth());
// Min Width
- // Normal input
setMinWidth(originalWidth + 1);
assertEquals(1, mTextView.getLineCount());
assertEquals(originalWidth + 1, mTextView.getWidth());
setMinWidth(originalWidth - 1);
- assertEquals(1, mTextView.getLineCount());
- assertEquals(originalWidth, mTextView.getWidth());
+ assertEquals(2, mTextView.getLineCount());
+ assertEquals(originalWidth - 1, mTextView.getWidth());
- // Edge input
- setMinWidth(-1);
- assertEquals(1, mTextView.getLineCount());
- assertEquals(originalWidth, mTextView.getWidth());
-
- setMinWidth(Integer.MAX_VALUE);
- assertEquals(1, mTextView.getLineCount());
- String name = Context.WINDOW_SERVICE;
- WindowManager wm = (WindowManager) mActivity.getSystemService(name);
- assertEquals(wm.getDefaultDisplay().getWidth(), mTextView.getWidth());
// Width
- // Normal input
setWidth(originalWidth + 1);
assertEquals(1, mTextView.getLineCount());
assertEquals(originalWidth + 1, mTextView.getWidth());
setWidth(originalWidth - 1);
- assertTrue(1 < mTextView.getLineCount());
+ assertEquals(2, mTextView.getLineCount());
assertEquals(originalWidth - 1, mTextView.getWidth());
-
- // Edge input
- setWidth(-1);
- assertTrue(1 < mTextView.getLineCount());
- assertEquals(0, mTextView.getWidth());
-
- setWidth(Integer.MAX_VALUE);
- assertEquals(1, mTextView.getLineCount());
- assertEquals(wm.getDefaultDisplay().getWidth(), mTextView.getWidth());
}
@TestTargetNew(
@@ -1045,28 +1017,15 @@
public void testSetMinEms() {
mTextView = findTextView(R.id.textview_text);
assertEquals(1, mTextView.getLineCount());
+
int originalWidth = mTextView.getWidth();
int originalEms = originalWidth / mTextView.getLineHeight();
- // Normal input
setMinEms(originalEms + 1);
assertEquals((originalEms + 1) * mTextView.getLineHeight(), mTextView.getWidth());
setMinEms(originalEms - 1);
assertEquals(originalWidth, mTextView.getWidth());
-
- // Edge input
- setMinEms(-1);
- assertEquals(originalWidth, mTextView.getWidth());
-
- setMinEms(Integer.MAX_VALUE); // MAX
- assertEquals(originalWidth, mTextView.getWidth());
-
- setMinEms(Integer.MAX_VALUE / mTextView.getLineHeight());
- String name = Context.WINDOW_SERVICE;
- WindowManager wm = (WindowManager) mActivity.getSystemService(name);
- int expected = wm.getDefaultDisplay().getWidth();
- assertEquals(expected, mTextView.getWidth());
}
@TestTargetNew(
@@ -1080,7 +1039,6 @@
int originalWidth = mTextView.getWidth();
int originalEms = originalWidth / mTextView.getLineHeight();
- // Normal input
setMaxEms(originalEms + 1);
assertEquals(1, mTextView.getLineCount());
assertEquals(originalWidth, mTextView.getWidth());
@@ -1089,19 +1047,6 @@
assertTrue(1 < mTextView.getLineCount());
assertEquals((originalEms - 1) * mTextView.getLineHeight(),
mTextView.getWidth());
-
- // Edge input
- setMaxEms(-1);
- assertTrue(1 < mTextView.getLineCount());
- assertEquals(0, mTextView.getWidth());
-
- setMaxEms(Integer.MAX_VALUE); // MAX
- assertTrue(1 < mTextView.getLineCount());
- assertEquals(0, mTextView.getWidth());
-
- setMaxEms(Integer.MAX_VALUE / mTextView.getLineHeight());
- assertEquals(1, mTextView.getLineCount());
- assertEquals(originalWidth, mTextView.getWidth());
}
@TestTargetNew(
@@ -1115,7 +1060,6 @@
int originalWidth = mTextView.getWidth();
int originalEms = originalWidth / mTextView.getLineHeight();
- // Normal input
setEms(originalEms + 1);
assertEquals(1, mTextView.getLineCount());
assertEquals((originalEms + 1) * mTextView.getLineHeight(),
@@ -1125,22 +1069,6 @@
assertTrue((1 < mTextView.getLineCount()));
assertEquals((originalEms - 1) * mTextView.getLineHeight(),
mTextView.getWidth());
-
- // Edge input
- setEms(-1);
- assertTrue((1 < mTextView.getLineCount()));
- assertEquals(0, mTextView.getWidth());
-
- setEms(Integer.MAX_VALUE); // MAX
- assertTrue((1 < mTextView.getLineCount()));
- assertEquals(0, mTextView.getWidth());
-
- setEms(Integer.MAX_VALUE / mTextView.getLineHeight());
- assertEquals(1, mTextView.getLineCount());
- String name = Context.WINDOW_SERVICE;
- WindowManager wm = (WindowManager) mActivity.getSystemService(name);
- int expected = wm.getDefaultDisplay().getWidth();
- assertEquals(expected, mTextView.getWidth());
}
@TestTargetNew(
@@ -2851,19 +2779,11 @@
int originalHeight = mTextView.getHeight();
int originalLines = mTextView.getLineCount();
- // Normal input
setMinLines(originalLines - 1);
assertTrue((originalLines - 1) * mTextView.getLineHeight() <= mTextView.getHeight());
setMinLines(originalLines + 1);
assertTrue((originalLines + 1) * mTextView.getLineHeight() <= mTextView.getHeight());
-
- // Edge input
- setMinLines(-1);
- assertEquals(originalHeight, mTextView.getHeight());
-
- setMinLines(Integer.MAX_VALUE);
- assertEquals(0, mTextView.getHeight());
}
@TestTargetNew(
diff --git a/tests/tests/widget/src/android/widget/cts/TimePickerTest.java b/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
index 18ea14f..881693f 100644
--- a/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
@@ -300,8 +300,8 @@
public void testOnSaveInstanceStateAndOnRestoreInstanceState() {
MyTimePicker source = new MyTimePicker(mContext);
MyTimePicker dest = new MyTimePicker(mContext);
- int expectHour = dest.getCurrentHour() + 10;
- int expectMinute = dest.getCurrentMinute() + 10;
+ int expectHour = (dest.getCurrentHour() + 10) % 24;
+ int expectMinute = (dest.getCurrentMinute() + 10) % 60;
source.setCurrentHour(expectHour);
source.setCurrentMinute(expectMinute);
diff --git a/tools/utils/buildCts.py b/tools/utils/buildCts.py
index 1f1967f..b3e9183 100755
--- a/tools/utils/buildCts.py
+++ b/tools/utils/buildCts.py
@@ -93,7 +93,7 @@
# Annotation classes are also required, since test annotations go into the description.
source_path = [
'frameworks/base/core/java', # android test classes
- 'frameworks/base/test-runner', # test runner
+ 'frameworks/base/test-runner/src', # test runner
'dalvik/libcore/junit/src/main/java', # junit classes
'development/tools/hosttestlib/src', # hosttestlib TestCase extensions
'dalvik/libcore/dalvik/src/main/java', # test annotations