Merge "Fix TextViewTest#testAccessError" into honeycomb
diff --git a/tests/src/android/provider/cts/FileCopyHelper.java b/tests/src/android/provider/cts/FileCopyHelper.java
index a9c53e5..011f551 100644
--- a/tests/src/android/provider/cts/FileCopyHelper.java
+++ b/tests/src/android/provider/cts/FileCopyHelper.java
@@ -18,6 +18,8 @@
import android.content.Context;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -95,4 +97,14 @@
mContext.deleteFile(path);
}
}
+
+ public static void createFile(File file, int numBytes) throws IOException {
+ byte[] buffer = new byte[numBytes];
+ FileOutputStream output = new FileOutputStream(file);
+ try {
+ output.write(buffer);
+ } finally {
+ output.close();
+ }
+ }
}
diff --git a/tests/tests/app/src/android/app/cts/ServiceTest.java b/tests/tests/app/src/android/app/cts/ServiceTest.java
index 7f6fe94..0b2b767 100644
--- a/tests/tests/app/src/android/app/cts/ServiceTest.java
+++ b/tests/tests/app/src/android/app/cts/ServiceTest.java
@@ -16,6 +16,11 @@
package android.app.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
@@ -27,10 +32,6 @@
import android.os.Parcel;
import android.os.RemoteException;
import android.test.suitebuilder.annotation.MediumTest;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
@TestTargetClass(Service.class)
public class ServiceTest extends ActivityTestsBase {
@@ -49,8 +50,8 @@
private Intent mLocalService;
private Intent mLocalDeniedService;
private Intent mLocalGrantedService;
- private Intent mLocalServiceGranted;
- private Intent mLocalServiceDenied;
+ private Intent mLocalService_ApplicationHasPermission;
+ private Intent mLocalService_ApplicationDoesNotHavePermission;
private IBinder mStateReceiver;
@@ -317,8 +318,8 @@
mLocalService = new Intent(mContext, LocalService.class);
mLocalDeniedService = new Intent(mContext, LocalDeniedService.class);
mLocalGrantedService = new Intent(mContext, LocalGrantedService.class);
- mLocalServiceGranted = new Intent(LocalService.SERVICE_LOCAL_GRANTED);
- mLocalServiceDenied = new Intent(LocalService.SERVICE_LOCAL_DENIED);
+ mLocalService_ApplicationHasPermission = new Intent(LocalService.SERVICE_LOCAL_GRANTED);
+ mLocalService_ApplicationDoesNotHavePermission = new Intent(LocalService.SERVICE_LOCAL_DENIED);
mStateReceiver = new MockBinder();
}
@@ -388,7 +389,7 @@
super.tearDown();
mContext.stopService(mLocalService);
mContext.stopService(mLocalGrantedService);
- mContext.stopService(mLocalServiceGranted);
+ mContext.stopService(mLocalService_ApplicationHasPermission);
}
@TestTargets({
@@ -634,8 +635,9 @@
)
})
@MediumTest
- public void testLocalStartClassPermissionGranted() throws Exception {
+ public void testLocalStartClassPermissions() throws Exception {
startExpectResult(mLocalGrantedService);
+ startExpectResult(mLocalDeniedService);
}
@TestTargets({
@@ -666,8 +668,9 @@
)
})
@MediumTest
- public void testLocalStartActionPermissionGranted() throws Exception {
- startExpectResult(mLocalServiceGranted);
+ public void testLocalStartActionPermissions() throws Exception {
+ startExpectResult(mLocalService_ApplicationHasPermission);
+ startExpectResult(mLocalService_ApplicationDoesNotHavePermission);
}
@TestTargets({
@@ -698,8 +701,9 @@
)
})
@MediumTest
- public void testLocalBindClassPermissionGranted() throws Exception {
+ public void testLocalBindClassPermissions() throws Exception {
bindExpectResult(mLocalGrantedService);
+ bindExpectResult(mLocalDeniedService);
}
@TestTargets({
@@ -730,8 +734,9 @@
)
})
@MediumTest
- public void testLocalBindActionPermissionGranted() throws Exception {
- bindExpectResult(mLocalServiceGranted);
+ public void testLocalBindActionPermissions() throws Exception {
+ bindExpectResult(mLocalService_ApplicationHasPermission);
+ bindExpectResult(mLocalService_ApplicationDoesNotHavePermission);
}
@TestTargets({
@@ -795,135 +800,7 @@
})
@MediumTest
public void testLocalBindAutoActionPermissionGranted() throws Exception {
- bindAutoExpectResult(mLocalServiceGranted);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onStart",
- args = {android.content.Intent.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onDestroy",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onBind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onRebind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onUnbind",
- args = {android.content.Intent.class}
- )
- })
- @MediumTest
- public void testLocalStartClassPermissionDenied() throws Exception {
- startExpectNoPermission(mLocalDeniedService);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onStart",
- args = {android.content.Intent.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onDestroy",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onBind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onRebind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onUnbind",
- args = {android.content.Intent.class}
- )
- })
- @MediumTest
- public void testLocalStartActionPermissionDenied() throws Exception {
- startExpectNoPermission(mLocalServiceDenied);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onStart",
- args = {android.content.Intent.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onDestroy",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onBind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onRebind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onUnbind",
- args = {android.content.Intent.class}
- )
- })
- @MediumTest
- public void testLocalBindClassPermissionDenied() throws Exception {
- bindExpectNoPermission(mLocalDeniedService);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onStart",
- args = {android.content.Intent.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onDestroy",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onBind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onRebind",
- args = {android.content.Intent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onUnbind",
- args = {android.content.Intent.class}
- )
- })
- @MediumTest
- public void testLocalBindActionPermissionDenied() throws Exception {
- bindExpectNoPermission(mLocalServiceDenied);
+ bindAutoExpectResult(mLocalService_ApplicationHasPermission);
}
@TestTargets({
@@ -957,7 +834,7 @@
public void testLocalUnbindTwice() throws Exception {
EmptyConnection conn = new EmptyConnection();
mContext.bindService(
- mLocalServiceGranted, conn, 0);
+ mLocalService_ApplicationHasPermission, conn, 0);
mContext.unbindService(conn);
try {
mContext.unbindService(conn);
diff --git a/tests/tests/content/src/android/content/cts/ContextTest.java b/tests/tests/content/src/android/content/cts/ContextTest.java
index 3eac36a..b662162 100644
--- a/tests/tests/content/src/android/content/cts/ContextTest.java
+++ b/tests/tests/content/src/android/content/cts/ContextTest.java
@@ -16,7 +16,14 @@
package android.content.cts;
-import java.io.IOException;
+import com.android.cts.stub.R;
+import com.android.internal.util.XmlUtils;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
import org.xmlpull.v1.XmlPullParserException;
@@ -28,14 +35,7 @@
import android.util.AttributeSet;
import android.util.Xml;
-import com.android.cts.stub.R;
-import com.android.internal.util.XmlUtils;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
+import java.io.IOException;
@TestTargetClass(Context.class)
public class ContextTest extends AndroidTestCase {
@@ -132,7 +132,6 @@
args = {android.util.AttributeSet.class, int[].class}
)
})
- @ToBeFixed(bug=" ", explanation = "Wrong resource ID can not result in a exception.")
public void testObtainStyledAttributes() {
// Test obtainStyledAttributes(int[])
TypedArray testTypedArray = mContext
@@ -165,17 +164,18 @@
testTypedArray.recycle();
// Test obtainStyledAttributes(AttributeSet, int[])
+ int[] attrs = android.R.styleable.DatePicker;
testTypedArray = mContext.obtainStyledAttributes(getAttributeSet(R.layout.context_layout),
- com.android.internal.R.styleable.DatePicker);
+ attrs);
assertNotNull(testTypedArray);
- assertEquals(2, testTypedArray.length());
+ assertEquals(attrs.length, testTypedArray.length());
testTypedArray.recycle();
// Test obtainStyledAttributes(AttributeSet, int[], int, int)
testTypedArray = mContext.obtainStyledAttributes(getAttributeSet(R.layout.context_layout),
- com.android.internal.R.styleable.DatePicker, 0, 0);
+ attrs, 0, 0);
assertNotNull(testTypedArray);
- assertEquals(2, testTypedArray.length());
+ assertEquals(attrs.length, testTypedArray.length());
testTypedArray.recycle();
}
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 d608c2f..c684a69 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java
@@ -249,12 +249,7 @@
assertEquals(3, c.getInt(0));
// close the database and see if requery throws an exception
mDatabase.close();
- try {
- c.requery();
- fail("expected IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
+ assertFalse(c.requery());
}
@TestTargets({
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
index f2410f1..8e8d650 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
@@ -35,10 +35,10 @@
import android.provider.MediaStore.Images.Media;
import android.provider.MediaStore.Images.Thumbnails;
import android.test.InstrumentationTestCase;
-import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -247,11 +247,15 @@
assertNull(mContentResolver.query(Media.getContentUri(volume), null, null, null, null));
}
- public void testStoreImagesMediaExternal() {
+ public void testStoreImagesMediaExternal() throws Exception {
final String externalPath = Environment.getExternalStorageDirectory().getPath() +
"/testimage.jpg";
final String externalPath2 = Environment.getExternalStorageDirectory().getPath() +
"/testimage1.jpg";
+
+ int numBytes = 1337;
+ FileCopyHelper.createFile(new File(externalPath), numBytes);
+
ContentValues values = new ContentValues();
values.put(Media.ORIENTATION, 0);
values.put(Media.PICASA_ID, 0);
@@ -265,7 +269,7 @@
values.put(Media.DATA, externalPath);
values.put(Media.DISPLAY_NAME, "testimage");
values.put(Media.MIME_TYPE, "image/jpeg");
- values.put(Media.SIZE, 86853);
+ values.put(Media.SIZE, numBytes);
values.put(Media.TITLE, "testimage");
long dateAdded = System.currentTimeMillis() / 1000;
values.put(Media.DATE_ADDED, dateAdded);
@@ -296,7 +300,7 @@
assertEquals("testimage", c.getString(c.getColumnIndex(Media.DISPLAY_NAME)));
assertEquals("image/jpeg", c.getString(c.getColumnIndex(Media.MIME_TYPE)));
assertEquals("testimage", c.getString(c.getColumnIndex(Media.TITLE)));
- assertEquals(86853, c.getInt(c.getColumnIndex(Media.SIZE)));
+ assertEquals(numBytes, c.getInt(c.getColumnIndex(Media.SIZE)));
long realDateAdded = c.getLong(c.getColumnIndex(Media.DATE_ADDED));
assertTrue(realDateAdded >= dateAdded);
assertEquals(dateModified, c.getLong(c.getColumnIndex(Media.DATE_MODIFIED)));
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java
index 9a720e5..6f7842c 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java
@@ -29,6 +29,8 @@
import android.provider.MediaStore.Video.Media;
import android.test.InstrumentationTestCase;
+import java.io.File;
+
@TestTargetClass(MediaStore.Video.Media.class)
public class MediaStore_Video_MediaTest extends InstrumentationTestCase {
private ContentResolver mContentResolver;
@@ -56,11 +58,15 @@
assertNull(mContentResolver.query(Media.getContentUri(volume), null, null, null, null));
}
- public void testStoreVideoMediaExternal() {
+ public void testStoreVideoMediaExternal() throws Exception {
final String externalVideoPath = Environment.getExternalStorageDirectory().getPath() +
"/video/testvideo.3gp";
final String externalVideoPath2 = Environment.getExternalStorageDirectory().getPath() +
"/video/testvideo1.3gp";
+
+ int numBytes = 1337;
+ FileCopyHelper.createFile(new File(externalVideoPath), numBytes);
+
ContentValues values = new ContentValues();
values.put(Media.ALBUM, "cts");
values.put(Media.ARTIST, "cts team");
@@ -79,11 +85,11 @@
values.put(Media.DATA, externalVideoPath);
values.put(Media.DISPLAY_NAME, "testvideo");
values.put(Media.MIME_TYPE, "video/3gpp");
- values.put(Media.SIZE, 86853);
+ values.put(Media.SIZE, numBytes);
values.put(Media.TITLE, "testvideo");
- long dateAdded = System.currentTimeMillis();
+ long dateAdded = System.currentTimeMillis() / 1000;
values.put(Media.DATE_ADDED, dateAdded);
- long dateModified = System.currentTimeMillis();
+ long dateModified = System.currentTimeMillis() / 1000;
values.put(Media.DATE_MODIFIED, dateModified);
// insert
@@ -115,9 +121,9 @@
assertEquals("testvideo.3gp", c.getString(c.getColumnIndex(Media.DISPLAY_NAME)));
assertEquals("video/3gpp", c.getString(c.getColumnIndex(Media.MIME_TYPE)));
assertEquals("testvideo", c.getString(c.getColumnIndex(Media.TITLE)));
- assertEquals(86853, c.getInt(c.getColumnIndex(Media.SIZE)));
+ assertEquals(numBytes, c.getInt(c.getColumnIndex(Media.SIZE)));
long realDateAdded = c.getLong(c.getColumnIndex(Media.DATE_ADDED));
- assertTrue(realDateAdded > 0);
+ assertTrue(realDateAdded >= dateAdded);
assertEquals(dateModified, c.getLong(c.getColumnIndex(Media.DATE_MODIFIED)));
c.close();
diff --git a/tests/tests/widget/src/android/widget/cts/TimePickerTest.java b/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
index 881693f..8287ae6 100644
--- a/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
@@ -136,20 +136,19 @@
int initialHour = 13;
int initialMinute = 50;
mTimePicker = new TimePicker(mContext);
- mTimePicker.setCurrentHour(Integer.valueOf(initialHour));
- mTimePicker.setCurrentMinute(Integer.valueOf(initialMinute));
+
MockOnTimeChangeListener listener = new MockOnTimeChangeListener();
mTimePicker.setOnTimeChangedListener(listener);
+ mTimePicker.setCurrentHour(Integer.valueOf(initialHour));
+ mTimePicker.setCurrentMinute(Integer.valueOf(initialMinute));
+ assertEquals(initialHour, listener.getNotifiedHourOfDay());
+ assertEquals(initialMinute, listener.getNotifiedMinute());
// set the same hour as current
listener.reset();
mTimePicker.setCurrentHour(Integer.valueOf(initialHour));
- assertTrue(listener.hasCalledOnTimeChanged());
- assertEquals(initialHour, listener.getNotifiedHourOfDay());
- assertEquals(initialMinute, listener.getNotifiedMinute());
- assertSame(mTimePicker, listener.getNotifiedView());
+ assertFalse(listener.hasCalledOnTimeChanged());
- listener.reset();
mTimePicker.setCurrentHour(Integer.valueOf(initialHour + 1));
assertTrue(listener.hasCalledOnTimeChanged());
assertEquals(initialHour + 1, listener.getNotifiedHourOfDay());
@@ -159,10 +158,7 @@
// set the same minute as current
listener.reset();
mTimePicker.setCurrentMinute(initialMinute);
- assertTrue(listener.hasCalledOnTimeChanged());
- assertEquals(initialHour + 1, listener.getNotifiedHourOfDay());
- assertEquals(initialMinute, listener.getNotifiedMinute());
- assertSame(mTimePicker, listener.getNotifiedView());
+ assertFalse(listener.hasCalledOnTimeChanged());
listener.reset();
mTimePicker.setCurrentMinute(initialMinute + 1);
@@ -174,10 +170,7 @@
// change time picker mode
listener.reset();
mTimePicker.setIs24HourView( !mTimePicker.is24HourView() );
- assertTrue(listener.hasCalledOnTimeChanged());
- assertEquals(initialHour + 1, listener.getNotifiedHourOfDay());
- assertEquals(initialMinute + 1, listener.getNotifiedMinute());
- assertSame(mTimePicker, listener.getNotifiedView());
+ assertFalse(listener.hasCalledOnTimeChanged());
}
@TestTargets({