summaryrefslogtreecommitdiffstats
path: root/media/tests/MediaFrameworkTest/src
diff options
context:
space:
mode:
authorJason Noguchi <jnoguchi@google.com>2013-05-01 16:59:22 -0700
committerJason Noguchi <jnoguchi@google.com>2013-05-28 15:28:32 -0700
commitc6cedc84f49b8b72d32069cfa515a51b8c128cc0 (patch)
tree73024ee413d52583f002af472a8ef5f0ecd362c2 /media/tests/MediaFrameworkTest/src
parenteed8411c8cc1f163ba06a928e3b4b6d3f1045282 (diff)
downloadframeworks_base-c6cedc84f49b8b72d32069cfa515a51b8c128cc0.zip
frameworks_base-c6cedc84f49b8b72d32069cfa515a51b8c128cc0.tar.gz
frameworks_base-c6cedc84f49b8b72d32069cfa515a51b8c128cc0.tar.bz2
Refactor of camera stress test to add camera test helper. Also add
additional functional tests for: flash, exposure, white balance, and focus mode. Also add pairwise tests. Slight refactor to add camera test helper and also additional tests for: flash, exposure, white balance, and focus mode Bug: 9174937 Change-Id: I3d26b545dc8ff972c8173066df59a2e572a837ef
Diffstat (limited to 'media/tests/MediaFrameworkTest/src')
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraStressTestRunner.java4
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraTestHelper.java165
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java12
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraFunctionalTest.java255
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraPairwiseTest.java501
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java255
6 files changed, 995 insertions, 197 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraStressTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraStressTestRunner.java
index fa59fa4..23b9705 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraStressTestRunner.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraStressTestRunner.java
@@ -19,6 +19,8 @@ package com.android.mediaframeworktest;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
import com.android.mediaframeworktest.stress.CameraStressTest;
+import com.android.mediaframeworktest.functional.camera.CameraFunctionalTest;
+import com.android.mediaframeworktest.functional.camera.CameraPairwiseTest;
import junit.framework.TestSuite;
@@ -28,6 +30,8 @@ public class CameraStressTestRunner extends InstrumentationTestRunner {
public TestSuite getAllTests() {
TestSuite suite = new InstrumentationTestSuite(this);
suite.addTestSuite(CameraStressTest.class);
+ suite.addTestSuite(CameraFunctionalTest.class);
+ suite.addTestSuite(CameraPairwiseTest.class);
return suite;
}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraTestHelper.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraTestHelper.java
new file mode 100644
index 0000000..8bf741c
--- /dev/null
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/CameraTestHelper.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2013 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.mediaframeworktest;
+
+import android.hardware.Camera;
+import android.hardware.Camera.Parameters;
+import android.hardware.Camera.PictureCallback;
+import android.hardware.Camera.ShutterCallback;
+import android.os.Environment;
+import android.util.Log;
+import android.view.SurfaceHolder;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+public class CameraTestHelper {
+
+ public Camera mCamera;
+ private String TAG = "CameraTestHelper";
+ private static final int CAMERA_ID = 0;
+ private static final long WAIT_GENERIC = 3 * 1000; // 3 seconds
+ private static final long WAIT_ZOOM_ANIMATION = 5 * 1000; // 5 seconds
+ protected static final String CAMERA_STRESS_IMAGES_DIRECTORY = "cameraStressImages";
+ private static final String CAMERA_STRESS_IMAGES_PREFIX = "camera-stress-test";
+ private final CameraErrorCallback mCameraErrorCallback = new CameraErrorCallback();
+
+ private final class CameraErrorCallback implements android.hardware.Camera.ErrorCallback {
+ public void onError(int error, android.hardware.Camera camera) {
+ Assert.fail(String.format("Camera error, code: %d", error));
+ }
+ }
+
+ private ShutterCallback shutterCallback = new ShutterCallback() {
+ @Override
+ public void onShutter() {
+ Log.v(TAG, "Shutter");
+ }
+ };
+
+ private PictureCallback rawCallback = new PictureCallback() {
+ @Override
+ public void onPictureTaken(byte[] data, Camera camera) {
+ Log.v(TAG, "Raw picture taken");
+ }
+ };
+
+ private PictureCallback jpegCallback = new PictureCallback() {
+ @Override
+ public void onPictureTaken(byte[] data, Camera camera) {
+ FileOutputStream fos = null;
+
+ try {
+ Log.v(TAG, "JPEG picture taken");
+ fos = new FileOutputStream(String.format("%s/%s/%s-%d.jpg",
+ Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY,
+ CAMERA_STRESS_IMAGES_PREFIX, System.currentTimeMillis()));
+ fos.write(data);
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "File not found: " + e.toString());
+ } catch (IOException e) {
+ Log.e(TAG, "Error accessing file: " + e.toString());
+ } finally {
+ try {
+ if (fos != null) {
+ fos.close();
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "Error closing file: " + e.toString());
+ }
+ }
+ }
+ };
+
+ /**
+ * Helper method for prepping test
+ */
+ public void setupCameraTest() {
+ // Create the test images directory if it doesn't exist
+ File stressImagesDirectory = new File(String.format("%s/%s",
+ Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY));
+ if (!stressImagesDirectory.exists()) {
+ stressImagesDirectory.mkdir();
+ }
+
+ mCamera = Camera.open(CAMERA_ID);
+ }
+
+ /**
+ * Helper method for getting the available parameters of the default camera
+ */
+ public Parameters getCameraParameters() {
+ mCamera = Camera.open(CAMERA_ID);
+ Parameters params = mCamera.getParameters();
+ mCamera.release();
+ return params;
+ }
+
+ /**
+ * Helper method for taking a photo
+ */
+ public void capturePhoto() throws Exception {
+ mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
+ Thread.sleep(WAIT_GENERIC);
+ mCamera.stopPreview();
+ mCamera.release();
+ }
+
+ /**
+ * Helper method for cleaning up pics taken during tests
+ */
+ public void cleanupTestImages() {
+ try {
+ File stressImagesDirectory = new File(String.format("%s/%s",
+ Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY));
+ File[] stressImages = stressImagesDirectory.listFiles();
+ for (File f : stressImages) {
+ f.delete();
+ }
+ } catch (SecurityException e) {
+ Log.e(TAG, "Security manager access violation: " + e.toString());
+ }
+ }
+
+ /**
+ * Helper method for setting the camera parameters
+ */
+ public void setParameters(Parameters params) {
+ try {
+ mCamera.setParameters(params);
+ } catch (Exception e) {
+ Log.e(TAG, "Error setting camera parameters");
+ }
+ }
+
+ /**
+ * Helper method for starting up the camera preview
+ */
+ public void startCameraPreview(SurfaceHolder surfaceHolder) throws Exception {
+ mCamera.setErrorCallback(mCameraErrorCallback);
+ mCamera.setPreviewDisplay(surfaceHolder);
+ mCamera.startPreview();
+ Thread.sleep(WAIT_GENERIC);
+ }
+}
+
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java
index ed9bb97..10df2e6 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java
@@ -48,9 +48,9 @@ import java.io.File;
import java.io.FileDescriptor;
import java.net.InetAddress;
-
+
public class MediaFrameworkTest extends Activity implements SurfaceHolder.Callback {
-
+
//public static Surface video_sf;
public static SurfaceView mSurfaceView;
private MediaController mMediaController;
@@ -58,10 +58,10 @@ public class MediaFrameworkTest extends Activity implements SurfaceHolder.Callba
private MediaPlayer mpmidi;
private MediaPlayer mpmp3;
private String testfilepath = "/sdcard/awb.awb";
-
+
public static AssetFileDescriptor midiafd;
public static AssetFileDescriptor mp3afd;
-
+
public static Bitmap mDestBitmap;
public static ImageView mOverlayView;
private SurfaceHolder mSurfaceHolder = null;
@@ -82,10 +82,10 @@ public class MediaFrameworkTest extends Activity implements SurfaceHolder.Callba
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mSurfaceHolder.addCallback(this);
-
+
//Get the midi fd
midiafd = this.getResources().openRawResourceFd(R.raw.testmidi);
-
+
//Get the mp3 fd
mp3afd = this.getResources().openRawResourceFd(R.raw.testmp3);
mOverlayView.setLayoutParams(lp);
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraFunctionalTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraFunctionalTest.java
new file mode 100644
index 0000000..e6f0aaf
--- /dev/null
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraFunctionalTest.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (C) 2013 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.mediaframeworktest.functional.camera;
+
+import com.android.mediaframeworktest.MediaFrameworkTest;
+import com.android.mediaframeworktest.CameraTestHelper;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import android.hardware.Camera;
+import android.hardware.Camera.Parameters;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Looper;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.FloatMath;
+import android.util.Log;
+import android.view.SurfaceHolder;
+import com.android.mediaframeworktest.CameraStressTestRunner;
+
+import junit.framework.Assert;
+
+/**
+ * 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
+ */
+public class CameraFunctionalTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> {
+ private static final long WAIT_TIMEOUT = 10 * 1000; // 10 seconds
+ private CameraTestHelper mCameraTestHelper;
+ private Handler mHandler;
+ private Thread mLooperThread;
+ private Writer mOutput;
+
+ private String TAG = "CameraFunctionalTest";
+
+ public CameraFunctionalTest() {
+ super("com.android.mediaframeworktest", MediaFrameworkTest.class);
+ }
+
+ protected void setUp() throws Exception {
+ 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();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ 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();
+ }
+
+ private void runOnLooper(final Runnable command) throws InterruptedException {
+ 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.");
+ }
+ }
+
+ /**
+ * Functional test iterating on the range of supported exposure compensation levels
+ */
+ @LargeTest
+ public void testFunctionalCameraExposureCompensation() throws Exception {
+ 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");
+ }
+ }
+
+ /**
+ * Functional test iterating on the various flash modes (on, off, auto, torch)
+ */
+ @LargeTest
+ public void testFunctionalCameraFlashModes() throws Exception {
+ 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");
+ }
+ }
+
+ /**
+ * Functional test iterating on the various focus modes (auto, infinitiy, macro, etc.)
+ */
+ @LargeTest
+ public void testFunctionalCameraFocusModes() throws Exception {
+ 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");
+ }
+ }
+
+ /**
+ * Functional test iterating on the various white balances (auto, daylight, cloudy, etc.)
+ */
+ @LargeTest
+ public void testFunctionalCameraWhiteBalance() throws Exception {
+ 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");
+ }
+ }
+}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraPairwiseTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraPairwiseTest.java
new file mode 100644
index 0000000..61b708a
--- /dev/null
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/camera/CameraPairwiseTest.java
@@ -0,0 +1,501 @@
+/*
+ * Copyright (C) 2013 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.mediaframeworktest.functional.camera;
+
+import android.hardware.Camera;
+import android.hardware.Camera.PictureCallback;
+import android.hardware.Camera.ShutterCallback;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Looper;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.FloatMath;
+import android.util.Log;
+import android.view.SurfaceHolder;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.List;
+
+import com.android.mediaframeworktest.MediaFrameworkTest;
+import com.android.mediaframeworktest.CameraStressTestRunner;
+import com.android.mediaframeworktest.CameraTestHelper;
+import junit.framework.Assert;
+
+/**
+ * Junit / Instrumentation test case for camera API pairwise testing
+ * Settings tested against: flash mode, exposure compensation, white balance,
+ * scene mode, picture size, and geotagging
+ *
+ * adb shell am instrument
+ * - e class com.android.mediaframeworktest.stress.CameraPairwiseTest
+ * - w com.android.mediaframeworktest/.CameraStressTestRunner
+ */
+public class CameraPairwiseTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> {
+ private CameraTestHelper mCameraTestHelper;
+ private Handler mHandler;
+ private Thread mLooperThread;
+ private String TAG = "CameraPairwiseTest";
+
+ private static final long WAIT_TIMEOUT = 10 * 1000; // 10 seconds
+
+ // coordinates of the Getty Museuem in Los Angeles
+ private static final double MOCK_LATITUDE = 34.076621;
+ private static final double MOCK_LONGITUDE = -118.473215;
+
+ // camera setting enums
+ public enum Flash { ON, OFF, AUTO };
+ public enum Exposure { MIN, MAX, NONE };
+ public enum WhiteBalance { DAYLIGHT, FLUORESCENT, CLOUDY, INCANDESCENT, AUTO };
+ public enum SceneMode { SUNSET, ACTION, PARTY, NIGHT, AUTO };
+ public enum PictureSize { SMALL, MEDIUM, LARGE };
+ public enum Geotagging { ON, OFF };
+
+ public CameraPairwiseTest() {
+ super("com.android.mediaframeworktest", MediaFrameworkTest.class);
+ }
+
+ protected void setUp() throws Exception {
+ 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();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ 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();
+ }
+
+ private void runOnLooper(final Runnable command) throws InterruptedException {
+ 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.");
+ }
+ }
+
+ /**
+ * Flash: Auto / Exposure: None / WB: Daylight
+ * Scene: Sunset / Pic: Medium / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario01() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.NONE, WhiteBalance.DAYLIGHT, SceneMode.SUNSET,
+ PictureSize.MEDIUM, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: On / Exposure: Min / WB: Fluorescent
+ * Scene: Auto / Pic: Large / Geo: on
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario02() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.MIN, WhiteBalance.FLUORESCENT, SceneMode.AUTO,
+ PictureSize.LARGE, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Off / Exposure: Max / WB: Auto
+ * Scene: Night / Pic: Small / Geo: on
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario03() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.MAX, WhiteBalance.AUTO, SceneMode.NIGHT,
+ PictureSize.SMALL, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Off / Exposure: Max / WB: Cloudy
+ * Scene: Auto / Pic: Med / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario04() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.MAX, WhiteBalance.CLOUDY, SceneMode.AUTO,
+ PictureSize.MEDIUM, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Auto / Exposure: Max / WB: Incandescent
+ * Scene: Auto / Pic: Large / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario05() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.MAX, WhiteBalance.INCANDESCENT,
+ SceneMode.AUTO, PictureSize.LARGE, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: On / Exposure: None / WB: Cloudy
+ * Scene: Auto / Pic: Small / Geo: on
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario06() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.NONE, WhiteBalance.CLOUDY, SceneMode.AUTO,
+ PictureSize.SMALL, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Auto / Exposure: Min / WB: Auto
+ * Scene: Action / Pic: Small / Geo: on
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario07() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.MIN, WhiteBalance.AUTO, SceneMode.ACTION,
+ PictureSize.SMALL, Geotagging.ON);
+ }
+
+ /**
+ * Flash: On / Exposure: Min / WB: Auto
+ * Scene: Action / Pic: Medium / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario08() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.MIN, WhiteBalance.AUTO, SceneMode.ACTION,
+ PictureSize.MEDIUM, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Off / Exposure: Min / WB: Auto
+ * Scene: Night / Pic: Large / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario09() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.MIN, WhiteBalance.AUTO, SceneMode.NIGHT,
+ PictureSize.LARGE, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Off / Exposure: Min / WB: Daylight
+ * Scene: Sunset / Pic: Small / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario10() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.MIN, WhiteBalance.DAYLIGHT, SceneMode.SUNSET,
+ PictureSize.SMALL, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: On / Exposure: Max / WB: Daylight
+ * Scene: Sunset / Pic: Large / Geo: on
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario11() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.MAX, WhiteBalance.DAYLIGHT, SceneMode.SUNSET,
+ PictureSize.LARGE, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Auto / Exposure: Min / WB: Cloudy
+ * Scene: Auto / Pic: Large / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario12() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.MIN, WhiteBalance.CLOUDY, SceneMode.AUTO,
+ PictureSize.LARGE, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Off / Exposure: None / WB: Auto
+ * Scene: Party / Pic: Medium / Geo: on
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario13() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.NONE, WhiteBalance.AUTO, SceneMode.PARTY,
+ PictureSize.MEDIUM, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Auto / Exposure: None / WB: Auto
+ * Scene: Night / Pic: Small / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario14() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.NONE, WhiteBalance.AUTO, SceneMode.NIGHT,
+ PictureSize.SMALL, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: On / Exposure: None / WB: Incandescent
+ * Scene: Auto / Pic: Medium / Geo: on
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario15() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.NONE, WhiteBalance.INCANDESCENT, SceneMode.AUTO,
+ PictureSize.MEDIUM, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Auto / Exposure: Min / WB: Auto
+ * Scene: Party / Pic: Small / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario16() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.MIN, WhiteBalance.AUTO, SceneMode.PARTY,
+ PictureSize.SMALL, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Off / Exposure: Min / WB: Incandescent
+ * Scene: Auto / Pic: Small / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario17() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.MIN, WhiteBalance.INCANDESCENT, SceneMode.AUTO,
+ PictureSize.SMALL, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: On / Exposure: None / WB: Auto
+ * Scene: Party / Pic: Large / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario18() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.NONE, WhiteBalance.AUTO, SceneMode.PARTY,
+ PictureSize.LARGE, Geotagging.OFF);
+ }
+
+ /**
+ * Flash Off / Exposure: None / WB: Auto
+ * Scene: Action / Pic: Large / Geo: off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario19() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.NONE, WhiteBalance.AUTO, SceneMode.ACTION,
+ PictureSize.LARGE, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Off / Exposure: Max / WB: Fluorescent
+ * Scene: Auto / Pic: Medium / Geo: Off
+ */
+ @LargeTest
+ public void testCameraPairwiseScenario20() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.MAX, WhiteBalance.FLUORESCENT, SceneMode.AUTO,
+ PictureSize.MEDIUM, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Off / Exposure: Min / WB: Auto
+ * Scene: Auto / Pic: Medium / Geo: off
+ */
+ public void testCameraPairwiseScenario21() throws Exception {
+ genericPairwiseTestCase(Flash.OFF, Exposure.MIN, WhiteBalance.AUTO, SceneMode.AUTO,
+ PictureSize.MEDIUM, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: On / Exposure: Max / WB: Auto
+ * Scene: Action / Pic: Small / Geo: off
+ */
+ public void testCameraPairwiseScenario22() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.MAX, WhiteBalance.AUTO, SceneMode.ACTION,
+ PictureSize.SMALL, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: On / Exposure: Max / WB: Auto
+ * Scene: Night / Pic: Medium / Geo: on
+ */
+ public void testCameraPairwiseScenario23() throws Exception {
+ genericPairwiseTestCase(Flash.ON, Exposure.MAX, WhiteBalance.AUTO, SceneMode.NIGHT,
+ PictureSize.MEDIUM, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Auto / Exposure: None / WB: Fluorescent
+ * Scene: Auto / Pic: Small / Geo: on
+ */
+ public void testCameraPairwiseScenario24() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.NONE, WhiteBalance.FLUORESCENT,
+ SceneMode.AUTO, PictureSize.SMALL, Geotagging.ON);
+ }
+
+ /**
+ * Flash: Auto / Exposure: Max / WB: Daylight
+ * Scene: Auto / Pic: Medium / Geo: off
+ */
+ public void testCameraPairwiseScenario25() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.MAX, WhiteBalance.DAYLIGHT, SceneMode.AUTO,
+ PictureSize.MEDIUM, Geotagging.OFF);
+ }
+
+ /**
+ * Flash: Auto / Exposure: Max / WB: Auto
+ * Scene: Party / Pic: Medium / Geo: on
+ */
+ public void testCameraPairwiseScenario26() throws Exception {
+ genericPairwiseTestCase(Flash.AUTO, Exposure.MAX, WhiteBalance.AUTO, SceneMode.PARTY,
+ PictureSize.MEDIUM, Geotagging.ON);
+ }
+
+ /**
+ * Generic pairwise test method
+ */
+ private void genericPairwiseTestCase(Flash flash, Exposure exposure, WhiteBalance whitebalance,
+ SceneMode scenemode, PictureSize picturesize, Geotagging geotagging) throws Exception {
+ try {
+ SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
+ Camera.Parameters params = mCameraTestHelper.getCameraParameters();
+
+ runOnLooper(new Runnable() {
+ @Override
+ public void run() {
+ mCameraTestHelper.setupCameraTest();
+ }
+ });
+
+ // Configure flash setting
+ switch (flash) {
+ case ON:
+ params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
+ break;
+ case OFF:
+ params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
+ break;
+ case AUTO:
+ params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
+ break;
+ }
+
+ // Configure exposure setting
+ switch (exposure) {
+ case MIN:
+ params.setExposureCompensation(params.getMinExposureCompensation());
+ break;
+ case MAX:
+ params.setExposureCompensation(params.getMaxExposureCompensation());
+ break;
+ case NONE:
+ params.setExposureCompensation(0);
+ break;
+ }
+
+ // Configure white balance setting
+ switch (whitebalance) {
+ case DAYLIGHT:
+ params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_DAYLIGHT);
+ break;
+ case FLUORESCENT:
+ params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_FLUORESCENT);
+ break;
+ case INCANDESCENT:
+ params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_INCANDESCENT);
+ break;
+ case CLOUDY:
+ params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT);
+ break;
+ case AUTO:
+ params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
+ break;
+ }
+
+ // Configure scene mode setting
+ switch (scenemode) {
+ case SUNSET:
+ params.setSceneMode(Camera.Parameters.SCENE_MODE_SUNSET);
+ break;
+ case ACTION:
+ params.setSceneMode(Camera.Parameters.SCENE_MODE_ACTION);
+ break;
+ case PARTY:
+ params.setSceneMode(Camera.Parameters.SCENE_MODE_PARTY);
+ break;
+ case NIGHT:
+ params.setSceneMode(Camera.Parameters.SCENE_MODE_NIGHT);
+ break;
+ case AUTO:
+ params.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
+ break;
+ }
+
+ // Configure picture size setting
+ List<Camera.Size> supportedPictureSizes = params.getSupportedPictureSizes();
+ int mid = (int) Math.floor(supportedPictureSizes.size() / 2);
+ int low = supportedPictureSizes.size() - 1;
+ switch (picturesize) {
+ case SMALL:
+ params.setPictureSize(supportedPictureSizes.get(low).width,
+ supportedPictureSizes.get(low).height);
+ break;
+ case MEDIUM:
+ params.setPictureSize(supportedPictureSizes.get(mid).width,
+ supportedPictureSizes.get(mid).height);
+ break;
+ case LARGE:
+ params.setPictureSize(supportedPictureSizes.get(0).width,
+ supportedPictureSizes.get(mid).height);
+ break;
+ }
+
+ // Configure geotagging setting
+ switch (geotagging) {
+ case ON:
+ params.setGpsLatitude(MOCK_LATITUDE);
+ params.setGpsLongitude(MOCK_LONGITUDE);
+ break;
+ case OFF:
+ break;
+ }
+
+ mCameraTestHelper.setParameters(params);
+ mCameraTestHelper.startCameraPreview(surfaceHolder);
+ mCameraTestHelper.capturePhoto();
+ mCameraTestHelper.cleanupTestImages();
+ } catch (Exception e) {
+ Log.e(TAG, e.toString());
+ fail("Test case failed");
+ }
+ }
+}
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java
index ed1d8fc..a112c73 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/CameraStressTest.java
@@ -17,13 +17,11 @@
package com.android.mediaframeworktest.stress;
import com.android.mediaframeworktest.MediaFrameworkTest;
+import com.android.mediaframeworktest.CameraTestHelper;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FilenameFilter;
import java.io.FileWriter;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.util.concurrent.Semaphore;
@@ -31,8 +29,7 @@ import java.util.concurrent.TimeUnit;
import java.util.List;
import android.hardware.Camera;
-import android.hardware.Camera.PictureCallback;
-import android.hardware.Camera.ShutterCallback;
+import android.hardware.Camera.Parameters;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
@@ -45,32 +42,28 @@ import com.android.mediaframeworktest.CameraStressTestRunner;
import junit.framework.Assert;
/**
- * Junit / Instrumentation test case for the camera zoom and scene mode APIs
+ * Junit / Instrumentation test case for the following camera APIs:
+ * - camera zoom
+ * - scene mode
*
* adb shell am instrument
* -e class com.android.mediaframeworktest.stress.CameraStressTest
* -w com.android.mediaframeworktest/.CameraStressTestRunner
*/
public class CameraStressTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> {
- private String TAG = "CameraStressTest";
- private Camera mCamera;
- private static final int CAMERA_ID = 0;
- private static final int NUMBER_OF_ZOOM_LOOPS = 100;
private static final int NUMBER_OF_SCENE_MODE_LOOPS = 10;
- private static final long WAIT_GENERIC = 3 * 1000; // 3 seconds
+ private static final int NUMBER_OF_ZOOM_LOOPS = 100;
private static final long WAIT_TIMEOUT = 10 * 1000; // 10 seconds
- private static final long WAIT_ZOOM_ANIMATION = 5 * 1000; // 5 seconds
- private static final String CAMERA_STRESS_IMAGES_DIRECTORY = "cameraStressImages";
- private static final String CAMERA_STRESS_IMAGES_PREFIX = "camera-stress-test";
private static final String CAMERA_STRESS_OUTPUT = "cameraStressOutput.txt";
- private final CameraErrorCallback mCameraErrorCallback = new CameraErrorCallback();
- private Thread mLooperThread;
+ private CameraTestHelper mCameraTestHelper;
private Handler mHandler;
-
+ private Thread mLooperThread;
private Writer mOutput;
+ private String TAG = "CameraStressTest";
+
public CameraStressTest() {
super("com.android.mediaframeworktest", MediaFrameworkTest.class);
}
@@ -95,19 +88,11 @@ public class CameraStressTest extends ActivityInstrumentationTestCase2<MediaFram
getActivity();
super.setUp();
- File sdcard = Environment.getExternalStorageDirectory();
-
- // Create the test images directory if it doesn't exist
- File stressImagesDirectory = new File(String.format("%s/%s", sdcard,
- CAMERA_STRESS_IMAGES_DIRECTORY));
- if (!stressImagesDirectory.exists()) {
- stressImagesDirectory.mkdir();
- }
-
- // Start writing output file
- File stressOutFile = new File(String.format("%s/%s",sdcard, CAMERA_STRESS_OUTPUT));
+ mCameraTestHelper = new CameraTestHelper();
+ File stressOutFile = new File(String.format("%s/%s",
+ Environment.getExternalStorageDirectory(), CAMERA_STRESS_OUTPUT));
mOutput = new BufferedWriter(new FileWriter(stressOutFile, true));
- mOutput.write(this.getName() + ":\n");
+ mOutput.write(this.getName() + "\n");
}
@Override
@@ -123,10 +108,8 @@ public class CameraStressTest extends ActivityInstrumentationTestCase2<MediaFram
}
mLooperThread = null;
}
-
mOutput.write("\n\n");
mOutput.close();
-
super.tearDown();
}
@@ -147,126 +130,67 @@ public class CameraStressTest extends ActivityInstrumentationTestCase2<MediaFram
}
}
- private final class CameraErrorCallback implements android.hardware.Camera.ErrorCallback {
- public void onError(int error, android.hardware.Camera camera) {
- fail(String.format("Camera error, code: %d", error));
- }
- }
-
- private ShutterCallback shutterCallback = new ShutterCallback() {
- @Override
- public void onShutter() {
- Log.v(TAG, "Shutter");
- }
- };
+ /**
+ * Stress test iterating on the various scene modes (action, night, party, etc.)
+ */
+ @LargeTest
+ public void testStressCameraSceneModes() throws Exception {
+ try {
+ SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
+ Parameters params = mCameraTestHelper.getCameraParameters();
+ List<String> supportedSceneModes = params.getSupportedSceneModes();
+ assertNotNull("No scene modes supported", supportedSceneModes);
- private PictureCallback rawCallback = new PictureCallback() {
- @Override
- public void onPictureTaken(byte[] data, Camera camera) {
- Log.v(TAG, "Raw picture taken");
- }
- };
+ mOutput.write("Total number of loops: " +
+ (NUMBER_OF_SCENE_MODE_LOOPS * supportedSceneModes.size()) + "\n");
+ Log.v(TAG, "Start preview");
+ mOutput.write("No of loop: ");
- private PictureCallback jpegCallback = new PictureCallback() {
- @Override
- public void onPictureTaken(byte[] data, Camera camera) {
- FileOutputStream fos = null;
+ for (int i = 0; i < supportedSceneModes.size(); i++) {
+ for (int j = 0; j < NUMBER_OF_SCENE_MODE_LOOPS; j++) {
+ runOnLooper(new Runnable() {
+ @Override
+ public void run() {
+ mCameraTestHelper.setupCameraTest();
+ }
+ });
+ Log.v(TAG, "Setting scene mode to " + supportedSceneModes.get(i));
+ params.setSceneMode(supportedSceneModes.get(i));
+ mCameraTestHelper.setParameters(params);
+ mCameraTestHelper.startCameraPreview(surfaceHolder);
+ mCameraTestHelper.capturePhoto();
- try {
- Log.v(TAG, "JPEG picture taken");
- fos = new FileOutputStream(String.format("%s/%s/%s-%d.jpg",
- Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY,
- CAMERA_STRESS_IMAGES_PREFIX, System.currentTimeMillis()));
- fos.write(data);
- } catch (FileNotFoundException e) {
- Log.e(TAG, "File not found: " + e.toString());
- } catch (IOException e) {
- Log.e(TAG, "Error accessing file: " + e.toString());
- } finally {
- try {
- if (fos != null) {
- fos.close();
+ if (i == 0 && j == 0) {
+ mOutput.write(Integer.toString(j + i * NUMBER_OF_SCENE_MODE_LOOPS));
+ } else {
+ mOutput.write(", " + (j + i * NUMBER_OF_SCENE_MODE_LOOPS));
}
- } catch (IOException e) {
- Log.e(TAG, "Error closing file: " + e.toString());
- }
- }
- }
- };
-
- // Helper method for cleaning up pics taken during testStressCameraZoom
- private void cleanupStressTestImages() {
- try {
- File stressImagesDirectory = new File(String.format("%s/%s",
- Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY));
- File[] zoomImages = null;
-
- FilenameFilter filter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.startsWith(CAMERA_STRESS_IMAGES_PREFIX);
}
- };
-
- zoomImages = stressImagesDirectory.listFiles(filter);
-
- for (File f : zoomImages) {
- f.delete();
}
- } catch (SecurityException e) {
- Log.e(TAG, "Security manager access violation: " + e.toString());
- }
- }
-
- // Helper method for starting up the camera preview
- private void startCameraPreview(SurfaceHolder surfaceHolder) {
- try {
- mCamera.setErrorCallback(mCameraErrorCallback);
- mCamera.setPreviewDisplay(surfaceHolder);
- mCamera.startPreview();
- Thread.sleep(WAIT_GENERIC);
- } catch (IOException e) {
- Log.e(TAG, "Error setting preview display: " + e.toString());
- } catch (InterruptedException e) {
- Log.e(TAG, "Error waiting for preview to come up: " + e.toString());
- } catch (Exception e) {
- Log.e(TAG, "Error starting up camera preview: " + e.toString());
- }
- }
-
- // Helper method for taking a photo
- private void capturePhoto() {
- try {
- mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
- Thread.sleep(WAIT_GENERIC);
- mCamera.stopPreview();
- mCamera.release();
- } catch (InterruptedException e) {
- Log.e(TAG, "Error waiting for photo to be taken: " + e.toString());
+ mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
- Log.e(TAG, "Error capturing photo: " + e.toString());
+ Log.e(TAG, e.toString());
+ fail("Camera scene mode test Exception");
}
}
- // Test case for stressing the camera zoom in/out feature
+ /**
+ * Stress test iterating on the range of supported camera zoom levels
+ */
@LargeTest
public void testStressCameraZoom() throws Exception {
- SurfaceHolder mSurfaceHolder;
- mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
- mOutput.write("Total number of loops: " + NUMBER_OF_ZOOM_LOOPS + "\n");
-
try {
- Log.v(TAG, "Start preview");
- mOutput.write("No of loop: ");
-
- mCamera = Camera.open(CAMERA_ID);
- Camera.Parameters params = mCamera.getParameters();
- mCamera.release();
+ SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
+ Parameters params = mCameraTestHelper.getCameraParameters();
if (!params.isSmoothZoomSupported() && !params.isZoomSupported()) {
Log.v(TAG, "Device camera does not support zoom");
- fail("Camera zoom stress test failed");
+ fail("Camera zoom stress test failed due to unsupported feature");
} else {
Log.v(TAG, "Device camera does support zoom");
+ Log.v(TAG, "Start preview");
+ mOutput.write("Total number of loops: " + NUMBER_OF_ZOOM_LOOPS + "\n");
+ mOutput.write("No of loops: ");
int nextZoomLevel = 0;
@@ -274,12 +198,12 @@ public class CameraStressTest extends ActivityInstrumentationTestCase2<MediaFram
runOnLooper(new Runnable() {
@Override
public void run() {
- mCamera = Camera.open(CAMERA_ID);
+ mCameraTestHelper.setupCameraTest();
}
});
- startCameraPreview(mSurfaceHolder);
- params = mCamera.getParameters();
+ mCameraTestHelper.startCameraPreview(surfaceHolder);
+ params = mCameraTestHelper.mCamera.getParameters();
int currentZoomLevel = params.getZoom();
if (nextZoomLevel >= params.getMaxZoom()) {
@@ -288,16 +212,12 @@ public class CameraStressTest extends ActivityInstrumentationTestCase2<MediaFram
++nextZoomLevel;
if (params.isSmoothZoomSupported()) {
- mCamera.startSmoothZoom(nextZoomLevel);
+ mCameraTestHelper.mCamera.startSmoothZoom(nextZoomLevel);
} else {
params.setZoom(nextZoomLevel);
- mCamera.setParameters(params);
+ mCameraTestHelper.setParameters(params);
}
- Log.v(TAG, "Zooming from " + currentZoomLevel + " to " + nextZoomLevel);
-
- // sleep allows for zoom animation to finish
- Thread.sleep(WAIT_ZOOM_ANIMATION);
- capturePhoto();
+ mCameraTestHelper.capturePhoto();
if (i == 0) {
mOutput.write(Integer.toString(i));
@@ -306,57 +226,10 @@ public class CameraStressTest extends ActivityInstrumentationTestCase2<MediaFram
}
}
}
- cleanupStressTestImages();
+ mCameraTestHelper.cleanupTestImages();
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera zoom stress test Exception");
}
}
-
- // Test case for stressing the camera scene mode feature
- @LargeTest
- public void testStressCameraSceneModes() throws Exception {
- SurfaceHolder mSurfaceHolder;
- mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-
- try {
- mCamera = Camera.open(CAMERA_ID);
- Camera.Parameters params = mCamera.getParameters();
- mCamera.release();
- List<String> supportedSceneModes = params.getSupportedSceneModes();
- assertNotNull("No scene modes supported", supportedSceneModes);
-
- mOutput.write("Total number of loops: " +
- (NUMBER_OF_SCENE_MODE_LOOPS * supportedSceneModes.size()) + "\n");
- Log.v(TAG, "Start preview");
- mOutput.write("No of loop: ");
-
- for (int i = 0; i < supportedSceneModes.size(); i++) {
- for (int j = 0; j < NUMBER_OF_SCENE_MODE_LOOPS; j++) {
- runOnLooper(new Runnable() {
- @Override
- public void run() {
- mCamera = Camera.open(CAMERA_ID);
- }
- });
-
- startCameraPreview(mSurfaceHolder);
- Log.v(TAG, "Setting mode to " + supportedSceneModes.get(i));
- params.setSceneMode(supportedSceneModes.get(i));
- mCamera.setParameters(params);
- capturePhoto();
-
- if ((i == 0) && (j == 0)) {
- mOutput.write(Integer.toString(j + i * NUMBER_OF_SCENE_MODE_LOOPS));
- } else {
- mOutput.write(", " + (j + i * NUMBER_OF_SCENE_MODE_LOOPS));
- }
- }
- }
- cleanupStressTestImages();
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- fail("Camera scene mode test Exception");
- }
- }
}