diff options
author | Brett Chabot <brettchabot@android.com> | 2010-04-01 21:45:41 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-04-01 21:45:41 -0700 |
commit | c162668e870cda9d336741f24c177cd925fef8e0 (patch) | |
tree | 479d06830326708e659887c6291254e53f4a1a76 /tests/AndroidTests/src/com/android/unit_tests | |
parent | 87e72cd3b327fefc39030a628e9e9b7141791d39 (diff) | |
parent | 0dc59e78e18493aecd37427531d093e800846c3e (diff) | |
download | frameworks_base-c162668e870cda9d336741f24c177cd925fef8e0.zip frameworks_base-c162668e870cda9d336741f24c177cd925fef8e0.tar.gz frameworks_base-c162668e870cda9d336741f24c177cd925fef8e0.tar.bz2 |
Merge "More framework tests cleanup." into froyo
Diffstat (limited to 'tests/AndroidTests/src/com/android/unit_tests')
30 files changed, 0 insertions, 10694 deletions
diff --git a/tests/AndroidTests/src/com/android/unit_tests/AndroidPerformanceTests.java b/tests/AndroidTests/src/com/android/unit_tests/AndroidPerformanceTests.java deleted file mode 100644 index 795fe2b..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/AndroidPerformanceTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.TestListActivity; - -public class AndroidPerformanceTests extends TestListActivity { - @Override - public String getTestSuite() { - return "com.android.unit_tests.AndroidPerformanceTests$Suite"; - } - - public static class Suite { - public static String[] children() { - return new String[] { - JavaPerformanceTests.class.getName(), - PerformanceTests.class.getName(), - }; - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java b/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java deleted file mode 100755 index fa7b9ff..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java +++ /dev/null @@ -1,745 +0,0 @@ -/* - * Copyright (C) 2006 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.unit_tests; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; - -import android.app.PendingIntent; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.ApplicationInfo; -import android.content.pm.IPackageDataObserver; -import android.content.pm.IPackageStatsObserver; -import android.content.pm.PackageStats; -import android.content.pm.IPackageManager; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; -import android.util.Log; -import android.os.Handler; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.os.StatFs; - -public class AppCacheTest extends AndroidTestCase { - private static final boolean localLOGV = false; - public static final String TAG="AppCacheTest"; - public final long MAX_WAIT_TIME=60*1000; - public final long WAIT_TIME_INCR=10*1000; - private static final int THRESHOLD=5; - private static final int ACTUAL_THRESHOLD=10; - - @Override - protected void setUp() throws Exception { - super.setUp(); - if(localLOGV) Log.i(TAG, "Cleaning up cache directory first"); - cleanUpCacheDirectory(); - } - - void cleanUpDirectory(File pDir, String dirName) { - File testDir = new File(pDir, dirName); - if(!testDir.exists()) { - return; - } - String fList[] = testDir.list(); - for(int i = 0; i < fList.length; i++) { - File file = new File(testDir, fList[i]); - if(file.isDirectory()) { - cleanUpDirectory(testDir, fList[i]); - } else { - file.delete(); - } - } - testDir.delete(); - } - - void cleanUpCacheDirectory() { - File testDir = mContext.getCacheDir(); - if(!testDir.exists()) { - return; - } - - String fList[] = testDir.list(); - if(fList == null) { - testDir.delete(); - return; - } - for(int i = 0; i < fList.length; i++) { - File file = new File(testDir, fList[i]); - if(file.isDirectory()) { - cleanUpDirectory(testDir, fList[i]); - } else { - file.delete(); - } - } - } - - @SmallTest - public void testDeleteAllCacheFiles() { - String testName="testDeleteAllCacheFiles"; - cleanUpCacheDirectory(); - } - - void failStr(String errMsg) { - Log.w(TAG, "errMsg="+errMsg); - fail(errMsg); - } - void failStr(Exception e) { - Log.w(TAG, "e.getMessage="+e.getMessage()); - Log.w(TAG, "e="+e); - } - long getFreeStorageBlks(StatFs st) { - st.restat("/data"); - return st.getFreeBlocks(); - } - - long getFreeStorageSize(StatFs st) { - st.restat("/data"); - return (st.getFreeBlocks()*st.getBlockSize()); - } - @LargeTest - public void testFreeApplicationCacheAllFiles() throws Exception { - boolean TRACKING = true; - StatFs st = new StatFs("/data"); - long blks1 = getFreeStorageBlks(st); - long availableMem = getFreeStorageSize(st); - File cacheDir = mContext.getCacheDir(); - assertNotNull(cacheDir); - createTestFiles1(cacheDir, "testtmpdir", 5); - long blks2 = getFreeStorageBlks(st); - if(localLOGV || TRACKING) Log.i(TAG, "blk1="+blks1+", blks2="+blks2); - //this should free up the test files that were created earlier - invokePMFreeApplicationCache(availableMem); - long blks3 = getFreeStorageBlks(st); - if(localLOGV || TRACKING) Log.i(TAG, "blks3="+blks3); - verifyTestFiles1(cacheDir, "testtmpdir", 5); - } - - public void testFreeApplicationCacheSomeFiles() throws Exception { - StatFs st = new StatFs("/data"); - long blks1 = getFreeStorageBlks(st); - File cacheDir = mContext.getCacheDir(); - assertNotNull(cacheDir); - createTestFiles1(cacheDir, "testtmpdir", 5); - long blks2 = getFreeStorageBlks(st); - Log.i(TAG, "blk1="+blks1+", blks2="+blks2); - long diff = (blks1-blks2-2); - assertTrue(invokePMFreeApplicationCache(diff*st.getBlockSize())); - long blks3 = getFreeStorageBlks(st); - //blks3 should be greater than blks2 and less than blks1 - if(!((blks3 <= blks1) && (blks3 >= blks2))) { - failStr("Expected "+(blks1-blks2)+" number of blocks to be freed but freed only " - +(blks1-blks3)); - } - } - - /** - * This method opens an output file writes to it, opens the same file as an input - * stream, reads the contents and verifies the data that was written earlier can be read - */ - public void openOutFileInAppFilesDir(File pFile, String pFileOut) { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(pFile); - } catch (FileNotFoundException e1) { - failStr("Error when opening file "+e1); - return; - } - try { - fos.write(pFileOut.getBytes()); - fos.close(); - } catch (FileNotFoundException e) { - failStr(e.getMessage()); - } catch (IOException e) { - failStr(e.getMessage()); - } - int count = pFileOut.getBytes().length; - byte[] buffer = new byte[count]; - try { - FileInputStream fis = new FileInputStream(pFile); - fis.read(buffer, 0, count); - fis.close(); - } catch (FileNotFoundException e) { - failStr("Failed when verifing output opening file "+e.getMessage()); - } catch (IOException e) { - failStr("Failed when verifying output, reading from written file "+e); - } - String str = new String(buffer); - assertEquals(str, pFileOut); - } - - /* - * This test case verifies that output written to a file - * using Context.openFileOutput has executed successfully. - * The operation is verified by invoking Context.openFileInput - */ - @MediumTest - public void testAppFilesCreateFile() { - String fileName = "testFile1.txt"; - String fileOut = "abcdefghijklmnopqrstuvwxyz"; - Context con = super.getContext(); - try { - FileOutputStream fos = con.openFileOutput(fileName, Context.MODE_PRIVATE); - fos.close(); - } catch (FileNotFoundException e) { - failStr(e); - } catch (IOException e) { - failStr(e); - } - } - - @SmallTest - public void testAppCacheCreateFile() { - String fileName = "testFile1.txt"; - String fileOut = "abcdefghijklmnopqrstuvwxyz"; - Context con = super.getContext(); - File file = new File(con.getCacheDir(), fileName); - openOutFileInAppFilesDir(file, fileOut); - cleanUpCacheDirectory(); - } - - @MediumTest - public void testAppCreateCacheFiles() { - File cacheDir = mContext.getCacheDir(); - String testDirName = "testtmp"; - File testTmpDir = new File(cacheDir, testDirName); - testTmpDir.mkdir(); - int numDirs = 3; - File fileArr[] = new File[numDirs]; - for(int i = 0; i < numDirs; i++) { - fileArr[i] = new File(testTmpDir, "dir"+(i+1)); - fileArr[i].mkdir(); - } - byte buffer[] = getBuffer(); - Log.i(TAG, "Size of bufer="+buffer.length); - for(int i = 0; i < numDirs; i++) { - for(int j = 1; j <= (i); j++) { - File file1 = new File(fileArr[i], "testFile"+j+".txt"); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(file1); - for(int k = 1; k < 10; k++) { - fos.write(buffer); - } - Log.i(TAG, "wrote 10K bytes to "+file1); - fos.close(); - } catch (FileNotFoundException e) { - Log.i(TAG, "Excetion ="+e); - fail("Error when creating outputstream "+e); - } catch(IOException e) { - Log.i(TAG, "Excetion ="+e); - fail("Error when writing output "+e); - } - } - } - } - - byte[] getBuffer() { - String sbuffer = "a"; - for(int i = 0; i < 10; i++) { - sbuffer += sbuffer; - } - return sbuffer.getBytes(); - } - - long getFileNumBlocks(long fileSize, int blkSize) { - long ret = fileSize/blkSize; - if(ret*blkSize < fileSize) { - ret++; - } - return ret; - } - - //@LargeTest - public void testAppCacheClear() { - String dataDir="/data/data"; - StatFs st = new StatFs(dataDir); - int blkSize = st.getBlockSize(); - int totBlks = st.getBlockCount(); - long availableBlks = st.getFreeBlocks(); - long thresholdBlks = (totBlks*THRESHOLD)/100; - String testDirName = "testdir"; - //create directory in cache - File testDir = new File(mContext.getCacheDir(), testDirName); - testDir.mkdirs(); - byte[] buffer = getBuffer(); - int i = 1; - if(localLOGV) Log.i(TAG, "availableBlks="+availableBlks+", thresholdBlks="+thresholdBlks); - long createdFileBlks = 0; - int imax = 300; - while((availableBlks > thresholdBlks) &&(i < imax)) { - File testFile = new File(testDir, "testFile"+i+".txt"); - if(localLOGV) Log.i(TAG, "Creating "+i+"th test file "+testFile); - int jmax = i; - i++; - FileOutputStream fos; - try { - fos = new FileOutputStream(testFile); - } catch (FileNotFoundException e) { - Log.i(TAG, "Failed creating test file:"+testFile); - continue; - } - boolean err = false; - for(int j = 1; j <= jmax;j++) { - try { - fos.write(buffer); - } catch (IOException e) { - Log.i(TAG, "Failed to write to file:"+testFile); - err = true; - } - } - try { - fos.close(); - } catch (IOException e) { - Log.i(TAG, "Failed closing file:"+testFile); - } - if(err) { - continue; - } - createdFileBlks += getFileNumBlocks(testFile.length(), blkSize); - st.restat(dataDir); - availableBlks = st.getFreeBlocks(); - } - st.restat(dataDir); - long availableBytes = st.getFreeBlocks()*blkSize; - long shouldFree = (ACTUAL_THRESHOLD-THRESHOLD)*totBlks; - //would have run out of memory - //wait for some time and confirm cache is deleted - try { - Log.i(TAG, "Sleeping for 2 minutes..."); - Thread.sleep(2*60*1000); - } catch (InterruptedException e) { - fail("Exception when sleeping "+e); - } - boolean removedFlag = false; - long existingFileBlks = 0; - for(int k = 1; k <i; k++) { - File testFile = new File(testDir, "testFile"+k+".txt"); - if(!testFile.exists()) { - removedFlag = true; - if(localLOGV) Log.i(TAG, testFile+" removed"); - } else { - existingFileBlks += getFileNumBlocks(testFile.length(), blkSize); - } - } - if(localLOGV) Log.i(TAG, "createdFileBlks="+createdFileBlks+ - ", existingFileBlks="+existingFileBlks); - long fileSize = createdFileBlks-existingFileBlks; - //verify fileSize number of bytes have been cleared from cache - if(localLOGV) Log.i(TAG, "deletedFileBlks="+fileSize+" shouldFreeBlks="+shouldFree); - if((fileSize > (shouldFree-blkSize) && (fileSize < (shouldFree+blkSize)))) { - Log.i(TAG, "passed"); - } - assertTrue(removedFlag); - } - - //createTestFiles(new File(super.getContext().getCacheDir(), "testtmp", "dir", 3) - void createTestFiles1(File cacheDir, String testFilePrefix, int numTestFiles) { - byte buffer[] = getBuffer(); - for(int i = 0; i < numTestFiles; i++) { - File file1 = new File(cacheDir, testFilePrefix+i+".txt"); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(file1); - for(int k = 1; k < 10; k++) { - fos.write(buffer); - } - fos.close(); - } catch (FileNotFoundException e) { - Log.i(TAG, "Exception ="+e); - fail("Error when creating outputstream "+e); - } catch(IOException e) { - Log.i(TAG, "Exception ="+e); - fail("Error when writing output "+e); - } - try { - //introduce sleep for 1 s to avoid common time stamps for files being created - Thread.sleep(1000); - } catch (InterruptedException e) { - fail("Exception when sleeping "+e); - } - } - } - - void verifyTestFiles1(File cacheDir, String testFilePrefix, int numTestFiles) { - for(int i = 0; i < numTestFiles; i++) { - File file1 = new File(cacheDir, testFilePrefix+i+".txt"); - if(file1.exists()) { - fail("file:"+file1+" should not exist"); - } - } - } - - void createTestFiles2(File cacheDir, String rootTestDirName, String subDirPrefix, int numDirs, String testFilePrefix) { - Context con = super.getContext(); - File testTmpDir = new File(cacheDir, rootTestDirName); - testTmpDir.mkdir(); - File fileArr[] = new File[numDirs]; - for(int i = 0; i < numDirs; i++) { - fileArr[i] = new File(testTmpDir, subDirPrefix+(i+1)); - fileArr[i].mkdir(); - } - byte buffer[] = getBuffer(); - for(int i = 0; i < numDirs; i++) { - for(int j = 1; j <= (i); j++) { - File file1 = new File(fileArr[i], testFilePrefix+j+".txt"); - FileOutputStream fos = null; - try { - fos = new FileOutputStream(file1); - for(int k = 1; k < 10; k++) { - fos.write(buffer); - } - fos.close(); - } catch (FileNotFoundException e) { - Log.i(TAG, "Exception ="+e); - fail("Error when creating outputstream "+e); - } catch(IOException e) { - Log.i(TAG, "Exception ="+e); - fail("Error when writing output "+e); - } - try { - //introduce sleep for 10 ms to avoid common time stamps for files being created - Thread.sleep(10); - } catch (InterruptedException e) { - fail("Exception when sleeping "+e); - } - } - } - } - - class PackageDataObserver extends IPackageDataObserver.Stub { - public boolean retValue = false; - private boolean doneFlag = false; - public void onRemoveCompleted(String packageName, boolean succeeded) - throws RemoteException { - synchronized(this) { - retValue = succeeded; - doneFlag = true; - notifyAll(); - } - } - public boolean isDone() { - return doneFlag; - } - } - - IPackageManager getPm() { - return IPackageManager.Stub.asInterface(ServiceManager.getService("package")); - } - - boolean invokePMDeleteAppCacheFiles() throws Exception { - try { - String packageName = mContext.getPackageName(); - PackageDataObserver observer = new PackageDataObserver(); - //wait on observer - synchronized(observer) { - getPm().deleteApplicationCacheFiles(packageName, observer); - long waitTime = 0; - while(!observer.isDone() || (waitTime > MAX_WAIT_TIME)) { - observer.wait(WAIT_TIME_INCR); - waitTime += WAIT_TIME_INCR; - } - if(!observer.isDone()) { - throw new Exception("timed out waiting for PackageDataObserver.onRemoveCompleted"); - } - } - return observer.retValue; - } catch (RemoteException e) { - Log.w(TAG, "Failed to get handle for PackageManger Exception: "+e); - return false; - } catch (InterruptedException e) { - Log.w(TAG, "InterruptedException :"+e); - return false; - } - } - - boolean invokePMFreeApplicationCache(long idealStorageSize) throws Exception { - try { - String packageName = mContext.getPackageName(); - PackageDataObserver observer = new PackageDataObserver(); - //wait on observer - synchronized(observer) { - getPm().freeStorageAndNotify(idealStorageSize, observer); - long waitTime = 0; - while(!observer.isDone() || (waitTime > MAX_WAIT_TIME)) { - observer.wait(WAIT_TIME_INCR); - waitTime += WAIT_TIME_INCR; - } - if(!observer.isDone()) { - throw new Exception("timed out waiting for PackageDataObserver.onRemoveCompleted"); - } - } - return observer.retValue; - } catch (RemoteException e) { - Log.w(TAG, "Failed to get handle for PackageManger Exception: "+e); - return false; - } catch (InterruptedException e) { - Log.w(TAG, "InterruptedException :"+e); - return false; - } - } - - boolean invokePMFreeStorage(long idealStorageSize, FreeStorageReceiver r, - PendingIntent pi) throws Exception { - try { - // Spin lock waiting for call back - synchronized(r) { - getPm().freeStorage(idealStorageSize, pi.getIntentSender()); - long waitTime = 0; - while(!r.isDone() && (waitTime < MAX_WAIT_TIME)) { - r.wait(WAIT_TIME_INCR); - waitTime += WAIT_TIME_INCR; - } - if(!r.isDone()) { - throw new Exception("timed out waiting for call back from PendingIntent"); - } - } - return r.getResultCode() == 1; - } catch (RemoteException e) { - Log.w(TAG, "Failed to get handle for PackageManger Exception: "+e); - return false; - } catch (InterruptedException e) { - Log.w(TAG, "InterruptedException :"+e); - return false; - } - } - - @LargeTest - public void testDeleteAppCacheFiles() throws Exception { - String testName="testDeleteAppCacheFiles"; - File cacheDir = mContext.getCacheDir(); - createTestFiles1(cacheDir, "testtmpdir", 5); - assertTrue(invokePMDeleteAppCacheFiles()); - //confirm files dont exist - verifyTestFiles1(cacheDir, "testtmpdir", 5); - } - - class PackageStatsObserver extends IPackageStatsObserver.Stub { - public boolean retValue = false; - public PackageStats stats; - private boolean doneFlag = false; - - public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) - throws RemoteException { - synchronized(this) { - retValue = succeeded; - stats = pStats; - doneFlag = true; - notifyAll(); - } - } - public boolean isDone() { - return doneFlag; - } - } - - public PackageStats invokePMGetPackageSizeInfo() throws Exception { - try { - String packageName = mContext.getPackageName(); - PackageStatsObserver observer = new PackageStatsObserver(); - //wait on observer - synchronized(observer) { - getPm().getPackageSizeInfo(packageName, observer); - long waitTime = 0; - while((!observer.isDone()) || (waitTime > MAX_WAIT_TIME) ) { - observer.wait(WAIT_TIME_INCR); - waitTime += WAIT_TIME_INCR; - } - if(!observer.isDone()) { - throw new Exception("Timed out waiting for PackageStatsObserver.onGetStatsCompleted"); - } - } - if(localLOGV) Log.i(TAG, "OBSERVER RET VALUES code="+observer.stats.codeSize+ - ", data="+observer.stats.dataSize+", cache="+observer.stats.cacheSize); - return observer.stats; - } catch (RemoteException e) { - Log.w(TAG, "Failed to get handle for PackageManger Exception: "+e); - return null; - } catch (InterruptedException e) { - Log.w(TAG, "InterruptedException :"+e); - return null; - } - } - - @SmallTest - public void testGetPackageSizeInfo() throws Exception { - String testName="testGetPackageSizeInfo"; - PackageStats stats = invokePMGetPackageSizeInfo(); - assertTrue(stats!=null); - //confirm result - if(localLOGV) Log.i(TAG, "code="+stats.codeSize+", data="+stats.dataSize+ - ", cache="+stats.cacheSize); - } - - @SmallTest - public void testGetSystemSharedLibraryNames() throws Exception { - try { - String[] sharedLibs = getPm().getSystemSharedLibraryNames(); - if (localLOGV) { - for (String str : sharedLibs) { - Log.i(TAG, str); - } - } - } catch (RemoteException e) { - fail("Failed invoking getSystemSharedLibraryNames with exception:" + e); - } - } - - class FreeStorageReceiver extends BroadcastReceiver { - public static final String ACTION_FREE = "com.android.unit_tests.testcallback"; - private boolean doneFlag = false; - - public boolean isDone() { - return doneFlag; - } - - @Override - public void onReceive(Context context, Intent intent) { - if(intent.getAction().equalsIgnoreCase(ACTION_FREE)) { - if (localLOGV) Log.i(TAG, "Got notification: clear cache succeeded "+getResultCode()); - synchronized (this) { - doneFlag = true; - notifyAll(); - } - } - } - } - - @SmallTest - public void testFreeStorage() throws Exception { - boolean TRACKING = true; - StatFs st = new StatFs("/data"); - long blks1 = getFreeStorageBlks(st); - if(localLOGV || TRACKING) Log.i(TAG, "Available free blocks="+blks1); - long availableMem = getFreeStorageSize(st); - File cacheDir = mContext.getCacheDir(); - assertNotNull(cacheDir); - createTestFiles1(cacheDir, "testtmpdir", 5); - long blks2 = getFreeStorageBlks(st); - if(localLOGV || TRACKING) Log.i(TAG, "Available blocks after writing test files in application cache="+blks2); - // Create receiver and register it - FreeStorageReceiver receiver = new FreeStorageReceiver(); - mContext.registerReceiver(receiver, new IntentFilter(FreeStorageReceiver.ACTION_FREE)); - PendingIntent pi = PendingIntent.getBroadcast(mContext, - 0, new Intent(FreeStorageReceiver.ACTION_FREE), 0); - // Invoke PackageManager api - invokePMFreeStorage(availableMem, receiver, pi); - long blks3 = getFreeStorageBlks(st); - if(localLOGV || TRACKING) Log.i(TAG, "Available blocks after freeing cache"+blks3); - assertEquals(receiver.getResultCode(), 1); - mContext.unregisterReceiver(receiver); - // Verify result - verifyTestFiles1(cacheDir, "testtmpdir", 5); - } - - /* utility method used to create observer and check async call back from PackageManager. - * ClearApplicationUserData - */ - boolean invokePMClearApplicationUserData() throws Exception { - try { - String packageName = mContext.getPackageName(); - PackageDataObserver observer = new PackageDataObserver(); - //wait on observer - synchronized(observer) { - getPm().clearApplicationUserData(packageName, observer); - long waitTime = 0; - while(!observer.isDone() || (waitTime > MAX_WAIT_TIME)) { - observer.wait(WAIT_TIME_INCR); - waitTime += WAIT_TIME_INCR; - } - if(!observer.isDone()) { - throw new Exception("timed out waiting for PackageDataObserver.onRemoveCompleted"); - } - } - return observer.retValue; - } catch (RemoteException e) { - Log.w(TAG, "Failed to get handle for PackageManger Exception: "+e); - return false; - } catch (InterruptedException e) { - Log.w(TAG, "InterruptedException :"+e); - return false; - } - } - - void verifyUserDataCleared(File pDir) { - if(localLOGV) Log.i(TAG, "Verifying "+pDir); - if(pDir == null) { - return; - } - String fileList[] = pDir.list(); - if(fileList == null) { - return; - } - int imax = fileList.length; - //look recursively in user data dir - for(int i = 0; i < imax; i++) { - if(localLOGV) Log.i(TAG, "Found entry "+fileList[i]+ "in "+pDir); - if("lib".equalsIgnoreCase(fileList[i])) { - if(localLOGV) Log.i(TAG, "Ignoring lib directory"); - continue; - } - fail(pDir+" should be empty or contain only lib subdirectory. Found "+fileList[i]); - } - } - - File getDataDir() { - try { - ApplicationInfo appInfo = getPm().getApplicationInfo(mContext.getPackageName(), 0); - return new File(appInfo.dataDir); - } catch (RemoteException e) { - throw new RuntimeException("Pacakge manager dead", e); - } - } - - @LargeTest - public void testClearApplicationUserDataWithTestData() throws Exception { - File cacheDir = mContext.getCacheDir(); - createTestFiles1(cacheDir, "testtmpdir", 5); - if(localLOGV) { - Log.i(TAG, "Created test data Waiting for 60seconds before continuing"); - Thread.sleep(60*1000); - } - assertTrue(invokePMClearApplicationUserData()); - //confirm files dont exist - verifyUserDataCleared(getDataDir()); - } - - @SmallTest - public void testClearApplicationUserDataWithNoTestData() throws Exception { - assertTrue(invokePMClearApplicationUserData()); - //confirm files dont exist - verifyUserDataCleared(getDataDir()); - } - - @LargeTest - public void testClearApplicationUserDataNoObserver() throws Exception { - getPm().clearApplicationUserData(mContext.getPackageName(), null); - //sleep for 1 minute - Thread.sleep(60*1000); - //confirm files dont exist - verifyUserDataCleared(getDataDir()); - } - -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/ArrayListTest.java b/tests/AndroidTests/src/com/android/unit_tests/ArrayListTest.java deleted file mode 100644 index 81e6efd..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/ArrayListTest.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import java.util.ArrayList; -import android.test.PerformanceTestBase; - -public class ArrayListTest extends PerformanceTestBase { - - private ArrayList<Integer> mList; - - @Override - @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - - mList = new ArrayList(); - mList.add(0); - mList.add(1); - mList.add(2); - mList.add(3); - mList.add(4); - mList.add(5); - mList.add(6); - mList.add(7); - mList.add(8); - mList.add(9); - } - - public void testArrayListAdd() { - int i = 0; - for (; i < 10; i++) { - mList.add(i); - mList.add(i); - mList.add(i); - mList.add(i); - mList.add(i); - mList.add(i); - mList.add(i); - mList.add(i); - mList.add(i); - mList.add(i); - } - } - - public void testArrayListAdd1() { - int i = 0; - for (; i < 10; i++) { - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - mList.add(7, i); - } - } - - public void testArrayListToArray() { - Object rArray; - int i = 0; - for (; i < 100; i++) { - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - rArray = mList.toArray(); - } - } - - public void testArrayListSize() { - int i = 0, len; - for (; i < 100; i++) { - len = mList.size(); - len = mList.size(); - len = mList.size(); - len = mList.size(); - len = mList.size(); - len = mList.size(); - len = mList.size(); - len = mList.size(); - len = mList.size(); - len = mList.size(); - } - } - - public void testArrayListGet() { - int i = 0, value; - int len = mList.size(); - for (; i < len; i++) { - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - value = mList.get(i); - } - } - - public void testArrayListContains() { - boolean flag; - int i = 0; - - for (; i < 100; i++) { - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - flag = mList.contains(i); - - } - } - - public void testArrayListToArray1() { - Integer[] rArray = new Integer[10]; - - Integer[] mArray; - int i = 0; - for (; i < 100; i++) { - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - mArray = mList.toArray(rArray); - } - } - - public void testArrayListSet() { - int i = 0; - for (; i < 10; i++) { - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - mList.set(5, 0); - } - } - - public void testArrayListIndexOf() { - int i = 0, index; - - for (; i < 100; i++) { - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - index = mList.indexOf(0); - } - } - - public void testArrayListLastIndexOf() { - int i = 0, index; - - for (; i < 100; i++) { - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - index = mList.lastIndexOf(0); - } - } - - @SuppressWarnings("unchecked") - public void testArrayListRemove() { - ArrayList<Integer> aList; - aList = new ArrayList(); - for (int j = 0; j < 10000; j++) { - aList.add(0); - } - - int i = 0, index; - - for (; i < 10; i++) { - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - index = aList.remove(0); - - - } - } - - @SuppressWarnings("unchecked") - public void testArrayListAddAll() { - ArrayList<Integer> aList = new ArrayList(); - - int i = 0; - boolean b; - for (; i < 10; i++) { - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - b = aList.addAll(mList); - - } - } - - @SuppressWarnings("unchecked") - public void testArrayListRemove1() { - ArrayList<String> aList; - String s; - - aList = new ArrayList(); - for (int j = 0; j < 100; j++) { - aList.add("a"); - aList.add("b"); - } - s = new String("a"); - - int i = 0; - boolean b; - for (; i < 10; i++) { - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - b = aList.remove(s); - } - } - - @SuppressWarnings("unchecked") - public void testArrayListAddAll1() { - ArrayList<Integer> aList = new ArrayList(); - - int i = 0; - boolean b; - - for (; i < 10; i++) { - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - b = aList.addAll(0, mList); - } - } - - public void testArrayListClone() { - Object rObj; - int i = 0; - - for (; i < 100; i++) { - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - rObj = mList.clone(); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/BrickDeniedTest.java b/tests/AndroidTests/src/com/android/unit_tests/BrickDeniedTest.java deleted file mode 100644 index 0f2b23b..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/BrickDeniedTest.java +++ /dev/null @@ -1,33 +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 com.android.unit_tests; - -import android.content.Intent; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; - -/** Test to make sure brick intents <b>don't</b> work without permission. */ -public class BrickDeniedTest extends AndroidTestCase { - @MediumTest - public void testBrick() { - // Try both the old and new brick intent names. Neither should work, - // since this test application doesn't have the required permission. - // If it does work, well, the test certainly won't pass. - getContext().sendBroadcast(new Intent("SHES_A_BRICK_HOUSE")); - getContext().sendBroadcast(new Intent("android.intent.action.BRICK")); - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/ComponentTest.java b/tests/AndroidTests/src/com/android/unit_tests/ComponentTest.java deleted file mode 100644 index 08fe742..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/ComponentTest.java +++ /dev/null @@ -1,738 +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 com.android.unit_tests; - -import com.android.unit_tests.enabled_app.DisabledActivity; -import com.android.unit_tests.enabled_app.DisabledProvider; -import com.android.unit_tests.enabled_app.DisabledReceiver; -import com.android.unit_tests.enabled_app.DisabledService; -import com.android.unit_tests.enabled_app.EnabledActivity; -import com.android.unit_tests.enabled_app.EnabledProvider; -import com.android.unit_tests.enabled_app.EnabledReceiver; -import com.android.unit_tests.enabled_app.EnabledService; - -import android.content.ComponentName; -import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.content.pm.ComponentInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; -import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; -import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; -import static android.content.pm.PackageManager.GET_DISABLED_COMPONENTS; -import android.content.pm.ProviderInfo; -import android.content.pm.ResolveInfo; -import android.content.pm.ServiceInfo; -import android.test.AndroidTestCase; - -import java.util.List; - -/** - * Tests for disabling and enabling application components. - * - * Note: These tests are on the slow side. This is probably because most of the tests trigger the - * package settings file to get written out by the PackageManagerService. Better, more unit-y test - * would fix this. - */ - -public class ComponentTest extends AndroidTestCase { - - private PackageManager mPackageManager; - private Intent mDisabledActivityIntent; - private Intent mEnabledActivityIntent; - private Intent mDisabledServiceIntent; - private Intent mEnabledServiceIntent; - private Intent mDisabledReceiverIntent; - private Intent mEnabledReceiverIntent; - private Intent mDisabledAppEnabledActivityIntent; - - private static final String ENABLED_PACKAGENAME = - "com.android.unit_tests.enabled_app"; - private static final String DISABLED_PACKAGENAME = - "com.android.unit_tests.disabled_app"; - private static final String DISABLED_ACTIVITY_CLASSNAME = - DisabledActivity.class.getName(); - private static final ComponentName DISABLED_ACTIVITY_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, DISABLED_ACTIVITY_CLASSNAME); - private static final String ENABLED_ACTIVITY_CLASSNAME = - EnabledActivity.class.getName(); - private static final ComponentName ENABLED_ACTIVITY_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, ENABLED_ACTIVITY_CLASSNAME); - private static final String DISABLED_SERVICE_CLASSNAME = - DisabledService.class.getName(); - private static final ComponentName DISABLED_SERVICE_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, DISABLED_SERVICE_CLASSNAME); - private static final String DISABLED_PROVIDER_CLASSNAME = - DisabledProvider.class.getName(); - private static final ComponentName DISABLED_PROVIDER_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, DISABLED_PROVIDER_CLASSNAME); - private static final String DISABLED_PROVIDER_NAME = DisabledProvider.class.getName(); - private static final String ENABLED_SERVICE_CLASSNAME = - EnabledService.class.getName(); - private static final ComponentName ENABLED_SERVICE_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, ENABLED_SERVICE_CLASSNAME); - private static final String DISABLED_RECEIVER_CLASSNAME = - DisabledReceiver.class.getName(); - private static final ComponentName DISABLED_RECEIVER_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, DISABLED_RECEIVER_CLASSNAME); - private static final String ENABLED_RECEIVER_CLASSNAME = - EnabledReceiver.class.getName(); - private static final ComponentName ENABLED_RECEIVER_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, ENABLED_RECEIVER_CLASSNAME); - private static final String ENABLED_PROVIDER_CLASSNAME = - EnabledProvider.class.getName(); - private static final ComponentName ENABLED_PROVIDER_COMPONENTNAME = - new ComponentName(ENABLED_PACKAGENAME, ENABLED_PROVIDER_CLASSNAME); - private static final String ENABLED_PROVIDER_NAME = EnabledProvider.class.getName(); - private static final String DISABLED_APP_ENABLED_ACTIVITY_CLASSNAME = - com.android.unit_tests.disabled_app.EnabledActivity.class.getName(); - private static final ComponentName DISABLED_APP_ENABLED_ACTIVITY_COMPONENTNAME = - new ComponentName(DISABLED_PACKAGENAME, DISABLED_APP_ENABLED_ACTIVITY_CLASSNAME); - private static final String TEST_CATEGORY = - "com.android.unit_tests.enabled_app.TEST_CATEGORY"; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mPackageManager = mContext.getPackageManager(); - mDisabledActivityIntent = new Intent(); - mDisabledActivityIntent.setComponent(DISABLED_ACTIVITY_COMPONENTNAME); - mEnabledActivityIntent = new Intent(); - mEnabledActivityIntent.setComponent(ENABLED_ACTIVITY_COMPONENTNAME); - mDisabledServiceIntent = new Intent(); - mDisabledServiceIntent.setComponent(DISABLED_SERVICE_COMPONENTNAME); - mEnabledServiceIntent = new Intent(); - mEnabledServiceIntent.setComponent(ENABLED_SERVICE_COMPONENTNAME); - mDisabledReceiverIntent = new Intent("android.intent.action.ENABLED_APP_DISABLED_RECEIVER"); - mDisabledReceiverIntent.setComponent(DISABLED_RECEIVER_COMPONENTNAME); - mEnabledReceiverIntent = new Intent("android.intent.action.ENABLED_APP_ENABLED_RECEIVER"); - mEnabledReceiverIntent.setComponent(ENABLED_RECEIVER_COMPONENTNAME); - mDisabledAppEnabledActivityIntent = new Intent(); - mDisabledAppEnabledActivityIntent.setComponent(DISABLED_APP_ENABLED_ACTIVITY_COMPONENTNAME); - } - - @SmallTest - public void testContextNotNull() throws Exception { - assertNotNull(mContext); - } - - @MediumTest - public void testResolveDisabledActivity() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveActivity(mDisabledActivityIntent, 0); - assertNull(info); - - final ResolveInfo info2 = mPackageManager.resolveActivity( - mDisabledActivityIntent, GET_DISABLED_COMPONENTS); - assertNotNull(info2); - assertNotNull(info2.activityInfo); - assertFalse(info2.activityInfo.enabled); - } - - @MediumTest - public void testResolveEnabledActivity() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveActivity(mEnabledActivityIntent, 0); - assertNotNull(info); - assertNotNull(info); - assertNotNull(info.activityInfo); - assertTrue(info.activityInfo.enabled); - } - - @MediumTest - public void testQueryDisabledActivity() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final List<ResolveInfo> infoList = - mPackageManager.queryIntentActivities(mDisabledActivityIntent, 0); - assertEquals(0, infoList.size()); - - final List<ResolveInfo> infoList2 = - mPackageManager.queryIntentActivities(mDisabledActivityIntent, - GET_DISABLED_COMPONENTS); - assertEquals(1, infoList2.size()); - final ResolveInfo info = infoList2.get(0); - assertNotNull(info); - assertNotNull(info.activityInfo); - assertFalse(info.activityInfo.enabled); - } - - @MediumTest - public void testQueryEnabledActivity() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final List<ResolveInfo> infoList = - mPackageManager.queryIntentActivities(mEnabledActivityIntent, 0); - assertEquals(1, infoList.size()); - final ResolveInfo info = infoList.get(0); - assertNotNull(info); - assertNotNull(info.activityInfo); - assertTrue(info.activityInfo.enabled); - } - - @MediumTest - public void testGetDisabledActivityInfo() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - try { - mPackageManager.getActivityInfo(DISABLED_ACTIVITY_COMPONENTNAME, 0); - fail("Attempt to get info on disabled component should fail."); - } catch (PackageManager.NameNotFoundException e) { - // expected - } - - final ActivityInfo activityInfo = - mPackageManager.getActivityInfo(DISABLED_ACTIVITY_COMPONENTNAME, - GET_DISABLED_COMPONENTS); - assertNotNull(activityInfo); - assertFalse(activityInfo.enabled); - } - - @MediumTest - public void testGetEnabledActivityInfo() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - ActivityInfo activityInfo = - mPackageManager.getActivityInfo(ENABLED_ACTIVITY_COMPONENTNAME, 0); - assertNotNull(activityInfo); - assertTrue(activityInfo.enabled); - } - - @MediumTest - public void testEnableActivity() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveActivity(mDisabledActivityIntent, 0); - assertNull(info); - mPackageManager.setComponentEnabledSetting(DISABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - final ResolveInfo info2 = - mPackageManager.resolveActivity(mDisabledActivityIntent, - 0); - assertNotNull(info2); - assertNotNull(info2.activityInfo); - assertFalse(info2.activityInfo.enabled); - - final List<ResolveInfo> infoList = - mPackageManager.queryIntentActivities(mDisabledActivityIntent, 0); - assertEquals(1, infoList.size()); - } - - @LargeTest - public void testDisableActivity() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveActivity(mEnabledActivityIntent, 0); - assertNotNull(info); - assertNotNull(info.activityInfo); - mPackageManager.setComponentEnabledSetting(ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DISABLED, - PackageManager.DONT_KILL_APP); - final ResolveInfo info2 = - mPackageManager.resolveActivity(mEnabledActivityIntent, - 0); - assertNull(info2); - - final ResolveInfo info3 = mPackageManager.resolveActivity(mEnabledActivityIntent, - GET_DISABLED_COMPONENTS); - assertNotNull(info3); - assertNotNull(info3.activityInfo); - assertTrue(info3.activityInfo.enabled); - - final List<ResolveInfo> infoList = - mPackageManager.queryIntentActivities(mEnabledActivityIntent, 0); - assertEquals(0, infoList.size()); - } - - @MediumTest - public void testResolveDisabledService() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveService(mDisabledServiceIntent, 0); - assertNull(info); - - final ResolveInfo info2 = mPackageManager.resolveService( - mDisabledServiceIntent, GET_DISABLED_COMPONENTS); - assertNotNull(info2); - assertNotNull(info2.serviceInfo); - assertFalse(info2.serviceInfo.enabled); - } - - @MediumTest - public void testResolveEnabledService() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveService(mEnabledServiceIntent, 0); - assertNotNull(info); - assertNotNull(info); - assertNotNull(info.serviceInfo); - assertTrue(info.serviceInfo.enabled); - } - - @MediumTest - public void testQueryDisabledService() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final List<ResolveInfo> infoList = - mPackageManager.queryIntentServices(mDisabledServiceIntent, 0); - assertEquals(0, infoList.size()); - - final List<ResolveInfo> infoList2 = - mPackageManager.queryIntentServices(mDisabledServiceIntent, - GET_DISABLED_COMPONENTS); - assertEquals(1, infoList2.size()); - final ResolveInfo info = infoList2.get(0); - assertNotNull(info); - assertNotNull(info.serviceInfo); - assertFalse(info.serviceInfo.enabled); - } - - @MediumTest - public void testQueryEnabledService() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final List<ResolveInfo> infoList = - mPackageManager.queryIntentServices(mEnabledServiceIntent, 0); - assertEquals(1, infoList.size()); - final ResolveInfo info = infoList.get(0); - assertNotNull(info); - assertNotNull(info.serviceInfo); - assertTrue(info.serviceInfo.enabled); - } - - @MediumTest - public void testGetDisabledServiceInfo() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - try { - mPackageManager.getServiceInfo(DISABLED_SERVICE_COMPONENTNAME, 0); - fail("Attempt to get info on disabled component should fail."); - } catch (PackageManager.NameNotFoundException e) { - // expected - } - - final ServiceInfo serviceInfo = - mPackageManager.getServiceInfo(DISABLED_SERVICE_COMPONENTNAME, - GET_DISABLED_COMPONENTS); - assertNotNull(serviceInfo); - assertFalse(serviceInfo.enabled); - } - - @MediumTest - public void testGetEnabledServiceInfo() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - ServiceInfo serviceInfo = - mPackageManager.getServiceInfo(ENABLED_SERVICE_COMPONENTNAME, 0); - assertNotNull(serviceInfo); - assertTrue(serviceInfo.enabled); - } - - @MediumTest - public void testEnableService() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveService(mDisabledServiceIntent, 0); - assertNull(info); - mPackageManager.setComponentEnabledSetting(DISABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - final ResolveInfo info2 = - mPackageManager.resolveService(mDisabledServiceIntent, - 0); - assertNotNull(info2); - assertNotNull(info2.serviceInfo); - assertFalse(info2.serviceInfo.enabled); - } - - @LargeTest - public void testDisableService() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveService(mEnabledServiceIntent, 0); - assertNotNull(info); - assertNotNull(info.serviceInfo); - mPackageManager.setComponentEnabledSetting(ENABLED_SERVICE_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DISABLED, - PackageManager.DONT_KILL_APP); - final ResolveInfo info2 = - mPackageManager.resolveService(mEnabledServiceIntent, - 0); - assertNull(info2); - - final ResolveInfo info3 = mPackageManager.resolveService(mEnabledServiceIntent, - GET_DISABLED_COMPONENTS); - assertNotNull(info3); - assertNotNull(info3.serviceInfo); - assertTrue(info3.serviceInfo.enabled); - } - - @MediumTest - public void testQueryDisabledReceiver() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final List<ResolveInfo> infoList = - mPackageManager.queryBroadcastReceivers(mDisabledReceiverIntent, 0); - assertEquals(0, infoList.size()); - - final List<ResolveInfo> infoList2 = - mPackageManager.queryBroadcastReceivers(mDisabledReceiverIntent, - GET_DISABLED_COMPONENTS); - assertEquals(1, infoList2.size()); - final ResolveInfo info = infoList2.get(0); - assertNotNull(info); - assertNotNull(info.activityInfo); - assertFalse(info.activityInfo.enabled); - } - - @MediumTest - public void testQueryEnabledReceiver() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final List<ResolveInfo> infoList = - mPackageManager.queryBroadcastReceivers(mEnabledReceiverIntent, 0); - assertEquals(1, infoList.size()); - final ResolveInfo info = infoList.get(0); - assertNotNull(info); - assertNotNull(info.activityInfo); - assertTrue(info.activityInfo.enabled); - } - - @MediumTest - public void testGetDisabledReceiverInfo() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - try { - mPackageManager.getReceiverInfo(DISABLED_RECEIVER_COMPONENTNAME, 0); - fail("Attempt to get info on disabled component should fail."); - } catch (PackageManager.NameNotFoundException e) { - // expected - } - - final ActivityInfo activityInfo = - mPackageManager.getReceiverInfo(DISABLED_RECEIVER_COMPONENTNAME, - GET_DISABLED_COMPONENTS); - assertNotNull(activityInfo); - assertFalse(activityInfo.enabled); - } - - @MediumTest - public void testGetEnabledReceiverInfo() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - ActivityInfo activityInfo = - mPackageManager.getReceiverInfo(ENABLED_RECEIVER_COMPONENTNAME, 0); - assertNotNull(activityInfo); - assertTrue(activityInfo.enabled); - } - - @MediumTest - public void testEnableReceiver() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - try { - mPackageManager.getReceiverInfo(DISABLED_RECEIVER_COMPONENTNAME, 0); - fail("Attempt to get info on disabled component should fail."); - } catch (PackageManager.NameNotFoundException e) { - // expected - } - - mPackageManager.setComponentEnabledSetting(DISABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - ActivityInfo activityInfo = - mPackageManager.getReceiverInfo(DISABLED_RECEIVER_COMPONENTNAME, 0); - assertNotNull(activityInfo); - assertFalse(activityInfo.enabled); - } - - @MediumTest - public void testDisableReceiver() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - ActivityInfo activityInfo = - mPackageManager.getReceiverInfo(ENABLED_RECEIVER_COMPONENTNAME, 0); - assertNotNull(activityInfo); - assertTrue(activityInfo.enabled); - mPackageManager.setComponentEnabledSetting(DISABLED_RECEIVER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DISABLED, - PackageManager.DONT_KILL_APP); - try { - mPackageManager.getReceiverInfo(DISABLED_RECEIVER_COMPONENTNAME, 0); - fail("Attempt to get info on disabled component should fail."); - } catch (PackageManager.NameNotFoundException e) { - // expected - } - } - - @MediumTest - public void testResolveEnabledProvider() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - ProviderInfo providerInfo = - mPackageManager.resolveContentProvider(ENABLED_PROVIDER_NAME, 0); - assertNotNull(providerInfo); - assertTrue(providerInfo.enabled); - } - - @MediumTest - public void testResolveDisabledProvider() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - ProviderInfo providerInfo = - mPackageManager.resolveContentProvider(DISABLED_PROVIDER_NAME, 0); - assertNull(providerInfo); - ProviderInfo providerInfo2 = - mPackageManager.resolveContentProvider(DISABLED_PROVIDER_NAME, - GET_DISABLED_COMPONENTS); - assertNotNull(providerInfo2); - assertFalse(providerInfo2.enabled); - } - - @MediumTest - public void testEnableProvider() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - ProviderInfo providerInfo = - mPackageManager.resolveContentProvider(DISABLED_PROVIDER_NAME, 0); - assertNull(providerInfo); - - mPackageManager.setComponentEnabledSetting(DISABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - ProviderInfo providerInfo2 = - mPackageManager.resolveContentProvider(DISABLED_PROVIDER_NAME, 0); - assertNotNull(providerInfo2); - assertFalse(providerInfo2.enabled); - } - - @MediumTest - public void testDisableProvider() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - ProviderInfo providerInfo = - mPackageManager.resolveContentProvider(ENABLED_PROVIDER_NAME, 0); - assertNotNull(providerInfo); - assertTrue(providerInfo.enabled); - - mPackageManager.setComponentEnabledSetting(ENABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DISABLED, - PackageManager.DONT_KILL_APP); - ProviderInfo providerInfo2 = - mPackageManager.resolveContentProvider(ENABLED_PROVIDER_NAME, 0); - assertNull(providerInfo2); - } - - @MediumTest - public void testQueryEnabledProvider() throws Exception { - mPackageManager.setComponentEnabledSetting(ENABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - String enabledProviderProcessName = getComponentProcessName(ENABLED_PROVIDER_NAME); - PackageInfo pi = mPackageManager.getPackageInfo(ENABLED_PACKAGENAME, 0); - List<ProviderInfo> providerInfoList = - mPackageManager.queryContentProviders(enabledProviderProcessName, - pi.applicationInfo.uid, 0); - assertNotNull(providerInfoList); - assertEquals(1, providerInfoList.size()); - assertEquals(ENABLED_PROVIDER_CLASSNAME, - providerInfoList.get(0).name); - } - - @MediumTest - public void testQueryDisabledProvider() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_PROVIDER_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - PackageInfo pi = mPackageManager.getPackageInfo(ENABLED_PACKAGENAME, 0); - - String disabledProviderProcessName = getComponentProcessName(DISABLED_PROVIDER_NAME); - List<ProviderInfo> providerInfoList = - mPackageManager.queryContentProviders(disabledProviderProcessName, - pi.applicationInfo.uid, 0); - assertNull(providerInfoList); - - - List<ProviderInfo> providerInfoList2 = - mPackageManager.queryContentProviders(disabledProviderProcessName, - pi.applicationInfo.uid, GET_DISABLED_COMPONENTS); - assertNotNull(providerInfoList2); - assertEquals(1, providerInfoList2.size()); - assertEquals(DISABLED_PROVIDER_CLASSNAME, - providerInfoList2.get(0).name); - } - - private String getComponentProcessName(String componentNameStr) { - ComponentInfo providerInfo = - mPackageManager.resolveContentProvider(componentNameStr, - GET_DISABLED_COMPONENTS); - return providerInfo.processName; - } - - public void DISABLED_testResolveEnabledActivityInDisabledApp() throws Exception { - mPackageManager.setApplicationEnabledSetting(DISABLED_PACKAGENAME, - COMPONENT_ENABLED_STATE_DEFAULT, - 0); - mPackageManager.setComponentEnabledSetting(DISABLED_APP_ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = - mPackageManager.resolveActivity(mDisabledAppEnabledActivityIntent, 0); - assertNull(info); - - final ResolveInfo info2 = mPackageManager.resolveActivity( - mDisabledAppEnabledActivityIntent, GET_DISABLED_COMPONENTS); - assertNotNull(info2); - assertNotNull(info2.activityInfo); - assertTrue(info2.activityInfo.enabled); - } - - public void DISABLED_testEnableApplication() throws Exception { - mPackageManager.setApplicationEnabledSetting(DISABLED_PACKAGENAME, - COMPONENT_ENABLED_STATE_DEFAULT, - 0); - mPackageManager.setComponentEnabledSetting(DISABLED_APP_ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = - mPackageManager.resolveActivity(mDisabledAppEnabledActivityIntent, 0); - assertNull(info); - - mPackageManager.setApplicationEnabledSetting(DISABLED_PACKAGENAME, - COMPONENT_ENABLED_STATE_ENABLED, - 0); - final ResolveInfo info2 = mPackageManager.resolveActivity( - mDisabledAppEnabledActivityIntent, 0); - assertNotNull(info2); - assertNotNull(info2.activityInfo); - assertTrue(info2.activityInfo.enabled); - - } - - public void DISABLED_testDisableApplication() throws Exception { - mPackageManager.setApplicationEnabledSetting(ENABLED_PACKAGENAME, - COMPONENT_ENABLED_STATE_DEFAULT, - 0); - mPackageManager.setComponentEnabledSetting(ENABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - final ResolveInfo info = mPackageManager.resolveActivity(mEnabledActivityIntent, 0); - assertNotNull(info); - assertNotNull(info.activityInfo); - assertTrue(info.activityInfo.enabled); - - mPackageManager.setApplicationEnabledSetting(ENABLED_PACKAGENAME, - COMPONENT_ENABLED_STATE_DISABLED, - 0); - final ResolveInfo info2 = mPackageManager.resolveActivity(mEnabledActivityIntent, 0); - assertNull(info2); - - // Clean up - mPackageManager.setApplicationEnabledSetting(ENABLED_PACKAGENAME, - COMPONENT_ENABLED_STATE_DEFAULT, - 0); - - } - - @MediumTest - public void testNonExplicitResolveAfterEnabling() throws Exception { - mPackageManager.setComponentEnabledSetting(DISABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_DEFAULT, - PackageManager.DONT_KILL_APP); - - Intent intent = new Intent(Intent.ACTION_MAIN, null); - intent.addCategory(TEST_CATEGORY); - - final List<ResolveInfo> launchables = - mPackageManager.queryIntentActivities(intent, 0); - - int numItems = launchables.size(); - assertEquals(0, numItems); - - mPackageManager.setComponentEnabledSetting(DISABLED_ACTIVITY_COMPONENTNAME, - COMPONENT_ENABLED_STATE_ENABLED, - PackageManager.DONT_KILL_APP); - - final List<ResolveInfo> launchables2 = - mPackageManager.queryIntentActivities(intent, 0); - - int numItems2 = launchables2.size(); - assertEquals(1, numItems2); - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/DNParserTest.java b/tests/AndroidTests/src/com/android/unit_tests/DNParserTest.java deleted file mode 100644 index 61d0b42..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/DNParserTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.unit_tests; - -import com.android.internal.net.DNParser; - -import javax.security.auth.x500.X500Principal; - -import junit.framework.TestCase; - -public class DNParserTest extends TestCase { - public void testFind() { - checkFind("", "cn", null); - checkFind("ou=xxx", "cn", null); - checkFind("ou=xxx,cn=xxx", "cn", "xxx"); - checkFind("ou=xxx+cn=yyy,cn=zzz+cn=abc", "cn", "yyy"); - checkFind("2.5.4.3=a,ou=xxx", "cn", "a"); // OID - checkFind("cn=a,cn=b", "cn", "a"); - checkFind("ou=Cc,ou=Bb,ou=Aa", "ou", "Cc"); - checkFind("cn=imap.gmail.com", "cn", "imap.gmail.com"); - - // Quoted string (see http://www.ietf.org/rfc/rfc2253.txt) - checkFind("o=\"\\\" a ,=<>#;\"", "o", "\" a ,=<>#;"); - checkFind("o=abc\\,def", "o", "abc,def"); - - // UTF-8 (example in rfc 2253) - checkFind("cn=Lu\\C4\\8Di\\C4\\87", "cn", "\u004c\u0075\u010d\u0069\u0107"); - - // whitespaces - checkFind("ou=a, o= a b ,cn=x", "o", "a b"); - checkFind("o=\" a b \" ,cn=x", "o", " a b "); - } - - private void checkFind(String dn, String attrType, String expected) { - String actual = new DNParser(new X500Principal(dn)).find(attrType); - assertEquals("dn:" + dn + " attr:" + attrType, expected, actual); - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/DomainNameValidatorTest.java b/tests/AndroidTests/src/com/android/unit_tests/DomainNameValidatorTest.java deleted file mode 100644 index 1754dbe..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/DomainNameValidatorTest.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.unit_tests; - -import com.android.internal.net.DomainNameValidator; - -import android.test.AndroidTestCase; - -import java.io.InputStream; -import java.math.BigInteger; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Principal; -import java.security.PublicKey; -import java.security.SignatureException; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateExpiredException; -import java.security.cert.CertificateFactory; -import java.security.cert.CertificateNotYetValidException; -import java.security.cert.CertificateParsingException; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import javax.security.auth.x500.X500Principal; - -public class DomainNameValidatorTest extends AndroidTestCase { - private static final int ALT_UNKNOWN = 0; - private static final int ALT_DNS_NAME = 2; - private static final int ALT_IPA_NAME = 7; - - /** - * Tests {@link DomainNameValidator#match}, using a simple {@link X509Certificate} - * implementation. - */ - public void testMatch() { - checkMatch("11", new StubX509Certificate("cn=imap.g.com"), "imap.g.com", true); - checkMatch("12", new StubX509Certificate("cn=imap2.g.com"), "imap.g.com", false); - checkMatch("13", new StubX509Certificate("cn=sub.imap.g.com"), "imap.g.com", false); - - // If a subjectAltName extension of type dNSName is present, that MUST - // be used as the identity - checkMatch("21", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_DNS_NAME, "a.y.com") - , "imap.g.com", false); - checkMatch("22", new StubX509Certificate("cn=imap.g.com") // This cn should be ignored - .addSubjectAlternativeName(ALT_DNS_NAME, "a.y.com") - , "imap.g.com", false); - checkMatch("23", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_DNS_NAME, "imap.g.com") - , "imap.g.com", true); - - // With wildcards - checkMatch("24", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_DNS_NAME, "*.g.com") - , "imap.g.com", true); - - // host name is ip address - checkMatch("31", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_IPA_NAME, "1.2.3.4") - , "1.2.3.4", true); - checkMatch("32", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_IPA_NAME, "1.2.3.4") - , "1.2.3.5", false); - checkMatch("32", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_IPA_NAME, "1.2.3.4") - .addSubjectAlternativeName(ALT_IPA_NAME, "192.168.100.1") - , "192.168.100.1", true); - - // Has unknown subject alternative names - checkMatch("41", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 1") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 2") - .addSubjectAlternativeName(ALT_DNS_NAME, "a.b.c.d") - .addSubjectAlternativeName(ALT_DNS_NAME, "*.google.com") - .addSubjectAlternativeName(ALT_DNS_NAME, "imap.g.com") - .addSubjectAlternativeName(ALT_IPA_NAME, "2.33.44.55") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 3") - , "imap.g.com", true); - - checkMatch("42", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 1") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 2") - .addSubjectAlternativeName(ALT_DNS_NAME, "a.b.c.d") - .addSubjectAlternativeName(ALT_DNS_NAME, "*.google.com") - .addSubjectAlternativeName(ALT_DNS_NAME, "imap.g.com") - .addSubjectAlternativeName(ALT_IPA_NAME, "2.33.44.55") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 3") - , "2.33.44.55", true); - - checkMatch("43", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 1") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 2") - .addSubjectAlternativeName(ALT_DNS_NAME, "a.b.c.d") - .addSubjectAlternativeName(ALT_DNS_NAME, "*.google.com") - .addSubjectAlternativeName(ALT_DNS_NAME, "imap.g.com") - .addSubjectAlternativeName(ALT_IPA_NAME, "2.33.44.55") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 3") - , "g.com", false); - - checkMatch("44", new StubX509Certificate("") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 1") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 2") - .addSubjectAlternativeName(ALT_DNS_NAME, "a.b.c.d") - .addSubjectAlternativeName(ALT_DNS_NAME, "*.google.com") - .addSubjectAlternativeName(ALT_DNS_NAME, "imap.g.com") - .addSubjectAlternativeName(ALT_IPA_NAME, "2.33.44.55") - .addSubjectAlternativeName(ALT_UNKNOWN, "random string 3") - , "2.33.44.1", false); - } - - private void checkMatch(String message, X509Certificate certificate, String thisDomain, - boolean expected) { - Boolean actual = DomainNameValidator.match(certificate, thisDomain); - assertEquals(message, (Object) expected, (Object) actual); - } - - /** - * Tests {@link DomainNameValidator#matchDns} - */ - public void testMatchDns() { - checkMatchDns("11", "a.b.c.d", "a.b.c.d", true); - checkMatchDns("12", "a.b.c.d", "*.b.c.d", true); - checkMatchDns("13", "b.c.d", "*.b.c.d", true); - checkMatchDns("14", "b.c.d", "b*.c.d", true); - - checkMatchDns("15", "a.b.c.d", "*.*.c.d", false); - checkMatchDns("16", "a.b.c.d", "*.c.d", false); - - checkMatchDns("21", "imap.google.com", "imap.google.com", true); - checkMatchDns("22", "imap2.google.com", "imap.google.com", false); - checkMatchDns("23", "imap.google.com", "*.google.com", true); - checkMatchDns("24", "imap2.google.com", "*.google.com", true); - checkMatchDns("25", "imap.google.com", "*.googl.com", false); - checkMatchDns("26", "imap2.google2.com", "*.google3.com", false); - checkMatchDns("27", "imap.google.com", "ima*.google.com", true); - checkMatchDns("28", "imap.google.com", "imap*.google.com", true); - checkMatchDns("29", "imap.google.com", "*.imap.google.com", true); - - checkMatchDns("41", "imap.google.com", "a*.google.com", false); - checkMatchDns("42", "imap.google.com", "ix*.google.com", false); - - checkMatchDns("51", "imap.google.com", "iMap.Google.Com", true); - } - - private void checkMatchDns(String message, String thisDomain, String thatDomain, - boolean expected) { - boolean actual = DomainNameValidator.matchDns(thisDomain, thatDomain); - assertEquals(message, expected, actual); - } - - /** - * Test {@link DomainNameValidator#match} with actual certificates. - */ - public void testWithActualCert() throws Exception { - // subject_only - // - // subject: C=JP, CN=www.example.com - // subject alt names: n/a - checkWithActualCert("11", R.raw.subject_only, "www.example.com", true); - checkWithActualCert("12", R.raw.subject_only, "www2.example.com", false); - - // subject_alt_only - // - // subject: C=JP (no CN) - // subject alt names: DNS:www.example.com - checkWithActualCert("21", R.raw.subject_alt_only, "www.example.com", true); - checkWithActualCert("22", R.raw.subject_alt_only, "www2.example.com", false); - - // subject_with_alt_names - // - // subject: C=JP, CN=www.example.com - // subject alt names: DNS:www2.example.com, DNS:www3.example.com - // * Subject should be ignored, because it has subject alt names. - checkWithActualCert("31", R.raw.subject_with_alt_names, "www.example.com", false); - checkWithActualCert("32", R.raw.subject_with_alt_names, "www2.example.com", true); - checkWithActualCert("33", R.raw.subject_with_alt_names, "www3.example.com", true); - checkWithActualCert("34", R.raw.subject_with_alt_names, "www4.example.com", false); - - // subject_with_wild_alt_name - // - // subject: C=JP, CN=www.example.com - // subject alt names: DNS:*.example2.com - // * Subject should be ignored, because it has subject alt names. - checkWithActualCert("41", R.raw.subject_with_wild_alt_name, "www.example.com", false); - checkWithActualCert("42", R.raw.subject_with_wild_alt_name, "www2.example.com", false); - checkWithActualCert("43", R.raw.subject_with_wild_alt_name, "www.example2.com", true); - checkWithActualCert("44", R.raw.subject_with_wild_alt_name, "abc.example2.com", true); - checkWithActualCert("45", R.raw.subject_with_wild_alt_name, "www.example3.com", false); - - // wild_alt_name_only - // - // subject: C=JP - // subject alt names: DNS:*.example.com - checkWithActualCert("51", R.raw.wild_alt_name_only, "www.example.com", true); - checkWithActualCert("52", R.raw.wild_alt_name_only, "www2.example.com", true); - checkWithActualCert("53", R.raw.wild_alt_name_only, "www.example2.com", false); - - // wild_alt_name_only - // - // subject: C=JP - // subject alt names: IP Address:192.168.10.1 - checkWithActualCert("61", R.raw.alt_ip_only, "192.168.10.1", true); - checkWithActualCert("61", R.raw.alt_ip_only, "192.168.10.2", false); - } - - private void checkWithActualCert(String message, int resId, String domain, - boolean expected) throws Exception { - CertificateFactory factory = CertificateFactory.getInstance("X509"); - InputStream certStream = getContext().getResources().openRawResource(resId); - X509Certificate certificate = (X509Certificate) factory.generateCertificate(certStream); - - checkMatch(message, certificate, domain, expected); - } - - /** - * Minimal {@link X509Certificate} implementation for {@link DomainNameValidator}. - */ - private static class StubX509Certificate extends X509Certificate { - private final X500Principal subjectX500Principal; - private Collection<List<?>> subjectAlternativeNames; - - public StubX509Certificate(String subjectDn) { - subjectX500Principal = new X500Principal(subjectDn); - subjectAlternativeNames = null; - } - - public StubX509Certificate addSubjectAlternativeName(int type, String name) { - if (subjectAlternativeNames == null) { - subjectAlternativeNames = new ArrayList<List<?>>(); - } - LinkedList<Object> entry = new LinkedList<Object>(); - entry.add(type); - entry.add(name); - subjectAlternativeNames.add(entry); - return this; - } - - @Override - public Collection<List<?>> getSubjectAlternativeNames() throws CertificateParsingException { - return subjectAlternativeNames; - } - - @Override - public X500Principal getSubjectX500Principal() { - return subjectX500Principal; - } - - @Override - public void checkValidity() throws CertificateExpiredException, - CertificateNotYetValidException { - throw new RuntimeException("Method not implemented"); - } - - @Override - public void checkValidity(Date date) throws CertificateExpiredException, - CertificateNotYetValidException { - throw new RuntimeException("Method not implemented"); - } - - @Override - public int getBasicConstraints() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public Principal getIssuerDN() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public boolean[] getIssuerUniqueID() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public boolean[] getKeyUsage() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public Date getNotAfter() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public Date getNotBefore() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public BigInteger getSerialNumber() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public String getSigAlgName() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public String getSigAlgOID() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public byte[] getSigAlgParams() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public byte[] getSignature() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public Principal getSubjectDN() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public boolean[] getSubjectUniqueID() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public byte[] getTBSCertificate() throws CertificateEncodingException { - throw new RuntimeException("Method not implemented"); - } - - @Override - public int getVersion() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public byte[] getEncoded() throws CertificateEncodingException { - throw new RuntimeException("Method not implemented"); - } - - @Override - public PublicKey getPublicKey() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public String toString() { - throw new RuntimeException("Method not implemented"); - } - - @Override - public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, - InvalidKeyException, NoSuchProviderException, SignatureException { - throw new RuntimeException("Method not implemented"); - } - - @Override - public void verify(PublicKey key, String sigProvider) throws CertificateException, - NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, - SignatureException { - throw new RuntimeException("Method not implemented"); - } - - public Set<String> getCriticalExtensionOIDs() { - throw new RuntimeException("Method not implemented"); - } - - public byte[] getExtensionValue(String oid) { - throw new RuntimeException("Method not implemented"); - } - - public Set<String> getNonCriticalExtensionOIDs() { - throw new RuntimeException("Method not implemented"); - } - - public boolean hasUnsupportedCriticalExtension() { - throw new RuntimeException("Method not implemented"); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/HashMapTest.java b/tests/AndroidTests/src/com/android/unit_tests/HashMapTest.java deleted file mode 100644 index b4d15c9..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/HashMapTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Set; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -public class HashMapTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - public HashMap mMap; - public String[] mKeys; - - @Override - @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - mMap = new HashMap(); - mKeys = new String[ITERATIONS]; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - mKeys[i] = Integer.toString(i, 16); - mMap.put(mKeys[i], i); - } - } - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testHashMapGet() { - int num; - for (int i = ITERATIONS - 1; i >= 0; i--) { - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - num = (Integer) mMap.get(mKeys[i]); - } - } - - public void testHashMapKeySet() { - Set keyset; - for (int i = ITERATIONS - 1; i >= 0; i--) { - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - keyset = mMap.keySet(); - } - } - - public void testHashMapEntrySet() { - Set keyset; - for (int i = ITERATIONS - 1; i >= 0; i--) { - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - keyset = mMap.entrySet(); - - - } - } - - public void testHashMapValues() { - Collection c; - for (int i = ITERATIONS - 1; i >= 0; i--) { - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - c = mMap.values(); - - - } - } - - public void testHashMapSize() { - int len; - for (int i = ITERATIONS - 1; i >= 0; i--) { - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - len = mMap.size(); - - - } - } - - public void testHashMapContainsValue() { - boolean flag; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - flag = mMap.containsValue(i); - - - } - } - - public void testHashMapRemove() { - for (int i = ITERATIONS - 1; i >= 0; i--) { - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - mMap.remove(mKeys[i]); - } - } - - - public void testHashMapClone() { - HashMap cMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - cMap = (HashMap) mMap.clone(); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/HashSetTest.java b/tests/AndroidTests/src/com/android/unit_tests/HashSetTest.java deleted file mode 100644 index 80d3d8d..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/HashSetTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -import java.util.HashSet; -import java.util.Iterator; - -/** - * Implements basic performance test functionality for HashSets - */ - -public class HashSetTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - public static HashSet<Integer> sSet; - - @Override - protected void setUp() throws Exception { - super.setUp(); - sSet = new HashSet<Integer>(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - sSet.add(i); - } - } - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - /** - * - * Tests performance for the HashSet method Add(Object arg 0) - * - */ - - @SuppressWarnings("unchecked") - public void testHashSetAdd() { - HashSet set = new HashSet(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - } - - } - - /** - * - * Tests performance of HashSet method contains(Object arg 0) - * - */ - - public void testHashSetContains() { - Integer index = new Integer(500); - boolean flag; - HashSet set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - } - } - - /** - * - * Tests performance of HashSet method size() - * - */ - - public void testHashSetSize() { - int num; - HashSet set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - num = set.size(); - num = set.size(); - num = set.size(); - num = set.size(); - num = set.size(); - num = set.size(); - num = set.size(); - num = set.size(); - num = set.size(); - } - } - - /** - * - * Tests performance of the HashSet method -iterator() - * - */ - - public void testHashSetIterator() { - Iterator iterator; - HashSet set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - } - } - - /** - * - * Tests performance for the HashSet method Remove(Object arg 0) - * - */ - - @SuppressWarnings("unchecked") - public void testHashSetRemove() { - HashSet set = new HashSet(sSet); - for (int i = ITERATIONS - 1; i >= 0; i--) { - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - } - } - - /** - * - * Tests performance for the HashSet method isEmpty(Object arg 0) - * - */ - - public void testHashSetIsEmpty() { - HashSet set = sSet; - boolean flag; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - flag = set.isEmpty(); - } - } - - /** - * - * Tests performance for the HashSet method clone() - * - */ - - public void testHashSetClone() { - HashSet hSet = sSet; - Object set; - for (int i = ITERATIONS - 1; i > 0; i--) { - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - set = hSet.clone(); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/HashtableTest.java b/tests/AndroidTests/src/com/android/unit_tests/HashtableTest.java deleted file mode 100644 index 42bec11..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/HashtableTest.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -import java.util.Hashtable; -import java.util.Set; -import java.util.Enumeration; - -/** - * Implements basic performance test functionality for java.util.Hashtable - */ - -public class HashtableTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - public Hashtable<String, Integer> sTable; - public String[] sKeys; - - @Override - @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - sTable = new Hashtable(); - sKeys = new String[ITERATIONS]; - for (int i = ITERATIONS - 1; i >= 0; i--) { - sKeys[i] = Integer.toString(i, 16); - sTable.put(sKeys[i], i); - } - } - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - @SuppressWarnings("unchecked") - public void testHashtablePut() { - Hashtable hTable = new Hashtable(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - hTable.put(i, i); - } - } - - public void testHashtableGet() { - int value; - String[] keys = sKeys; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - value = hTable.get(keys[i]); - } - } - - public void testHashtablekeyset() { - Set keyset; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - keyset = hTable.keySet(); - } - } - - /** - * - */ - - public void testHashtableEntrySet() { - Set keyset; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - keyset = hTable.entrySet(); - } - } - - public void testHashtableSize() { - int len; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - len = hTable.size(); - } - } - - public void testHashtableContainsValue() { - boolean flag; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - flag = hTable.containsValue(i); - } - } - - @SuppressWarnings("unchecked") - public void testHashtableRemove() { - Hashtable<String, Integer> hTable = new Hashtable(sTable); - String[] keys = sKeys; - for (int i = ITERATIONS - 1; i >= 0; i--) { - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - hTable.remove(keys[i]); - } - } - - public void testHashtableContains() { - Hashtable<String, Integer> hTable = sTable; - boolean flag; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - flag = hTable.contains(i); - } - } - - public void testHashtableContainsKey() { - Hashtable<String, Integer> hTable = sTable; - boolean flag; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - flag = hTable.containsKey(i); - } - } - - public void testHashtableIsEmpty() { - Hashtable<String, Integer> hTable = sTable; - boolean flag; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - flag = hTable.isEmpty(); - } - } - - public void testHashtableKeys() { - Hashtable<String, Integer> hTable = sTable; - Enumeration<String> keys; - for (int i = ITERATIONS - 1; i >= 0; i--) { - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - keys = hTable.keys(); - } - } - - public void testHashtableElements() { - Hashtable<String, Integer> hTable = sTable; - Enumeration<Integer> elements; - for (int i = ITERATIONS - 1; i >= 0; i--) { - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - elements = hTable.elements(); - } - } - - public void testHashtableHashCode() { - int index; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - index = hTable.hashCode(); - } - } - - public void testHashtableEquals() { - boolean flag; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - flag = hTable.equals(hTable); - } - } - - public void testHashtableToString() { - String str; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - str = hTable.toString(); - } - } - - @SuppressWarnings("unchecked") - public void testHashtablePutAll() { - Hashtable<String, Integer> hTable = new Hashtable(); - Hashtable<String, Integer> hTable1 = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - hTable.putAll(hTable1); - } - } - - /** - * - * clone() returns a Hashtable .. It should return Object as per the - * specification. - * - */ - - public void testHashtableClone() { - Hashtable hashTable; - Hashtable<String, Integer> hTable = sTable; - for (int i = ITERATIONS - 1; i >= 0; i--) { - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - hashTable = (Hashtable) hTable.clone(); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/HeapTest.java b/tests/AndroidTests/src/com/android/unit_tests/HeapTest.java deleted file mode 100644 index f6ae6f6..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/HeapTest.java +++ /dev/null @@ -1,633 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.util.Log; -import android.test.suitebuilder.annotation.Suppress; -import dalvik.system.VMRuntime; -import junit.framework.TestCase; - -import java.lang.ref.PhantomReference; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; -import java.util.LinkedList; -import java.util.Random; - - -public class HeapTest extends TestCase { - - private static final String TAG = "HeapTest"; - - /** - * Returns a WeakReference to an object that has no - * other references. This is done in a separate method - * to ensure that the Object's address isn't sitting in - * a stale local register. - */ - private WeakReference<Object> newRef() { - return new WeakReference<Object>(new Object()); - } - - /** - * Allocates the specified number of bytes. This is done in a separate method - * to ensure that the Object's address isn't sitting in a stale local register. - */ - private void allocateMemory(int size) { - byte[] b = new byte[size]; - } - - @MediumTest - public void testMinimumHeapSize() throws Exception { - VMRuntime r = VMRuntime.getRuntime(); - final boolean RUN_FLAKY = false; - - long origSize = r.getMinimumHeapSize(); - if (RUN_FLAKY) { - /* Check that the default value is zero. This will break if anyone - * in this process sets the minimum heap size to a positive value - * before calling this test. - */ - assertTrue(origSize == 0); - } - - long size = 4 * 1024 * 1024; - long oldSize = r.setMinimumHeapSize(size); - assertTrue(oldSize == origSize); - - long newSize = r.getMinimumHeapSize(); - /* This will fail if the maximum heap size (-Xmx) is smaller than 4MB. - */ - assertTrue(newSize == size); - - /* Make sure that getting the size doesn't change anything. - */ - newSize = r.getMinimumHeapSize(); - assertTrue(newSize == size); - - /* This test is flaky; if the heap is already large and fragmented, - * it can fail. It can also fail if another thread causes a GC - * at the wrong time. - */ - if (RUN_FLAKY) { - /* Increase the minimum size, allocate a big object, and make sure that - * a GC didn't happen. - */ - WeakReference ref = newRef(); - assertNotNull(ref.get()); - - r.setMinimumHeapSize(8 * 1024 * 1024); - allocateMemory(4 * 1024 * 1024); - - /* If a GC happened, this reference will be null. - */ - assertNotNull(ref.get()); - } - - /* Restore the original setting. - */ - r.setMinimumHeapSize(origSize); - newSize = r.getMinimumHeapSize(); - assertTrue(newSize == origSize); - - /* Clean up any large stuff we've allocated, - * and re-establish the normal utilization ratio. - */ - Runtime.getRuntime().gc(); - } - - private static void makeRefs(Object objects[], SoftReference<Object> refs[]) { - for (int i = 0; i < objects.length; i++) { - objects[i] = (Object) new byte[8 * 1024]; - refs[i] = new SoftReference<Object>(objects[i]); - } - } - - private static <T> int checkRefs(SoftReference<T> refs[], int last) { - int i; - int numCleared = 0; - for (i = 0; i < refs.length; i++) { - Object o = refs[i].get(); - if (o == null) { - numCleared++; - } - } - if (numCleared != last) { - Log.i(TAG, "****** " + numCleared + "/" + i + " cleared ******"); - } - return numCleared; - } - - private static void clearRefs(Object objects[], int skip) { - for (int i = 0; i < objects.length; i += skip) { - objects[i] = null; - } - } - - private static void clearRefs(Object objects[]) { - clearRefs(objects, 1); - } - - private static <T> void checkRefs(T objects[], SoftReference<T> refs[]) { - boolean ok = true; - - for (int i = 0; i < objects.length; i++) { - if (refs[i].get() != objects[i]) { - ok = false; - } - } - if (!ok) { - throw new RuntimeException("Test failed: soft refs not cleared"); - } - } - - @MediumTest - public void testGcSoftRefs() throws Exception { - final int NUM_REFS = 128; - - Object objects[] = new Object[NUM_REFS]; - SoftReference<Object> refs[] = new SoftReference[objects.length]; - - /* Create a bunch of objects and a parallel array - * of SoftReferences. - */ - makeRefs(objects, refs); - Runtime.getRuntime().gc(); - - /* Let go of some of the hard references to the objects so that - * the references can be cleared. - */ - clearRefs(objects, 3); - - /* Collect all softly-reachable objects. - */ - VMRuntime.getRuntime().gcSoftReferences(); - Runtime.getRuntime().runFinalization(); - - /* Make sure that the objects were collected. - */ - checkRefs(objects, refs); - - /* Remove more hard references and re-check. - */ - clearRefs(objects, 2); - VMRuntime.getRuntime().gcSoftReferences(); - Runtime.getRuntime().runFinalization(); - checkRefs(objects, refs); - - /* Remove the rest of the references and re-check. - */ - /* Remove more hard references and re-check. - */ - clearRefs(objects); - VMRuntime.getRuntime().gcSoftReferences(); - Runtime.getRuntime().runFinalization(); - checkRefs(objects, refs); - } - - public void xxtestSoftRefPartialClean() throws Exception { - final int NUM_REFS = 128; - - Object objects[] = new Object[NUM_REFS]; - SoftReference<Object> refs[] = new SoftReference[objects.length]; - - /* Create a bunch of objects and a parallel array - * of SoftReferences. - */ - makeRefs(objects, refs); - Runtime.getRuntime().gc(); - - /* Let go of the hard references to the objects so that - * the references can be cleared. - */ - clearRefs(objects); - - /* Start creating a bunch of temporary and permanent objects - * to drive GC. - */ - final int NUM_OBJECTS = 64 * 1024; - Object junk[] = new Object[NUM_OBJECTS]; - Random random = new Random(); - - int i = 0; - int mod = 0; - int totalSize = 0; - int cleared = -1; - while (i < junk.length && totalSize < 8 * 1024 * 1024) { - int r = random.nextInt(64 * 1024) + 128; - Object o = (Object) new byte[r]; - if (++mod % 16 == 0) { - junk[i++] = o; - totalSize += r * 4; - } - cleared = checkRefs(refs, cleared); - } - } - - private static void makeRefs(Object objects[], WeakReference<Object> refs[]) { - for (int i = 0; i < objects.length; i++) { - objects[i] = new Object(); - refs[i] = new WeakReference<Object>(objects[i]); - } - } - - private static <T> void checkRefs(T objects[], WeakReference<T> refs[]) { - boolean ok = true; - - for (int i = 0; i < objects.length; i++) { - if (refs[i].get() != objects[i]) { - ok = false; - } - } - if (!ok) { - throw new RuntimeException("Test failed: " + - "weak refs not cleared"); - } - } - - @MediumTest - public void testWeakRefs() throws Exception { - final int NUM_REFS = 16; - - Object objects[] = new Object[NUM_REFS]; - WeakReference<Object> refs[] = new WeakReference[objects.length]; - - /* Create a bunch of objects and a parallel array - * of WeakReferences. - */ - makeRefs(objects, refs); - Runtime.getRuntime().gc(); - checkRefs(objects, refs); - - /* Clear out every other strong reference. - */ - for (int i = 0; i < objects.length; i += 2) { - objects[i] = null; - } - Runtime.getRuntime().gc(); - checkRefs(objects, refs); - - /* Clear out the rest of them. - */ - for (int i = 0; i < objects.length; i++) { - objects[i] = null; - } - Runtime.getRuntime().gc(); - checkRefs(objects, refs); - } - - private static void makeRefs(Object objects[], PhantomReference<Object> refs[], - ReferenceQueue<Object> queue) { - for (int i = 0; i < objects.length; i++) { - objects[i] = new Object(); - refs[i] = new PhantomReference<Object>(objects[i], queue); - } - } - - static <T> void checkRefs(T objects[], PhantomReference<T> refs[], - ReferenceQueue<T> queue) { - boolean ok = true; - - /* Make sure that the reference that should be on - * the queue are marked as enqueued. Once we - * pull them off the queue, they will no longer - * be marked as enqueued. - */ - for (int i = 0; i < objects.length; i++) { - if (objects[i] == null && refs[i] != null) { - if (!refs[i].isEnqueued()) { - ok = false; - } - } - } - if (!ok) { - throw new RuntimeException("Test failed: " + - "phantom refs not marked as enqueued"); - } - - /* Make sure that all of the references on the queue - * are supposed to be there. - */ - PhantomReference<T> ref; - while ((ref = (PhantomReference<T>) queue.poll()) != null) { - /* Find the list index that corresponds to this reference. - */ - int i; - for (i = 0; i < objects.length; i++) { - if (refs[i] == ref) { - break; - } - } - if (i == objects.length) { - throw new RuntimeException("Test failed: " + - "unexpected ref on queue"); - } - if (objects[i] != null) { - throw new RuntimeException("Test failed: " + - "reference enqueued for strongly-reachable " + - "object"); - } - refs[i] = null; - - /* TODO: clear doesn't do much, since we're losing the - * strong ref to the ref object anyway. move the ref - * into another list. - */ - ref.clear(); - } - - /* We've visited all of the enqueued references. - * Make sure that there aren't any other references - * that should have been enqueued. - * - * NOTE: there is a race condition here; this assumes - * that the VM has serviced all outstanding reference - * enqueue() calls. - */ - for (int i = 0; i < objects.length; i++) { - if (objects[i] == null && refs[i] != null) { -// System.out.println("HeapTest/PhantomRefs: refs[" + i + -// "] should be enqueued"); - ok = false; - } - } - if (!ok) { - throw new RuntimeException("Test failed: " + - "phantom refs not enqueued"); - } - } - - @MediumTest - public void testPhantomRefs() throws Exception { - final int NUM_REFS = 16; - - Object objects[] = new Object[NUM_REFS]; - PhantomReference<Object> refs[] = new PhantomReference[objects.length]; - ReferenceQueue<Object> queue = new ReferenceQueue<Object>(); - - /* Create a bunch of objects and a parallel array - * of PhantomReferences. - */ - makeRefs(objects, refs, queue); - Runtime.getRuntime().gc(); - checkRefs(objects, refs, queue); - - /* Clear out every other strong reference. - */ - for (int i = 0; i < objects.length; i += 2) { - objects[i] = null; - } - // System.out.println("HeapTest/PhantomRefs: cleared evens"); - Runtime.getRuntime().gc(); - Runtime.getRuntime().runFinalization(); - checkRefs(objects, refs, queue); - - /* Clear out the rest of them. - */ - for (int i = 0; i < objects.length; i++) { - objects[i] = null; - } - // System.out.println("HeapTest/PhantomRefs: cleared all"); - Runtime.getRuntime().gc(); - Runtime.getRuntime().runFinalization(); - checkRefs(objects, refs, queue); - } - - private static int sNumFinalized = 0; - private static final Object sLock = new Object(); - - private static class FinalizableObject { - protected void finalize() { - // System.out.println("gc from finalize()"); - Runtime.getRuntime().gc(); - synchronized (sLock) { - sNumFinalized++; - } - } - } - - private static void makeRefs(FinalizableObject objects[], - WeakReference<FinalizableObject> refs[]) { - for (int i = 0; i < objects.length; i++) { - objects[i] = new FinalizableObject(); - refs[i] = new WeakReference<FinalizableObject>(objects[i]); - } - } - - @LargeTest - public void testWeakRefsAndFinalizers() throws Exception { - final int NUM_REFS = 16; - - FinalizableObject objects[] = new FinalizableObject[NUM_REFS]; - WeakReference<FinalizableObject> refs[] = new WeakReference[objects.length]; - int numCleared; - - /* Create a bunch of objects and a parallel array - * of WeakReferences. - */ - makeRefs(objects, refs); - Runtime.getRuntime().gc(); - checkRefs(objects, refs); - - /* Clear out every other strong reference. - */ - sNumFinalized = 0; - numCleared = 0; - for (int i = 0; i < objects.length; i += 2) { - objects[i] = null; - numCleared++; - } - // System.out.println("HeapTest/WeakRefsAndFinalizers: cleared evens"); - Runtime.getRuntime().gc(); - Runtime.getRuntime().runFinalization(); - checkRefs(objects, refs); - if (sNumFinalized != numCleared) { - throw new RuntimeException("Test failed: " + - "expected " + numCleared + " finalizations, saw " + - sNumFinalized); - } - - /* Clear out the rest of them. - */ - sNumFinalized = 0; - numCleared = 0; - for (int i = 0; i < objects.length; i++) { - if (objects[i] != null) { - objects[i] = null; - numCleared++; - } - } - // System.out.println("HeapTest/WeakRefsAndFinalizers: cleared all"); - Runtime.getRuntime().gc(); - Runtime.getRuntime().runFinalization(); - checkRefs(objects, refs); - if (sNumFinalized != numCleared) { - throw new RuntimeException("Test failed: " + - "expected " + numCleared + " finalizations, saw " + - sNumFinalized); - } - } - - // TODO: flaky test - //@MediumTest - public void testOomeLarge() throws Exception { - /* Just shy of the typical max heap size so that it will actually - * try to allocate it instead of short-circuiting. - */ - final int SIXTEEN_MB = (16 * 1024 * 1024 - 32); - - Boolean sawEx = false; - byte a[]; - - try { - a = new byte[SIXTEEN_MB]; - } catch (OutOfMemoryError oom) { - //Log.i(TAG, "HeapTest/OomeLarge caught " + oom); - sawEx = true; - } - - if (!sawEx) { - throw new RuntimeException("Test failed: " + - "OutOfMemoryError not thrown"); - } - } - - //See bug 1308253 for reasons. - @Suppress - public void disableTestOomeSmall() throws Exception { - final int SIXTEEN_MB = (16 * 1024 * 1024); - final int LINK_SIZE = 6 * 4; // estimated size of a LinkedList's node - - Boolean sawEx = false; - - LinkedList<Object> list = new LinkedList<Object>(); - - /* Allocate progressively smaller objects to fill up the entire heap. - */ - int objSize = 1 * 1024 * 1024; - while (objSize >= LINK_SIZE) { - try { - for (int i = 0; i < SIXTEEN_MB / objSize; i++) { - list.add((Object)new byte[objSize]); - } - } catch (OutOfMemoryError oom) { - sawEx = true; - } - - if (!sawEx) { - throw new RuntimeException("Test failed: " + - "OutOfMemoryError not thrown while filling heap"); - } - sawEx = false; - - objSize = (objSize * 4) / 5; - } - } - - // TODO: flaky test - //@SmallTest - public void testExternalOomeLarge() { - /* Just shy of the typical max heap size so that it will actually - * try to allocate it instead of short-circuiting. - */ - final int HUGE_SIZE = (16 * 1024 * 1024 - 32); - - assertFalse(VMRuntime.getRuntime().trackExternalAllocation(HUGE_SIZE)); - } - - /** - * "Allocates" external memory in progressively smaller chunks until there's - * only roughly 16 bytes left. - * - * @return the number of bytes allocated - */ - private long allocateMaxExternal() { - final VMRuntime runtime = VMRuntime.getRuntime(); - final int SIXTEEN_MB = (16 * 1024 * 1024); - final int MIN_SIZE = 16; - long totalAllocated = 0; - boolean success; - - success = false; - try { - /* "Allocate" progressively smaller chunks to "fill up" the entire heap. - */ - int objSize = 1 * 1024 * 1024; - while (objSize >= MIN_SIZE) { - boolean sawFailure = false; - for (int i = 0; i < SIXTEEN_MB / objSize; i++) { - if (runtime.trackExternalAllocation(objSize)) { - totalAllocated += objSize; - } else { - sawFailure = true; - break; - } - } - - if (!sawFailure) { - throw new RuntimeException("Test failed: " + - "no failure while filling heap"); - } - - objSize = (objSize * 4) / 5; - } - success = true; - } finally { - if (!success) { - runtime.trackExternalFree(totalAllocated); - totalAllocated = 0; - } - } - return totalAllocated; - } - - public void xxtest00ExternalOomeSmall() { - VMRuntime.getRuntime().trackExternalFree(allocateMaxExternal()); - } - - /** - * Allocates as much external memory as possible, then allocates from the heap - * until an OOME is caught. - * - * It's nice to run this test while the real heap is small, hence the '00' in its - * name to force it to run before testOomeSmall(). - */ - public void xxtest00CombinedOomeSmall() { - long totalAllocated = 0; - boolean sawEx = false; - try { - totalAllocated = allocateMaxExternal(); - LinkedList<Object> list = new LinkedList<Object>(); - try { - while (true) { - list.add((Object)new byte[8192]); - } - /*NOTREACHED*/ - } catch (OutOfMemoryError oom) { - sawEx = true; - } - } finally { - VMRuntime.getRuntime().trackExternalFree(totalAllocated); - } - assertTrue(sawEx); - } - - //TODO: test external alloc debugging/inspection -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java b/tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java deleted file mode 100644 index 027730f..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/HtmlTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.content.res.ColorStateList; -import android.content.res.Resources; -import android.graphics.Typeface; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.text.Html; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.Spanned; -import android.text.style.ForegroundColorSpan; -import android.text.style.QuoteSpan; -import android.text.style.StrikethroughSpan; -import android.text.style.StyleSpan; -import android.text.style.SubscriptSpan; -import android.text.style.SuperscriptSpan; -import android.text.style.TextAppearanceSpan; -import android.text.style.TypefaceSpan; -import android.text.style.URLSpan; -import android.text.style.UnderlineSpan; - -import junit.framework.TestCase; - -/** - * HtmlTest tests the Spanned-to-HTML converter - */ -public class HtmlTest extends TestCase { - @MediumTest - public void testColor() throws Exception { - Spanned s; - ForegroundColorSpan[] colors; - - s = Html.fromHtml("<font color=\"#00FF00\">something</font>"); - colors = s.getSpans(0, s.length(), ForegroundColorSpan.class); - assertEquals(1, colors.length); - assertEquals(0xFF00FF00, colors[0].getForegroundColor()); - - s = Html.fromHtml("<font color=\"navy\">something</font>"); - colors = s.getSpans(0, s.length(), ForegroundColorSpan.class); - assertEquals(1, colors.length); - assertEquals(0xFF000080, colors[0].getForegroundColor()); - - s = Html.fromHtml("<font color=\"gibberish\">something</font>"); - colors = s.getSpans(0, s.length(), ForegroundColorSpan.class); - assertEquals(0, colors.length); - } - - @MediumTest - public void testResourceColor() throws Exception { - ColorStateList c = - Resources.getSystem().getColorStateList(android.R.color.primary_text_dark); - Spanned s; - TextAppearanceSpan[] colors; - - s = Html.fromHtml("<font color=\"@android:color/primary_text_dark\">something</font>"); - colors = s.getSpans(0, s.length(), TextAppearanceSpan.class); - assertEquals(1, colors.length); - assertEquals(c.toString(), colors[0].getTextColor().toString()); - - s = Html.fromHtml("<font color=\"@android:primary_text_dark\">something</font>"); - colors = s.getSpans(0, s.length(), TextAppearanceSpan.class); - assertEquals(1, colors.length); - assertEquals(c.toString(), colors[0].getTextColor().toString()); - - s = Html.fromHtml("<font color=\"@color/primary_text_dark\">something</font>"); - colors = s.getSpans(0, s.length(), TextAppearanceSpan.class); - assertEquals(1, colors.length); - assertEquals(c.toString(), colors[0].getTextColor().toString()); - - s = Html.fromHtml("<font color=\"@primary_text_dark\">something</font>"); - colors = s.getSpans(0, s.length(), TextAppearanceSpan.class); - assertEquals(1, colors.length); - assertEquals(c.toString(), colors[0].getTextColor().toString()); - - s = Html.fromHtml("<font color=\"@" + android.R.color.primary_text_dark - + "\">something</font>"); - colors = s.getSpans(0, s.length(), TextAppearanceSpan.class); - assertEquals(1, colors.length); - assertEquals(c.toString(), colors[0].getTextColor().toString()); - - s = Html.fromHtml("<font color=\"gibberish\">something</font>"); - colors = s.getSpans(0, s.length(), TextAppearanceSpan.class); - assertEquals(colors.length, 0); - } - - @SmallTest - public void testParagraphs() throws Exception { - SpannableString s; - - s = new SpannableString("Hello world"); - assertEquals(Html.toHtml(s), "<p>Hello world</p>\n"); - - s = new SpannableString("Hello world\nor something"); - assertEquals(Html.toHtml(s), "<p>Hello world<br>\nor something</p>\n"); - - s = new SpannableString("Hello world\n\nor something"); - assertEquals(Html.toHtml(s), "<p>Hello world</p>\n<p>or something</p>\n"); - - s = new SpannableString("Hello world\n\n\nor something"); - assertEquals(Html.toHtml(s), "<p>Hello world<br></p>\n<p>or something</p>\n"); - - assertEquals("foo\nbar", Html.fromHtml("foo<br>bar").toString()); - assertEquals("foo\nbar", Html.fromHtml("foo<br>\nbar").toString()); - assertEquals("foo\nbar", Html.fromHtml("foo<br>\n \nbar").toString()); - } - - @SmallTest - public void testBlockquote() throws Exception { - SpannableString s; - - s = new SpannableString("Hello world"); - s.setSpan(new QuoteSpan(), 0, s.length(), Spannable.SPAN_PARAGRAPH); - assertEquals(Html.toHtml(s), "<blockquote><p>Hello world</p>\n</blockquote>\n"); - - s = new SpannableString("Hello\n\nworld"); - s.setSpan(new QuoteSpan(), 0, 7, Spannable.SPAN_PARAGRAPH); - assertEquals(Html.toHtml(s), "<blockquote><p>Hello</p>\n</blockquote>\n<p>world</p>\n"); - } - - @SmallTest - public void testEntities() throws Exception { - SpannableString s; - - s = new SpannableString("Hello <&> world"); - assertEquals(Html.toHtml(s), "<p>Hello <&> world</p>\n"); - - s = new SpannableString("Hello \u03D5 world"); - assertEquals(Html.toHtml(s), "<p>Hello ϕ world</p>\n"); - - s = new SpannableString("Hello world"); - assertEquals(Html.toHtml(s), "<p>Hello world</p>\n"); - } - - @SmallTest - public void testMarkup() throws Exception { - SpannableString s; - - s = new SpannableString("Hello bold world"); - s.setSpan(new StyleSpan(Typeface.BOLD), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), "<p>Hello <b>bold</b> world</p>\n"); - - s = new SpannableString("Hello italic world"); - s.setSpan(new StyleSpan(Typeface.ITALIC), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), "<p>Hello <i>italic</i> world</p>\n"); - - s = new SpannableString("Hello monospace world"); - s.setSpan(new TypefaceSpan("monospace"), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), "<p>Hello <tt>monospace</tt> world</p>\n"); - - s = new SpannableString("Hello superscript world"); - s.setSpan(new SuperscriptSpan(), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), "<p>Hello <sup>superscript</sup> world</p>\n"); - - s = new SpannableString("Hello subscript world"); - s.setSpan(new SubscriptSpan(), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), "<p>Hello <sub>subscript</sub> world</p>\n"); - - s = new SpannableString("Hello underline world"); - s.setSpan(new UnderlineSpan(), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), "<p>Hello <u>underline</u> world</p>\n"); - - s = new SpannableString("Hello struck world"); - s.setSpan(new StrikethroughSpan(), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), "<p>Hello <strike>struck</strike> world</p>\n"); - - s = new SpannableString("Hello linky world"); - s.setSpan(new URLSpan("http://www.google.com"), 6, s.length() - 6, - Spannable.SPAN_EXCLUSIVE_INCLUSIVE); - assertEquals(Html.toHtml(s), - "<p>Hello <a href=\"http://www.google.com\">linky</a> world</p>\n"); - } - - @SmallTest - public void testImg() throws Exception { - Spanned s; - - s = Html.fromHtml("yes<img src=\"http://example.com/foo.gif\">no"); - - assertEquals("<p>yes<img src=\"http://example.com/foo.gif\">no</p>\n", - Html.toHtml(s)); - } - - @SmallTest - public void testUtf8() throws Exception { - Spanned s; - - s = Html.fromHtml("<p>\u0124\u00eb\u0142\u0142o, world!</p>"); - assertEquals("<p>Ĥëłło, world!</p>\n", Html.toHtml(s)); - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/InstanceofTest.java b/tests/AndroidTests/src/com/android/unit_tests/InstanceofTest.java deleted file mode 100644 index 1f82df8..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/InstanceofTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2006 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.unit_tests; - -import junit.framework.TestCase; -import android.test.suitebuilder.annotation.MediumTest; - - -public class InstanceofTest extends TestCase { - - protected A mA; - protected ChildOfAOne mOne; - protected ChildOfAOne mTwo; - protected ChildOfAOne mThree; - protected ChildOfAOne mFour; - protected ChildOfAFive mFive; - - @Override - protected void setUp() throws Exception { - super.setUp(); - - mA = new A(); - mOne = new ChildOfAOne(); - mTwo = new ChildOfATwo(); - mThree = new ChildOfAThree(); - mFour = new ChildOfAFour(); - mFive = new ChildOfAFive(); - } - - - @MediumTest - public void testNoInterface() throws Exception { - A a = mA; - for (int i = 0; i < 100000; i++) { - assertFalse("m_a should not be a ChildOfAFive", a instanceof ChildOfAFive); - } - } - - @MediumTest - public void testDerivedOne() throws Exception { - InterfaceOne one = mOne; - for (int i = 0; i < 100000; i++) { - assertFalse("m_one should not be a ChildOfAFive", one instanceof ChildOfAFive); - } - } - - @MediumTest - public void testDerivedTwo() throws Exception { - InterfaceTwo two = mTwo; - for (int i = 0; i < 100000; i++) { - assertFalse("m_two should not be a ChildOfAFive", two instanceof ChildOfAFive); - } - } - - @MediumTest - public void testDerivedThree() throws Exception { - InterfaceThree three = mThree; - for (int i = 0; i < 100000; i++) { - assertFalse("m_three should not be a ChildOfAFive", three instanceof ChildOfAFive); - } - } - - @MediumTest - public void testDerivedFour() throws Exception { - InterfaceFour four = mFour; - for (int i = 0; i < 100000; i++) { - assertFalse("m_four should not be a ChildOfAFive", four instanceof ChildOfAFive); - } - } - - @MediumTest - public void testSuccessClass() throws Exception { - ChildOfAOne five = mFive; - for (int i = 0; i < 100000; i++) { - assertTrue("m_five is suppose to be a ChildOfAFive", five instanceof ChildOfAFive); - } - } - - @MediumTest - public void testSuccessInterface() throws Exception { - ChildOfAFive five = mFive; - for (int i = 0; i < 100000; i++) { - assertTrue("m_five is suppose to be a InterfaceFour", five instanceof InterfaceFour); - } - } - - @MediumTest - public void testFailInterface() throws Exception { - InterfaceOne one = mFive; - for (int i = 0; i < 100000; i++) { - assertFalse("m_five does not implement InterfaceFive", one instanceof InterfaceFive); - } - } - - private interface InterfaceOne { - } - - private interface InterfaceTwo { - } - - private interface InterfaceThree { - } - - private interface InterfaceFour { - } - - private interface InterfaceFive { - } - - private static class A { - } - - private static class ChildOfAOne extends A implements InterfaceOne, InterfaceTwo, InterfaceThree, InterfaceFour { - } - - private static class ChildOfATwo extends ChildOfAOne { - } - - private static class ChildOfAThree extends ChildOfATwo { - } - - private static class ChildOfAFour extends ChildOfAThree { - } - - private static class ChildOfAFive extends ChildOfAFour { - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/JavaPerformanceTests.java b/tests/AndroidTests/src/com/android/unit_tests/JavaPerformanceTests.java deleted file mode 100644 index e778d53..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/JavaPerformanceTests.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -/** - * - */ -public class JavaPerformanceTests { - - public static String[] children() { - return new String[] { - StringTest.class.getName(), - HashMapTest.class.getName(), - ArrayListTest.class.getName(), - TreeMapTest.class.getName(), - TreeSetTest.class.getName(), - HashSetTest.class.getName(), - HashtableTest.class.getName(), - VectorTest.class.getName(), - LinkedListTest.class.getName(), - MathTest.class.getName(), - }; - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/JniLibTest.java b/tests/AndroidTests/src/com/android/unit_tests/JniLibTest.java deleted file mode 100644 index 6b740ba..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/JniLibTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2006 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.unit_tests; - -import android.test.suitebuilder.annotation.Suppress; -import android.util.Log; -import junit.framework.TestCase; - - -@Suppress -public class JniLibTest extends TestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - /* - * This causes the native shared library to be loaded when the - * class is first used. The library is only loaded once, even if - * multiple classes include this line. - * - * The library must be in java.library.path, which is derived from - * LD_LIBRARY_PATH. The actual library name searched for will be - * "libjni_lib_test.so" under Linux, but may be different on other - * platforms. - */ - try { - System.loadLibrary("jni_lib_test"); - } catch (UnsatisfiedLinkError ule) { - Log.e("JniLibTest", "WARNING: Could not load jni_lib_test natives"); - } - } - - private static native int nativeStaticThing(float f); - private native void nativeThing(int val); - - public void testNativeCall() { - Log.i("JniLibTest", "JNI search path is " - + System.getProperty("java.library.path")); - Log.i("JniLibTest", "'jni_lib_test' becomes '" - + System.mapLibraryName("jni_lib_test") + "'"); - - int result = nativeStaticThing(1234.5f); - nativeThing(result); - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/LinkedListTest.java b/tests/AndroidTests/src/com/android/unit_tests/LinkedListTest.java deleted file mode 100644 index ca470cd..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/LinkedListTest.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; -import java.util.LinkedList; -import java.util.ListIterator; - -/** - * This class contains performance tests for methods in java.util.LinkedList - * - */ -@SuppressWarnings("unchecked") -public class LinkedListTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - LinkedList<Integer> mLinkedList; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mLinkedList = new LinkedList(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - mLinkedList.add(i); - } - } - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testLinkedListAdd() { - LinkedList<Integer> list = new LinkedList(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - list.add(i); - list.add(i); - list.add(i); - list.add(i); - list.add(i); - list.add(i); - list.add(i); - list.add(i); - list.add(i); - list.add(i); - } - } - - public void testLinkedListAdd1() { - LinkedList<Integer> list = new LinkedList(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - list.add(0, i); - list.add(0, i); - list.add(0, i); - list.add(0, i); - list.add(0, i); - list.add(0, i); - list.add(0, i); - list.add(0, i); - list.add(0, i); - list.add(0, i); - } - } - - public void testLinkedListToArray() { - Object array; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - array = list.toArray(); - } - } - - public void testLinkedListSize() { - LinkedList<Integer> list = mLinkedList; - int len; - for (int i = ITERATIONS - 1; i >= 0; i--) { - len = list.size(); - len = list.size(); - len = list.size(); - len = list.size(); - len = list.size(); - len = list.size(); - len = list.size(); - len = list.size(); - len = list.size(); - len = list.size(); - } - } - - public void testLinkedListGet() { - int element; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - element = list.get(i); - element = list.get(i); - element = list.get(i); - element = list.get(i); - element = list.get(i); - element = list.get(i); - element = list.get(i); - element = list.get(i); - element = list.get(i); - element = list.get(i); - } - } - - public void testLinkedListContains() { - boolean flag; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - flag = list.contains(i); - } - } - - public void testLinkedListToArray1() { - Integer[] rArray = new Integer[100]; - Integer[] array; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - array = list.toArray(rArray); - } - } - - public void testLinkedListSet() { - LinkedList<Integer> list = mLinkedList; - int value1 = 500, value2 = 0; - for (int i = ITERATIONS - 1; i >= 0; i--) { - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - list.set(value1, value2); - } - } - - public void testLinkedListIndexOf() { - int index; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - index = list.indexOf(0); - - } - } - - public void testLinkedListLastIndexOf() { - int index; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - index = list.lastIndexOf(0); - } - } - - public void testLinkedListRemove() { - int index; - LinkedList<Integer> list = new LinkedList(mLinkedList); - for (int i = 10; i > 0; i--) { - index = list.remove(); - index = list.remove(); - index = list.remove(); - index = list.remove(); - index = list.remove(); - index = list.remove(); - index = list.remove(); - index = list.remove(); - index = list.remove(); - index = list.remove(); - } - } - - public void testLinkedListRemove1() { - int index; - LinkedList<Integer> list = new LinkedList(mLinkedList); - for (int i = 10; i > 0; i--) { - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - index = list.remove(0); - } - } - - public void testLinkedListRemoveFirst() { - int index; - LinkedList<Integer> list = new LinkedList(mLinkedList); - for (int i = 10; i > 0; i--) { - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - index = list.removeFirst(); - } - } - - public void testLinkedListRemoveLast() { - int index; - LinkedList<Integer> list = new LinkedList(mLinkedList); - for (int i = 10; i > 0; i--) { - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - index = list.removeLast(); - } - } - - public void testLinkedListAddAll() { - LinkedList<Integer> mList = mLinkedList; - boolean flag; - LinkedList<Integer> list = new LinkedList(); - for (int i = 10; i > 0; i--) { - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - flag = list.addAll(mList); - } - } - - public void testLinkedListRemove2() { - LinkedList<String> list; - String s = new String("a"); - list = new LinkedList(); - for (int j = 1000; j > 0; j--) { - list.add("a"); - list.add("b"); - } - boolean flag; - for (int i = 10; i > 0; i--) { - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - flag = list.remove(s); - } - } - - public void testLinkedListAddAll1() { - LinkedList<Integer> mList = new LinkedList(); - int pos = 0; - boolean flag; - LinkedList<Integer> list = mLinkedList; - for (int i = 0; i < 10; i++) { - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - flag = mList.addAll(pos, list); - } - } - - public void testLinkedListClone() { - Object rObj; - LinkedList<Integer> list = mLinkedList; - for (int i = 100; i > 0; i--) { - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - rObj = list.clone(); - } - } - - public void testLinkedListHashcode() { - int element; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - element = list.hashCode(); - } - } - - public void testLinkedListElement() { - int element; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - element = list.element(); - element = list.element(); - element = list.element(); - element = list.element(); - element = list.element(); - element = list.element(); - element = list.element(); - element = list.element(); - element = list.element(); - element = list.element(); - } - } - - public void testLinkedListToString() { - String str; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - str = list.toString(); - str = list.toString(); - str = list.toString(); - str = list.toString(); - str = list.toString(); - str = list.toString(); - str = list.toString(); - str = list.toString(); - str = list.toString(); - str = list.toString(); - } - } - - public void testLinkedListIsEmpty() { - boolean flag; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - flag = list.isEmpty(); - } - } - - public void testLinkedListOffer() { - LinkedList<Integer> list = new LinkedList(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - list.offer(i); - list.offer(i); - list.offer(i); - list.offer(i); - list.offer(i); - list.offer(i); - list.offer(i); - list.offer(i); - list.offer(i); - list.offer(i); - } - } - - public void testLinkedListPeek() { - int element; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - element = list.peek(); - element = list.peek(); - element = list.peek(); - element = list.peek(); - element = list.peek(); - element = list.peek(); - element = list.peek(); - element = list.peek(); - element = list.peek(); - element = list.peek(); - } - } - - public void testLinkedListPoll() { - int element; - LinkedList<Integer> list = new LinkedList(mLinkedList); - for (int i = 10; i > 0; i--) { - element = list.poll(); - element = list.poll(); - element = list.poll(); - element = list.poll(); - element = list.poll(); - element = list.poll(); - element = list.poll(); - element = list.poll(); - element = list.poll(); - element = list.poll(); - } - } - - public void testLinkedListAddLast() { - LinkedList<Integer> list = new LinkedList(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - list.addLast(i); - list.addLast(i); - list.addLast(i); - list.addLast(i); - list.addLast(i); - list.addLast(i); - list.addLast(i); - list.addLast(i); - list.addLast(i); - list.addLast(i); - } - } - - public void testLinkedListAddFirst() { - LinkedList<Integer> list = new LinkedList(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - list.addFirst(i); - } - } - - public void testLinkedListIterator() { - ListIterator iterator; - LinkedList<Integer> list = mLinkedList; - for (int i = ITERATIONS - 1; i >= 0; i--) { - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - iterator = list.listIterator(); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/LinkifyTest.java b/tests/AndroidTests/src/com/android/unit_tests/LinkifyTest.java deleted file mode 100644 index 83e0758..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/LinkifyTest.java +++ /dev/null @@ -1,68 +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 com.android.unit_tests; - -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.text.*; -import android.text.method.*; -import android.text.style.*; -import android.text.util.*; -import android.widget.*; - -/** - * LinkifyTest tests {@link Linkify}. - */ -public class LinkifyTest extends AndroidTestCase { - - @SmallTest - public void testNothing() throws Exception { - TextView tv; - - tv = new TextView(getContext()); - tv.setText("Hey, foo@google.com, call 415-555-1212."); - - assertFalse(tv.getMovementMethod() instanceof LinkMovementMethod); - assertTrue(tv.getUrls().length == 0); - } - - @MediumTest - public void testNormal() throws Exception { - TextView tv; - - tv = new TextView(getContext()); - tv.setAutoLinkMask(Linkify.ALL); - tv.setText("Hey, foo@google.com, call 415-555-1212."); - - assertTrue(tv.getMovementMethod() instanceof LinkMovementMethod); - assertTrue(tv.getUrls().length == 2); - } - - @SmallTest - public void testUnclickable() throws Exception { - TextView tv; - - tv = new TextView(getContext()); - tv.setAutoLinkMask(Linkify.ALL); - tv.setLinksClickable(false); - tv.setText("Hey, foo@google.com, call 415-555-1212."); - - assertFalse(tv.getMovementMethod() instanceof LinkMovementMethod); - assertTrue(tv.getUrls().length == 2); - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/MathTest.java b/tests/AndroidTests/src/com/android/unit_tests/MathTest.java deleted file mode 100644 index caf2d20..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/MathTest.java +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -/** - * - * Implements basic performance test functionality for java.lang.Math - * - */ - -public class MathTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - public static final double sDouble1 = -2450.50; - public static final double sDouble2 = -500; - public static final float sFloat = 300.50f; - public static final int sInt = 90; - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testDoubleAbs() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - result = Math.abs(sDouble1); - } - } - - public void testFloatAbs() { - float result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - result = Math.abs(sFloat); - } - } - - public void testMathSin() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - result = Math.sin(sDouble1); - } - } - - public void testMathCos() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - result = Math.cos(sDouble1); - } - } - - public void testMathTan() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - result = Math.tan(sDouble1); - } - } - - public void testMathASin() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - result = Math.asin(sDouble1); - } - } - - public void testMathACos() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - result = Math.acos(sDouble1); - } - } - - public void testMathATan() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - result = Math.atan(sDouble1); - } - } - - public void testMathLog() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - result = Math.log(sDouble1); - } - } - - public void testMathSqrt() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - result = Math.sqrt(sDouble1); - } - } - - public void testMathCeil() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - result = Math.ceil(sDouble1); - } - } - - public void testMathRound() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - result = Math.round(sDouble1); - } - } - - public void testMathFloor() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - result = Math.floor(sDouble1); - } - } - - public void testMathExp() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - result = Math.exp(sDouble1); - } - } - - /** - * - */ - - public void testMathPow() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - result = Math.pow(sDouble1, sDouble2); - } - } - - public void testMathMax() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - result = Math.max(sDouble1, sDouble2); - } - } - - public void testMathMin() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - result = Math.min(sDouble1, sDouble2); - } - } - - public void testMathRandom() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.random(); - result = Math.random(); - result = Math.random(); - result = Math.random(); - result = Math.random(); - result = Math.random(); - result = Math.random(); - result = Math.random(); - result = Math.random(); - result = Math.random(); - } - } - - public void testMathIEEERemainder() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - result = Math.IEEEremainder(sDouble1, sDouble2); - } - } - - public void testMathToDegrees() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - result = Math.toDegrees(sDouble1); - } - } - - public void testMathToRadians() { - double result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - result = Math.toRadians(sDouble1); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/MonitorTest.java b/tests/AndroidTests/src/com/android/unit_tests/MonitorTest.java deleted file mode 100644 index b5c6d87..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/MonitorTest.java +++ /dev/null @@ -1,469 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import junit.framework.TestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.SmallTest; - -public class MonitorTest extends TestCase { - - @MediumTest - public void testWaitArgumentsTest() throws Exception { - /* Try some valid arguments. These should all - * return very quickly. - */ - try { - synchronized (this) { - /* millisecond version */ - wait(1); - wait(10); - - /* millisecond + nanosecond version */ - wait(0, 1); - wait(0, 999999); - wait(1, 1); - wait(1, 999999); - } - } catch (InterruptedException ex) { - throw new RuntimeException("good Object.wait() interrupted", - ex); - } catch (Exception ex) { - throw new RuntimeException("Unexpected exception when calling" + - "Object.wait() with good arguments", ex); - } - - /* Try some invalid arguments. - */ - boolean sawException = false; - try { - synchronized (this) { - wait(-1); - } - } catch (InterruptedException ex) { - throw new RuntimeException("bad Object.wait() interrupted", ex); - } catch (IllegalArgumentException ex) { - sawException = true; - } catch (Exception ex) { - throw new RuntimeException("Unexpected exception when calling" + - "Object.wait() with bad arguments", ex); - } - if (!sawException) { - throw new RuntimeException("bad call to Object.wait() should " + - "have thrown IllegalArgumentException"); - } - - sawException = false; - try { - synchronized (this) { - wait(0, -1); - } - } catch (InterruptedException ex) { - throw new RuntimeException("bad Object.wait() interrupted", ex); - } catch (IllegalArgumentException ex) { - sawException = true; - } catch (Exception ex) { - throw new RuntimeException("Unexpected exception when calling" + - "Object.wait() with bad arguments", ex); - } - if (!sawException) { - throw new RuntimeException("bad call to Object.wait() should " + - "have thrown IllegalArgumentException"); - } - - sawException = false; - try { - synchronized (this) { - /* The legal range of nanos is 0-999999. */ - wait(0, 1000000); - } - } catch (InterruptedException ex) { - throw new RuntimeException("bad Object.wait() interrupted", ex); - } catch (IllegalArgumentException ex) { - sawException = true; - } catch (Exception ex) { - throw new RuntimeException("Unexpected exception when calling" + - "Object.wait() with bad arguments", ex); - } - if (!sawException) { - throw new RuntimeException("bad call to Object.wait() should " + - "have thrown IllegalArgumentException"); - } - } - - private class Interrupter extends Thread { - Waiter waiter; - - Interrupter(String name, Waiter waiter) { - super(name); - this.waiter = waiter; - } - - public void run() { - try { - run_inner(); - } catch (Throwable t) { - MonitorTest.errorException = t; - MonitorTest.testThread.interrupt(); - } - } - - void run_inner() { - waiter.spin = true; - // System.out.println("InterruptTest: starting waiter"); - waiter.start(); - - try { - Thread.currentThread().sleep(500); - } catch (InterruptedException ex) { - throw new RuntimeException("Test sleep interrupted.", ex); - } - - /* Waiter is spinning, and its monitor should still be thin. - */ - // System.out.println("Test interrupting waiter"); - waiter.interrupt(); - waiter.spin = false; - - for (int i = 0; i < 3; i++) { - /* Wait for the waiter to start waiting. - */ - synchronized (waiter.interrupterLock) { - try { - waiter.interrupterLock.wait(); - } catch (InterruptedException ex) { - throw new RuntimeException("Test wait interrupted.", ex); - } - } - - /* Before interrupting, grab the waiter lock, which - * guarantees that the waiter is already sitting in wait(). - */ - synchronized (waiter) { - //System.out.println("Test interrupting waiter (" + i + ")"); - waiter.interrupt(); - } - } - - // System.out.println("Test waiting for waiter to die."); - try { - waiter.join(); - } catch (InterruptedException ex) { - throw new RuntimeException("Test join interrupted.", ex); - } - // System.out.println("InterruptTest done."); - } - } - - private class Waiter extends Thread { - Object interrupterLock = new Object(); - Boolean spin = false; - - Waiter(String name) { - super(name); - } - - public void run() { - try { - run_inner(); - } catch (Throwable t) { - MonitorTest.errorException = t; - MonitorTest.testThread.interrupt(); - } - } - - void run_inner() { - // System.out.println("Waiter spinning"); - while (spin) { - // We're going to get interrupted while we spin. - } - if (interrupted()) { - // System.out.println("Waiter done spinning; interrupted."); - } else { - throw new RuntimeException("Thread not interrupted " + - "during spin"); - } - - synchronized (this) { - Boolean sawEx = false; - - try { - synchronized (interrupterLock) { - interrupterLock.notify(); - } - // System.out.println("Waiter calling wait()"); - this.wait(); - } catch (InterruptedException ex) { - sawEx = true; - // System.out.println("wait(): Waiter caught " + ex); - } - // System.out.println("wait() finished"); - - if (!sawEx) { - throw new RuntimeException("Thread not interrupted " + - "during wait()"); - } - } - synchronized (this) { - Boolean sawEx = false; - - try { - synchronized (interrupterLock) { - interrupterLock.notify(); - } - // System.out.println("Waiter calling wait(1000)"); - this.wait(1000); - } catch (InterruptedException ex) { - sawEx = true; - // System.out.println("wait(1000): Waiter caught " + ex); - } - // System.out.println("wait(1000) finished"); - - if (!sawEx) { - throw new RuntimeException("Thread not interrupted " + - "during wait(1000)"); - } - } - synchronized (this) { - Boolean sawEx = false; - - try { - synchronized (interrupterLock) { - interrupterLock.notify(); - } - // System.out.println("Waiter calling wait(1000, 5000)"); - this.wait(1000, 5000); - } catch (InterruptedException ex) { - sawEx = true; - // System.out.println("wait(1000, 5000): Waiter caught " + ex); - } - // System.out.println("wait(1000, 5000) finished"); - - if (!sawEx) { - throw new RuntimeException("Thread not interrupted " + - "during wait(1000, 5000)"); - } - } - - // System.out.println("Waiter returning"); - } - } - - private static Throwable errorException; - private static Thread testThread; - - // TODO: Flaky test. Add back MediumTest annotation once fixed - public void testInterruptTest() throws Exception { - - - testThread = Thread.currentThread(); - errorException = null; - - Waiter waiter = new Waiter("InterruptTest Waiter"); - Interrupter interrupter = - new Interrupter("InterruptTest Interrupter", waiter); - interrupter.start(); - - try { - interrupter.join(); - waiter.join(); - } catch (InterruptedException ex) { - throw new RuntimeException("Test join interrupted.", ex); - } - - if (errorException != null) { - throw new RuntimeException("InterruptTest failed", - errorException); - } - - - - - } - - private static void deepWait(int depth, Object lock) { - synchronized (lock) { - if (depth > 0) { - deepWait(depth - 1, lock); - } else { - String threadName = Thread.currentThread().getName(); - try { - // System.out.println(threadName + " waiting"); - lock.wait(); - // System.out.println(threadName + " done waiting"); - } catch (InterruptedException ex) { - // System.out.println(threadName + " interrupted."); - } - } - } - } - - private class Worker extends Thread { - Object lock; - int id; - - Worker(int id, Object lock) { - super("Worker(" + id + ")"); - this.id = id; - this.lock = lock; - } - - public void run() { - int iterations = 0; - - while (MonitorTest.running) { - MonitorTest.deepWait(id, lock); - iterations++; - } - // System.out.println(getName() + " done after " + iterations + " iterations."); - } - } - - private static Object commonLock = new Object(); - private static Boolean running = false; - - - @LargeTest - public void testNestedMonitors() throws Exception { - final int NUM_WORKERS = 5; - - Worker w[] = new Worker[NUM_WORKERS]; - int i; - - for (i = 0; i < NUM_WORKERS; i++) { - w[i] = new Worker(i * 2 - 1, new Object()); - } - - running = true; - - // System.out.println("NestedMonitors: starting workers"); - for (i = 0; i < NUM_WORKERS; i++) { - w[i].start(); - } - - try { - Thread.currentThread().sleep(1000); - } catch (InterruptedException ex) { - // System.out.println("Test sleep interrupted."); - } - - for (i = 0; i < 100; i++) { - for (int j = 0; j < NUM_WORKERS; j++) { - synchronized (w[j].lock) { - w[j].lock.notify(); - } - } - } - - // System.out.println("NesterMonitors: stopping workers"); - running = false; - for (i = 0; i < NUM_WORKERS; i++) { - synchronized (w[i].lock) { - w[i].lock.notifyAll(); - } - } - } - - private static class CompareAndExchange extends Thread { - static Object toggleLock = null; - static int toggle = -1; - static Boolean running = false; - - public void run() { - toggleLock = new Object(); - toggle = -1; - - Worker w1 = new Worker(0, 1); - Worker w2 = new Worker(2, 3); - Worker w3 = new Worker(4, 5); - Worker w4 = new Worker(6, 7); - - running = true; - - // System.out.println("CompareAndExchange: starting workers"); - - w1.start(); - w2.start(); - w3.start(); - w4.start(); - - try { - this.sleep(10000); - } catch (InterruptedException ex) { - // System.out.println(getName() + " interrupted."); - } - - // System.out.println("MonitorTest: stopping workers"); - running = false; - - toggleLock = null; - } - - class Worker extends Thread { - int i1; - int i2; - - Worker(int i1, int i2) { - super("Worker(" + i1 + ", " + i2 + ")"); - this.i1 = i1; - this.i2 = i2; - } - - public void run() { - int iterations = 0; - - /* Latch this because run() may set the static field to - * null at some point. - */ - Object toggleLock = CompareAndExchange.toggleLock; - - // System.out.println(getName() + " running"); - try { - while (CompareAndExchange.running) { - synchronized (toggleLock) { - int test; - int check; - - if (CompareAndExchange.toggle == i1) { - this.sleep(5 + i2); - CompareAndExchange.toggle = test = i2; - } else { - this.sleep(5 + i1); - CompareAndExchange.toggle = test = i1; - } - if ((check = CompareAndExchange.toggle) != test) { -// System.out.println("Worker(" + i1 + ", " + -// i2 + ") " + "test " + test + -// " != toggle " + check); - throw new RuntimeException( - "locked value changed"); - } - } - - iterations++; - } - } catch (InterruptedException ex) { - // System.out.println(getName() + " interrupted."); - } - -// System.out.println(getName() + " done after " + -// iterations + " iterations."); - } - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/NewDatabasePerformanceTestSuite.java b/tests/AndroidTests/src/com/android/unit_tests/NewDatabasePerformanceTestSuite.java deleted file mode 100644 index 3462f97..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/NewDatabasePerformanceTestSuite.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2005 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.unit_tests; -import android.test.FrameworkTests; -import android.test.suitebuilder.TestSuiteBuilder; - -import junit.framework.TestSuite; -import junit.framework.TestCase; - -public class NewDatabasePerformanceTestSuite extends TestSuite { - public static TestSuite suite() { - TestSuite suite = - new TestSuite(NewDatabasePerformanceTestSuite.class.getName()); - - suite.addTestSuite(NewDatabasePerformanceTests. - Insert1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InsertIndexed1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - Select100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectStringComparison100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectIndex100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InnerJoin100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InnerJoinOneSide100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InnerJoinNoIndex100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectSubQIndex100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectIndexStringComparison100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectInteger100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectString100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectIntegerIndex100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectIndexString100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectStringStartsWith100.class); - suite.addTestSuite(NewDatabasePerformanceTests. - DeleteIndexed1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - Delete1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - DeleteWhere1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - DeleteIndexWhere1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - UpdateIndexWhere1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - UpdateWhere1000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InsertInteger10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InsertIntegerIndex10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InsertString10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - InsertStringIndexed10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectStringStartsWith10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectStringIndexedStartsWith10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectInteger10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectIntegerIndexed10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectStringContains10000.class); - suite.addTestSuite(NewDatabasePerformanceTests. - SelectStringIndexedContains10000.class); - - return suite; - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/NewDatabasePerformanceTests.java b/tests/AndroidTests/src/com/android/unit_tests/NewDatabasePerformanceTests.java deleted file mode 100644 index 8644fbb..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/NewDatabasePerformanceTests.java +++ /dev/null @@ -1,1234 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.content.ContentValues; -import android.database.sqlite.SQLiteDatabase; -import android.test.PerformanceTestCase; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import java.io.File; -import java.util.Random; - -/** - * Database Performance Tests - * - */ - -public class NewDatabasePerformanceTests { - - // Edit this to change the test run times. The original is 100. - final static int kMultiplier = 1; - - public static class PerformanceBase extends TestCase - implements PerformanceTestCase { - protected static final int CURRENT_DATABASE_VERSION = 42; - protected SQLiteDatabase mDatabase; - protected File mDatabaseFile; - - public void setUp() { - mDatabaseFile = new File("/sdcard", "perf_database_test.db"); - if (mDatabaseFile.exists()) { - mDatabaseFile.delete(); - } - mDatabase = - SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), - null); - assertTrue(mDatabase != null); - mDatabase.setVersion(CURRENT_DATABASE_VERSION); - } - - public void tearDown() { - mDatabase.close(); - mDatabaseFile.delete(); - } - - public boolean isPerformanceOnly() { - return true; - } - - // These tests can only be run once. - public int startPerformance(Intermediates intermediates) { - return 0; - } - - public String numberName(int number) { - String result = ""; - - if (number >= 1000) { - result += numberName((number / 1000)) + " thousand"; - number = (number % 1000); - - if (number > 0) result += " "; - } - - if (number >= 100) { - result += ONES[(number / 100)] + " hundred"; - number = (number % 100); - - if (number > 0) result += " "; - } - - if (number >= 20) { - result += TENS[(number / 10)]; - number = (number % 10); - - if (number > 0) result += " "; - } - - if (number > 0) { - result += ONES[number]; - } - - return result; - } - } - - /** - * Test 1000 inserts. - */ - - public static class Insert1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - - private String[] statements = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - statements[i] = - "INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"; - } - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.execSQL(statements[i]); - } - } - } - - /** - * Test 1000 inserts into an indexed table. - */ - - public static class InsertIndexed1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - - private String[] statements = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - statements[i] = - "INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"; - } - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1c ON t1(c)"); - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.execSQL(statements[i]); - } - } - } - - /** - * 100 SELECTs without an index - */ - - public static class Select100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"count(*)", "avg(b)"}; - - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "b >= " + lower + " AND b < " + upper; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase - .query("t1", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 100 SELECTs on a string comparison - */ - - public static class SelectStringComparison100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"count(*)", "avg(b)"}; - - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - where[i] = "c LIKE '" + numberName(i) + "'"; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase - .query("t1", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 100 SELECTs with an index - */ - - public static class SelectIndex100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"count(*)", "avg(b)"}; - - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1b ON t1(b)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "b >= " + lower + " AND b < " + upper; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase - .query("t1", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * INNER JOIN without an index - */ - - public static class InnerJoin100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"t1.a"}; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase - .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - } - - public void testRun() { - mDatabase.query("t1 INNER JOIN t2 ON t1.b = t2.b", COLUMNS, null, - null, null, null, null); - } - } - - /** - * INNER JOIN without an index on one side - */ - - public static class InnerJoinOneSide100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"t1.a"}; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase - .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))"); - - mDatabase.execSQL("CREATE INDEX i1b ON t1(b)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - } - - public void testRun() { - mDatabase.query("t1 INNER JOIN t2 ON t1.b = t2.b", COLUMNS, null, - null, null, null, null); - } - } - - /** - * INNER JOIN without an index on one side - */ - - public static class InnerJoinNoIndex100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"t1.a"}; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase - .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))"); - - mDatabase.execSQL("CREATE INDEX i1b ON t1(b)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - } - - public void testRun() { - mDatabase.query("t1 INNER JOIN t2 ON t1.c = t2.c", COLUMNS, null, - null, null, null, null); - } - } - - /** - * 100 SELECTs with subqueries. Subquery is using an index - */ - - public static class SelectSubQIndex100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"t1.a"}; - - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase - .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))"); - - mDatabase.execSQL("CREATE INDEX i2b ON t2(b)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = - "t1.b IN (SELECT t2.b FROM t2 WHERE t2.b >= " + lower - + " AND t2.b < " + upper + ")"; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase - .query("t1", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 100 SELECTs on string comparison with Index - */ - - public static class SelectIndexStringComparison100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"count(*)", "avg(b)"}; - - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i3c ON t1(c)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - where[i] = "c LIKE '" + numberName(i) + "'"; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase - .query("t1", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 100 SELECTs on integer - */ - - public static class SelectInteger100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"b"}; - - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t1", COLUMNS, null, null, null, null, null); - } - } - } - - /** - * 100 SELECTs on String - */ - - public static class SelectString100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"c"}; - - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t1", COLUMNS, null, null, null, null, null); - } - } - } - - /** - * 100 SELECTs on integer with index - */ - - public static class SelectIntegerIndex100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"b"}; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1b on t1(b)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t1", COLUMNS, null, null, null, null, null); - } - } - } - - /** - * 100 SELECTs on String with index - */ - - public static class SelectIndexString100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"c"}; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1c ON t1(c)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t1", COLUMNS, null, null, null, null, null); - } - } - } - - /** - * 100 SELECTs on String with starts with - */ - - public static class SelectStringStartsWith100 extends PerformanceBase { - private static final int SIZE = 1 * kMultiplier; - private static final String[] COLUMNS = {"c"}; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1c ON t1(c)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - where[i] = "c LIKE '" + numberName(r).substring(0, 1) + "*'"; - - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase - .query("t1", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 1000 Deletes on an indexed table - */ - - public static class DeleteIndexed1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - private static final String[] COLUMNS = {"c"}; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i3c ON t1(c)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.delete("t1", null, null); - } - } - } - - /** - * 1000 Deletes - */ - - public static class Delete1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - private static final String[] COLUMNS = {"c"}; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.delete("t1", null, null); - } - } - } - - /** - * 1000 DELETE's without an index with where clause - */ - - public static class DeleteWhere1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "b >= " + lower + " AND b < " + upper; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.delete("t1", where[i], null); - } - } - } - - /** - * 1000 DELETE's with an index with where clause - */ - - public static class DeleteIndexWhere1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1b ON t1(b)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "b >= " + lower + " AND b < " + upper; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.delete("t1", where[i], null); - } - } - } - - /** - * 1000 update's with an index with where clause - */ - - public static class UpdateIndexWhere1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - private String[] where = new String[SIZE]; - ContentValues[] mValues = new ContentValues[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1b ON t1(b)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "b >= " + lower + " AND b < " + upper; - ContentValues b = new ContentValues(1); - b.put("b", upper); - mValues[i] = b; - - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.update("t1", mValues[i], where[i], null); - } - } - } - - /** - * 1000 update's without an index with where clause - */ - - public static class UpdateWhere1000 extends PerformanceBase { - private static final int SIZE = 10 * kMultiplier; - private String[] where = new String[SIZE]; - ContentValues[] mValues = new ContentValues[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "b >= " + lower + " AND b < " + upper; - ContentValues b = new ContentValues(1); - b.put("b", upper); - mValues[i] = b; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.update("t1", mValues[i], where[i], null); - } - } - } - - /** - * 10000 inserts for an integer - */ - - public static class InsertInteger10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - ContentValues[] mValues = new ContentValues[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - ContentValues b = new ContentValues(1); - b.put("a", r); - mValues[i] = b; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.insert("t1", null, mValues[i]); - } - } - } - - /** - * 10000 inserts for an integer -indexed table - */ - - public static class InsertIntegerIndex10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - ContentValues[] mValues = new ContentValues[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a INTEGER)"); - mDatabase.execSQL("CREATE INDEX i1a ON t1(a)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - ContentValues b = new ContentValues(1); - b.put("a", r); - mValues[i] = b; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.insert("t1", null, mValues[i]); - } - } - } - - /** - * 10000 inserts for a String - */ - - public static class InsertString10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - ContentValues[] mValues = new ContentValues[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - ContentValues b = new ContentValues(1); - b.put("a", numberName(r)); - mValues[i] = b; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.insert("t1", null, mValues[i]); - } - } - } - - /** - * 10000 inserts for a String - indexed table - */ - - public static class InsertStringIndexed10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - ContentValues[] mValues = new ContentValues[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t1(a VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i1a ON t1(a)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - ContentValues b = new ContentValues(1); - b.put("a", numberName(r)); - mValues[i] = b; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.insert("t1", null, mValues[i]); - } - } - } - - - /** - * 10000 selects for a String -starts with - */ - - public static class SelectStringStartsWith10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - private static final String[] COLUMNS = {"t3.a"}; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t3(a VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t3 VALUES('" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - where[i] = "a LIKE '" + numberName(r).substring(0, 1) + "*'"; - - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t3", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 10000 selects for a String - indexed table -starts with - */ - - public static class SelectStringIndexedStartsWith10000 extends - PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - private static final String[] COLUMNS = {"t3.a"}; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t3(a VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i3a ON t3(a)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t3 VALUES('" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - where[i] = "a LIKE '" + numberName(r).substring(0, 1) + "*'"; - - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t3", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 10000 selects for an integer - - */ - - public static class SelectInteger10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - private static final String[] COLUMNS = {"t4.a"}; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t4(a INTEGER)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t4 VALUES(" + r + ")"); - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "a >= " + lower + " AND a < " + upper; - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t4", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 10000 selects for an integer -indexed table - */ - - public static class SelectIntegerIndexed10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - private static final String[] COLUMNS = {"t4.a"}; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t4(a INTEGER)"); - mDatabase.execSQL("CREATE INDEX i4a ON t4(a)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t4 VALUES(" + r + ")"); - - int lower = i * 100; - int upper = (i + 10) * 100; - where[i] = "a >= " + lower + " AND a < " + upper; - } - - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t4", COLUMNS, where[i], null, null, null, null); - } - } - } - - - /** - * 10000 selects for a String - contains 'e' - */ - - public static class SelectStringContains10000 extends PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - private static final String[] COLUMNS = {"t3.a"}; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t3(a VARCHAR(100))"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t3 VALUES('" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - where[i] = "a LIKE '*e*'"; - - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t3", COLUMNS, where[i], null, null, null, null); - } - } - } - - /** - * 10000 selects for a String - contains 'e'-indexed table - */ - - public static class SelectStringIndexedContains10000 extends - PerformanceBase { - private static final int SIZE = 100 * kMultiplier; - private static final String[] COLUMNS = {"t3.a"}; - private String[] where = new String[SIZE]; - - @Override - public void setUp() { - super.setUp(); - Random random = new Random(42); - - mDatabase - .execSQL("CREATE TABLE t3(a VARCHAR(100))"); - mDatabase.execSQL("CREATE INDEX i3a ON t3(a)"); - - for (int i = 0; i < SIZE; i++) { - int r = random.nextInt(100000); - mDatabase.execSQL("INSERT INTO t3 VALUES('" - + numberName(r) + "')"); - } - - for (int i = 0; i < SIZE; i++) { - where[i] = "a LIKE '*e*'"; - - } - } - - public void testRun() { - for (int i = 0; i < SIZE; i++) { - mDatabase.query("t3", COLUMNS, where[i], null, null, null, null); - } - } - } - - public static final String[] ONES = - {"zero", "one", "two", "three", "four", "five", "six", "seven", - "eight", "nine", "ten", "eleven", "twelve", "thirteen", - "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", - "nineteen"}; - - public static final String[] TENS = - {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", - "seventy", "eighty", "ninety"}; -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/PatternsTest.java b/tests/AndroidTests/src/com/android/unit_tests/PatternsTest.java deleted file mode 100644 index 0edcd6d..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/PatternsTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.unit_tests; - -import android.test.suitebuilder.annotation.SmallTest; -import android.util.Patterns; - -import java.util.regex.Matcher; - -import junit.framework.TestCase; - -public class PatternsTest extends TestCase { - - @SmallTest - public void testTldPattern() throws Exception { - boolean t; - - t = Patterns.TOP_LEVEL_DOMAIN.matcher("com").matches(); - assertTrue("Missed valid TLD", t); - - // One of the new top level domain. - t = Patterns.TOP_LEVEL_DOMAIN.matcher("me").matches(); - assertTrue("Missed valid TLD", t); - - // One of the new top level test domain. - t = Patterns.TOP_LEVEL_DOMAIN.matcher("xn--0zwm56d").matches(); - assertTrue("Missed valid TLD", t); - - t = Patterns.TOP_LEVEL_DOMAIN.matcher("mem").matches(); - assertFalse("Matched invalid TLD!", t); - - t = Patterns.TOP_LEVEL_DOMAIN.matcher("xn").matches(); - assertFalse("Matched invalid TLD!", t); - - t = Patterns.TOP_LEVEL_DOMAIN.matcher("xer").matches(); - assertFalse("Matched invalid TLD!", t); - } - - @SmallTest - public void testUrlPattern() throws Exception { - boolean t; - - t = Patterns.WEB_URL.matcher("http://www.google.com").matches(); - assertTrue("Valid URL", t); - - // Google in one of the new top level domain. - t = Patterns.WEB_URL.matcher("http://www.google.me").matches(); - assertTrue("Valid URL", t); - t = Patterns.WEB_URL.matcher("google.me").matches(); - assertTrue("Valid URL", t); - - // Test url in Chinese: http://xn--fsqu00a.xn--0zwm56d - t = Patterns.WEB_URL.matcher("http://xn--fsqu00a.xn--0zwm56d").matches(); - assertTrue("Valid URL", t); - t = Patterns.WEB_URL.matcher("xn--fsqu00a.xn--0zwm56d").matches(); - assertTrue("Valid URL", t); - - // Internationalized URL. - t = Patterns.WEB_URL.matcher("http://\uD604\uAE08\uC601\uC218\uC99D.kr").matches(); - assertTrue("Valid URL", t); - t = Patterns.WEB_URL.matcher("\uD604\uAE08\uC601\uC218\uC99D.kr").matches(); - assertTrue("Valid URL", t); - - t = Patterns.WEB_URL.matcher("ftp://www.example.com").matches(); - assertFalse("Matched invalid protocol", t); - - t = Patterns.WEB_URL.matcher("http://www.example.com:8080").matches(); - assertTrue("Didn't match valid URL with port", t); - - t = Patterns.WEB_URL.matcher("http://www.example.com:8080/?foo=bar").matches(); - assertTrue("Didn't match valid URL with port and query args", t); - - t = Patterns.WEB_URL.matcher("http://www.example.com:8080/~user/?foo=bar").matches(); - assertTrue("Didn't match valid URL with ~", t); - } - - @SmallTest - public void testIpPattern() throws Exception { - boolean t; - - t = Patterns.IP_ADDRESS.matcher("172.29.86.3").matches(); - assertTrue("Valid IP", t); - - t = Patterns.IP_ADDRESS.matcher("1234.4321.9.9").matches(); - assertFalse("Invalid IP", t); - } - - @SmallTest - public void testDomainPattern() throws Exception { - boolean t; - - t = Patterns.DOMAIN_NAME.matcher("mail.example.com").matches(); - assertTrue("Valid domain", t); - - t = Patterns.WEB_URL.matcher("google.me").matches(); - assertTrue("Valid domain", t); - - // Internationalized domains. - t = Patterns.DOMAIN_NAME.matcher("\uD604\uAE08\uC601\uC218\uC99D.kr").matches(); - assertTrue("Valid domain", t); - - t = Patterns.DOMAIN_NAME.matcher("__+&42.xer").matches(); - assertFalse("Invalid domain", t); - } - - @SmallTest - public void testPhonePattern() throws Exception { - boolean t; - - t = Patterns.PHONE.matcher("(919) 555-1212").matches(); - assertTrue("Valid phone", t); - - t = Patterns.PHONE.matcher("2334 9323/54321").matches(); - assertFalse("Invalid phone", t); - - String[] tests = { - "Me: 16505551212 this\n", - "Me: 6505551212 this\n", - "Me: 5551212 this\n", - - "Me: 1-650-555-1212 this\n", - "Me: (650) 555-1212 this\n", - "Me: +1 (650) 555-1212 this\n", - "Me: +1-650-555-1212 this\n", - "Me: 650-555-1212 this\n", - "Me: 555-1212 this\n", - - "Me: 1.650.555.1212 this\n", - "Me: (650) 555.1212 this\n", - "Me: +1 (650) 555.1212 this\n", - "Me: +1.650.555.1212 this\n", - "Me: 650.555.1212 this\n", - "Me: 555.1212 this\n", - - "Me: 1 650 555 1212 this\n", - "Me: (650) 555 1212 this\n", - "Me: +1 (650) 555 1212 this\n", - "Me: +1 650 555 1212 this\n", - "Me: 650 555 1212 this\n", - "Me: 555 1212 this\n", - }; - - for (String test : tests) { - Matcher m = Patterns.PHONE.matcher(test); - - assertTrue("Valid phone " + test, m.find()); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/PerformanceTests.java b/tests/AndroidTests/src/com/android/unit_tests/PerformanceTests.java deleted file mode 100644 index 9e54540..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/PerformanceTests.java +++ /dev/null @@ -1,1223 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.os.Debug; -import junit.framework.Assert; -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; -import org.apache.harmony.dalvik.NativeTestTarget; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -public class PerformanceTests { - public static String[] children() { - return new String[] { - //StringEquals2.class.getName(), - //StringEquals10.class.getName(), - //StringEquals20.class.getName(), - //StringEquals200.class.getName(), - //StringEquals200U.class.getName(), - //StringCompareTo10.class.getName(), - //StringCompareTo200.class.getName(), - StringLength.class.getName(), - StringCrawl.class.getName(), - Ackermann.class.getName(), - AddTest.class.getName(), -// AddMemberVariableTest.class.getName(), - ArrayListIterator.class.getName(), - BoundsCheckTest.class.getName(), -// EmptyClassBaseTest.class.getName(), - EmptyJniStaticMethod0.class.getName(), - EmptyJniStaticMethod6.class.getName(), - EmptyJniStaticMethod6L.class.getName(), - FibonacciFast.class.getName(), - FibonacciSlow.class.getName(), -// LoopTests.class.getName(), -// HashMapTest.class.getName(), -// InterfaceTests.class.getName(), - LocalVariableAccess.class.getName(), - MemeberVariableAccess.class.getName(), - NestedLoop.class.getName(), -// StringConcatenationTests.class.getName(), -// ArrayListBase.class.getName(), - SynchronizedGetAndSetInt.class.getName(), - - /* this will not work on JamVM -- lacks atomic ops */ - AtomicGetAndSetInt.class.getName(), - }; - } - - public static class SizeTest { - private int mSize; - - public SizeTest(int size) { - mSize = size; - } - - public int size() { - return mSize; - } - } - - public static class LocalVariableAccess extends PerformanceTestBase { - private static final int ITERATIONS = 100000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 20); - return 0; - } - - public void testRun() { - boolean variable = false; - boolean local = true; - for (int i = ITERATIONS - 1; i >= 0; i--) { - local = variable; - local = variable; - local = variable; - local = variable; - local = variable; // 5 - local = variable; - local = variable; - local = variable; - local = variable; - local = variable; // 10 - local = variable; - local = variable; - local = variable; - local = variable; - local = variable; // 15 - local = variable; - local = variable; - local = variable; - local = variable; - local = variable; // 20 - } - } - } - - /* This test is intentionally misspelled. Please do not rename it. Thanks! */ - public static class MemeberVariableAccess extends PerformanceTestBase { - private static final int ITERATIONS = 100000; - - public volatile boolean mMember = false; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 20); - return 0; - } - - public void testRun() { - boolean local = true; - for (int i = ITERATIONS - 1; i >= 0; i--) { - local = mMember; - local = mMember; - local = mMember; - local = mMember; - local = mMember; // 5 - local = mMember; - local = mMember; - local = mMember; - local = mMember; - local = mMember; // 10 - local = mMember; - local = mMember; - local = mMember; - local = mMember; - local = mMember; // 15 - local = mMember; - local = mMember; - local = mMember; - local = mMember; - local = mMember; // 20 - } - } - } - - public static class ArrayListIterator extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - private ArrayList mList; - private String[] mKeys; - private Iterator mIterator; - - public void setUp() throws Exception { - super.setUp(); - mList = new ArrayList(); - mKeys = new String[ITERATIONS]; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - mKeys[i] = Integer.toString(i, 16); - mList.add(mKeys[i]); - } - } - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testRun() { - mIterator = mList.iterator(); - while (mIterator.hasNext()) { - mIterator.next(); - } - } - } - - public static class Ackermann extends PerformanceTestBase { - public static final int ITERATIONS = 100; - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testRun() { - for (int i = ITERATIONS - 1; i >= 0; i--) { - ackermann(3, 13); - } - } - - private int ackermann(int m, int n) { - if (m == 0) - return n + 1; - if (n == 0) - return ackermann(m - 1, 1); - return ackermann(m, n - 1); - } - } - - public static class FibonacciSlow extends PerformanceTestBase { - public void setUp() throws Exception { - super.setUp(); - Assert.assertEquals(0, fibonacci(0)); - Assert.assertEquals(1, fibonacci(1)); - Assert.assertEquals(1, fibonacci(2)); - Assert.assertEquals(2, fibonacci(3)); - Assert.assertEquals(6765, fibonacci(20)); - } - - public void tearDown() { - } - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - return 0; - } - - public void testRun() { - fibonacci(20); - } - - private long fibonacci(long n) { - if (n == 0) - return 0; - if (n == 1) - return 1; - return fibonacci(n - 2) + fibonacci(n - 1); - } - } - - public static class FibonacciFast extends PerformanceTestBase { - public void setUp() throws Exception { - super.setUp(); - Assert.assertEquals(0, fibonacci(0)); - Assert.assertEquals(1, fibonacci(1)); - Assert.assertEquals(1, fibonacci(2)); - Assert.assertEquals(2, fibonacci(3)); - Assert.assertEquals(6765, fibonacci(20)); - } - - public void tearDown() { - } - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - return 0; - } - - public void testRun() { - fibonacci(5000); - } - - private long fibonacci(long n) { - if (n == 0) - return 0; - if (n == 1) - return 1; - - int x = 0; - int y = 1; - for (int i = 0; i < n - 1; i++) { - y = y + x; - x = y - x; - } - - return y; - } - } - - public static class HashMapTest extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - private HashMap mMap; - private String[] mKeys; - - public void setUp() throws Exception { - super.setUp(); - mMap = new HashMap(); - mKeys = new String[ITERATIONS]; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - mKeys[i] = Integer.toString(i, 16); - mMap.put(mKeys[i], i); - } - } - - public void tearDown() { - } - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testHashMapContainsKey() { - for (int i = ITERATIONS - 1; i >= 0; i--) { - mMap.containsKey(mKeys[i]); - } - } - - public void testHashMapIterator() { - Iterator iterator; - - iterator = mMap.entrySet().iterator(); - while (iterator.hasNext()) { - iterator.next(); - } - } - - public void testHashMapPut() { - HashMap map = new HashMap(); - String[] keys = mKeys; - for (int i = ITERATIONS - 1; i >= 0; i--) { - map.put(keys[i], i); - } - } - } - - interface IA { - void funcA0(); - void funcA1(); - void funcA2(); - void funcA3(); - } - interface IAB extends IA { - void funcAB0(); - void funcAB1(); - void funcAB2(); - void funcAB3(); - } - interface IABC extends IAB { - void funcABC0(); - void funcABC1(); - void funcABC2(); - void funcABC3(); - } - interface IB { - void funcB0(); - void funcB1(); - void funcB2(); - void funcB3(); - } - interface IC { - void funcC0(); - void funcC1(); - void funcC2(); - void funcC3(); - } - - static class Alphabet implements Cloneable, IB, IABC, IC, Runnable { - public void funcA0() { - } - public void funcA1() { - } - public void funcA2() { - } - public void funcA3() { - } - public void funcAB0() { - } - public void funcAB1() { - } - public void funcAB2() { - } - public void funcAB3() { - } - public void funcABC0() { - } - public void funcABC1() { - } - public void funcABC2() { - } - public void funcABC3() { - } - public void funcB0() { - } - public void funcB1() { - } - public void funcB2() { - } - public void funcB3() { - } - public void funcC0() { - } - public void funcC1() { - } - public void funcC2() { - } - public void funcC3() { - } - public void run() { - } - }; - - public static class InterfaceTests extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - /* call method directly */ - public void testInterfaceCalls0() { - Alphabet alpha = new Alphabet(); - - for (int i = ITERATIONS - 1; i >= 0; i--) { - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - alpha.funcABC1(); - } - } - - /* call method through interface reference */ - public void testInterfaceCalls1() { - Alphabet alpha = new Alphabet(); - IABC iabc = alpha; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - iabc.funcABC1(); - } - } - - public void testInstanceOfTrivial() { - Alphabet alpha = new Alphabet(); - IABC iabc = alpha; - boolean val; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - val = iabc instanceof Alphabet; - } - } - - public void testInstanceOfInterface() { - Alphabet alpha = new Alphabet(); - IABC iabc = alpha; - boolean val; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - val = iabc instanceof IA; - } - } - - public void testInstanceOfNot() { - Alphabet alpha = new Alphabet(); - IABC iabc = alpha; - boolean val; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - val = iabc instanceof EmptyInterface; - } - } - } - - public static class NestedLoop extends PerformanceTestBase { - private static final int ITERATIONS = 10; - private static final int LOOPS = 5; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * LOOPS); - return 0; - } - - public void testRun() { - int x = 0; - for (int a = 0; a < ITERATIONS; a++) { - for (int b = 0; b < ITERATIONS; b++) { - for (int c = 0; c < ITERATIONS; c++) { - for (int d = 0; d < ITERATIONS; d++) { - for (int e = 0; e < ITERATIONS; e++) { - x++; - } - } - } - } - } - } - } - - public static class StringConcatenationTests extends PerformanceTestBase { - private static final int ITERATIONS = 1000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testStringConcatenation1() { - StringBuffer buffer = new StringBuffer(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - buffer.append("Hello World!\n"); - } - buffer = null; - } - - public void testStringConcatenation2() { - String string = ""; - for (int i = ITERATIONS - 1; i >= 0; i--) { - string += "Hello World!\n"; - } - string = null; - } - } - - public static class StringLength extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - private static final String TEST_STRING = "This is the string we use for testing..."; // 40 chars - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testRun() { - String testStr = TEST_STRING; - int length; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - length = testStr.length(); - } - } - } - - public static class EmptyJniStaticMethod0 extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testRun() { - int a, b, c, d, e, f; - - a = b = c = d = e = f = 0; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - } - } - } - public static class EmptyJniStaticMethod6 extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testRun() { - int a, b, c, d, e, f; - - a = b = c = d = e = f = 0; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - } - } - } - public static class EmptyJniStaticMethod6L extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testRun() { - String a = null; - String[] b = null; - int[][] c = null; - Object d = null; - Object[] e = null; - Object[][][][] f = null; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6L(a, b, c, d, e, f); - } - } - } - - public static class StringCrawl extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - private static final String TEST_STRING = "This is the string we use for testing..."; // 40 chars - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * TEST_STRING.length()); - return 0; - } - - public void testRun() { - String testStr = TEST_STRING; - char ch; - for (int i = ITERATIONS - 1; i >= 0; i--) { - /* this is the wrong way to walk through a string */ - for (int j = 0; j < testStr.length(); j++) { - ch = testStr.charAt(j); - } - } - } - } - - public static class AddTest extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 20); - return 0; - } - - public void testRun() { - int j = 0; - for (int i = ITERATIONS - 1; i >= 0; i--) { - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - } - } - } - - public static class AddMemberVariableTest extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - private int j; - - public void setUp() throws Exception { - super.setUp(); - j = 0; - } - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testAddMemberVariableTest() { - for (int i = ITERATIONS - 1; i >= 0; i--) { - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - j++; - } - } - - public void testAddMemberVariableInMethodTest() { - for (int i = ITERATIONS - 1; i >= 0; i--) { - add(); - add(); - add(); - add(); - add(); - add(); - add(); - add(); - add(); - add(); - } - } - - public void add() { - j++; - } - } - - private interface EmptyInterface { - public void emptyVirtual(); - - } - - private static class EmptyClass implements EmptyInterface { - public void emptyVirtual() { - } - - public static void emptyStatic() { - } - } - - public static class EmptyClassBaseTest extends PerformanceTestBase { - protected EmptyInterface mEmptyInterface; - protected EmptyClass mEmptyClass; - - public void setUp() throws Exception { - super.setUp(); - mEmptyClass = new EmptyClass(); - mEmptyInterface = mEmptyClass; - } - private static final int ITERATIONS = 10000; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testEmptyVirtualMethod() { - //EmptyClass emtpyClass = mEmptyClass; - for (int i = ITERATIONS - 1; i >= 0; i--) { - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - mEmptyClass.emptyVirtual(); - } - } - - public void testEmptyVirtualMethodTestInLocal() { - EmptyClass empty = mEmptyClass; - for (int i = ITERATIONS - 1; i >= 0; i--) { - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - empty.emptyVirtual(); - } - } - - public void testEmptyStaticMethod () { - for (int i = ITERATIONS - 1; i >= 0; i--) { - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - EmptyClass.emptyStatic(); - } - } - - public void testEmptyJniStaticMethod0() { - - for (int i = ITERATIONS - 1; i >= 0; i--) { - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - NativeTestTarget.emptyJniStaticMethod0(); - } - } - - public void testEmptyJniStaticMethod6() { - int a, b, c, d, e, f; - - a = b = c = d = e = f = 0; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - NativeTestTarget.emptyJniStaticMethod6(a, b, c, d, e, f); - } - } - - public void testEmptyInternalStaticMethod() { - /* - * The method called is a VM-internal method with no extra - * wrapping. - */ - for (int i = ITERATIONS - 1; i >= 0; i--) { - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - NativeTestTarget.emptyInternalStaticMethod(); - } - } - - public void testEmptyInlineStaticMethod() { - /* - * The method called is a VM-internal method that gets - * specially "inlined" in a bytecode transformation. - */ - for (int i = ITERATIONS - 1; i >= 0; i--) { - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - NativeTestTarget.emptyInlineMethod(); - } - } - - public void testEmptyInterfaceMethodTest() { - EmptyInterface emptyInterface = mEmptyInterface; - for (int i = ITERATIONS - 1; i >= 0; i--) { - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - emptyInterface.emptyVirtual(); - } - } - } - - public static class LoopTests extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - private SizeTest mSizeTest = new SizeTest(ITERATIONS); - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testForLoopTest() { - int i = 0; - for (; i < 10000; i++) { - } - } - - public void testWhileLoopTest() { - int i = 0; - - while (i < 10000) { - i++; - } - } - - public void testForLoopSizeCalledInside() { - for (int i = 0; i < mSizeTest.size(); i++) { - } - } - - public void testForLoopSizeCalledOutside() { - final int size = mSizeTest.size(); - for (int i = 0; i < size; i++) { - } - } - } - - public static class BoundsCheckTest extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testRun() { - int[] data = new int[1]; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - data[0] = i; - data[0] = i; - data[0] = i; - data[0] = i; - data[0] = i; - data[0] = i; - data[0] = i; - data[0] = i; - data[0] = i; - data[0] = i; - } - } - } - - public static class ArrayListBase extends PerformanceTestBase { - public void setUp() throws Exception { - super.setUp(); - mList = new ArrayList(); - mList.add(0); - mList.add(1); - mList.add(2); - mList.add(3); - mList.add(4); - mList.add(5); - mList.add(6); - mList.add(7); - mList.add(8); - mList.add(9); - } - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(100); - return 0; - } - - ArrayList<Integer> mList; - - public void testForArrayList() { - int i = 0; - int res = 0; - for (; i < 100; i++) { - for (int j = 0; j < mList.size(); j++) { - res += mList.get(j); - } - } - } - - public void testForLocalArrayList() { - int i = 0; - int res = 0; - for (; i < 100; i++) { - final List<Integer> list = mList; - final int N = list.size(); - for (int j = 0; j < N; j++) { - res += list.get(j); - } - } - } - - public void testForEachArrayList() { - int i = 0; - int res = 0; - for (; i < 100; i++) { - for (Integer v : mList) { - res += v; - } - } - } - } - - public static class SynchronizedGetAndSetInt extends PerformanceTestBase { - private static final int ITERATIONS = 100000; - - public int mMember = 0; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testRun() { - int result = 0; - for (int i = ITERATIONS - 1; i >= 0; i--) { - synchronized (this) { - result = mMember; - mMember = i; - } - } - } - } - - public static class AtomicGetAndSetInt extends PerformanceTestBase { - private static final int ITERATIONS = 100000; - - public AtomicInteger mMember = new AtomicInteger(0); - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testRun() { - int result = 0; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = mMember.getAndSet(i); - } - } - } - - public static abstract class StringEquals extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - - protected String mString1, mString2; - public void setUp() throws Exception { - super.setUp(); - } - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testRun() { - String string1 = mString1; - String string2 = mString2; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - string1.equals(string2); - } - } - } - - public static class StringEquals2 extends StringEquals { - public void setUp() throws Exception { - mString1 = "01"; - mString2 = "0x"; - } - } - public static class StringEquals10 extends StringEquals { - public void setUp() throws Exception { - mString1 = "0123456789"; - mString2 = "012345678x"; - } - } - public static class StringEquals20 extends StringEquals { - public void setUp() throws Exception { - mString1 = "01234567890123456789"; - mString2 = "0123456789012345678x"; - } - } - - public static class StringEquals200 extends StringEquals { - public void setUp() throws Exception { - mString1 = "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789"; - mString2 = "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "012345678901234567890123456789012345678x"; - } - } - public static class StringEquals200U extends StringEquals { - /* make one of the strings non-word aligned (bad memcmp case) */ - public void setUp() throws Exception { - String tmpStr; - mString1 = "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789"; - tmpStr = "z0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "012345678901234567890123456789012345678x"; - mString2 = tmpStr.substring(1); - } - } - - public static abstract class StringCompareTo extends PerformanceTestBase { - private static final int ITERATIONS = 10000; - - protected String mString1, mString2; - - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS * 10); - return 0; - } - - public void testRun() { - String string1 = mString1; - String string2 = mString2; - - for (int i = ITERATIONS - 1; i >= 0; i--) { - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - string1.compareTo(string2); - } - } - } - public static class StringCompareTo10 extends StringCompareTo { - public void setUp() throws Exception { - mString1 = "0123456789"; - mString2 = "012345678x"; - } - } - public static class StringCompareTo200 extends StringCompareTo { - public void setUp() throws Exception { - mString1 = "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789"; - mString2 = "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "0123456789012345678901234567890123456789" - + "012345678901234567890123456789012345678x"; - } - } -} - diff --git a/tests/AndroidTests/src/com/android/unit_tests/SerializationTest.java b/tests/AndroidTests/src/com/android/unit_tests/SerializationTest.java deleted file mode 100644 index 4b64144..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/SerializationTest.java +++ /dev/null @@ -1,47 +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 com.android.unit_tests; - -import junit.framework.TestCase; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import android.test.suitebuilder.annotation.SmallTest; - -/** - * Tests serialization of user-level classes. - */ -public class SerializationTest extends TestCase { - - static class MySerializable implements Serializable {} - - @SmallTest - public void testSerialization() throws IOException, ClassNotFoundException { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - ObjectOutputStream oout = new ObjectOutputStream(bout); - oout.writeObject(new MySerializable()); - oout.close(); - - ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); - Object o = new ObjectInputStream(bin).readObject(); - assertTrue(o instanceof MySerializable); - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/StringTest.java b/tests/AndroidTests/src/com/android/unit_tests/StringTest.java deleted file mode 100644 index dc40a0a..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/StringTest.java +++ /dev/null @@ -1,951 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import java.util.Locale; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -public class StringTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - public static final String STATIC_STRING_01 = "Hello Android"; - public static final String STATIC_STRING_02 = - "Remember, today is the tomorrow you worried about yesterday"; - public static final char[] STATIC_CHAR_ARRAY = - {'N', 'A', 'N', 'D', 'R', 'O', 'I', 'D'}; - public static StringBuffer STATIC_SBUF = new StringBuffer(STATIC_STRING_02); - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - /** Create an empty String object* */ - - public void testStringCreate() { - String rString; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = new String(); - rString = new String(); - rString = new String(); - rString = new String(); - rString = new String(); - rString = new String(); - rString = new String(); - rString = new String(); - rString = new String(); - rString = new String(); - } - } - - /** Create an initialised String object* */ - - public void testStringCreate1() { - String rString, str = STATIC_STRING_01; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = new String(str); - rString = new String(str); - rString = new String(str); - rString = new String(str); - rString = new String(str); - rString = new String(str); - rString = new String(str); - rString = new String(str); - rString = new String(str); - rString = new String(str); // 10 - } - } - - /** equals() with for loop* */ - public void testStringEquals() { - String mString = new String(STATIC_STRING_01); - String str = STATIC_STRING_01; - boolean result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - result = mString.equals(str); - } - } - - /** - * ContentEquals- Comparing the content of a String with that of a String - * Buffer* - */ - - public void testStringContentEquals() { - StringBuffer sBuf = new StringBuffer(STATIC_STRING_01); - String str = STATIC_STRING_01; - boolean result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - result = str.contentEquals(sBuf); - } - } - - /** Compare string objects lexicographically using compareTo() with for loop* */ - - public void testStringCompareTo() { - String str1 = new String(STATIC_STRING_01); - String str2 = STATIC_STRING_01; - int result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - result = str1.compareTo(str2); - } - - } - - /** Compare string objects using compareToIgnorecase() with for loop* */ - - public void testStringCompareToIgnoreCase() { - String mString = new String(STATIC_STRING_01); - String str2 = STATIC_STRING_01; - int result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - result = mString.compareToIgnoreCase(str2); - } - } - - /** startsWith * */ - - public void testStringstartsWith() { - boolean result; - String str1 = STATIC_STRING_02, str2 = "Rem"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - result = str1.startsWith(str2); - } - } - - /** startsWith(String seq, int begin) * */ - - public void testStringstartsWith1() { - String str1 = STATIC_STRING_02, str2 = "tom"; - int pos = 10; - boolean result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - result = str1.startsWith(str2, pos); - } - } - - /** endsWith * */ - - public void testStringendsWith() { - String str = STATIC_STRING_02, str1 = "day"; - boolean result; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - result = str.endsWith(str1); - } - } - - /** - * indexOf to determine whether a string contains a substring - */ - public void testStringindexOf() { - boolean result; - String str = STATIC_STRING_02, str1 = "tomo"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - result = str.indexOf(str1) > 0; - } - } - - /** indexOf()* */ - - public void testStringindexOf1() { - int index; - String str = STATIC_STRING_02; - char c = 't'; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - index = str.indexOf(c); - } - - } - - /** indexOf(char c, int start)* */ - public void testStringindexOf2() { - int index, pos = 12; - String str = STATIC_STRING_02, str1 = "tom"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - index = str.indexOf(str1, pos); - } - } - - /** lastIndexOf()* */ - - public void testStringlastIndexOf() { - int index; - char c = 't'; - String str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - index = str.lastIndexOf(c); - } - } - - /** lastIndexOf()* */ - - public void testStringlastIndexOf1() { - int index, pos = 36; - String str = STATIC_STRING_02, str1 = "tom"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - index = str.lastIndexOf(str1, pos); - } - } - - /** - * contains() to determine whether a string contains a substring - */ - - public void testStringcontains() { - boolean result; - String str = STATIC_STRING_02, str1 = "tomo"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - result = str.contains(str1); - } - } - - /** substring(int start) */ - - public void testStringsubstring() { - String rString; - String str = STATIC_STRING_02; - int index = 10; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - rString = str.substring(index); - } - } - - /** substring(int start, int end) in a for loop* */ - - public void testStringsubstring1() { - String rString; - String str = STATIC_STRING_02; - int start = 10, end = 48; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - rString = str.substring(start, end); - } - } - - /** - * valueOf(char[] cArray) String representation of a character array - */ - public void testStringvalueOf() { - String rString; - char[] cArray = STATIC_CHAR_ARRAY; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - rString = String.valueOf(cArray); - } - } - - /** valueOf(char[] cArray, int offset, int count)* */ - - public void testStringvalueOf1() { - String rString; - char[] cArray = STATIC_CHAR_ARRAY; - int start = 1, end = 7; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - rString = String.valueOf(cArray, start, end); - } - } - - /** Convert a string to a char Array* */ - - public void testStringtoCharArray() { - char[] cArray; - String str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - cArray = str.toCharArray(); - } - } - - /** length()* */ - - public void testStringlength() { - int len; - String str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - len = str.length(); - len = str.length(); - len = str.length(); - len = str.length(); - len = str.length(); - len = str.length(); - len = str.length(); - len = str.length(); - len = str.length(); - len = str.length(); - } - } - - /** hashcode()* */ - - public void testStringhashCode() { - int index; - String str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - index = str.hashCode(); - } - } - - /** replace()* */ - - public void testStringreplace() { - String rString; - String str = STATIC_STRING_02; - char c1 = ' ', c2 = ' '; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - rString = str.replace(c1, c2); - } - } - - public void testStringreplaceAll() { - String rString; - String str = STATIC_STRING_02, str1 = " ", str2 = "/"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - rString = str.replaceAll(str1, str2); - } - } - - /** Convert a StringBuffer to a String* */ - - public void testStringtoString() { - StringBuffer sBuf = new StringBuffer(STATIC_STRING_02); - - String rString; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - rString = sBuf.toString(); - } - } - - /** Split a string into an array of strings* */ - - public void testStringsplit() { - String[] strings; - String str1 = STATIC_STRING_02, str = " "; - for (int i = ITERATIONS - 1; i >= 0; i--) { - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - strings = str1.split(str); - - } - } - - /** Split a string into an array of strings* */ - - public void testStringsplit1() { - String str = STATIC_STRING_02, str1 = " "; - String[] strings; - int pos = 8; - for (int i = ITERATIONS - 1; i >= 0; i--) { - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - strings = str.split(str1, pos); - } - } - - public void testStringgetBytes() { - byte[] bytes; - String str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - bytes = str.getBytes(); - } - } - - /** copyValueOf(char[] data) * */ - - public void testStringcopyValueOf() { - String rString; - char[] cArray = STATIC_CHAR_ARRAY; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - rString = String.copyValueOf(cArray); - } - } - - /** copyValueOf(char[] data, int index, int count)* */ - - public void testStringcopyValueOf1() { - String rString; - int start = 1, end = 7; - char[] cArray = STATIC_CHAR_ARRAY; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - rString = String.copyValueOf(cArray, start, end); - } - } - - /** trim()* */ - - public void testStringtrim() { - String mString = - new String( - " HELLO ANDROID "); - String rString; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - rString = mString.trim(); - } - } - - /** getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)* */ - - public void testStringgetChars() { - char[] cArray = STATIC_CHAR_ARRAY; - String str = STATIC_STRING_01; - int value1 = 7, value2 = 12, value3 = 1; - for (int i = ITERATIONS - 1; i >= 0; i--) { - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - str.getChars(value1, value2, cArray, value3); - } - } - - /** toUpperCase()* */ - - public void testStringtoUpperCase() { - String rString, str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - rString = str.toUpperCase(); - } - } - - /** toUpperCase() with locale* */ - - public void testStringtoUpperCase1() { - Locale locale = new Locale("tr"); - String str = STATIC_STRING_02; - String rString; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - rString = str.toUpperCase(locale); - } - } - - /** toLowerCase* */ - - public void StringtoLowerCase() { - String rString, str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - rString = str.toLowerCase(); - } - } - - /** toLowerCase with locale* */ - - public void testStringtoLowerCase1() { - Locale locale = new Locale("tr"); - String rString, str = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - rString = str.toLowerCase(locale); - } - } - - /** charAt()* */ - - public void testStringcharAt() { - String str = STATIC_STRING_02; - int index, pos = 21; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - index = str.charAt(pos); - } - } - - public void testStringConcat() { - String mString, str1 = STATIC_STRING_01, str2 = STATIC_STRING_02; - for (int i = ITERATIONS - 1; i >= 0; i--) { - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - mString = str1.concat(str2); - } - } - - public void testStringBufferAppend() { - StringBuffer sBuf = new StringBuffer(" "); - for (int i = ITERATIONS - 1; i >= 0; i--) { - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - sBuf.append(i); - } - } - - public void testStringBufferInsert() { - StringBuffer sBuf = new StringBuffer(" "); - int index = sBuf.length(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - sBuf.insert(index, i); - } - } - - public void testStringBufferReverse() { - StringBuffer sBuf = STATIC_SBUF; - for (int i = ITERATIONS - 1; i >= 0; i--) { - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - sBuf.reverse(); - } - } - - public void testStringBufferSubstring() { - StringBuffer sBuf = STATIC_SBUF; - String rString; - int index = 0; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - rString = sBuf.substring(index); - } - } - - public void testStringBufferSubstring1() { - StringBuffer sBuf = STATIC_SBUF; - String rString; - int start = 5, end = 25; - for (int i = ITERATIONS - 1; i >= 0; i--) { - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - rString = sBuf.substring(start, end); - } - } - - public void testStringBufferReplace() { - StringBuffer sBuf = STATIC_SBUF; - int start = 3, end = 6; - String str = "ind"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - sBuf.replace(start, end, str); - } - } - - public void testStringBufferIndexOf() { - StringBuffer sBuf = STATIC_SBUF; - String str = "t"; - int index; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - index = sBuf.indexOf(str); - } - } - - public void testStringBufferIndexOf1() { - StringBuffer sBuf = STATIC_SBUF; - String str = "tom"; - int index, pos = 12; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - index = sBuf.indexOf(str, pos); - } - - } - - public void testStringBufferLastIndexOf() { - StringBuffer sBuf = STATIC_SBUF; - String str = "t"; - int index; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - index = sBuf.lastIndexOf(str); - } - } - - public void testStringBufferLastIndexOf1() { - StringBuffer sBuf = STATIC_SBUF; - int index, pos = 36; - String str = "tom"; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - index = sBuf.lastIndexOf(str, pos); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/TestHttpClient.java b/tests/AndroidTests/src/com/android/unit_tests/TestHttpClient.java deleted file mode 100644 index 9b5e655..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/TestHttpClient.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha6/module-main/src/test/java/org/apache/http/mockup/TestHttpClient.java $ - * $Revision: 576077 $ - * $Date: 2007-09-16 04:50:22 -0700 (Sun, 16 Sep 2007) $ - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - * - */ - -package com.android.unit_tests; - -import java.io.IOException; - -import org.apache.http.ConnectionReuseStrategy; -import org.apache.http.HttpClientConnection; -import org.apache.http.HttpException; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.HttpVersion; -import org.apache.http.impl.DefaultConnectionReuseStrategy; -import org.apache.http.params.BasicHttpParams; -import org.apache.http.params.CoreConnectionPNames; -import org.apache.http.params.DefaultedHttpParams; -import org.apache.http.params.HttpParams; -import org.apache.http.params.CoreProtocolPNames; -import org.apache.http.protocol.BasicHttpProcessor; -import org.apache.http.protocol.HttpContext; -import org.apache.http.protocol.BasicHttpContext; -import org.apache.http.protocol.ExecutionContext; -import org.apache.http.protocol.HttpRequestExecutor; -import org.apache.http.protocol.RequestConnControl; -import org.apache.http.protocol.RequestContent; -import org.apache.http.protocol.RequestExpectContinue; -import org.apache.http.protocol.RequestTargetHost; -import org.apache.http.protocol.RequestUserAgent; - -public class TestHttpClient { - - private final HttpParams params; - private final BasicHttpProcessor httpproc; - private final HttpRequestExecutor httpexecutor; - private final ConnectionReuseStrategy connStrategy; - private final HttpContext context; - - public TestHttpClient() { - super(); - this.params = new BasicHttpParams(); - this.params - .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) - .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) - .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1) - .setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1"); - - this.httpproc = new BasicHttpProcessor(); - // Required protocol interceptors - this.httpproc.addInterceptor(new RequestContent()); - this.httpproc.addInterceptor(new RequestTargetHost()); - // Recommended protocol interceptors - this.httpproc.addInterceptor(new RequestConnControl()); - this.httpproc.addInterceptor(new RequestUserAgent()); - this.httpproc.addInterceptor(new RequestExpectContinue()); - - this.httpexecutor = new HttpRequestExecutor(); - this.connStrategy = new DefaultConnectionReuseStrategy(); - this.context = new BasicHttpContext(null); - } - - public HttpParams getParams() { - return this.params; - } - - public HttpResponse execute( - final HttpRequest request, - final HttpHost targetHost, - final HttpClientConnection conn) throws HttpException, IOException { - this.context.setAttribute(ExecutionContext.HTTP_REQUEST, request); - this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost); - this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); - request.setParams( - new DefaultedHttpParams(request.getParams(), this.params)); - this.httpexecutor.preProcess(request, this.httpproc, this.context); - HttpResponse response = this.httpexecutor.execute(request, conn, this.context); - response.setParams( - new DefaultedHttpParams(response.getParams(), this.params)); - this.httpexecutor.postProcess(response, this.httpproc, this.context); - return response; - } - - public boolean keepAlive(final HttpResponse response) { - return this.connStrategy.keepAlive(response, this.context); - } - -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/TreeMapTest.java b/tests/AndroidTests/src/com/android/unit_tests/TreeMapTest.java deleted file mode 100644 index d77a819..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/TreeMapTest.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -import java.util.Collection; -import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; - -/** - * Implements basic performance test functionality for java.util.TreeMap - */ - -public class TreeMapTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - public static TreeMap<String, Integer> sMap; - public static String[] sKeys; - - @Override - @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - sMap = new TreeMap(); - sKeys = new String[ITERATIONS]; - for (int i = ITERATIONS - 1; i >= 0; i--) { - sKeys[i] = Integer.toString(i, 16); - sMap.put(sKeys[i], i); - } - } - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - @SuppressWarnings("unchecked") - public void testTreeMapPut() { - TreeMap map = new TreeMap(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - map.put(i, i); - map.put(i, i); - map.put(i, i); - map.put(i, i); - map.put(i, i); - map.put(i, i); - map.put(i, i); - map.put(i, i); - map.put(i, i); - map.put(i, i); - } - } - - public void testTreeMapGet() { - int value; - TreeMap<String, Integer> map = sMap; - String[] keys = sKeys; - for (int i = ITERATIONS - 1; i >= 0; i--) { - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - value = map.get(keys[i]); - } - } - - public void testTreeMapFirstKey() { - String key; - TreeMap<String, Integer> map = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - key = map.firstKey(); - } - } - - public void testTreeMapKeySet() { - Set keyset; - TreeMap<String, Integer> map = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - keyset = map.keySet(); - } - } - - public void testTreeMapEntrySet() { - Set keyset; - TreeMap<String, Integer> map = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - keyset = map.entrySet(); - } - } - - public void testTreeMapValues() { - Collection collection; - TreeMap<String, Integer> map = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - collection = map.values(); - collection = map.values(); - collection = map.values(); - collection = map.values(); - collection = map.values(); - collection = map.values(); - collection = map.values(); - collection = map.values(); - collection = map.values(); - collection = map.values(); - } - } - - public void testTreeMapSize() { - int len; - TreeMap<String, Integer> map = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - len = map.size(); - len = map.size(); - len = map.size(); - len = map.size(); - len = map.size(); - len = map.size(); - len = map.size(); - len = map.size(); - len = map.size(); - len = map.size(); - } - } - - public void testTreeMapContainsKey() { - boolean flag; - String key = sKeys[525]; - TreeMap<String, Integer> map = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - flag = map.containsKey(key); - } - } - - public void testTreeMapContainsValue() { - boolean flag; - TreeMap<String, Integer> map = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - flag = map.containsValue(i); - } - } - - public void testTreeMapHeadMap() { - SortedMap map; - String str = sKeys[100]; - TreeMap<String, Integer> tMap = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - map = tMap.headMap(str); - } - } - - public void testTreeMapSubMap() { - String str1 = sKeys[400]; - String str2 = sKeys[500]; - SortedMap map; - TreeMap<String, Integer> tMap = sMap; - for (int i = ITERATIONS - 1; i >= 0; i--) { - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - map = tMap.subMap(str1, str2); - } - } - - public void testTreeMapTailMap() { - String str = sKeys[900]; - TreeMap<String, Integer> tMap = sMap; - SortedMap map; - for (int i = ITERATIONS - 1; i >= 0; i--) { - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - map = tMap.tailMap(str); - } - } - - @SuppressWarnings("unchecked") - public void testTreeMapRemove() { - TreeMap<String, Integer> tMap = new TreeMap(sMap); - String[] keys = sKeys; - for (int i = ITERATIONS - 1; i >= 0; i--) { - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - tMap.remove(keys[i]); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/TreeSetTest.java b/tests/AndroidTests/src/com/android/unit_tests/TreeSetTest.java deleted file mode 100644 index 60dfe9a..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/TreeSetTest.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -import java.util.TreeSet; -import java.util.SortedSet; -import java.util.Iterator; -import java.util.Comparator; - -/** - * Implements basic performance test functionality for java.util.TreeSet - */ - -public class TreeSetTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - public static TreeSet<Integer> sSet; - - @Override - protected void setUp() throws Exception { - super.setUp(); - sSet = new TreeSet<Integer>(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - sSet.add(i); - } - } - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - /** - * - * Tests performance for the java.util.TreeSet method Add(Object arg 0) - * - */ - - @SuppressWarnings("unchecked") - public void testTreeSetAdd() { - TreeSet<Integer> set = new TreeSet(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - set.add(i); - } - } - - /** - * - * Tests performance for the java.util.TreeSet method - first() - * - */ - - public void testTreeSetFirst() { - int value; - TreeSet<Integer> set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - value = set.first(); - value = set.first(); - value = set.first(); - value = set.first(); - value = set.first(); - value = set.first(); - value = set.first(); - value = set.first(); - value = set.first(); - } - } - - /** - * - * Tests performance for the java.util.TreeSet method - last() - * - */ - - public void testTreeSetLast() { - int value; - TreeSet<Integer> set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - value = set.last(); - value = set.last(); - value = set.last(); - value = set.last(); - value = set.last(); - value = set.last(); - value = set.last(); - value = set.last(); - value = set.last(); - } - } - - /** - * - * Tests performance of the java.util.TreeSet method- contains(Object arg0) - * - */ - - public void testTreeSetContains() { - Integer index = new Integer(500); - boolean flag; - TreeSet<Integer> set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - flag = set.contains(index); - } - } - - /** - * - * Tests performance for the java.util.TreeSet method - size() - * - */ - - public void testTreeSetSize() { - int value; - TreeSet<Integer> set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - value = set.size(); - value = set.size(); - value = set.size(); - value = set.size(); - value = set.size(); - value = set.size(); - value = set.size(); - value = set.size(); - value = set.size(); - } - } - - /** - * - * Tests performance for the java.util.TreeSet method - iterator() - * - */ - - public void testTreeSetIterator() { - Iterator iterator; - TreeSet<Integer> set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - iterator = set.iterator(); - } - } - - /** - * - * Tests performance for the java.util.TreeSet method - comparator() - * - */ - - public void testTreeSetComparator() { - Comparator comparator; - TreeSet<Integer> set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - comparator = set.comparator(); - comparator = set.comparator(); - comparator = set.comparator(); - comparator = set.comparator(); - comparator = set.comparator(); - comparator = set.comparator(); - comparator = set.comparator(); - comparator = set.comparator(); - comparator = set.comparator(); - } - } - - /** - * - * Tests performance for the java.util.TreeSet method - clone() - * - */ - - public void testTreeSetClone() { - Object obj; - TreeSet<Integer> set = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - obj = set.clone(); - } - } - - /** - * - * Tests performance of the java.util.TreeSet method - remove(Object arg0) - * - */ - - @SuppressWarnings("unchecked") - public void testTreeSetRemove() { - TreeSet<Integer> set = new TreeSet(sSet); - for (int i = ITERATIONS - 1; i >= 0; i--) { - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - set.remove(i); - } - } - - /** - * - * Tests performance of the java.util.TreeSet method- headSet(Integer arg0) - * - */ - - public void testTreeSetHeadSet() { - Integer value = new Integer(100); - SortedSet set; - TreeSet<Integer> tSet = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - set = tSet.headSet(value); - } - } - - /** - * - * Tests performance of subSet(Integer arg0, Integer arg1) - TreeSet - * - */ - - public void testTreeSetSubSet() { - Integer value = new Integer(400); - Integer nInt = new Integer(500); - SortedSet set; - TreeSet<Integer> tSet = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - set = tSet.subSet(value, nInt); - - } - - } - - /** - * - * Tests performance of tailSet(Integer arg0) - TreeSet - * - */ - - public void testTreeSetTailSet() { - Integer value = new Integer(900); - SortedSet set; - TreeSet<Integer> tSet = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - set = tSet.tailSet(value); - } - } - - /** - * - * Tests performance for the java.util.TreeSet method - isEmpty() - * - */ - - public void testTreeSetIsEmpty() { - boolean flag; - TreeSet<Integer> tSet = sSet; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - flag = tSet.isEmpty(); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/VectorTest.java b/tests/AndroidTests/src/com/android/unit_tests/VectorTest.java deleted file mode 100644 index 22f9771..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/VectorTest.java +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests; - -import android.test.PerformanceTestBase; -import android.test.PerformanceTestCase; - -import java.util.Vector; -import java.util.Enumeration; - -/** - * Basic Performance Tests for java.util.Vector - */ - -@SuppressWarnings("unchecked") -public class VectorTest extends PerformanceTestBase { - public static final int ITERATIONS = 1000; - private Vector<Integer> mVector; - private Vector<String> mStrVector; - private String mTestString = "Hello Android"; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mVector = new Vector(); - mStrVector = new Vector(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - assertTrue(mVector.add(i)); - assertTrue(mStrVector.add(Integer.toString(i))); - } - } - - @Override - public int startPerformance(PerformanceTestCase.Intermediates intermediates) { - intermediates.setInternalIterations(ITERATIONS); - return 0; - } - - public void testVectorAdd() { - Vector<Integer> vector = new Vector(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - vector.add(i); - vector.add(i); - vector.add(i); - vector.add(i); - vector.add(i); - vector.add(i); - vector.add(i); - vector.add(i); - vector.add(i); - vector.add(i); - } - } - - public void testVectorAdd1() { - Vector<Integer> vector = new Vector(); - for (int i = ITERATIONS - 1; i >= 0; i--) { - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - vector.add(0, i); - } - } - - public void testVectorToArray() { - Object array; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i >= 0; i--) { - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - array = vector.toArray(); - } - } - - /** - * - */ - public void testVectorSize() { - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i >= 0; i--) { - int mLen; - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - mLen = vector.size(); - } - } - - public void testVectorGet() { - int element; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i >= 0; i--) { - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - element = vector.get(i); - } - - } - - public void testVectorContains() { - boolean flag; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i >= 0; i--) { - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - flag = vector.contains(i); - } - } - - public void testVectorToArray1() { - Integer[] rArray = new Integer[100]; - Integer[] array; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i >= 0; i--) { - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - array = vector.toArray(rArray); - } - } - - public void testVectorSet() { - Vector<Integer> vector = mVector; - int pos = 5, value = 0; - for (int i = ITERATIONS - 1; i >= 0; i--) { - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - vector.set(pos, value); - } - } - - public void testVectorIndexOf() { - int index, value = 0; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - index = vector.indexOf(value); - } - } - - public void testVectorLastIndexOf() { - int index, value = 0; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i >= 0; i--) { - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - index = vector.lastIndexOf(value); - } - } - - public void testVectorRemove() { - int index, value = 0; - Vector<Integer> vector = new Vector(mVector); - for (int i = 10; i > 0; i--) { - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - index = vector.remove(value); - } - } - - public void testVectorRemoveElement() { - Vector<Integer> vector = new Vector(mVector); - for (int i = 10; i > 0; i--) { - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - vector.removeElement(i); - } - } - - public void VectorRemoveElementAt() { - Vector<Integer> vector = new Vector(mVector); - for (int i = 10; i > 0; i--) { - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - vector.removeElementAt(i); - } - } - - public void VectorAddAll() { - Vector<Integer> vector = new Vector(), vector1 = mVector; - - boolean flag; - for (int i = 10; i > 0; i--) { - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - flag = vector.addAll(vector1); - } - } - - public void VectorRemove1() { - Vector<String> vector = mStrVector; - for (int j = 1000; j > 0; j--) { - vector.add("a"); - vector.add("b"); - } - String s = new String("a"); - boolean flag; - for (int i = 10; i > 0; i--) { - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - flag = vector.remove(s); - } - } - - public void testVectorAddAll1() { - Vector<Integer> mEmptyVector = new Vector(); - boolean flag; - int pos = 0; - Vector<Integer> vector1 = mVector; - Vector<Integer> vector = mEmptyVector; - for (int i = 10; i > 0; i--) { - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - flag = vector.addAll(pos, vector1); - } - } - - public void testVectorClone() { - Object obj; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - obj = vector.clone(); - } - } - - public void testVectorCapacity() { - int capacity; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - capacity = vector.capacity(); - } - } - - public void testVectorHashcode() { - int element; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - element = vector.hashCode(); - } - } - - public void testVectorElements() { - Enumeration<Integer> elements; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - elements = vector.elements(); - } - } - - public void testVectorToString() { - String str; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - str = vector.toString(); - } - } - - public void testVectorElementAt() { - int element; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - element = vector.elementAt(50); - } - } - - public void testVectorAddElement() { - int element; - Vector<String> vector = mStrVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - vector.addElement(mTestString); - } - } - - public void testVectorFirstElement() { - int element; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - element = vector.firstElement(); - } - } - - public void testVectorLastElement() { - int element; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - element = vector.lastElement(); - } - } - - public void testVectorSetElementAt() { - Vector<Integer> vector = mVector; - int value1 = 500, value2 = 50; - for (int i = ITERATIONS - 1; i > 0; i--) { - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - vector.setElementAt(value1, value2); - } - } - - public void testVectorIsEmpty() { - boolean flag; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - flag = vector.isEmpty(); - } - } - - public void testVectorCopyInto() { - Integer[] rArray = new Integer[ITERATIONS]; - Vector<Integer> vector = mVector; - for (int i = ITERATIONS - 1; i > 0; i--) { - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - vector.copyInto(rArray); - } - } - - public void testVectorInsertElementAt() { - Vector<String> vector = mStrVector; - String string = mTestString; - for (int i = ITERATIONS - 1; i > 0; i--) { - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - vector.insertElementAt(string, i); - } - } -} diff --git a/tests/AndroidTests/src/com/android/unit_tests/internal/util/HanziToPinyinTest.java b/tests/AndroidTests/src/com/android/unit_tests/internal/util/HanziToPinyinTest.java deleted file mode 100644 index 71a8ea7..0000000 --- a/tests/AndroidTests/src/com/android/unit_tests/internal/util/HanziToPinyinTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.unit_tests.internal.util; - -import java.text.Collator; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.Locale; - -import android.test.suitebuilder.annotation.SmallTest; -import android.util.Log; - -import com.android.internal.util.HanziToPinyin; -import com.android.internal.util.HanziToPinyin.Token; - -import junit.framework.TestCase; - -public class HanziToPinyinTest extends TestCase { - private final static String ONE_HANZI = "\u675C"; - private final static String TWO_HANZI = "\u675C\u9D51"; - private final static String ASSIC = "test"; - private final static String ONE_UNKNOWN = "\uFF71"; - private final static String MISC = "test\u675C Test with space\uFF71\uFF71\u675C"; - - @SmallTest - public void testGetToken() throws Exception { - if (!Arrays.asList(Collator.getAvailableLocales()).contains(Locale.CHINA)) { - return; - } - ArrayList<Token> tokens = HanziToPinyin.getInstance().get(ONE_HANZI); - assertEquals(tokens.size(), 1); - assertEquals(tokens.get(0).type, Token.PINYIN); - assertTrue(tokens.get(0).target.equalsIgnoreCase("DU")); - - tokens = HanziToPinyin.getInstance().get(TWO_HANZI); - assertEquals(tokens.size(), 2); - assertEquals(tokens.get(0).type, Token.PINYIN); - assertEquals(tokens.get(1).type, Token.PINYIN); - assertTrue(tokens.get(0).target.equalsIgnoreCase("DU")); - assertTrue(tokens.get(1).target.equalsIgnoreCase("JUAN")); - - tokens = HanziToPinyin.getInstance().get(ASSIC); - assertEquals(tokens.size(), 1); - assertEquals(tokens.get(0).type, Token.LATIN); - - tokens = HanziToPinyin.getInstance().get(ONE_UNKNOWN); - assertEquals(tokens.size(), 1); - assertEquals(tokens.get(0).type, Token.UNKNOWN); - - tokens = HanziToPinyin.getInstance().get(MISC); - assertEquals(tokens.size(), 7); - assertEquals(tokens.get(0).type, Token.LATIN); - assertEquals(tokens.get(1).type, Token.PINYIN); - assertEquals(tokens.get(2).type, Token.LATIN); - assertEquals(tokens.get(3).type, Token.LATIN); - assertEquals(tokens.get(4).type, Token.LATIN); - assertEquals(tokens.get(5).type, Token.UNKNOWN); - assertEquals(tokens.get(6).type, Token.PINYIN); - } -} |