FileDocCategorySizeDatePackage
CameraTest.javaAPI DocAndroid 1.5 API9574Wed May 06 22:42:00 BST 2009com.android.mediaframeworktest.functional

CameraTest

public class CameraTest extends android.test.ActivityInstrumentationTestCase
Junit / Instrumentation test case for the camera api

Fields Summary
private String
TAG
private boolean
rawPreviewCallbackResult
private boolean
shutterCallbackResult
private boolean
rawPictureCallbackResult
private boolean
jpegPictureCallbackResult
private static int
WAIT_FOR_COMMAND_TO_COMPLETE
private RawPreviewCallback
mRawPreviewCallback
private TestShutterCallback
mShutterCallback
private RawPictureCallback
mRawPictureCallback
private JpegPictureCallback
mJpegPictureCallback
private boolean
mInitialized
private android.os.Looper
mLooper
private final Object
lock
private final Object
previewDone
android.hardware.Camera
mCamera
android.content.Context
mContext
Constructors Summary
public CameraTest()

  
      
        super("com.android.mediaframeworktest", MediaFrameworkTest.class);
    
Methods Summary
private voidcheckPreviewCallback()

 
        SurfaceHolder mSurfaceHolder;
        try {
            mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
            mCamera.setPreviewDisplay(mSurfaceHolder);
            Log.v(TAG, "start preview");
            mCamera.startPreview();                      
            synchronized (previewDone) {
                try {
                    previewDone.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
                    Log.v(TAG, "setPreview done");
                } catch (Exception e) {
                    Log.v(TAG, "wait was interrupted.");
                }
            }
            mCamera.setPreviewCallback(null);
        } catch (Exception e) {
            Log.v(TAG, e.toString());
        }      
    
private voidcheckTakePicture()

 
        SurfaceHolder mSurfaceHolder;
        try {
            mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
            mCamera.setPreviewDisplay(mSurfaceHolder);
            Log.v(TAG, "Start preview");
            mCamera.startPreview();
            synchronized (previewDone) {
                try {
                    previewDone.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
                    Log.v(TAG, "Preview Done");
                } catch (Exception e) {
                    Log.v(TAG, "wait was interrupted.");
                }
            }
            mCamera.setPreviewCallback(null);
            mCamera.takePicture(mShutterCallback, mRawPictureCallback, mJpegPictureCallback);
            Thread.sleep(MediaNames.WAIT_LONG);
        } catch (Exception e) {
            Log.v(TAG, e.toString());
        }      
    
private voidinitializeMessageLooper()

        Log.v(TAG, "start looper");
        new Thread() {
            @Override
            public void run() {
                // Set up a looper to be used by camera.
                Looper.prepare();
                Log.v(TAG, "start loopRun");
                // Save the looper so that we can terminate this thread 
                // after we are done with it.
                mLooper = Looper.myLooper();                
                mCamera = Camera.open();                                
                synchronized (lock) {
                    mInitialized = true;
                    lock.notify();
                }
                Looper.loop();  // Blocks forever until Looper.quit() is called.
                Log.v(TAG, "initializeMessageLooper: quit.");
            }
        }.start();
    
protected voidsetUp()

        super.setUp(); 
    
private voidterminateMessageLooper()

        mLooper.quit();
        //TODO yslau : take out the sleep until bug#1693519 fix
        try {
            Thread.sleep(1000);
        } catch (Exception e){
            Log.v(TAG, e.toString());
        }
        mCamera.release();
    
public voidtestCheckPreview()

  
        synchronized (lock) {
            initializeMessageLooper();
            try {
                lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
            } catch(Exception e) {
                Log.v(TAG, "wait was interrupted.");
            }
        }
        mCamera.setPreviewCallback(mRawPreviewCallback);
        checkPreviewCallback();     
        terminateMessageLooper();
        assertTrue("RawPreviewCallbackResult", rawPreviewCallbackResult);
    
public voidtestTakePicture()

  
        synchronized (lock) {
            initializeMessageLooper();
            try {
                lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
            } catch(Exception e) {
                Log.v(TAG, "runTestOnMethod: wait was interrupted.");
            }
        }
        mCamera.setPreviewCallback(mRawPreviewCallback);
        checkTakePicture();
        terminateMessageLooper();
        assertTrue("shutterCallbackResult", shutterCallbackResult);
        assertTrue("rawPictureCallbackResult", rawPictureCallbackResult);
        assertTrue("jpegPictureCallbackResult", jpegPictureCallbackResult);