am 4841ff58: am 91291a1f: am 7ae74408: am a59ff92b: Merge "Nuke Problematic ContextWrapperTest" into froyo
* commit '4841ff58bbc23dc5a299733826898e33a37fbb95':
Nuke Problematic ContextWrapperTest
diff --git a/tests/accessibilityservice/res/values/strings.xml b/tests/accessibilityservice/res/values/strings.xml
index 4c717c1..3730f85 100644
--- a/tests/accessibilityservice/res/values/strings.xml
+++ b/tests/accessibilityservice/res/values/strings.xml
@@ -20,31 +20,4 @@
<!-- String title of the mock accessibility service -->
<string name="title_delegating_accessibility_service">Delegating Accessibility Service</string>
- <!-- String title of the accessibility end-to-end test activity -->
- <string name="accessibility_end_to_end_test_activity">End-to-end test</string>
-
- <!-- String value of used as text input -->
- <string name="text_input_blah">Blah</string>
-
- <!-- String value of used as text input -->
- <string name="text_input_blah_blah">Blah blah</string>
-
- <!-- String title of the button -->
- <string name="button_title">Click me</string>
-
- <!-- String value of the first list item -->
- <string name="first_list_item">First list item</string>
-
- <!-- String value of the second list item -->
- <string name="second_list_item">Second list item</string>
-
- <!-- String alert title -->
- <string name="alert_title">Alert title</string>
-
- <!-- String alert message -->
- <string name="alert_message">Alert message</string>
-
- <!-- String notification message -->
- <string name="notification_message">Notification message</string>
-
</resources>
diff --git a/tests/appsecurity-tests/test-apps/PermissionDeclareApp/AndroidManifest.xml b/tests/appsecurity-tests/test-apps/PermissionDeclareApp/AndroidManifest.xml
index 683ec9e..de71966 100644
--- a/tests/appsecurity-tests/test-apps/PermissionDeclareApp/AndroidManifest.xml
+++ b/tests/appsecurity-tests/test-apps/PermissionDeclareApp/AndroidManifest.xml
@@ -31,6 +31,8 @@
<application>
<receiver android:name="GrantUriPermission" android:exported="true">
</receiver>
+ <receiver android:name="SetInstallerPackage" android:exported="true">
+ </receiver>
<!-- Need a way for another app to try to access the permission. So create a content
provider which is enforced by the permission -->
diff --git a/tests/appsecurity-tests/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/GrantUriPermission.java b/tests/appsecurity-tests/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/GrantUriPermission.java
index 8c14575..31a3f47 100644
--- a/tests/appsecurity-tests/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/GrantUriPermission.java
+++ b/tests/appsecurity-tests/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/GrantUriPermission.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package com.android.cts.permissiondeclareapp;
import android.content.BroadcastReceiver;
diff --git a/tests/appsecurity-tests/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/SetInstallerPackage.java b/tests/appsecurity-tests/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/SetInstallerPackage.java
new file mode 100644
index 0000000..ea06d8c
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/SetInstallerPackage.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.permissiondeclareapp;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+public class SetInstallerPackage extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String targetPackage = intent.getStringExtra("target");
+ String installerPackage = intent.getStringExtra("installer");
+ try {
+ context.getPackageManager().setInstallerPackageName(targetPackage, installerPackage);
+ if (isOrderedBroadcast()) {
+ setResultCode(101);
+ }
+ } catch (SecurityException e) {
+ Log.i("SetInstallerPackage", "Security exception", e);
+ if (isOrderedBroadcast()) {
+ setResultCode(100);
+ }
+ }
+ }
+}
diff --git a/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/ModifyInstallerPackageTest.java b/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/ModifyInstallerPackageTest.java
new file mode 100644
index 0000000..989e24b
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/ModifyInstallerPackageTest.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.usespermissiondiffcertapp;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.SystemClock;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+/**
+ * Tests that one application can and can not modify the installer package
+ * of another application is appropriate.
+ *
+ * Accesses app cts/tests/appsecurity-tests/test-apps/PermissionDeclareApp/...
+ */
+public class ModifyInstallerPackageTest extends AndroidTestCase {
+ static final ComponentName SET_INSTALLER_PACKAGE_COMP
+ = new ComponentName("com.android.cts.permissiondeclareapp",
+ "com.android.cts.permissiondeclareapp.SetInstallerPackage");
+ static final String OTHER_PACKAGE = "com.android.cts.permissiondeclareapp";
+ static final String MY_PACKAGE = "com.android.cts.usespermissiondiffcertapp";
+
+ static class SetInstallerPackageReceiver extends BroadcastReceiver {
+ boolean mHaveResult = false;
+ boolean mGoodResult = false;
+ boolean mSucceeded = false;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ synchronized (this) {
+ mHaveResult = true;
+ switch (getResultCode()) {
+ case 100:
+ mGoodResult = true;
+ mSucceeded = false;
+ break;
+ case 101:
+ mGoodResult = true;
+ mSucceeded = true;
+ break;
+ default:
+ mGoodResult = false;
+ break;
+ }
+ notifyAll();
+ }
+ }
+
+ void assertSuccess(String failureMessage) {
+ synchronized (this) {
+ final long startTime = SystemClock.uptimeMillis();
+ while (!mHaveResult) {
+ try {
+ wait(5000);
+ } catch (InterruptedException e) {
+ }
+ if (SystemClock.uptimeMillis() >= (startTime+5000)) {
+ throw new RuntimeException("Timeout");
+ }
+ }
+ if (!mGoodResult) {
+ fail("Broadcast receiver did not return good result");
+ }
+ if (!mSucceeded) {
+ fail(failureMessage);
+ }
+ }
+ }
+
+ void assertFailure(String failureMessage) {
+ synchronized (this) {
+ final long startTime = SystemClock.uptimeMillis();
+ while (!mHaveResult) {
+ try {
+ wait(5000);
+ } catch (InterruptedException e) {
+ }
+ if (SystemClock.uptimeMillis() >= (startTime+5000)) {
+ throw new RuntimeException("Timeout");
+ }
+ }
+ if (!mGoodResult) {
+ fail("Broadcast receiver did not return good result");
+ }
+ if (mSucceeded) {
+ fail(failureMessage);
+ }
+ }
+ }
+ }
+
+ PackageManager getPackageManager() {
+ return getContext().getPackageManager();
+ }
+
+ /**
+ * Test that we can set the installer package name.
+ */
+ public void testSetInstallPackage() {
+ // Pre-condition.
+ assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+
+ getPackageManager().setInstallerPackageName(OTHER_PACKAGE, MY_PACKAGE);
+ assertEquals(MY_PACKAGE, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+
+ // Clean up.
+ getPackageManager().setInstallerPackageName(OTHER_PACKAGE, null);
+ assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+ }
+
+ /**
+ * Test that we fail if trying to set an installer package with an unknown
+ * target package name.
+ */
+ public void testSetInstallPackageBadTarget() {
+ try {
+ getPackageManager().setInstallerPackageName("thisdoesnotexistihope!", MY_PACKAGE);
+ fail("setInstallerPackageName did not throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // That's what we want!
+ }
+ }
+
+ /**
+ * Test that we fail if trying to set an installer package with an unknown
+ * installer package name.
+ */
+ public void testSetInstallPackageBadInstaller() {
+ try {
+ getPackageManager().setInstallerPackageName(OTHER_PACKAGE, "thisdoesnotexistihope!");
+ fail("setInstallerPackageName did not throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // That's what we want!
+ }
+ assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+ }
+
+ /**
+ * Test that we fail if trying to set an installer package that is not
+ * signed with our cert.
+ */
+ public void testSetInstallPackageWrongCertificate() {
+ // Pre-condition.
+ assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+
+ try {
+ getPackageManager().setInstallerPackageName(OTHER_PACKAGE, OTHER_PACKAGE);
+ fail("setInstallerPackageName did not throw SecurityException");
+ } catch (SecurityException e) {
+ // That's what we want!
+ }
+
+ assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+ }
+
+ /**
+ * Test that we fail if trying to set an installer package that is not
+ * signed with the same cert as the currently set installer.
+ */
+ public void testSetInstallPackageConflictingInstaller() {
+ // Pre-condition.
+ assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+
+ // Have the other package set the installer, under its cert.
+ Intent intent = new Intent();
+ intent.setComponent(SET_INSTALLER_PACKAGE_COMP);
+ intent.putExtra("target", OTHER_PACKAGE);
+ intent.putExtra("installer", OTHER_PACKAGE);
+ SetInstallerPackageReceiver receiver = new SetInstallerPackageReceiver();
+ getContext().sendOrderedBroadcast(intent, null, receiver, null, 0, null, null);
+ receiver.assertSuccess("Failure initializing with other installer");
+
+ assertEquals(OTHER_PACKAGE, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+
+ try {
+ getPackageManager().setInstallerPackageName(OTHER_PACKAGE, MY_PACKAGE);
+ fail("setInstallerPackageName did not throw SecurityException");
+ } catch (SecurityException e) {
+ // That's what we want!
+ }
+
+ assertEquals(OTHER_PACKAGE, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+
+ // Now clear the installer
+ intent.putExtra("target", OTHER_PACKAGE);
+ intent.putExtra("installer", (String)null);
+ receiver = new SetInstallerPackageReceiver();
+ getContext().sendOrderedBroadcast(intent, null, receiver, null, 0, null, null);
+ receiver.assertSuccess("Failure clearing other installer");
+
+ assertEquals(null, getPackageManager().getInstallerPackageName(OTHER_PACKAGE));
+ }
+}
diff --git a/tests/core/luni-io/Android.mk b/tests/core/luni-io/Android.mk
index ed39e03..6669c6a 100644
--- a/tests/core/luni-io/Android.mk
+++ b/tests/core/luni-io/Android.mk
@@ -24,7 +24,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under,../../../../libcore/luni/src/test/java/tests/api/java/io) \
- $(call all-java-files-under,../../../../libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io) \
+ $(call all-java-files-under,../../../../libcore/luni/src/test/java/libcore/java/io) \
$(call all-java-files-under,../../../../libcore/support/src/test/java/) \
$(call all-java-files-under,../../../../libcore/luni/src/test/java/org/apache/harmony/luni/tests/pkg1) \
$(call all-java-files-under,../../../../libcore/luni/src/test/java/org/apache/harmony/luni/tests/pkg2) \
diff --git a/tests/core/luni-lang/Android.mk b/tests/core/luni-lang/Android.mk
index a31b881..c3528ec 100644
--- a/tests/core/luni-lang/Android.mk
+++ b/tests/core/luni-lang/Android.mk
@@ -23,7 +23,7 @@
##########################################################
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(call all-java-files-under,../../../../libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/lang) \
+LOCAL_SRC_FILES := \
$(call all-java-files-under,../../../../libcore/luni/src/test/java/tests/api/java/lang) \
$(call all-java-files-under,../../../../libcore/support/src/test/java/) \
../../../../libcore/luni/src/test/java/tests/luni/AllTestsLang.java
diff --git a/tests/core/xml/Android.mk b/tests/core/xml/Android.mk
index 4f8af07..0f643a0 100644
--- a/tests/core/xml/Android.mk
+++ b/tests/core/xml/Android.mk
@@ -26,7 +26,6 @@
LOCAL_SRC_FILES := $(call all-java-files-under,../../../../libcore/xml/src/test/java) \
$(call all-java-files-under,../../../../libcore/dom/src/test) \
$(call all-java-files-under,../../../../libcore/junit/src/test/java/junit) \
- $(call all-java-files-under,../../../../libcore/luni/src/test/java/org/apache/harmony/xml) \
$(call all-java-files-under,../../../../libcore/luni/src/test/java/tests/api/javax/xml/parsers) \
$(call all-java-files-under,../../../../libcore/luni/src/test/java/tests/api/org/xml/sax) \
$(call all-java-files-under,../../../../libcore/luni/src/test/java/tests/api/org/xml/sax/support) \
diff --git a/tests/res/drawable/mipmapdrawable.xml b/tests/res/drawable/mipmapdrawable.xml
new file mode 100644
index 0000000..fc6342c
--- /dev/null
+++ b/tests/res/drawable/mipmapdrawable.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<mipmap xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/testimage"/>
+ <item android:drawable="@drawable/start"/>
+</mipmap>
+
diff --git a/tests/res/layout/dialog_stub_layout.xml b/tests/res/layout/dialog_stub_layout.xml
index 11b502f..b0a8861 100644
--- a/tests/res/layout/dialog_stub_layout.xml
+++ b/tests/res/layout/dialog_stub_layout.xml
@@ -14,65 +14,8 @@
limitations under the License.
-->
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
- android:layout_width="match_parent" android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent" android:layout_height="match_parent"
- android:orientation="vertical">
- <Button android:id="@+id/dialog_test_button_1"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button1"/>
- <Button android:id="@+id/dialog_test_button_2"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button2"/>
- <Button android:id="@+id/dialog_test_button_3"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button3"/>
- <Button android:id="@+id/dialog_test_button_4"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button4"/>
- <Button android:id="@+id/dialog_test_button_5"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button5"/>
- <Button android:id="@+id/dialog_test_button_6"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button6"/>
- <Button android:id="@+id/dialog_test_button_7"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button7"/>
- <Button android:id="@+id/dialog_test_button_8"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button8"/>
- <Button android:id="@+id/dialog_test_button_9"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button9"/>
- <Button android:id="@+id/dialog_test_button_10"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button10"/>
- <Button android:id="@+id/dialog_test_button_11"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button11"/>
- <Button android:id="@+id/dialog_test_button_12"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button12"/>
- <Button android:id="@+id/dialog_test_button_13"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button13"/>
- <Button android:id="@+id/dialog_test_button_14"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button14"/>
- <Button android:id="@+id/dialog_test_button_15"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button15"/>
- <Button android:id="@+id/dialog_test_button_16"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button16"/>
- <Button android:id="@+id/dialog_test_button_17"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button17"/>
- <Button android:id="@+id/dialog_test_button_18"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:text="@string/dialog_stub_dialog_test_button18"/>
- </LinearLayout>
-</ScrollView>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ >
+</LinearLayout>
diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml
index a779b47..8fcd75a 100644
--- a/tests/res/values/strings.xml
+++ b/tests/res/values/strings.xml
@@ -40,24 +40,6 @@
<string name="text">DialogTest</string>
<string name="text_country">Country</string>
<string name="text_name">Name</string>
- <string name="dialog_stub_dialog_test_button1">Test Dialog without theme</string>
- <string name="dialog_stub_dialog_test_button2">Test Dialog with theme</string>
- <string name="dialog_stub_dialog_test_button3">Test AlertDialog</string>
- <string name="dialog_stub_dialog_test_button4">Test AlertDialog with theme</string>
- <string name="dialog_stub_dialog_test_button5">Test DatePickerDialog</string>
- <string name="dialog_stub_dialog_test_button6">Test DatePickerDialog with theme</string>
- <string name="dialog_stub_dialog_test_button7">Test TimePickerDialog</string>
- <string name="dialog_stub_dialog_test_button8">Test TimePickerDialog with theme</string>
- <string name="dialog_stub_dialog_test_button9">Test onStart() and onStop()</string>
- <string name="dialog_stub_dialog_test_button10">Test AlertDialog deprecated</string>
- <string name="dialog_stub_dialog_test_button11">Test AlertDialog callback</string>
- <string name="dialog_stub_dialog_test_button12">Test AlertDialog setview </string>
- <string name="dialog_stub_dialog_test_button13">Test AlertDialog deprecated with Message</string>
- <string name="dialog_stub_dialog_test_button14">Test AlertDialog with theme</string>
- <string name="dialog_stub_dialog_test_button15">Test AlertDialog cancelable</string>
- <string name="dialog_stub_dialog_test_button16">Test AlertDialog can\'n cancelable</string>
- <string name="dialog_stub_dialog_test_button17">Test Dialog cancelable</string>
- <string name="dialog_stub_dialog_test_button18">Test Dialog not cancelable</string>
<string name="hello_world">Hello, World!</string>
<string name="hello_android">Hello, Android!</string>
<string name="alert_dialog_username">Name:</string>
diff --git a/tests/res/xml/mipmap_correct.xml b/tests/res/xml/mipmap_correct.xml
new file mode 100644
index 0000000..46cc360
--- /dev/null
+++ b/tests/res/xml/mipmap_correct.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+-->
+
+<mipmap xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:drawable="@drawable/testimage" />
+ <item>
+ <color android:color="#77ffffff" />
+ </item>
+ <item android:drawable="@drawable/start" />
+</mipmap>
+
diff --git a/tests/res/xml/mipmap_missing_item_drawable.xml b/tests/res/xml/mipmap_missing_item_drawable.xml
new file mode 100644
index 0000000..4ef6ec7
--- /dev/null
+++ b/tests/res/xml/mipmap_missing_item_drawable.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+-->
+
+<mipmap xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item/>
+</mipmap>
+
diff --git a/tests/src/android/app/cts/DialogStubActivity.java b/tests/src/android/app/cts/DialogStubActivity.java
index f715b51..817e716 100644
--- a/tests/src/android/app/cts/DialogStubActivity.java
+++ b/tests/src/android/app/cts/DialogStubActivity.java
@@ -16,6 +16,8 @@
package android.app.cts;
+import com.android.cts.stub.R;
+
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
@@ -25,21 +27,19 @@
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
-import com.android.cts.stub.R;
-
/*
* Stub class for Dialog, AlertDialog, DatePickerDialog, TimePickerDialog etc.
*/
@@ -289,49 +289,27 @@
return (String) mDialog.getWindow().getAttributes().getTitle();
}
+ private static final String TEST_DIALOG_NUMBER_EXTRA = "testDialogNumber";
+
+ public static <T extends Activity> T startDialogActivity(
+ ActivityInstrumentationTestCase2<T> testCase, int dialogNumber) {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.putExtra(TEST_DIALOG_NUMBER_EXTRA, dialogNumber);
+ testCase.setActivityIntent(intent);
+ return testCase.getActivity();
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_stub_layout);
- findViewById(R.id.dialog_test_button_1).setOnClickListener(
- new MockClickListener(TEST_DIALOG_WITHOUT_THEME));
- findViewById(R.id.dialog_test_button_2).setOnClickListener(
- new MockClickListener(TEST_DIALOG_WITH_THEME));
- findViewById(R.id.dialog_test_button_3).setOnClickListener(
- new MockClickListener(TEST_ALERTDIALOG));
- findViewById(R.id.dialog_test_button_4).setOnClickListener(
- new MockClickListener(TEST_CUSTOM_ALERTDIALOG));
- final Button dialogTestButton5 = (Button) findViewById(R.id.dialog_test_button_5);
- dialogTestButton5.setOnClickListener(new MockClickListener(TEST_DATEPICKERDIALOG));
- findViewById(R.id.dialog_test_button_6).setOnClickListener(
- new MockClickListener(TEST_DATEPICKERDIALOG_WITH_THEME));
- findViewById(R.id.dialog_test_button_7).setOnClickListener(
- new MockClickListener(TEST_TIMEPICKERDIALOG));
- findViewById(R.id.dialog_test_button_8).setOnClickListener(
- new MockClickListener(TEST_TIMEPICKERDIALOG_WITH_THEME));
- findViewById(R.id.dialog_test_button_9).setOnClickListener(
- new MockClickListener(TEST_ONSTART_AND_ONSTOP));
- findViewById(R.id.dialog_test_button_10).setOnClickListener(
- new MockClickListener(TEST_ALERTDIALOG_DEPRECATED));
- findViewById(R.id.dialog_test_button_11).setOnClickListener(
- new MockClickListener(TEST_ALERTDIALOG_CALLBACK));
- findViewById(R.id.dialog_test_button_12).setOnClickListener(
- new MockClickListener(TEST_CUSTOM_ALERTDIALOG_VIEW));
- findViewById(R.id.dialog_test_button_13).setOnClickListener(
- new MockClickListener(TEST_ALERTDIALOG_DEPRECATED_WITH_MESSAGE));
-
- findViewById(R.id.dialog_test_button_14).setOnClickListener(
- new MockClickListener(TEST_ALERTDIALOG_THEME));
- findViewById(R.id.dialog_test_button_15).setOnClickListener(
- new MockClickListener(TEST_ALERTDIALOG_CANCELABLE));
- findViewById(R.id.dialog_test_button_16).setOnClickListener(
- new MockClickListener(TEST_ALERTDIALOG_NOT_CANCELABLE));
- findViewById(R.id.dialog_test_button_17).setOnClickListener(
- new MockClickListener(TEST_PROTECTED_CANCELABLE));
- findViewById(R.id.dialog_test_button_18).setOnClickListener(
- new MockClickListener(TEST_PROTECTED_NOT_CANCELABLE));
+ Intent intent = getIntent();
+ int dialogNum = intent.getIntExtra(TEST_DIALOG_NUMBER_EXTRA, -1);
+ if (dialogNum != -1) {
+ showDialog(dialogNum);
+ }
}
public void setUpTitle(final String title) {
@@ -383,18 +361,6 @@
}
- private class MockClickListener implements OnClickListener {
- private final int mId;
-
- public MockClickListener(final int id) {
- mId = id;
- }
-
- public void onClick(View v) {
- showDialog(mId);
- }
- }
-
class MockOnClickListener implements DialogInterface.OnClickListener {
private final int mId;
diff --git a/tests/src/android/content/cts/MockSyncAdapter.java b/tests/src/android/content/cts/MockSyncAdapter.java
index 32b3a8d..df24749 100644
--- a/tests/src/android/content/cts/MockSyncAdapter.java
+++ b/tests/src/android/content/cts/MockSyncAdapter.java
@@ -23,13 +23,14 @@
import android.os.Bundle;
import android.os.RemoteException;
+import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
public class MockSyncAdapter extends ISyncAdapter.Stub {
private static MockSyncAdapter sSyncAdapter = null;
- private Account mAccount;
+ private ArrayList<Account> mAccounts = new ArrayList<Account>();
private String mAuthority;
private Bundle mExtras;
private boolean mInitialized;
@@ -37,8 +38,8 @@
private boolean mCancelSync;
private CountDownLatch mLatch;
- public Account getAccount() {
- return mAccount;
+ public ArrayList<Account> getAccounts() {
+ return mAccounts;
}
public String getAuthority() {
@@ -62,7 +63,7 @@
}
public void clearData() {
- mAccount = null;
+ mAccounts.clear();
mAuthority = null;
mExtras = null;
mInitialized = false;
@@ -78,7 +79,7 @@
public void startSync(ISyncContext syncContext, String authority, Account account,
Bundle extras) throws RemoteException {
- mAccount = account;
+ mAccounts.add(account);
mAuthority = authority;
mExtras = extras;
@@ -98,7 +99,7 @@
}
public void cancelSync(ISyncContext syncContext) throws RemoteException {
- mAccount = null;
+ mAccounts.clear();
mAuthority = null;
mExtras = null;
@@ -114,7 +115,7 @@
public void initialize(android.accounts.Account account, java.lang.String authority)
throws android.os.RemoteException {
- mAccount = account;
+ mAccounts.add(account);
mAuthority = authority;
mInitialized = true;
diff --git a/tests/src/android/provider/cts/MediaStoreAudioTestHelper.java b/tests/src/android/provider/cts/MediaStoreAudioTestHelper.java
index 3cc3bbe..e6c9809 100644
--- a/tests/src/android/provider/cts/MediaStoreAudioTestHelper.java
+++ b/tests/src/android/provider/cts/MediaStoreAudioTestHelper.java
@@ -112,7 +112,7 @@
public static final String EXTERNAL_DATA = Environment.getExternalStorageDirectory() +
"/" + FILE_NAME;
- public static final long DATE_MODIFIED = System.currentTimeMillis();
+ public static final long DATE_MODIFIED = System.currentTimeMillis() / 1000;
public static final String GENRE = "POP";
@Override
diff --git a/tests/src/android/provider/cts/TestSearchRecentSuggestionsProvider.java b/tests/src/android/provider/cts/TestSearchRecentSuggestionsProvider.java
new file mode 100644
index 0000000..d1cb1ef
--- /dev/null
+++ b/tests/src/android/provider/cts/TestSearchRecentSuggestionsProvider.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.provider.cts;
+
+import android.content.SearchRecentSuggestionsProvider;
+
+public class TestSearchRecentSuggestionsProvider extends SearchRecentSuggestionsProvider {
+ final static String AUTHORITY = "android.provider.cts.TestSRSProvider";
+ final static int MODE = DATABASE_MODE_QUERIES + DATABASE_MODE_2LINES;
+
+ public TestSearchRecentSuggestionsProvider() {
+ super();
+ setupSuggestions(AUTHORITY, MODE);
+ }
+}
diff --git a/tests/src/android/webkit/cts/CtsTestServer.java b/tests/src/android/webkit/cts/CtsTestServer.java
index 87b3d1d..6f378c8 100644
--- a/tests/src/android/webkit/cts/CtsTestServer.java
+++ b/tests/src/android/webkit/cts/CtsTestServer.java
@@ -395,14 +395,9 @@
if (path.startsWith(AUTH_PREFIX)) {
// authentication required
Header[] auth = request.getHeaders("Authorization");
- if (auth.length > 0) {
- if (auth[0].getValue().equals(AUTH_CREDENTIALS)) {
- // fall through and serve content
- path = path.substring(AUTH_PREFIX.length());
- } else {
- // incorrect password
- response = createResponse(HttpStatus.SC_FORBIDDEN);
- }
+ if (auth.length > 0 && auth[0].getValue().equals(AUTH_CREDENTIALS)) {
+ // fall through and serve content
+ path = path.substring(AUTH_PREFIX.length());
} else {
// request authorization
response = createResponse(HttpStatus.SC_UNAUTHORIZED);
diff --git a/tests/tests/accessibilityservice/AndroidManifest.xml b/tests/tests/accessibilityservice/AndroidManifest.xml
index 811c87f..b4fe6ab 100644
--- a/tests/tests/accessibilityservice/AndroidManifest.xml
+++ b/tests/tests/accessibilityservice/AndroidManifest.xml
@@ -24,7 +24,7 @@
<uses-library android:name="android.test.runner"/>
<activity android:label="@string/accessibility_end_to_end_test_activity"
- android:name="android.accessibilityservice.cts.AccessibilityEndToEndTestActivity"/>
+ android:name="android.accessibilityservice.cts.AccessibilityEndToEndTestActivity"/>
</application>
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java
index 5259753..7f5be31 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java
@@ -16,6 +16,8 @@
package android.accessibilityservice.cts;
+import com.android.cts.accessibilityservice.R;
+
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.IAccessibilityServiceDelegate;
import android.accessibilityservice.IAccessibilityServiceDelegateConnection;
@@ -47,8 +49,6 @@
import android.widget.EditText;
import android.widget.ListView;
-import com.android.cts.accessibilityservice.R;
-
import junit.framework.TestCase;
import java.util.Iterator;
@@ -56,23 +56,25 @@
import java.util.List;
import java.util.Queue;
+import junit.framework.TestCase;
+
/**
* This class performs end-to-end testing of the accessibility feature by
* creating an {@link Activity} and poking around so {@link AccessibilityEvent}s
* are generated and their correct dispatch verified.
- * </p>
- * Note: The end-to-end test is composed of two APKs, one with a delegating accessibility
+ * <p>
+ * Note: The end-to-end test is composed of two APKs, one with a mock accessibility
* service, another with the instrumented activity and test cases. The motivation for
* two APKs design is that CTS tests cannot access the secure settings which is
* required for enabling accessibility and accessibility services. Therefore, manual
- * installation of the <strong>CtsDelegatingAccessibilityService.apk</strong>
- * whose source is located at <strong>cts/tests/accessibilityservice</strong> is required.
+ * installation of the <strong>CtsAccessibilityServiceTestMockService.apk</strong>
+ * whose source is located at <strong>cts/tests/accessibility</strong> is required.
* Once the former package has been installed accessibility must be enabled (Settings ->
- * Accessibility), the delegating service must be enabled (Settings -> Accessibility
- * -> Delegating Accessibility Service), and then the CTS tests in this package can be
- * successfully run. Further, the delegate and tests run in separate processes since
+ * Accessibility), the mock service must be enabled (Settings -> Accessibility
+ * -> Mock Accessibility Service), and then the CTS tests in this package can be
+ * successfully run. Further, the mock and tests run in separate processes since
* the instrumentation restarts the process in which it is running and this
- * breaks the binding between the delegating accessibility service and the system.
+ * breaks the binding between the mock accessibility service and the system.
*/
public class AccessibilityEndToEndTest extends
ActivityInstrumentationTestCase2<AccessibilityEndToEndTestActivity> {
@@ -114,15 +116,17 @@
* @throws Exception If any error occurs.
*/
public AccessibilityEndToEndTest() throws Exception {
- super("com.android.cts.accessibilityservice", AccessibilityEndToEndTestActivity.class);
+ super(AccessibilityEndToEndTestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
- // wait for the activity to settle down so we do not receive
- // the event for its start, thus breaking the tests
- getInstrumentation().waitForIdleSync();
+ // TODO (svetoslavganov): This is a temporary workaround for
+ // nondeterministically failing tests with partially populated events.
+ // It seems that not all times the View hierarchy is fully
+ // instantiated on time. This seems related to bug 2630683.
+ Thread.sleep(500);
}
@LargeTest
@@ -247,7 +251,7 @@
@LargeTest
public void testTypeViewTextChangedAccessibilityEvent() throws Throwable {
- Activity activity = getActivity();
+ final Activity activity = getActivity();
// focus the edit text
final EditText editText = (EditText) activity.findViewById(R.id.edittext);
@@ -677,8 +681,7 @@
receivedEvent.isFullScreen());
TestCase.assertEquals("itemCount has incorrect value", expectedEvent.getItemCount(),
receivedEvent.getItemCount());
- // This will fail due to a bug fixed in Gingerbread. Bug 2593810 (removed the method).
- // assertEqualsNotificationAsParcelableData(expectedEvent, receivedEvent);
+ assertEqualsNotificationAsParcelableData(expectedEvent, receivedEvent);
TestCase.assertEquals("password has incorrect value", expectedEvent.isPassword(),
receivedEvent.isPassword());
TestCase.assertEquals("removedCount has incorrect value", expectedEvent
@@ -687,6 +690,30 @@
}
/**
+ * Compares the {@link android.os.Parcelable} data of the
+ * <code>expectedEvent</code> and <code>receivedEvent</code> to verify
+ * that the received event is the one that is expected.
+ */
+ private void assertEqualsNotificationAsParcelableData(AccessibilityEvent expectedEvent,
+ AccessibilityEvent receivedEvent) {
+ String message = "parcelableData has incorrect value";
+ Notification expectedNotification = (Notification) expectedEvent.getParcelableData();
+ Notification receivedNotification = (Notification) receivedEvent.getParcelableData();
+
+ if (expectedNotification == null) {
+ if (receivedNotification == null) {
+ return;
+ }
+ }
+
+ TestCase.assertNotNull(message, receivedNotification);
+
+ // we do a very simple sanity check
+ TestCase.assertEquals(message, expectedNotification.tickerText.toString(),
+ receivedNotification.tickerText.toString());
+ }
+
+ /**
* Compares the text of the <code>expectedEvent</code> and
* <code>receivedEvent</code> by comparing the string representation of
* the corresponding {@link CharSequence}s.
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTestActivity.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTestActivity.java
index e806622..adfc9e6 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTestActivity.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTestActivity.java
@@ -16,6 +16,8 @@
package android.accessibilityservice.cts;
+import com.android.cts.accessibilityservice.R;
+
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
@@ -26,8 +28,6 @@
import android.widget.ListView;
import android.widget.TextView;
-import com.android.cts.accessibilityservice.R;
-
/**
* This class is an {@link Activity} used to perform end-to-end
* testing of the accessibility feature by interaction with the
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java
index 48b4aae..ab7ecd7 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityServiceInfoTest.java
@@ -72,8 +72,7 @@
receivedInfo.eventTypes);
assertEquals("feedbackType not marshalled properly", sentInfo.feedbackType,
receivedInfo.feedbackType);
- // This will fail here and is fixed in Froyo. Bug 2448479.
- // assertEquals("flags not marshalled properly", sentInfo.flags, receivedInfo.flags);
+ assertEquals("flags not marshalled properly", sentInfo.flags, receivedInfo.flags);
assertEquals("notificationTimeout not marshalled properly", sentInfo.notificationTimeout,
receivedInfo.notificationTimeout);
assertEquals("packageNames not marshalled properly", sentInfo.packageNames.length,
diff --git a/tests/tests/accounts/src/android/accounts/cts/AccountManagerTest.java b/tests/tests/accounts/src/android/accounts/cts/AccountManagerTest.java
index e72e4db..e2c1f66 100644
--- a/tests/tests/accounts/src/android/accounts/cts/AccountManagerTest.java
+++ b/tests/tests/accounts/src/android/accounts/cts/AccountManagerTest.java
@@ -28,6 +28,7 @@
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
+import android.os.StrictMode;
import android.test.AndroidTestCase;
import java.io.IOException;
@@ -1326,4 +1327,28 @@
handler);
waitForLatch(latch);
}
+
+ /**
+ * Tests that AccountManagerService is properly caching data.
+ */
+ public void testGetsAreCached() throws IOException, AuthenticatorException,
+ OperationCanceledException {
+
+ // Add an account,
+ assertEquals(false, isAccountPresent(am.getAccounts(), ACCOUNT));
+ addAccountExplicitly(ACCOUNT, ACCOUNT_PASSWORD, null /* userData */);
+
+ // Then verify that we don't hit disk retrieving it,
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
+ try {
+ StrictMode.setThreadPolicy(
+ new StrictMode.ThreadPolicy.Builder().detectDiskReads().penaltyDeath().build());
+ Account[] accounts = am.getAccounts();
+ assertNotNull(accounts);
+ assertTrue(accounts.length > 0);
+ } finally {
+ StrictMode.setThreadPolicy(oldPolicy);
+ }
+ }
+
}
diff --git a/tests/tests/app/src/android/app/cts/AlertDialogTest.java b/tests/tests/app/src/android/app/cts/AlertDialogTest.java
index 4ab57da..b5711ed 100644
--- a/tests/tests/app/src/android/app/cts/AlertDialogTest.java
+++ b/tests/tests/app/src/android/app/cts/AlertDialogTest.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.AlertDialog;
import android.app.Instrumentation;
import android.content.Context;
@@ -29,10 +34,6 @@
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
/*
* Test AlertDialog
@@ -55,15 +56,10 @@
protected void setUp() throws Exception {
super.setUp();
mInstrumentation = getInstrumentation();
- mActivity = getActivity();
}
- protected void popDialog(int index) {
- while (index != 0) {
- sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
- index--;
- }
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+ protected void startDialogActivity(int dialogNumber) {
+ mActivity = DialogStubActivity.startDialogActivity(this, dialogNumber);
}
@TestTargets({
@@ -121,7 +117,7 @@
}
private void doTestAlertDialog(int index) throws Throwable {
- popDialog(index);
+ startDialogActivity(index);
assertTrue(mActivity.getDialog().isShowing());
mPositiveButton = ((AlertDialog) (mActivity.getDialog())).getButton(
@@ -294,7 +290,7 @@
)
})
public void testAlertDialogDeprecatedAPIWithMessage() throws Throwable {
- popDialog(DialogStubActivity.TEST_ALERTDIALOG_DEPRECATED_WITH_MESSAGE);
+ startDialogActivity(DialogStubActivity.TEST_ALERTDIALOG_DEPRECATED_WITH_MESSAGE);
assertTrue(mActivity.getDialog().isShowing());
mPositiveButton = ((AlertDialog) (mActivity.getDialog())).getButton(
@@ -368,7 +364,7 @@
)
})
public void testCustomAlertDialog() {
- popDialog(DialogStubActivity.TEST_CUSTOM_ALERTDIALOG);
+ startDialogActivity(DialogStubActivity.TEST_CUSTOM_ALERTDIALOG);
assertTrue(mActivity.getDialog().isShowing());
}
@@ -405,7 +401,7 @@
)
})
public void testCustomAlertDialogView() {
- popDialog(DialogStubActivity.TEST_CUSTOM_ALERTDIALOG_VIEW);
+ startDialogActivity(DialogStubActivity.TEST_CUSTOM_ALERTDIALOG_VIEW);
assertTrue(mActivity.getDialog().isShowing());
}
@@ -437,7 +433,7 @@
)
})
public void testCallback() {
- popDialog(DialogStubActivity.TEST_ALERTDIALOG_CALLBACK);
+ startDialogActivity(DialogStubActivity.TEST_ALERTDIALOG_CALLBACK);
assertTrue(mActivity.onCreateCalled);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_0);
@@ -453,7 +449,7 @@
args = {Context.class, int.class}
)
public void testAlertDialogTheme() throws Exception {
- popDialog(DialogStubActivity.TEST_ALERTDIALOG_THEME);
+ startDialogActivity(DialogStubActivity.TEST_ALERTDIALOG_THEME);
assertTrue(mActivity.getDialog().isShowing());
}
@@ -464,7 +460,7 @@
args = {Context.class, boolean.class, OnCancelListener.class}
)
public void testAlertDialogCancelable() throws Exception {
- popDialog(DialogStubActivity.TEST_ALERTDIALOG_CANCELABLE);
+ startDialogActivity(DialogStubActivity.TEST_ALERTDIALOG_CANCELABLE);
assertTrue(mActivity.getDialog().isShowing());
assertFalse(mActivity.onCancelCalled);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
@@ -479,7 +475,7 @@
args = {Context.class, boolean.class, OnCancelListener.class}
)
public void testAlertDialogNotCancelable() throws Exception {
- popDialog(DialogStubActivity.TEST_ALERTDIALOG_NOT_CANCELABLE);
+ startDialogActivity(DialogStubActivity.TEST_ALERTDIALOG_NOT_CANCELABLE);
assertTrue(mActivity.getDialog().isShowing());
assertFalse(mActivity.onCancelCalled);
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
diff --git a/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java b/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java
index 140ccaa..4ca5a4e 100644
--- a/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java
+++ b/tests/tests/app/src/android/app/cts/DatePickerDialogTest.java
@@ -47,15 +47,6 @@
protected void setUp() throws Exception {
super.setUp();
mInstrumentation = getInstrumentation();
- mActivity = getActivity();
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (mActivity != null) {
- mActivity.finish();
- }
- super.tearDown();
}
@TestTargets({
@@ -144,7 +135,7 @@
}
private void doTestDatePickerDialog(int index) throws Exception {
- popDialog(index);
+ startDialogActivity(index);
final DatePickerDialog datePickerDialog = (DatePickerDialog) mActivity.getDialog();
assertTrue(datePickerDialog.isShowing());
final TextView title = (TextView) datePickerDialog.findViewById(
@@ -178,15 +169,7 @@
assertTrue(DialogStubActivity.onRestoreInstanceStateCalled);
}
- private void popDialog(int index) {
- assertTrue(index > 0);
-
- while (index != 0) {
- sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
- index--;
- }
-
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+ private void startDialogActivity(int index) {
+ mActivity = DialogStubActivity.startDialogActivity(this, index);
}
-
}
diff --git a/tests/tests/app/src/android/app/cts/DialogTest.java b/tests/tests/app/src/android/app/cts/DialogTest.java
index 6a48358..3500d27 100644
--- a/tests/tests/app/src/android/app/cts/DialogTest.java
+++ b/tests/tests/app/src/android/app/cts/DialogTest.java
@@ -15,8 +15,14 @@
*/
package android.app.cts;
-import java.lang.ref.WeakReference;
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 android.app.Dialog;
import android.app.Instrumentation;
import android.content.Context;
@@ -24,7 +30,6 @@
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnKeyListener;
-import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -45,11 +50,8 @@
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.ToBeFixed;
+
+import java.lang.ref.WeakReference;
@TestTargetClass(Dialog.class)
public class DialogTest extends ActivityInstrumentationTestCase2<DialogStubActivity> {
@@ -84,30 +86,12 @@
@Override
protected void setUp() throws Exception {
super.setUp();
-
mInstrumentation = getInstrumentation();
mContext = mInstrumentation.getContext();
- mActivity = getActivity();
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
-
- if (mActivity != null) {
- mActivity.finish();
- }
- }
-
- protected void popDialog(int index) {
- assertTrue(index >= 0);
-
- while (index != 0) {
- sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
- index--;
- }
-
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+ private void startDialogActivity(int dialogNumber) {
+ mActivity = DialogStubActivity.startDialogActivity(this, dialogNumber);
}
@TestTargets({
@@ -139,7 +123,7 @@
args = {}
)
})
- public void testDialog(){
+ public void testConstructor(){
new Dialog(mContext);
Dialog d = new Dialog(mContext, 0);
// According to javadoc of constructors, it will set theme to system default theme,
@@ -154,16 +138,17 @@
final Window w = d.getWindow();
ta = w.getContext().getTheme().obtainStyledAttributes(R.styleable.TextAppearance);
assertTextAppearanceStyle(ta);
+ }
- // test protected constructor
- // Dialog(Context context, boolean cancelable, OnCancelListener cancelListener)
+ public void testConstructor_protectedCancellable() {
+ startDialogActivity(DialogStubActivity.TEST_PROTECTED_CANCELABLE);
mActivity.onCancelListenerCalled = false;
- popDialog(DialogStubActivity.TEST_PROTECTED_CANCELABLE);
sendKeys(KeyEvent.KEYCODE_BACK);
assertTrue(mActivity.onCancelListenerCalled);
+ }
- // open DialogStubActivity.TEST_PROTECTED_NOT_CANCELABLE
- sendKeys(KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
+ public void testConstructor_protectedNotCancellable() {
+ startDialogActivity(DialogStubActivity.TEST_PROTECTED_NOT_CANCELABLE);
mActivity.onCancelListenerCalled = false;
sendKeys(KeyEvent.KEYCODE_BACK);
assertFalse(mActivity.onCancelListenerCalled);
@@ -209,7 +194,7 @@
)
})
public void testOnStartCreateStop(){
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertTrue(d.isOnStartCalled);
@@ -243,7 +228,7 @@
)
})
public void testAccessOwnerActivity() {
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
Dialog d = mActivity.getDialog();
assertNotNull(d);
assertSame(mActivity, d.getOwnerActivity());
@@ -284,7 +269,7 @@
)
})
public void testShow() throws Throwable {
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
final Dialog d = mActivity.getDialog();
final View decor = d.getWindow().getDecorView();
@@ -324,7 +309,7 @@
)
})
public void testOnSaveInstanceState() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertFalse(d.isOnSaveInstanceStateCalled);
@@ -342,7 +327,7 @@
args = {}
)
public void testGetCurrentFocus() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertNull(d.getCurrentFocus());
runTestOnUiThread(new Runnable() {
@@ -386,7 +371,7 @@
)
})
public void testSetContentView() throws Throwable {
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
final Dialog d = mActivity.getDialog();
assertNotNull(d);
@@ -472,7 +457,7 @@
})
public void testSetTitle() {
final String expectedTitle = "Test Dialog Without theme";
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
assertNotNull(mActivity.getDialog());
mActivity.setUpTitle(expectedTitle);
@@ -500,7 +485,7 @@
)
})
public void testOnKeyDownKeyUp() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertFalse(d.isOnKeyDownCalled);
assertFalse(d.isOnKeyUpCalled);
@@ -524,7 +509,7 @@
args = {int.class, int.class, android.view.KeyEvent.class}
)
public void testOnKeyMultiple() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertNull(d.keyMultipleEvent);
@@ -553,7 +538,7 @@
)
})
public void testTouchEvent() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertNull(d.onTouchEvent);
@@ -603,7 +588,7 @@
)
})
public void testTrackballEvent() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
final MotionEvent trackBallEvent = MotionEvent.obtain(MOTION_DOWN_TIME, MOTION_EVENT_TIME,
MotionEvent.ACTION_DOWN, MOTION_X, MOTION_Y, 0);
@@ -636,7 +621,7 @@
args = {android.view.WindowManager.LayoutParams.class}
)
public void testOnWindowAttributesChanged() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertTrue(d.isOnWindowAttributesChangedCalled);
@@ -661,7 +646,7 @@
args = {}
)
public void testOnContentChanged() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertNotNull(d);
@@ -683,7 +668,7 @@
args = {boolean.class}
)
public void testOnWindowFocusChanged() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertTrue(d.isOnWindowFocusChangedCalled);
d.isOnWindowFocusChangedCalled = false;
@@ -712,7 +697,7 @@
)
})
public void testDispatchKeyEvent() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
sendKeys(KeyEvent.KEYCODE_0);
@@ -829,7 +814,7 @@
+ "onContextMenuClosed() should be called in onPanelClosed() source code, "
+ "but now onMenuItemSelected() and onPanelClosed() method are empty, is this a bug?")
public void testOptionMenu() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
assertFalse(d.isOnMenuOpenedCalled);
assertFalse(d.isOnCreatePanelViewCalled);
@@ -943,7 +928,7 @@
+ "onContextMenuClosed() should be called in onPanelClosed() source code, "
+ "but now onMenuItemSelected() and onPanelClosed() method are empty, is this a bug?")
public void testContextMenu() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
final LinearLayout parent = new LinearLayout(mContext);
final MockView v = new MockView(mContext);
@@ -1035,7 +1020,7 @@
@ToBeFixed(bug = "1695243",
explanation = "It still get KeyEvent while set takeKeyEvents to false")
public void testTakeKeyEvents() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
final View v = d.getWindow().getDecorView();
assertNull(d.getCurrentFocus());
@@ -1067,7 +1052,7 @@
args = {int.class}
)
public void testRequestWindowFeature() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
// called requestWindowFeature at TestDialog onCreate method
assertTrue(((TestDialog) mActivity.getDialog()).isRequestWindowFeature);
}
@@ -1080,7 +1065,7 @@
args = {int.class, int.class}
)
public void testSetFeatureDrawableResource() throws Throwable {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
runTestOnUiThread(new Runnable() {
public void run() {
mActivity.getDialog().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
@@ -1098,7 +1083,7 @@
args = {int.class, android.net.Uri.class}
)
public void testSetFeatureDrawableUri() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
mActivity.getDialog().setFeatureDrawableUri(0, Uri.parse("http://www.google.com"));
}
@@ -1110,7 +1095,7 @@
args = {int.class, android.graphics.drawable.Drawable.class}
)
public void testSetFeatureDrawable() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
mActivity.getDialog().setFeatureDrawable(0, new MockDrawable());
}
@@ -1122,7 +1107,7 @@
args = {int.class, int.class}
)
public void testSetFeatureDrawableAlpha() {
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
mActivity.getDialog().setFeatureDrawableAlpha(0, 0);
}
@@ -1132,7 +1117,7 @@
args = {}
)
public void testGetLayoutInflater() {
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
final Dialog d = mActivity.getDialog();
assertEquals(d.getWindow().getLayoutInflater(), d.getLayoutInflater());
}
@@ -1142,17 +1127,21 @@
method = "setCancelable",
args = {boolean.class}
)
- public void testSetCancelable() {
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ public void testSetCancelable_true() {
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
final Dialog d = mActivity.getDialog();
d.setCancelable(true);
assertTrue(d.isShowing());
sendKeys(KeyEvent.KEYCODE_BACK);
assertFalse(d.isShowing());
+ }
+
+ public void testSetCancellable_false() {
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ final Dialog d = mActivity.getDialog();
d.setCancelable(false);
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
assertTrue(d.isShowing());
sendKeys(KeyEvent.KEYCODE_BACK);
assertTrue(d.isShowing());
@@ -1175,8 +1164,8 @@
args = {android.content.DialogInterface.OnCancelListener.class}
)
})
- public void testCancel() throws Throwable {
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ public void testCancel_listener() throws Throwable {
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
final Dialog d = mActivity.getDialog();
assertTrue(d.isShowing());
@@ -1190,8 +1179,12 @@
assertFalse(d.isShowing());
assertTrue(mOnCancelListenerCalled);
+ }
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+ public void testCancel_noListener() throws Throwable {
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ final Dialog d = mActivity.getDialog();
+
assertTrue(d.isShowing());
mOnCancelListenerCalled = false;
d.setOnCancelListener(null);
@@ -1209,7 +1202,7 @@
)
public void testSetCancelMessage() throws Exception {
mCalledCallback = false;
- popDialog(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
+ startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
final TestDialog d = (TestDialog) mActivity.getDialog();
final HandlerThread ht = new HandlerThread("DialogTest");
ht.start();
@@ -1239,9 +1232,9 @@
method = "setOnDismissListener",
args = {android.content.DialogInterface.OnDismissListener.class}
)
- public void testSetOnDismissListener() throws Throwable {
+ public void testSetOnDismissListener_listener() throws Throwable {
mCalledCallback = false;
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
final Dialog d = mActivity.getDialog();
d.setOnDismissListener(new OnDismissListener() {
@@ -1255,9 +1248,11 @@
dialogDismiss(d);
assertTrue(mCalledCallback);
assertFalse(d.isShowing());
+ }
- // show the dialog again
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+ public void testSetOnDismissListener_noListener() throws Throwable {
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ final Dialog d = mActivity.getDialog();
assertTrue(d.isShowing());
mCalledCallback = false;
d.setOnDismissListener(null);
@@ -1273,7 +1268,7 @@
)
public void testSetDismissMessage() throws Throwable {
mCalledCallback = false;
- popDialog(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
+ startDialogActivity(DialogStubActivity.TEST_DIALOG_WITHOUT_THEME);
final Dialog d = mActivity.getDialog();
final HandlerThread ht = new HandlerThread("DialogTest");
diff --git a/tests/tests/app/src/android/app/cts/InstrumentationTest.java b/tests/tests/app/src/android/app/cts/InstrumentationTest.java
index 1861ae2..12baed5 100644
--- a/tests/tests/app/src/android/app/cts/InstrumentationTest.java
+++ b/tests/tests/app/src/android/app/cts/InstrumentationTest.java
@@ -16,7 +16,12 @@
package android.app.cts;
-import java.util.List;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import android.app.Activity;
import android.app.Application;
@@ -46,12 +51,7 @@
import android.view.Window;
import android.view.ViewGroup.LayoutParams;
-import com.android.cts.stub.R;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
+import java.util.List;
@TestTargetClass(Instrumentation.class)
public class InstrumentationTest extends InstrumentationTestCase {
@@ -493,7 +493,7 @@
assertEquals(text.length(), keyDownList.size());
assertEquals(text.length(), keyUpList.size());
- KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
+ KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
KeyEvent[] keyEvents = kcm.getEvents(text.toCharArray());
int i = 0;
@@ -508,10 +508,14 @@
method = "callActivityOnSaveInstanceState",
args = {Activity.class, Bundle.class}
)
- public void testCallActivityOnSaveInstanceState() {
+ public void testCallActivityOnSaveInstanceState() throws Throwable {
final Bundle bundle = new Bundle();
mActivity.setOnSaveInstanceState(false);
- mInstrumentation.callActivityOnSaveInstanceState(mActivity, bundle);
+ runTestOnUiThread(new Runnable() {
+ public void run() {
+ mInstrumentation.callActivityOnSaveInstanceState(mActivity, bundle);
+ }
+ });
mInstrumentation.waitForIdleSync();
assertTrue(mActivity.isOnSaveInstanceState());
@@ -958,11 +962,15 @@
@Override
public void togglePanel(int featureId, KeyEvent event) {
}
-
+
+ @Override
+ public void invalidatePanelMenu(int featureId) {
+ }
+
@Override
public void takeSurface(SurfaceHolder.Callback2 callback) {
}
-
+
@Override
public void takeInputQueue(InputQueue.Callback queue) {
}
diff --git a/tests/tests/app/src/android/app/cts/TimePickerDialogTest.java b/tests/tests/app/src/android/app/cts/TimePickerDialogTest.java
index 01f1ec9..417d046 100644
--- a/tests/tests/app/src/android/app/cts/TimePickerDialogTest.java
+++ b/tests/tests/app/src/android/app/cts/TimePickerDialogTest.java
@@ -26,7 +26,6 @@
import android.content.Context;
import android.os.Bundle;
import android.test.ActivityInstrumentationTestCase2;
-import android.view.KeyEvent;
import android.widget.TimePicker;
/**
@@ -59,7 +58,6 @@
super.setUp();
mContext = getInstrumentation().getContext();
- mActivity = getActivity();
mOnTimeSetListener = new OnTimeSetListener(){
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mCallbackHour = hourOfDay;
@@ -131,7 +129,7 @@
)
public void testOnTimeChanged() throws Throwable {
final int minute = 34;
- popDialog(DialogStubActivity.TEST_TIMEPICKERDIALOG);
+ startDialogActivity(DialogStubActivity.TEST_TIMEPICKERDIALOG);
final TimePickerDialog d = (TimePickerDialog) mActivity.getDialog();
runTestOnUiThread(new Runnable() {
@@ -181,14 +179,7 @@
assertFalse(b2.getBoolean(IS_24_HOUR));
}
- private void popDialog(int index) {
- assertTrue(index > 0);
-
- while (index != 0) {
- sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
- index--;
- }
-
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+ private void startDialogActivity(int dialogNumber) {
+ mActivity = DialogStubActivity.startDialogActivity(this, dialogNumber);
}
}
diff --git a/tests/tests/content/src/android/content/cts/BroadcastReceiverTest.java b/tests/tests/content/src/android/content/cts/BroadcastReceiverTest.java
index 7fb403e..62d8724 100644
--- a/tests/tests/content/src/android/content/cts/BroadcastReceiverTest.java
+++ b/tests/tests/content/src/android/content/cts/BroadcastReceiverTest.java
@@ -77,33 +77,6 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "abortBroadcast",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "clearAbortBroadcast",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getAbortBroadcast",
- args = {}
- )
- })
- public void testAccessAbortBroadcast() {
- MockReceiverInternal mockReceiver = new MockReceiverInternal();
-
- mockReceiver.abortBroadcast();
- assertTrue(mockReceiver.getAbortBroadcast());
-
- mockReceiver.clearAbortBroadcast();
- assertFalse(mockReceiver.getAbortBroadcast());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "getDebugUnregister",
args = {}
),
@@ -377,7 +350,7 @@
static class MyServiceConnection implements ServiceConnection {
private boolean serviceConnected;
-
+
public synchronized void onServiceConnected(ComponentName name, IBinder service) {
serviceConnected = true;
notifyAll();
@@ -385,7 +358,7 @@
public synchronized void onServiceDisconnected(ComponentName name) {
}
-
+
public synchronized boolean waitForService(long timeout) {
if (!serviceConnected) {
try {
diff --git a/tests/tests/content/src/android/content/cts/ContentProviderTest.java b/tests/tests/content/src/android/content/cts/ContentProviderTest.java
index 0824e84..eabd470 100644
--- a/tests/tests/content/src/android/content/cts/ContentProviderTest.java
+++ b/tests/tests/content/src/android/content/cts/ContentProviderTest.java
@@ -394,6 +394,15 @@
public Bundle call(String method, String request, Bundle args) {
return null;
}
+
+ public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException {
+ return null;
+ }
+
+ public AssetFileDescriptor openTypedAssetFile(Uri url, String mimeType, Bundle opts)
+ throws RemoteException, FileNotFoundException {
+ return null;
+ }
};
assertNull(ContentProvider.coerceToLocalContentProvider(iContentProvider));
}
diff --git a/tests/tests/content/src/android/content/cts/ContentResolverSyncTestCase.java b/tests/tests/content/src/android/content/cts/ContentResolverSyncTestCase.java
index 032f10a..4d7ca6d 100644
--- a/tests/tests/content/src/android/content/cts/ContentResolverSyncTestCase.java
+++ b/tests/tests/content/src/android/content/cts/ContentResolverSyncTestCase.java
@@ -93,7 +93,7 @@
}
private void addAccountAndVerifyInitSync(Account account, String password,
- String authority, int latchTimeoutMs) {
+ String authority, int latchTimeoutMs, int accountIndex) {
CountDownLatch latch = setNewLatch(new CountDownLatch(1));
@@ -109,7 +109,7 @@
assertFalse(getMockSyncAdapter().isStartSync());
assertFalse(getMockSyncAdapter().isCancelSync());
assertTrue(getMockSyncAdapter().isInitialized());
- assertEquals(account, getMockSyncAdapter().getAccount());
+ assertEquals(account, getMockSyncAdapter().getAccounts().get(accountIndex));
assertEquals(authority, getMockSyncAdapter().getAuthority());
}
@@ -159,8 +159,11 @@
ContentResolver.setMasterSyncAutomatically(false);
assertEquals(false, ContentResolver.getMasterSyncAutomatically());
- addAccountAndVerifyInitSync(ACCOUNT, MockAccountAuthenticator.ACCOUNT_PASSWORD, AUTHORITY,
- LATCH_TIMEOUT_MS);
+ addAccountAndVerifyInitSync(ACCOUNT,
+ MockAccountAuthenticator.ACCOUNT_PASSWORD,
+ AUTHORITY,
+ LATCH_TIMEOUT_MS,
+ 0);
getMockSyncAdapter().clearData();
@@ -174,7 +177,7 @@
assertTrue(getMockSyncAdapter().isStartSync());
assertFalse(getMockSyncAdapter().isCancelSync());
assertFalse(getMockSyncAdapter().isInitialized());
- assertEquals(ACCOUNT, getMockSyncAdapter().getAccount());
+ assertEquals(ACCOUNT, getMockSyncAdapter().getAccounts().get(0));
assertEquals(AUTHORITY, getMockSyncAdapter().getAuthority());
}
@@ -188,8 +191,11 @@
ContentResolver.setMasterSyncAutomatically(false);
assertEquals(false, ContentResolver.getMasterSyncAutomatically());
- addAccountAndVerifyInitSync(ACCOUNT, MockAccountAuthenticator.ACCOUNT_PASSWORD, AUTHORITY,
- LATCH_TIMEOUT_MS);
+ addAccountAndVerifyInitSync(ACCOUNT,
+ MockAccountAuthenticator.ACCOUNT_PASSWORD,
+ AUTHORITY,
+ LATCH_TIMEOUT_MS,
+ 0);
getMockSyncAdapter().clearData();
@@ -315,4 +321,35 @@
//expected.
}
}
+
+ /**
+ * Test to verify that a SyncAdapter is called on all the accounts accounts
+ */
+ public void testCallMultipleAccounts() {
+ // Prevent auto sync
+ ContentResolver.setMasterSyncAutomatically(false);
+ assertEquals(false, ContentResolver.getMasterSyncAutomatically());
+
+ addAccountAndVerifyInitSync(ACCOUNT,
+ MockAccountAuthenticator.ACCOUNT_PASSWORD,
+ AUTHORITY,
+ LATCH_TIMEOUT_MS,
+ 0);
+
+ getMockSyncAdapter().clearData();
+
+ setIsSyncable(ACCOUNT, AUTHORITY, true);
+ cancelSync(ACCOUNT, AUTHORITY, LATCH_TIMEOUT_MS);
+
+ getMockSyncAdapter().clearData();
+
+ requestSync(null /* all accounts */, AUTHORITY, LATCH_TIMEOUT_MS);
+
+ assertTrue(getMockSyncAdapter().isStartSync());
+ assertFalse(getMockSyncAdapter().isCancelSync());
+ assertFalse(getMockSyncAdapter().isInitialized());
+ assertEquals(ACCOUNT, getMockSyncAdapter().getAccounts().get(0));
+ assertEquals(AUTHORITY, getMockSyncAdapter().getAuthority());
+
+ }
}
diff --git a/tests/tests/content/src/android/content/res/cts/AssetFileDescriptor_AutoCloseInputStreamTest.java b/tests/tests/content/src/android/content/res/cts/AssetFileDescriptor_AutoCloseInputStreamTest.java
index 1ff3f49..de9f0e3 100644
--- a/tests/tests/content/src/android/content/res/cts/AssetFileDescriptor_AutoCloseInputStreamTest.java
+++ b/tests/tests/content/src/android/content/res/cts/AssetFileDescriptor_AutoCloseInputStreamTest.java
@@ -16,80 +16,252 @@
package android.content.res.cts;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import android.content.res.AssetFileDescriptor;
-import android.os.ParcelFileDescriptor;
-import android.test.AndroidTestCase;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
+import android.content.res.AssetFileDescriptor;
+import android.os.ParcelFileDescriptor;
+import android.test.AndroidTestCase;
+import android.test.MoreAsserts;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
@TestTargetClass(AssetFileDescriptor.AutoCloseInputStream.class)
public class AssetFileDescriptor_AutoCloseInputStreamTest extends AndroidTestCase {
private static final int FILE_END = -1;
- private static final int FILE_LENGTH = 10;
private static final String FILE_NAME = "testAssertFileDescriptorAutoCloseInputStream";
private static final byte[] FILE_DATA = new byte[] {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
};
- private static final int OFFSET = 0;
- private static final int READ_LENGTH = 1;
+ private static final int FILE_LENGTH = FILE_DATA.length;
private File mFile;
- private AssetFileDescriptor mAssetFileDes;
+ private AssetFileDescriptor mFd;
+ private AssetFileDescriptor.AutoCloseInputStream mInput;
@Override
protected void setUp() throws Exception {
super.setUp();
mFile = new File(getContext().getFilesDir(), FILE_NAME);
- mFile.createNewFile();
+ FileOutputStream outputStream = new FileOutputStream(mFile);
+ outputStream.write(FILE_DATA);
+ outputStream.close();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
- // As {@link AssetFileDescripter#createOutputStream()}
- // and {@link AssetFileDescripter#createInputStream()} doc,
- // the input and output stream will be auto closed when the AssetFileDescriptor closed.
- // Here is no need to close AutoCloseInputStream, as AssetFileDescriptor will do it for us.
- if (mAssetFileDes != null) {
- mAssetFileDes.close();
+ if (mFd != null) {
+ mFd.close();
+ mFd = null;
}
- getContext().deleteFile(FILE_NAME);
+ mFile.delete();
}
- /*
- * Test AutoInputStream life circle.
- * Test point:
- * 1. Test AutoInputStream read what we write into file.
- */
@TestTargets({
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.PARTIAL_COMPLETE,
method = "AssetFileDescriptor.AutoCloseInputStream",
args = {AssetFileDescriptor.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "skip",
+ args = {long.class}
+ )
+ })
+ public void testSkip() throws IOException {
+ openInput(0, FILE_LENGTH);
+ assertEquals(FILE_DATA[0], mInput.read());
+ assertEquals(0, mInput.skip(0));
+ assertEquals(FILE_DATA[1], mInput.read());
+ assertEquals(3, mInput.skip(3));
+ assertEquals(FILE_DATA[5], mInput.read());
+ assertEquals(3, mInput.skip(10));
+ assertEquals(FILE_END, mInput.read());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
method = "read",
args = {}
+ )
+ })
+ public void testRead() throws IOException {
+ openInput(0, FILE_LENGTH);
+ for (int i = 0; i < FILE_LENGTH; i++) {
+ assertEquals(FILE_DATA[i], mInput.read());
+ }
+ assertEquals(FILE_END, mInput.read());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
),
@TestTargetNew(
- level = TestLevel.COMPLETE,
+ level = TestLevel.PARTIAL_COMPLETE,
method = "read",
- args = {byte[].class, int.class, int.class}
+ args = {}
+ )
+ })
+ public void testReadPartial() throws IOException {
+ long len = 6;
+ openInput(0, len);
+ for (int i = 0; i < len; i++) {
+ assertEquals(FILE_DATA[i], mInput.read());
+ }
+ assertEquals(FILE_END, mInput.read());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
),
@TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class}
+ level = TestLevel.COMPLETE,
+ method = "read",
+ args = {byte[].class, int.class, int.class}
+ )
+ })
+ public void testReadBufferLen() throws IOException {
+ openInput(0, FILE_LENGTH);
+ byte[] buf = new byte[FILE_LENGTH];
+ assertEquals(3, mInput.read(buf, 0, 3));
+ assertEquals(3, mInput.read(buf, 3, 3));
+ assertEquals(3, mInput.read(buf, 6, 4));
+ MoreAsserts.assertEquals(FILE_DATA, buf);
+ assertEquals(FILE_END, mInput.read(buf, 0, 4));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
),
@TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "read",
+ args = {byte[].class}
+ )
+ })
+ public void testReadBuffer() throws IOException {
+ openInput(0, FILE_LENGTH);
+ byte[] buf = new byte[6];
+ assertEquals(6, mInput.read(buf));
+ assertEquals(FILE_DATA[0], buf[0]);
+ assertEquals(3, mInput.read(buf));
+ assertEquals(FILE_DATA[6], buf[0]);
+ assertEquals(FILE_END, mInput.read(buf));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "read",
+ args = {byte[].class}
+ )
+ })
+ public void testReadBufferPartial() throws IOException {
+ long len = 8;
+ openInput(0, len);
+ byte[] buf = new byte[6];
+ assertEquals(6, mInput.read(buf));
+ assertEquals(FILE_DATA[0], buf[0]);
+ assertEquals(2, mInput.read(buf));
+ assertEquals(FILE_DATA[6], buf[0]);
+ assertEquals(FILE_END, mInput.read(buf));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "available",
+ args = {}
+ )
+ })
+ public void testAvailableRead() throws IOException {
+ openInput(0, FILE_LENGTH);
+ assertEquals(FILE_LENGTH, mInput.available());
+ assertEquals(FILE_DATA[0], mInput.read());
+ assertEquals(FILE_LENGTH -1 , mInput.available());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "available",
+ args = {}
+ )
+ })
+ public void testAvailableReadBuffer() throws IOException {
+ openInput(0, FILE_LENGTH);
+ byte[] buf = new byte[3];
+ assertEquals(FILE_LENGTH, mInput.available());
+ assertEquals(buf.length, mInput.read(buf));
+ assertEquals(FILE_LENGTH - buf.length, mInput.available());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "available",
+ args = {}
+ )
+ })
+ public void testAvailableReadBufferLen() throws IOException {
+ openInput(0, FILE_LENGTH);
+ byte[] buf = new byte[3];
+ assertEquals(FILE_LENGTH, mInput.available());
+ assertEquals(2, mInput.read(buf, 0, 2));
+ assertEquals(FILE_LENGTH - 2, mInput.available());
+ }
+
+ /*
+ * Tests that AutoInputStream doesn't support mark().
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "AssetFileDescriptor.AutoCloseInputStream",
+ args = {AssetFileDescriptor.class}
+ ),
+ @TestTargetNew(
level = TestLevel.COMPLETE,
method = "mark",
args = {int.class}
@@ -103,57 +275,27 @@
level = TestLevel.COMPLETE,
method = "markSupported",
args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "available",
- args = {}
)
})
- public void testInputStream() throws IOException {
- initAssetFileDescriptor();
- FileOutputStream outputStream = null;
- outputStream = mAssetFileDes.createOutputStream();
- outputStream.write(FILE_DATA);
- mAssetFileDes.close();
-
- initAssetFileDescriptor();
- AssetFileDescriptor.AutoCloseInputStream inputStream = null;
- inputStream = new AssetFileDescriptor.AutoCloseInputStream(mAssetFileDes);
- assertEquals(FILE_LENGTH, inputStream.available());
- assertEquals(FILE_DATA[0], inputStream.read());
- byte[] readFromFile = new byte[2];
- int readBytes = inputStream.read(readFromFile);
- assertTrue(FILE_END != readBytes);
- while (readBytes < readFromFile.length) {
- readFromFile[readBytes] = (byte) inputStream.read();
- readBytes++;
- }
- assertEquals(FILE_DATA[1], readFromFile[0]);
- assertEquals(FILE_DATA[2], readFromFile[1]);
- inputStream.mark(FILE_LENGTH);
- assertEquals(5, inputStream.skip(5));
- readBytes = inputStream.read(readFromFile, OFFSET, READ_LENGTH);
- while (readBytes < READ_LENGTH) {
- readFromFile[readBytes] = (byte) inputStream.read();
- readBytes++;
- }
- assertEquals(FILE_DATA[8], readFromFile[0]);
- assertEquals(FILE_END, inputStream.read());
- inputStream.reset();
- assertEquals(FILE_END, inputStream.read(readFromFile));
- assertEquals(FILE_END, inputStream.read(readFromFile, 0, 1));
- assertFalse(inputStream.markSupported());
+ public void testMark() throws IOException {
+ openInput(0, FILE_LENGTH);
+ assertFalse(mInput.markSupported());
+ assertEquals(FILE_DATA[0], mInput.read());
+ mInput.mark(FILE_LENGTH); // should do nothing
+ assertEquals(FILE_DATA[1], mInput.read());
+ mInput.reset(); // should do nothing
+ assertEquals(FILE_DATA[2], mInput.read());
}
- private void initAssetFileDescriptor() throws FileNotFoundException {
+ private void openInput(long startOffset, long length)
+ throws IOException {
+ if (mFd != null) {
+ mFd.close();
+ mFd = null;
+ }
ParcelFileDescriptor fd =
- ParcelFileDescriptor.open(mFile, ParcelFileDescriptor.MODE_READ_WRITE);
- mAssetFileDes = new AssetFileDescriptor(fd, 0, FILE_LENGTH);
+ ParcelFileDescriptor.open(mFile, ParcelFileDescriptor.MODE_READ_WRITE);
+ mFd = new AssetFileDescriptor(fd, startOffset, length);
+ mInput = new AssetFileDescriptor.AutoCloseInputStream(mFd);
}
}
diff --git a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
index 47c52ba..8f5fead 100644
--- a/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
+++ b/tests/tests/database/src/android/database/cts/AbstractCursorTest.java
@@ -453,16 +453,9 @@
method = "getUpdatedField",
args = {int.class}
)
- @ToBeFixed(bug = "1569265", explanation = "All other updating-related methods are 'hide' and "
- + "'deprecated.")
public void testGetUpdatedField() {
mTestAbstractCursor.moveToFirst();
- try {
- assertEquals("hello", mTestAbstractCursor.getUpdatedField(0));
- fail("getUpdatedField should throws a NullPointerException here.");
- } catch (NullPointerException e) {
- // expected
- }
+ assertNull(mTestAbstractCursor.getUpdatedField(0));
}
@TestTargetNew(
@@ -746,12 +739,6 @@
return mRows.length;
}
- @Deprecated
- @Override
- public boolean deleteRow() {
- return false;
- }
-
@Override
public String[] getColumnNames() {
return mColumnNames;
diff --git a/tests/tests/database/src/android/database/cts/CursorWrapperTest.java b/tests/tests/database/src/android/database/cts/CursorWrapperTest.java
index dba9784..df90237 100644
--- a/tests/tests/database/src/android/database/cts/CursorWrapperTest.java
+++ b/tests/tests/database/src/android/database/cts/CursorWrapperTest.java
@@ -750,7 +750,17 @@
private void setupDatabase() {
File dbDir = getContext().getDir("tests", Context.MODE_PRIVATE);
- mDatabaseFile = new File(dbDir, "database_test.db");
+ /* don't use the same database name as the one in super class
+ * this class's setUp() method deletes a database file just opened by super.setUp().
+ * that can cause corruption in database in the following situation:
+ * super.setUp() creates the database, inserts some data into it.
+ * this class setUp() deletes just the database file but not the associated
+ * database files such as wal, shm files.
+ * solution is to have this class delete the whole database directory.
+ * better yet, this class shouldn't extend DatabaseCursortest at all.
+ * TODO: fix this bogus cts class hierarchy
+ */
+ mDatabaseFile = new File(dbDir, "cursor_test.db");
if (mDatabaseFile.exists()) {
mDatabaseFile.delete();
}
diff --git a/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java b/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
index 4d0c6ac..7a8657d 100644
--- a/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
+++ b/tests/tests/database/src/android/database/cts/DatabaseCursorTest.java
@@ -103,43 +103,6 @@
}
@MediumTest
- public void testCursorUpdate() {
- mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, d INTEGER, s INTEGER);");
- for (int i = 0; i < 20; i++) {
- mDatabase.execSQL("INSERT INTO test (d, s) VALUES (" + i + "," + i % 2 + ");");
- }
-
- Cursor testCursor = getTestCursor(mDatabase.query("test", null, "s = 0", null, null, null,
- null));
-
- int dCol = testCursor.getColumnIndexOrThrow("d");
- int sCol = testCursor.getColumnIndexOrThrow("s");
-
- int count = 0;
- while (testCursor.moveToNext()) {
- assertTrue(testCursor.updateInt(dCol, 3));
- count++;
- }
- assertEquals(10, count);
-
- assertTrue(testCursor.commitUpdates());
-
- assertTrue(testCursor.requery());
-
- count = 0;
- while (testCursor.moveToNext()) {
- assertEquals(3, testCursor.getInt(dCol));
- count++;
- }
-
- assertEquals(10, count);
- assertTrue(testCursor.moveToFirst());
- assertTrue(testCursor.deleteRow());
- assertEquals(9, testCursor.getCount());
- testCursor.close();
- }
-
- @MediumTest
public void testBlob() throws Exception {
// create table
mDatabase.execSQL(
@@ -178,23 +141,6 @@
assertEquals(s, testCursor.getString(sCol));
assertEquals((double) d, testCursor.getDouble(dCol));
assertEquals((long) l, testCursor.getLong(lCol));
-
- // new byte[]
- byte[] newblob = new byte[1000];
- value = 98;
- Arrays.fill(blob, value);
-
- testCursor.updateBlob(bCol, newblob);
- cBlob = testCursor.getBlob(bCol);
- assertTrue(Arrays.equals(newblob, cBlob));
-
- // commit
- assertTrue(testCursor.commitUpdates());
- assertTrue(testCursor.requery());
- testCursor.moveToNext();
- cBlob = testCursor.getBlob(bCol);
- assertTrue(Arrays.equals(newblob, cBlob));
- testCursor.close();
}
@MediumTest
diff --git a/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java b/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
index c47b65b..ae2a204 100644
--- a/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
+++ b/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
@@ -33,11 +33,15 @@
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteStatement;
import android.os.Parcel;
+import android.os.ParcelFileDescriptor;
import android.test.AndroidTestCase;
+import android.test.MoreAsserts;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintStream;
@TestTargetClass(android.database.DatabaseUtils.class)
@@ -64,6 +68,8 @@
assertNotNull(mDatabase);
mDatabase.execSQL("CREATE TABLE " + TABLE_NAME + " (_id INTEGER PRIMARY KEY, " +
"name TEXT, age INTEGER, address TEXT);");
+ mDatabase.execSQL(
+ "CREATE TABLE blob_test (_id INTEGER PRIMARY KEY, name TEXT, data BLOB)");
}
@Override
@@ -769,11 +775,98 @@
args = new String[] { "1000" }; // NO people can be older than this.
try {
- DatabaseUtils.stringForQuery(statement, args);
+ DatabaseUtils.blobFileDescriptorForQuery(statement, args);
fail("should throw SQLiteDoneException");
} catch (SQLiteDoneException e) {
// expected
}
statement.close();
}
-}
\ No newline at end of file
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "blobFileDescriptorForQuery",
+ args = {android.database.sqlite.SQLiteDatabase.class, java.lang.String.class,
+ java.lang.String[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "blobFileDescriptorForQuery",
+ args = {android.database.sqlite.SQLiteStatement.class, java.lang.String[].class}
+ )
+ })
+ public void testBlobFileDescriptorForQuery() throws Exception {
+ String data1 = "5300FEFF";
+ String data2 = "DECAFBAD";
+ mDatabase.execSQL("INSERT INTO blob_test (name, data) VALUES ('Mike', X'" + data1 + "')");
+
+ String query = "SELECT data FROM blob_test";
+ assertFileDescriptorContent(parseBlob(data1),
+ DatabaseUtils.blobFileDescriptorForQuery(mDatabase, query, null));
+
+ mDatabase.execSQL("INSERT INTO blob_test (name, data) VALUES ('Jack', X'" + data2 + "');");
+ query = "SELECT data FROM blob_test WHERE name = ?";
+ String[] args = new String[] { "Jack" };
+ assertFileDescriptorContent(parseBlob(data2),
+ DatabaseUtils.blobFileDescriptorForQuery(mDatabase, query, args));
+
+ args = new String[] { "No such name" };
+ try {
+ DatabaseUtils.stringForQuery(mDatabase, query, args);
+ fail("should throw SQLiteDoneException");
+ } catch (SQLiteDoneException e) {
+ // expected
+ }
+
+ query = "SELECT data FROM blob_test WHERE name = ?;";
+ SQLiteStatement statement = mDatabase.compileStatement(query);
+ args = new String[] { "Mike" };
+ assertFileDescriptorContent(parseBlob(data1),
+ DatabaseUtils.blobFileDescriptorForQuery(statement, args));
+
+ args = new String[] { "No such name" };
+ try {
+ DatabaseUtils.blobFileDescriptorForQuery(statement, args);
+ fail("should throw SQLiteDoneException");
+ } catch (SQLiteDoneException e) {
+ // expected
+ }
+ statement.close();
+ }
+
+ private static byte[] parseBlob(String src) {
+ int len = src.length();
+ byte[] result = new byte[len / 2];
+
+ for (int i = 0; i < len/2; i++) {
+ int val;
+ char c1 = src.charAt(i*2);
+ char c2 = src.charAt(i*2+1);
+ int val1 = Character.digit(c1, 16);
+ int val2 = Character.digit(c2, 16);
+ val = (val1 << 4) | val2;
+ result[i] = (byte)val;
+ }
+ return result;
+ }
+
+ private static void assertFileDescriptorContent(byte[] expected, ParcelFileDescriptor fd)
+ throws IOException {
+ assertInputStreamContent(expected, new ParcelFileDescriptor.AutoCloseInputStream(fd));
+ }
+
+ private static void assertInputStreamContent(byte[] expected, InputStream is)
+ throws IOException {
+ try {
+ byte[] observed = new byte[expected.length];
+ int count = is.read(observed);
+ assertEquals(expected.length, count);
+ assertEquals(-1, is.read());
+ MoreAsserts.assertEquals(expected, observed);
+ } finally {
+ is.close();
+ }
+ }
+
+}
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 ae5b9d4..d608c2f 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteCursorTest.java
@@ -24,6 +24,7 @@
import android.content.Context;
import android.database.AbstractCursor;
+import android.database.Cursor;
import android.database.CursorWindow;
import android.database.DataSetObserver;
import android.database.StaleDataException;
@@ -79,8 +80,8 @@
TEST_SQL, TABLE_NAME);
try {
new SQLiteCursor(mDatabase, cursorDriver, TABLE_NAME, null);
- fail("constructor didn't throw NullPointerException when SQLiteQuery is null");
- } catch (NullPointerException e) {
+ fail("constructor didn't throw IllegalArgumentException when SQLiteQuery is null");
+ } catch (IllegalArgumentException e) {
}
// get SQLiteCursor by querying database
@@ -221,6 +222,44 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "requery",
+ args = {}
+ )
+ })
+ public void testRequery2() {
+ mDatabase.disableWriteAheadLogging();
+ mDatabase.execSQL("create table testRequery2 (i int);");
+ mDatabase.execSQL("insert into testRequery2 values(1);");
+ mDatabase.execSQL("insert into testRequery2 values(2);");
+ Cursor c = mDatabase.rawQuery("select * from testRequery2 order by i", null);
+ assertEquals(2, c.getCount());
+ assertTrue(c.moveToFirst());
+ assertEquals(1, c.getInt(0));
+ assertTrue(c.moveToNext());
+ assertEquals(2, c.getInt(0));
+ // add more data to the table and requery
+ mDatabase.execSQL("insert into testRequery2 values(3);");
+ assertTrue(c.requery());
+ assertEquals(3, c.getCount());
+ assertTrue(c.moveToFirst());
+ assertEquals(1, c.getInt(0));
+ assertTrue(c.moveToNext());
+ assertEquals(2, c.getInt(0));
+ assertTrue(c.moveToNext());
+ 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
+ }
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
method = "getColumnIndex",
args = {java.lang.String.class}
),
@@ -242,16 +281,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "getDatabase",
- args = {}
- )
- public void testGetDatabase() {
- SQLiteCursor cursor = getCursor();
- assertSame(mDatabase, cursor.getDatabase());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "setSelectionArguments",
args = {java.lang.String[].class}
)
diff --git a/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java b/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java
index 7a18cd8..e5d5a30 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteDatabaseTest.java
@@ -18,10 +18,7 @@
import java.io.File;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
import android.content.ContentValues;
import android.database.Cursor;
@@ -37,6 +34,8 @@
import android.database.sqlite.SQLiteTransactionListener;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.SmallTest;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestLevel;
@@ -150,6 +149,7 @@
}
File dbFile = new File(mDatabaseDir, "database_test12345678.db");
+ dbFile.delete();
assertFalse(dbFile.exists());
db = SQLiteDatabase.openOrCreateDatabase(dbFile.getPath(), factory);
assertNotNull(db);
@@ -338,88 +338,6 @@
}
}
- @SuppressWarnings("deprecation")
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test getSyncedTables()",
- method = "getSyncedTables",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test markTableSyncable(String, String)",
- method = "markTableSyncable",
- args = {java.lang.String.class, java.lang.String.class}
- )
- })
- public void testGetSyncedTables() {
- mDatabase.execSQL("CREATE TABLE people (_id INTEGER PRIMARY KEY, name TEXT, "
- + "_sync_dirty INTEGER);");
- mDatabase.execSQL("CREATE TABLE _delete_people (name TEXT);");
- Map<String, String> tableMap = mDatabase.getSyncedTables();
- assertEquals(0, tableMap.size());
- mDatabase.markTableSyncable("people", "_delete_people");
- tableMap = mDatabase.getSyncedTables();
- assertEquals(1, tableMap.size());
- Set<String> keys = tableMap.keySet();
- Iterator<String> iterator = keys.iterator();
- assertTrue(iterator.hasNext());
- assertEquals("people", iterator.next());
- assertEquals("_delete_people", tableMap.get("people"));
- assertFalse(iterator.hasNext());
-
- // test sync
- mDatabase.execSQL("INSERT INTO people VALUES (0, \"foo\", 0);");
- Cursor c = mDatabase.query("people", new String[] {"_id", "name" },
- "_id = 0", null, null, null, null);
- assertTrue(c.moveToFirst());
- c.updateString(1, "updated");
- c.commitUpdates();
- c.close();
- c = mDatabase.query("people", new String[] {"_id", "_sync_dirty" },
- "_id = 0", null, null, null, null);
- assertTrue(c.moveToFirst());
- // _sync_dirty flag has been set
- assertEquals(1, c.getInt(1));
- c.close();
- }
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test markTableSyncable(String, String, String)",
- method = "markTableSyncable",
- args = {java.lang.String.class, java.lang.String.class, java.lang.String.class}
- )
- public void testMarkTableSyncable() {
- mDatabase.execSQL("CREATE TABLE phone (_id INTEGER PRIMARY KEY, _people_id INTEGER, " +
- "name TEXT);");
- mDatabase.execSQL("CREATE TABLE people (_id INTEGER PRIMARY KEY, " +
- "name TEXT, _sync_dirty INTEGER);");
- mDatabase.markTableSyncable("phone", "_people_id", "people");
-
- Map<String, String> tableMap = mDatabase.getSyncedTables();
- // since no delete table was given, there is no mapping
- assertEquals(0, tableMap.size());
-
- // test sync
- mDatabase.execSQL("INSERT INTO people VALUES (13, \"foo\", 0);");
- mDatabase.execSQL("INSERT INTO phone VALUES (0, 13, \"bar\");");
- Cursor c = mDatabase.query("phone", new String[] {"_id", "name" },
- "_id = 0", null, null, null, null);
- assertTrue(c.moveToFirst());
- c.updateString(1, "updated");
- c.commitUpdates();
- c.close();
- c = mDatabase.query("people", new String[] {"_id", "_sync_dirty" },
- "_id = 13", null, null, null, null);
- assertTrue(c.moveToFirst());
- // _sync_dirty flag has been set
- assertEquals(1, c.getInt(1));
- c.close();
- }
-
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -546,7 +464,8 @@
mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Jim', 35, 'Chicago');");
// delete one record.
- mDatabase.delete(TABLE_NAME, "name = 'Mike'", null);
+ int count = mDatabase.delete(TABLE_NAME, "name = 'Mike'", null);
+ assertEquals(1, count);
Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION, null,
null, null, null, null);
@@ -564,7 +483,8 @@
cursor.close();
// delete another record.
- mDatabase.delete(TABLE_NAME, "name = ?", new String[] { "Jack" });
+ count = mDatabase.delete(TABLE_NAME, "name = ?", new String[] { "Jack" });
+ assertEquals(1, count);
cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION, null, null, null,
null, null);
@@ -581,7 +501,8 @@
mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Jack', 30, 'London');");
// delete all records.
- mDatabase.delete(TABLE_NAME, null, null);
+ count = mDatabase.delete(TABLE_NAME, null, null);
+ assertEquals(3, count);
cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION, null, null, null, null, null);
assertNotNull(cursor);
@@ -1594,4 +1515,128 @@
assertEquals(1, cursor.getInt(0));
assertEquals(2, cursor.getInt(1));
}
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "test enableWriteAheadLogging",
+ method = "enableWriteAheadLogging",
+ args = {}
+ )
+ /**
+ * With sqlite's write-ahead-logging (WAL) enabled, readers get old version of data
+ * from the table that a writer is modifying at the same time.
+ * <p>
+ * This method does the following to test this sqlite3 feature
+ * <ol>
+ * <li>creates a table in the database and populates it with 5 rows of data</li>
+ * <li>do "select count(*) from this_table" and expect to receive 5</li>
+ * <li>start a writer thread who BEGINs a transaction, INSERTs a single row
+ * into this_table</li>
+ * <li>writer stops the transaction at this point, kicks off a reader thread - which will
+ * do the above SELECT query: "select count(*) from this_table"</li>
+ * <li>this query should return value 5 - because writer is still in transaction and
+ * sqlite returns OLD version of the data</li>
+ * <li>writer ends the transaction, thus making the extra row now visible to everyone</li>
+ * <li>reader is kicked off again to do the same query. this time query should
+ * return value = 6 which includes the newly inserted row into this_table.</li>
+ *</p>
+ * @throws InterruptedException
+ */
+ @LargeTest
+ public void testReaderGetsOldVersionOfDataWhenWriterIsInXact() throws InterruptedException {
+ // redo setup to create WAL enabled database
+ mDatabase.close();
+ new File(mDatabase.getPath()).delete();
+ mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null, null);
+ boolean rslt = mDatabase.enableWriteAheadLogging();
+ assertTrue(rslt);
+ assertNotNull(mDatabase);
+
+ // create a new table and insert 5 records into it.
+ mDatabase.execSQL("CREATE TABLE t1 (i int, j int);");
+ mDatabase.beginTransaction();
+ for (int i = 0; i < 5; i++) {
+ mDatabase.execSQL("insert into t1 values(?,?);", new String[] {i+"", i+""});
+ }
+ mDatabase.setTransactionSuccessful();
+ mDatabase.endTransaction();
+
+ // make sure a reader can read the above data
+ ReaderQueryingData r1 = new ReaderQueryingData(5);
+ r1.start();
+ Thread.yield();
+ try {r1.join();} catch (Exception e) {}
+
+ WriterDoingSingleTransaction w = new WriterDoingSingleTransaction();
+ w.start();
+ w.join();
+ }
+
+ private class WriterDoingSingleTransaction extends Thread {
+ @Override public void run() {
+ // start a transaction
+ mDatabase.beginTransactionNonExclusive();
+ mDatabase.execSQL("insert into t1 values(?,?);", new String[] {"11", "11"});
+ assertTrue(mDatabase.isOpen());
+
+ // while the writer is in a transaction, start a reader and make sure it can still
+ // read 5 rows of data (= old data prior to the current transaction)
+ ReaderQueryingData r1 = new ReaderQueryingData(5);
+ r1.start();
+ try {r1.join();} catch (Exception e) {}
+
+ // now, have the writer do the select count(*)
+ // it should execute on the same connection as this transaction
+ // and count(*) should reflect the newly inserted row
+ Long l = DatabaseUtils.longForQuery(mDatabase, "select count(*) from t1", null);
+ assertEquals(6, l.intValue());
+
+ // end transaction
+ mDatabase.setTransactionSuccessful();
+ mDatabase.endTransaction();
+
+ // reader should now be able to read 6 rows = new data AFTER this transaction
+ r1 = new ReaderQueryingData(6);
+ r1.start();
+ try {r1.join();} catch (Exception e) {}
+ }
+ }
+
+ private class ReaderQueryingData extends Thread {
+ private int count;
+ /**
+ * constructor with a param to indicate the number of rows expected to be read
+ */
+ public ReaderQueryingData(int count) {
+ this.count = count;
+ }
+ @Override public void run() {
+ Long l = DatabaseUtils.longForQuery(mDatabase, "select count(*) from t1", null);
+ assertEquals(count, l.intValue());
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "test exceptions from enableWriteAheadLogging().",
+ method = "enableWriteAheadLogging",
+ args = {}
+ )
+ public void testExceptionsFromEnableWriteAheadLogging() {
+ // attach a database
+ // redo setup to create WAL enabled database
+ mDatabase.close();
+ new File(mDatabase.getPath()).delete();
+ mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null, null);
+
+ // attach a database and call enableWriteAheadLogging - should not be allowed
+ mDatabase.execSQL("attach database ':memory:' as memoryDb");
+ boolean rslt = mDatabase.enableWriteAheadLogging();
+ assertFalse(rslt);
+ // enableWriteAheadLogging on memory database is not allowed
+ SQLiteDatabase db = SQLiteDatabase.create(null);
+ rslt = db.enableWriteAheadLogging();
+ assertFalse(rslt);
+ db.close();
+ }
}
diff --git a/tests/tests/database/src/android/database/sqlite/cts/SQLiteProgramTest.java b/tests/tests/database/src/android/database/sqlite/cts/SQLiteProgramTest.java
index 89918a1..a9a3293 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteProgramTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteProgramTest.java
@@ -20,13 +20,13 @@
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
-import dalvik.annotation.ToBeFixed;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDoneException;
import android.database.sqlite.SQLiteException;
+import android.database.sqlite.SQLiteQuery;
import android.database.sqlite.SQLiteStatement;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;
@@ -37,9 +37,6 @@
private SQLiteDatabase mDatabase;
- @ToBeFixed(bug="1448885", explanation="SQLiteProgram is an abstract class and its " +
- "constructor is package private, so it can not be extended directly to test. " +
- "For this reason, the test uses SQLiteStatement instead.")
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -57,79 +54,6 @@
super.tearDown();
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test getUniqueId()",
- method = "getUniqueId",
- args = {}
- )
- public void testGetUniqueId() {
- mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, text1 TEXT, text2 TEXT, " +
- "num1 INTEGER, num2 INTEGER, image BLOB);");
- final String statement = "DELETE FROM test WHERE _id=?;";
- SQLiteStatement statementOne = mDatabase.compileStatement(statement);
- SQLiteStatement statementTwo = mDatabase.compileStatement(statement);
- // since the same compiled statement is being accessed at the same time by 2 different
- // objects, they each get their own statement id
- assertTrue(statementOne.getUniqueId() != statementTwo.getUniqueId());
- statementOne.close();
- statementTwo.close();
-
- statementOne = mDatabase.compileStatement(statement);
- int n = statementOne.getUniqueId();
- statementOne.close();
- statementTwo = mDatabase.compileStatement(statement);
- assertEquals(n, statementTwo.getUniqueId());
- statementTwo.close();
-
- // now try to compile 2 different statements and they should have different uniquerIds.
- SQLiteStatement statement1 = mDatabase.compileStatement("DELETE FROM test WHERE _id=1;");
- SQLiteStatement statement2 = mDatabase.compileStatement("DELETE FROM test WHERE _id=2;");
- assertTrue(statement1.getUniqueId() != statement2.getUniqueId());
- statement1.close();
- statement2.close();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test onAllReferencesReleased(). Since sql statements are always cached in " +
- "SQLiteDatabase, compiledSql should NOT be released " +
- "when onAllReferencesReleased() is called",
- method = "onAllReferencesReleased",
- args = {}
- )
- public void testOnAllReferencesReleased() {
- mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, text1 TEXT, text2 TEXT, " +
- "num1 INTEGER, num2 INTEGER, image BLOB);");
- final String statement = "DELETE FROM test WHERE _id=?;";
- SQLiteStatement statementOne = mDatabase.compileStatement(statement);
- assertTrue(statementOne.getUniqueId() > 0);
- int nStatement = statementOne.getUniqueId();
- statementOne.releaseReference();
- assertTrue(statementOne.getUniqueId() == nStatement);
- statementOne.close();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test onAllReferencesReleasedFromContainer(). " +
- "Since sql statements are always cached in " +
- "SQLiteDatabase, compiledSql should NOT be released " +
- "when onAllReferencesReleasedFromContainer() is called",
- args = {}
- )
- public void testOnAllReferencesReleasedFromContainer() {
- mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, text1 TEXT, text2 TEXT, " +
- "num1 INTEGER, num2 INTEGER, image BLOB);");
- final String statement = "DELETE FROM test WHERE _id=?;";
- SQLiteStatement statementOne = mDatabase.compileStatement(statement);
- assertTrue(statementOne.getUniqueId() > 0);
- int nStatement = statementOne.getUniqueId();
- statementOne.releaseReferenceFromContainer();
- assertTrue(statementOne.getUniqueId() == nStatement);
- statementOne.close();
- }
-
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -195,39 +119,36 @@
}
statement.close();
- statement = mDatabase.compileStatement("SELECT text1 FROM test;");
+ Cursor cursor = null;
try {
- statement.bindString(1, "foo");
+ cursor = mDatabase.query("test", new String[]{"text1"}, "where text1='a'",
+ new String[]{"foo"}, null, null, null);
fail("Should throw exception (no value to bind)");
} catch (SQLiteException expected) {
// expected
- }
-
- statement =
- mDatabase.compileStatement("SELECT text1 FROM test WHERE text2 = ? AND num2 = ?;");
-
- try {
- statement.bindString(0, "Jack");
- fail("Should throw exception (index is 0)");
- } catch (SQLiteException expected) {
- // expected
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
try {
- statement.bindLong(-1, 30);
- fail("Should throw exception (index is negative)");
- } catch (SQLiteException expected) {
- // expected
- }
- try {
- statement.bindDouble(3, 589.0);
+ cursor = mDatabase.query("test", new String[]{"text1"}, "where text1='a'",
+ new String[]{"foo", "bar"}, null, null, null);
fail("Should throw exception (index too large)");
} catch (SQLiteException expected) {
// expected
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
// test positive case
+ statement = mDatabase.compileStatement(
+ "SELECT text1 FROM test WHERE text2 = ? AND num2 = ?;");
statement.bindString(1, "Jack");
statement.bindLong(2, 30);
assertEquals("Mike", statement.simpleQueryForString());
+ statement.close();
}
@TestTargetNew(
@@ -303,64 +224,4 @@
MoreAsserts.assertEquals(blob, value);
cursor.close();
}
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "onAllReferencesReleased",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "onAllReferencesReleasedFromContainer",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "compile",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "native_bind_blob",
- args = {int.class, byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "native_bind_double",
- args = {int.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "native_bind_long",
- args = {int.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "native_bind_null",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "native_compile",
- args = {java.lang.String.class}
- )
- })
- @ToBeFixed(bug = "1448885", explanation = "Cannot test protected methods, since constructor" +
- " is private.")
- public void testProtectedMethods() {
- // cannot test
- }
-
- private void closeDatabaseWithOrphanedStatement(){
- try {
- mDatabase.close();
- } catch (SQLiteException e) {
- // A SQLiteException is thrown if there are some unfinialized exceptions
- // This is expected as some tests explicitly leave statements in this state
- if (!e.getMessage().equals("Unable to close due to unfinalised statements")) {
- throw e;
- }
- }
- }
}
diff --git a/tests/tests/database/src/android/database/sqlite/cts/SQLiteStatementTest.java b/tests/tests/database/src/android/database/sqlite/cts/SQLiteStatementTest.java
index ec6b79a..b568b8c 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteStatementTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteStatementTest.java
@@ -21,19 +21,35 @@
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
+import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
+import android.database.DatabaseUtils;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDoneException;
import android.database.sqlite.SQLiteStatement;
+import android.os.ParcelFileDescriptor;
import android.test.AndroidTestCase;
+import android.test.MoreAsserts;
+
+import java.io.IOException;
+import java.io.InputStream;
@TestTargetClass(android.database.sqlite.SQLiteStatement.class)
public class SQLiteStatementTest extends AndroidTestCase {
private static final String STRING1 = "this is a test";
private static final String STRING2 = "another test";
+ private static final byte[][] BLOBS = new byte [][] {
+ parseBlob("86FADCF1A820666AEBD0789F47932151A2EF734269E8AC4E39630AB60519DFD8"),
+ new byte[1],
+ null,
+ parseBlob("00"),
+ parseBlob("FF"),
+ parseBlob("D7B500FECF25F7A4D83BF823D3858690790F2526013DE6CAE9A69170E2A1E47238"),
+ };
+
private static final String DATABASE_NAME = "database_test.db";
private static final int CURRENT_DATABASE_VERSION = 42;
@@ -60,40 +76,62 @@
mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, data TEXT);");
}
+ private void populateBlobTable() {
+ mDatabase.execSQL("CREATE TABLE blob_test (_id INTEGER PRIMARY KEY, data BLOB)");
+ for (int i = 0; i < BLOBS.length; i++) {
+ ContentValues values = new ContentValues();
+ values.put("_id", i);
+ values.put("data", BLOBS[i]);
+ mDatabase.insert("blob_test", null, values);
+ }
+ }
+
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "execute",
+ method = "executeUpdateDelete",
args = {}
)
public void testExecute() {
+ mDatabase.disableWriteAheadLogging();
populateDefaultTable();
- Cursor c = mDatabase.query("test", null, null, null, null, null, null);
- assertEquals(0, c.getCount());
+ assertEquals(0, DatabaseUtils.longForQuery(mDatabase, "select count(*) from test", null));
- // test insert
- SQLiteStatement statement = mDatabase.compileStatement(
- "INSERT INTO test (data) VALUES ('" + STRING1 + "')");
- statement.execute();
+ // test update
+ // insert 2 rows and then update them.
+ SQLiteStatement statement1 = mDatabase.compileStatement(
+ "INSERT INTO test (data) VALUES ('" + STRING2 + "')");
+ assertEquals(1, statement1.executeInsert());
+ assertEquals(2, statement1.executeInsert());
+ SQLiteStatement statement2 =
+ mDatabase.compileStatement("UPDATE test set data = 'a' WHERE _id > 0");
+ assertEquals(2, statement2.executeUpdateDelete());
+ statement2.close();
+ // should still have 2 rows in the table
+ assertEquals(2, DatabaseUtils.longForQuery(mDatabase, "select count(*) from test", null));
- c = mDatabase.query("test", null, null, null, null, null, null);
- assertEquals(1, c.getCount());
+ // test delete
+ // insert 2 more rows and delete 3 of them
+ assertEquals(3, statement1.executeInsert());
+ assertEquals(4, statement1.executeInsert());
+ statement1.close();
+ statement2 = mDatabase.compileStatement("DELETE from test WHERE _id < 4");
+ assertEquals(3, statement2.executeUpdateDelete());
+ statement2.close();
+ // should still have 1 row1 in the table
+ assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "select count(*) from test", null));
- c.moveToFirst();
- assertEquals(STRING1, c.getString(c.getColumnIndex("data")));
-
- // invalid SQL statement
- statement = mDatabase.compileStatement(
- "SELECT * FROM test WHERE data=\"" + STRING1 + "\"");
+ // if the SQL statement is something that causes rows of data to
+ // be returned, executeUpdateDelete() (and execute()) throw an exception.
+ statement2 = mDatabase.compileStatement("SELECT count(*) FROM test");
try {
- statement.execute();
- fail("There should be a SQLException thrown out.");
+ statement2.executeUpdateDelete();
+ fail("exception expected");
} catch (SQLException e) {
- // expected.
+ // expected
+ } finally {
+ statement2.close();
}
-
- c.deactivate();
- statement.close();
}
@TestTargets({
@@ -118,25 +156,33 @@
SQLiteStatement statement = mDatabase.compileStatement(
"INSERT INTO test (data) VALUES ('" + STRING2 + "')");
assertEquals(1, statement.executeInsert());
+ statement.close();
+
+ // try to insert another row with the same id. last inserted rowid should be -1
+ statement = mDatabase.compileStatement("insert or ignore into test values(1, 1);");
+ assertEquals(-1, statement.executeInsert());
+ statement.close();
c = mDatabase.query("test", null, null, null, null, null, null);
assertEquals(1, c.getCount());
c.moveToFirst();
assertEquals(STRING2, c.getString(c.getColumnIndex("data")));
+ c.close();
- // invalid SQL statement
+ // if the sql statement is something that causes rows of data to
+ // be returned, executeInsert() throws an exception
statement = mDatabase.compileStatement(
"SELECT * FROM test WHERE data=\"" + STRING2 + "\"");
try {
statement.executeInsert();
- fail("There should be a SQLException thrown out.");
+ fail("exception expected");
} catch (SQLException e) {
- // expected.
- }
+ // expected
+ } finally {
+ statement.close();
- c.deactivate();
- statement.close();
+ }
}
@TestTargetNew(
@@ -196,4 +242,177 @@
statement.close();
}
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testSimpleQueryForBlobFileDescriptorSuccessNormal() throws IOException {
+ doTestSimpleQueryForBlobFileDescriptorSuccess(0);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testSimpleQueryForBlobFileDescriptorSuccessEmpty() throws IOException {
+ doTestSimpleQueryForBlobFileDescriptorSuccess(1);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testSimpleQueryForBlobFileDescriptorSuccessNull() {
+ populateBlobTable();
+
+ String sql = "SELECT data FROM blob_test WHERE _id = " + 2;
+ SQLiteStatement stm = mDatabase.compileStatement(sql);
+ assertNull(stm.simpleQueryForBlobFileDescriptor());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testSimpleQueryForBlobFileDescriptorSuccess00() throws IOException {
+ doTestSimpleQueryForBlobFileDescriptorSuccess(3);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testSimpleQueryForBlobFileDescriptorSuccessFF() throws IOException {
+ doTestSimpleQueryForBlobFileDescriptorSuccess(4);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testSimpleQueryForBlobFileDescriptorSuccessEmbeddedNul() throws IOException {
+ doTestSimpleQueryForBlobFileDescriptorSuccess(5);
+ }
+
+ private void doTestSimpleQueryForBlobFileDescriptorSuccess(int i) throws IOException {
+ populateBlobTable();
+
+ String sql = "SELECT data FROM blob_test WHERE _id = " + i;
+ SQLiteStatement stm = mDatabase.compileStatement(sql);
+ ParcelFileDescriptor fd = stm.simpleQueryForBlobFileDescriptor();
+ assertFileDescriptorContent(BLOBS[i], fd);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testSimpleQueryForBlobFileDescriptorSuccessParam() throws IOException {
+ populateBlobTable();
+
+ String sql = "SELECT data FROM blob_test WHERE _id = ?";
+ SQLiteStatement stm = mDatabase.compileStatement(sql);
+ stm.bindLong(1, 0);
+ ParcelFileDescriptor fd = stm.simpleQueryForBlobFileDescriptor();
+ assertFileDescriptorContent(BLOBS[0], fd);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testGetBlobFailureNoParam() throws Exception {
+ populateBlobTable();
+
+ String sql = "SELECT data FROM blob_test WHERE _id = 100";
+ SQLiteStatement stm = mDatabase.compileStatement(sql);
+ ParcelFileDescriptor fd = null;
+ SQLiteDoneException expectedException = null;
+ try {
+ fd = stm.simpleQueryForBlobFileDescriptor();
+ } catch (SQLiteDoneException ex) {
+ expectedException = ex;
+ } finally {
+ if (fd != null) {
+ fd.close();
+ fd = null;
+ }
+ }
+ assertNotNull("Should have thrown SQLiteDoneException", expectedException);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "simpleQueryForBlobFileDescriptor",
+ args = {}
+ )
+ public void testGetBlobFailureParam() throws Exception {
+ populateBlobTable();
+
+ String sql = "SELECT data FROM blob_test WHERE _id = ?";
+ SQLiteStatement stm = mDatabase.compileStatement(sql);
+ stm.bindLong(1, 100);
+ ParcelFileDescriptor fd = null;
+ SQLiteDoneException expectedException = null;
+ try {
+ fd = stm.simpleQueryForBlobFileDescriptor();
+ } catch (SQLiteDoneException ex) {
+ expectedException = ex;
+ } finally {
+ if (fd != null) {
+ fd.close();
+ fd = null;
+ }
+ }
+ assertNotNull("Should have thrown SQLiteDoneException", expectedException);
+ }
+
+ /*
+ * Convert string of hex digits to byte array.
+ * Results are undefined for poorly formed string.
+ *
+ * @param src hex string
+ */
+ private static byte[] parseBlob(String src) {
+ int len = src.length();
+ byte[] result = new byte[len / 2];
+
+ for (int i = 0; i < len/2; i++) {
+ int val;
+ char c1 = src.charAt(i*2);
+ char c2 = src.charAt(i*2+1);
+ int val1 = Character.digit(c1, 16);
+ int val2 = Character.digit(c2, 16);
+ val = (val1 << 4) | val2;
+ result[i] = (byte)val;
+ }
+ return result;
+ }
+
+ private static void assertFileDescriptorContent(byte[] expected, ParcelFileDescriptor fd)
+ throws IOException {
+ assertInputStreamContent(expected, new ParcelFileDescriptor.AutoCloseInputStream(fd));
+ }
+
+ private static void assertInputStreamContent(byte[] expected, InputStream is)
+ throws IOException {
+ try {
+ byte[] observed = new byte[expected.length];
+ int count = is.read(observed);
+ assertEquals(expected.length, count);
+ assertEquals(-1, is.read());
+ MoreAsserts.assertEquals(expected, observed);
+ } finally {
+ is.close();
+ }
+ }
}
diff --git a/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java b/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java
index 07612d4..b00a383 100644
--- a/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java
@@ -96,7 +96,6 @@
)
public void testCanvas1() {
final Canvas c = new Canvas();
- assertNull(c.getGL());
}
@TestTargetNew(
@@ -128,36 +127,6 @@
new Canvas(mMutableBitmap);
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "Canvas",
- args = {javax.microedition.khronos.opengles.GL.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getGL",
- args = {}
- )
- })
- public void testCanvas3() {
- Canvas c = new Canvas();
- assertNull(c.getGL());
- final MyGL myGL = new MyGL();
- c = new Canvas(myGL);
- assertTrue(myGL.equals(c.getGL()));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "freeGlCaches",
- args = {}
- )
- public void testFreeGlCaches() {
- // can't get the changed state
- Canvas.freeGlCaches();
- }
-
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "setBitmap",
@@ -173,16 +142,6 @@
// expected
}
- // abnormal case: GL not null
- final Canvas c = new Canvas(new MyGL());
- try {
- c.setBitmap(mMutableBitmap);
- fail("should throw out RuntimeException when setting MutableBitmap to Canvas "
- + "when the Canvas is created with GL");
- } catch (RuntimeException e) {
- // expected
- }
-
// abnormal case: bitmap to be set has been recycled
mMutableBitmap.recycle();
try {
@@ -199,39 +158,6 @@
assertEquals(31, mCanvas.getHeight());
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setViewport",
- args = {int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getWidth",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getHeight",
- args = {}
- )
- })
- public void testSetViewport() {
- assertEquals(BITMAP_WIDTH, mCanvas.getWidth());
- assertEquals(BITMAP_HEIGHT, mCanvas.getHeight());
-
- // set viewport has no effect for bitmap based canvas
- mCanvas.setViewport(BITMAP_HEIGHT, BITMAP_WIDTH);
- assertEquals(BITMAP_WIDTH, mCanvas.getWidth());
- assertEquals(BITMAP_HEIGHT, mCanvas.getHeight());
-
- // only GL based canvas that can set viewport
- mCanvas = new Canvas(new MyGL());
- mCanvas.setViewport(BITMAP_HEIGHT, BITMAP_WIDTH);
- assertEquals(BITMAP_HEIGHT, mCanvas.getWidth());
- assertEquals(BITMAP_WIDTH, mCanvas.getHeight());
- }
-
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "isOpaque",
@@ -2266,8 +2192,4 @@
assertEquals(0.0f, values[7]);
assertEquals(1.0f, values[8]);
}
-
- private class MyGL implements GL {
- //do nothing
- }
}
diff --git a/tests/tests/graphics/src/android/graphics/cts/PorterDuff_ModeTest.java b/tests/tests/graphics/src/android/graphics/cts/PorterDuff_ModeTest.java
deleted file mode 100644
index 170992d..0000000
--- a/tests/tests/graphics/src/android/graphics/cts/PorterDuff_ModeTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.graphics.cts;
-
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuff.Mode;
-import android.test.AndroidTestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(PorterDuff.Mode.class)
-public class PorterDuff_ModeTest extends AndroidTestCase {
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void testValueOf() {
- assertEquals(Mode.CLEAR, Mode.valueOf("CLEAR"));
- assertEquals(Mode.SRC, Mode.valueOf("SRC"));
- assertEquals(Mode.DST, Mode.valueOf("DST"));
- assertEquals(Mode.SRC_OVER, Mode.valueOf("SRC_OVER"));
- assertEquals(Mode.DST_OVER, Mode.valueOf("DST_OVER"));
- assertEquals(Mode.SRC_IN, Mode.valueOf("SRC_IN"));
- assertEquals(Mode.DST_IN, Mode.valueOf("DST_IN"));
- assertEquals(Mode.SRC_OUT, Mode.valueOf("SRC_OUT"));
- assertEquals(Mode.DST_OUT, Mode.valueOf("DST_OUT"));
- assertEquals(Mode.SRC_ATOP, Mode.valueOf("SRC_ATOP"));
- assertEquals(Mode.DST_ATOP, Mode.valueOf("DST_ATOP"));
- assertEquals(Mode.XOR, Mode.valueOf("XOR"));
- assertEquals(Mode.DARKEN, Mode.valueOf("DARKEN"));
- assertEquals(Mode.LIGHTEN, Mode.valueOf("LIGHTEN"));
- assertEquals(Mode.MULTIPLY, Mode.valueOf("MULTIPLY"));
- assertEquals(Mode.SCREEN, Mode.valueOf("SCREEN"));
- // Every Mode element will be tested in other test cases.
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "values",
- args = {}
- )
- public void testValues() {
- // set the expected value
- Mode[] expected = {
- Mode.CLEAR,
- Mode.SRC,
- Mode.DST,
- Mode.SRC_OVER,
- Mode.DST_OVER,
- Mode.SRC_IN,
- Mode.DST_IN,
- Mode.SRC_OUT,
- Mode.DST_OUT,
- Mode.SRC_ATOP,
- Mode.DST_ATOP,
- Mode.XOR,
- Mode.DARKEN,
- Mode.LIGHTEN,
- Mode.MULTIPLY,
- Mode.SCREEN};
- Mode[] actual = Mode.values();
- assertEquals(expected.length, actual.length);
- for (int i = 0; i < actual.length; i ++) {
- assertEquals(expected[i], actual[i]);
- }
- }
-
-}
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java
index b47d906..604f1e2 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java
@@ -283,9 +283,6 @@
assertFalse(layerDrawable.setDrawableByLayerId(30, d1));
- layerDrawable.setDrawableByLayerId(20, null);
- assertEquals(null, layerDrawable.getDrawable(1));
-
try {
layerDrawable.getDrawable(layerDrawable.getNumberOfLayers());
fail("Should throw IndexOutOfBoundsException");
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/MipmapDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/MipmapDrawableTest.java
new file mode 100644
index 0000000..c591f3c
--- /dev/null
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/MipmapDrawableTest.java
@@ -0,0 +1,371 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.graphics.drawable.cts;
+
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.ToBeFixed;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import android.content.res.Resources;
+import android.content.res.XmlResourceParser;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.MipmapDrawable;
+import android.graphics.drawable.DrawableContainer.DrawableContainerState;
+import android.test.InstrumentationTestCase;
+import android.util.Xml;
+
+import java.io.IOException;
+
+@TestTargetClass(MipmapDrawable.class)
+public class MipmapDrawableTest extends InstrumentationTestCase {
+ private MockMipmapDrawable mMipmapDrawable;
+
+ private Resources mResources;
+
+ private DrawableContainerState mDrawableContainerState;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mMipmapDrawable = new MockMipmapDrawable();
+ mDrawableContainerState = (DrawableContainerState) mMipmapDrawable.getConstantState();
+ mResources = getInstrumentation().getTargetContext().getResources();
+ }
+
+ public void testMipmapDrawable() {
+ new MipmapDrawable();
+ // Check the values set in the constructor
+ assertNotNull(new MipmapDrawable().getConstantState());
+ assertTrue(new MockMipmapDrawable().hasCalledOnBoundsChanged());
+ }
+
+ public void testAddDrawable() {
+ assertEquals(0, mDrawableContainerState.getChildCount());
+
+ // nothing happens if drawable is null
+ mMipmapDrawable.reset();
+ mMipmapDrawable.addDrawable(null);
+ assertEquals(0, mDrawableContainerState.getChildCount());
+ assertFalse(mMipmapDrawable.hasCalledOnBoundsChanged());
+
+ mMipmapDrawable.reset();
+ mMipmapDrawable.addDrawable(new MockDrawable());
+ assertEquals(1, mDrawableContainerState.getChildCount());
+ assertTrue(mMipmapDrawable.hasCalledOnBoundsChanged());
+
+ mMipmapDrawable.reset();
+ mMipmapDrawable.addDrawable(new MockDrawable());
+ assertEquals(2, mDrawableContainerState.getChildCount());
+ assertTrue(mMipmapDrawable.hasCalledOnBoundsChanged());
+ }
+
+ public void testSortedByHeight() {
+ Drawable small = new MockDrawable(8);
+ Drawable medium = new MockDrawable(32);
+ Drawable large = new MockDrawable(128);
+
+ mMipmapDrawable.addDrawable(medium);
+ assertSame(medium, mDrawableContainerState.getChildren()[0]);
+
+ mMipmapDrawable.addDrawable(small);
+ assertSame(small, mDrawableContainerState.getChildren()[0]);
+ assertSame(medium, mDrawableContainerState.getChildren()[1]);
+
+ mMipmapDrawable.addDrawable(large);
+ assertSame(small, mDrawableContainerState.getChildren()[0]);
+ assertSame(medium, mDrawableContainerState.getChildren()[1]);
+ assertSame(large, mDrawableContainerState.getChildren()[2]);
+
+ mMipmapDrawable.addDrawable(small);
+ assertSame(small, mDrawableContainerState.getChildren()[0]);
+ assertSame(small, mDrawableContainerState.getChildren()[1]);
+ assertSame(medium, mDrawableContainerState.getChildren()[2]);
+ assertSame(large, mDrawableContainerState.getChildren()[3]);
+
+ mMipmapDrawable.addDrawable(medium);
+ assertSame(small, mDrawableContainerState.getChildren()[0]);
+ assertSame(small, mDrawableContainerState.getChildren()[1]);
+ assertSame(medium, mDrawableContainerState.getChildren()[2]);
+ assertSame(medium, mDrawableContainerState.getChildren()[3]);
+ assertSame(large, mDrawableContainerState.getChildren()[4]);
+
+ mMipmapDrawable.addDrawable(large);
+ assertSame(small, mDrawableContainerState.getChildren()[0]);
+ assertSame(small, mDrawableContainerState.getChildren()[1]);
+ assertSame(medium, mDrawableContainerState.getChildren()[2]);
+ assertSame(medium, mDrawableContainerState.getChildren()[3]);
+ assertSame(large, mDrawableContainerState.getChildren()[4]);
+ assertSame(large, mDrawableContainerState.getChildren()[5]);
+ }
+
+ public void testSetBoundsOneItem() {
+ // the method is not called if same bounds are set
+ mMipmapDrawable.reset();
+ mMipmapDrawable.setBounds(mMipmapDrawable.getBounds());
+ assertFalse(mMipmapDrawable.hasCalledOnBoundsChanged());
+
+ // the method is called if different bounds are set, even without drawables
+ mMipmapDrawable.reset();
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, mMipmapDrawable.getBounds().height() + 1));
+ assertTrue(mMipmapDrawable.hasCalledOnBoundsChanged());
+
+ // adding an item should check bounds to see if new drawable is more appropriate
+ mMipmapDrawable.reset();
+ Drawable item = new MockDrawable(42);
+ mMipmapDrawable.addDrawable(item);
+ assertTrue(mMipmapDrawable.hasCalledOnBoundsChanged());
+
+ // the method is called if different bounds are set
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, mMipmapDrawable.getBounds().height() + 1));
+ assertTrue(mMipmapDrawable.hasCalledOnBoundsChanged());
+
+ // check that correct drawable is selected for any size.
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, item.getIntrinsicHeight() - 1));
+ assertSame(item, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, item.getIntrinsicHeight()));
+ assertSame(item, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, item.getIntrinsicHeight() + 1));
+ assertSame(item, mMipmapDrawable.getCurrent());
+ }
+
+ public void testSetBounds() {
+ Drawable small = new MockDrawable(8);
+ Drawable medium = new MockDrawable(32);
+ Drawable large = new MockDrawable(128);
+
+ mMipmapDrawable.addDrawable(large);
+ mMipmapDrawable.addDrawable(small);
+ mMipmapDrawable.addDrawable(medium);
+
+ // check that correct drawable is selected.
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, small.getIntrinsicHeight() - 1));
+ assertSame(small, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, small.getIntrinsicHeight()));
+ assertSame(small, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, small.getIntrinsicHeight() + 1));
+ assertSame(medium, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, medium.getIntrinsicHeight() - 1));
+ assertSame(medium, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, medium.getIntrinsicHeight()));
+ assertSame(medium, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, medium.getIntrinsicHeight() + 1));
+ assertSame(large, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, large.getIntrinsicHeight() - 1));
+ assertSame(large, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, large.getIntrinsicHeight()));
+ assertSame(large, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, large.getIntrinsicHeight() + 1));
+ assertSame(large, mMipmapDrawable.getCurrent());
+ }
+
+ public void testSizes() {
+ // Check default value with no mipmap defined
+ assertEquals(-1, mMipmapDrawable.getIntrinsicHeight());
+ assertEquals(-1, mMipmapDrawable.getIntrinsicWidth());
+ assertEquals(0, mMipmapDrawable.getMinimumHeight());
+ assertEquals(0, mMipmapDrawable.getMinimumWidth());
+
+ Drawable small = new MockDrawable(8, 4);
+ Drawable medium = new MockDrawable(32, 16);
+ Drawable large = new MockDrawable(128, 64);
+
+ mMipmapDrawable.addDrawable(medium);
+ assertEquals(medium.getIntrinsicHeight(), mMipmapDrawable.getIntrinsicHeight());
+ assertEquals(medium.getMinimumHeight(), mMipmapDrawable.getMinimumHeight());
+
+ mMipmapDrawable.addDrawable(large);
+ assertEquals(large.getIntrinsicHeight(), mMipmapDrawable.getIntrinsicHeight());
+ assertEquals(medium.getMinimumHeight(), mMipmapDrawable.getMinimumHeight());
+
+ mMipmapDrawable.addDrawable(small);
+ assertEquals(large.getIntrinsicHeight(), mMipmapDrawable.getIntrinsicHeight());
+ assertEquals(small.getMinimumHeight(), mMipmapDrawable.getMinimumHeight());
+ }
+
+ public void testReplacementWhenAdded() {
+ Drawable small = new MockDrawable(8);
+ Drawable medium = new MockDrawable(32);
+ Drawable large = new MockDrawable(128);
+
+ // Small bounds, so that the smallest mipmap should always be selected
+ mMipmapDrawable.setBounds(new Rect(0, 0, 0, 0));
+
+ // Providing smaller versions, that should immediately be used as current
+ mMipmapDrawable.addDrawable(large);
+ assertSame(large, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.addDrawable(medium);
+ assertSame(medium, mMipmapDrawable.getCurrent());
+
+ mMipmapDrawable.addDrawable(small);
+ assertSame(small, mMipmapDrawable.getCurrent());
+ }
+
+ public void testInflate() throws XmlPullParserException, IOException {
+ XmlResourceParser parser = getResourceParser(R.xml.mipmap_correct);
+
+ mMipmapDrawable.reset();
+ mMipmapDrawable.inflate(mResources, parser, Xml.asAttributeSet(parser));
+ assertTrue(mMipmapDrawable.hasCalledOnBoundsChanged());
+ assertEquals(3, mDrawableContainerState.getChildCount());
+
+ // The color should be the first children
+ assertTrue(mDrawableContainerState.getChildren()[0] instanceof ColorDrawable);
+ Resources resources = getInstrumentation().getTargetContext().getResources();
+
+ parser = getResourceParser(R.xml.mipmap_missing_item_drawable);
+ try {
+ mMipmapDrawable.inflate(mResources, parser, Xml.asAttributeSet(parser));
+ fail("Should throw XmlPullParserException if drawable of item is missing");
+ } catch (XmlPullParserException e) {
+ }
+ }
+
+ @ToBeFixed(bug = "1417734", explanation = "should add @throws clause into javadoc of "
+ + "MipmapDrawable#inflate(Resources, XmlPullParser, AttributeSet) when param r,"
+ + "parser or attrs is out of bounds")
+ public void testInflateWithNullParameters() throws XmlPullParserException, IOException{
+ XmlResourceParser parser = getResourceParser(R.xml.mipmap_correct);
+ try {
+ mMipmapDrawable.inflate(null, parser, Xml.asAttributeSet(parser));
+ fail("Should throw XmlPullParserException if resource is null");
+ } catch (NullPointerException e) {
+ }
+
+ try {
+ mMipmapDrawable.inflate(mResources, null, Xml.asAttributeSet(parser));
+ fail("Should throw XmlPullParserException if parser is null");
+ } catch (NullPointerException e) {
+ }
+
+ try {
+ mMipmapDrawable.inflate(mResources, parser, null);
+ fail("Should throw XmlPullParserException if AttributeSet is null");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void testMutate() {
+ Resources resources = getInstrumentation().getTargetContext().getResources();
+ MipmapDrawable d1 = (MipmapDrawable) resources.getDrawable(R.drawable.mipmapdrawable);
+ MipmapDrawable d2 = (MipmapDrawable) resources.getDrawable(R.drawable.mipmapdrawable);
+ MipmapDrawable d3 = (MipmapDrawable) resources.getDrawable(R.drawable.mipmapdrawable);
+
+ // the state does not appear to be shared before calling mutate()
+ d1.addDrawable(resources.getDrawable(R.drawable.testimage));
+ assertEquals(3, ((DrawableContainerState) d1.getConstantState()).getChildCount());
+ assertEquals(2, ((DrawableContainerState) d2.getConstantState()).getChildCount());
+ assertEquals(2, ((DrawableContainerState) d3.getConstantState()).getChildCount());
+
+ // simply call mutate to make sure no exception is thrown
+ d1.mutate();
+ d2.mutate();
+ }
+
+ private XmlResourceParser getResourceParser(int resId) throws XmlPullParserException,
+ IOException {
+ XmlResourceParser parser = getInstrumentation().getTargetContext().getResources().getXml(
+ resId);
+ int type;
+ while ((type = parser.next()) != XmlPullParser.START_TAG
+ && type != XmlPullParser.END_DOCUMENT) {
+ // Empty loop
+ }
+ return parser;
+ }
+
+ private class MockMipmapDrawable extends MipmapDrawable {
+ private boolean mHasCalledOnBoundsChanged;
+
+ public boolean hasCalledOnBoundsChanged() {
+ return mHasCalledOnBoundsChanged;
+ }
+
+ public void reset() {
+ mHasCalledOnBoundsChanged = false;
+ }
+
+ @Override
+ protected void onBoundsChange(Rect bounds) {
+ super.onBoundsChange(bounds);
+ mHasCalledOnBoundsChanged = true;
+ }
+ }
+
+ private class MockDrawable extends Drawable {
+ int mIntrinsicHeight;
+ int mMinimumHeight;
+
+ public MockDrawable() {
+ this(0);
+ }
+
+ public MockDrawable(int intrinsicHeight) {
+ this(intrinsicHeight, intrinsicHeight);
+ }
+
+ public MockDrawable(int intrinsicHeight, int minimumHeight) {
+ mIntrinsicHeight = intrinsicHeight;
+ mMinimumHeight = minimumHeight;
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ }
+
+ @Override
+ public int getOpacity() {
+ return 0;
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ }
+
+ @Override
+ public int getIntrinsicHeight() {
+ return mIntrinsicHeight;
+ }
+
+ @Override
+ public int getMinimumHeight() {
+ return mMinimumHeight;
+ }
+ }
+}
diff --git a/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/RoundRectShapeTest.java b/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/RoundRectShapeTest.java
index fa164e3..ada9d69 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/RoundRectShapeTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/RoundRectShapeTest.java
@@ -62,11 +62,7 @@
} catch (ArrayIndexOutOfBoundsException e) {
}
- try {
- new RoundRectShape(null, new RectF(), new float[8]);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- }
+ new RoundRectShape(null, new RectF(), new float[8]);
try {
new RoundRectShape(new float[8], new RectF(), new float[7]);
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
index a261914..60b41ac 100644
--- a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
@@ -689,6 +689,45 @@
assertTrue(paramActual.getPreviewFrameRate() > 0);
checkExposureCompensation(parameters);
+ checkPreferredPreviewSizeForVideo(parameters);
+ }
+
+ private void checkPreferredPreviewSizeForVideo(Parameters parameters) {
+ List<Size> videoSizes = parameters.getSupportedVideoSizes();
+ Size preferredPreviewSize = parameters.getPreferredPreviewSizeForVideo();
+
+ // If getSupportedVideoSizes() returns null,
+ // getPreferredPreviewSizeForVideo() will return null;
+ // otherwise, if getSupportedVideoSizes() does not return null,
+ // getPreferredPreviewSizeForVideo() will not return null.
+ if (videoSizes == null) {
+ assertNull(preferredPreviewSize);
+ } else {
+ assertNotNull(preferredPreviewSize);
+ }
+
+ // If getPreferredPreviewSizeForVideo() returns null,
+ // getSupportedVideoSizes() will return null;
+ // otherwise, if getPreferredPreviewSizeForVideo() does not return null,
+ // getSupportedVideoSizes() will not return null.
+ if (preferredPreviewSize == null) {
+ assertNull(videoSizes);
+ } else {
+ assertNotNull(videoSizes);
+ }
+
+ if (videoSizes != null) { // implies: preferredPreviewSize != null
+ // If getSupportedVideoSizes() does not return null,
+ // the returned list will contain at least one size.
+ assertTrue(videoSizes.size() > 0);
+
+ // In addition, getPreferredPreviewSizeForVideo() returns a size
+ // that is among the supported preview sizes.
+ List<Size> previewSizes = parameters.getSupportedPreviewSizes();
+ assertNotNull(previewSizes);
+ assertTrue(previewSizes.size() > 0);
+ assertTrue(previewSizes.contains(preferredPreviewSize));
+ }
}
private void checkExposureCompensation(Parameters parameters) {
diff --git a/tests/tests/media/src/android/media/cts/AudioManagerTest.java b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
index 3558fa3..635c196 100644
--- a/tests/tests/media/src/android/media/cts/AudioManagerTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
@@ -22,6 +22,7 @@
import static android.media.AudioManager.FLAG_ALLOW_RINGER_MODES;
import static android.media.AudioManager.FLAG_SHOW_UI;
import static android.media.AudioManager.MODE_IN_CALL;
+import static android.media.AudioManager.MODE_IN_COMMUNICATION;
import static android.media.AudioManager.MODE_NORMAL;
import static android.media.AudioManager.MODE_RINGTONE;
import static android.media.AudioManager.RINGER_MODE_NORMAL;
@@ -230,6 +231,8 @@
assertEquals(MODE_RINGTONE, mAudioManager.getMode());
mAudioManager.setMode(MODE_IN_CALL);
assertEquals(MODE_IN_CALL, mAudioManager.getMode());
+ mAudioManager.setMode(MODE_IN_COMMUNICATION);
+ assertEquals(MODE_IN_COMMUNICATION, mAudioManager.getMode());
mAudioManager.setMode(MODE_NORMAL);
assertEquals(MODE_NORMAL, mAudioManager.getMode());
}
@@ -291,25 +294,30 @@
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_RINGTONE));
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_NORMAL));
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));
+ assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_COMMUNICATION));
mAudioManager.setBluetoothScoOn(true);
assertTrue(mAudioManager.isBluetoothScoOn());
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_RINGTONE));
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_NORMAL));
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));
+ assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_COMMUNICATION));
mAudioManager.setBluetoothScoOn(false);
assertFalse(mAudioManager.isBluetoothScoOn());
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_RINGTONE));
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_NORMAL));
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));
+ assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_COMMUNICATION));
mAudioManager.setSpeakerphoneOn(true);
assertTrue(mAudioManager.isSpeakerphoneOn());
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));
+ assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_COMMUNICATION));
mAudioManager.setSpeakerphoneOn(false);
assertFalse(mAudioManager.isSpeakerphoneOn());
assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_CALL));
+ assertEquals(AudioManager.MODE_CURRENT, mAudioManager.getRouting(MODE_IN_COMMUNICATION));
}
@TestTargets({
diff --git a/tests/tests/media/src/android/media/cts/CamcorderProfileTest.java b/tests/tests/media/src/android/media/cts/CamcorderProfileTest.java
index b94da11..17e2481 100644
--- a/tests/tests/media/src/android/media/cts/CamcorderProfileTest.java
+++ b/tests/tests/media/src/android/media/cts/CamcorderProfileTest.java
@@ -22,6 +22,8 @@
import dalvik.annotation.TestTargets;
import android.hardware.Camera;
+import android.hardware.Camera.Parameters;
+import android.hardware.Camera.Size;
import android.media.CamcorderProfile;
import android.test.AndroidTestCase;
import android.util.Log;
@@ -33,7 +35,16 @@
private static final String TAG = "CamcorderProfileTest";
- private void checkProfile(CamcorderProfile profile) {
+ // Uses get without id if cameraId == -1 and get with id otherwise.
+ private CamcorderProfile getWithOptionalId(int quality, int cameraId) {
+ if (cameraId == -1) {
+ return CamcorderProfile.get(quality);
+ } else {
+ return CamcorderProfile.get(cameraId, quality);
+ }
+ }
+
+ private void checkProfile(CamcorderProfile profile, List<Size> videoSizes) {
Log.v(TAG, String.format("profile: duration=%d, quality=%d, " +
"fileFormat=%d, videoCodec=%d, videoBitRate=%d, videoFrameRate=%d, " +
"videoFrameWidth=%d, videoFrameHeight=%d, audioCodec=%d, " +
@@ -52,7 +63,19 @@
profile.audioChannels));
assertTrue(profile.duration > 0);
assertTrue(profile.quality == CamcorderProfile.QUALITY_LOW ||
- profile.quality == CamcorderProfile.QUALITY_HIGH);
+ profile.quality == CamcorderProfile.QUALITY_HIGH ||
+ profile.quality == CamcorderProfile.QUALITY_QCIF ||
+ profile.quality == CamcorderProfile.QUALITY_CIF ||
+ profile.quality == CamcorderProfile.QUALITY_480P ||
+ profile.quality == CamcorderProfile.QUALITY_720P ||
+ profile.quality == CamcorderProfile.QUALITY_1080P ||
+ profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_LOW ||
+ profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_HIGH ||
+ profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_QCIF ||
+ profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_CIF ||
+ profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_480P ||
+ profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_720P ||
+ profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_1080P);
assertTrue(profile.videoBitRate > 0);
assertTrue(profile.videoFrameRate > 0);
assertTrue(profile.videoFrameWidth > 0);
@@ -60,6 +83,143 @@
assertTrue(profile.audioBitRate > 0);
assertTrue(profile.audioSampleRate > 0);
assertTrue(profile.audioChannels > 0);
+ assertTrue(isSizeSupported(profile.videoFrameWidth,
+ profile.videoFrameHeight,
+ videoSizes));
+ }
+
+ private void assertProfileEquals(CamcorderProfile expectedProfile,
+ CamcorderProfile actualProfile) {
+ assertEquals(expectedProfile.duration, actualProfile.duration);
+ assertEquals(expectedProfile.fileFormat, actualProfile.fileFormat);
+ assertEquals(expectedProfile.videoCodec, actualProfile.videoCodec);
+ assertEquals(expectedProfile.videoBitRate, actualProfile.videoBitRate);
+ assertEquals(expectedProfile.videoFrameRate, actualProfile.videoFrameRate);
+ assertEquals(expectedProfile.videoFrameWidth, actualProfile.videoFrameWidth);
+ assertEquals(expectedProfile.videoFrameHeight, actualProfile.videoFrameHeight);
+ assertEquals(expectedProfile.audioCodec, actualProfile.audioCodec);
+ assertEquals(expectedProfile.audioBitRate, actualProfile.audioBitRate);
+ assertEquals(expectedProfile.audioSampleRate, actualProfile.audioSampleRate);
+ assertEquals(expectedProfile.audioChannels, actualProfile.audioChannels);
+ }
+
+ private void checkSpecificProfileDimensions(CamcorderProfile profile, int quality) {
+ Log.v(TAG, String.format("specific profile: quality=%d, width = %d, height = %d",
+ profile.quality, profile.videoFrameWidth, profile.videoFrameHeight));
+
+ switch (quality) {
+ case CamcorderProfile.QUALITY_QCIF:
+ case CamcorderProfile.QUALITY_TIME_LAPSE_QCIF:
+ assertEquals(176, profile.videoFrameWidth);
+ assertEquals(144, profile.videoFrameHeight);
+ break;
+
+ case CamcorderProfile.QUALITY_CIF:
+ case CamcorderProfile.QUALITY_TIME_LAPSE_CIF:
+ assertEquals(352, profile.videoFrameWidth);
+ assertEquals(288, profile.videoFrameHeight);
+ break;
+
+ case CamcorderProfile.QUALITY_480P:
+ case CamcorderProfile.QUALITY_TIME_LAPSE_480P:
+ assertEquals(720, profile.videoFrameWidth);
+ assertEquals(480, profile.videoFrameHeight);
+ break;
+
+ case CamcorderProfile.QUALITY_720P:
+ case CamcorderProfile.QUALITY_TIME_LAPSE_720P:
+ assertEquals(1280, profile.videoFrameWidth);
+ assertEquals(720, profile.videoFrameHeight);
+ break;
+
+ case CamcorderProfile.QUALITY_1080P:
+ case CamcorderProfile.QUALITY_TIME_LAPSE_1080P:
+ assertEquals(1920, profile.videoFrameWidth);
+ assertEquals(1088, profile.videoFrameHeight);
+ break;
+ }
+ }
+
+ // Checks if the existing specific profiles have the correct dimensions.
+ // Also checks that the mimimum quality specific profile matches the low profile and
+ // similarly that the maximum quality specific profile matches the high profile.
+ private void checkSpecificProfiles(
+ int cameraId,
+ CamcorderProfile low,
+ CamcorderProfile high,
+ int[] specificQualities,
+ List<Size> videoSizes) {
+
+ CamcorderProfile minProfile = null;
+ CamcorderProfile maxProfile = null;
+
+ for (int i = 0; i < specificQualities.length; i++) {
+ int quality = specificQualities[i];
+ if (CamcorderProfile.hasProfile(quality)) {
+ CamcorderProfile profile = getWithOptionalId(quality, cameraId);
+ checkSpecificProfileDimensions(profile, quality);
+
+ assertTrue(isSizeSupported(profile.videoFrameWidth,
+ profile.videoFrameHeight,
+ videoSizes));
+
+ if (minProfile == null) {
+ minProfile = profile;
+ }
+ maxProfile = profile;
+ }
+ }
+
+ assertNotNull(minProfile);
+ assertNotNull(maxProfile);
+
+ Log.v(TAG, String.format("min profile: quality=%d, width = %d, height = %d",
+ minProfile.quality, minProfile.videoFrameWidth, minProfile.videoFrameHeight));
+ Log.v(TAG, String.format("max profile: quality=%d, width = %d, height = %d",
+ maxProfile.quality, maxProfile.videoFrameWidth, maxProfile.videoFrameHeight));
+
+ assertProfileEquals(low, minProfile);
+ assertProfileEquals(high, maxProfile);
+
+ }
+
+ private void checkGet(int cameraId) {
+ Log.v(TAG, (cameraId == -1)
+ ? "Checking get without id"
+ : "Checking get with id = " + cameraId);
+
+ final List<Size> videoSizes = getSupportedVideoSizes(cameraId);
+
+ CamcorderProfile lowProfile =
+ getWithOptionalId(CamcorderProfile.QUALITY_LOW, cameraId);
+ CamcorderProfile highProfile =
+ getWithOptionalId(CamcorderProfile.QUALITY_HIGH, cameraId);
+ checkProfile(lowProfile, videoSizes);
+ checkProfile(highProfile, videoSizes);
+
+ CamcorderProfile lowTimeLapseProfile =
+ getWithOptionalId(CamcorderProfile.QUALITY_TIME_LAPSE_LOW, cameraId);
+ CamcorderProfile highTimeLapseProfile =
+ getWithOptionalId(CamcorderProfile.QUALITY_TIME_LAPSE_HIGH, cameraId);
+ checkProfile(lowTimeLapseProfile, null);
+ checkProfile(highTimeLapseProfile, null);
+
+ int[] specificProfileQualities = {CamcorderProfile.QUALITY_QCIF,
+ CamcorderProfile.QUALITY_CIF,
+ CamcorderProfile.QUALITY_480P,
+ CamcorderProfile.QUALITY_720P,
+ CamcorderProfile.QUALITY_1080P};
+
+ int[] specificTimeLapseProfileQualities = {CamcorderProfile.QUALITY_TIME_LAPSE_QCIF,
+ CamcorderProfile.QUALITY_TIME_LAPSE_CIF,
+ CamcorderProfile.QUALITY_TIME_LAPSE_480P,
+ CamcorderProfile.QUALITY_TIME_LAPSE_720P,
+ CamcorderProfile.QUALITY_TIME_LAPSE_1080P};
+
+ checkSpecificProfiles(cameraId, lowProfile, highProfile,
+ specificProfileQualities, videoSizes);
+ checkSpecificProfiles(cameraId, lowTimeLapseProfile, highTimeLapseProfile,
+ specificTimeLapseProfileQualities, null);
}
@TestTargets({
@@ -70,10 +230,7 @@
)
})
public void testGet() {
- CamcorderProfile lowProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
- CamcorderProfile highProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
- checkProfile(lowProfile);
- checkProfile(highProfile);
+ checkGet(-1);
}
@TestTargets({
@@ -85,13 +242,31 @@
})
public void testGetWithId() {
int nCamera = Camera.getNumberOfCameras();
- for (int id = 0; id < nCamera; id++) {
- CamcorderProfile lowProfile = CamcorderProfile.get(id,
- CamcorderProfile.QUALITY_LOW);
- CamcorderProfile highProfile = CamcorderProfile.get(id,
- CamcorderProfile.QUALITY_HIGH);
- checkProfile(lowProfile);
- checkProfile(highProfile);
+ for (int cameraId = 0; cameraId < nCamera; cameraId++) {
+ checkGet(cameraId);
}
}
+
+ private List<Size> getSupportedVideoSizes(int cameraId) {
+ Camera camera = (cameraId == -1)? Camera.open(): Camera.open(cameraId);
+ Parameters parameters = camera.getParameters();
+ List<Size> videoSizes = parameters.getSupportedVideoSizes();
+ if (videoSizes == null) {
+ videoSizes = parameters.getSupportedPreviewSizes();
+ assertNotNull(videoSizes);
+ }
+ camera.release();
+ return videoSizes;
+ }
+
+ private boolean isSizeSupported(int width, int height, List<Size> sizes) {
+ if (sizes == null) return true;
+
+ for (Size size: sizes) {
+ if (size.width == width && size.height == height) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/tests/tests/os/src/android/os/cts/ParcelFileDescriptorTest.java b/tests/tests/os/src/android/os/cts/ParcelFileDescriptorTest.java
index ce6658f..3974b6c 100644
--- a/tests/tests/os/src/android/os/cts/ParcelFileDescriptorTest.java
+++ b/tests/tests/os/src/android/os/cts/ParcelFileDescriptorTest.java
@@ -28,9 +28,14 @@
import android.os.Parcelable;
import android.os.ParcelFileDescriptor.AutoCloseInputStream;
import android.test.AndroidTestCase;
+import android.test.MoreAsserts;
import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
@@ -110,6 +115,72 @@
}
@TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ method = "fromData",
+ args = {byte[].class}
+ )
+ public void testFromData() throws IOException {
+ assertNull(ParcelFileDescriptor.fromData(null, null));
+ byte[] data = new byte[] { 0 };
+ assertFileDescriptorContent(data, ParcelFileDescriptor.fromData(data, null));
+ data = new byte[] { 0, 1, 2, 3 };
+ assertFileDescriptorContent(data, ParcelFileDescriptor.fromData(data, null));
+ data = new byte[0];
+ assertFileDescriptorContent(data, ParcelFileDescriptor.fromData(data, null));
+
+ // Check that modifying the data does not modify the data in the FD
+ data = new byte[] { 0, 1, 2, 3 };
+ ParcelFileDescriptor pfd = ParcelFileDescriptor.fromData(data, null);
+ data[1] = 42;
+ assertFileDescriptorContent(new byte[] { 0, 1, 2, 3 }, pfd);
+ }
+
+ private static void assertFileDescriptorContent(byte[] expected, ParcelFileDescriptor fd)
+ throws IOException {
+ assertInputStreamContent(expected, new ParcelFileDescriptor.AutoCloseInputStream(fd));
+ }
+
+ private static void assertInputStreamContent(byte[] expected, InputStream is)
+ throws IOException {
+ try {
+ byte[] observed = new byte[expected.length];
+ int count = is.read(observed);
+ assertEquals(expected.length, count);
+ assertEquals(-1, is.read());
+ MoreAsserts.assertEquals(expected, observed);
+ } finally {
+ is.close();
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Tests that skip() works on FDs returned by fromData()",
+ method = "fromData",
+ args = {byte[].class}
+ )
+ public void testFromDataSkip() throws IOException {
+ byte[] data = new byte[] { 40, 41, 42, 43, 44, 45, 46 };
+ ParcelFileDescriptor pfd = ParcelFileDescriptor.fromData(data, null);
+ assertNotNull(pfd);
+ FileDescriptor fd = pfd.getFileDescriptor();
+ assertNotNull(fd);
+ assertTrue(fd.valid());
+ FileInputStream is = new FileInputStream(fd);
+ try {
+ assertEquals(1, is.skip(1));
+ assertEquals(41, is.read());
+ assertEquals(42, is.read());
+ assertEquals(2, is.skip(2));
+ assertEquals(45, is.read());
+ assertEquals(46, is.read());
+ assertEquals(-1, is.read());
+ } finally {
+ is.close();
+ }
+ }
+
+ @TestTargetNew(
level = TestLevel.COMPLETE,
method = "toString",
args = {}
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_PlaylistsTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_PlaylistsTest.java
index e50abf4..48ae5d7 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_PlaylistsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_PlaylistsTest.java
@@ -30,6 +30,8 @@
import android.provider.MediaStore.Audio.Playlists;
import android.test.InstrumentationTestCase;
+import java.util.regex.Pattern;
+
@TestTargetClass(Playlists.class)
public class MediaStore_Audio_PlaylistsTest extends InstrumentationTestCase {
private ContentResolver mContentResolver;
@@ -74,9 +76,8 @@
ContentValues values = new ContentValues();
values.put(Playlists.NAME, "My favourites");
values.put(Playlists.DATA, externalPlaylistPath);
- long dateAdded = System.currentTimeMillis();
- values.put(Playlists.DATE_ADDED, dateAdded);
- long dateModified = System.currentTimeMillis();
+ long dateAdded = System.currentTimeMillis() / 1000;
+ long dateModified = System.currentTimeMillis() / 1000;
values.put(Playlists.DATE_MODIFIED, dateModified);
// insert
Uri uri = mContentResolver.insert(Playlists.EXTERNAL_CONTENT_URI, values);
@@ -91,7 +92,8 @@
assertEquals(externalPlaylistPath,
c.getString(c.getColumnIndex(Playlists.DATA)));
- assertEquals(dateAdded, c.getLong(c.getColumnIndex(Playlists.DATE_ADDED)));
+ long realDateAdded = c.getLong(c.getColumnIndex(Playlists.DATE_ADDED));
+ assertTrue(realDateAdded >= dateAdded);
assertEquals(dateModified, c.getLong(c.getColumnIndex(Playlists.DATE_MODIFIED)));
assertTrue(c.getLong(c.getColumnIndex(Playlists._ID)) > 0);
c.close();
@@ -108,7 +110,7 @@
assertEquals(externalPlaylistPath,
c.getString(c.getColumnIndex(Playlists.DATA)));
- assertEquals(dateAdded, c.getLong(c.getColumnIndex(Playlists.DATE_ADDED)));
+ assertEquals(realDateAdded, c.getLong(c.getColumnIndex(Playlists.DATE_ADDED)));
assertEquals(dateModified, c.getLong(c.getColumnIndex(Playlists.DATE_MODIFIED)));
c.close();
} finally {
@@ -117,7 +119,6 @@
}
public void testStoreAudioPlaylistsInternal() {
- // the internal database does not have play lists
ContentValues values = new ContentValues();
values.put(Playlists.NAME, "My favourites");
values.put(Playlists.DATA, "/data/data/com.android.cts.stub/files/my_favorites.pl");
@@ -126,6 +127,8 @@
long dateModified = System.currentTimeMillis();
values.put(Playlists.DATE_MODIFIED, dateModified);
Uri uri = mContentResolver.insert(Playlists.INTERNAL_CONTENT_URI, values);
- assertNull(uri);
+ assertNotNull(uri);
+ assertTrue(Pattern.matches("content://media/internal/audio/playlists/\\d+",
+ uri.toString()));
}
}
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
index 6b15bb9..4c29f97 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
@@ -20,7 +20,6 @@
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.ToBeFixed;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -34,6 +33,8 @@
import android.provider.cts.MediaStoreAudioTestHelper.Audio2;
import android.test.InstrumentationTestCase;
+import java.util.regex.Pattern;
+
@TestTargetClass(Members.class)
public class MediaStore_Audio_Playlists_MembersTest extends InstrumentationTestCase {
private String[] mAudioProjection = {
@@ -279,7 +280,6 @@
}
public void testStoreAudioPlaylistsMembersInternal() {
- // the internal database does not have play lists
ContentValues values = new ContentValues();
values.put(Playlists.NAME, "My favourites");
values.put(Playlists.DATA, "/data/data/com.android.cts.stub/files/my_favorites.pl");
@@ -288,6 +288,8 @@
long dateModified = System.currentTimeMillis();
values.put(Playlists.DATE_MODIFIED, dateModified);
Uri uri = mContentResolver.insert(Playlists.INTERNAL_CONTENT_URI, values);
- assertNull(uri);
+ assertNotNull(uri);
+ assertTrue(Pattern.matches("content://media/internal/audio/playlists/\\d+",
+ uri.toString()));
}
}
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 2de72c8..f2410f1 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
@@ -267,9 +267,9 @@
values.put(Media.MIME_TYPE, "image/jpeg");
values.put(Media.SIZE, 86853);
values.put(Media.TITLE, "testimage");
- 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
@@ -298,7 +298,7 @@
assertEquals("testimage", c.getString(c.getColumnIndex(Media.TITLE)));
assertEquals(86853, 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();
@@ -318,7 +318,7 @@
values.put(Media.MIME_TYPE, "image/jpeg");
values.put(Media.SIZE, 86854);
values.put(Media.TITLE, "testimage1");
- dateModified = System.currentTimeMillis();
+ dateModified = System.currentTimeMillis() / 1000;
values.put(Media.DATE_MODIFIED, dateModified);
assertEquals(1, mContentResolver.update(uri, values, null, null));
diff --git a/tests/tests/provider/src/android/provider/cts/SearchRecentSuggestionsTest.java b/tests/tests/provider/src/android/provider/cts/SearchRecentSuggestionsTest.java
new file mode 100644
index 0000000..1395de1
--- /dev/null
+++ b/tests/tests/provider/src/android/provider/cts/SearchRecentSuggestionsTest.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.provider.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.SearchRecentSuggestions;
+import android.test.ProviderTestCase2;
+import android.view.animation.cts.DelayedCheck;
+
+@TestTargetClass(android.provider.SearchRecentSuggestions.class)
+public class SearchRecentSuggestionsTest extends
+ ProviderTestCase2<TestSearchRecentSuggestionsProvider> {
+ private final static String AUTHORITY_HEAD = "content://"
+ + TestSearchRecentSuggestionsProvider.AUTHORITY;
+
+ private Uri mTestUri;
+ private TestSearchRecentSuggestionsProvider mTestSRSProvider;
+ private Context mContext;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mTestUri = Uri.parse(AUTHORITY_HEAD + "/suggestions");
+ mTestSRSProvider = getProvider();
+ mContext = mTestSRSProvider.getContext();
+ }
+
+ public SearchRecentSuggestionsTest() {
+ super(TestSearchRecentSuggestionsProvider.class,
+ TestSearchRecentSuggestionsProvider.AUTHORITY);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "SearchRecentSuggestions",
+ args = {android.content.Context.class, java.lang.String.class, int.class}
+ )
+ public void testConstructor() {
+ new SearchRecentSuggestions(mContext, TestSearchRecentSuggestionsProvider.AUTHORITY,
+ TestSearchRecentSuggestionsProvider.MODE);
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "SearchRecentSuggestions",
+ args = {android.content.Context.class, java.lang.String.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "saveRecentQuery",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "clearHistory",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "truncateHistory",
+ args = {android.content.ContentResolver.class, int.class}
+ )
+ })
+ public void testSearchRecentSuggestions() {
+ MySearchRecentSuggestions srs = new MySearchRecentSuggestions(mContext,
+ TestSearchRecentSuggestionsProvider.AUTHORITY,
+ TestSearchRecentSuggestionsProvider.MODE);
+ Cursor c = mTestSRSProvider.query(mTestUri, null, null, null, null);
+
+ try {
+ assertNotNull(c);
+ assertEquals(0, c.getCount());
+ c.close();
+
+ // insert three rows
+ String query1 = "query1";
+ String line1 = "line1";
+ srs.saveRecentQuery(query1, line1);
+
+ waitForCursorCount(mTestUri, SearchRecentSuggestions.QUERIES_PROJECTION_2LINE, 1);
+
+ c = mTestSRSProvider.query(mTestUri, SearchRecentSuggestions.QUERIES_PROJECTION_2LINE,
+ null, null, null);
+ c.moveToFirst();
+ assertEquals(query1, c
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_QUERY_INDEX));
+ assertEquals(line1, c
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_DISPLAY2_INDEX));
+ c.close();
+
+ String query2 = "query2";
+ String line2 = "line2";
+ srs.saveRecentQuery(query2, line2);
+ waitForCursorCount(mTestUri, null, 2);
+
+ String query3 = "query3";
+ String line3 = "line3";
+ srs.saveRecentQuery(query3, line3);
+ waitForCursorCount(mTestUri, null, 3);
+
+ // truncateHistory will delete the oldest one record
+ ContentResolver cr = mContext.getContentResolver();
+ srs.truncateHistory(cr, 2);
+
+ waitForCursorCount(mTestUri, SearchRecentSuggestions.QUERIES_PROJECTION_2LINE, 2);
+
+ c = mTestSRSProvider.query(mTestUri, SearchRecentSuggestions.QUERIES_PROJECTION_2LINE,
+ null, null, null);
+
+ // and the left two should be: test2 and test3, test1 should be delete
+ c.moveToFirst();
+ assertEquals(query2, c
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_QUERY_INDEX));
+ assertEquals(line2, c
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_DISPLAY2_INDEX));
+ c.moveToNext();
+ assertEquals(query3, c
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_QUERY_INDEX));
+ assertEquals(line3, c
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_DISPLAY2_INDEX));
+ c.close();
+
+ // clear all history
+ srs.clearHistory();
+ waitForCursorCount(mTestUri, null, 0);
+ } finally {
+ c.close();
+ }
+ }
+
+ public void testSuggestionsTable() {
+ String insertDisplay1 = "display1_insert";
+ String insertDisplay2 = "display2_insert";
+ String insertQuery = "query_insert";
+
+ String updateDisplay1 = "display1_update";
+ String updateDisplay2 = "display2_update";
+ String updateQuery = "query_update";
+
+ // Test: insert
+ ContentValues value = new ContentValues();
+ value.put("display1", insertDisplay1);
+ value.put("display2", insertDisplay2);
+ value.put("query", insertQuery);
+ value.put("date", 1);
+
+ mTestSRSProvider.insert(mTestUri, value);
+
+ Cursor cursor = mTestSRSProvider.query(mTestUri,
+ SearchRecentSuggestions.QUERIES_PROJECTION_2LINE,
+ "display1=\"" + insertDisplay1 + "\"", null, null);
+ try {
+ assertNotNull(cursor);
+ assertEquals(1, cursor.getCount());
+ assertTrue(cursor.moveToFirst());
+ assertEquals(insertDisplay2, cursor
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_DISPLAY2_INDEX));
+ assertEquals(insertQuery, cursor
+ .getString(SearchRecentSuggestions.QUERIES_PROJECTION_QUERY_INDEX));
+ assertEquals(1, cursor.getInt(SearchRecentSuggestions.QUERIES_PROJECTION_DATE_INDEX));
+ cursor.close();
+
+ // Test: update
+ /**
+ * SearchRecentSuggestionsProvider.update is not implement, always
+ * throw an UnsupportedOperationException.
+ */
+ value.clear();
+ value.put("display1", updateDisplay1);
+ value.put("display2", updateDisplay2);
+ value.put("query", updateQuery);
+ value.put("date", 2);
+
+ try {
+ mTestSRSProvider.update(mTestUri, value, "display1=\"" + insertDisplay1 + "\"",
+ null);
+ fail("There should be an UnsupportedOperationException thrown out.");
+ } catch (UnsupportedOperationException e) {
+ // expected, test success.
+ }
+
+ // Test: delete
+ mTestSRSProvider.delete(mTestUri, "display1=\"" + insertDisplay1 + "\"", null);
+ cursor = mTestSRSProvider.query(mTestUri,
+ SearchRecentSuggestions.QUERIES_PROJECTION_2LINE, "display1=\""
+ + insertDisplay1 + "\"", null, null);
+ assertNotNull(cursor);
+ assertEquals(0, cursor.getCount());
+ } finally {
+ cursor.close();
+ }
+ }
+
+ private class MySearchRecentSuggestions extends SearchRecentSuggestions {
+ public MySearchRecentSuggestions(Context context, String authority, int mode) {
+ super(context, authority, mode);
+ }
+
+ protected void truncateHistory(ContentResolver cr, int maxEntries) {
+ super.truncateHistory(cr, maxEntries);
+ }
+ }
+
+ private void waitForCursorCount(final Uri uri, final String[] projection,
+ final int expectedCount) {
+ new DelayedCheck() {
+ protected boolean check() {
+ Cursor cursor = null;
+ try {
+ cursor = mTestSRSProvider.query(uri, projection, null, null, null);
+ return cursor != null && cursor.getCount() == expectedCount;
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ }
+ }.run();
+ }
+}
diff --git a/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java b/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
index 26ebfb5..f8b4336 100644
--- a/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
+++ b/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
@@ -16,6 +16,12 @@
package android.text.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
import android.test.AndroidTestCase;
import android.text.InputFilter;
import android.text.SpannableString;
@@ -24,11 +30,6 @@
import android.text.style.StrikethroughSpan;
import android.text.style.TabStopSpan;
import android.text.style.UnderlineSpan;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
/**
* Test {@link SpannableStringBuilder}.
@@ -250,6 +251,28 @@
builder.replace(0, 5, text, 0, text.length());
assertEquals("ahiabc, world", builder.toString());
+ // Replacing by an empty string (identical target indexes)
+ builder = new SpannableStringBuilder("hello, world");
+ builder.replace(4, 6, "", 0, 0);
+ assertEquals("hell world", builder.toString());
+
+ builder = new SpannableStringBuilder("hello, world");
+ builder.replace(4, 6, "any string", 5, 5);
+ assertEquals("hell world", builder.toString());
+
+ // Inserting in place (no deletion)
+ builder = new SpannableStringBuilder("hello, world");
+ builder.replace(3, 3, "any string", 0, 0);
+ assertEquals("hello, world", builder.toString());
+
+ builder = new SpannableStringBuilder("hello, world");
+ builder.replace(7, 7, "nice ", 0, 5);
+ assertEquals("hello, nice world", builder.toString());
+
+ builder = new SpannableStringBuilder("hello, world");
+ builder.replace(0, 0, "say ", 1, 4);
+ assertEquals("ay hello, world", builder.toString());
+
try {
builder.replace(0, 5, text, 10, 3);
fail("should throw IndexOutOfBoundsException here");
diff --git a/tests/tests/view/src/android/view/cts/AccessibilityEventTest.java b/tests/tests/view/src/android/view/cts/AccessibilityEventTest.java
index 731784a..f7c1e7a 100644
--- a/tests/tests/view/src/android/view/cts/AccessibilityEventTest.java
+++ b/tests/tests/view/src/android/view/cts/AccessibilityEventTest.java
@@ -202,8 +202,7 @@
TestCase.assertEquals("fromIndex not properly recycled", 0, event.getFromIndex());
TestCase.assertEquals("itemCount not properly recycled", 0, event.getItemCount());
TestCase.assertNull("packageName not properly recycled", event.getPackageName());
- // This will fail and is fixed in Gingerbread Bug: 2593810
- // TestCase.assertNull("parcelableData not properly recycled", event.getParcelableData());
+ TestCase.assertNull("parcelableData not properly recycled", event.getParcelableData());
TestCase.assertEquals("removedCount not properly recycled", 0, event.getRemovedCount());
TestCase.assertTrue("text not properly recycled", event.getText().isEmpty());
}
diff --git a/tests/tests/view/src/android/view/cts/KeyCharacterMapTest.java b/tests/tests/view/src/android/view/cts/KeyCharacterMapTest.java
index 4ab38df..156dc49 100644
--- a/tests/tests/view/src/android/view/cts/KeyCharacterMapTest.java
+++ b/tests/tests/view/src/android/view/cts/KeyCharacterMapTest.java
@@ -16,17 +16,17 @@
package android.view.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
import android.test.AndroidTestCase;
import android.text.TextUtils;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.KeyCharacterMap.KeyData;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
@TestTargetClass(KeyCharacterMap.class)
public class KeyCharacterMapTest extends AndroidTestCase {
@@ -36,7 +36,7 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
+ mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
}
@TestTargetNew(
@@ -113,6 +113,7 @@
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SHIFT_RIGHT));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TAB));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SPACE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SYM));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_EXPLORER));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ENVELOPE));
@@ -133,11 +134,131 @@
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_HEADSETHOOK));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FOCUS));
assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PLUS));
-
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MENU));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NOTIFICATION));
assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SEARCH));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_STOP));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_NEXT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PREVIOUS));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_REWIND));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MUTE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PAGE_UP));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PAGE_DOWN));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PICTSYMBOLS));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SWITCH_CHARSET));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_A));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_B));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_C));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_X));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_Y));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_Z));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_L1));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_R1));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_L2));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_R2));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_THUMBL));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_THUMBR));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_START));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_SELECT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BUTTON_MODE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ESCAPE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FORWARD_DEL));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CTRL_LEFT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CTRL_RIGHT));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAPS_LOCK));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SCROLL_LOCK));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_META_LEFT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_META_RIGHT));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FUNCTION));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SYSRQ));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BREAK));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MOVE_HOME));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MOVE_END));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_INSERT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_FORWARD));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PLAY));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_PAUSE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_CLOSE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_EJECT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_MEDIA_RECORD));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F1));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F2));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F3));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F4));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F5));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F6));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F7));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F8));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F9));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F10));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F11));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_F12));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUM_LOCK));
+
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_0));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_1));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_2));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_3));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_4));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_5));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_6));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_7));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_8));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_9));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_DIVIDE));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_MULTIPLY));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_SUBTRACT));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_ADD));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_DOT));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_COMMA));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_ENTER));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_EQUALS));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_LEFT_PAREN));
+ assertTrue(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_VOLUME_MUTE));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_INFO));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CHANNEL_UP));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CHANNEL_DOWN));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ZOOM_IN));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_ZOOM_OUT));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_WINDOW));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_GUIDE));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_DVR));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_BOOKMARK));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_CAPTIONS));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_SETTINGS));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV_POWER));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_TV_INPUT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STB_POWER));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_STB_INPUT));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AVR_POWER));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_AVR_INPUT));
+
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_RED));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_GREEN));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_YELLOW));
+ assertFalse(mKeyCharacterMap.isPrintingKey(KeyEvent.KEYCODE_PROG_BLUE));
}
@TestTargetNew(
diff --git a/tests/tests/view/src/android/view/cts/LayoutInflaterTest.java b/tests/tests/view/src/android/view/cts/LayoutInflaterTest.java
index 6f637fc..f5bd8f4 100644
--- a/tests/tests/view/src/android/view/cts/LayoutInflaterTest.java
+++ b/tests/tests/view/src/android/view/cts/LayoutInflaterTest.java
@@ -16,6 +16,14 @@
package android.view.cts;
+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 org.xmlpull.v1.XmlPullParser;
import android.app.cts.MockActivity;
@@ -23,6 +31,7 @@
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.test.AndroidTestCase;
import android.util.AttributeSet;
@@ -35,21 +44,13 @@
import android.view.LayoutInflater.Factory;
import android.view.LayoutInflater.Filter;
import android.widget.LinearLayout;
-import com.android.cts.stub.R;
-
-import com.android.internal.util.XmlUtils;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
@TestTargetClass(LayoutInflater.class)
public class LayoutInflaterTest extends AndroidTestCase {
private LayoutInflater mLayoutInflater;
private Context mContext;
- private Factory mFactory = new Factory() {
+ private final Factory mFactory = new Factory() {
public View onCreateView(String name, Context context,
AttributeSet attrs) {
@@ -57,7 +58,7 @@
}
};
private boolean isOnLoadClass;
- private Filter mFilter = new Filter() {
+ private final Filter mFilter = new Filter() {
@SuppressWarnings("unchecked")
public boolean onLoadClass(Class clazz) {
@@ -172,7 +173,7 @@
}
String nodeName = parser.getName();
if (!"alias".equals(nodeName)) {
- throw new RuntimeException();
+ throw new InflateException();
}
int outerDepth = parser.getDepth();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
@@ -296,8 +297,7 @@
try {
view = mLayoutInflater.inflate(-1, null);
fail("should throw exception");
- } catch (RuntimeException e) {
-
+ } catch (Resources.NotFoundException e) {
}
LinearLayout mLayout;
mLayout = new LinearLayout(mContext);
@@ -335,7 +335,7 @@
try {
view = mLayoutInflater.inflate(-1, null, false);
fail("should throw exception");
- } catch (RuntimeException e) {
+ } catch (Resources.NotFoundException e) {
}
LinearLayout mLayout;
@@ -381,7 +381,7 @@
try {
view = mLayoutInflater.inflate(null, null);
fail("should throw exception");
- } catch (RuntimeException e) {
+ } catch (NullPointerException e) {
}
LinearLayout mLayout;
mLayout = new LinearLayout(mContext);
@@ -395,7 +395,7 @@
try {
view = mLayoutInflater.inflate(parser, mLayout);
fail("should throw exception");
- } catch (RuntimeException e) {
+ } catch (NullPointerException e) {
}
parser = getContext().getResources().getLayout(
R.layout.inflater_layout);
@@ -440,7 +440,7 @@
try {
view = mLayoutInflater.inflate(null, null, false);
fail("should throw exception");
- } catch (RuntimeException e) {
+ } catch (NullPointerException e) {
}
LinearLayout mLayout;
mLayout = new LinearLayout(mContext);
@@ -454,7 +454,7 @@
try {
view = mLayoutInflater.inflate(parser, mLayout, false);
fail("should throw exception");
- } catch (RuntimeException e) {
+ } catch (NullPointerException e) {
}
parser = getContext().getResources().getLayout(
R.layout.inflater_layout);
@@ -475,7 +475,7 @@
try {
view = mLayoutInflater.inflate(parser, mLayout, false);
fail("should throw exception");
- } catch (RuntimeException e) {
+ } catch (InflateException e) {
}
parser = null;
@@ -497,6 +497,7 @@
super(original, newContext);
}
+ @Override
public View onCreateView(String name, AttributeSet attrs)
throws ClassNotFoundException {
return super.onCreateView(name, attrs);
diff --git a/tests/tests/view/src/android/view/cts/MotionEventTest.java b/tests/tests/view/src/android/view/cts/MotionEventTest.java
index e4df594..f8a14e6 100644
--- a/tests/tests/view/src/android/view/cts/MotionEventTest.java
+++ b/tests/tests/view/src/android/view/cts/MotionEventTest.java
@@ -22,12 +22,15 @@
import dalvik.annotation.TestTargets;
import dalvik.annotation.ToBeFixed;
+import android.graphics.Matrix;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.test.AndroidTestCase;
+import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
+import android.view.MotionEvent.PointerCoords;
/**
* Test {@link MotionEvent}.
@@ -497,4 +500,103 @@
mMotionEvent2 = null; // since it was recycled, don't try to recycle again in tear down
}
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "transform",
+ args = {}
+ )
+ public void testTransformShouldThrowWhenMatrixIsNull() {
+ try {
+ mMotionEvent1.transform(null);
+ fail("transform() should throw an exception when matrix is null.");
+ } catch (IllegalArgumentException ex) {
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "transform",
+ args = {}
+ )
+ public void testTransformShouldApplyMatrixToPointsAndPreserveRawPosition() {
+ // Generate some points on a circle.
+ // Each point 'i' is a point on a circle of radius ROTATION centered at (3,2) at an angle
+ // of ARC * i degrees clockwise relative to the Y axis.
+ // The geometrical representation is irrelevant to the test, it's just easy to generate
+ // and check rotation. We set the orientation to the same angle.
+ // Coordinate system: down is increasing Y, right is increasing X.
+ final float PI_180 = (float) (Math.PI / 180);
+ final float RADIUS = 10;
+ final float ARC = 36;
+ final float ROTATION = ARC * 2;
+
+ final int pointerCount = 11;
+ final int[] pointerIds = new int[pointerCount];
+ final PointerCoords[] pointerCoords = new PointerCoords[pointerCount];
+ for (int i = 0; i < pointerCount; i++) {
+ final PointerCoords c = new PointerCoords();
+ final float angle = (float) (i * ARC * PI_180);
+ pointerIds[i] = i;
+ pointerCoords[i] = c;
+ c.x = (float) (Math.sin(angle) * RADIUS + 3);
+ c.y = (float) (- Math.cos(angle) * RADIUS + 2);
+ c.orientation = angle;
+ }
+ final MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
+ pointerCount, pointerIds, pointerCoords, 0, 0, 0, 0, 0, 0, 0);
+ final float originalRawX = 0 + 3;
+ final float originalRawY = - RADIUS + 2;
+ dump("Original points.", event);
+
+ // Check original raw X and Y assumption.
+ assertEquals(originalRawX, event.getRawX(), 0.001);
+ assertEquals(originalRawY, event.getRawY(), 0.001);
+
+ // Now translate the motion event so the circle's origin is at (0,0).
+ event.offsetLocation(-3, -2);
+ dump("Translated points.", event);
+
+ // Offsetting the location should preserve the raw X and Y of the first point.
+ assertEquals(originalRawX, event.getRawX(), 0.001);
+ assertEquals(originalRawY, event.getRawY(), 0.001);
+
+ // Apply a rotation about the origin by ROTATION degrees clockwise.
+ Matrix matrix = new Matrix();
+ matrix.setRotate(ROTATION);
+ event.transform(matrix);
+ dump("Rotated points.", event);
+
+ // Check the points.
+ for (int i = 0; i < pointerCount; i++) {
+ final PointerCoords c = pointerCoords[i];
+ event.getPointerCoords(i, c);
+
+ final float angle = (float) ((i * ARC + ROTATION) * PI_180);
+ assertEquals(Math.sin(angle) * RADIUS, c.x, 0.001);
+ assertEquals(- Math.cos(angle) * RADIUS, c.y, 0.001);
+ assertEquals(Math.tan(angle), Math.tan(c.orientation), 0.1);
+ }
+
+ // Applying the transformation should preserve the raw X and Y of the first point.
+ assertEquals(originalRawX, event.getRawX(), 0.001);
+ assertEquals(originalRawY, event.getRawY(), 0.001);
+ }
+
+ private void dump(String label, MotionEvent ev) {
+ if (false) {
+ StringBuilder msg = new StringBuilder();
+ msg.append(label).append("\n");
+
+ msg.append(" Raw: (").append(ev.getRawX()).append(",").append(ev.getRawY()).append(")\n");
+ int pointerCount = ev.getPointerCount();
+ for (int i = 0; i < pointerCount; i++) {
+ msg.append(" Pointer[").append(i).append("]: (")
+ .append(ev.getX(i)).append(",").append(ev.getY(i)).append("), orientation=")
+ .append(ev.getOrientation(i) * 180 / Math.PI).append(" deg\n");
+ }
+
+ android.util.Log.i("TEST", msg.toString());
+ }
+ }
}
diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java
index e07e105..a8b9b57 100644
--- a/tests/tests/view/src/android/view/cts/ViewTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTest.java
@@ -47,6 +47,8 @@
import android.util.SparseArray;
import android.util.Xml;
import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.view.ActionMode;
import android.view.Display;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
@@ -54,11 +56,6 @@
import android.view.SoundEffectConstants;
import android.view.TouchDelegate;
import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.ViewGroup;
-import android.view.ViewParent;
-import android.view.WindowManagerImpl;
-import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.BaseSavedState;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
@@ -66,6 +63,10 @@
import android.view.View.OnKeyListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
+import android.view.ViewConfiguration;
+import android.view.ViewGroup;
+import android.view.ViewParent;
+import android.view.WindowManagerImpl;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.cts.DelayedCheck;
@@ -4606,6 +4607,11 @@
return false;
}
+ public ActionMode startActionModeForChild(View originalView,
+ ActionMode.Callback callback) {
+ return null;
+ }
+
public boolean hasShowContextMenuForChild() {
return mHasShowContextMenuForChild;
}
diff --git a/tests/tests/view/src/android/view/cts/WindowTest.java b/tests/tests/view/src/android/view/cts/WindowTest.java
index 0e31888..484a61d 100644
--- a/tests/tests/view/src/android/view/cts/WindowTest.java
+++ b/tests/tests/view/src/android/view/cts/WindowTest.java
@@ -37,7 +37,7 @@
import android.os.Bundle;
import android.test.ActivityInstrumentationTestCase2;
import android.util.DisplayMetrics;
-import android.view.accessibility.AccessibilityEvent;
+import android.view.ActionMode;
import android.view.Gravity;
import android.view.InputQueue;
import android.view.KeyEvent;
@@ -50,6 +50,7 @@
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
+import android.view.accessibility.AccessibilityEvent;
import android.widget.TextView;
@TestTargetClass(Window.class)
@@ -1148,6 +1149,9 @@
public void togglePanel(int featureId, KeyEvent event) {
}
+ public void invalidatePanelMenu(int featureId) {
+ }
+
public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
return true;
}
@@ -1326,5 +1330,15 @@
public boolean onSearchRequested() {
return false;
}
+
+ public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) {
+ return null;
+ }
+
+ public void onActionModeStarted(ActionMode mode) {
+ }
+
+ public void onActionModeFinished(ActionMode mode) {
+ }
}
}
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
index ca1b76f..28f8def 100755
--- a/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
@@ -286,4 +286,14 @@
}
}.run();
}
+
+ public void testb3167208() throws Exception {
+ String uri = "http://host.android.com/path/";
+ // note the space after the domain=
+ String problemCookie = "foo=bar; domain= .android.com; path=/";
+ mCookieManager.setCookie(uri, problemCookie);
+ String cookie = mCookieManager.getCookie(uri);
+ assertNotNull(cookie);
+ assertTrue(cookie.contains("foo=bar"));
+ }
}
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
index 2f4c35a..391478a 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
@@ -62,21 +62,30 @@
assertSame(csm1, csm2);
final CookieManager cookieManager = CookieManager.getInstance();
- assertFalse(cookieManager.hasCookies());
+
+ // Remove all cookies from the database.
+ cookieManager.removeAllCookie();
+ new DelayedCheck(30000) {
+ @Override
+ protected boolean check() {
+ return !cookieManager.hasCookies();
+ }
+ }.run();
cookieManager.setAcceptCookie(true);
assertTrue(cookieManager.acceptCookie());
- String cookieValue = "a = b";
- cookieManager.setCookie(TestHtmlConstants.HELLO_WORLD_URL, cookieValue);
- assertEquals(cookieValue, cookieManager.getCookie(TestHtmlConstants.HELLO_WORLD_URL));
+ String url = TestHtmlConstants.getFileUrl(TestHtmlConstants.HELLO_WORLD_URL);
+ String cookieValue = "a=b";
+ cookieManager.setCookie(url, cookieValue);
+ assertEquals(cookieValue, cookieManager.getCookie(url));
// Cookie is stored in RAM but not in the database.
assertFalse(cookieManager.hasCookies());
// Store the cookie to the database.
csm1.sync();
- new DelayedCheck(10000) {
+ new DelayedCheck(30000) {
@Override
protected boolean check() {
return cookieManager.hasCookies();
@@ -85,7 +94,7 @@
// Remove all cookies from the database.
cookieManager.removeAllCookie();
- new DelayedCheck(10000) {
+ new DelayedCheck(30000) {
@Override
protected boolean check() {
return !cookieManager.hasCookies();
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
index a95cd90..14a14d0 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
@@ -211,24 +211,16 @@
public void testEmptyValue() {
String url = "http://www.foobar.com";
- mCookieManager.setCookie(url, "foo;");
- String cookie = mCookieManager.getCookie(url);
- assertTrue(cookie.equals("foo"));
-
- mCookieManager.setCookie(url, "bar");
- cookie = mCookieManager.getCookie(url);
- assertTrue(cookie.equals("bar; foo"));
-
mCookieManager.setCookie(url, "bar=");
- cookie = mCookieManager.getCookie(url);
- assertTrue(cookie.equals("bar=; bar; foo"));
+ String cookie = mCookieManager.getCookie(url);
+ assertTrue(cookie.equals("bar="));
mCookieManager.setCookie(url, "foobar=;");
cookie = mCookieManager.getCookie(url);
- assertTrue(cookie.equals("bar=; foobar=; bar; foo"));
+ assertTrue(cookie.equals("bar=; foobar="));
mCookieManager.setCookie(url, "baz=; path=/wee");
cookie = mCookieManager.getCookie(url + "/wee");
- assertTrue(cookie.equals("baz=; bar=; foobar=; bar; foo"));
+ assertTrue(cookie.equals("baz=; bar=; foobar="));
}
}
diff --git a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
index e51f574..8721326 100644
--- a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
@@ -90,7 +90,7 @@
assertLoadUrlSuccessfully(url);
assertEquals(CtsTestServer.AUTH_REALM, client.realm);
- assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_FORBIDDEN), mWebView.getTitle());
+ assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mWebView.getTitle());
assertTrue(client.useHttpAuthUsernamePassword);
// missing credentials
@@ -148,6 +148,7 @@
private boolean mProceed;
private String mUser;
private String mPassword;
+ private int mAuthCount;
MyWebViewClient(boolean proceed, String user, String password) {
mProceed = proceed;
@@ -157,6 +158,11 @@
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
+ ++mAuthCount;
+ if (mAuthCount > 1) {
+ handler.cancel();
+ return;
+ }
this.realm = realm;
this.useHttpAuthUsernamePassword = handler.useHttpAuthUsernamePassword();
if (mProceed) {
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index b9d054f..84fe827 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -336,56 +336,15 @@
)
})
public void testScrollBarOverlay() throws Throwable {
- DisplayMetrics metrics = mWebView.getContext().getResources().getDisplayMetrics();
- int dimension = 2 * Math.max(metrics.widthPixels, metrics.heightPixels);
-
- String p = "<p style=\"height:" + dimension + "px;" +
- "width:" + dimension + "px;margin:0px auto;\">Test scroll bar overlay.</p>";
- mWebView.loadData("<html><body>" + p + "</body></html>", "text/html", "UTF-8");
- waitForLoadComplete(mWebView, TEST_TIMEOUT);
+ mWebView.setHorizontalScrollbarOverlay(true);
+ mWebView.setVerticalScrollbarOverlay(false);
assertTrue(mWebView.overlayHorizontalScrollbar());
assertFalse(mWebView.overlayVerticalScrollbar());
- int startX = mWebView.getScrollX();
- int startY = mWebView.getScrollY();
-
- final int bigVelocity = 10000;
- // fling to the max and wait for ending scroll
- runTestOnUiThread(new Runnable() {
- public void run() {
- mWebView.flingScroll(bigVelocity, bigVelocity);
- }
- });
- getInstrumentation().waitForIdleSync();
-
- int overlayOffsetX = mWebView.getScrollX() - startX;
- int insetOffsetY = mWebView.getScrollY() - startY;
-
- // scroll back
- runTestOnUiThread(new Runnable() {
- public void run() {
- mWebView.flingScroll(-bigVelocity, -bigVelocity);
- }
- });
- getInstrumentation().waitForIdleSync();
mWebView.setHorizontalScrollbarOverlay(false);
mWebView.setVerticalScrollbarOverlay(true);
assertFalse(mWebView.overlayHorizontalScrollbar());
assertTrue(mWebView.overlayVerticalScrollbar());
-
- // fling to the max and wait for ending scroll
- runTestOnUiThread(new Runnable() {
- public void run() {
- mWebView.flingScroll(bigVelocity, bigVelocity);
- }
- });
- getInstrumentation().waitForIdleSync();
-
- int insetOffsetX = mWebView.getScrollX() - startX;
- int overlayOffsetY = mWebView.getScrollY() - startY;
-
- assertTrue(overlayOffsetY > insetOffsetY);
- assertTrue(overlayOffsetX > insetOffsetX);
}
@TestTargets({
@@ -577,6 +536,67 @@
}.run();
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "addJavascriptInterface",
+ args = {Object.class, String.class}
+ )
+ public void testAddJavascriptInterfaceNull() throws Exception {
+ WebSettings settings = mWebView.getSettings();
+ settings.setJavaScriptEnabled(true);
+ String setTitleToPropertyTypeHtml = "<html><head></head>" +
+ "<body onload=\"document.title = typeof window.injectedObject;\"></body></html>";
+
+ // Test that the property is initially undefined.
+ mWebView.loadData(setTitleToPropertyTypeHtml, "text/html", "UTF-8");
+ waitForLoadComplete(mWebView, TEST_TIMEOUT);
+ assertEquals("undefined", mWebView.getTitle());
+
+ // Test that adding a null object has no effect.
+ mWebView.addJavascriptInterface(null, "injectedObject");
+ mWebView.loadData(setTitleToPropertyTypeHtml, "text/html", "UTF-8");
+ waitForLoadComplete(mWebView, TEST_TIMEOUT);
+ assertEquals("undefined", mWebView.getTitle());
+
+ // Test that adding an object gives an object type.
+ final DummyJavaScriptInterface obj = new DummyJavaScriptInterface();
+ mWebView.addJavascriptInterface(obj, "injectedObject");
+ mWebView.loadData(setTitleToPropertyTypeHtml, "text/html", "UTF-8");
+ waitForLoadComplete(mWebView, TEST_TIMEOUT);
+ assertEquals("object", mWebView.getTitle());
+
+ // Test that trying to replace with a null object has no effect.
+ mWebView.addJavascriptInterface(null, "injectedObject");
+ mWebView.loadData(setTitleToPropertyTypeHtml, "text/html", "UTF-8");
+ waitForLoadComplete(mWebView, TEST_TIMEOUT);
+ assertEquals("object", mWebView.getTitle());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "removeJavascriptInterface",
+ args = {String.class}
+ )
+ public void testRemoveJavascriptInterface() throws Exception {
+ WebSettings settings = mWebView.getSettings();
+ settings.setJavaScriptEnabled(true);
+ String setTitleToPropertyTypeHtml = "<html><head></head>" +
+ "<body onload=\"document.title = typeof window.injectedObject;\"></body></html>";
+
+ // Test that adding an object gives an object type.
+ final DummyJavaScriptInterface obj = new DummyJavaScriptInterface();
+ mWebView.addJavascriptInterface(obj, "injectedObject");
+ mWebView.loadData(setTitleToPropertyTypeHtml, "text/html", "UTF-8");
+ waitForLoadComplete(mWebView, TEST_TIMEOUT);
+ assertEquals("object", mWebView.getTitle());
+
+ // Test that removing the object leaves the property undefined.
+ mWebView.removeJavascriptInterface("injectedObject");
+ mWebView.loadData(setTitleToPropertyTypeHtml, "text/html", "UTF-8");
+ waitForLoadComplete(mWebView, TEST_TIMEOUT);
+ assertEquals("undefined", mWebView.getTitle());
+ }
+
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
diff --git a/tests/tests/widget/src/android/widget/cts/ExpandableListTester.java b/tests/tests/widget/src/android/widget/cts/ExpandableListTester.java
new file mode 100644
index 0000000..8175807
--- /dev/null
+++ b/tests/tests/widget/src/android/widget/cts/ExpandableListTester.java
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.widget.cts;
+
+import android.app.Instrumentation;
+import android.test.ActivityInstrumentationTestCase2;
+import android.view.KeyEvent;
+import android.view.View;
+import android.widget.ExpandableListAdapter;
+import android.widget.ExpandableListView;
+import android.widget.cts.util.ExpandableListScenario;
+import android.widget.cts.util.ListUtil;
+
+import junit.framework.Assert;
+
+public class ExpandableListTester {
+ private final ExpandableListView mExpandableListView;
+ private final ExpandableListAdapter mAdapter;
+ private final ListUtil mListUtil;
+
+ private final ActivityInstrumentationTestCase2<? extends ExpandableListScenario>
+ mActivityInstrumentation;
+
+ Instrumentation mInstrumentation;
+
+ public ExpandableListTester(
+ ExpandableListView expandableListView,
+ ActivityInstrumentationTestCase2<? extends ExpandableListScenario>
+ activityInstrumentation) {
+ mExpandableListView = expandableListView;
+ Instrumentation instrumentation = activityInstrumentation.getInstrumentation();
+ mListUtil = new ListUtil(mExpandableListView, instrumentation);
+ mAdapter = mExpandableListView.getExpandableListAdapter();
+ mActivityInstrumentation = activityInstrumentation;
+ mInstrumentation = mActivityInstrumentation.getInstrumentation();
+ }
+
+ private void expandGroup(final int groupIndex, int flatPosition) {
+ Assert.assertFalse("Group is already expanded", mExpandableListView
+ .isGroupExpanded(groupIndex));
+ mListUtil.arrowScrollToSelectedPosition(flatPosition);
+ mInstrumentation.waitForIdleSync();
+ mActivityInstrumentation.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+ mActivityInstrumentation.getInstrumentation().waitForIdleSync();
+ Assert.assertTrue("Group did not expand " + groupIndex,
+ mExpandableListView.isGroupExpanded(groupIndex));
+ }
+
+ void testContextMenus() {
+ // Add a position tester ContextMenu listener to the ExpandableListView
+ PositionTesterContextMenuListener menuListener = new PositionTesterContextMenuListener();
+ mExpandableListView.setOnCreateContextMenuListener(menuListener);
+
+ int index = 0;
+
+ // Scrolling on header elements should trigger an AdapterContextMenu
+ for (int i=0; i<mExpandableListView.getHeaderViewsCount(); i++) {
+ // Check group index in context menu
+ menuListener.expectAdapterContextMenu(i);
+ // Make sure the group is visible so that getChild finds it
+ mListUtil.arrowScrollToSelectedPosition(index);
+ View headerChild = mExpandableListView.getChildAt(index
+ - mExpandableListView.getFirstVisiblePosition());
+ mExpandableListView.showContextMenuForChild(headerChild);
+ mInstrumentation.waitForIdleSync();
+ Assert.assertNull(menuListener.getErrorMessage(), menuListener.getErrorMessage());
+ index++;
+ }
+
+ int groupCount = mAdapter.getGroupCount();
+ for (int groupIndex = 0; groupIndex < groupCount; groupIndex++) {
+
+ // Expand group
+ expandGroup(groupIndex, index);
+
+ // Check group index in context menu
+ menuListener.expectGroupContextMenu(groupIndex);
+ // Make sure the group is visible so that getChild finds it
+ mListUtil.arrowScrollToSelectedPosition(index);
+ View groupChild = mExpandableListView.getChildAt(index
+ - mExpandableListView.getFirstVisiblePosition());
+ mExpandableListView.showContextMenuForChild(groupChild);
+ mInstrumentation.waitForIdleSync();
+ Assert.assertNull(menuListener.getErrorMessage(), menuListener.getErrorMessage());
+ index++;
+
+ final int childrenCount = mAdapter.getChildrenCount(groupIndex);
+ for (int childIndex = 0; childIndex < childrenCount; childIndex++) {
+ // Check child index in context menu
+ mListUtil.arrowScrollToSelectedPosition(index);
+ menuListener.expectChildContextMenu(groupIndex, childIndex);
+ View child = mExpandableListView.getChildAt(index
+ - mExpandableListView.getFirstVisiblePosition());
+ mExpandableListView.showContextMenuForChild(child);
+ mInstrumentation.waitForIdleSync();
+ Assert.assertNull(menuListener.getErrorMessage(), menuListener.getErrorMessage());
+ index++;
+ }
+ }
+
+ // Scrolling on footer elements should trigger an AdapterContextMenu
+ for (int i=0; i<mExpandableListView.getFooterViewsCount(); i++) {
+ // Check group index in context menu
+ menuListener.expectAdapterContextMenu(index);
+ // Make sure the group is visible so that getChild finds it
+ mListUtil.arrowScrollToSelectedPosition(index);
+ View footerChild = mExpandableListView.getChildAt(index
+ - mExpandableListView.getFirstVisiblePosition());
+ mExpandableListView.showContextMenuForChild(footerChild);
+ mInstrumentation.waitForIdleSync();
+ Assert.assertNull(menuListener.getErrorMessage(), menuListener.getErrorMessage());
+ index++;
+ }
+
+ // Cleanup: remove the listener we added.
+ mExpandableListView.setOnCreateContextMenuListener(null);
+ }
+
+ private int expandAGroup() {
+ final int groupIndex = 2;
+ final int headerCount = mExpandableListView.getHeaderViewsCount();
+ Assert.assertTrue("Not enough groups", groupIndex < mAdapter.getGroupCount());
+ expandGroup(groupIndex, groupIndex + headerCount);
+ return groupIndex;
+ }
+
+ // This method assumes that NO group is expanded when called
+ void testConvertionBetweenFlatAndPackedOnGroups() {
+ final int headerCount = mExpandableListView.getHeaderViewsCount();
+
+ for (int i=0; i<headerCount; i++) {
+ Assert.assertEquals("Non NULL position for header item",
+ ExpandableListView.PACKED_POSITION_VALUE_NULL,
+ mExpandableListView.getExpandableListPosition(i));
+ }
+
+ // Test all (non expanded) groups
+ final int groupCount = mAdapter.getGroupCount();
+ for (int groupIndex = 0; groupIndex < groupCount; groupIndex++) {
+ int expectedFlatPosition = headerCount + groupIndex;
+ long packedPositionForGroup = ExpandableListView.getPackedPositionForGroup(groupIndex);
+ Assert.assertEquals("Group not found at flat position " + expectedFlatPosition,
+ packedPositionForGroup,
+ mExpandableListView.getExpandableListPosition(expectedFlatPosition));
+
+ Assert.assertEquals("Wrong flat position for group " + groupIndex,
+ expectedFlatPosition,
+ mExpandableListView.getFlatListPosition(packedPositionForGroup));
+ }
+
+ for (int i=0; i<mExpandableListView.getFooterViewsCount(); i++) {
+ Assert.assertEquals("Non NULL position for header item",
+ ExpandableListView.PACKED_POSITION_VALUE_NULL,
+ mExpandableListView.getExpandableListPosition(headerCount + groupCount + i));
+ }
+ }
+
+ // This method assumes that NO group is expanded when called
+ void testConvertionBetweenFlatAndPackedOnChildren() {
+ // Test with an expanded group
+ final int headerCount = mExpandableListView.getHeaderViewsCount();
+ final int groupIndex = expandAGroup();
+
+ final int childrenCount = mAdapter.getChildrenCount(groupIndex);
+ for (int childIndex = 0; childIndex < childrenCount; childIndex++) {
+ int expectedFlatPosition = headerCount + groupIndex + 1 + childIndex;
+ long childPos = ExpandableListView.getPackedPositionForChild(groupIndex, childIndex);
+
+ Assert.assertEquals("Wrong flat position for child ",
+ childPos,
+ mExpandableListView.getExpandableListPosition(expectedFlatPosition));
+
+ Assert.assertEquals("Wrong flat position for child ",
+ expectedFlatPosition,
+ mExpandableListView.getFlatListPosition(childPos));
+ }
+ }
+
+ // This method assumes that NO group is expanded when called
+ void testSelectedPositionOnGroups() {
+ int index = 0;
+
+ // Scrolling on header elements should not give a valid selected position.
+ for (int i=0; i<mExpandableListView.getHeaderViewsCount(); i++) {
+ mListUtil.arrowScrollToSelectedPosition(index);
+ Assert.assertEquals("Header item is selected",
+ ExpandableListView.PACKED_POSITION_VALUE_NULL,
+ mExpandableListView.getSelectedPosition());
+ index++;
+ }
+
+ // Check selection on group items
+ final int groupCount = mAdapter.getGroupCount();
+ for (int groupIndex = 0; groupIndex < groupCount; groupIndex++) {
+ mListUtil.arrowScrollToSelectedPosition(index);
+ Assert.assertEquals("Group item is not selected",
+ ExpandableListView.getPackedPositionForGroup(groupIndex),
+ mExpandableListView.getSelectedPosition());
+ index++;
+ }
+
+ // Scrolling on footer elements should not give a valid selected position.
+ for (int i=0; i<mExpandableListView.getFooterViewsCount(); i++) {
+ mListUtil.arrowScrollToSelectedPosition(index);
+ Assert.assertEquals("Footer item is selected",
+ ExpandableListView.PACKED_POSITION_VALUE_NULL,
+ mExpandableListView.getSelectedPosition());
+ index++;
+ }
+ }
+
+ // This method assumes that NO group is expanded when called
+ void testSelectedPositionOnChildren() {
+ // Test with an expanded group
+ final int headerCount = mExpandableListView.getHeaderViewsCount();
+ final int groupIndex = expandAGroup();
+
+ final int childrenCount = mAdapter.getChildrenCount(groupIndex);
+ for (int childIndex = 0; childIndex < childrenCount; childIndex++) {
+ int childFlatPosition = headerCount + groupIndex + 1 + childIndex;
+ mListUtil.arrowScrollToSelectedPosition(childFlatPosition);
+ Assert.assertEquals("Group item is not selected",
+ ExpandableListView.getPackedPositionForChild(groupIndex, childIndex),
+ mExpandableListView.getSelectedPosition());
+ }
+ }
+}
diff --git a/tests/tests/widget/src/android/widget/cts/ExpandableListViewBasicTest.java b/tests/tests/widget/src/android/widget/cts/ExpandableListViewBasicTest.java
index c6c0b35..fc39364 100644
--- a/tests/tests/widget/src/android/widget/cts/ExpandableListViewBasicTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ExpandableListViewBasicTest.java
@@ -16,7 +16,10 @@
package android.widget.cts;
-import java.util.List;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
@@ -27,21 +30,19 @@
import android.widget.cts.util.ExpandableListScenario;
import android.widget.cts.util.ListUtil;
import android.widget.cts.util.ExpandableListScenario.MyGroup;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
+
+import java.util.List;
@TestTargetClass(ExpandableListView.class)
public class ExpandableListViewBasicTest extends
ActivityInstrumentationTestCase2<ExpandableListSimple> {
private ExpandableListScenario mActivity;
- private ExpandableListView mListView;
+ private ExpandableListView mExpandableListView;
private ExpandableListAdapter mAdapter;
private ListUtil mListUtil;
public ExpandableListViewBasicTest() {
- super("com.android.cts.stub", ExpandableListSimple.class);
+ super(ExpandableListSimple.class);
}
@Override
@@ -49,27 +50,27 @@
super.setUp();
mActivity = getActivity();
- mListView = mActivity.getExpandableListView();
- mAdapter = mListView.getExpandableListAdapter();
- mListUtil = new ListUtil(mListView, getInstrumentation());
+ mExpandableListView = mActivity.getExpandableListView();
+ mAdapter = mExpandableListView.getExpandableListAdapter();
+ mListUtil = new ListUtil(mExpandableListView, getInstrumentation());
}
@MediumTest
public void testPreconditions() {
assertNotNull(mActivity);
- assertNotNull(mListView);
+ assertNotNull(mExpandableListView);
}
private int expandGroup(int numChildren, boolean atLeastOneChild) {
final int groupPos = mActivity.findGroupWithNumChildren(numChildren, atLeastOneChild);
assertTrue("Could not find group to expand", groupPos >= 0);
- assertFalse("Group is already expanded", mListView.isGroupExpanded(groupPos));
+ assertFalse("Group is already expanded", mExpandableListView.isGroupExpanded(groupPos));
mListUtil.arrowScrollToSelectedPosition(groupPos);
getInstrumentation().waitForIdleSync();
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
getInstrumentation().waitForIdleSync();
- assertTrue("Group did not expand", mListView.isGroupExpanded(groupPos));
+ assertTrue("Group did not expand", mExpandableListView.isGroupExpanded(groupPos));
return groupPos;
}
@@ -97,7 +98,7 @@
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
getInstrumentation().waitForIdleSync();
- assertFalse("Group did not collapse", mListView.isGroupExpanded(groupPos));
+ assertFalse("Group did not collapse", mExpandableListView.isGroupExpanded(groupPos));
}
@TestTargets({
@@ -122,13 +123,13 @@
getInstrumentation().waitForIdleSync();
// Ensure it expanded
- assertTrue("Group did not expand", mListView.isGroupExpanded(0));
+ assertTrue("Group did not expand", mExpandableListView.isGroupExpanded(0));
// Wait until that's all good
getInstrumentation().waitForIdleSync();
// Make sure it expanded
- assertTrue("Group did not expand", mListView.isGroupExpanded(0));
+ assertTrue("Group did not expand", mExpandableListView.isGroupExpanded(0));
// Insert a collapsed group in front of the one just expanded
List<MyGroup> groups = mActivity.getGroups();
@@ -149,8 +150,28 @@
// Make sure the right group is expanded
assertTrue("The expanded state didn't stay with the proper group",
- mListView.isGroupExpanded(1));
+ mExpandableListView.isGroupExpanded(1));
assertFalse("The expanded state was given to the inserted group",
- mListView.isGroupExpanded(0));
+ mExpandableListView.isGroupExpanded(0));
+ }
+
+ @MediumTest
+ public void testContextMenus() {
+ ExpandableListTester tester = new ExpandableListTester(mExpandableListView, this);
+ tester.testContextMenus();
+ }
+
+ @MediumTest
+ public void testConvertionBetweenFlatAndPacked() {
+ ExpandableListTester tester = new ExpandableListTester(mExpandableListView, this);
+ tester.testConvertionBetweenFlatAndPackedOnGroups();
+ tester.testConvertionBetweenFlatAndPackedOnChildren();
+ }
+
+ @MediumTest
+ public void testSelectedPosition() {
+ ExpandableListTester tester = new ExpandableListTester(mExpandableListView, this);
+ tester.testSelectedPositionOnGroups();
+ tester.testSelectedPositionOnChildren();
}
}
diff --git a/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java b/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java
index af420b4..5ab7f4d 100644
--- a/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ExpandableListViewTest.java
@@ -519,10 +519,10 @@
args = {int.class, int.class}
)
public void testGetPackedPositionForChild() {
- assertEquals((long) 0x8000000000000000L,
+ assertEquals(0x8000000000000000L,
ExpandableListView.getPackedPositionForChild(0, 0));
- assertEquals((long) 0xffffffffffffffffL,
+ assertEquals(0xffffffffffffffffL,
ExpandableListView.getPackedPositionForChild(Integer.MAX_VALUE, 0xffffffff));
}
diff --git a/tests/tests/widget/src/android/widget/cts/ExpandableListViewWithHeadersTest.java b/tests/tests/widget/src/android/widget/cts/ExpandableListViewWithHeadersTest.java
index 57776a0..fe65f98 100644
--- a/tests/tests/widget/src/android/widget/cts/ExpandableListViewWithHeadersTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ExpandableListViewWithHeadersTest.java
@@ -16,16 +16,16 @@
package android.widget.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.KeyEvent;
import android.widget.ExpandableListView;
import android.widget.cts.util.ListUtil;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
@TestTargetClass(ExpandableListView.class)
public class ExpandableListViewWithHeadersTest extends
@@ -34,7 +34,7 @@
private ListUtil mListUtil;
public ExpandableListViewWithHeadersTest() {
- super("com.android.cts.stub", ExpandableListWithHeaders.class);
+ super(ExpandableListWithHeaders.class);
}
@Override
@@ -78,4 +78,24 @@
getInstrumentation().waitForIdleSync();
assertTrue(mExpandableListView.isGroupExpanded(0));
}
+
+ @MediumTest
+ public void testContextMenus() {
+ ExpandableListTester tester = new ExpandableListTester(mExpandableListView, this);
+ tester.testContextMenus();
+ }
+
+ @MediumTest
+ public void testConvertionBetweenFlatAndPacked() {
+ ExpandableListTester tester = new ExpandableListTester(mExpandableListView, this);
+ tester.testConvertionBetweenFlatAndPackedOnGroups();
+ tester.testConvertionBetweenFlatAndPackedOnChildren();
+ }
+
+ @MediumTest
+ public void testSelectedPosition() {
+ ExpandableListTester tester = new ExpandableListTester(mExpandableListView, this);
+ tester.testSelectedPositionOnGroups();
+ tester.testSelectedPositionOnChildren();
+ }
}
diff --git a/tests/tests/widget/src/android/widget/cts/GridViewTest.java b/tests/tests/widget/src/android/widget/cts/GridViewTest.java
index 40684c9..ee9c7e2 100644
--- a/tests/tests/widget/src/android/widget/cts/GridViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/GridViewTest.java
@@ -531,6 +531,48 @@
assertEquals(0, child.getLeft() - mGridView.getListPaddingLeft());
}
}
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test {@link GridView#getNumColumns()}",
+ method = "getNumColumns"
+ )
+ public void testGetNumColumns() {
+ mGridView = new GridView(mActivity);
+
+ assertEquals(mGridView.getNumColumns(), GridView.AUTO_FIT);
+
+ mGridView = findGridViewById(R.id.gridview);
+
+ mActivity.runOnUiThread(new Runnable() {
+ public void run() {
+ mGridView.setAdapter(new MockGridViewAdapter(10));
+ mGridView.setNumColumns(10);
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
+ assertEquals(mGridView.getNumColumns(), 10);
+
+ mActivity.runOnUiThread(new Runnable() {
+ public void run() {
+ mGridView.setNumColumns(1);
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
+ assertEquals(mGridView.getNumColumns(), 1);
+
+ mActivity.runOnUiThread(new Runnable() {
+ public void run() {
+ mGridView.setNumColumns(0);
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
+ //although setNumColumns(0) was called, the number of columns should be 1
+ assertEquals(mGridView.getNumColumns(), 1);
+ }
@TestTargetNew(
level = TestLevel.COMPLETE,
diff --git a/tests/tests/widget/src/android/widget/cts/PositionTesterContextMenuListener.java b/tests/tests/widget/src/android/widget/cts/PositionTesterContextMenuListener.java
new file mode 100644
index 0000000..a1c9bc4
--- /dev/null
+++ b/tests/tests/widget/src/android/widget/cts/PositionTesterContextMenuListener.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.widget.cts;
+
+import android.view.ContextMenu;
+import android.view.View;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.view.View.OnCreateContextMenuListener;
+import android.widget.ExpandableListView;
+import android.widget.AdapterView.AdapterContextMenuInfo;
+
+public class PositionTesterContextMenuListener implements OnCreateContextMenuListener {
+
+ private int groupPosition, childPosition;
+
+ // Fake constant to store in testType a test type specific to headers and footers
+ private static final int ADAPTER_TYPE = -1;
+ private int testType; // as returned by getPackedPositionType
+
+ // Will be set to null by each call to onCreateContextMenu, unless an error occurred.
+ private String errorMessage;
+
+ public void expectGroupContextMenu(int groupPosition) {
+ this.groupPosition = groupPosition;
+ testType = ExpandableListView.PACKED_POSITION_TYPE_GROUP;
+ }
+
+ public void expectChildContextMenu(int groupPosition, int childPosition) {
+ this.groupPosition = groupPosition;
+ this.childPosition = childPosition;
+ testType = ExpandableListView.PACKED_POSITION_TYPE_CHILD;
+ }
+
+ public void expectAdapterContextMenu(int flatPosition) {
+ this.groupPosition = flatPosition;
+ testType = ADAPTER_TYPE;
+ }
+
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
+ errorMessage = null;
+ if (testType == ADAPTER_TYPE) {
+ if (!isTrue("MenuInfo is not an AdapterContextMenuInfo",
+ menuInfo instanceof AdapterContextMenuInfo)) {
+ return;
+ }
+ AdapterContextMenuInfo adapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo;
+ if (!areEqual("Wrong flat position", groupPosition, adapterContextMenuInfo.position)) {
+ return;
+ }
+ } else {
+ if (!isTrue("MenuInfo is not an ExpandableListContextMenuInfo",
+ menuInfo instanceof ExpandableListView.ExpandableListContextMenuInfo)) {
+ return;
+ }
+ ExpandableListView.ExpandableListContextMenuInfo elvMenuInfo =
+ (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
+ long packedPosition = elvMenuInfo.packedPosition;
+
+ int packedPositionType = ExpandableListView.getPackedPositionType(packedPosition);
+ if (!areEqual("Wrong packed position type", testType, packedPositionType)) {
+ return;
+ }
+
+ int packedPositionGroup = ExpandableListView.getPackedPositionGroup(packedPosition);
+ if (!areEqual("Wrong group position", groupPosition, packedPositionGroup)) {
+ return;
+ }
+
+ if (testType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
+ int packedPositionChild = ExpandableListView.getPackedPositionChild(packedPosition);
+ if (!areEqual("Wrong child position", childPosition, packedPositionChild)) {
+ return;
+ }
+ }
+ }
+ }
+
+ private boolean areEqual(String message, int expected, int actual) {
+ if (expected != actual) {
+ errorMessage = String.format(message + " (%d vs %d", expected, actual);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isTrue(String message, boolean value) {
+ if (!value) {
+ errorMessage = message;
+ return false;
+ }
+ return true;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+}