FileDocCategorySizeDatePackage
ActivityTestsBase.javaAPI DocAndroid 1.5 API6169Wed May 06 22:42:02 BST 2009com.android.unit_tests.activity

ActivityTestsBase

public class ActivityTestsBase extends android.test.AndroidTestCase implements android.test.PerformanceTestCase, LaunchpadActivity.CallingTest

Fields Summary
public static final String
PERMISSION_GRANTED
public static final String
PERMISSION_DENIED
protected android.content.Intent
mIntent
private PerformanceTestCase.Intermediates
mIntermediates
private String
mExpecting
private boolean
mFinished
private int
mResultCode
private android.content.Intent
mData
private RuntimeException
mResultStack
Constructors Summary
Methods Summary
public voidactivityFinished(int resultCode, android.content.Intent data, java.lang.RuntimeException where)

        finishWithResult(resultCode, data, where);
    
public voidaddIntermediate(java.lang.String name)

        if (mIntermediates != null) {
            mIntermediates.addIntermediate(name);
        }
    
public voidaddIntermediate(java.lang.String name, long timeInNS)

        if (mIntermediates != null) {
            mIntermediates.addIntermediate(name, timeInNS);
        }
    
public android.content.IntenteditIntent()

        return mIntent;
    
public voidfinishBad(java.lang.String error)

        finishWithResult(Activity.RESULT_CANCELED, (new Intent()).setAction(error));
    
public voidfinishGood()

        finishWithResult(Activity.RESULT_OK, null);
    
public voidfinishTiming(boolean realTime)

        if (mIntermediates != null) {
            mIntermediates.finishTiming(realTime);
        }
    
public voidfinishWithResult(int resultCode, android.content.Intent data)

        RuntimeException where = new RuntimeException("Original error was here");
        where.fillInStackTrace();
        finishWithResult(resultCode, data, where);
    
public voidfinishWithResult(int resultCode, android.content.Intent data, java.lang.RuntimeException where)

        synchronized (this) {
            //System.out.println("*** Activity finished!!");
            mResultCode = resultCode;
            mData = data;
            mResultStack = where;
            mFinished = true;
            notifyAll();
        }
    
public android.content.ContextgetContext()

        return mContext;
    
public intgetResultCode()

        return mResultCode;
    
public android.content.IntentgetResultData()

        return mData;
    
public java.lang.RuntimeExceptiongetResultStack()

        return mResultStack;
    
public booleanisPerformanceOnly()

        return false;
    
public voidonTimeout()

        String msg = mExpecting == null
                ? "Timeout" : ("Timeout while expecting " + mExpecting);
        finishWithResult(Activity.RESULT_CANCELED, (new Intent()).setAction(msg));
    
public intrunLaunchpad(java.lang.String action)

        LaunchpadActivity.setCallingTest(this);

        synchronized (this) {
            mIntent.setAction(action);
            mFinished = false;
            //System.out.println("*** Starting: " + mIntent);
            mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(mIntent);
        }

        return waitForResultOrThrow(60 * 1000);
    
public voidsetInternalIterations(int count)

    
protected voidsetUp()


    
         
        super.setUp();
        mIntent = new Intent(mContext, LaunchpadActivity.class);
        mIntermediates = null;
    
public intstartPerformance(Intermediates intermediates)

        mIntermediates = intermediates;
        return 1;
    
public voidstartTiming(boolean realTime)

        if (mIntermediates != null) {
            mIntermediates.startTiming(realTime);
        }
    
protected voidtearDown()

        mIntermediates = null;
        super.tearDown();
    
public intwaitForResult(int timeoutMs, java.lang.String expected)

        mExpecting = expected;

        long endTime = System.currentTimeMillis() + timeoutMs;

        boolean timeout = false;
        synchronized (this) {
            while (!mFinished) {
                long delay = endTime - System.currentTimeMillis();
                if (delay < 0) {
                    timeout = true;
                    break;
                }

                try {
                    wait(delay);
                } catch (java.lang.InterruptedException e) {
                    // do nothing
                }
            }
        }

        mFinished = false;

        if (timeout) {
            mResultCode = Activity.RESULT_CANCELED;
            onTimeout();
        }
        return mResultCode;
    
public intwaitForResultOrThrow(int timeoutMs)

        return waitForResultOrThrow(timeoutMs, null);
    
public intwaitForResultOrThrow(int timeoutMs, java.lang.String expected)

        int res = waitForResult(timeoutMs, expected);

        if (res == Activity.RESULT_CANCELED) {
            if (mResultStack != null) {
                throw new RuntimeException(
                        mData != null ? mData.toString() : "Unable to launch",
                        mResultStack);
            } else {
                throw new RuntimeException(
                        mData != null ? mData.toString() : "Unable to launch");
            }
        }
        return res;