diff options
Diffstat (limited to 'tests')
7 files changed, 364 insertions, 9 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java b/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java index d775dc2..8b6cad1 100644 --- a/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java +++ b/tests/AndroidTests/src/com/android/unit_tests/DatabaseGeneralTest.java @@ -509,9 +509,13 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase Cursor c; mDatabase.execSQL("CREATE TABLE tokens (" + "token TEXT COLLATE unicode," + - "source INTEGER " + + "source INTEGER," + + "token_index INTEGER" + + ");"); + mDatabase.execSQL("CREATE TABLE tokens_no_index (" + + "token TEXT COLLATE unicode," + + "source INTEGER" + ");"); - String[] cols = new String[]{"token", "source"}; Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, "SELECT _TOKENIZE(NULL, NULL, NULL, NULL)", null)); @@ -523,17 +527,22 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase "SELECT _TOKENIZE('tokens', 10, 'some string', NULL)", null)); Assert.assertEquals(3, DatabaseUtils.longForQuery(mDatabase, - "SELECT _TOKENIZE('tokens', 1, 'some string ok', ' ')", null)); + "SELECT _TOKENIZE('tokens', 11, 'some string ok', ' ', 1)", null)); + Assert.assertEquals(3, DatabaseUtils.longForQuery(mDatabase, + "SELECT _TOKENIZE('tokens_no_index', 20, 'some string ok', ' ')", null)); + Assert.assertEquals(3, DatabaseUtils.longForQuery(mDatabase, + "SELECT _TOKENIZE('tokens_no_index', 21, 'foo bar baz', ' ', 0)", null)); + // test Chinese String chinese = new String("\u4eac\u4ec5 \u5c3d\u5f84\u60ca"); Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase, - "SELECT _TOKENIZE('tokens', 1,'" + chinese + "', ' ')", null)); + "SELECT _TOKENIZE('tokens', 12,'" + chinese + "', ' ', 1)", null)); String icustr = new String("Fr\u00e9d\u00e9ric Hj\u00f8nnev\u00e5g"); Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase, - "SELECT _TOKENIZE('tokens', 1, '" + icustr + "', ' ')", null)); + "SELECT _TOKENIZE('tokens', 13, '" + icustr + "', ' ', 1)", null)); Assert.assertEquals(7, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens;", null)); @@ -541,42 +550,102 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase String key = DatabaseUtils.getHexCollationKey("Frederic Hjonneva"); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(13, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); key = DatabaseUtils.getHexCollationKey("Hjonneva"); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(13, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); key = DatabaseUtils.getHexCollationKey("some string ok"); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(11, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); key = DatabaseUtils.getHexCollationKey("string"); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(11, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); key = DatabaseUtils.getHexCollationKey("ok"); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(11, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); key = DatabaseUtils.getHexCollationKey(chinese); String[] a = new String[1]; a[0] = key; Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token= ?", a)); + Assert.assertEquals(12, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token= ?", a)); + Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token= ?", a)); a[0] += "*"; Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB ?", a)); + Assert.assertEquals(12, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB ?", a)); + Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB ?", a)); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token= '" + key + "'", null)); + Assert.assertEquals(12, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token= '" + key + "'", null)); + Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token= '" + key + "'", null)); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(12, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); key = DatabaseUtils.getHexCollationKey("\u4eac\u4ec5"); Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(12, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); + key = DatabaseUtils.getHexCollationKey("\u5c3d\u5f84\u60ca"); + Log.d("DatabaseGeneralTest", "key = " + key); + Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, + "SELECT count(*) from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(12, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens where token GLOB '" + key + "*'", null)); + Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, + "SELECT token_index from tokens where token GLOB '" + key + "*'", null)); Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase, "SELECT count(*) from tokens where token GLOB 'ab*'", null)); + + key = DatabaseUtils.getHexCollationKey("some string ok"); + Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, + "SELECT count(*) from tokens_no_index where token GLOB '" + key + "*'", null)); + Assert.assertEquals(20, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens_no_index where token GLOB '" + key + "*'", null)); + + key = DatabaseUtils.getHexCollationKey("bar"); + Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, + "SELECT count(*) from tokens_no_index where token GLOB '" + key + "*'", null)); + Assert.assertEquals(21, DatabaseUtils.longForQuery(mDatabase, + "SELECT source from tokens_no_index where token GLOB '" + key + "*'", null)); } @MediumTest diff --git a/tests/FrameworkTest/AndroidManifest.xml b/tests/FrameworkTest/AndroidManifest.xml index c70302b..4e4ebff 100644 --- a/tests/FrameworkTest/AndroidManifest.xml +++ b/tests/FrameworkTest/AndroidManifest.xml @@ -20,6 +20,9 @@ <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.HARDWARE_TEST" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> + <uses-permission android:name="android.permission.ACCESSIBILITY_EVENT_VIEW_TYPES" /> + <uses-permission android:name="android.permission.ACCESSIBILITY_EVENT_TRANSITION_TYPES" /> + <uses-permission android:name="android.permission.ACCESSIBILITY_EVENT_NOTIFICATION_TYPES" /> <application android:theme="@style/Theme"> <uses-library android:name="android.test.runner" /> @@ -939,7 +942,7 @@ </intent-filter> </activity> - <activity android:name="android.widget.AutoCompleteTextViewSimple" + <activity android:name="android.widget.AutoCompleteTextViewSimple" android:label="AutoCompleteTextViewSimple"> <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -947,6 +950,12 @@ </intent-filter> </activity> + <service android:name=".accessibility.AccessibilityTestService"> + <intent-filter> + <action android:name="android.accessibilityservice.AccessibilityService" /> + </intent-filter> + </service> + </application> </manifest> diff --git a/tests/FrameworkTest/src/com/android/frameworktest/accessibility/AccessibilityTestService.java b/tests/FrameworkTest/src/com/android/frameworktest/accessibility/AccessibilityTestService.java new file mode 100644 index 0000000..83d6056 --- /dev/null +++ b/tests/FrameworkTest/src/com/android/frameworktest/accessibility/AccessibilityTestService.java @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.frameworktest.accessibility; + +import android.accessibilityservice.AccessibilityService; +import android.accessibilityservice.AccessibilityServiceInfo; +import android.app.Notification; +import android.util.Log; +import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityManager; + +import java.util.Timer; +import java.util.TimerTask; + +/** + * This class text the accessibility framework end to end. + * <p> + * Note: Since accessibility is provided by {@link AccessibilityService}s we create one, + * and it generates an event and an interruption dispatching them through the + * {@link AccessibilityManager}. We verify the received result. To trigger the test + * go to Settings->Accessibility and select the enable accessibility check and then + * select the check for this service (same name as the class). + */ +public class AccessibilityTestService extends AccessibilityService { + + private static final String LOG_TAG = "AccessibilityTestService"; + + private static final String CLASS_NAME = "foo.bar.baz.Test"; + private static final String PACKAGE_NAME = "foo.bar.baz"; + private static final String TEXT = "Some stuff"; + private static final String BEFORE_TEXT = "Some other stuff"; + + private static final String CONTENT_DESCRIPTION = "Content description"; + + private static final int ITEM_COUNT = 10; + private static final int CURRENT_ITEM_INDEX = 1; + private static final int INTERRUPT_INVOCATION_TYPE = 0x00000200; + + private static final int FROM_INDEX = 1; + private static final int ADDED_COUNT = 2; + private static final int REMOVED_COUNT = 1; + + private static final int NOTIFICATION_TIMEOUT_MILLIS = 80; + + private int mReceivedResult; + + private Timer mTimer = new Timer(); + + @Override + public void onServiceConnected() { + AccessibilityServiceInfo info = new AccessibilityServiceInfo(); + info.eventTypes = AccessibilityEvent.TYPES_ALL_MASK; + info.feedbackType = AccessibilityServiceInfo.FEEDBACK_AUDIBLE; + info.notificationTimeout = NOTIFICATION_TIMEOUT_MILLIS; + info.flags &= AccessibilityServiceInfo.DEFAULT; + setServiceInfo(info); + + // we need to wait until the system picks our configuration + // otherwise it will not notify us + mTimer.schedule(new TimerTask() { + @Override + public void run() { + try { + testAccessibilityEventDispatching(); + testInterrupt(); + } catch (Exception e) { + Log.e(LOG_TAG, "Error in testing Accessibility feature", e); + } + } + }, 1000); + } + + /** + * Check here if the event we received is actually the one we sent. + */ + @Override + public void onAccessibilityEvent(AccessibilityEvent event) { + assert(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED == event.getEventType()); + assert(event != null); + assert(event.getEventTime() > 0); + assert(CLASS_NAME.equals(event.getClassName())); + assert(PACKAGE_NAME.equals(event.getPackageName())); + assert(1 == event.getText().size()); + assert(TEXT.equals(event.getText().get(0))); + assert(BEFORE_TEXT.equals(event.getBeforeText())); + assert(event.isChecked()); + assert(CONTENT_DESCRIPTION.equals(event.getContentDescription())); + assert(ITEM_COUNT == event.getItemCount()); + assert(CURRENT_ITEM_INDEX == event.getCurrentItemIndex()); + assert(event.isEnabled()); + assert(event.isPassword()); + assert(FROM_INDEX == event.getFromIndex()); + assert(ADDED_COUNT == event.getAddedCount()); + assert(REMOVED_COUNT == event.getRemovedCount()); + assert(event.getParcelableData() != null); + assert(1 == ((Notification) event.getParcelableData()).icon); + + // set the type of the receved request + mReceivedResult = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED; + } + + /** + * Set a flag that we received the interrupt request. + */ + @Override + public void onInterrupt() { + + // set the type of the receved request + mReceivedResult = INTERRUPT_INVOCATION_TYPE; + } + + /** + * If an {@link AccessibilityEvent} is sent and received correctly. + */ + public void testAccessibilityEventDispatching() throws Exception { + AccessibilityEvent event = + AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); + + assert(event != null); + event.setClassName(CLASS_NAME); + event.setPackageName(PACKAGE_NAME); + event.getText().add(TEXT); + event.setBeforeText(BEFORE_TEXT); + event.setChecked(true); + event.setContentDescription(CONTENT_DESCRIPTION); + event.setItemCount(ITEM_COUNT); + event.setCurrentItemIndex(CURRENT_ITEM_INDEX); + event.setEnabled(true); + event.setPassword(true); + event.setFromIndex(FROM_INDEX); + event.setAddedCount(ADDED_COUNT); + event.setRemovedCount(REMOVED_COUNT); + event.setParcelableData(new Notification(1, "Foo", 1234)); + + AccessibilityManager.getInstance(this).sendAccessibilityEvent(event); + + assert(mReceivedResult == event.getEventType()); + + Log.i(LOG_TAG, "AccessibilityTestService#testAccessibilityEventDispatching: Success"); + } + + /** + * If accessibility feedback interruption is triggered and received correctly. + */ + public void testInterrupt() throws Exception { + AccessibilityManager.getInstance(this).interrupt(); + + assert(INTERRUPT_INVOCATION_TYPE == mReceivedResult); + + Log.i(LOG_TAG, "AccessibilityTestService#testInterrupt: Success"); + } +} + diff --git a/tests/FrameworkTest/tests/src/com/android/frameworktest/accessibility/RecycleAccessibilityEventTest.java b/tests/FrameworkTest/tests/src/com/android/frameworktest/accessibility/RecycleAccessibilityEventTest.java new file mode 100644 index 0000000..d6380f9 --- /dev/null +++ b/tests/FrameworkTest/tests/src/com/android/frameworktest/accessibility/RecycleAccessibilityEventTest.java @@ -0,0 +1,81 @@ +/** + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.frameworktest.accessibility; + +import android.test.suitebuilder.annotation.MediumTest; +import android.view.accessibility.AccessibilityEvent; + +import junit.framework.TestCase; + +/** + * This class exercises the caching and recycling of {@link AccessibilityEvent}s. + */ +public class RecycleAccessibilityEventTest extends TestCase { + + private static final String CLASS_NAME = "foo.bar.baz.Test"; + private static final String PACKAGE_NAME = "foo.bar.baz"; + private static final String TEXT = "Some stuff"; + + private static final String CONTENT_DESCRIPTION = "Content description"; + private static final int ITEM_COUNT = 10; + private static final int CURRENT_ITEM_INDEX = 1; + + private static final int FROM_INDEX = 1; + private static final int ADDED_COUNT = 2; + private static final int REMOVED_COUNT = 1; + + /** + * If an {@link AccessibilityEvent} is marshaled/unmarshaled correctly + */ + @MediumTest + public void testAccessibilityEventViewTextChangedType() { + AccessibilityEvent first = + AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED); + assertNotNull(first); + + first.setClassName(CLASS_NAME); + first.setPackageName(PACKAGE_NAME); + first.getText().add(TEXT); + first.setFromIndex(FROM_INDEX); + first.setAddedCount(ADDED_COUNT); + first.setRemovedCount(REMOVED_COUNT); + first.setChecked(true); + first.setContentDescription(CONTENT_DESCRIPTION); + first.setItemCount(ITEM_COUNT); + first.setCurrentItemIndex(CURRENT_ITEM_INDEX); + first.setEnabled(true); + first.setPassword(true); + + first.recycle(); + + assertNotNull(first); + assertNull(first.getClassName()); + assertNull(first.getPackageName()); + assertEquals(0, first.getText().size()); + assertFalse(first.isChecked()); + assertNull(first.getContentDescription()); + assertEquals(0, first.getItemCount()); + assertEquals(AccessibilityEvent.INVALID_POSITION, first.getCurrentItemIndex()); + assertFalse(first.isEnabled()); + assertFalse(first.isPassword()); + assertEquals(0, first.getFromIndex()); + assertEquals(0, first.getAddedCount()); + assertEquals(0, first.getRemovedCount()); + + // get another event from the pool (this must be the recycled first) + AccessibilityEvent second = AccessibilityEvent.obtain(); + assertEquals(first, second); + } +} diff --git a/tests/backup/backup_helper_test.cpp b/tests/backup/backup_helper_test.cpp index 6da16b4..1085909 100644 --- a/tests/backup/backup_helper_test.cpp +++ b/tests/backup/backup_helper_test.cpp @@ -3,6 +3,8 @@ #include <stdio.h> #include <string.h> +using namespace android; + #if TEST_BACKUP_HELPERS // ============================================================ @@ -20,6 +22,8 @@ Test TESTS[] = { { "backup_helper_test_empty", backup_helper_test_empty, 0, false }, { "backup_helper_test_four", backup_helper_test_four, 0, false }, { "backup_helper_test_files", backup_helper_test_files, 0, false }, + { "backup_helper_test_data_writer", backup_helper_test_data_writer, 0, false }, + { "backup_helper_test_data_reader", backup_helper_test_data_reader, 0, false }, { 0, NULL, 0, false} }; diff --git a/tests/backup/src/com/android/backuptest/BackupTestActivity.java b/tests/backup/src/com/android/backuptest/BackupTestActivity.java index de68cb7..af7dfd4 100644 --- a/tests/backup/src/com/android/backuptest/BackupTestActivity.java +++ b/tests/backup/src/com/android/backuptest/BackupTestActivity.java @@ -83,6 +83,27 @@ public class BackupTestActivity extends ListActivity bm.dataChanged(); } }, + new Test("Clear File") { + void run() { + PrintStream output = null; + try { + output = new PrintStream(openFileOutput(FILE_NAME, MODE_PRIVATE)); + output.close(); + } catch (IOException ex) { + if (output != null) { + output.close(); + } + } + BackupManager bm = new BackupManager(BackupTestActivity.this); + bm.dataChanged(); + } + }, + new Test("Poke") { + void run() { + BackupManager bm = new BackupManager(BackupTestActivity.this); + bm.dataChanged(); + } + }, new Test("Show Shared Pref") { void run() { SharedPreferences prefs = getSharedPreferences(PREF_GROUP_SETTINGS, MODE_PRIVATE); diff --git a/tests/backup/src/com/android/backuptest/BackupTestService.java b/tests/backup/src/com/android/backuptest/BackupTestService.java index c58c98b..00eb86e 100644 --- a/tests/backup/src/com/android/backuptest/BackupTestService.java +++ b/tests/backup/src/com/android/backuptest/BackupTestService.java @@ -17,6 +17,8 @@ package com.android.backuptest; import android.backup.BackupService; +import android.backup.BackupDataOutput; +import android.backup.FileBackupHelper; import android.os.ParcelFileDescriptor; import android.util.Log; @@ -25,10 +27,12 @@ public class BackupTestService extends BackupService static final String TAG = "BackupTestService"; @Override - public void onBackup(ParcelFileDescriptor oldState, - ParcelFileDescriptor data, - ParcelFileDescriptor newState) { + public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, + ParcelFileDescriptor newState) { Log.d(TAG, "onBackup"); + FileBackupHelper.performBackup(this, oldState, data, newState, new String[] { + BackupTestActivity.FILE_NAME + }); } @Override |