CameraFunctionalTestpublic class CameraFunctionalTest extends android.test.ActivityInstrumentationTestCase2 Junit / Instrumentation test case for the following camera APIs:
- flash
- exposure compensation
- white balance
- focus mode
adb shell am instrument
-e class com.android.mediaframeworktest.functional.camera.CameraFunctionalTest
-w com.android.mediaframework/.CameraStressTestRunner |
Fields Summary |
---|
private static final long | WAIT_TIMEOUT | private com.android.mediaframeworktest.CameraTestHelper | mCameraTestHelper | private android.os.Handler | mHandler | private Thread | mLooperThread | private Writer | mOutput | private String | TAG |
Constructors Summary |
---|
public CameraFunctionalTest()
super("com.android.mediaframeworktest", MediaFrameworkTest.class);
|
Methods Summary |
---|
private void | runOnLooper(java.lang.Runnable command)
final Semaphore sem = new Semaphore(0);
mHandler.post(new Runnable() {
@Override
public void run() {
try {
command.run();
} finally {
sem.release();
}
}
});
if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Failed to run the command on the looper.");
}
| protected void | setUp()
final Semaphore sem = new Semaphore(0);
mLooperThread = new Thread() {
@Override
public void run() {
Log.v(TAG, "starting looper");
Looper.prepare();
mHandler = new Handler();
sem.release();
Looper.loop();
Log.v(TAG, "quit looper");
}
};
mLooperThread.start();
if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Failed to start the looper.");
}
getActivity();
super.setUp();
mCameraTestHelper = new CameraTestHelper();
| protected void | tearDown()
if (mHandler != null) {
mHandler.getLooper().quit();
mHandler = null;
}
if (mLooperThread != null) {
mLooperThread.join(WAIT_TIMEOUT);
if (mLooperThread.isAlive()) {
fail("Failed to stop the looper.");
}
mLooperThread = null;
}
super.tearDown();
| public void | testFunctionalCameraExposureCompensation()Functional test iterating on the range of supported exposure compensation levels
try {
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
Parameters params = mCameraTestHelper.getCameraParameters();
int min = params.getMinExposureCompensation();
int max = params.getMaxExposureCompensation();
assertFalse("Adjusting exposure not supported", (max == 0 && min == 0));
float step = params.getExposureCompensationStep();
int stepsPerEV = (int) Math.round(Math.pow((double) step, -1));
// only get integer values for exposure compensation
for (int i = min; i <= max; i += stepsPerEV) {
runOnLooper(new Runnable() {
@Override
public void run() {
mCameraTestHelper.setupCameraTest();
}
});
Log.v(TAG, "Setting exposure compensation index to " + i);
params.setExposureCompensation(i);
mCameraTestHelper.setParameters(params);
mCameraTestHelper.startCameraPreview(surfaceHolder);
mCameraTestHelper.capturePhoto();
}
mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera exposure compensation test Exception");
}
| public void | testFunctionalCameraFlashModes()Functional test iterating on the various flash modes (on, off, auto, torch)
try {
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
Parameters params = mCameraTestHelper.getCameraParameters();
List<String> supportedFlashModes = params.getSupportedFlashModes();
assertNotNull("No flash modes supported", supportedFlashModes);
for (int i = 0; i < supportedFlashModes.size(); i++) {
runOnLooper(new Runnable() {
@Override
public void run() {
mCameraTestHelper.setupCameraTest();
}
});
Log.v(TAG, "Setting flash mode to " + supportedFlashModes.get(i));
params.setFlashMode(supportedFlashModes.get(i));
mCameraTestHelper.setParameters(params);
mCameraTestHelper.startCameraPreview(surfaceHolder);
mCameraTestHelper.capturePhoto();
}
mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera flash mode test Exception");
}
| public void | testFunctionalCameraFocusModes()Functional test iterating on the various focus modes (auto, infinitiy, macro, etc.)
try {
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
Parameters params = mCameraTestHelper.getCameraParameters();
List<String> supportedFocusModes = params.getSupportedFocusModes();
assertNotNull("No focus modes supported", supportedFocusModes);
for (int i = 0; i < supportedFocusModes.size(); i++) {
runOnLooper(new Runnable() {
@Override
public void run() {
mCameraTestHelper.setupCameraTest();
}
});
Log.v(TAG, "Setting focus mode to: " + supportedFocusModes.get(i));
params.setFocusMode(supportedFocusModes.get(i));
mCameraTestHelper.setParameters(params);
mCameraTestHelper.startCameraPreview(surfaceHolder);
mCameraTestHelper.capturePhoto();
}
mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera focus modes test Exception");
}
| public void | testFunctionalCameraWhiteBalance()Functional test iterating on the various white balances (auto, daylight, cloudy, etc.)
try {
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
Parameters params = mCameraTestHelper.getCameraParameters();
List<String> supportedWhiteBalance = params.getSupportedWhiteBalance();
assertNotNull("No white balance modes supported", supportedWhiteBalance);
for (int i = 0; i < supportedWhiteBalance.size(); i++) {
runOnLooper(new Runnable() {
@Override
public void run() {
mCameraTestHelper.setupCameraTest();
}
});
Log.v(TAG, "Setting white balance to: " + supportedWhiteBalance.get(i));
params.setWhiteBalance(supportedWhiteBalance.get(i));
mCameraTestHelper.setParameters(params);
mCameraTestHelper.startCameraPreview(surfaceHolder);
mCameraTestHelper.capturePhoto();
}
mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera focus modes test Exception");
}
|
|