diff options
| author | 2017-05-11 23:59:49 +0000 | |
|---|---|---|
| committer | 2017-05-11 23:59:54 +0000 | |
| commit | cd32b42e1cf6c487572c0286a6cbdaadf1109879 (patch) | |
| tree | 900a6c282067e0e0919e77e7faf60e1525400f11 | |
| parent | 4116913e3a337dd2bdc24d7da6b85b565d85d31f (diff) | |
| parent | 6b771ce3c360a395d618de33d07d2403a0c6764b (diff) | |
Merge "Suppress AppCacheTest tests that cause am instrument failure." into oc-dev
| -rw-r--r-- | core/tests/coretests/src/android/content/pm/AppCacheTest.java | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/core/tests/coretests/src/android/content/pm/AppCacheTest.java b/core/tests/coretests/src/android/content/pm/AppCacheTest.java index 1567046aee2b..15dbddff54df 100644 --- a/core/tests/coretests/src/android/content/pm/AppCacheTest.java +++ b/core/tests/coretests/src/android/content/pm/AppCacheTest.java @@ -25,11 +25,11 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.StatFs; import android.os.UserHandle; +import android.support.test.filters.LargeTest; +import android.support.test.filters.MediumTest; +import android.support.test.filters.SmallTest; +import android.support.test.filters.Suppress; 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 java.io.File; @@ -48,14 +48,14 @@ public class AppCacheTest extends AndroidTestCase { public final long WAIT_TIME_INCR=10*1000; private static final long THRESHOLD=5; private static final long 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()) { @@ -72,13 +72,13 @@ public class AppCacheTest extends AndroidTestCase { } testDir.delete(); } - + void cleanUpCacheDirectory() { File testDir = mContext.getCacheDir(); if(!testDir.exists()) { return; } - + String fList[] = testDir.list(); if(fList == null) { testDir.delete(); @@ -93,7 +93,7 @@ public class AppCacheTest extends AndroidTestCase { } } } - + @SmallTest public void testDeleteAllCacheFiles() { String testName="testDeleteAllCacheFiles"; @@ -160,9 +160,9 @@ public class AppCacheTest extends AndroidTestCase { +(blks1-blks3)); } } - + /** - * This method opens an output file writes to it, opens the same file as an input + * 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) { @@ -180,7 +180,7 @@ public class AppCacheTest extends AndroidTestCase { failStr(e.getMessage()); } catch (IOException e) { failStr(e.getMessage()); - } + } int count = pFileOut.getBytes().length; byte[] buffer = new byte[count]; try { @@ -194,8 +194,8 @@ public class AppCacheTest extends AndroidTestCase { } String str = new String(buffer); assertEquals(str, pFileOut); - } - + } + /* * This test case verifies that output written to a file * using Context.openFileOutput has executed successfully. @@ -215,7 +215,7 @@ public class AppCacheTest extends AndroidTestCase { failStr(e); } } - + @SmallTest public void testAppCacheCreateFile() { String fileName = "testFile1.txt"; @@ -225,7 +225,7 @@ public class AppCacheTest extends AndroidTestCase { openOutFileInAppFilesDir(file, fileOut); cleanUpCacheDirectory(); } - + @MediumTest public void testAppCreateCacheFiles() { File cacheDir = mContext.getCacheDir(); @@ -261,7 +261,7 @@ public class AppCacheTest extends AndroidTestCase { } } } - + byte[] getBuffer() { String sbuffer = "a"; for(int i = 0; i < 10; i++) { @@ -360,7 +360,7 @@ public class AppCacheTest extends AndroidTestCase { } assertTrue("Files should have been removed", removedFlag); } - + //createTestFiles(new File(super.getContext().getCacheDir(), "testtmp", "dir", 3) void createTestFiles1(File cacheDir, String testFilePrefix, int numTestFiles) { byte buffer[] = getBuffer(); @@ -439,7 +439,7 @@ public class AppCacheTest extends AndroidTestCase { } } } - + class PackageDataObserver extends IPackageDataObserver.Stub { public boolean retValue = false; private boolean doneFlag = false; @@ -455,11 +455,11 @@ public class AppCacheTest extends AndroidTestCase { return doneFlag; } } - + IPackageManager getPm() { return IPackageManager.Stub.asInterface(ServiceManager.getService("package")); } - + boolean invokePMDeleteAppCacheFiles() throws Exception { try { String packageName = mContext.getPackageName(); @@ -485,7 +485,7 @@ public class AppCacheTest extends AndroidTestCase { return false; } } - + boolean invokePMFreeApplicationCache(long idealStorageSize) throws Exception { try { String packageName = mContext.getPackageName(); @@ -512,7 +512,7 @@ public class AppCacheTest extends AndroidTestCase { } } - boolean invokePMFreeStorage(long idealStorageSize, FreeStorageReceiver r, + boolean invokePMFreeStorage(long idealStorageSize, FreeStorageReceiver r, PendingIntent pi) throws Exception { try { // Spin lock waiting for call back @@ -536,7 +536,7 @@ public class AppCacheTest extends AndroidTestCase { return false; } } - + @LargeTest public void testDeleteAppCacheFiles() throws Exception { String testName="testDeleteAppCacheFiles"; @@ -551,7 +551,7 @@ public class AppCacheTest extends AndroidTestCase { public boolean retValue = false; public PackageStats stats; private boolean doneFlag = false; - + public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException { synchronized(this) { @@ -565,7 +565,7 @@ public class AppCacheTest extends AndroidTestCase { return doneFlag; } } - + public PackageStats invokePMGetPackageSizeInfo() throws Exception { try { String packageName = mContext.getPackageName(); @@ -593,7 +593,7 @@ public class AppCacheTest extends AndroidTestCase { return null; } } - + @SmallTest public void testGetPackageSizeInfo() throws Exception { String testName="testGetPackageSizeInfo"; @@ -603,7 +603,7 @@ public class AppCacheTest extends AndroidTestCase { if(localLOGV) Log.i(TAG, "code="+stats.codeSize+", data="+stats.dataSize+ ", cache="+stats.cacheSize); } - + @SmallTest public void testGetSystemSharedLibraryNames() throws Exception { try { @@ -615,17 +615,17 @@ public class AppCacheTest extends AndroidTestCase { } } 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)) { @@ -637,7 +637,7 @@ public class AppCacheTest extends AndroidTestCase { } } } - + // TODO: flaky test, omit from LargeTest for now //@LargeTest public void testFreeStorage() throws Exception { @@ -664,10 +664,10 @@ public class AppCacheTest extends AndroidTestCase { if(localLOGV || TRACKING) Log.i(TAG, "Available blocks after freeing cache"+blks3); assertEquals(receiver.getResultCode(), 1); mContext.unregisterReceiver(receiver); - // Verify result + // Verify result verifyTestFiles1(cacheDir, "testtmpdir", 5); } - + /* utility method used to create observer and check async call back from PackageManager. * ClearApplicationUserData */ @@ -696,7 +696,7 @@ public class AppCacheTest extends AndroidTestCase { return false; } } - + void verifyUserDataCleared(File pDir) { if(localLOGV) Log.i(TAG, "Verifying "+pDir); if(pDir == null) { @@ -717,7 +717,7 @@ public class AppCacheTest extends AndroidTestCase { fail(pDir+" should be empty or contain only lib subdirectory. Found "+fileList[i]); } } - + File getDataDir() { try { ApplicationInfo appInfo = getPm().getApplicationInfo(mContext.getPackageName(), 0, @@ -727,7 +727,8 @@ public class AppCacheTest extends AndroidTestCase { throw new RuntimeException("Pacakge manager dead", e); } } - + + @Suppress @LargeTest public void testClearApplicationUserDataWithTestData() throws Exception { File cacheDir = mContext.getCacheDir(); @@ -740,14 +741,16 @@ public class AppCacheTest extends AndroidTestCase { //confirm files dont exist verifyUserDataCleared(getDataDir()); } - + + @Suppress @SmallTest public void testClearApplicationUserDataWithNoTestData() throws Exception { assertTrue(invokePMClearApplicationUserData()); //confirm files dont exist verifyUserDataCleared(getDataDir()); } - + + @Suppress @LargeTest public void testClearApplicationUserDataNoObserver() throws Exception { getPm().clearApplicationUserData(mContext.getPackageName(), null, UserHandle.myUserId()); @@ -756,5 +759,5 @@ public class AppCacheTest extends AndroidTestCase { //confirm files dont exist verifyUserDataCleared(getDataDir()); } - + } |