Merge "Fix for ContactsTest#testGroupMembershipTable" into honeycomb
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 9e3f0a5..60e6858 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -44,6 +44,7 @@
CtsJniTestCases \
CtsLocationTestCases \
CtsMediaTestCases \
+ CtsNdefTestCases \
CtsOsTestCases \
CtsPermissionTestCases \
CtsPermission2TestCases \
diff --git a/apps/CtsVerifier/res/layout/main.xml b/apps/CtsVerifier/res/layout/main.xml
index 479cc1b..35f6f23 100644
--- a/apps/CtsVerifier/res/layout/main.xml
+++ b/apps/CtsVerifier/res/layout/main.xml
@@ -29,7 +29,6 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
- android:onClick="continueButtonClickHandler"
android:text="@string/continue_button_text"
/>
</RelativeLayout>
diff --git a/apps/CtsVerifier/res/layout/pass_fail_buttons.xml b/apps/CtsVerifier/res/layout/pass_fail_buttons.xml
index 5c64e31..d70e839 100644
--- a/apps/CtsVerifier/res/layout/pass_fail_buttons.xml
+++ b/apps/CtsVerifier/res/layout/pass_fail_buttons.xml
@@ -23,7 +23,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="@drawable/fs_good"
- android:onClick="passFailButtonsClickHandler"
android:text="@string/pass_button_text"/>
<Button android:id="@+id/info_button"
@@ -39,7 +38,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="@drawable/fs_error"
- android:onClick="passFailButtonsClickHandler"
android:text="@string/fail_button_text"/>
</LinearLayout>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/CtsVerifierActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/CtsVerifierActivity.java
index 9c0566e..5fd140f 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/CtsVerifierActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/CtsVerifierActivity.java
@@ -20,6 +20,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
+import android.view.View.OnClickListener;
/** {@link Activity} that displays an introduction to the verifier. */
public class CtsVerifierActivity extends Activity {
@@ -29,9 +30,11 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- }
-
- public void continueButtonClickHandler(View target) {
- startActivity(new Intent(this, TestListActivity.class));
+ findViewById(R.id.continue_button).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startActivity(new Intent(CtsVerifierActivity.this, TestListActivity.class));
+ }
+ });
}
}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
index 1c407b8..c070ec8 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
@@ -34,7 +34,8 @@
* <li>Include the pass fail buttons layout in your layout:
* <pre><include layout="@layout/pass_fail_buttons" /></pre>
* </li>
- * <li>Extend one of the activities to get the click handler for the buttons.</li>
+ * <li>Extend one of the activities and call setPassFailButtonClickListeners after
+ * setting your content view.</li>
* <li>Make sure to call setResult(RESULT_CANCEL) in your Activity initially.</li>
* <li>Optionally call setInfoTextResources to add an info button that will show a
* dialog with instructional text.</li>
@@ -46,6 +47,13 @@
private interface PassFailActivity {
/**
+ * Hooks up the pass and fail buttons to click listeners that will record the test results.
+ * <p>
+ * Call from {@link Activity#onCreate} after {@link Activity #setContentView(int)}.
+ */
+ void setPassFailButtonClickListeners();
+
+ /**
* Adds an initial informational dialog that appears when entering the test activity for
* the first time. Also enables the visibility of an "Info" button between the "Pass" and
* "Fail" buttons that can be clicked to show the information dialog again.
@@ -56,34 +64,40 @@
* @param messageId for the text shown in the dialog's body area
*/
void setInfoResources(int titleId, int messageId, int viewId);
-
- /**
- * Click handler for the pass and fail buttons. No need to call this ever as the XML
- * view layout will bind to this automatically.
- */
- void passFailButtonsClickHandler(View target);
}
public static class Activity extends android.app.Activity implements PassFailActivity {
- public void setInfoResources(int titleId, int messageId, int viewId) {
- setInfo(this, titleId, messageId, viewId);
+ public void setPassFailButtonClickListeners() {
+ setPassFailClickListeners(this);
}
- public void passFailButtonsClickHandler(View target) {
- setTestResultAndFinish(this, target);
+ public void setInfoResources(int titleId, int messageId, int viewId) {
+ setInfo(this, titleId, messageId, viewId);
}
}
public static class ListActivity extends android.app.ListActivity implements PassFailActivity {
+ public void setPassFailButtonClickListeners() {
+ setPassFailClickListeners(this);
+ }
+
public void setInfoResources(int titleId, int messageId, int viewId) {
setInfo(this, titleId, messageId, viewId);
}
+ }
- public void passFailButtonsClickHandler(View target) {
- setTestResultAndFinish(this, target);
- }
+ private static void setPassFailClickListeners(final android.app.Activity activity) {
+ View.OnClickListener clickListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View target) {
+ setTestResultAndFinish(activity, target);
+ }
+ };
+
+ activity.findViewById(R.id.pass_button).setOnClickListener(clickListener);
+ activity.findViewById(R.id.fail_button).setOnClickListener(clickListener);
}
private static void setInfo(final android.app.Activity activity, final int titleId,
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioQualityVerifierActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioQualityVerifierActivity.java
index ce9c165..fd84cd3 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioQualityVerifierActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioQualityVerifierActivity.java
@@ -94,8 +94,8 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aq_verifier_activity);
+ setPassFailButtonClickListeners();
setInfoResources(R.string.aq_verifier, R.string.aq_verifier_info, -1);
- setResult(RESULT_CANCELED);
mCalibrateButton = (Button) findViewById(R.id.calibrateButton);
mRunAllButton = (Button) findViewById(R.id.runAllButton);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java
index a007574..8543890 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java
@@ -65,7 +65,7 @@
/**
* Constructor does not include 'present' because that's a detected
* value, and not set during creation.
- *
+ *
* @param name value for this.name
* @param required value for this.required
*/
@@ -92,8 +92,8 @@
};
/**
- * A list of all features added in FroYo (API=8) and Gingerbread (API=9).
- * Because we want to run on Eclair devices,
+ * A list of all features added in FroYo (API=8) and Gingerbread (API=9).
+ * Because we want to run on Eclair devices,
* we can't use static references to constants added later
* than Eclair. We could use Reflection, but we'd still need a list of
* string literals (for constant names) anyway, and there's little point in
@@ -133,8 +133,8 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fs_main);
+ setPassFailButtonClickListeners();
setInfoResources(R.string.feature_summary, R.string.feature_summary_info, R.layout.fs_info);
- setResult(RESULT_CANCELED);
// some values used to detect warn-able conditions involving multiple
// features
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerTestActivity.java
index 2100c0f..193f37e 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerTestActivity.java
@@ -41,7 +41,6 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setResult(RESULT_CANCELED);
mSensorManager = (SensorManager) getApplicationContext().getSystemService(
Context.SENSOR_SERVICE);
@@ -49,6 +48,7 @@
mListener = renderer;
setContentView(R.layout.pass_fail_gl);
+ setPassFailButtonClickListeners();
setInfoResources(R.string.snsr_accel_test, R.string.snsr_accel_test_info, -1);
mGLSurfaceView = (GLSurfaceView) findViewById(R.id.gl_surface_view);
mGLSurfaceView.setRenderer(renderer);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagnetometerTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagnetometerTestActivity.java
index 479a2fb..f3ba411 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagnetometerTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/MagnetometerTestActivity.java
@@ -40,7 +40,6 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setResult(RESULT_CANCELED);
mSensorManager = (SensorManager) getApplicationContext().getSystemService(
Context.SENSOR_SERVICE);
@@ -48,6 +47,7 @@
mListener = renderer;
setContentView(R.layout.pass_fail_gl);
+ setPassFailButtonClickListeners();
setInfoResources(R.string.snsr_mag_test, R.string.snsr_mag_test_info, -1);
mGLSurfaceView = (GLSurfaceView) findViewById(R.id.gl_surface_view);
mGLSurfaceView.setRenderer(renderer);
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 43eb5fc..8cf1de2 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -65,6 +65,7 @@
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.DUMP" />
+ <uses-permission android:name="android.permission.NFC" />
<!-- Used for PackageManager test, don't delete this INTERNET permission -->
<uses-permission android:name="android.permission.INTERNET" />
@@ -867,8 +868,6 @@
</intent-filter>
</service>
- <activity android:name="android.app.cts.ListActivityTestHelper"
- android:label="ListActivityTestHelper" />
<activity android:name="android.app.ActivityGroup"
android:label="ActivityGroup" />
diff --git a/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java b/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
index aa6b4d0..106f1af 100644
--- a/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
+++ b/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
@@ -25,6 +25,7 @@
import com.android.ddmlib.AdbCommandRejectedException;
import com.android.ddmlib.InstallException;
import com.android.ddmlib.Log;
+import com.android.ddmlib.Log.LogLevel;
import com.android.ddmlib.ShellCommandUnresponsiveException;
import com.android.ddmlib.TimeoutException;
import com.android.ddmlib.testrunner.ITestRunListener;
@@ -53,6 +54,12 @@
// testAppFailAccessPrivateData constants
private static final String APP_WITH_DATA_APK = "CtsAppWithData.apk";
private static final String APP_WITH_DATA_PKG = "com.android.cts.appwithdata";
+ private static final String APP_WITH_DATA_CLASS =
+ "com.android.cts.appwithdata.CreatePrivateDataTest";
+ private static final String APP_WITH_DATA_CREATE_METHOD =
+ "testCreatePrivateData";
+ private static final String APP_WITH_DATA_CHECK_NOEXIST_METHOD =
+ "testEnsurePrivateDataNotExist";
private static final String APP_ACCESS_DATA_APK = "CtsAppAccessData.apk";
private static final String APP_ACCESS_DATA_PKG = "com.android.cts.appaccessdata";
@@ -144,7 +151,8 @@
false);
assertNull("failed to install app with data", installResult);
// run appwithdata's tests to create private data
- assertTrue("failed to create app's private data", runDeviceTests(APP_WITH_DATA_PKG));
+ assertTrue("failed to create app's private data", runDeviceTests(APP_WITH_DATA_PKG,
+ APP_WITH_DATA_CLASS, APP_WITH_DATA_CREATE_METHOD));
installResult = getDevice().installPackage(getTestAppFilePath(APP_ACCESS_DATA_APK),
false);
@@ -159,6 +167,37 @@
}
/**
+ * Test that uninstall of an app removes its private data.
+ */
+ public void testUninstallRemovesData() throws Exception {
+ Log.i(LOG_TAG, "Uninstalling app, verifying data is removed.");
+ try {
+ // cleanup test app that might be installed from previous partial test run
+ getDevice().uninstallPackage(APP_WITH_DATA_PKG);
+
+ String installResult = getDevice().installPackage(getTestAppFilePath(APP_WITH_DATA_APK),
+ false);
+ assertNull("failed to install app with data", installResult);
+ // run appwithdata's tests to create private data
+ assertTrue("failed to create app's private data", runDeviceTests(APP_WITH_DATA_PKG,
+ APP_WITH_DATA_CLASS, APP_WITH_DATA_CREATE_METHOD));
+
+ getDevice().uninstallPackage(APP_WITH_DATA_PKG);
+
+ installResult = getDevice().installPackage(getTestAppFilePath(APP_WITH_DATA_APK),
+ false);
+ assertNull("failed to install app with data second time", installResult);
+ // run appwithdata's 'check if file exists' test
+ assertTrue("app's private data still exists after install", runDeviceTests(
+ APP_WITH_DATA_PKG, APP_WITH_DATA_CLASS, APP_WITH_DATA_CHECK_NOEXIST_METHOD));
+
+ }
+ finally {
+ getDevice().uninstallPackage(APP_WITH_DATA_PKG);
+ }
+ }
+
+ /**
* Test that an app cannot instrument another app that is signed with different certificate.
*/
public void testInstrumentationDiffCert() throws InstallException, TimeoutException,
@@ -239,10 +278,21 @@
* a period longer than the max time to output.
* @throws IOException if connection to device was lost.
*/
- private boolean runDeviceTests(String pkgName)
- throws TimeoutException, AdbCommandRejectedException,
- ShellCommandUnresponsiveException, IOException {
- CollectingTestRunListener listener = doRunTests(pkgName);
+ private boolean runDeviceTests(String pkgName) throws AdbCommandRejectedException,
+ ShellCommandUnresponsiveException, IOException, TimeoutException {
+ return runDeviceTests(pkgName, null, null);
+ }
+
+ /**
+ * Helper method that will the specified packages tests on device.
+ *
+ * @param pkgName Android application package for tests
+ * @return <code>true</code> if all tests passed.
+ */
+ private boolean runDeviceTests(String pkgName, String testClassName, String testMethodName)
+ throws AdbCommandRejectedException, IOException, ShellCommandUnresponsiveException,
+ TimeoutException {
+ CollectingTestRunListener listener = doRunTests(pkgName, testClassName, testMethodName);
return listener.didAllTestsPass();
}
@@ -256,28 +306,18 @@
* a period longer than the max time to output.
* @throws IOException if connection to device was lost.
*/
- private CollectingTestRunListener doRunTests(String pkgName)
- throws TimeoutException, AdbCommandRejectedException,
- ShellCommandUnresponsiveException, IOException {
+ private CollectingTestRunListener doRunTests(String pkgName, String testClassName,
+ String testMethodName) throws AdbCommandRejectedException, IOException,
+ ShellCommandUnresponsiveException, TimeoutException {
RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner(pkgName, getDevice());
+ if (testClassName != null && testMethodName != null) {
+ testRunner.setMethodName(testClassName, testMethodName);
+ }
CollectingTestRunListener listener = new CollectingTestRunListener();
testRunner.run(listener);
return listener;
}
- /**
- * Helper method to run the specified packages tests, and return the test run error message.
- *
- * @param pkgName Android application package for tests
- * @return the test run error message or <code>null</code> if test run completed.
- * @throws IOException if connection to device was lost
- */
- private String runDeviceTestsWithRunResult(String pkgName) throws TimeoutException,
- AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
- CollectingTestRunListener listener = doRunTests(pkgName);
- return listener.getTestRunErrorMessage();
- }
-
private static class CollectingTestRunListener implements ITestRunListener {
private boolean mAllTestsPassed = true;
@@ -289,7 +329,8 @@
public void testFailed(TestFailure status, TestIdentifier test,
String trace) {
- Log.w(LOG_TAG, String.format("%s#%s failed: %s", test.getClassName(),
+ Log.logAndDisplay(LogLevel.WARN, LOG_TAG, String.format("%s#%s failed: %s",
+ test.getClassName(),
test.getTestName(), trace));
mAllTestsPassed = false;
}
@@ -299,7 +340,8 @@
}
public void testRunFailed(String errorMessage) {
- Log.w(LOG_TAG, String.format("test run failed: %s", errorMessage));
+ Log.logAndDisplay(LogLevel.WARN, LOG_TAG, String.format("test run failed: %s",
+ errorMessage));
mAllTestsPassed = false;
mTestRunErrorMessage = errorMessage;
}
diff --git a/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java b/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java
index de8cb78..d77a872 100644
--- a/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java
+++ b/tests/appsecurity-tests/test-apps/AppWithData/src/com/android/cts/appwithdata/CreatePrivateDataTest.java
@@ -44,5 +44,14 @@
Context.MODE_PRIVATE);
outputStream.write("file contents".getBytes());
outputStream.close();
+ assertTrue(getContext().getFileStreamPath(PRIVATE_FILE_NAME).exists());
+ }
+
+ /**
+ * Check to ensure the private file created in testCreatePrivateData does not exist.
+ * Used to check that uninstall of an app deletes the app's data.
+ */
+ public void testEnsurePrivateDataNotExist() throws IOException {
+ assertFalse(getContext().getFileStreamPath(PRIVATE_FILE_NAME).exists());
}
}
diff --git a/tests/res/drawable/typeface_test.png b/tests/res/drawable/typeface_test.png
deleted file mode 100644
index c337f5f..0000000
--- a/tests/res/drawable/typeface_test.png
+++ /dev/null
Binary files differ
diff --git a/tests/src/android/app/cts/ListActivityTestHelper.java b/tests/src/android/app/cts/ListActivityTestHelper.java
deleted file mode 100644
index 4e35bd8..0000000
--- a/tests/src/android/app/cts/ListActivityTestHelper.java
+++ /dev/null
@@ -1,84 +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.app.cts;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-
-import com.android.cts.stub.R;
-
-public class ListActivityTestHelper extends ListActivity {
- public ListView listView;
- public View view;
- public int itemPosition;
- public long itemId;
- public boolean isOnContentChangedCalled = false;
- public static boolean isOnRestoreInstanceStateCalled = false;
- public boolean isSubActivityFinished = false;
-
- private static final int WAIT_BEFORE_FINISH = 1;
-
- @Override
- public void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- listView = l;
- view = v;
- itemPosition = position;
- itemId = id;
- }
-
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setListAdapter(new ArrayAdapter<String>(this,
- R.layout.list_activity_layout, STRING_ITEMS));
- Intent intent = new Intent(TestedScreen.WAIT_BEFORE_FINISH);
- intent.setClass(this, LocalScreen.class);
- startActivityForResult(intent, WAIT_BEFORE_FINISH);
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch (requestCode) {
- case WAIT_BEFORE_FINISH:
- isSubActivityFinished = true;
- break;
- default:
- break;
- }
- }
-
- public static final String[] STRING_ITEMS = {
- "Item 0", "Item 1", "Item 2", "Item 3", "Item 4", "Item 5"
- };
-
- @Override
- public void onContentChanged() {
- isOnContentChangedCalled = true;
- super.onContentChanged();
- }
-
- @Override
- protected void onRestoreInstanceState(Bundle state) {
- isOnRestoreInstanceStateCalled = true;
- super.onRestoreInstanceState(state);
- }
-
-}
diff --git a/tests/src/android/view/cts/WindowStubActivity.java b/tests/src/android/view/cts/WindowStubActivity.java
old mode 100644
new mode 100755
index 24a971f..502c947
--- a/tests/src/android/view/cts/WindowStubActivity.java
+++ b/tests/src/android/view/cts/WindowStubActivity.java
@@ -39,8 +39,8 @@
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Quit").setAlphabeticShortcut('q');
- menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Action").setAlphabeticShortcut('a');
+ menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Quit").setShortcut('1', 'q');
+ menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Action").setShortcut('2', 'a');
mIsOnCreateOptionsMenuCalled = true;
return super.onCreateOptionsMenu(menu);
}
diff --git a/tests/tests/app/src/android/app/cts/DialogTest.java b/tests/tests/app/src/android/app/cts/DialogTest.java
index 8cba3b5..0afb051 100644
--- a/tests/tests/app/src/android/app/cts/DialogTest.java
+++ b/tests/tests/app/src/android/app/cts/DialogTest.java
@@ -42,6 +42,7 @@
import android.os.Message;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
+import android.view.animation.cts.DelayedCheck;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -60,6 +61,7 @@
private static final float MOTION_X = -20.0f;
private static final float MOTION_Y = -20.0f;
private static final String STUB_ACTIVITY_PACKAGE = "com.android.cts.stub";
+ private static final long TEST_TIMEOUT = 1000L;
/**
* please refer to Dialog
@@ -681,7 +683,12 @@
});
mInstrumentation.waitForIdleSync();
- assertTrue(d.isOnWindowFocusChangedCalled);
+ // Wait until TestDialog#OnWindowFocusChanged() is called
+ new DelayedCheck(TEST_TIMEOUT) {
+ protected boolean check() {
+ return d.isOnWindowFocusChangedCalled;
+ }
+ }.run();
}
@TestTargets({
diff --git a/tests/tests/app/src/android/app/cts/LauncherActivityTest.java b/tests/tests/app/src/android/app/cts/LauncherActivityTest.java
index b8129e6..4e5e7d4 100644
--- a/tests/tests/app/src/android/app/cts/LauncherActivityTest.java
+++ b/tests/tests/app/src/android/app/cts/LauncherActivityTest.java
@@ -16,7 +16,6 @@
package android.app.cts;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
@@ -84,7 +83,6 @@
args = {int.class}
)
})
- @BrokenTest("flaky test, assertTrue(mActivity.isOnListItemClick) intermittently fails")
public void testLaunchActivity() {
// Constructor of LaunchActivity can't be invoked directly.
new LauncherActivityStub();
@@ -109,6 +107,9 @@
// There should be an activity(but with uncertain content) in position 0.
assertNotNull(mActivity.intentForPosition(0));
// Test onListItemClick
+ sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
+ sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
+ sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
assertTrue(mActivity.isOnListItemClick);
}
diff --git a/tests/tests/app/src/android/app/cts/ListActivityTest.java b/tests/tests/app/src/android/app/cts/ListActivityTest.java
deleted file mode 100644
index d3a43f9..0000000
--- a/tests/tests/app/src/android/app/cts/ListActivityTest.java
+++ /dev/null
@@ -1,171 +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.app.cts;
-
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import android.app.ListActivity;
-import android.test.ActivityInstrumentationTestCase2;
-import android.view.KeyEvent;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-
-@TestTargetClass(ListActivity.class)
-public class ListActivityTest extends ActivityInstrumentationTestCase2<ListActivityTestHelper> {
- private ListActivityTestHelper mStubListActivity;
-
- public ListActivityTest() {
- super("com.android.cts.stub", ListActivityTestHelper.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mStubListActivity = getActivity();
- assertNotNull(mStubListActivity);
- }
-
- protected void waitForAction() throws InterruptedException {
- final long TIMEOUT_MSEC = 20000;
- final int TIME_SLICE_MSEC = 100;
- final long endTime = System.currentTimeMillis() + TIMEOUT_MSEC;
- while (!mStubListActivity.isSubActivityFinished && System.currentTimeMillis() < endTime) {
- Thread.sleep(TIME_SLICE_MSEC);
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onListItemClick",
- args = {ListView.class, View.class, int.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getListView",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getSelectedItemId",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getSelectedItemPosition",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setListAdapter",
- args = {android.widget.ListAdapter.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setSelection",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getListAdapter",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onContentChanged",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onRestoreInstanceState",
- args = {android.os.Bundle.class}
- )
- })
- @BrokenTest(value="flaky test. bug 2334738")
- public void testListActivity() throws Throwable {
- waitForAction();
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
- getInstrumentation().waitForIdleSync();
- // view should get created on list item click
- assertNotNull(mStubListActivity.view);
- String s = (String) ((TextView) mStubListActivity.view).getText();
- int pos = mStubListActivity.itemPosition;
- long id = mStubListActivity.itemId;
- assertEquals(0, id);
- assertEquals(0, pos);
- assertEquals(ListActivityTestHelper.STRING_ITEMS[pos], s);
- assertEquals(ListActivityTestHelper.STRING_ITEMS.length,
- mStubListActivity.listView.getCount());
- assertEquals(id, mStubListActivity.getSelectedItemId());
- assertEquals(pos, mStubListActivity.getSelectedItemPosition());
-
- sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
- s = (String) ((TextView) mStubListActivity.view).getText();
- pos = mStubListActivity.itemPosition;
- id = mStubListActivity.itemId;
- assertEquals(1, id);
- assertEquals(1, pos);
- assertEquals(ListActivityTestHelper.STRING_ITEMS[pos], s);
- assertEquals(ListActivityTestHelper.STRING_ITEMS.length,
- mStubListActivity.listView.getCount());
- assertEquals(id, mStubListActivity.getSelectedItemId());
- assertEquals(pos, mStubListActivity.getSelectedItemPosition());
-
- final int selectPos = 2;
- assertTrue(mStubListActivity.isOnContentChangedCalled);
- runTestOnUiThread(new Runnable() {
- public void run() {
- mStubListActivity.setSelection(selectPos);
- }
- });
- sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
- s = (String) ((TextView) mStubListActivity.view).getText();
- pos = mStubListActivity.itemPosition;
- id = mStubListActivity.itemId;
- assertEquals(ListActivityTestHelper.STRING_ITEMS[selectPos], s);
- assertEquals(ListActivityTestHelper.STRING_ITEMS.length,
- mStubListActivity.listView.getCount());
- assertEquals(selectPos, id);
- assertEquals(selectPos, pos);
- assertEquals(selectPos, mStubListActivity.getSelectedItemId());
- assertEquals(selectPos, mStubListActivity.getSelectedItemPosition());
-
- final ArrayAdapter<String> arrayAdapter = (ArrayAdapter<String>)
- mStubListActivity.getListAdapter();
- assertNotNull(arrayAdapter);
- final String[] str = ListActivityTestHelper.STRING_ITEMS;
- final int len = str.length;
- assertEquals(len, arrayAdapter.getCount());
- for (int i = 0; i < len; i++) {
- assertEquals(str[i], arrayAdapter.getItem(i));
- }
-
- assertNotNull(mStubListActivity.getListView());
- assertEquals(arrayAdapter, mStubListActivity.getListView().getAdapter());
- assertTrue(mStubListActivity.isOnContentChangedCalled);
- assertFalse(ListActivityTestHelper.isOnRestoreInstanceStateCalled);
- OrientationTestUtils.toggleOrientationSync(mStubListActivity, getInstrumentation());
- assertTrue(ListActivityTestHelper.isOnRestoreInstanceStateCalled);
- }
-}
diff --git a/tests/tests/content/src/android/content/cts/ContextTest.java b/tests/tests/content/src/android/content/cts/ContextTest.java
index b662162..9661a1d 100644
--- a/tests/tests/content/src/android/content/cts/ContextTest.java
+++ b/tests/tests/content/src/android/content/cts/ContextTest.java
@@ -31,6 +31,7 @@
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.content.res.Resources.NotFoundException;
+import android.content.res.Resources.Theme;
import android.test.AndroidTestCase;
import android.util.AttributeSet;
import android.util.Xml;
@@ -45,6 +46,7 @@
protected void setUp() throws Exception {
super.setUp();
mContext = getContext();
+ mContext.setTheme(R.style.Test_Theme);
}
@TestTargets({
@@ -109,6 +111,46 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "getTheme",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setTheme",
+ args = {int.class}
+ )
+ })
+ public void testAccessTheme() {
+ mContext.setTheme(R.style.Test_Theme);
+ final Theme testTheme = mContext.getTheme();
+ assertNotNull(testTheme);
+
+ int[] attrs = {
+ android.R.attr.windowNoTitle,
+ android.R.attr.panelColorForeground,
+ android.R.attr.panelColorBackground
+ };
+ TypedArray attrArray = null;
+ try {
+ attrArray = testTheme.obtainStyledAttributes(attrs);
+ assertTrue(attrArray.getBoolean(0, false));
+ assertEquals(0xff000000, attrArray.getColor(1, 0));
+ assertEquals(0xffffffff, attrArray.getColor(2, 0));
+ } finally {
+ if (attrArray != null) {
+ attrArray.recycle();
+ attrArray = null;
+ }
+ }
+
+ // setTheme only works for the first time
+ mContext.setTheme(android.R.style.Theme_Black);
+ assertSame(testTheme, mContext.getTheme());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
notes = "",
method = "obtainStyledAttributes",
args = {int[].class}
@@ -135,7 +177,7 @@
public void testObtainStyledAttributes() {
// Test obtainStyledAttributes(int[])
TypedArray testTypedArray = mContext
- .obtainStyledAttributes(com.android.internal.R.styleable.View);
+ .obtainStyledAttributes(android.R.styleable.View);
assertNotNull(testTypedArray);
assertTrue(testTypedArray.length() > 2);
assertTrue(testTypedArray.length() > 0);
@@ -143,7 +185,7 @@
// Test obtainStyledAttributes(int, int[])
testTypedArray = mContext.obtainStyledAttributes(android.R.style.TextAppearance_Small,
- com.android.internal.R.styleable.TextAppearance);
+ android.R.styleable.TextAppearance);
assertNotNull(testTypedArray);
assertTrue(testTypedArray.length() > 2);
testTypedArray.recycle();
diff --git a/tests/tests/content/src/android/content/cts/ContextWrapperTest.java b/tests/tests/content/src/android/content/cts/ContextWrapperTest.java
index 65bdc47..6ad14e0 100644
--- a/tests/tests/content/src/android/content/cts/ContextWrapperTest.java
+++ b/tests/tests/content/src/android/content/cts/ContextWrapperTest.java
@@ -35,8 +35,6 @@
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import android.content.res.TypedArray;
-import android.content.res.Resources.Theme;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
@@ -237,46 +235,6 @@
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "getTheme",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setTheme",
- args = {int.class}
- )
- })
- public void testAccessTheme() {
- mContextWrapper.setTheme(R.style.Test_Theme);
- final Theme testTheme = mContextWrapper.getTheme();
- assertNotNull(testTheme);
-
- int[] attrs = {
- android.R.attr.windowNoTitle,
- android.R.attr.panelColorForeground,
- android.R.attr.panelColorBackground
- };
- TypedArray attrArray = null;
- try {
- attrArray = testTheme.obtainStyledAttributes(attrs);
- assertTrue(attrArray.getBoolean(0, false));
- assertEquals(0xff000000, attrArray.getColor(1, 0));
- assertEquals(0xffffffff, attrArray.getColor(2, 0));
- } finally {
- if (attrArray != null) {
- attrArray.recycle();
- attrArray = null;
- }
- }
-
- // setTheme only works for the first time
- mContextWrapper.setTheme(android.R.style.Theme_Black);
- assertSame(testTheme, mContextWrapper.getTheme());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "registerReceiver",
args = {BroadcastReceiver.class, IntentFilter.class}
),
diff --git a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
index cb420a6..624f35a 100644
--- a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
@@ -43,9 +43,11 @@
double density = 160.0d * metrics.density;
assertTrue("Screen density must be at least 100 dpi: " + density, density >= 100.0d);
- double aspectRatio = (double) Math.max(metrics.widthPixels, metrics.heightPixels)
- / (double) Math.min(metrics.widthPixels, metrics.heightPixels);
- assertTrue("Aspect ratio must be between 1.333 (4:3) and 1.779 (16:9): " + aspectRatio,
- aspectRatio >= 1.333d && aspectRatio <= 1.779d);
+ int max = Math.max(metrics.widthPixels, metrics.heightPixels);
+ int min = Math.min(metrics.widthPixels, metrics.heightPixels);
+ boolean format16x9 = Math.floor(max * 9.0d / 16.0d) <= min;
+ boolean format4x3 = Math.ceil(max * 3.0d / 4.0d) >= min;
+ assertTrue("Aspect ratio must be between 4:3 and 16:9. It was " + max + ":" + min,
+ format4x3 && format16x9);
}
}
diff --git a/tests/tests/graphics/src/android/graphics/cts/PaintFlagsDrawFilterTest.java b/tests/tests/graphics/src/android/graphics/cts/PaintFlagsDrawFilterTest.java
old mode 100644
new mode 100755
index bf39818..b394d28
--- a/tests/tests/graphics/src/android/graphics/cts/PaintFlagsDrawFilterTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/PaintFlagsDrawFilterTest.java
@@ -112,7 +112,7 @@
// underline is at least one pixel high
assertTrue(rect.top <= rect.bottom);
// underline is roughly the same length at the text (5% tolerance)
- assertEquals(mTextWidth, rect.right - rect.left, mTextWidth * 0.05);
+ assertEquals(mTextWidth, rect.right - rect.left, mTextWidth * 0.053);
// underline is under the text or at least at the bottom of it
assertTrue(rect.top >= TEXT_Y);
}
diff --git a/tests/tests/graphics/src/android/graphics/cts/PaintTest.java b/tests/tests/graphics/src/android/graphics/cts/PaintTest.java
index 42e557c..20701cb 100644
--- a/tests/tests/graphics/src/android/graphics/cts/PaintTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/PaintTest.java
@@ -16,13 +16,17 @@
package android.graphics.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
import android.graphics.ColorFilter;
import android.graphics.MaskFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.Rasterizer;
-import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.graphics.Xfermode;
@@ -31,14 +35,7 @@
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.test.AndroidTestCase;
-import android.text.SpannableString;
-import android.text.SpannableStringBuilder;
import android.text.SpannedString;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
@TestTargetClass(Paint.class)
public class PaintTest extends AndroidTestCase {
@@ -69,225 +66,85 @@
new Paint(p);
}
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "breakText",
- args = {char[].class, int.class, int.class, float.class, float[].class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testBreakText1() {
+ public void testBreakText() {
+ String text = "HIJKLMN";
+ char[] textChars = text.toCharArray();
+ SpannedString textSpan = new SpannedString(text);
+
Paint p = new Paint();
+ float[] widths = new float[text.length()];
+ assertEquals(text.length(), p.getTextWidths(text, widths));
- char[] chars = {'H', 'I', 'J', 'K', 'L', 'M', 'N'};
- float[] width = {8.0f, 4.0f, 3.0f, 7.0f, 6.0f, 10.0f, 9.0f};
- float[] f = new float[1];
-
- for (int i = 0; i < chars.length; i++) {
- assertEquals(1, p.breakText(chars, i, 1, 20.0f, f));
- assertEquals(width[i], f[0]);
+ float totalWidth = 0.0f;
+ for (int i = 0; i < text.length(); i++) {
+ totalWidth += widths[i];
}
- // start from 'H'
- int indexH = 0;
- assertEquals(4, p.breakText(chars, indexH, 4, 30.0f, f));
- assertEquals(22.0f, f[0]);
- assertEquals(3, p.breakText(chars, indexH, 3, 30.0f, f));
- assertEquals(15.0f, f[0]);
- assertEquals(2, p.breakText(chars, indexH, 2, 30.0f, f));
- assertEquals(12.0f, f[0]);
- assertEquals(1, p.breakText(chars, indexH, 1, 30.0f, f));
- assertEquals(8.0f, f[0]);
- assertEquals(0, p.breakText(chars, indexH, 0, 30.0f, f));
- assertEquals(0.0f, f[0]);
-
- assertEquals(1, p.breakText(chars, indexH + 2, 1, 30.0f, f));
- assertEquals(3.0f, f[0]);
- assertEquals(1, p.breakText(chars, indexH + 2, -1, 30.0f, f));
- assertEquals(3.0f, f[0]);
-
- assertEquals(1, p.breakText(chars, indexH, -1, 30.0f, f));
- assertEquals(8.0f, f[0]);
- assertEquals(2, p.breakText(chars, indexH, -2, 30.0f, f));
- assertEquals(12.0f, f[0]);
- assertEquals(3, p.breakText(chars, indexH, -3, 30.0f, f));
- assertEquals(15.0f, f[0]);
- assertEquals(4, p.breakText(chars, indexH, -4, 30.0f, f));
- assertEquals(22.0f, f[0]);
-
- assertEquals(7, p.breakText(chars, indexH, 7, 50.0f, f));
- assertEquals(47.0f, f[0]);
- assertEquals(6, p.breakText(chars, indexH, 7, 40.0f, f));
- assertEquals(38.0f, f[0]);
-
- assertEquals(7, p.breakText(chars, indexH, -7, 50.0f, null));
- assertEquals(7, p.breakText(chars, indexH, 7, 50.0f, null));
-
- try {
- p.breakText(chars, 0, 8, 60.0f, null);
- fail("Should throw an ArrayIndexOutOfboundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
- try {
- p.breakText(chars, -1, 7, 50.0f, null);
- fail("Should throw an ArrayIndexOutOfboundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
+ float[] measured = new float[1];
+ for (int i = 0; i < text.length(); i++) {
+ assertBreakText(text, textChars, textSpan, i, i + 1, true, totalWidth, 1, widths[i]);
}
+ // Measure empty string
+ assertBreakText(text, textChars, textSpan, 0, 0, true, totalWidth, 0, 0);
+
+ // Measure substring from front: "HIJ"
+ assertBreakText(text, textChars, textSpan, 0, 3, true, totalWidth,
+ 3, widths[0] + widths[1] + widths[2]);
+
+ // Reverse measure substring from front: "HIJ"
+ assertBreakText(text, textChars, textSpan, 0, 3, false, totalWidth,
+ 3, widths[0] + widths[1] + widths[2]);
+
+ // Measure substring from back: "MN"
+ assertBreakText(text, textChars, textSpan, 5, 7, false, totalWidth,
+ 2, widths[5] + widths[6]);
+
+ // Reverse measure substring from back: "MN"
+ assertBreakText(text, textChars, textSpan, 5, 7, false, totalWidth,
+ 2, widths[5] + widths[6]);
+
+ // Measure substring in the middle: "JKL"
+ assertBreakText(text, textChars, textSpan, 2, 5, true, totalWidth,
+ 3, widths[2] + widths[3] + widths[4]);
+
+ // Reverse measure substring in the middle: "JKL"
+ assertBreakText(text, textChars, textSpan, 2, 5, false, totalWidth,
+ 3, widths[2] + widths[3] + widths[4]);
+
+ // Measure substring in the middle and restrict width to the first 2 characters.
+ assertBreakText(text, textChars, textSpan, 2, 5, true, widths[2] + widths[3],
+ 2, widths[2] + widths[3]);
+
+ // Reverse measure substring in the middle and restrict width to the last 2 characters.
+ assertBreakText(text, textChars, textSpan, 2, 5, false, widths[3] + widths[4],
+ 2, widths[3] + widths[4]);
}
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "breakText",
- args = {java.lang.CharSequence.class, int.class, int.class, boolean.class, float.class,
- float[].class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testBreakText2() {
+ private void assertBreakText(String text, char[] textChars, SpannedString textSpan,
+ int start, int end, boolean measureForwards, float maxWidth, int expectedCount,
+ float expectedWidth) {
Paint p = new Paint();
- String string = "HIJKLMN";
- float[] width = {8.0f, 4.0f, 3.0f, 7.0f, 6.0f, 10.0f, 9.0f};
- float[] f = new float[1];
- assertEquals(7, p.breakText(string, 0, 7, true, 50.0f, f));
- assertEquals(47.0f, f[0]);
- assertEquals(6, p.breakText(string, 0, 7, true, 40.0f, f));
- assertEquals(38.0f, f[0]);
- assertEquals(7, p.breakText(string, 0, 7, false, 50.0f, f));
- assertEquals(47.0f, f[0]);
-
- for (int i = 0; i < string.length(); i++) {
- assertEquals(1, p.breakText(string, i, i + 1, true, 20.0f, f));
- assertEquals(width[i], f[0]);
+ int count = end - start;
+ if (!measureForwards) {
+ count = -count;
}
- assertEquals(4, p.breakText(string, 0, 4, true, 30.0f, f));
- assertEquals(22.0f, f[0]);
- assertEquals(3, p.breakText(string, 0, 3, true, 30.0f, f));
- assertEquals(15.0f, f[0]);
- assertEquals(2, p.breakText(string, 0, 2, true, 30.0f, f));
- assertEquals(12.0f, f[0]);
- assertEquals(1, p.breakText(string, 0, 1, true, 30.0f, f));
- assertEquals(8.0f, f[0]);
- assertEquals(0, p.breakText(string, 0, 0, true, 30.0f, f));
- assertEquals(0.0f, f[0]);
+ float[][] measured = new float[][] {
+ new float[1],
+ new float[1],
+ new float[1]
+ };
+ String textSlice = text.substring(start, end);
+ assertEquals(expectedCount, p.breakText(textSlice, measureForwards, maxWidth, measured[0]));
+ assertEquals(expectedCount, p.breakText(textChars, start, count, maxWidth, measured[1]));
+ assertEquals(expectedCount, p.breakText(textSpan, start, end, measureForwards, maxWidth,
+ measured[2]));
- assertEquals(1, p.breakText(string, 2, 3, true, 30.0f, f));
- assertEquals(3.0f, f[0]);
- assertEquals(1, p.breakText(string, 2, 3, false, 30.0f, f));
- assertEquals(3.0f, f[0]);
-
- assertEquals(1, p.breakText(string, 0, 1, true, 30.0f, f));
- assertEquals(8.0f, f[0]);
- assertEquals(2, p.breakText(string, 0, 2, true, 30.0f, f));
- assertEquals(12.0f, f[0]);
- assertEquals(3, p.breakText(string, 0, 3, true, 30.0f, f));
- assertEquals(15.0f, f[0]);
- assertEquals(4, p.breakText(string, 0, 4, true, 30.0f, f));
- assertEquals(22.0f, f[0]);
-
- assertEquals(7, p.breakText(string, 0, 7, true, 50.0f, f));
- assertEquals(47.0f, f[0]);
- assertEquals(6, p.breakText(string, 0, 7, true, 40.0f, f));
- assertEquals(38.0f, f[0]);
-
- assertEquals(7, p.breakText(string, 0, 7, false, 50.0f, null));
- assertEquals(7, p.breakText(string, 0, 7, true, 50.0f, null));
-
- try {
- p.breakText(string, 0, 8, true, 60.0f, null);
- fail("Should throw an StringIndexOutOfboundsException");
- } catch (StringIndexOutOfBoundsException e) {
- //except here
+ for (int i = 0; i < measured.length; i++) {
+ assertEquals("i: " + i, expectedWidth, measured[i][0]);
}
- try {
- p.breakText(string, -1, 7, true, 50.0f, null);
- fail("Should throw an StringIndexOutOfboundsException");
- } catch (StringIndexOutOfBoundsException e) {
- //except here
- }
- try {
- p.breakText(string, 1, -7, true, 50.0f, null);
- fail("Should throw an StringIndexOutOfboundsException");
- } catch (StringIndexOutOfBoundsException e) {
- //except here
- }
- try {
- p.breakText(string, 7, 1, true, 50.0f, null);
- fail("Should throw an StringIndexOutOfboundsException");
- } catch (StringIndexOutOfBoundsException e) {
- //except here
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "breakText",
- args = {java.lang.String.class, boolean.class, float.class, float[].class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testBreakText3() {
- Paint p = new Paint();
- String string = "HIJKLMN";
- float[] width = {8.0f, 4.0f, 3.0f, 7.0f, 6.0f, 10.0f, 9.0f};
- float[] f = new float[1];
-
- for (int i = 0; i < string.length(); i++) {
- assertEquals(1, p.breakText(string.substring(i, i+1), true, 20.0f, f));
- assertEquals(width[i], f[0]);
- assertEquals(1, p.breakText(string.substring(i, i+1), false, 20.0f, f));
- assertEquals(width[i], f[0]);
- }
-
- assertEquals(0, p.breakText("", false, 20.0f, f));
- assertEquals(0.0f, f[0]);
-
- assertEquals(7, p.breakText(string, true, 50.0f, f));
- assertEquals(47.0f, f[0]);
- assertEquals(7, p.breakText(string, false, 50.0f, f));
- assertEquals(47.0f, f[0]);
- assertEquals(6, p.breakText(string, false, 40.0f, f));
- assertEquals(39.0f, f[0]);
- assertEquals(5, p.breakText(string, false, 35.0f, f));
- assertEquals(35.0f, f[0]);
- assertEquals(4, p.breakText(string, false, 33.0f, f));
- assertEquals(32.0f, f[0]);
- assertEquals(3, p.breakText(string, false, 25.0f, f));
- assertEquals(25.0f, f[0]);
- assertEquals(2, p.breakText(string, false, 20.0f, f));
- assertEquals(19.0f, f[0]);
- assertEquals(1, p.breakText(string, false, 13.0f, f));
- assertEquals(9.0f, f[0]);
- assertEquals(0, p.breakText(string, false, 3.0f, f));
- assertEquals(0.0f, f[0]);
-
- assertEquals(7, p.breakText(string, true, 50.0f, f));
- assertEquals(47.0f, f[0]);
- assertEquals(6, p.breakText(string, true, 40.0f, f));
- assertEquals(38.0f, f[0]);
- assertEquals(5, p.breakText(string, true, 35.0f, f));
- assertEquals(28.0f, f[0]);
- assertEquals(4, p.breakText(string, true, 25.0f, f));
- assertEquals(22.0f, f[0]);
- assertEquals(3, p.breakText(string, true, 20.0f, f));
- assertEquals(15.0f, f[0]);
- assertEquals(2, p.breakText(string, true, 12.0f, f));
- assertEquals(12.0f, f[0]);
- assertEquals(1, p.breakText(string, true, 10.0f, f));
- assertEquals(8.0f, f[0]);
- assertEquals(0, p.breakText(string, true, 3.0f, f));
- assertEquals(0.0f, f[0]);
-
- assertEquals(7, p.breakText(string, true, 50.0f, null));
- assertEquals(6, p.breakText(string, true, 40.0f, null));
- assertEquals(5, p.breakText(string, true, 35.0f, null));
- assertEquals(4, p.breakText(string, true, 25.0f, null));
- assertEquals(3, p.breakText(string, true, 20.0f, null));
- assertEquals(2, p.breakText(string, true, 12.0f, null));
- assertEquals(1, p.breakText(string, true, 10.0f, null));
- assertEquals(0, p.breakText(string, true, 3.0f, null));
}
@TestTargetNew(
@@ -831,427 +688,48 @@
}
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "getTextWidths",
- args = {char[].class, int.class, int.class, float[].class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testGetTextWidths1() throws Exception {
- Paint p = new Paint();
- char[] chars = {'H', 'I', 'J', 'K', 'L', 'M', 'N'};
- float[] width = {8.0f, 4.0f, 3.0f, 7.0f, 6.0f, 10.0f, 9.0f};
- float[] f = new float[7];
+ public void testGetTextWidths() throws Exception {
+ String text = "HIJKLMN";
+ char[] textChars = text.toCharArray();
+ SpannedString textSpan = new SpannedString(text);
- assertEquals(7, p.getTextWidths(chars, 0, 7, f));
- for (int i = 0; i < chars.length; i++) {
- assertEquals(width[i], f[i]);
- }
+ // Test measuring the widths of the entire text
+ assertGetTextWidths(text, textChars, textSpan, 0, 7);
- assertEquals(4, p.getTextWidths(chars, 3, 4, f));
- for (int i = 3; i < chars.length; i++) {
- assertEquals(width[i], f[i - 3]);
- }
+ // Test measuring a substring of the text
+ assertGetTextWidths(text, textChars, textSpan, 1, 3);
- assertEquals(1, p.getTextWidths(chars, 6, 1, f));
- assertEquals(width[6], f[0]);
- assertEquals(0, p.getTextWidths(chars, 6, 0, f));
+ // Test measuring a substring of zero length.
+ assertGetTextWidths(text, textChars, textSpan, 3, 3);
- try {
- p.getTextWidths(chars, -1, 6, f);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(chars, 0, -1, f);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(chars, 1, 8, f);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
-
- float[] f2 = new float[3];
- try {
- p.getTextWidths(chars, 0, 6, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
+ // Test measuring substrings from the front and back
+ assertGetTextWidths(text, textChars, textSpan, 0, 2);
+ assertGetTextWidths(text, textChars, textSpan, 4, 7);
}
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "getTextWidths",
- args = {java.lang.CharSequence.class, int.class, int.class, float[].class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testGetTextWidths2() throws Exception {
+ /** Tests all four overloads of getTextWidths are the same. */
+ private void assertGetTextWidths(String text, char[] textChars, SpannedString textSpan,
+ int start, int end) {
Paint p = new Paint();
+ int count = end - start;
+ float[][] widths = new float[][] {
+ new float[count],
+ new float[count],
+ new float[count],
+ new float[count]
+ };
- // CharSequence of String
- String string = "HIJKLMN";
- float[] width = {8.0f, 4.0f, 3.0f, 7.0f, 6.0f, 10.0f, 9.0f};
- float[] f = new float[7];
+ String textSlice = text.substring(start, end);
+ assertEquals(count, p.getTextWidths(textSlice, widths[0]));
+ assertEquals(count, p.getTextWidths(textChars, start, count, widths[1]));
+ assertEquals(count, p.getTextWidths(textSpan, start, end, widths[2]));
+ assertEquals(count, p.getTextWidths(text, start, end, widths[3]));
- assertEquals(7, p.getTextWidths((CharSequence) string, 0, 7, f));
- for (int i = 0; i < string.length(); i++) {
- assertEquals(width[i], f[i]);
- }
-
- assertEquals(4, p.getTextWidths((CharSequence) string, 3, 7, f));
- for (int i = 3; i < string.length(); i++) {
- assertEquals(width[i], f[i - 3]);
- }
-
- assertEquals(1, p.getTextWidths((CharSequence) string, 6, 7, f));
- assertEquals(width[6], f[0]);
- assertEquals(0, p.getTextWidths((CharSequence) string, 7, 7, f));
-
- try {
- p.getTextWidths((CharSequence) string, -1, 6, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
- try {
- p.getTextWidths((CharSequence) string, 0, -1, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths((CharSequence) string, 4, 3, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths((CharSequence) string, 1, 8, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- float[] f2 = new float[3];
- try {
- p.getTextWidths((CharSequence) string, 0, 6, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
- // CharSequence of SpannedString
- SpannedString spannedString = new SpannedString("HIJKLMN");
-
- assertEquals(7, p.getTextWidths(spannedString, 0, 7, f));
- for (int i = 0; i < spannedString.length(); i++) {
- assertEquals(width[i], f[i]);
- }
-
- assertEquals(4, p.getTextWidths(spannedString, 3, 7, f));
- for (int i = 3; i < spannedString.length(); i++) {
- assertEquals(width[i], f[i - 3]);
- }
-
- assertEquals(1, p.getTextWidths(spannedString, 6, 7, f));
- assertEquals(width[6], f[0]);
- assertEquals(0, p.getTextWidths(spannedString, 7, 7, f));
-
- try {
- p.getTextWidths(spannedString, -1, 6, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannedString, 0, -1, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannedString, 4, 3, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannedString, 1, 8, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannedString, 0, 6, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
-
- // CharSequence of SpannableString
- SpannableString spannableString = new SpannableString("HIJKLMN");
-
- assertEquals(7, p.getTextWidths(spannableString, 0, 7, f));
- for (int i = 0; i < spannableString.length(); i++) {
- assertEquals(width[i], f[i]);
- }
-
- assertEquals(4, p.getTextWidths(spannableString, 3, 7, f));
- for (int i = 3; i < spannableString.length(); i++) {
- assertEquals(width[i], f[i - 3]);
- }
-
- assertEquals(1, p.getTextWidths(spannableString, 6, 7, f));
- assertEquals(width[6], f[0]);
- assertEquals(0, p.getTextWidths(spannableString, 7, 7, f));
-
- try {
- p.getTextWidths(spannableString, -1, 6, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableString, 0, -1, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableString, 4, 3, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableString, 1, 8, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableString, 0, 6, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
-
- // CharSequence of SpannableStringBuilder (GraphicsOperations)
- SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("HIJKLMN");
-
- assertEquals(7, p.getTextWidths(spannableStringBuilder, 0, 7, f));
- for (int i = 0; i < spannableStringBuilder.length(); i++) {
- assertEquals(width[i], f[i]);
- }
-
- assertEquals(4, p.getTextWidths(spannableStringBuilder, 3, 7, f));
- for (int i = 3; i < spannableStringBuilder.length(); i++) {
- assertEquals(width[i], f[i - 3]);
- }
-
- assertEquals(1, p.getTextWidths(spannableStringBuilder, 6, 7, f));
- assertEquals(width[6], f[0]);
- assertEquals(0, p.getTextWidths(spannableStringBuilder, 7, 7, f));
-
- try {
- p.getTextWidths(spannableStringBuilder, -1, 6, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableStringBuilder, 0, -1, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableStringBuilder, 4, 3, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableStringBuilder, 1, 8, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(spannableStringBuilder, 0, 6, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
-
- // CharSequence of StringBuilder
- StringBuilder stringBuilder = new StringBuilder("HIJKLMN");
-
- assertEquals(7, p.getTextWidths(stringBuilder, 0, 7, f));
- for (int i = 0; i < stringBuilder.length(); i++) {
- assertEquals(width[i], f[i]);
- }
-
- assertEquals(4, p.getTextWidths(stringBuilder, 3, 7, f));
- for (int i = 3; i < stringBuilder.length(); i++) {
- assertEquals(width[i], f[i - 3]);
- }
-
- assertEquals(1, p.getTextWidths(stringBuilder, 6, 7, f));
- assertEquals(width[6], f[0]);
- assertEquals(0, p.getTextWidths(stringBuilder, 7, 7, f));
-
- try {
- p.getTextWidths(stringBuilder, -1, 6, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(stringBuilder, 0, -1, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(stringBuilder, 4, 3, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(stringBuilder, 1, 8, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(stringBuilder, 0, 6, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "getTextWidths",
- args = {java.lang.String.class, int.class, int.class, float[].class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testGetTextWidths3() {
- Paint p = new Paint();
- String string = "HIJKLMN";
- float[] width = {8.0f, 4.0f, 3.0f, 7.0f, 6.0f, 10.0f, 9.0f};
- float[] f = new float[7];
-
- assertEquals(7, p.getTextWidths(string, 0, 7, f));
- for (int i = 0; i < string.length(); i++) {
- assertEquals(width[i], f[i]);
- }
-
- assertEquals(4, p.getTextWidths(string, 3, 7, f));
- for (int i = 3; i < string.length(); i++) {
- assertEquals(width[i], f[i - 3]);
- }
-
- assertEquals(1, p.getTextWidths(string, 6, 7, f));
- assertEquals(width[6], f[0]);
- assertEquals(0, p.getTextWidths(string, 7, 7, f));
-
- try {
- p.getTextWidths(string, -1, 6, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(string, 0, -1, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(string, 4, 3, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextWidths(string, 1, 8, f);
- fail("Should throw an IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
- float[] f2 = new float[3];
- try {
- p.getTextWidths(string, 0, 6, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
- }
- }
-
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "getTextWidths",
- args = {java.lang.String.class, float[].class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testGetTextWidths4() throws Exception {
- Paint p = new Paint();
- String string = "HIJKLMN";
- float[] width = {8.0f, 4.0f, 3.0f, 7.0f, 6.0f, 10.0f, 9.0f};
- float[] f = new float[7];
-
- assertEquals(7, p.getTextWidths(string, f));
- for (int i = 0; i < string.length(); i++) {
- assertEquals(width[i], f[i]);
- }
-
- assertEquals(0, p.getTextWidths("", f));
-
- try {
- p.getTextWidths(null, f);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- float[] f2 = new float[3];
- try {
- p.getTextWidths(string, f2);
- fail("Should throw an ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- //except here
+ // Check that the widths returned by the overloads are the same.
+ for (int i = 0; i < count; i++) {
+ assertEquals(widths[0][i], widths[1][i]);
+ assertEquals(widths[1][i], widths[2][i]);
+ assertEquals(widths[2][i], widths[3][i]);
}
}
@@ -1407,138 +885,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "getTextBounds",
- args = {java.lang.String.class, int.class, int.class, android.graphics.Rect.class}
- )
- @BrokenTest("Test result will be different when run in batch mode")
- public void testGetTextBounds1() throws Exception {
- Paint p = new Paint();
- Rect r = new Rect();
- String s = "HIJKLMN";
-
- try {
- p.getTextBounds(s, -1, 2, r);
- } catch (IndexOutOfBoundsException e) {
- } catch (RuntimeException e) {
- fail("Should not throw a RuntimeException");
- }
-
- try {
- p.getTextBounds(s, 0, -2, r);
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextBounds(s, 4, 3, r);
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextBounds(s, 0, 8, r);
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextBounds(s, 0, 2, null);
- } catch (NullPointerException e) {
- //except here
- }
-
- p.getTextBounds(s, 0, 0, r);
- assertEquals(0, r.bottom);
- assertEquals(-1, r.left);
- assertEquals(0, r.right);
- assertEquals(-1, r.top);
-
- p.getTextBounds(s, 0, 1, r);
- assertEquals(0, r.bottom);
- assertEquals(1, r.left);
- assertEquals(8, r.right);
- assertEquals(-9, r.top);
-
- p.getTextBounds(s, 1, 2, r);
- assertEquals(0, r.bottom);
- assertEquals(0, r.left);
- assertEquals(4, r.right);
- assertEquals(-9, r.top);
-
- p.getTextBounds(s, 0, 6, r);
- assertEquals(3, r.bottom);
- assertEquals(1, r.left);
- assertEquals(38, r.right);
- assertEquals(-9, r.top);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getTextBounds",
- args = {char[].class, int.class, int.class, android.graphics.Rect.class}
- )
- @BrokenTest("Test result will be different when run in batch mode")
- public void testGetTextBounds2() throws Exception {
- Paint p = new Paint();
- Rect r = new Rect();
- char[] chars = {'H', 'I', 'J', 'K', 'L', 'M', 'N'};
-
- try {
- p.getTextBounds(chars, -1, 2, r);
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextBounds(chars, 0, -2, r);
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextBounds(chars, 4, 3, r);
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
-
- try {
- p.getTextBounds(chars, 0, 8, r);
- } catch (IndexOutOfBoundsException e) {
- //except here
- }
- try {
- p.getTextBounds(chars, 0, 2, null);
- } catch (NullPointerException e) {
- //except here
- }
-
- p.getTextBounds(chars, 0, 0, r);
- assertEquals(0, r.bottom);
- assertEquals(-1, r.left);
- assertEquals(0, r.right);
- assertEquals(0, r.top);
-
- p.getTextBounds(chars, 0, 1, r);
- assertEquals(0, r.bottom);
- assertEquals(1, r.left);
- assertEquals(8, r.right);
- assertEquals(-9, r.top);
-
- p.getTextBounds(chars, 1, 2, r);
- assertEquals(3, r.bottom);
- assertEquals(0, r.left);
- assertEquals(7, r.right);
- assertEquals(-9, r.top);
-
- p.getTextBounds(chars, 0, 6, r);
- assertEquals(3, r.bottom);
- assertEquals(1, r.left);
- assertEquals(38, r.right);
- assertEquals(-9, r.top);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "setShadowLayer",
args = {float.class, float.class, float.class, int.class}
)
@@ -1920,433 +1266,54 @@
assertEquals(-26, fmi.top);
}
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "measureText",
- args = {char[].class, int.class, int.class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testMeasureText1() {
+ public void testMeasureText() {
+ String text = "HIJKLMN";
+ char[] textChars = text.toCharArray();
+ SpannedString textSpan = new SpannedString(text);
+
Paint p = new Paint();
-
- // The default text size
- assertEquals(12.0f, p.getTextSize());
-
- char[] c = {};
- char[] c2 = {'H'};
- char[] c3 = {'H', 'I', 'J', 'H', 'I', 'J'};
- assertEquals(0.0f, p.measureText(c, 0, 0));
- assertEquals(8.0f, p.measureText(c2, 0, 1));
- assertEquals(8.0f, p.measureText(c3, 0, 1));
- assertEquals(15.0f, p.measureText(c3, 0, 3));
- assertEquals(15.0f, p.measureText(c3, 3, 3));
- assertEquals(30.0f, p.measureText(c3, 0, 6));
-
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText(c2, 0, 1));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText(c2, 0, 1));
-
- try {
- p.measureText(c3, -1, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
+ float[] widths = new float[text.length()];
+ for (int i = 0; i < widths.length; i++) {
+ widths[i] = p.measureText(text, i, i + 1);
}
- try {
- p.measureText(c3, 4, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
+ float totalWidth = 0;
+ for (int i = 0; i < widths.length; i++) {
+ totalWidth += widths[i];
}
- try {
- p.measureText(c3, 0, 9);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
+ // Test measuring the widths of the entire text
+ assertMeasureText(text, textChars, textSpan, 0, 7, totalWidth);
- try {
- p.measureText((char[]) null, 0, 0);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
+ // Test measuring a substring of the text
+ assertMeasureText(text, textChars, textSpan, 1, 3, widths[1] + widths[2]);
+
+ // Test measuring a substring of zero length.
+ assertMeasureText(text, textChars, textSpan, 3, 3, 0);
+
+ // Test measuring substrings from the front and back
+ assertMeasureText(text, textChars, textSpan, 0, 2, widths[0] + widths[1]);
+ assertMeasureText(text, textChars, textSpan, 4, 7, widths[4] + widths[5] + widths[6]);
}
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "measureText",
- args = {java.lang.String.class, int.class, int.class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testMeasureText2() {
+ /** Tests that all four overloads of measureText are the same and match some value. */
+ private void assertMeasureText(String text, char[] textChars, SpannedString textSpan,
+ int start, int end, float expectedWidth) {
Paint p = new Paint();
- String string = "HIJHIJ";
+ int count = end - start;
+ float[] widths = new float[] {-1, -1, -1, -1};
- // The default text size
- assertEquals(12.0f, p.getTextSize());
+ String textSlice = text.substring(start, end);
+ widths[0] = p.measureText(textSlice);
+ widths[1] = p.measureText(textChars, start, count);
+ widths[2] = p.measureText(textSpan, start, end);
+ widths[3] = p.measureText(text, start, end);
- assertEquals(0.0f, p.measureText("", 0, 0));
- assertEquals(8.0f, p.measureText("H", 0, 1));
- assertEquals(4.0f, p.measureText("I", 0, 1));
- assertEquals(3.0f, p.measureText("J", 0, 1));
- assertEquals(8.0f, p.measureText(string, 0, 1));
- assertEquals(15.0f, p.measureText(string, 0, 3));
- assertEquals(15.0f, p.measureText(string, 3, 6));
- assertEquals(30.0f, p.measureText(string, 0, 6));
-
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText("H", 0, 1));
- assertEquals(8.0f, p.measureText("I", 0, 1));
- assertEquals(7.0f, p.measureText("J", 0, 1));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText("H", 0, 1));
- assertEquals(7.0f, p.measureText("I", 0, 1));
- assertEquals(7.0f, p.measureText("J", 0, 1));
-
- try {
- p.measureText(string, -1, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(string, 4, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(string, 0, 9);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((String) null, 0, 0);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "measureText",
- args = {java.lang.String.class}
- )
- @BrokenTest("unknown if hardcoded values being checked are correct")
- public void testMeasureText3() {
- Paint p = new Paint();
-
- // The default text size
- p.setTextSize(12.0f);
- assertEquals(12.0f, p.getTextSize());
-
- assertEquals(0.0f, p.measureText(""));
- assertEquals(8.0f, p.measureText("H"));
- assertEquals(4.0f, p.measureText("I"));
- assertEquals(3.0f, p.measureText("J"));
- assertEquals(7.0f, p.measureText("K"));
- assertEquals(6.0f, p.measureText("L"));
- assertEquals(10.0f, p.measureText("M"));
- assertEquals(9.0f, p.measureText("N"));
- assertEquals(12.0f, p.measureText("HI"));
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText("H"));
- assertEquals(8.0f, p.measureText("I"));
- assertEquals(7.0f, p.measureText("J"));
- assertEquals(14.0f, p.measureText("K"));
- assertEquals(12.0f, p.measureText("L"));
- assertEquals(21.0f, p.measureText("M"));
- assertEquals(18.0f, p.measureText("N"));
- assertEquals(25.0f, p.measureText("HI"));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText("H"));
- assertEquals(7.0f, p.measureText("I"));
- assertEquals(7.0f, p.measureText("J"));
- assertEquals(7.0f, p.measureText("K"));
- assertEquals(7.0f, p.measureText("L"));
- assertEquals(7.0f, p.measureText("M"));
- assertEquals(7.0f, p.measureText("N"));
- assertEquals(14.0f, p.measureText("HI"));
-
- try {
- p.measureText(null);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.TODO,
- method = "measureText",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- @BrokenTest("unknown if hardcoded values being tested are correct")
- public void testMeasureText4() {
-
- Paint p = new Paint();
- // CharSequence of String
- String string = "HIJHIJ";
- // The default text size
- p.setTextSize(12.0f);
- assertEquals(12.0f, p.getTextSize());
-
- assertEquals(8.0f, p.measureText((CharSequence) string, 0, 1));
- assertEquals(15.0f, p.measureText((CharSequence) string, 0, 3));
- assertEquals(15.0f, p.measureText((CharSequence) string, 3, 6));
- assertEquals(30.0f, p.measureText((CharSequence) string, 0, 6));
-
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText((CharSequence) string, 0, 1));
- assertEquals(32.0f, p.measureText((CharSequence) string, 0, 3));
- assertEquals(32.0f, p.measureText((CharSequence) string, 3, 6));
- assertEquals(64.0f, p.measureText((CharSequence) string, 0, 6));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText((CharSequence) string, 0, 1));
- assertEquals(21.0f, p.measureText((CharSequence) string, 0, 3));
- assertEquals(21.0f, p.measureText((CharSequence) string, 3, 6));
- assertEquals(42.0f, p.measureText((CharSequence) string, 0, 6));
-
- try {
- p.measureText((CharSequence) "HIJHIJ", -1, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((CharSequence) "HIJHIJ", 4, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((CharSequence) "HIJHIJ", 0, 9);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((CharSequence) null, 0, 0);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- // CharSequence of SpannedString
- SpannedString spannedString = new SpannedString("HIJHIJ");
- // The default text size and typeface
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.DEFAULT);
-
- assertEquals(8.0f, p.measureText(spannedString, 0, 1));
- assertEquals(15.0f, p.measureText(spannedString, 0, 3));
- assertEquals(15.0f, p.measureText(spannedString, 3, 6));
- assertEquals(30.0f, p.measureText(spannedString, 0, 6));
-
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText(spannedString, 0, 1));
- assertEquals(32.0f, p.measureText(spannedString, 0, 3));
- assertEquals(32.0f, p.measureText(spannedString, 3, 6));
- assertEquals(64.0f, p.measureText(spannedString, 0, 6));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText(spannedString, 0, 1));
- assertEquals(21.0f, p.measureText(spannedString, 0, 3));
- assertEquals(21.0f, p.measureText(spannedString, 3, 6));
- assertEquals(42.0f, p.measureText(spannedString, 0, 6));
-
- try {
- p.measureText(spannedString, -1, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(spannedString, 4, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(spannedString, 0, 9);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((SpannedString) null, 0, 0);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- // CharSequence of SpannableString
- SpannableString spannableString = new SpannableString("HIJHIJ");
- // The default text size and typeface
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.DEFAULT);
-
- assertEquals(8.0f, p.measureText(spannableString, 0, 1));
- assertEquals(15.0f, p.measureText(spannableString, 0, 3));
- assertEquals(15.0f, p.measureText(spannableString, 3, 6));
- assertEquals(30.0f, p.measureText(spannableString, 0, 6));
-
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText(spannableString, 0, 1));
- assertEquals(32.0f, p.measureText(spannableString, 0, 3));
- assertEquals(32.0f, p.measureText(spannableString, 3, 6));
- assertEquals(64.0f, p.measureText(spannableString, 0, 6));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText(spannableString, 0, 1));
- assertEquals(21.0f, p.measureText(spannableString, 0, 3));
- assertEquals(21.0f, p.measureText(spannableString, 3, 6));
- assertEquals(42.0f, p.measureText(spannableString, 0, 6));
-
- try {
- p.measureText(spannableString, -1, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(spannableString, 4, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(spannableString, 0, 9);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((SpannableString) null, 0, 0);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- // CharSequence of SpannableStringBuilder (GraphicsOperations)
- SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("HIJHIJ");
- // The default text size
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.DEFAULT);
-
- assertEquals(8.0f, p.measureText(spannableStringBuilder, 0, 1));
- assertEquals(15.0f, p.measureText(spannableStringBuilder, 0, 3));
- assertEquals(15.0f, p.measureText(spannableStringBuilder, 3, 6));
- assertEquals(30.0f, p.measureText(spannableStringBuilder, 0, 6));
-
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText(spannableStringBuilder, 0, 1));
- assertEquals(32.0f, p.measureText(spannableStringBuilder, 0, 3));
- assertEquals(32.0f, p.measureText(spannableStringBuilder, 3, 6));
- assertEquals(64.0f, p.measureText(spannableStringBuilder, 0, 6));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText(spannableStringBuilder, 0, 1));
- assertEquals(21.0f, p.measureText(spannableStringBuilder, 0, 3));
- assertEquals(21.0f, p.measureText(spannableStringBuilder, 3, 6));
- assertEquals(42.0f, p.measureText(spannableStringBuilder, 0, 6));
-
- try {
- p.measureText(spannableStringBuilder, -1, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(spannableStringBuilder, 4, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(spannableStringBuilder, 0, 9);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((SpannableStringBuilder) null, 0, 0);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- // CharSequence of StringBuilder
- StringBuilder stringBuilder = new StringBuilder("HIJHIJ");
- // The default text size and typeface
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.DEFAULT);
-
- assertEquals(8.0f, p.measureText(stringBuilder, 0, 1));
- assertEquals(15.0f, p.measureText(stringBuilder, 0, 3));
- assertEquals(15.0f, p.measureText(stringBuilder, 3, 6));
- assertEquals(30.0f, p.measureText(stringBuilder, 0, 6));
-
- p.setTextSize(24.0f);
-
- assertEquals(17.0f, p.measureText(stringBuilder, 0, 1));
- assertEquals(32.0f, p.measureText(stringBuilder, 0, 3));
- assertEquals(32.0f, p.measureText(stringBuilder, 3, 6));
- assertEquals(64.0f, p.measureText(stringBuilder, 0, 6));
-
- p.setTextSize(12.0f);
- p.setTypeface(Typeface.MONOSPACE);
-
- assertEquals(7.0f, p.measureText(stringBuilder, 0, 1));
- assertEquals(21.0f, p.measureText(stringBuilder, 0, 3));
- assertEquals(21.0f, p.measureText(stringBuilder, 3, 6));
- assertEquals(42.0f, p.measureText(stringBuilder, 0, 6));
-
- try {
- p.measureText(stringBuilder, -1, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(stringBuilder, 4, 3);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText(stringBuilder, 0, 9);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
- try {
- p.measureText((StringBuilder) null, 0, 0);
- fail("Should throw a RuntimeException");
- } catch (RuntimeException e) {
- }
-
+ // Check that the widths returned by the overloads are the same.
+ assertEquals(widths[0], widths[1]);
+ assertEquals(widths[1], widths[2]);
+ assertEquals(widths[2], widths[3]);
+ assertEquals(widths[3], expectedWidth);
}
@TestTargetNew(
diff --git a/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java b/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java
index c738d40..614a44e 100644
--- a/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java
@@ -16,17 +16,17 @@
package android.graphics.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PathMeasure;
+import android.graphics.Path.Direction;
import android.test.AndroidTestCase;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
@TestTargetClass(PathMeasure.class)
public class PathMeasureTest extends AndroidTestCase {
private PathMeasure mPathMeasure;
@@ -119,13 +119,22 @@
method = "isClosed",
args = {}
)
- @BrokenTest("Flaky test. new PathMeasure().isClosed() does not return consistent result")
public void testIsClosed() {
- assertTrue(mPathMeasure.isClosed());
- mPathMeasure = null;
- mPathMeasure = new PathMeasure();
- mPathMeasure.setPath(mPath, false);
- assertFalse(mPathMeasure.isClosed());
+ Path circle = new Path();
+ circle.addCircle(0, 0, 1, Direction.CW);
+
+ PathMeasure measure = new PathMeasure(circle, false);
+ assertTrue(measure.isClosed());
+ measure.setPath(circle, true);
+ assertTrue(measure.isClosed());
+
+ Path line = new Path();
+ line.lineTo(5, 5);
+
+ measure.setPath(line, false);
+ assertFalse(measure.isClosed());
+ measure.setPath(line, true);
+ assertTrue(measure.isClosed());
}
@TestTargetNew(
diff --git a/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java b/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java
old mode 100644
new mode 100755
index d09483d..c861b3e
--- a/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java
@@ -16,21 +16,12 @@
package android.graphics.cts;
-import com.android.cts.stub.R;
-
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
import android.graphics.Typeface;
-import android.graphics.Bitmap.Config;
import android.test.AndroidTestCase;
@TestTargetClass(android.graphics.Typeface.class)
@@ -174,28 +165,5 @@
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "samplefont.ttf");
assertNotNull(typeface);
-
- Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
- bitmap.eraseColor(Color.BLACK);
- Canvas canvas = new Canvas(bitmap);
- Paint p = new Paint();
- p.setTypeface(typeface);
- p.setColor(Color.WHITE);
- p.setTextAlign(Paint.Align.CENTER);
- p.setTextSize(50);
- p.setFlags(0); // clear all flags (not sure what defaults flags are set)
- canvas.drawText("test", bitmap.getWidth() / 2, 3 * bitmap.getHeight() / 4 , p);
-
- BitmapFactory.Options opt = new BitmapFactory.Options();
- opt.inScaled = false;
- Bitmap expected = BitmapFactory.decodeResource(
- getContext().getResources(), R.drawable.typeface_test, opt);
- assertEquals(expected.getWidth(), bitmap.getWidth());
- assertEquals(expected.getHeight(), bitmap.getHeight());
- for (int y = 0; y < bitmap.getHeight(); y++) {
- for (int x = 0; x < bitmap.getWidth(); x++) {
- assertEquals(expected.getPixel(x, y), bitmap.getPixel(x, y));
- }
- }
}
}
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
index 6a13ab2..9052f5c 100644
--- a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
@@ -406,10 +406,8 @@
parameters.setPreviewSize(size.width, size.height);
mCamera.setParameters(parameters);
assertEquals(size, mCamera.getParameters().getPreviewSize());
- mCamera.startPreview();
- waitForPreviewDone();
+ checkPreviewCallback();
assertTrue(mPreviewCallbackResult);
- mCamera.stopPreview();
try {
// Wait for a while to throw away the remaining preview frames.
Thread.sleep(1000);
@@ -1386,6 +1384,7 @@
// Ensure the camera can be opened if release is called right after AF.
mCamera = Camera.open(cameraId);
+ mCamera.setPreviewDisplay(getActivity().getSurfaceView().getHolder());
mCamera.startPreview();
mCamera.autoFocus(mAutoFocusCallback);
mCamera.release();
@@ -1674,7 +1673,7 @@
Iterator<Long> it = mFrames.iterator();
while(it.hasNext()) {
long time = it.next();
- if (arrivalTime - time > 1000 && mFrames.size() > 1) {
+ if (arrivalTime - time > 1000 && mFrames.size() > 2) {
it.remove();
} else {
break;
diff --git a/tests/tests/location/src/android/location/cts/LocationTest.java b/tests/tests/location/src/android/location/cts/LocationTest.java
index 531a949..2855436 100644
--- a/tests/tests/location/src/android/location/cts/LocationTest.java
+++ b/tests/tests/location/src/android/location/cts/LocationTest.java
@@ -29,6 +29,8 @@
import android.util.Printer;
import android.util.StringBuilderPrinter;
+import java.text.DecimalFormat;
+
@TestTargetClass(Location.class)
public class LocationTest extends AndroidTestCase {
private static final float DELTA = 0.1f;
@@ -141,22 +143,23 @@
args = {double.class, int.class}
)
public void testConvert_CoordinateToRepresentation() {
+ DecimalFormat df = new DecimalFormat("###.#####");
String result;
result = Location.convert(-80.0, Location.FORMAT_DEGREES);
- assertEquals("-80", result);
+ assertEquals("-" + df.format(80.0), result);
result = Location.convert(-80.085, Location.FORMAT_MINUTES);
- assertEquals("-80:5.1", result);
+ assertEquals("-80:" + df.format(5.1), result);
result = Location.convert(-80, Location.FORMAT_MINUTES);
- assertEquals("-80:0", result);
+ assertEquals("-80:" + df.format(0), result);
result = Location.convert(-80.075, Location.FORMAT_MINUTES);
- assertEquals("-80:4.5", result);
+ assertEquals("-80:" + df.format(4.5), result);
result = Location.convert(-80.075, Location.FORMAT_DEGREES);
- assertEquals("-80.075", result);
+ assertEquals("-" + df.format(80.075), result);
result = Location.convert(-80.075, Location.FORMAT_SECONDS);
assertEquals("-80:4:30", result);
diff --git a/tests/tests/media/src/android/media/cts/AudioTrackTest.java b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
index 4adc582..0316ef9 100644
--- a/tests/tests/media/src/android/media/cts/AudioTrackTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
@@ -394,8 +394,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
assertTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
track.write(data, OFFSET_DEFAULT, data.length);
@@ -453,8 +453,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
assertTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
track.write(data, OFFSET_DEFAULT, data.length);
@@ -519,8 +519,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
assertTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
track.write(data, OFFSET_DEFAULT, data.length);
@@ -586,8 +586,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
assertTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
track.write(data, OFFSET_DEFAULT, data.length);
@@ -661,8 +661,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
track.write(data, OFFSET_DEFAULT, data.length);
track.write(data, OFFSET_DEFAULT, data.length);
@@ -728,8 +728,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
track.write(data, OFFSET_DEFAULT, data.length);
track.write(data, OFFSET_DEFAULT, data.length);
@@ -790,8 +790,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
track.write(data, OFFSET_DEFAULT, data.length);
@@ -848,8 +848,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
track.write(data, OFFSET_DEFAULT, data.length);
track.write(data, OFFSET_DEFAULT, data.length);
@@ -964,8 +964,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE);
// -------- test --------------
track.write(data, OFFSET_DEFAULT, data.length);
@@ -1028,8 +1028,8 @@
// -------- initialization --------------
int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
- minBuffSize, TEST_MODE);
- byte data[] = new byte[minBuffSize / 2];
+ 2 * minBuffSize, TEST_MODE);
+ byte data[] = new byte[minBuffSize];
// -------- test --------------
track.write(data, OFFSET_DEFAULT, data.length);
track.write(data, OFFSET_DEFAULT, data.length);
diff --git a/tests/tests/media/src/android/media/cts/EqualizerTest.java b/tests/tests/media/src/android/media/cts/EqualizerTest.java
index 4b63828..955986e 100644
--- a/tests/tests/media/src/android/media/cts/EqualizerTest.java
+++ b/tests/tests/media/src/android/media/cts/EqualizerTest.java
@@ -33,8 +33,8 @@
private String TAG = "EqualizerTest";
private final static int MIN_NUMBER_OF_BANDS = 4;
- private final static int MAX_LEVEL_RANGE_LOW = -1200; // -12dB
- private final static int MIN_LEVEL_RANGE_HIGH = 1200; // +12dB
+ private final static int MAX_LEVEL_RANGE_LOW = 0; // 0dB
+ private final static int MIN_LEVEL_RANGE_HIGH = 0; // 0dB
private final static int TEST_FREQUENCY_MILLIHERTZ = 1000000; // 1kHz
private final static int MIN_NUMBER_OF_PRESETS = 0;
private final static float TOLERANCE = 100; // +/-1dB
@@ -597,4 +597,4 @@
}
}
-}
\ No newline at end of file
+}
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index a9e1c33..ead3d62 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -37,6 +37,7 @@
public class MediaRecorderTest extends ActivityInstrumentationTestCase2<MediaStubActivity> {
private final String OUTPUT_PATH;
+ private final String OUTPUT_PATH2;
private static final int RECORD_TIME = 3000;
private static final int VIDEO_WIDTH = 176;
private static final int VIDEO_HEIGHT = 144;
@@ -46,6 +47,7 @@
private boolean mOnInfoCalled;
private boolean mOnErrorCalled;
private File mOutFile;
+ private File mOutFile2;
private Camera mCamera;
/*
@@ -61,11 +63,14 @@
super("com.android.cts.stub", MediaStubActivity.class);
OUTPUT_PATH = new File(Environment.getExternalStorageDirectory(),
"record.out").getAbsolutePath();
+ OUTPUT_PATH2 = new File(Environment.getExternalStorageDirectory(),
+ "record2.out").getAbsolutePath();
}
@Override
protected void setUp() throws Exception {
mOutFile = new File(OUTPUT_PATH);
+ mOutFile2 = new File(OUTPUT_PATH2);
mMediaRecorder.reset();
mMediaRecorder.setOutputFile(OUTPUT_PATH);
mMediaRecorder.setOnInfoListener(new OnInfoListener() {
@@ -87,6 +92,9 @@
if (mOutFile != null && mOutFile.exists()) {
mOutFile.delete();
}
+ if (mOutFile2 != null && mOutFile2.exists()) {
+ mOutFile2.delete();
+ }
if (mCamera != null) {
mCamera.release();
mCamera = null;
@@ -251,15 +259,16 @@
public void testRecorderVideo() throws Exception {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
+ mMediaRecorder.setOutputFile(OUTPUT_PATH2);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setPreviewDisplay(getActivity().getSurfaceHolder().getSurface());
mMediaRecorder.setVideoFrameRate(FRAME_RATE);
mMediaRecorder.setVideoSize(VIDEO_WIDTH, VIDEO_HEIGHT);
- FileOutputStream fos = new FileOutputStream(OUTPUT_PATH);
+ FileOutputStream fos = new FileOutputStream(OUTPUT_PATH2);
FileDescriptor fd = fos.getFD();
mMediaRecorder.setOutputFile(fd);
long maxFileSize = MAX_FILE_SIZE * 10;
- recordMedia(maxFileSize);
+ recordMedia(maxFileSize, mOutFile2);
}
@TestTargets({
@@ -318,8 +327,9 @@
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
assertEquals(0, mMediaRecorder.getMaxAmplitude());
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+ mMediaRecorder.setOutputFile(OUTPUT_PATH);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- recordMedia(MAX_FILE_SIZE);
+ recordMedia(MAX_FILE_SIZE, mOutFile);
}
@TestTargets({
@@ -432,22 +442,21 @@
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- recordMedia(MAX_FILE_SIZE);
+ recordMedia(MAX_FILE_SIZE, mOutFile);
// TODO: how can we trigger a recording error?
assertFalse(mOnErrorCalled);
}
- private void recordMedia(long maxFileSize) throws Exception {
+ private void recordMedia(long maxFileSize, File outFile) throws Exception {
mMediaRecorder.setMaxFileSize(maxFileSize);
mMediaRecorder.prepare();
mMediaRecorder.start();
Thread.sleep(RECORD_TIME);
mMediaRecorder.stop();
- assertTrue(mOutFile.exists());
+ assertTrue(outFile.exists());
// The max file size is always guaranteed.
// We just make sure that the margin is not too big
- assertTrue(mOutFile.length() < 1.1 * maxFileSize);
- assertTrue(mOutFile.length() > 0);
+ assertTrue(outFile.length() < 1.1 * maxFileSize);
+ assertTrue(outFile.length() > 0);
}
-
}
diff --git a/tests/tests/ndef/Android.mk b/tests/tests/ndef/Android.mk
new file mode 100644
index 0000000..4cb0b78
--- /dev/null
+++ b/tests/tests/ndef/Android.mk
@@ -0,0 +1,34 @@
+# Copyright (C) 2011 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := CtsNdefTestCases
+
+# Don't include this package in any target.
+LOCAL_MODULE_TAGS := optional
+
+# When built, explicitly put it in the data partition.
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+# All tests should include android.test.runner.
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/ndef/AndroidManifest.xml b/tests/tests/ndef/AndroidManifest.xml
new file mode 100644
index 0000000..4a65818
--- /dev/null
+++ b/tests/tests/ndef/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.cts.ndef">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!-- This is a self-instrumenting test package. -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.cts.ndef"
+ android:label="CTS tests of NDEF data classes"/>
+
+</manifest>
+
diff --git a/tests/tests/ndef/src/android/ndef/cts/BasicNdefTest.java b/tests/tests/ndef/src/android/ndef/cts/BasicNdefTest.java
new file mode 100644
index 0000000..6e2ac3c
--- /dev/null
+++ b/tests/tests/ndef/src/android/ndef/cts/BasicNdefTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2011 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.ndef.cts;
+
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.FormatException;
+
+import junit.framework.TestCase;
+
+public class BasicNdefTest extends TestCase {
+ /**
+ * A Smart Poster containing a URL and no text.
+ */
+ public static final byte[] SMART_POSTER_URL_NO_TEXT = new byte[] {
+ (byte) 0xd1, (byte) 0x02, (byte) 0x0f, (byte) 0x53, (byte) 0x70, (byte) 0xd1,
+ (byte) 0x01, (byte) 0x0b, (byte) 0x55, (byte) 0x01, (byte) 0x67, (byte) 0x6f,
+ (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x2e, (byte) 0x63,
+ (byte) 0x6f, (byte) 0x6d
+ };
+
+ public void test_parseSmartPoster() throws FormatException {
+ NdefMessage msg = new NdefMessage(SMART_POSTER_URL_NO_TEXT);
+ NdefRecord[] records = msg.getRecords();
+
+ assertEquals(1, records.length);
+
+ assertEquals(0, records[0].getId().length);
+
+ assertEquals(NdefRecord.TNF_WELL_KNOWN, records[0].getTnf());
+
+ assertByteArrayEquals(NdefRecord.RTD_SMART_POSTER, records[0].getType());
+
+ assertByteArrayEquals(new byte[] {
+ (byte) 0xd1, (byte) 0x01, (byte) 0x0b, (byte) 0x55, (byte) 0x01,
+ (byte) 0x67, (byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c,
+ (byte) 0x65, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d},
+ records[0].getPayload());
+ }
+
+ private static void assertByteArrayEquals(byte[] b1, byte[] b2) {
+ assertEquals(b1.length, b2.length);
+ for (int i = 0; i < b1.length; i++) {
+ assertEquals(b1[i], b2[i]);
+ }
+ }
+}
diff --git a/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java
index b69bffd..3751b3c 100644
--- a/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -22,27 +22,46 @@
import dalvik.annotation.TestTargets;
import dalvik.annotation.ToBeFixed;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkInfo.State;
+import android.net.wifi.WifiManager;
import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
@TestTargetClass(ConnectivityManager.class)
public class ConnectivityManagerTest extends AndroidTestCase {
+ private static final String TAG = ConnectivityManagerTest.class.getSimpleName();
+
+ private static final String FEATURE_ENABLE_HIPRI = "enableHIPRI";
+
public static final int TYPE_MOBILE = ConnectivityManager.TYPE_MOBILE;
public static final int TYPE_WIFI = ConnectivityManager.TYPE_WIFI;
private static final int HOST_ADDRESS = 0x7f000001;// represent ip 127.0.0.1
- private ConnectivityManager mCm;
+
// device could have only one interface: data, wifi.
private static final int MIN_NUM_NETWORK_TYPES = 1;
+ private ConnectivityManager mCm;
+ private WifiManager mWifiManager;
+ private PackageManager mPackageManager;
+
@Override
protected void setUp() throws Exception {
super.setUp();
mCm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
+ mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+ mPackageManager = getContext().getPackageManager();
}
@TestTargetNew(
@@ -185,4 +204,91 @@
public void testTest() {
mCm.getBackgroundDataSetting();
}
+
+ /** Test that hipri can be brought up when Wifi is enabled. */
+ public void testStartUsingNetworkFeature_enableHipri() throws Exception {
+ if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
+ || !mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)) {
+ // This test requires a mobile data connection and WiFi.
+ return;
+ }
+
+ boolean isWifiConnected = mWifiManager.isWifiEnabled()
+ && mWifiManager.getConnectionInfo().getSSID() != null;
+
+ try {
+ // Make sure WiFi is connected to an access point.
+ if (!isWifiConnected) {
+ connectToWifi();
+ }
+
+ // Register a receiver that will capture the connectivity change for hipri.
+ ConnectivityActionReceiver receiver =
+ new ConnectivityActionReceiver(ConnectivityManager.TYPE_MOBILE_HIPRI);
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ mContext.registerReceiver(receiver, filter);
+
+ // Try to start using the hipri feature...
+ int result = mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+ FEATURE_ENABLE_HIPRI);
+ assertTrue("Couldn't start using the HIPRI feature.", result != -1);
+
+ // Check that the ConnectivityManager reported that it connected using hipri...
+ assertTrue("Couldn't connect using hipri...", receiver.waitForConnection());
+
+ assertTrue("Couldn't requestRouteToHost using HIPRI.",
+ mCm.requestRouteToHost(ConnectivityManager.TYPE_MOBILE_HIPRI, HOST_ADDRESS));
+
+ } catch (InterruptedException e) {
+ fail("Broadcast receiver waiting for ConnectivityManager interrupted.");
+ } finally {
+ mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+ FEATURE_ENABLE_HIPRI);
+ if (!isWifiConnected) {
+ mWifiManager.setWifiEnabled(false);
+ }
+ }
+ }
+
+ private void connectToWifi() throws InterruptedException {
+ ConnectivityActionReceiver receiver =
+ new ConnectivityActionReceiver(ConnectivityManager.TYPE_WIFI);
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ mContext.registerReceiver(receiver, filter);
+
+ assertTrue(mWifiManager.setWifiEnabled(true));
+ assertTrue("Wifi must be configured to connect to an access point for this test.",
+ receiver.waitForConnection());
+
+ mContext.unregisterReceiver(receiver);
+ }
+
+ /** Receiver that captures the last connectivity change's network type and state. */
+ private class ConnectivityActionReceiver extends BroadcastReceiver {
+
+ private final CountDownLatch mReceiveLatch = new CountDownLatch(1);
+
+ private final int mNetworkType;
+
+ ConnectivityActionReceiver(int networkType) {
+ mNetworkType = networkType;
+ }
+
+ public void onReceive(Context context, Intent intent) {
+ NetworkInfo networkInfo = intent.getExtras()
+ .getParcelable(ConnectivityManager.EXTRA_NETWORK_INFO);
+ int networkType = networkInfo.getType();
+ State networkState = networkInfo.getState();
+ Log.i(TAG, "Network type: " + networkType + " state: " + networkState);
+ if (networkType == mNetworkType && networkInfo.getState() == State.CONNECTED) {
+ mReceiveLatch.countDown();
+ }
+ }
+
+ public boolean waitForConnection() throws InterruptedException {
+ return mReceiveLatch.await(10, TimeUnit.SECONDS);
+ }
+ }
}
diff --git a/tests/tests/os/src/android/os/cts/BuildTest.java b/tests/tests/os/src/android/os/cts/BuildTest.java
index a0b0459..ec3f49a 100644
--- a/tests/tests/os/src/android/os/cts/BuildTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildTest.java
@@ -106,14 +106,56 @@
}
}
+ private static final Pattern BOARD_PATTERN =
+ Pattern.compile("^([0-9A-Za-z._-]+)$");
+ private static final Pattern BRAND_PATTERN =
+ Pattern.compile("^([0-9A-Za-z._-]+)$");
private static final Pattern DEVICE_PATTERN =
- Pattern.compile("^([0-9A-Za-z_-]+)$");
+ Pattern.compile("^([0-9A-Za-z._-]+)$");
+ private static final Pattern ID_PATTERN =
+ Pattern.compile("^([0-9A-Za-z._-]+)$");
+ private static final Pattern PRODUCT_PATTERN =
+ Pattern.compile("^([0-9A-Za-z._-]+)$");
private static final Pattern SERIAL_NUMBER_PATTERN =
Pattern.compile("^([0-9A-Za-z]{0,20})$");
+ private static final Pattern TAGS_PATTERN =
+ Pattern.compile("^([0-9A-Za-z.,_-]+)$");
+ private static final Pattern TYPE_PATTERN =
+ Pattern.compile("^([0-9A-Za-z._-]+)$");
/** Tests that check for valid values of constants in Build. */
public void testBuildConstants() {
- assertTrue(SERIAL_NUMBER_PATTERN.matcher(Build.SERIAL).matches());
+ // Build.VERSION.* constants tested by BuildVersionTest
+
+ assertTrue(BOARD_PATTERN.matcher(Build.BOARD).matches());
+
+ assertTrue(BRAND_PATTERN.matcher(Build.BRAND).matches());
+
assertTrue(DEVICE_PATTERN.matcher(Build.DEVICE).matches());
+
+ // Build.FINGERPRINT tested by BuildVersionTest
+
+ assertNotEmpty(Build.HOST);
+
+ assertTrue(ID_PATTERN.matcher(Build.ID).matches());
+
+ assertNotEmpty(Build.MODEL);
+
+ assertTrue(PRODUCT_PATTERN.matcher(Build.PRODUCT).matches());
+
+ assertTrue(SERIAL_NUMBER_PATTERN.matcher(Build.SERIAL).matches());
+
+ assertTrue(TAGS_PATTERN.matcher(Build.TAGS).matches());
+
+ // No format requirements stated in CDD for Build.TIME
+
+ assertTrue(TYPE_PATTERN.matcher(Build.TYPE).matches());
+
+ assertNotEmpty(Build.USER);
+ }
+
+ private void assertNotEmpty(String value) {
+ assertNotNull(value);
+ assertFalse(value.isEmpty());
}
}
diff --git a/tests/tests/os/src/android/os/cts/BuildVersionTest.java b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
index 76be1bc..2ef5167 100644
--- a/tests/tests/os/src/android/os/cts/BuildVersionTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
@@ -45,6 +45,10 @@
assertEquals(EXPECTED_SDK, Build.VERSION.SDK_INT);
}
+ public void testIncremental() {
+ assertNotEmpty(Build.VERSION.INCREMENTAL);
+ }
+
/**
* Verifies {@link Build.FINGERPRINT} follows expected format:
* <p/>
@@ -75,4 +79,9 @@
// no strict requirement for TAGS
//assertEquals(Build.TAGS, fingerprintSegs[5]);
}
+
+ private void assertNotEmpty(String value) {
+ assertNotNull(value);
+ assertFalse(value.isEmpty());
+ }
}
diff --git a/tests/tests/permission/src/android/permission/cts/NoExecutePermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoExecutePermissionTest.java
new file mode 100644
index 0000000..5c0a4c3
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoExecutePermissionTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 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.permission.cts;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+import junit.framework.TestCase;
+
+/**
+ * {@link TestCase} that checks that the NX (No Execute) feature is enabled. This feature makes it
+ * harder to perform attacks against Android by marking certain data blocks as non-executable.
+ */
+public class NoExecutePermissionTest extends TestCase {
+
+ public void testNoExecutePermission() throws FileNotFoundException {
+ String heapPermissions = null;
+ String stackPermissions = null;
+
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(new File("/proc/self/maps"));
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine().trim();
+ String[] fields = line.split("\\s+");
+
+ // Sample line:
+ // 0001d000-00024000 rw-p 00000000 00:00 0 [heap]
+ if (fields != null && fields.length >= 1) {
+ String permissions = fields[1];
+ if (fields.length >= 6) {
+ String tag = fields[5];
+ if ("[heap]".equals(tag)) {
+ heapPermissions = permissions;
+ } else if ("[stack]".equals(tag)) {
+ stackPermissions = permissions;
+ }
+ }
+ }
+ }
+ } finally {
+ if (scanner != null) {
+ scanner.close();
+ }
+ }
+
+ assertEquals("NX (No Execute) not enabled for heap", "rw-p", heapPermissions);
+ assertEquals("NX (No Execute) not enabled for stack", "rw-p", stackPermissions);
+ }
+}
diff --git a/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java b/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java
index 732e75d..d8d6baa 100644
--- a/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java
+++ b/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java
@@ -33,6 +33,7 @@
import android.os.RemoteException;
import android.provider.Contacts;
import android.provider.Contacts.Groups;
+import android.provider.Contacts.GroupsColumns;
import android.provider.Contacts.People;
import android.test.InstrumentationTestCase;
@@ -148,6 +149,11 @@
public void testAddToGroup() {
Cursor cursor;
try {
+ // Add the My Contacts group, since it is no longer automatically created.
+ ContentValues testValues = new ContentValues();
+ testValues.put(GroupsColumns.SYSTEM_ID, Groups.GROUP_MY_CONTACTS);
+ mProvider.insert(Groups.CONTENT_URI, testValues);
+
// People: test_people_0, Group: Groups.GROUP_MY_CONTACTS
cursor = mProvider.query(mPeopleRowsAdded.get(0), PEOPLE_PROJECTION,
null, null, null);
diff --git a/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java b/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java
index 8c02419..13a32d6 100644
--- a/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java
+++ b/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java
@@ -23,6 +23,7 @@
import android.content.ContentResolver;
import android.net.Uri;
+import android.provider.Settings;
import android.provider.Settings.Secure;
import android.provider.Settings.SettingNotFoundException;
import android.test.AndroidTestCase;
@@ -177,4 +178,9 @@
assertNotNull(uri);
assertEquals(Uri.withAppendedPath(Secure.CONTENT_URI, name), uri);
}
+
+ public void testUnknownSourcesOffByDefault() throws SettingNotFoundException {
+ assertEquals("Device should not ship with 'Unknown Sources' enabled by default.",
+ 0, Secure.getInt(cr, Settings.Secure.INSTALL_NON_MARKET_APPS));
+ }
}
diff --git a/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
old mode 100644
new mode 100755
index 65e1b63..f8f2146
--- a/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
@@ -58,7 +58,23 @@
// List of network operators that don't support SMS delivery report
private static final List<String> NO_DELIVERY_REPORTS =
Arrays.asList(
- "310410" // AT&T Mobility
+ "310410", // AT&T Mobility
+ "44010", // NTT DOCOMO
+ "45005", // SKT Mobility
+ "45002", // SKT Mobility
+ "45008" // KT Mobility
+ );
+
+ // List of network operators that doesn't support Data(binary) SMS message
+ private static final List<String> UNSUPPORT_DATA_SMS_MESSAGES =
+ Arrays.asList(
+ "44010" // NTT DOCOMO
+ );
+
+ // List of network operators that doesn't support Maltipart SMS message
+ private static final List<String> UNSUPPORT_MULTIPART_SMS_MESSAGES =
+ Arrays.asList(
+ "44010" // NTT DOCOMO
);
private TelephonyManager mTelephonyManager;
@@ -73,7 +89,7 @@
private Intent mDeliveryIntent;
private boolean mDeliveryReportSupported;
- private static final int TIME_OUT = 1000 * 60 * 4;
+ private static final int TIME_OUT = 1000 * 60 * 5;
@Override
protected void setUp() throws Exception {
@@ -89,9 +105,6 @@
} else if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
// CDMA supports SMS delivery report
mDeliveryReportSupported = true;
- } else if (mTelephonyManager.getDeviceId().equals("000000000000000")) {
- // emulator doesn't support SMS delivery report
- mDeliveryReportSupported = false;
} else {
// is this a GSM network that doesn't support SMS delivery report?
String mccmnc = mTelephonyManager.getSimOperator();
@@ -136,6 +149,8 @@
return;
}
+ String mccmnc = mTelephonyManager.getSimOperator();
+
mSendIntent = new Intent(SMS_SEND_ACTION);
mDeliveryIntent = new Intent(SMS_DELIVERY_ACTION);
@@ -162,30 +177,40 @@
}
// send data sms
- byte[] data = mText.getBytes();
- short port = 19989;
+ if (!UNSUPPORT_DATA_SMS_MESSAGES.contains(mccmnc)) {
+ byte[] data = mText.getBytes();
+ short port = 19989;
- init();
- sendDataMessage(mDestAddr, port, data, mSentIntent, mDeliveredIntent);
- assertTrue(mSendReceiver.waitForCalls(1, TIME_OUT));
- if (mDeliveryReportSupported) {
- assertTrue(mDeliveryReceiver.waitForCalls(1, TIME_OUT));
+ init();
+ sendDataMessage(mDestAddr, port, data, mSentIntent, mDeliveredIntent);
+ assertTrue(mSendReceiver.waitForCalls(1, TIME_OUT));
+ if (mDeliveryReportSupported) {
+ assertTrue(mDeliveryReceiver.waitForCalls(1, TIME_OUT));
+ }
+ } else {
+ // This GSM network doesn't support Data(binary) SMS message.
+ // Skip the test.
}
// send multi parts text sms
- init();
- ArrayList<String> parts = divideMessage(LONG_TEXT);
- int numParts = parts.size();
- ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
- ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
- for (int i = 0; i < numParts; i++) {
- sentIntents.add(PendingIntent.getBroadcast(getContext(), 0, mSendIntent, 0));
- deliveryIntents.add(PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, 0));
- }
- sendMultiPartTextMessage(mDestAddr, parts, sentIntents, deliveryIntents);
- assertTrue(mSendReceiver.waitForCalls(numParts, TIME_OUT));
- if (mDeliveryReportSupported) {
- assertTrue(mDeliveryReceiver.waitForCalls(numParts, TIME_OUT));
+ if (!UNSUPPORT_MULTIPART_SMS_MESSAGES.contains(mccmnc)) {
+ init();
+ ArrayList<String> parts = divideMessage(LONG_TEXT);
+ int numParts = parts.size();
+ ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
+ ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
+ for (int i = 0; i < numParts; i++) {
+ sentIntents.add(PendingIntent.getBroadcast(getContext(), 0, mSendIntent, 0));
+ deliveryIntents.add(PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, 0));
+ }
+ sendMultiPartTextMessage(mDestAddr, parts, sentIntents, deliveryIntents);
+ assertTrue(mSendReceiver.waitForCalls(numParts, TIME_OUT));
+ if (mDeliveryReportSupported) {
+ assertTrue(mDeliveryReceiver.waitForCalls(numParts, TIME_OUT));
+ }
+ } else {
+ // This GSM network doesn't support Multipart SMS message.
+ // Skip the test.
}
}
diff --git a/tests/tests/text/src/android/text/cts/TextUtilsTest.java b/tests/tests/text/src/android/text/cts/TextUtilsTest.java
old mode 100644
new mode 100755
index b432c1d..99f4f40
--- a/tests/tests/text/src/android/text/cts/TextUtilsTest.java
+++ b/tests/tests/text/src/android/text/cts/TextUtilsTest.java
@@ -98,7 +98,7 @@
// issue 1688347, the expected result for this case does not be described
// in the javadoc of commaEllipsize().
assertEquals("",
- TextUtils.commaEllipsize(text, p, textWidth - 1, "plus 1", "%d plus").toString());
+ TextUtils.commaEllipsize(text, p, textWidth - 1.4f, "plus 1", "%d plus").toString());
// avail is long enough for only one item plus the appropriate ellipsis.
assertEquals("long, 3 plus",
TextUtils.commaEllipsize(text, p, textWidth, "plus 1", "%d plus").toString());
diff --git a/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java
index 225c4b4..daaedf4 100644
--- a/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/DateTimeKeyListenerTest.java
@@ -28,6 +28,7 @@
import android.test.ActivityInstrumentationTestCase2;
import android.text.InputType;
import android.text.method.DateTimeKeyListener;
+import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.widget.TextView;
@@ -107,12 +108,15 @@
* Scenario description:
* 1. Press '1' key and check if the content of TextView becomes "1"
* 2. Press '2' key and check if the content of TextView becomes "12"
- * 3. Press 'a' key and check if the content of TextView becomes "12a"
- * 4. Press an unaccepted key if it exists. and this key will not be accepted.
- * 5. remove DateKeyListener and Press '1' key, this key will not be accepted
+ * 3. Press 'a' key if it is producible
+ * 4. Press 'p' key if it is producible
+ * 5. Press 'm' key if it is producible
+ * 6. Press an unaccepted key if it exists. and this key will not be accepted.
+ * 7. Remove DateKeyListener and Press '1' key, this key will not be accepted
*/
public void testDateTimeKeyListener() {
final DateTimeKeyListener dateTimeKeyListener = DateTimeKeyListener.getInstance();
+ String expectedText = "";
mActivity.runOnUiThread(new Runnable() {
public void run() {
@@ -121,25 +125,45 @@
}
});
mInstrumentation.waitForIdleSync();
- assertEquals("", mTextView.getText().toString());
+ assertEquals(expectedText, mTextView.getText().toString());
// press '1' key.
mInstrumentation.sendStringSync("1");
- assertEquals("1", mTextView.getText().toString());
+ expectedText += "1";
+ assertEquals(expectedText, mTextView.getText().toString());
// press '2' key.
mInstrumentation.sendStringSync("2");
- assertEquals("12", mTextView.getText().toString());
+ expectedText += "2";
+ assertEquals(expectedText, mTextView.getText().toString());
- // press 'a' key.
- mInstrumentation.sendStringSync("a");
- assertEquals("12a", mTextView.getText().toString());
+ // press 'a' key if producible
+ KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+ if ('a' == kcm.getMatch(KeyEvent.KEYCODE_A, DateTimeKeyListener.CHARACTERS)) {
+ expectedText += "a";
+ mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_A);
+ assertEquals(expectedText, mTextView.getText().toString());
+ }
+
+ // press 'p' key if producible
+ if ('p' == kcm.getMatch(KeyEvent.KEYCODE_P, DateTimeKeyListener.CHARACTERS)) {
+ expectedText += "p";
+ mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_P);
+ assertEquals(expectedText, mTextView.getText().toString());
+ }
+
+ // press 'm' key if producible
+ if ('m' == kcm.getMatch(KeyEvent.KEYCODE_M, DateTimeKeyListener.CHARACTERS)) {
+ expectedText += "m";
+ mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_M);
+ assertEquals(expectedText, mTextView.getText().toString());
+ }
// press an unaccepted key if it exists.
int keyCode = TextMethodUtils.getUnacceptedKeyCode(DateTimeKeyListener.CHARACTERS);
if (-1 != keyCode) {
sendKeys(keyCode);
- assertEquals("12a", mTextView.getText().toString());
+ assertEquals(expectedText, mTextView.getText().toString());
}
// remove DateTimeKeyListener
@@ -150,10 +174,10 @@
}
});
mInstrumentation.waitForIdleSync();
- assertEquals("12a", mTextView.getText().toString());
+ assertEquals(expectedText, mTextView.getText().toString());
mInstrumentation.sendStringSync("1");
- assertEquals("12a", mTextView.getText().toString());
+ assertEquals(expectedText, mTextView.getText().toString());
}
private class MyDateTimeKeyListener extends DateTimeKeyListener {
diff --git a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
old mode 100644
new mode 100755
index 175047e..d9bf6d9
--- a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
@@ -176,8 +176,7 @@
callOnKeyDown(keyListener, KeyEvent.KEYCODE_1, 1);
assertEquals("Hi.", mTextView.getText().toString());
- callOnKeyDown(keyListener, KeyEvent.KEYCODE_POUND, 1);
- assertEquals("Hi. ", mTextView.getText().toString());
+ addSpace();
callOnKeyDown(keyListener, KeyEvent.KEYCODE_2, 2);
assertEquals("Hi. B", mTextView.getText().toString());
@@ -201,8 +200,7 @@
callOnKeyDown(keyListener, KeyEvent.KEYCODE_4, 3);
assertEquals("Hi", mTextView.getText().toString());
- callOnKeyDown(keyListener, KeyEvent.KEYCODE_POUND, 1);
- assertEquals("Hi ", mTextView.getText().toString());
+ addSpace();
callOnKeyDown(keyListener, KeyEvent.KEYCODE_2, 2);
assertEquals("Hi B", mTextView.getText().toString());
@@ -245,6 +243,15 @@
}
}
+ private void addSpace() {
+ mActivity.runOnUiThread(new Runnable() {
+ public void run() {
+ mTextView.append(" ");
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+ }
+
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "getInstance",
diff --git a/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java
index 5c0b9f1..d9242c5 100644
--- a/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/NumberKeyListenerTest.java
@@ -37,9 +37,11 @@
import android.widget.TextView;
import android.widget.TextView.BufferType;
+
@TestTargetClass(NumberKeyListener.class)
public class NumberKeyListenerTest extends
ActivityInstrumentationTestCase2<KeyListenerStubActivity> {
+
private MockNumberKeyListener mNumberKeyListener;
private Activity mActivity;
private Instrumentation mInstrumentation;
@@ -74,7 +76,7 @@
@ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete, " +
"should add NPE description in javadoc.")
public void testFilter() {
- mNumberKeyListener = new MockNumberKeyListener();
+ mNumberKeyListener = new MockNumberKeyListener(MockNumberKeyListener.DIGITS);
String source = "Android test";
SpannableString dest = new SpannableString("012345");
assertEquals("", mNumberKeyListener.filter(source, 0, source.length(),
@@ -122,12 +124,12 @@
)
@ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete.")
public void testLookup() {
- mNumberKeyListener = new MockNumberKeyListener();
-
+ mNumberKeyListener = new MockNumberKeyListener(MockNumberKeyListener.DIGITS);
KeyEvent event1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0);
SpannableString str = new SpannableString("012345");
assertEquals('0', mNumberKeyListener.lookup(event1, str));
+ mNumberKeyListener = new MockNumberKeyListener(MockNumberKeyListener.NOTHING);
KeyEvent event2 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A);
str = new SpannableString("ABCD");
assertEquals('\0', mNumberKeyListener.lookup(event2, str));
@@ -147,7 +149,7 @@
)
@ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete.")
public void testOk() {
- mNumberKeyListener = new MockNumberKeyListener();
+ mNumberKeyListener = new MockNumberKeyListener(MockNumberKeyListener.DIGITS);
assertTrue(mNumberKeyListener.callOk(mNumberKeyListener.getAcceptedChars(), '3'));
assertFalse(mNumberKeyListener.callOk(mNumberKeyListener.getAcceptedChars(), 'e'));
@@ -172,7 +174,8 @@
)
public void testPressKey() {
final CharSequence text = "123456";
- final MockNumberKeyListener numberKeyListener = new MockNumberKeyListener();
+ final MockNumberKeyListener numberKeyListener =
+ new MockNumberKeyListener(MockNumberKeyListener.DIGITS);
mActivity.runOnUiThread(new Runnable() {
public void run() {
@@ -189,7 +192,7 @@
assertEquals("0123456", mTextView.getText().toString());
// an unaccepted key if it exists.
- int keyCode = TextMethodUtils.getUnacceptedKeyCode(MockNumberKeyListener.CHARACTERS);
+ int keyCode = TextMethodUtils.getUnacceptedKeyCode(MockNumberKeyListener.DIGITS);
if (-1 != keyCode) {
sendKeys(keyCode);
// text of TextView will not be changed.
@@ -209,12 +212,21 @@
}
private static class MockNumberKeyListener extends NumberKeyListener {
- static final char[] CHARACTERS = new char[] {'0', '1', '2',
- '3', '4', '5', '6', '7', '8', '9'};
+
+ static final char[] DIGITS =
+ new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+
+ static final char[] NOTHING = new char[0];
+
+ private final char[] mAcceptedChars;
+
+ MockNumberKeyListener(char[] acceptedChars) {
+ this.mAcceptedChars = acceptedChars;
+ }
@Override
protected char[] getAcceptedChars() {
- return CHARACTERS;
+ return mAcceptedChars;
}
@Override
diff --git a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
old mode 100644
new mode 100755
index 6058cdd..b751b32
--- a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
@@ -28,6 +28,7 @@
import android.test.ActivityInstrumentationTestCase2;
import android.text.Editable;
import android.text.method.PasswordTransformationMethod;
+import android.view.KeyCharacterMap;
import android.view.View;
import android.view.animation.cts.DelayedCheck;
import android.widget.Button;
@@ -145,7 +146,16 @@
});
mMethod.reset();
- sendKeys("H E 2*L O");
+ // 12-key support
+ KeyCharacterMap keymap
+ = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+ if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+ // "HELLO" in case of 12-key(NUMERIC) keyboard
+ sendKeys("6*4 6*3 7*5 DPAD_RIGHT 7*5 7*6 DPAD_RIGHT");
+ }
+ else {
+ sendKeys("H E 2*L O");
+ }
assertTrue(mMethod.hasCalledBeforeTextChanged());
assertTrue(mMethod.hasCalledOnTextChanged());
assertTrue(mMethod.hasCalledAfterTextChanged());
diff --git a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
old mode 100644
new mode 100755
index cdb1409..78ebfa4
--- a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
@@ -187,7 +187,7 @@
}
}));
assertTrue(mTextView.getScrollX() > previousScrollX);
- assertEquals(rightMost, mTextView.getScrollX(), 0f);
+ assertEquals(rightMost, mTextView.getScrollX(), 1.0f);
previousScrollX = mTextView.getScrollX();
assertTrue(getActionResult(new ActionRunnerWithResult() {
diff --git a/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java
index 278af6b..8062adf 100644
--- a/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/TimeKeyListenerTest.java
@@ -27,6 +27,7 @@
import android.test.ActivityInstrumentationTestCase2;
import android.text.InputType;
import android.text.method.TimeKeyListener;
+import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.widget.TextView;
@@ -100,13 +101,15 @@
* Scenario description:
* 1. Press '1' key and check if the content of TextView becomes "1"
* 2. Press '2' key and check if the content of TextView becomes "12"
- * 3. Press 'a' key and check if the content of TextView becomes "12a"
- * 4. Press an unaccepted key if it exists and this key could not be entered.
- * 5. Press 'm' key and check if the content of TextView becomes "12am"
- * 6. remove TimeKeyListener, '1' key will not be accepted.
+ * 3. Press 'a' key if it is producible
+ * 4. Press 'p' key if it is producible
+ * 5. Press 'm' key if it is producible
+ * 6. Press an unaccepted key if it exists and this key could not be entered.
+ * 7. Remove TimeKeyListener, '1' key will not be accepted.
*/
public void testTimeKeyListener() {
final TimeKeyListener timeKeyListener = TimeKeyListener.getInstance();
+ String expectedText = "";
mActivity.runOnUiThread(new Runnable() {
public void run() {
@@ -115,31 +118,47 @@
}
});
mInstrumentation.waitForIdleSync();
- assertEquals("", mTextView.getText().toString());
+ assertEquals(expectedText, mTextView.getText().toString());
// press '1' key.
mInstrumentation.sendStringSync("1");
- assertEquals("1", mTextView.getText().toString());
+ expectedText += "1";
+ assertEquals(expectedText, mTextView.getText().toString());
// press '2' key.
mInstrumentation.sendStringSync("2");
+ expectedText += "2";
assertEquals("12", mTextView.getText().toString());
- // press 'a' key.
- mInstrumentation.sendStringSync("a");
- assertEquals("12a", mTextView.getText().toString());
+ // press 'a' key if producible
+ KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+ if ('a' == kcm.getMatch(KeyEvent.KEYCODE_A, TimeKeyListener.CHARACTERS)) {
+ expectedText += "a";
+ mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_A);
+ assertEquals(expectedText, mTextView.getText().toString());
+ }
+
+ // press 'p' key if producible
+ if ('p' == kcm.getMatch(KeyEvent.KEYCODE_P, TimeKeyListener.CHARACTERS)) {
+ expectedText += "p";
+ mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_P);
+ assertEquals(expectedText, mTextView.getText().toString());
+ }
+
+ // press 'm' key if producible
+ if ('m' == kcm.getMatch(KeyEvent.KEYCODE_M, TimeKeyListener.CHARACTERS)) {
+ expectedText += "m";
+ mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_M);
+ assertEquals(expectedText, mTextView.getText().toString());
+ }
// press an unaccepted key if it exists.
int keyCode = TextMethodUtils.getUnacceptedKeyCode(TimeKeyListener.CHARACTERS);
if (-1 != keyCode) {
sendKeys(keyCode);
- assertEquals("12a", mTextView.getText().toString());
+ assertEquals(expectedText, mTextView.getText().toString());
}
- // press 'm' key.
- mInstrumentation.sendStringSync("m");
- assertEquals("12am", mTextView.getText().toString());
-
mActivity.runOnUiThread(new Runnable() {
public void run() {
mTextView.setKeyListener(null);
@@ -150,7 +169,7 @@
// press '1' key.
mInstrumentation.sendStringSync("1");
- assertEquals("12am", mTextView.getText().toString());
+ assertEquals(expectedText, mTextView.getText().toString());
}
private class MyTimeKeyListener extends TimeKeyListener {
diff --git a/tests/tests/text/src/android/text/method/cts/TouchTest.java b/tests/tests/text/src/android/text/method/cts/TouchTest.java
old mode 100644
new mode 100755
index 22a5515..03e5835
--- a/tests/tests/text/src/android/text/method/cts/TouchTest.java
+++ b/tests/tests/text/src/android/text/method/cts/TouchTest.java
@@ -99,7 +99,7 @@
}
});
getInstrumentation().waitForIdleSync();
- assertEquals(width - tv.getWidth(), tv.getScrollX());
+ assertEquals(width - tv.getWidth(), tv.getScrollX(), 1.0f);
assertEquals(5, tv.getScrollY());
runTestOnUiThread(new Runnable() {
@@ -108,7 +108,7 @@
}
});
getInstrumentation().waitForIdleSync();
- assertEquals(width - tv.getWidth(), tv.getScrollX());
+ assertEquals(width - tv.getWidth(), tv.getScrollX(), 1.0f);
assertEquals(5, tv.getScrollY());
}
diff --git a/tests/tests/util/src/android/util/cts/EventLogTest.java b/tests/tests/util/src/android/util/cts/EventLogTest.java
index 43d1b02..318b010 100644
--- a/tests/tests/util/src/android/util/cts/EventLogTest.java
+++ b/tests/tests/util/src/android/util/cts/EventLogTest.java
@@ -18,9 +18,12 @@
import android.os.Process;
import android.util.EventLog;
+import android.util.EventLog.Event;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import junit.framework.TestCase;
@@ -30,13 +33,14 @@
private static final int E_TAG = 2718;
public void testWriteEvent() throws Exception {
- long t0 = getTime();
+ long markerData = System.currentTimeMillis();
+ EventLog.writeEvent(ANSWER_TAG, markerData);
EventLog.writeEvent(ANSWER_TAG, 12345);
EventLog.writeEvent(ANSWER_TAG, 23456L);
EventLog.writeEvent(ANSWER_TAG, "Test");
EventLog.writeEvent(ANSWER_TAG, 12345, 23456L, "Test");
- ArrayList<EventLog.Event> events = getEventsSince(t0, new int[] {ANSWER_TAG});
+ List<EventLog.Event> events = getEventsAfterMarker(markerData, ANSWER_TAG);
assertEquals(4, events.size());
assertEquals(ANSWER_TAG, events.get(0).getTag());
assertEquals(12345, events.get(0).getData());
@@ -57,7 +61,8 @@
Object[] longArray = new Object[1000];
for (int i = 0; i < 1000; i++) longArray[i] = 12345;
- long t0 = getTime();
+ Long markerData = System.currentTimeMillis();
+ EventLog.writeEvent(ANSWER_TAG, markerData);
EventLog.writeEvent(ANSWER_TAG, longString.toString());
EventLog.writeEvent(ANSWER_TAG, "hi", longString.toString());
EventLog.writeEvent(ANSWER_TAG, 12345, longString.toString());
@@ -65,7 +70,7 @@
EventLog.writeEvent(ANSWER_TAG, longString.toString(), longString.toString());
EventLog.writeEvent(ANSWER_TAG, longArray);
- ArrayList<EventLog.Event> events = getEventsSince(t0, new int[] {ANSWER_TAG});
+ List<Event> events = getEventsAfterMarker(markerData, ANSWER_TAG);
assertEquals(6, events.size());
// subtract: log header, type byte, final newline
@@ -105,11 +110,12 @@
}
public void testWriteNullEvent() throws Exception {
- long t0 = getTime();
+ Long markerData = System.currentTimeMillis();
+ EventLog.writeEvent(ANSWER_TAG, markerData);
EventLog.writeEvent(ANSWER_TAG, (String) null);
EventLog.writeEvent(ANSWER_TAG, 12345, (String) null);
- ArrayList<EventLog.Event> events = getEventsSince(t0, new int[] {ANSWER_TAG});
+ List<EventLog.Event> events = getEventsAfterMarker(markerData, ANSWER_TAG);
assertEquals(2, events.size());
assertEquals("NULL", events.get(0).getData());
@@ -120,31 +126,65 @@
}
public void testReadEvents() throws Exception {
- long t0 = getTime();
- EventLog.writeEvent(ANSWER_TAG, 0);
- long t1 = getTime();
- EventLog.writeEvent(PI_TAG, "1");
- long t2 = getTime();
- EventLog.writeEvent(E_TAG, 2);
- long t3 = getTime();
+ Long markerData = System.currentTimeMillis();
+ EventLog.writeEvent(ANSWER_TAG, markerData);
- // Exclude E_TAG
- ArrayList<EventLog.Event> events = getEventsSince(t0, new int[] {ANSWER_TAG, PI_TAG});
+ Long data0 = markerData + 1;
+ EventLog.writeEvent(ANSWER_TAG, data0);
+
+ Long data1 = data0 + 1;
+ EventLog.writeEvent(PI_TAG, data1);
+
+ Long data2 = data1 + 1;
+ EventLog.writeEvent(E_TAG, data2);
+
+ List<Event> events = getEventsAfterMarker(markerData, ANSWER_TAG, PI_TAG, E_TAG);
+ assertEquals(3, events.size());
+ assertEvent(events.get(0), ANSWER_TAG, data0);
+ assertEvent(events.get(1), PI_TAG, data1);
+ assertEvent(events.get(2), E_TAG, data2);
+
+ events = getEventsAfterMarker(markerData, ANSWER_TAG, E_TAG);
assertEquals(2, events.size());
+ assertEvent(events.get(0), ANSWER_TAG, data0);
+ assertEvent(events.get(1), E_TAG, data2);
- assertEquals(Process.myPid(), events.get(0).getProcessId());
- assertEquals(Process.myTid(), events.get(0).getThreadId());
- assertTrue(events.get(0).getTimeNanos() >= t0 * 1000000L);
- assertTrue(events.get(0).getTimeNanos() <= t1 * 1000000L);
- assertEquals(ANSWER_TAG, events.get(0).getTag());
- assertEquals(0, events.get(0).getData());
+ events = getEventsAfterMarker(markerData, ANSWER_TAG);
+ assertEquals(1, events.size());
+ assertEvent(events.get(0), ANSWER_TAG, data0);
+ }
- assertEquals(Process.myPid(), events.get(1).getProcessId());
- assertEquals(Process.myTid(), events.get(1).getThreadId());
- assertTrue(events.get(1).getTimeNanos() >= t1 * 1000000L);
- assertTrue(events.get(1).getTimeNanos() <= t2 * 1000000L);
- assertEquals(PI_TAG, events.get(1).getTag());
- assertEquals("1", events.get(1).getData());
+ /** Return elements after and the event that has the marker data and matching tag. */
+ private List<Event> getEventsAfterMarker(Object marker, int... tags) throws IOException {
+ List<Event> events = new ArrayList<Event>();
+ EventLog.readEvents(tags, events);
+
+ for (Iterator<Event> itr = events.iterator(); itr.hasNext(); ) {
+ Event event = itr.next();
+ itr.remove();
+ if (marker.equals(event.getData())) {
+ break;
+ }
+ }
+
+ assertEventTimes(events);
+
+ return events;
+ }
+
+ private void assertEvent(Event event, int expectedTag, Object expectedData) {
+ assertEquals(Process.myPid(), event.getProcessId());
+ assertEquals(Process.myTid(), event.getThreadId());
+ assertEquals(expectedTag, event.getTag());
+ assertEquals(expectedData, event.getData());
+ }
+
+ private void assertEventTimes(List<Event> events) {
+ for (int i = 0; i + 1 < events.size(); i++) {
+ long time = events.get(i).getTimeNanos();
+ long nextTime = events.get(i).getTimeNanos();
+ assertTrue(time <= nextTime);
+ }
}
public void testGetTagName() throws Exception {
@@ -160,23 +200,4 @@
assertEquals(E_TAG, EventLog.getTagCode("e"));
assertEquals(-1, EventLog.getTagCode("does_not_exist"));
}
-
- private long getTime() throws InterruptedException {
- // The precision of currentTimeMillis is poor compared to event timestamps
- Thread.sleep(40);
- return System.currentTimeMillis() - 20;
- }
-
- private ArrayList<EventLog.Event> getEventsSince(long since, int[] tags) throws IOException {
- ArrayList<EventLog.Event> tmp = new ArrayList<EventLog.Event>();
- EventLog.readEvents(tags, tmp);
-
- ArrayList<EventLog.Event> out = new ArrayList<EventLog.Event>();
- for (EventLog.Event event : tmp) {
- if (event.getTimeNanos() / 1000000 >= since) {
- out.add(event);
- }
- }
- return out;
- }
}
diff --git a/tests/tests/view/src/android/view/cts/TouchDelegateTest.java b/tests/tests/view/src/android/view/cts/TouchDelegateTest.java
index f82b903..0a78d1f 100644
--- a/tests/tests/view/src/android/view/cts/TouchDelegateTest.java
+++ b/tests/tests/view/src/android/view/cts/TouchDelegateTest.java
@@ -16,6 +16,11 @@
package android.view.cts;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
import android.app.Activity;
import android.app.Instrumentation;
import android.app.cts.MockActivity;
@@ -25,45 +30,22 @@
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
-import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
@TestTargetClass(TouchDelegate.class)
public class TouchDelegateTest extends ActivityInstrumentationTestCase2<MockActivity> {
private static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
private static final int ACTION_DOWN = MotionEvent.ACTION_DOWN;
- private static final int ACTION_UP = MotionEvent.ACTION_UP;
- private static final int ACTION_CANCEL = MotionEvent.ACTION_CANCEL;
- private static final int ACTION_MOVE = MotionEvent.ACTION_MOVE;
- private ViewConfiguration mViewConfig;
private Activity mActivity;
private Instrumentation mInstrumentation;
- private TouchDelegate mTouchDelegate;
private Button mButton;
private Rect mRect;
private int mXInside;
private int mYInside;
- private int mXOutside;
- private int mYOutside;
- private int mScaledTouchSlop;
-
- private MotionEvent mActionDownInside;
- private MotionEvent mActionDownOutside;
- private MotionEvent mActionUpInside;
- private MotionEvent mActionUpOutside;
- private MotionEvent mActionMoveInside;
- private MotionEvent mActionMoveOutside;
- private MotionEvent mActionCancelInside;
- private MotionEvent mActionCancelOutside;
private Exception mException;
@@ -76,7 +58,6 @@
super.setUp();
mActivity = getActivity();
mInstrumentation = getInstrumentation();
- mViewConfig = ViewConfiguration.get(mActivity);
mButton = new Button(mActivity);
mActivity.runOnUiThread(new Runnable() {
@@ -99,38 +80,11 @@
int bottom = mButton.getBottom();
mXInside = (mButton.getLeft() + right) / 3;
mYInside = (mButton.getTop() + bottom) / 3;
- mScaledTouchSlop = mViewConfig.getScaledTouchSlop() << 1;
- mXOutside = right + mScaledTouchSlop;
- mYOutside = bottom + mScaledTouchSlop;
mRect = new Rect();
mButton.getHitRect(mRect);
}
- private void init() {
- mTouchDelegate = new TouchDelegate(mRect, mButton);
-
- mActionDownInside = MotionEvent.obtain(0, 0, ACTION_DOWN, mXInside, mYInside, 0);
- mActionDownOutside = MotionEvent.obtain(0, 0, ACTION_DOWN, mXOutside, mYOutside, 0);
- mActionUpInside = MotionEvent.obtain(0, 0, ACTION_UP, mXInside, mYInside, 0);
- mActionUpOutside = MotionEvent.obtain(0, 0, ACTION_UP, mXOutside, mYOutside, 0);
- mActionMoveInside = MotionEvent.obtain(0, 0, ACTION_MOVE, mXInside, mYInside, 0);
- mActionMoveOutside = MotionEvent.obtain(0, 0, ACTION_MOVE, mXOutside, mYOutside, 0);
- mActionCancelInside = MotionEvent.obtain(0, 0, ACTION_CANCEL, mXInside, mYInside, 0);
- mActionCancelOutside = MotionEvent.obtain(0, 0, ACTION_CANCEL, mXOutside, mYOutside, 0);
- }
-
- private void clear() {
- mActionDownInside.recycle();
- mActionDownOutside.recycle();
- mActionUpInside.recycle();
- mActionUpOutside.recycle();
- mActionMoveInside.recycle();
- mActionMoveOutside.recycle();
- mActionCancelInside.recycle();
- mActionCancelOutside.recycle();
- }
-
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -154,59 +108,6 @@
assertFalse(touchDelegate.mOnTouchEventCalled);
view.onTouchEvent(MotionEvent.obtain(0, 0, ACTION_DOWN, mXInside, mYInside, 0));
assertTrue(touchDelegate.mOnTouchEventCalled);
-
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onTouchEvent",
- args = {MotionEvent.class}
- )
- @UiThreadTest
- @BrokenTest("Will fail in batch mode but can pass if only run this TestCase")
- public void testOn() {
-
- init();
- assertTrue(mTouchDelegate.onTouchEvent(mActionDownInside));
- clear();
-
- init();
- assertFalse(mTouchDelegate.onTouchEvent(mActionDownOutside));
- clear();
-
- init();
- assertTrue(mTouchDelegate.onTouchEvent(mActionDownInside));
- assertTrue(mTouchDelegate.onTouchEvent(mActionUpInside));
- clear();
-
- init();
- assertFalse(mTouchDelegate.onTouchEvent(mActionUpInside));
- clear();
-
- init();
- assertTrue(mTouchDelegate.onTouchEvent(mActionDownInside));
- assertTrue(mTouchDelegate.onTouchEvent(mActionUpOutside));
- clear();
-
- init();
- assertFalse(mTouchDelegate.onTouchEvent(mActionMoveInside));
- clear();
-
- init();
- assertTrue(mTouchDelegate.onTouchEvent(mActionDownInside));
- assertTrue(mTouchDelegate.onTouchEvent(mActionMoveInside));
- clear();
-
- init();
- assertTrue(mTouchDelegate.onTouchEvent(mActionDownInside));
- assertTrue(mTouchDelegate.onTouchEvent(mActionMoveOutside));
- clear();
-
- init();
- assertTrue(mTouchDelegate.onTouchEvent(mActionDownInside));
- assertTrue(mTouchDelegate.onTouchEvent(mActionCancelInside));
- assertFalse(mTouchDelegate.onTouchEvent(mActionUpInside));
- clear();
}
class MockTouchDelegate extends TouchDelegate {
diff --git a/tests/tests/view/src/android/view/cts/VelocityTrackerTest.java b/tests/tests/view/src/android/view/cts/VelocityTrackerTest.java
index 3ba3a9b..35254b6 100644
--- a/tests/tests/view/src/android/view/cts/VelocityTrackerTest.java
+++ b/tests/tests/view/src/android/view/cts/VelocityTrackerTest.java
@@ -96,10 +96,10 @@
VelocityTracker vt = VelocityTracker.obtain();
assertNotNull(vt);
- MotionEvent me = MotionEvent.obtain(0L, 1, 1, .0f, .0f, 0);
+ MotionEvent me = MotionEvent.obtain(0L, 10, 1, .0f, .0f, 0);
vt.clear();
- me.addBatch(2L, 2, 2, .0f, .0f, 0);
+ me.addBatch(20L, 20, 20, .0f, .0f, 0);
vt.addMovement(me);
vt.computeCurrentVelocity(1);
XVelocity = 2.0f;
@@ -112,7 +112,7 @@
assertEquals(XVelocity, vt.getXVelocity(), ERROR_TOLERANCE);
assertEquals(YVelocity, vt.getYVelocity(), ERROR_TOLERANCE);
- for (int i = 3; i < 10; i++) {
+ for (int i = 30; i < 100; i += 10) {
me.addBatch((long)i, (float)i, (float)i, .0f, .0f, 0);
}
vt.clear();
@@ -124,7 +124,7 @@
assertEquals(YVelocity, vt.getYVelocity(), ERROR_TOLERANCE);
vt.clear();
- me.addBatch(10L, 10, 10, .0f, .0f, 0);
+ me.addBatch(100L, 100, 100, .0f, .0f, 0);
vt.addMovement(me);
vt.computeCurrentVelocity(1);
XVelocity = 1.1562872f;
diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java
index f3d449b..6b5c0a1 100644
--- a/tests/tests/view/src/android/view/cts/ViewTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTest.java
@@ -2254,8 +2254,14 @@
assertFalse(view.hasWindowFocus());
// mAttachInfo is not null
- view = mActivity.findViewById(R.id.fit_windows);
- assertTrue(view.hasWindowFocus());
+ final View view2 = mActivity.findViewById(R.id.fit_windows);
+ // Wait until the window has been focused.
+ new DelayedCheck(TIMEOUT_DELTA) {
+ @Override
+ protected boolean check() {
+ return view2.hasWindowFocus();
+ }
+ }.run();
}
@TestTargetNew(
@@ -3929,6 +3935,7 @@
fitWindowsView.requestFocus();
}
});
+ getInstrumentation().waitForIdleSync();
assertTrue(mockView.isFocusableInTouchMode());
assertFalse(fitWindowsView.isFocusableInTouchMode());
assertTrue(mockView.isFocusable());
@@ -3946,12 +3953,14 @@
mockView.requestFocus();
}
});
+ getInstrumentation().waitForIdleSync();
assertTrue(mockView.isFocused());
runTestOnUiThread(new Runnable() {
public void run() {
fitWindowsView.requestFocus();
}
});
+ getInstrumentation().waitForIdleSync();
assertFalse(fitWindowsView.isFocused());
assertTrue(mockView.isInTouchMode());
assertTrue(fitWindowsView.isInTouchMode());
@@ -3965,6 +3974,7 @@
fitWindowsView.requestFocus();
}
});
+ getInstrumentation().waitForIdleSync();
assertFalse(mockView.isFocused());
assertTrue(fitWindowsView.isFocused());
assertFalse(mockView.isInTouchMode());
@@ -4410,6 +4420,14 @@
viewGroup.addView(editText);
editText.requestFocus();
+
+ new DelayedCheck(TIMEOUT_DELTA) {
+ @Override
+ protected boolean check() {
+ return editText.isFocused();
+ }
+ }.run();
+
imm.showSoftInput(editText, 0);
assertTrue(editText.hasCalledOnCreateInputConnection());
assertTrue(editText.hasCalledOnCheckIsTextEditor());
diff --git a/tests/tests/view/src/android/view/cts/WindowTest.java b/tests/tests/view/src/android/view/cts/WindowTest.java
old mode 100644
new mode 100755
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
old mode 100644
new mode 100755
index 6241a1e..72a113b
--- a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
@@ -31,6 +31,7 @@
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
+import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
@@ -347,7 +348,17 @@
}
});
- mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Q));
+ // 12-key support
+ KeyCharacterMap keymap
+ = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+ if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+ // 'Q' in case of 12-key(NUMERIC) keyboard
+ mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_7));
+ mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_7));
+ }
+ else {
+ mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Q));
+ }
new DelayedCheck() {
@Override
protected boolean check() {
diff --git a/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java
index 5e0fca5..bebb1fa 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java
@@ -32,6 +32,7 @@
@TestTargetClass(android.webkit.CacheManager.class)
public class CacheManagerTest extends ActivityInstrumentationTestCase2<WebViewStubActivity> {
+ private static final long CACHEMANAGER_INIT_TIMEOUT = 5000l;
private static final long NETWORK_OPERATION_DELAY = 10000l;
private WebView mWebView;
@@ -96,6 +97,14 @@
mWebServer = new CtsTestServer(getActivity());
final String url = mWebServer.getAssetUrl(TestHtmlConstants.EMBEDDED_IMG_URL);
+ // Wait for CacheManager#init() finish.
+ new DelayedCheck(CACHEMANAGER_INIT_TIMEOUT) {
+ @Override
+ protected boolean check() {
+ return CacheManager.getCacheFileBaseDir() != null;
+ }
+ }.run();
+
mWebView.clearCache(true);
new DelayedCheck(NETWORK_OPERATION_DELAY) {
@Override
diff --git a/tests/tests/webkit/src/android/webkit/cts/CacheManager_CacheResultTest.java b/tests/tests/webkit/src/android/webkit/cts/CacheManager_CacheResultTest.java
old mode 100644
new mode 100755
index 1a18a86..48a6a1f
--- a/tests/tests/webkit/src/android/webkit/cts/CacheManager_CacheResultTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CacheManager_CacheResultTest.java
@@ -27,6 +27,7 @@
import android.test.ActivityInstrumentationTestCase2;
import android.view.animation.cts.DelayedCheck;
import android.webkit.CacheManager;
+import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.CacheManager.CacheResult;
@@ -49,6 +50,7 @@
protected void setUp() throws Exception {
super.setUp();
mWebView = getActivity().getWebView();
+ mWebView.setWebChromeClient(new WebChromeClient());
}
@Override
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java b/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
index 016d566..71ba504 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
@@ -104,42 +104,6 @@
assertTrue(firstId != secondId);
}
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getOriginalUrl",
- args = {}
- )
- @ToBeFixed(explanation = "History item does not have the original URL set after a redirect.")
- @BrokenTest(value = "Bug 2121787: Test times out on the host side. Not 100% reproducible.")
- public void testRedirect() throws InterruptedException {
- final WebView view = getActivity().getWebView();
- view.setWebChromeClient(new WebChromeClient());
- // set the web view client so that redirects are loaded in the WebView itself
- view.setWebViewClient(new WebViewClient());
- WebBackForwardList list = view.copyBackForwardList();
- assertEquals(0, list.getSize());
-
- String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
- String redirect = mWebServer.getRedirectingAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
- assertLoadUrlSuccessfully(view, redirect);
- // wait for the redirect to take place
- new DelayedCheck(10000) {
- @Override
- protected boolean check() {
- WebBackForwardList list = view.copyBackForwardList();
- return list.getSize() >= 1;
- }
- }.run();
- list = view.copyBackForwardList();
- assertEquals(1, list.getSize());
- WebHistoryItem item = list.getCurrentItem();
- assertNotNull(item);
- assertEquals(url, item.getUrl());
- assertEquals(TestHtmlConstants.HELLO_WORLD_TITLE, item.getTitle());
- // To be fixed: item.getOriginalUrl() returns null
- // assertEquals(redirect, item.getOriginalUrl());
- }
-
private void assertLoadUrlSuccessfully(final WebView view, String url) {
view.loadUrl(url);
// wait for the page load to complete
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebIconDatabaseTest.java b/tests/tests/webkit/src/android/webkit/cts/WebIconDatabaseTest.java
deleted file mode 100644
index 64b5204..0000000
--- a/tests/tests/webkit/src/android/webkit/cts/WebIconDatabaseTest.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * 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 android.webkit.cts;
-
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import android.graphics.Bitmap;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.UiThreadTest;
-import android.view.animation.cts.DelayedCheck;
-import android.webkit.WebIconDatabase;
-import android.webkit.WebView;
-
-import java.io.File;
-
-@TestTargetClass(android.webkit.WebIconDatabase.class)
-public class WebIconDatabaseTest extends
- ActivityInstrumentationTestCase2<WebViewStubActivity> {
- private static final long ICON_FETCH_TIMEOUT = 15000;
- private static final String DATA_FOLDER = "/webkittest/";
- private String mFilePath;
- private WebView mWebView;
- private CtsTestServer mWebServer;
-
- /**
- * Instantiates a new text view test.
- */
- public WebIconDatabaseTest() {
- super("com.android.cts.stub", WebViewStubActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- WebViewStubActivity activity = (WebViewStubActivity) getActivity();
- mFilePath = activity.getFilesDir().toString() + DATA_FOLDER;
- clearDatabasePath();
-
- mWebView = activity.getWebView();
- mWebView.clearCache(true);
- }
-
- @Override
- protected void tearDown() throws Exception {
- clearDatabasePath();
- if (mWebServer != null) {
- mWebServer.shutdown();
- }
- super.tearDown();
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "open",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- })
- @BrokenTest(value="intermittently fails bug 2250024")
- public void testOpen() {
- final WebIconDatabase webIconDatabase = WebIconDatabase.getInstance();
-
- final File path = new File(mFilePath);
- // To assure no files under the directory
- assertNull(path.listFiles());
- // open() should create and open database file for storing icon related datum.
- webIconDatabase.open(mFilePath);
-
- // Need to wait for a moment, let the internal Handler complete the operation
- new DelayedCheck(10000) {
- @Override
- protected boolean check() {
- return path.listFiles() != null;
- }
- }.run();
-
- assertTrue(path.listFiles().length > 0);
-
- webIconDatabase.close();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getInstance",
- args = {}
- )
- @UiThreadTest
- public void testGetInstance() {
- WebIconDatabase webIconDatabase1 = WebIconDatabase.getInstance();
- WebIconDatabase webIconDatabase2 = WebIconDatabase.getInstance();
-
- assertSame(webIconDatabase1, webIconDatabase2);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "retainIconForPageUrl",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "requestIconForPageUrl",
- args = {String.class, WebIconDatabase.IconListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "releaseIconForPageUrl",
- args = {String.class}
- )
- })
- @BrokenTest(value="intermittently fails bug 2250024")
- public void testRetainIconForPageUrl() throws Exception {
- final WebIconDatabase webIconDatabase = WebIconDatabase.getInstance();
- webIconDatabase.open(mFilePath);
-
- mWebServer = new CtsTestServer(getActivity());
- String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
- assertLoadUrlSuccessfully(mWebView, url);
-
- MyIconListener listener = new MyIconListener();
-
- webIconDatabase.retainIconForPageUrl(url);
-
- webIconDatabase.requestIconForPageUrl(url, listener);
-
- listener.waitForIcon(ICON_FETCH_TIMEOUT);
- assertTrue(listener.hasReceivedStatus());
- assertNotNull(listener.getIcon());
-
- // release the icon.
- webIconDatabase.releaseIconForPageUrl(url);
-
- listener = new MyIconListener();
- webIconDatabase.requestIconForPageUrl(url, listener);
-
- listener.waitForIcon(ICON_FETCH_TIMEOUT);
-
- assertTrue(listener.hasReceivedStatus());
- assertNotNull(listener.getIcon());
-
- webIconDatabase.close();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "removeAllIcons",
- args = {}
- )
- @BrokenTest(value="intermittently fails bug 2250024")
- public void testRemoveAllIcons() throws Exception {
- final WebIconDatabase webIconDatabase = WebIconDatabase.getInstance();
- webIconDatabase.open(mFilePath);
-
- mWebServer = new CtsTestServer(getActivity());
- String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
- assertLoadUrlSuccessfully(mWebView, url);
-
- MyIconListener listener = new MyIconListener();
-
- webIconDatabase.retainIconForPageUrl(url);
-
- webIconDatabase.requestIconForPageUrl(url, listener);
-
- listener.waitForIcon(ICON_FETCH_TIMEOUT);
- assertTrue(listener.hasReceivedStatus());
- assertNotNull(listener.getIcon());
-
- // remove all icons.
- webIconDatabase.removeAllIcons();
-
- listener = new MyIconListener();
- webIconDatabase.requestIconForPageUrl(url, listener);
-
- listener.waitForIcon(ICON_FETCH_TIMEOUT);
-
- assertFalse(listener.hasReceivedStatus());
- assertNull(listener.getIcon());
-
- webIconDatabase.close();
- }
-
- private static class MyIconListener implements WebIconDatabase.IconListener {
- private Bitmap mIcon;
- private String mUrl;
- private boolean mHasReceivedIcon = false;
-
- public synchronized void onReceivedIcon(String url, Bitmap icon) {
- mHasReceivedIcon = true;
- mIcon = icon;
- mUrl = url;
- notifyAll();
- }
-
- public synchronized void waitForIcon(long timeout) throws InterruptedException {
- if (!mHasReceivedIcon) {
- wait(timeout);
- }
- }
-
- public boolean hasReceivedStatus() {
- return mHasReceivedIcon;
- }
-
- public Bitmap getIcon() {
- return mIcon;
- }
-
- public String getUrl() {
- return mUrl;
- }
- }
-
- private void clearDatabasePath() throws InterruptedException {
- File path = new File(mFilePath);
- if (path.exists()) {
- // FIXME: WebIconDatabase.close() is asynchronous, so some files may still be in use
- // after we return. Wait some time for the files to be closed.
- Thread.sleep(1000);
- File[] files = path.listFiles();
- if (files != null) {
- for (int i = 0; i < files.length; i++) {
- assertTrue(files[i].delete());
- }
- }
- path.delete();
- }
- }
-
- private void assertLoadUrlSuccessfully(final WebView view, String url) {
- view.loadUrl(url);
- new DelayedCheck(10000) {
- @Override
- protected boolean check() {
- return view.getProgress() == 100;
- }
- }.run();
- }
-}
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
old mode 100644
new mode 100755
index 6f62cb9..b1398ec
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -1422,39 +1422,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "clearFormData",
- args = {}
- )
- @BrokenTest(value = "Causes the process to crash some time after test completion.")
- public void testClearFormData() throws Throwable {
- String form = "<form><input type=\"text\" name=\"testClearFormData\"></form>";
- mWebView.loadData("<html><body>" + form + "</body></html>", "text/html", "UTF-8");
- waitForLoadComplete(mWebView, TEST_TIMEOUT);
- moveFocusDown();
- getInstrumentation().sendStringSync("test");
- sendKeys(KeyEvent.KEYCODE_ENTER);
-
- mWebView.reload();
- waitForLoadComplete(mWebView, TEST_TIMEOUT);
- moveFocusDown();
- View input = mWebView.findFocus();
- assertTrue(input instanceof AutoCompleteTextView);
- getInstrumentation().sendStringSync("te");
- assertTrue(((AutoCompleteTextView) input).isPopupShowing());
-
- mWebView.reload();
- waitForLoadComplete(mWebView, TEST_TIMEOUT);
- moveFocusDown();
- mWebView.clearFormData();
- // no auto completion choice after clearing
- input = mWebView.findFocus();
- assertTrue(input instanceof AutoCompleteTextView);
- getInstrumentation().sendStringSync("te");
- assertFalse(((AutoCompleteTextView) input).isPopupShowing());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
method = "getHitTestResult",
args = {}
)
@@ -1528,13 +1495,13 @@
waitForLoadComplete(mWebView, TEST_TIMEOUT);
final float defaultScale = getInstrumentation().getTargetContext().getResources().
getDisplayMetrics().density;
- assertEquals(defaultScale, mWebView.getScale(), 0f);
+ assertEquals(defaultScale, mWebView.getScale(), .01f);
mWebView.setInitialScale(0);
// modify content to fool WebKit into re-loading
mWebView.loadData("<html><body>" + p + "2" + "</body></html>", "text/html", "UTF-8");
waitForLoadComplete(mWebView, TEST_TIMEOUT);
- assertEquals(defaultScale, mWebView.getScale(), 0f);
+ assertEquals(defaultScale, mWebView.getScale(), .01f);
mWebView.setInitialScale(50);
mWebView.loadData("<html><body>" + p + "3" + "</body></html>", "text/html", "UTF-8");
@@ -1544,7 +1511,7 @@
mWebView.setInitialScale(0);
mWebView.loadData("<html><body>" + p + "4" + "</body></html>", "text/html", "UTF-8");
waitForLoadComplete(mWebView, TEST_TIMEOUT);
- assertEquals(defaultScale, mWebView.getScale(), 0f);
+ assertEquals(defaultScale, mWebView.getScale(), .01f);
}
@TestTargetNew(
@@ -1739,42 +1706,6 @@
mWebView.clearSslPreferences();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "pauseTimers",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "resumeTimers",
- args = {}
- )
- })
- @ToBeFixed(explanation = "WebView.pauseTimers() does not pause javascript timers")
- @BrokenTest(value = "Frequently crashes the process some time after test completion.")
- public void testPauseTimers() throws Exception {
- WebSettings settings = mWebView.getSettings();
- settings.setJavaScriptEnabled(true);
- startWebServer(false);
- // load a page which increments the number in its title every second
- String url = mWebServer.getAssetUrl(TestHtmlConstants.TEST_TIMER_URL);
- assertLoadUrlSuccessfully(mWebView, url);
- int counter = Integer.parseInt(mWebView.getTitle());
- Thread.sleep(2000);
- assertTrue(Integer.parseInt(mWebView.getTitle()) > counter);
- mWebView.pauseTimers();
- Thread.sleep(2000); // give the implementation time to stop the timer
- counter = Integer.parseInt(mWebView.getTitle());
- Thread.sleep(2000);
- // ToBeFixed: Uncomment the following line once pauseTimers() is fixed
- // assertEquals(counter, Integer.parseInt(mWebView.getTitle()));
- mWebView.resumeTimers();
- Thread.sleep(2000);
- assertTrue(Integer.parseInt(mWebView.getTitle()) > counter);
- }
-
-
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "requestChildRectangleOnScreen",
diff --git a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
old mode 100644
new mode 100755
index 27a285a..0f17552
--- a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
@@ -35,6 +35,7 @@
import android.test.UiThreadTest;
import android.util.AttributeSet;
import android.util.Xml;
+import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -64,6 +65,7 @@
/** The m instrumentation. */
private Instrumentation mInstrumentation;
private AutoCompleteTextView mAutoCompleteTextView;
+ private boolean mNumeric = false;
ArrayAdapter<String> mAdapter;
private final String[] WORDS = new String[] { "testOne", "testTwo", "testThree", "testFour" };
boolean isOnFilterComplete = false;
@@ -95,6 +97,11 @@
.findViewById(R.id.autocompletetv_edit);
mAdapter = new ArrayAdapter<String>(mActivity,
android.R.layout.simple_dropdown_item_1line, WORDS);
+ KeyCharacterMap keymap
+ = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+ if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+ mNumeric = true;
+ }
}
@TestTargets({
@@ -499,7 +506,13 @@
// Set Threshold to 4 characters
mAutoCompleteTextView.setThreshold(4);
- String testString = "tes";
+ String testString = "";
+ if (mNumeric) {
+ // "tes" in case of 12-key(NUMERIC) keyboard
+ testString = "8337777";
+ } else {
+ testString = "tes";
+ }
// Test the filter if the input string is not long enough to threshold
runTestOnUiThread(new Runnable() {
public void run() {
@@ -513,7 +526,12 @@
// onFilterComplete will close the popup.
assertFalse(mAutoCompleteTextView.isPopupShowing());
- testString = "that";
+ if (mNumeric) {
+ // "that" in case of 12-key(NUMERIC) keyboard
+ testString = "84428";
+ } else {
+ testString = "that";
+ }
mInstrumentation.sendStringSync(testString);
assertFalse(mAutoCompleteTextView.isPopupShowing());
@@ -525,7 +543,12 @@
mAutoCompleteTextView.setText("");
}
});
- mInstrumentation.sendStringSync("test");
+ if (mNumeric) {
+ // "test" in case of 12-key(NUMERIC) keyboard
+ mInstrumentation.sendStringSync("83377778");
+ } else {
+ mInstrumentation.sendStringSync("test");
+ }
assertTrue(mAutoCompleteTextView.hasFocus());
assertTrue(mAutoCompleteTextView.hasWindowFocus());
// give some time for UI to settle
@@ -595,10 +618,18 @@
// performFiltering will be indirectly invoked by onKeyDown
assertNull(filter.getResult());
- mInstrumentation.sendStringSync(STRING_TEST);
- // give some time for UI to settle
- Thread.sleep(100);
- assertEquals(STRING_TEST, filter.getResult());
+ // 12-key support
+ if (mNumeric) {
+ // "numeric" in case of 12-key(NUMERIC) keyboard
+ mInstrumentation.sendStringSync("6688633777444222");
+ Thread.sleep(100);
+ assertEquals("numeric", filter.getResult());
+ } else {
+ mInstrumentation.sendStringSync(STRING_TEST);
+ // give some time for UI to settle
+ Thread.sleep(100);
+ assertEquals(STRING_TEST, filter.getResult());
+ }
}
@TestTargets({
diff --git a/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java b/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
old mode 100644
new mode 100755
index 8d8e4c2..ec2a250
--- a/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
@@ -37,6 +37,7 @@
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
+import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.widget.DialerFilter;
import android.widget.EditText;
@@ -132,7 +133,16 @@
});
mInstrumentation.waitForIdleSync();
- mInstrumentation.sendStringSync("adg");
+ // 12-key support
+ KeyCharacterMap keymap
+ = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+ if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+ // "adg" in case of 12-key(NUMERIC) keyboard
+ mInstrumentation.sendStringSync("234");
+ }
+ else {
+ mInstrumentation.sendStringSync("adg");
+ }
assertEquals("ADG", mDialerFilter.getLetters().toString());
assertEquals("", mDialerFilter.getDigits().toString());
@@ -144,7 +154,14 @@
});
mInstrumentation.waitForIdleSync();
- mInstrumentation.sendStringSync("adg");
+ // 12-key support
+ if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+ // "adg" in case of 12-key(NUMERIC) keyboard
+ mInstrumentation.sendStringSync("234");
+ }
+ else {
+ mInstrumentation.sendStringSync("adg");
+ }
assertEquals("ADG", mDialerFilter.getLetters().toString());
// A, D, K may map to numbers on some keyboards. Don't test.
diff --git a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
old mode 100644
new mode 100755
index 1f8cd23..172d8a9
--- a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
+++ b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
@@ -379,8 +379,8 @@
int topDelta = rect.top - container.getTop();
int bottomDelta = container.getBottom() - rect.bottom;
- assertTrue(Math.abs(leftDelta - rightDelta) < 1);
- assertTrue(Math.abs(topDelta - bottomDelta) < 1);
+ assertTrue(Math.abs(leftDelta - rightDelta) <= 1);
+ assertTrue(Math.abs(topDelta - bottomDelta) <= 1);
}
private AttributeSet getAttributeSet() throws XmlPullParserException, IOException {
diff --git a/tests/tests/widget/src/android/widget/cts/GalleryTest.java b/tests/tests/widget/src/android/widget/cts/GalleryTest.java
index e95deb7..aea178a 100644
--- a/tests/tests/widget/src/android/widget/cts/GalleryTest.java
+++ b/tests/tests/widget/src/android/widget/cts/GalleryTest.java
@@ -19,7 +19,6 @@
import com.android.cts.stub.R;
import com.android.internal.view.menu.ContextMenuBuilder;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
@@ -34,7 +33,6 @@
import android.content.Context;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
-import android.test.TouchUtils;
import android.test.UiThreadTest;
import android.test.ViewAsserts;
import android.util.AttributeSet;
@@ -133,70 +131,6 @@
}
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setCallbackDuringFling",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onTouchEvent",
- args = {android.view.MotionEvent.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onFling",
- args = {MotionEvent.class, MotionEvent.class, float.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onDown",
- args = {android.view.MotionEvent.class}
- )
- })
- @BrokenTest("listener.isItemSelected() is false, need to investigate")
- public void testSetCallbackDuringFling() {
- MockOnItemSelectedListener listener = new MockOnItemSelectedListener();
- mGallery.setOnItemSelectedListener(listener);
-
- mGallery.setCallbackDuringFling(true);
-
- int[] xy = new int[2];
- getSelectedViewCenter(mGallery, xy);
-
- // This drags over only one item.
- TouchUtils.drag(this, xy[0], 0, xy[1], xy[1], 1);
-
- listener.reset();
- // This will drags over several items.
- TouchUtils.drag(this, xy[0], 0, xy[1], xy[1], 1);
-
- assertTrue(listener.isItemSelected());
- // onItemSelected called more than once
- assertTrue(listener.getItemSelectedCalledCount() > 1);
-
- listener.reset();
- mGallery.setCallbackDuringFling(false);
-
- TouchUtils.drag(this, xy[0], 240, xy[1], xy[1], 1);
-
- assertTrue(listener.isItemSelected());
- // onItemSelected called only once
- assertTrue(listener.getItemSelectedCalledCount() == 1);
- }
-
- private void getSelectedViewCenter(Gallery gallery, int[] xy) {
- View v = gallery.getSelectedView();
- v.getLocationOnScreen(xy);
-
- final int viewWidth = v.getWidth();
- final int viewHeight = v.getHeight();
-
- xy[1] += viewHeight / 2;
- xy[0] += viewWidth / 2;
- }
-
@TestTargetNew(
level = TestLevel.NOT_FEASIBLE,
method = "setAnimationDuration",
diff --git a/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java b/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java
index 40465ea..9f27138 100644
--- a/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/MediaControllerTest.java
@@ -18,7 +18,6 @@
import com.android.cts.stub.R;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
@@ -31,11 +30,9 @@
import android.app.Instrumentation;
import android.content.Context;
import android.test.ActivityInstrumentationTestCase2;
-import android.test.TouchUtils;
import android.test.UiThreadTest;
import android.util.AttributeSet;
import android.util.Xml;
-import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
@@ -266,50 +263,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link MediaController#onTouchEvent(MotionEvent)}, " +
- "this function always returns true",
- method = "onTouchEvent",
- args = {android.view.MotionEvent.class}
- )
- @ToBeFixed(bug = "1559790", explanation = "MediaController does not appear " +
- "when the user touches the anchor view.")
- @BrokenTest("NullPointerException thrown; no stacktrace in result")
- public void testOnTouchEvent() {
- final XmlPullParser parser =
- mActivity.getResources().getXml(R.layout.mediacontroller_layout);
- final AttributeSet attrs = Xml.asAttributeSet(parser);
- mMediaController = new MediaController(mActivity, attrs);
- final MockMediaPlayerControl mediaPlayerControl = new MockMediaPlayerControl();
- mMediaController.setMediaPlayer(mediaPlayerControl);
-
- final VideoView videoView =
- (VideoView) mActivity.findViewById(R.id.mediacontroller_videoview);
- videoView.setMediaController(mMediaController);
- mActivity.runOnUiThread(new Runnable() {
- public void run() {
- videoView.setVideoPath(prepareSampleVideo());
- }
- });
- mInstrumentation.waitForIdleSync();
-
- assertFalse(mMediaController.isShowing());
- TouchUtils.tapView(this, videoView);
- mInstrumentation.waitForIdleSync();
-
- // isShowing() should return true, but MediaController still not shows, this may be a bug.
- assertFalse(mMediaController.isShowing());
-
- // timeout is larger than duration, in case the system is sluggish
- new DelayedCheck(DEFAULT_TIMEOUT + 500) {
- @Override
- protected boolean check() {
- return !mMediaController.isShowing();
- }
- }.run();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
notes = "Test {@link MediaController#onTrackballEvent(MotionEvent)}, " +
"this function always returns false",
method = "onTrackballEvent",
@@ -351,46 +304,6 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
- notes = "Test {@link MediaController#dispatchKeyEvent(KeyEvent)}",
- method = "dispatchKeyEvent",
- args = {android.view.KeyEvent.class}
- )
- @ToBeFixed(bug = "1559790", explanation = "MediaController does not appear " +
- "when the user presses a key.")
- @BrokenTest("Fragile test. Passes only occasionally.")
- public void testDispatchKeyEvent() {
- mMediaController = new MediaController(mActivity);
- final MockMediaPlayerControl mediaPlayerControl = new MockMediaPlayerControl();
- mMediaController.setMediaPlayer(mediaPlayerControl);
-
- final VideoView videoView =
- (VideoView) mActivity.findViewById(R.id.mediacontroller_videoview);
- videoView.setMediaController(mMediaController);
- mActivity.runOnUiThread(new Runnable() {
- public void run() {
- videoView.setVideoPath(prepareSampleVideo());
- videoView.requestFocus();
- }
- });
- mInstrumentation.waitForIdleSync();
-
- mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_SPACE);
- mInstrumentation.waitForIdleSync();
-
- // isShowing() should return true, but MediaController still not shows, this may be a bug.
- assertFalse(mMediaController.isShowing());
-
- // timeout is larger than duration, in case the system is sluggish
- new DelayedCheck(DEFAULT_TIMEOUT + 500) {
- @Override
- protected boolean check() {
- return !mMediaController.isShowing();
- }
- }.run();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
notes = "Test {@link MediaController#setEnabled(boolean)}",
method = "setEnabled",
args = {boolean.class}
diff --git a/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java b/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
index de2b167..681e641 100644
--- a/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
@@ -78,10 +78,10 @@
// calculate pixel positions from dpi constants.
final float density = getActivity().getResources().getDisplayMetrics().density;
- mItemWidth = (int) (ITEM_WIDTH_DPI * density);
- mItemHeight = (int) (ITEM_HEIGHT_DPI * density);
- mPageWidth = (int) (PAGE_WIDTH_DPI * density);
- mPageHeight = (int) (PAGE_HEIGHT_DPI * density);
+ mItemWidth = (int) (ITEM_WIDTH_DPI * density + 0.5f);
+ mItemHeight = (int) (ITEM_HEIGHT_DPI * density + 0.5f);
+ mPageWidth = (int) (PAGE_WIDTH_DPI * density + 0.5f);
+ mPageHeight = (int) (PAGE_HEIGHT_DPI * density + 0.5f);
mScrollBottom = mItemHeight * ITEM_COUNT - mPageHeight;
mScrollRight = mItemWidth - mPageWidth;
diff --git a/tests/tests/widget/src/android/widget/cts/TableLayoutTest.java b/tests/tests/widget/src/android/widget/cts/TableLayoutTest.java
index 258883d..8214102 100644
--- a/tests/tests/widget/src/android/widget/cts/TableLayoutTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TableLayoutTest.java
@@ -16,6 +16,14 @@
package android.widget.cts;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.ToBeFixed;
+
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.test.ActivityInstrumentationTestCase2;
@@ -33,15 +41,6 @@
import android.widget.TableRow;
import android.widget.TextView;
-import com.android.cts.stub.R;
-
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
-
/**
* Test {@link TableLayout}.
*/
@@ -492,169 +491,6 @@
assertTrue(tableLayout.getChildAt(1).isLayoutRequested());
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "test whether columns are actually shrunk",
- method = "setColumnShrinkable",
- args = {java.lang.Integer.class, java.lang.Boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "test whether columns are actually shrunk",
- method = "setShrinkAllColumns",
- args = {java.lang.Boolean.class}
- )
- })
- @ToBeFixed( bug = "", explanation = "After set a column unable to be shrunk," +
- " the other shrinkable columns are not shrunk more.")
- @BrokenTest("fails consistently")
- public void testColumnShrinkableEffect() {
- final TableStubActivity activity = getActivity();
- getInstrumentation().runOnMainSync(new Runnable() {
- public void run() {
- activity.setContentView(com.android.cts.stub.R.layout.table_layout_2);
- }
- });
- getInstrumentation().waitForIdleSync();
- final TableLayout tableLayout =
- (TableLayout) activity.findViewById(com.android.cts.stub.R.id.table2);
-
- final int columnVirtualIndex0 = 1;
- final int columnVirtualIndex1 = 2;
- final int columnVirtualIndex2 = 4;
- final TextView child0 = (TextView) ((TableRow) tableLayout.getChildAt(0)).getChildAt(0);
- final TextView child1 = (TextView) ((TableRow) tableLayout.getChildAt(0)).getChildAt(1);
- final TextView child2 = (TextView) ((TableRow) tableLayout.getChildAt(0)).getChildAt(2);
-
- // get the original width of each child.
- int oldWidth0 = child0.getWidth();
- int oldWidth1 = child1.getWidth();
- int oldWidth2 = child2.getWidth();
- child0.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.EXACTLY);
- int orignalWidth0 = child0.getMeasuredWidth();
- // child1 has 2 columns.
- child1.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.EXACTLY);
- TextView column12 = (TextView) ((TableRow) tableLayout.getChildAt(1)).getChildAt(2);
- column12.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.EXACTLY);
- int orignalWidth1 = child1.getMeasuredWidth() + column12.getMeasuredWidth();
- child2.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.EXACTLY);
- int orignalWidth2 = child2.getMeasuredWidth();
- int totalSpace = tableLayout.getWidth() - orignalWidth0
- - orignalWidth1 - orignalWidth2;
-
- // Test: set column 2 which is the start column for child 1 is able to be shrunk.
- getInstrumentation().runOnMainSync(new Runnable() {
- public void run() {
- tableLayout.setColumnShrinkable(columnVirtualIndex1, true);
- }
- });
- getInstrumentation().waitForIdleSync();
- assertTrue(oldWidth0 < child0.getWidth());
- assertTrue(oldWidth1 > child1.getWidth());
- assertEquals(oldWidth2, child2.getWidth());
- int extraSpace = totalSpace / 2;
- assertEquals(dropNegative(orignalWidth0 + extraSpace), child0.getWidth());
- assertEquals(dropNegative(orignalWidth1 + extraSpace), child1.getWidth());
- assertEquals(orignalWidth2, child2.getWidth());
- oldWidth0 = child0.getWidth();
- oldWidth1 = child1.getWidth();
- oldWidth2 = child2.getWidth();
-
- // Test: set column 4 which is the column for child 2 is able to be shrunk.
- getInstrumentation().runOnMainSync(new Runnable() {
- public void run() {
- tableLayout.setColumnShrinkable(columnVirtualIndex2, true);
- }
- });
- getInstrumentation().waitForIdleSync();
- assertTrue(oldWidth0 < child0.getWidth());
- assertTrue(oldWidth1 < child1.getWidth());
- assertTrue(oldWidth2 > child2.getWidth());
- extraSpace = totalSpace / 3;
- assertEquals(dropNegative(orignalWidth0 + extraSpace), child0.getWidth());
- assertEquals(dropNegative(orignalWidth1 + extraSpace), child1.getWidth());
- assertEquals(dropNegative(orignalWidth2 + extraSpace), child2.getWidth());
- oldWidth0 = child0.getWidth();
- oldWidth1 = child1.getWidth();
- oldWidth2 = child2.getWidth();
-
- // Test: set column 3 which is the end column for child 1 is able to be shrunk.
- getInstrumentation().runOnMainSync(new Runnable() {
- public void run() {
- tableLayout.setColumnShrinkable(columnVirtualIndex1+1, true);
- }
- });
- getInstrumentation().waitForIdleSync();
- assertTrue(oldWidth0 < child0.getWidth());
- assertTrue(oldWidth1 > child1.getWidth());
- assertTrue(oldWidth2 < child2.getWidth());
- extraSpace = totalSpace / 4;
- assertEquals(dropNegative(orignalWidth0 + extraSpace), child0.getWidth());
- assertEquals(dropNegative(orignalWidth1 + extraSpace * 2), child1.getWidth());
- assertEquals(dropNegative(orignalWidth2 + extraSpace), child2.getWidth());
- oldWidth0 = child0.getWidth();
- oldWidth1 = child1.getWidth();
- oldWidth2 = child2.getWidth();
-
- // Test: set column 1 which is the column for child 0 is unable to be shrunk.
- getInstrumentation().runOnMainSync(new Runnable() {
- public void run() {
- tableLayout.setColumnShrinkable(columnVirtualIndex0, false);
- }
- });
- getInstrumentation().waitForIdleSync();
- assertTrue(oldWidth0 < child0.getWidth());
- // assertTrue(oldWidth1 > column1.getWidth());
- // assertTrue(oldWidth2 > column2.getWidth());
- assertEquals(oldWidth1, child1.getWidth());
- assertEquals(oldWidth2, child2.getWidth());
- // extraSpace = totalSpace / 3;
- extraSpace = totalSpace / 4;
- assertEquals(orignalWidth0, child0.getWidth());
- assertEquals(orignalWidth1 + extraSpace * 2, child1.getWidth());
- assertEquals(orignalWidth2 + extraSpace, child2.getWidth());
- oldWidth0 = child0.getWidth();
- oldWidth1 = child1.getWidth();
- oldWidth2 = child2.getWidth();
-
- // Test: mark all columns are able to be shrunk.
- getInstrumentation().runOnMainSync(new Runnable() {
- public void run() {
- tableLayout.setShrinkAllColumns(true);
- tableLayout.requestLayout();
- }
- });
- getInstrumentation().waitForIdleSync();
- assertTrue(oldWidth0 > child0.getWidth());
- assertTrue(oldWidth1 < child1.getWidth());
- assertTrue(oldWidth2 < child2.getWidth());
- extraSpace = totalSpace / 5;
- assertEquals(orignalWidth0 + extraSpace, child0.getWidth());
- assertEquals(orignalWidth1 + extraSpace * 2, child1.getWidth());
- assertEquals(orignalWidth2 + extraSpace, child2.getWidth());
- oldWidth0 = child0.getWidth();
- oldWidth1 = child1.getWidth();
- oldWidth2 = child2.getWidth();
-
- // Test: Remove the mark for all columns are able to be shrunk.
- getInstrumentation().runOnMainSync(new Runnable() {
- public void run() {
- tableLayout.setShrinkAllColumns(false);
- tableLayout.requestLayout();
- }
- });
- getInstrumentation().waitForIdleSync();
- assertTrue(oldWidth0 < child0.getWidth());
- assertTrue(oldWidth1 > child1.getWidth());
- assertTrue(oldWidth2 > child2.getWidth());
- // extraSpace = totalSpace / 3;
- extraSpace = totalSpace / 4;
- assertEquals(orignalWidth0, child0.getWidth());
- assertEquals(orignalWidth1 + extraSpace * 2, child1.getWidth());
- assertEquals(orignalWidth2 + extraSpace, child2.getWidth());
- }
-
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test addView(View child)",
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
old mode 100644
new mode 100755
index bf0714c..71b2dba
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -81,11 +81,9 @@
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.Gravity;
-import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.WindowManager;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.view.View.OnLongClickListener;
@@ -94,7 +92,6 @@
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
-import android.widget.AbsoluteLayout;
import android.widget.FrameLayout;
import android.widget.Scroller;
import android.widget.TextView;
@@ -236,7 +233,6 @@
mActivity.runOnUiThread(new Runnable() {
public void run() {
mTextView = findTextView(R.id.textview_text);
- mTextView.setText("");
}
});
mInstrumentation.waitForIdleSync();
@@ -248,45 +244,20 @@
mActivity.runOnUiThread(new Runnable() {
public void run() {
mTextView.setKeyListener(digitsKeyListener);
- mTextView.requestFocus();
}
});
mInstrumentation.waitForIdleSync();
assertSame(digitsKeyListener, mTextView.getKeyListener());
- assertEquals("", mTextView.getText().toString());
-
- // press '-' key.
- mInstrumentation.sendStringSync("-");
- assertEquals("", mTextView.getText().toString());
-
- // press '1' key.
- mInstrumentation.sendStringSync("1");
- assertEquals("1", mTextView.getText().toString());
-
- // press '.' key.
- mInstrumentation.sendStringSync(".");
- assertEquals("1", mTextView.getText().toString());
-
- // press 'a' key.
- mInstrumentation.sendStringSync("a");
- assertEquals("1", mTextView.getText().toString());
final QwertyKeyListener qwertyKeyListener
= QwertyKeyListener.getInstance(false, Capitalize.NONE);
mActivity.runOnUiThread(new Runnable() {
public void run() {
mTextView.setKeyListener(qwertyKeyListener);
- mTextView.requestFocus();
}
});
mInstrumentation.waitForIdleSync();
assertSame(qwertyKeyListener, mTextView.getKeyListener());
- assertEquals("1", mTextView.getText().toString());
-
- // press 'a' key.
- mInstrumentation.sendStringSync("a");
-
- assertEquals("1a", mTextView.getText().toString());
}
@TestTargets({
@@ -1796,10 +1767,9 @@
mInstrumentation.waitForIdleSync();
assertNull(mTextView.getError());
- final DigitsKeyListener digitsKeyListener = DigitsKeyListener.getInstance();
mActivity.runOnUiThread(new Runnable() {
public void run() {
- mTextView.setKeyListener(digitsKeyListener);
+ mTextView.setKeyListener(DigitsKeyListener.getInstance(""));
mTextView.setText("", BufferType.EDITABLE);
mTextView.setError(errorText);
mTextView.requestFocus();
@@ -1815,6 +1785,16 @@
// The icon and error message will not be reset to null
assertNull(mTextView.getError());
+ mActivity.runOnUiThread(new Runnable() {
+ public void run() {
+ mTextView.setKeyListener(DigitsKeyListener.getInstance());
+ mTextView.setText("", BufferType.EDITABLE);
+ mTextView.setError(errorText);
+ mTextView.requestFocus();
+ }
+ });
+ mInstrumentation.waitForIdleSync();
+
mInstrumentation.sendStringSync("1");
// a key event cause changes to the TextView's text
assertEquals("1", mTextView.getText().toString());
@@ -1910,12 +1890,12 @@
mTextView.getFocusedRect(rc);
assertNotNull(mTextView.getLayout());
assertEquals(mTextView.getLayout().getPrimaryHorizontal(13),
- (float) rc.left, 0.01f);
+ (float) rc.left, 0.4f);
// 'right' is one pixel larger than 'left'
assertEquals(mTextView.getLayout().getPrimaryHorizontal(13) + 1,
- (float) rc.right, 0.01f);
+ (float) rc.right, 0.4f);
assertEquals(mTextView.getLayout().getLineTop(0), rc.top);
- assertEquals(mTextView.getLayout().getLineBottom(0), rc.bottom);
+ assertEquals(mTextView.getLayout().getLineBottom(0), rc.bottom, 0.4f);
// Exception
try {
diff --git a/tests/tests/widget/src/android/widget/cts/VideoViewTest.java b/tests/tests/widget/src/android/widget/cts/VideoViewTest.java
index 00db05f..6b9aa84 100644
--- a/tests/tests/widget/src/android/widget/cts/VideoViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/VideoViewTest.java
@@ -18,12 +18,10 @@
import com.android.cts.stub.R;
-import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
-import dalvik.annotation.ToBeFixed;
import android.app.Activity;
import android.app.Instrumentation;
@@ -32,7 +30,6 @@
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
-import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
import android.view.View.MeasureSpec;
@@ -240,142 +237,6 @@
}.run();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setVideoURI",
- args = {android.net.Uri.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnPreparedListener",
- args = {android.media.MediaPlayer.OnPreparedListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "isPlaying",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "pause",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "start",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "seekTo",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "stopPlayback",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getCurrentPosition",
- args = {}
- )
- })
- @BrokenTest("Fails in individual mode (current pos > 0 before start)")
- public void testPlayVideo2() throws Throwable {
- final int seekTo = mVideoView.getDuration() >> 1;
- final MockOnPreparedListener listener = new MockOnPreparedListener();
- mVideoView.setOnPreparedListener(listener);
-
- runTestOnUiThread(new Runnable() {
- public void run() {
- mVideoView.setVideoURI(Uri.parse(mVideoPath));
- }
- });
- new DelayedCheck(TIME_OUT) {
- @Override
- protected boolean check() {
- return listener.isTriggered();
- }
- }.run();
- assertEquals(0, mVideoView.getCurrentPosition());
-
- // test start
- runTestOnUiThread(new Runnable() {
- public void run() {
- mVideoView.start();
- }
- });
- new DelayedCheck(TIME_OUT) {
- @Override
- protected boolean check() {
- return mVideoView.isPlaying();
- }
- }.run();
- assertTrue(mVideoView.getCurrentPosition() > 0);
-
- // test pause
- runTestOnUiThread(new Runnable() {
- public void run() {
- mVideoView.pause();
- }
- });
- new DelayedCheck(TIME_OUT) {
- @Override
- protected boolean check() {
- return !mVideoView.isPlaying();
- }
- }.run();
- int currentPosition = mVideoView.getCurrentPosition();
-
- // sleep a second and then check whether player is paused.
- Thread.sleep(OPERATION_INTERVAL);
- assertEquals(currentPosition, mVideoView.getCurrentPosition());
-
- // test seekTo
- runTestOnUiThread(new Runnable() {
- public void run() {
- mVideoView.seekTo(seekTo);
- }
- });
- new DelayedCheck(TIME_OUT) {
- @Override
- protected boolean check() {
- return mVideoView.getCurrentPosition() >= seekTo;
- }
- }.run();
- assertFalse(mVideoView.isPlaying());
-
- // test start again
- runTestOnUiThread(new Runnable() {
- public void run() {
- mVideoView.start();
- }
- });
- new DelayedCheck(TIME_OUT) {
- @Override
- protected boolean check() {
- return mVideoView.isPlaying();
- }
- }.run();
- assertTrue(mVideoView.getCurrentPosition() > seekTo);
-
- // test stop
- runTestOnUiThread(new Runnable() {
- public void run() {
- mVideoView.stopPlayback();
- }
- });
- new DelayedCheck(TIME_OUT) {
- @Override
- protected boolean check() {
- return !mVideoView.isPlaying();
- }
- }.run();
- assertEquals(0, mVideoView.getCurrentPosition());
- }
-
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "setOnErrorListener",
@@ -462,9 +323,6 @@
method = "onKeyDown",
args = {int.class, android.view.KeyEvent.class}
)
- @ToBeFixed(bug = "", explanation = "After pressing KEYCODE_HEADSETHOOK, "
- + "the video should be playing, but it did not until time out.")
- @BrokenTest("Video starts playing automatically after setting the path.")
public void testOnKeyDown() throws Throwable {
runTestOnUiThread(new Runnable() {
public void run() {
@@ -480,7 +338,7 @@
new DelayedCheck(TIME_OUT) {
@Override
protected boolean check() {
- return !mVideoView.isPlaying();
+ return mVideoView.isPlaying();
}
}.run();
assertFalse(mMediaController.isShowing());
@@ -493,7 +351,7 @@
}
}.run();
// MediaController should show
- assertFalse(mMediaController.isShowing());
+ assertTrue(mMediaController.isShowing());
runTestOnUiThread(new Runnable() {
public void run() {
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java
index d181a9b..bfe5aaa 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java
@@ -23,6 +23,7 @@
*/
public interface DeviceInfoConstants {
+ public static final String PARTITIONS = "partitions";
public static final String OPEN_GL_ES_VERSION = "openGlEsVersion";
public static final String PROCESSES = "processes";
public static final String FEATURES = "features";
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
index 1299aae..606adfd 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
@@ -31,10 +31,12 @@
import android.view.Display;
import android.view.WindowManager;
+import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Scanner;
import java.util.Set;
public class DeviceInfoInstrument extends Instrumentation implements DeviceInfoConstants {
@@ -125,6 +127,9 @@
String openGlEsVersion = getOpenGlEsVersion();
addResult(OPEN_GL_ES_VERSION, openGlEsVersion);
+ // partitions
+ String partitions = getPartitions();
+ addResult(PARTITIONS, partitions);
finish(Activity.RESULT_OK, mResults);
}
@@ -296,4 +301,22 @@
}
return "No feature for Open GL ES version.";
}
+
+ private String getPartitions() {
+ try {
+ StringBuilder builder = new StringBuilder();
+ Process df = new ProcessBuilder("df").start();
+ Scanner scanner = new Scanner(df.getInputStream());
+ try {
+ while (scanner.hasNextLine()) {
+ builder.append(scanner.nextLine()).append(';');
+ }
+ return builder.toString();
+ } finally {
+ scanner.close();
+ }
+ } catch (IOException e) {
+ return "Not able to run df for partition information.";
+ }
+ }
}
diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java
index 19f754a..e72b97c 100644
--- a/tools/host/src/com/android/cts/TestDevice.java
+++ b/tools/host/src/com/android/cts/TestDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+* 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.
@@ -828,6 +828,15 @@
public String getOpenGlEsVersion() {
return mInfoMap.get(OPEN_GL_ES_VERSION);
}
+
+ /**
+ * Get partitions.
+ *
+ * @return partitions or error message.
+ */
+ public String getPartitions() {
+ return mInfoMap.get(PARTITIONS);
+ }
}
/**
diff --git a/tools/host/src/com/android/cts/TestSessionLog.java b/tools/host/src/com/android/cts/TestSessionLog.java
index cc59a3e..0b53076 100644
--- a/tools/host/src/com/android/cts/TestSessionLog.java
+++ b/tools/host/src/com/android/cts/TestSessionLog.java
@@ -46,7 +46,7 @@
private static final String ATTRIBUTE_KNOWN_FAILURE = "KnownFailure";
public static final String CTS_RESULT_FILE_NAME = "testResult.xml";
- private static final String CTS_RESULT_FILE_VERSION = "1.10";
+ private static final String CTS_RESULT_FILE_VERSION = "1.11";
static final String ATTRIBUTE_STARTTIME = "starttime";
static final String ATTRIBUTE_ENDTIME = "endtime";
@@ -73,6 +73,7 @@
static final String ATTRIBUTE_TYPE = "type";
static final String ATTRIBUTE_UID = "uid";
static final String ATTRIBUTE_OPEN_GL_ES_VERSION = "openGlEsVersion";
+ static final String ATTRIBUTE_PARTITIONS = "partitions";
static final String ATTRIBUTE_PASS = "pass";
static final String ATTRIBUTE_FAILED = "failed";
@@ -327,6 +328,8 @@
setAttribute(doc, devInfoNode, ATTRIBUTE_IMSI, bldInfo.getIMSI());
setAttribute(doc, devInfoNode, ATTRIBUTE_OPEN_GL_ES_VERSION,
bldInfo.getOpenGlEsVersion());
+ setAttribute(doc, devInfoNode, ATTRIBUTE_PARTITIONS,
+ bldInfo.getPartitions());
setAttribute(doc, devInfoNode,
DeviceParameterCollector.BUILD_FINGERPRINT, bldInfo.getBuildFingerPrint());
diff --git a/tools/host/src/com/android/cts/Version.java b/tools/host/src/com/android/cts/Version.java
index 0426560..f2c83b9 100644
--- a/tools/host/src/com/android/cts/Version.java
+++ b/tools/host/src/com/android/cts/Version.java
@@ -18,7 +18,7 @@
public class Version {
// The CTS version string
- private static final String version = "2.3_r1";
+ private static final String version = "3.0_r1";
private Version() {
// no instances allowed
diff --git a/tools/host/src/res/cts_result.xsd b/tools/host/src/res/cts_result.xsd
index d154bc4..665795f 100644
--- a/tools/host/src/res/cts_result.xsd
+++ b/tools/host/src/res/cts_result.xsd
@@ -74,6 +74,7 @@
<xs:attribute name="network" type="xs:string"/>
<xs:attribute name="touch" type="xs:string"/>
<xs:attribute name="openGlEsVersion" type="xs:string"/>
+ <xs:attribute name="partitions" type="xs:string"/>
<xs:attribute name="build_abi" type="xs:string"/>
<xs:attribute name="build_abi2" type="xs:string"/>
</xs:complexType>
diff --git a/tools/host/src/res/cts_result.xsl b/tools/host/src/res/cts_result.xsl
index 4317655..b6c9acc 100644
--- a/tools/host/src/res/cts_result.xsl
+++ b/tools/host/src/res/cts_result.xsl
@@ -252,6 +252,19 @@
</UL>
</TD>
</TR>
+ <TR>
+ <TD class="rowtitle">Partitions</TD>
+ <TD>
+ <UL>
+ <pre>
+ <xsl:call-template name="formatDelimitedString">
+ <xsl:with-param name="string" select="TestResult/DeviceInfo/BuildInfo/@partitions" />
+ <xsl:with-param name="numTokensPerRow" select="1" />
+ </xsl:call-template>
+ </pre>
+ </UL>
+ </TD>
+ </TR>
</TABLE>
</div>
</TD>