diff options
author | Igor Murashkin <iam@google.com> | 2013-06-25 20:27:06 +0000 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2013-06-26 13:19:45 -0700 |
commit | 70725500dcf3b666b43d50563d64705aab58d2d3 (patch) | |
tree | ad2d6206c590e11c4b86e871c138f2aabd822956 /media/tests/MediaFrameworkTest/src | |
parent | e363fbb2647aeb5ef4c87160d84c6b9ae8d45598 (diff) | |
download | frameworks_base-70725500dcf3b666b43d50563d64705aab58d2d3.zip frameworks_base-70725500dcf3b666b43d50563d64705aab58d2d3.tar.gz frameworks_base-70725500dcf3b666b43d50563d64705aab58d2d3.tar.bz2 |
Initial camera device implementation
* Working streaming preview requests only
* Almost everything else returns empty objects that don't do anything
Bug: 9213377
Change-Id: Ie6f02a7c0952b0f5ebc41905425b15cae221f7d3
Diffstat (limited to 'media/tests/MediaFrameworkTest/src')
6 files changed, 606 insertions, 95 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkIntegrationTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkIntegrationTestRunner.java index 88c5b0c..7751fcc 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkIntegrationTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkIntegrationTestRunner.java @@ -19,8 +19,10 @@ package com.android.mediaframeworktest; import android.os.Bundle; import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestSuite; +import android.util.Log; import com.android.mediaframeworktest.integration.CameraBinderTest; +import com.android.mediaframeworktest.integration.CameraDeviceBinderTest; import junit.framework.TestSuite; @@ -34,11 +36,15 @@ import junit.framework.TestSuite; public class MediaFrameworkIntegrationTestRunner extends InstrumentationTestRunner { + private static final String TAG = "MediaFrameworkIntegrationTestRunner"; + + public static int mCameraId = 0; @Override public TestSuite getAllTests() { TestSuite suite = new InstrumentationTestSuite(this); suite.addTestSuite(CameraBinderTest.class); + suite.addTestSuite(CameraDeviceBinderTest.class); return suite; } @@ -50,5 +56,17 @@ public class MediaFrameworkIntegrationTestRunner extends InstrumentationTestRunn @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); + + String cameraId = (String) icicle.get("camera_id"); + if (cameraId != null) { + try { + Log.v(TAG, + String.format("Reading camera_id from icicle: '%s'", cameraId)); + mCameraId = Integer.parseInt(cameraId); + } + catch (NumberFormatException e) { + Log.e(TAG, String.format("Failed to convert camera_id to integer")); + } + } } } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java index e9fbca7..ecdc287 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java @@ -62,6 +62,7 @@ public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner { suite.addTestSuite(CameraUtilsRuntimeExceptionTest.class); suite.addTestSuite(CameraUtilsUncheckedThrowTest.class); suite.addTestSuite(CameraUtilsBinderDecoratorTest.class); + suite.addTestSuite(CameraMetadataTest.class); } // Running all unit tests checking the state machine may be time-consuming. diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java index ba2859b..bc3adc9 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java @@ -16,122 +16,72 @@ package com.android.mediaframeworktest.integration; -import android.content.Context; -import android.content.pm.FeatureInfo; -import android.content.pm.PackageManager; import android.hardware.CameraInfo; import android.hardware.ICamera; import android.hardware.ICameraClient; -import android.hardware.ICameraService; import android.hardware.ICameraServiceListener; import android.hardware.IProCameraCallbacks; import android.hardware.IProCameraUser; +import android.hardware.photography.CameraMetadata; +import android.hardware.photography.ICameraDeviceCallbacks; +import android.hardware.photography.ICameraDeviceUser; import android.os.Binder; import android.os.IBinder; import android.os.RemoteException; -import android.os.ServiceManager; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; /** + * <p> * Junit / Instrumentation test case for the camera2 api + * </p> + * <p> + * To run only tests in this class: + * </p> * - * To run only tests in - * this class: - * + * <pre> * adb shell am instrument \ - * -e class com.android.mediaframeworktest.integration.CameraBinderTest \ - * -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner + * -e class com.android.mediaframeworktest.integration.CameraBinderTest \ + * -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner + * </pre> */ public class CameraBinderTest extends AndroidTestCase { - private static String TAG = "CameraBinderTest"; - - private static final String CAMERA_SERVICE_BINDER_NAME = "media.camera"; - private static final int NO_ERROR = 0; - private static final int ALREADY_EXISTS = -17; - private static final int BAD_VALUE = -22; - - private static final int USE_CALLING_UID = -1; + static String TAG = "CameraBinderTest"; - private ICameraService mCameraService; - private int mGuessedNumCameras = 0; + protected CameraBinderTestUtils mUtils; public CameraBinderTest() { } - private final static boolean isFeatureAvailable(Context context, String feature) { - final PackageManager packageManager = context.getPackageManager(); - final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures(); - for (FeatureInfo f : featuresList) { - if (f.name != null && f.name.equals(feature)) { - return true; - } - } - - return false; - } - - // Guess the lower bound for how many cameras there are - private void guessNumCameras() { - - /** - * Why do we need this? This way we have no dependency on getNumCameras - * actually working. On most systems there are only 0, 1, or 2 cameras, - * and this covers that 'usual case'. On other systems there might be 3+ - * cameras, but this will at least check the first 2. - */ - mGuessedNumCameras = 0; - - // Front facing camera - if (isFeatureAvailable(getContext(), PackageManager.FEATURE_CAMERA_FRONT)) { - mGuessedNumCameras++; - } - - // Back facing camera - if (isFeatureAvailable(getContext(), PackageManager.FEATURE_CAMERA)) { - mGuessedNumCameras++; - } - - // Any facing camera - if (mGuessedNumCameras == 0 - && isFeatureAvailable(getContext(), PackageManager.FEATURE_CAMERA_ANY)) { - mGuessedNumCameras++; - } - - Log.v(TAG, "Guessing there are at least " + mGuessedNumCameras + " cameras"); - } - + @Override protected void setUp() throws Exception { super.setUp(); - guessNumCameras(); - - IBinder cameraServiceBinder = ServiceManager.getService(CAMERA_SERVICE_BINDER_NAME); - assertNotNull("Camera service IBinder should not be null", cameraServiceBinder); - - mCameraService = ICameraService.Stub.asInterface(cameraServiceBinder); - assertNotNull("Camera service should not be null", mCameraService); + mUtils = new CameraBinderTestUtils(getContext()); } @SmallTest public void testNumberOfCameras() throws Exception { - int numCameras = mCameraService.getNumberOfCameras(); - assertTrue("At least this many cameras: " + mGuessedNumCameras, - numCameras >= mGuessedNumCameras); + + int numCameras = mUtils.getCameraService().getNumberOfCameras(); + assertTrue("At least this many cameras: " + mUtils.getGuessedNumCameras(), + numCameras >= mUtils.getGuessedNumCameras()); Log.v(TAG, "Number of cameras " + numCameras); } @SmallTest public void testCameraInfo() throws Exception { - for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { CameraInfo info = new CameraInfo(); info.info.facing = -1; info.info.orientation = -1; - assertTrue("Camera service returned info for camera " + cameraId, - mCameraService.getCameraInfo(cameraId, info) == NO_ERROR); + assertTrue( + "Camera service returned info for camera " + cameraId, + mUtils.getCameraService().getCameraInfo(cameraId, info) == + CameraBinderTestUtils.NO_ERROR); assertTrue("Facing was not set for camera " + cameraId, info.info.facing != -1); assertTrue("Orientation was not set for camera " + cameraId, info.info.orientation != -1); @@ -153,14 +103,15 @@ public class CameraBinderTest extends AndroidTestCase { @SmallTest public void testConnect() throws Exception { - for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { ICameraClient dummyCallbacks = new DummyCameraClient(); String clientPackageName = getContext().getPackageName(); - ICamera cameraUser = mCameraService.connect(dummyCallbacks, cameraId, clientPackageName, - USE_CALLING_UID); + ICamera cameraUser = mUtils.getCameraService().connect(dummyCallbacks, cameraId, + clientPackageName, + CameraBinderTestUtils.USE_CALLING_UID); assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); Log.v(TAG, String.format("Camera %s connected", cameraId)); @@ -174,14 +125,45 @@ public class CameraBinderTest extends AndroidTestCase { @SmallTest public void testConnectPro() throws Exception { - for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { IProCameraCallbacks dummyCallbacks = new DummyProCameraCallbacks(); String clientPackageName = getContext().getPackageName(); - IProCameraUser cameraUser = mCameraService.connectPro(dummyCallbacks, cameraId, - clientPackageName, USE_CALLING_UID); + IProCameraUser cameraUser = mUtils.getCameraService().connectPro(dummyCallbacks, + cameraId, + clientPackageName, CameraBinderTestUtils.USE_CALLING_UID); + assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); + + Log.v(TAG, String.format("Camera %s connected", cameraId)); + + cameraUser.disconnect(); + } + } + + static class DummyCameraDeviceCallbacks extends DummyBase implements ICameraDeviceCallbacks { + + @Override + public void notifyCallback(int msgType, int ext1, int ext2) throws RemoteException { + } + + @Override + public void onResultReceived(int frameId, CameraMetadata result) throws RemoteException { + } + } + + @SmallTest + public void testConnectDevice() throws Exception { + for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { + + ICameraDeviceCallbacks dummyCallbacks = new DummyCameraDeviceCallbacks(); + + String clientPackageName = getContext().getPackageName(); + + ICameraDeviceUser cameraUser = mUtils.getCameraService().connectDevice(dummyCallbacks, + cameraId, + clientPackageName, CameraBinderTestUtils.USE_CALLING_UID); assertNotNull(String.format("Camera %s was null", cameraId), cameraUser); Log.v(TAG, String.format("Camera %s connected", cameraId)); @@ -199,27 +181,39 @@ public class CameraBinderTest extends AndroidTestCase { } /** + * <pre> * adb shell am instrument \ - * -e class 'com.android.mediaframeworktest.integration.CameraBinderTest#testAddRemoveListeners' \ - * -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner + * -e class 'com.android.mediaframeworktest.integration.CameraBinderTest#testAddRemoveListeners' \ + * -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner + * </pre> */ @SmallTest public void testAddRemoveListeners() throws Exception { - for (int cameraId = 0; cameraId < mGuessedNumCameras; ++cameraId) { + for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) { ICameraServiceListener listener = new DummyCameraServiceListener(); - assertTrue("Listener was removed before added", - mCameraService.removeListener(listener) == BAD_VALUE); - - assertTrue("Listener was not added", mCameraService.addListener(listener) == NO_ERROR); - assertTrue("Listener was wrongly added again", - mCameraService.addListener(listener) == ALREADY_EXISTS); - - assertTrue("Listener was not removed", - mCameraService.removeListener(listener) == NO_ERROR); - assertTrue("Listener was wrongly removed again", - mCameraService.removeListener(listener) == BAD_VALUE); + assertTrue( + "Listener was removed before added", + mUtils.getCameraService().removeListener(listener) == + CameraBinderTestUtils.BAD_VALUE); + + assertTrue("Listener was not added", + mUtils.getCameraService().addListener(listener) == + CameraBinderTestUtils.NO_ERROR); + assertTrue( + "Listener was wrongly added again", + mUtils.getCameraService().addListener(listener) == + CameraBinderTestUtils.ALREADY_EXISTS); + + assertTrue( + "Listener was not removed", + mUtils.getCameraService().removeListener(listener) == + CameraBinderTestUtils.NO_ERROR); + assertTrue( + "Listener was wrongly removed again", + mUtils.getCameraService().removeListener(listener) == + CameraBinderTestUtils.BAD_VALUE); } } } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTestUtils.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTestUtils.java new file mode 100644 index 0000000..f0fc817 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTestUtils.java @@ -0,0 +1,92 @@ + +package com.android.mediaframeworktest.integration; + +import static org.junit.Assert.assertNotNull; + +import android.content.Context; +import android.content.pm.FeatureInfo; +import android.content.pm.PackageManager; +import android.hardware.ICameraService; +import android.os.IBinder; +import android.os.ServiceManager; +import android.util.Log; + +public class CameraBinderTestUtils { + private final ICameraService mCameraService; + private int mGuessedNumCameras; + + static final String CAMERA_SERVICE_BINDER_NAME = "media.camera"; + + protected static final int USE_CALLING_UID = -1; + protected static final int BAD_VALUE = -22; + protected static final int ALREADY_EXISTS = -17; + protected static final int NO_ERROR = 0; + private final Context mContext; + + public CameraBinderTestUtils(Context context) { + + mContext = context; + + guessNumCameras(); + + IBinder cameraServiceBinder = ServiceManager + .getService(CameraBinderTestUtils.CAMERA_SERVICE_BINDER_NAME); + assertNotNull("Camera service IBinder should not be null", cameraServiceBinder); + + this.mCameraService = ICameraService.Stub.asInterface(cameraServiceBinder); + assertNotNull("Camera service should not be null", getCameraService()); + } + + private void guessNumCameras() { + + /** + * Why do we need this? This way we have no dependency on getNumCameras + * actually working. On most systems there are only 0, 1, or 2 cameras, + * and this covers that 'usual case'. On other systems there might be 3+ + * cameras, but this will at least check the first 2. + */ + this.mGuessedNumCameras = 0; + + // Front facing camera + if (CameraBinderTestUtils.isFeatureAvailable(mContext, + PackageManager.FEATURE_CAMERA_FRONT)) { + this.mGuessedNumCameras = getGuessedNumCameras() + 1; + } + + // Back facing camera + if (CameraBinderTestUtils.isFeatureAvailable(mContext, + PackageManager.FEATURE_CAMERA)) { + this.mGuessedNumCameras = getGuessedNumCameras() + 1; + } + + // Any facing camera + if (getGuessedNumCameras() == 0 + && CameraBinderTestUtils.isFeatureAvailable(mContext, + PackageManager.FEATURE_CAMERA_ANY)) { + this.mGuessedNumCameras = getGuessedNumCameras() + 1; + } + + Log.v(CameraBinderTest.TAG, "Guessing there are at least " + getGuessedNumCameras() + + " cameras"); + } + + final static public boolean isFeatureAvailable(Context context, String feature) { + final PackageManager packageManager = context.getPackageManager(); + final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures(); + for (FeatureInfo f : featuresList) { + if (f.name != null && f.name.equals(feature)) { + return true; + } + } + + return false; + } + + ICameraService getCameraService() { + return mCameraService; + } + + int getGuessedNumCameras() { + return mGuessedNumCameras; + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java new file mode 100644 index 0000000..0cbb989 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java @@ -0,0 +1,297 @@ +/* + * 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.integration; + +import android.graphics.SurfaceTexture; +import android.hardware.photography.CameraMetadata; +import android.hardware.photography.CaptureRequest; +import android.hardware.photography.ICameraDeviceCallbacks; +import android.hardware.photography.ICameraDeviceUser; +import android.os.RemoteException; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.util.Log; +import android.view.Surface; + +import static android.hardware.photography.CameraDevice.TEMPLATE_PREVIEW; + +import com.android.mediaframeworktest.MediaFrameworkIntegrationTestRunner; +import com.android.mediaframeworktest.integration.CameraBinderTest.DummyBase; + +public class CameraDeviceBinderTest extends AndroidTestCase { + private static String TAG = "CameraDeviceBinderTest"; + + private int mCameraId; + private ICameraDeviceUser mCameraUser; + private CameraBinderTestUtils mUtils; + + public CameraDeviceBinderTest() { + } + + static class DummyCameraDeviceCallbacks extends DummyBase implements ICameraDeviceCallbacks { + + @Override + public void notifyCallback(int msgType, int ext1, int ext2) throws RemoteException { + } + + @Override + public void onResultReceived(int frameId, CameraMetadata result) throws RemoteException { + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mUtils = new CameraBinderTestUtils(getContext()); + + // This cannot be set in the constructor, since the onCreate isn't + // called yet + mCameraId = MediaFrameworkIntegrationTestRunner.mCameraId; + + ICameraDeviceCallbacks dummyCallbacks = new DummyCameraDeviceCallbacks(); + + String clientPackageName = getContext().getPackageName(); + + mCameraUser = mUtils.getCameraService().connectDevice(dummyCallbacks, mCameraId, + clientPackageName, CameraBinderTestUtils.USE_CALLING_UID); + assertNotNull(String.format("Camera %s was null", mCameraId), mCameraUser); + + Log.v(TAG, String.format("Camera %s connected", mCameraId)); + } + + @Override + protected void tearDown() throws Exception { + mCameraUser.disconnect(); + mCameraUser = null; + } + + @SmallTest + public void testCreateDefaultRequest() throws Exception { + CameraMetadata metadata = new CameraMetadata(); + assertTrue(metadata.isEmpty()); + + int status = mCameraUser.createDefaultRequest(TEMPLATE_PREVIEW, /* out */metadata); + assertEquals(CameraBinderTestUtils.NO_ERROR, status); + assertFalse(metadata.isEmpty()); + + metadata.close(); + } + + @SmallTest + public void testCreateStream() throws Exception { + SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */0); + surfaceTexture.setDefaultBufferSize(640, 480); + Surface surface = new Surface(surfaceTexture); + + int streamId = mCameraUser.createStream(/* ignored */10, /* ignored */20, /* ignored */30, + surface); + + assertEquals(0, streamId); + + assertEquals(CameraBinderTestUtils.ALREADY_EXISTS, + mCameraUser.createStream(/* ignored */0, /* ignored */0, /* ignored */0, surface)); + + assertEquals(CameraBinderTestUtils.NO_ERROR, mCameraUser.deleteStream(streamId)); + } + + @SmallTest + public void testDeleteInvalidStream() throws Exception { + assertEquals(CameraBinderTestUtils.BAD_VALUE, mCameraUser.deleteStream(-1)); + assertEquals(CameraBinderTestUtils.BAD_VALUE, mCameraUser.deleteStream(0)); + assertEquals(CameraBinderTestUtils.BAD_VALUE, mCameraUser.deleteStream(1)); + assertEquals(CameraBinderTestUtils.BAD_VALUE, mCameraUser.deleteStream(0xC0FFEE)); + } + + @SmallTest + public void testCreateStreamTwo() throws Exception { + + // Create first stream + + SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */0); + surfaceTexture.setDefaultBufferSize(640, 480); + Surface surface = new Surface(surfaceTexture); + + int streamId = mCameraUser.createStream(/* ignored */0, /* ignored */0, /* ignored */0, + surface); + + assertEquals(0, streamId); + + assertEquals(CameraBinderTestUtils.ALREADY_EXISTS, + mCameraUser.createStream(/* ignored */0, /* ignored */0, /* ignored */0, surface)); + + // Create second stream. + + SurfaceTexture surfaceTexture2 = new SurfaceTexture(/* ignored */0); + surfaceTexture2.setDefaultBufferSize(640, 480); + Surface surface2 = new Surface(surfaceTexture2); + + int streamId2 = mCameraUser.createStream(/* ignored */0, /* ignored */0, /* ignored */0, + surface2); + + assertEquals(1, streamId2); + + // Clean up streams + + assertEquals(CameraBinderTestUtils.NO_ERROR, mCameraUser.deleteStream(streamId)); + assertEquals(CameraBinderTestUtils.NO_ERROR, mCameraUser.deleteStream(streamId2)); + } + + @SmallTest + public void testSubmitBadRequest() throws Exception { + + CameraMetadata metadata = new CameraMetadata(); + assertTrue(metadata.isEmpty()); + + CaptureRequest request = new CaptureRequest(); + assertTrue(request.isEmpty()); + + int status = mCameraUser.createDefaultRequest(TEMPLATE_PREVIEW, /* out */metadata); + assertEquals(CameraBinderTestUtils.NO_ERROR, status); + assertFalse(metadata.isEmpty()); + + request.swap(metadata); + assertFalse(request.isEmpty()); + assertTrue(metadata.isEmpty()); + + status = mCameraUser.submitRequest(request, /* streaming */false); + assertEquals("Expected submitRequest to return BAD_VALUE " + + "since we had 0 surface targets set.", CameraBinderTestUtils.BAD_VALUE, status); + + SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */0); + surfaceTexture.setDefaultBufferSize(640, 480); + Surface surface = new Surface(surfaceTexture); + request.addTarget(surface); + + status = mCameraUser.submitRequest(request, /* streaming */false); + assertEquals("Expected submitRequest to return BAD_VALUE since " + + "the target surface wasn't registered with createStream.", + CameraBinderTestUtils.BAD_VALUE, status); + + request.close(); + metadata.close(); + surface.release(); + } + + @SmallTest + public void testSubmitGoodRequest() throws Exception { + + CameraMetadata metadata = new CameraMetadata(); + assertTrue(metadata.isEmpty()); + + CaptureRequest request = new CaptureRequest(); + assertTrue(request.isEmpty()); + + // Create default request from template. + + int status = mCameraUser.createDefaultRequest(TEMPLATE_PREVIEW, /* out */metadata); + assertEquals(CameraBinderTestUtils.NO_ERROR, status); + assertFalse(metadata.isEmpty()); + + request.swap(metadata); + assertFalse(request.isEmpty()); + assertTrue(metadata.isEmpty()); + + SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */0); + surfaceTexture.setDefaultBufferSize(640, 480); + Surface surface = new Surface(surfaceTexture); + + // Create stream first. Pre-requisite to submitting a request using that + // stream. + + int streamId = mCameraUser.createStream(/* ignored */10, /* ignored */20, /* ignored */30, + surface); + assertEquals(0, streamId); + + request.addTarget(surface); + + // Submit valid request twice. + + int requestId1; + requestId1 = mCameraUser.submitRequest(request, /* streaming */false); + assertTrue("Request IDs should be non-negative", requestId1 >= 0); + + int requestId2 = mCameraUser.submitRequest(request, /* streaming */false); + assertTrue("Request IDs should be non-negative", requestId2 >= 0); + assertNotSame("Request IDs should be unique for multiple requests", requestId1, requestId2); + + surface.release(); + request.close(); + metadata.close(); + } + + @SmallTest + public void testSubmitStreamingRequest() throws Exception { + + CameraMetadata metadata = new CameraMetadata(); + assertTrue(metadata.isEmpty()); + + CaptureRequest request = new CaptureRequest(); + assertTrue(request.isEmpty()); + + // Create default request from template. + + int status = mCameraUser.createDefaultRequest(TEMPLATE_PREVIEW, /* out */metadata); + assertEquals(CameraBinderTestUtils.NO_ERROR, status); + assertFalse(metadata.isEmpty()); + + request.swap(metadata); + assertFalse(request.isEmpty()); + assertTrue(metadata.isEmpty()); + + SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */0); + surfaceTexture.setDefaultBufferSize(640, 480); + Surface surface = new Surface(surfaceTexture); + + // Create stream first. Pre-requisite to submitting a request using that + // stream. + + int streamId = mCameraUser.createStream(/* ignored */10, /* ignored */20, /* ignored */30, + surface); + assertEquals(0, streamId); + + request.addTarget(surface); + + // Submit valid request once (non-streaming), and another time + // (streaming) + + int requestId1; + requestId1 = mCameraUser.submitRequest(request, /* streaming */true); + assertTrue("Request IDs should be non-negative", requestId1 >= 0); + + int requestIdStreaming = mCameraUser.submitRequest(request, /* streaming */false); + assertTrue("Request IDs should be non-negative", requestIdStreaming >= 0); + assertNotSame("Request IDs should be unique for multiple requests", requestId1, + requestIdStreaming); + + status = mCameraUser.cancelRequest(-1); + assertEquals("Invalid request IDs should not be cancellable", + CameraBinderTestUtils.BAD_VALUE, status); + + status = mCameraUser.cancelRequest(requestId1); + assertEquals("Non-streaming request IDs should not be cancellable", + CameraBinderTestUtils.BAD_VALUE, status); + + status = mCameraUser.cancelRequest(requestIdStreaming); + assertEquals("Streaming request IDs should be cancellable", CameraBinderTestUtils.NO_ERROR, + status); + + surface.release(); + request.close(); + metadata.close(); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraMetadataTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraMetadataTest.java new file mode 100644 index 0000000..3400434 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraMetadataTest.java @@ -0,0 +1,109 @@ +/* + * 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.unit; + +import android.os.Parcel; +import android.test.suitebuilder.annotation.SmallTest; +import android.hardware.photography.CameraMetadata; + +/** + * <pre> + * adb shell am instrument \ + * -e class 'com.android.mediaframeworktest.unit.CameraMetadataTest' \ + * -w com.android.mediaframeworktest/.MediaFrameworkUnitTestRunner + * </pre> + */ +public class CameraMetadataTest extends junit.framework.TestCase { + + CameraMetadata mMetadata; + Parcel mParcel; + + @Override + public void setUp() { + mMetadata = new CameraMetadata(); + mParcel = Parcel.obtain(); + } + + @Override + public void tearDown() throws Exception { + mMetadata.close(); + mMetadata = null; + + mParcel.recycle(); + mParcel = null; + } + + @SmallTest + public void testNew() { + assertEquals(0, mMetadata.getEntryCount()); + assertTrue(mMetadata.isEmpty()); + } + + @SmallTest + public void testClose() throws Exception { + mMetadata.isEmpty(); // no throw + + assertFalse(mMetadata.isClosed()); + + mMetadata.close(); + + assertTrue(mMetadata.isClosed()); + + // OK: second close should not throw + mMetadata.close(); + + assertTrue(mMetadata.isClosed()); + + // All other calls after close should throw IllegalStateException + + try { + mMetadata.isEmpty(); + fail("Unreachable -- isEmpty after close should throw IllegalStateException"); + } catch (IllegalStateException e) { + // good: we expect calling this method after close to fail + } + + try { + mMetadata.getEntryCount(); + fail("Unreachable -- getEntryCount after close should throw IllegalStateException"); + } catch (IllegalStateException e) { + // good: we expect calling this method after close to fail + } + + + try { + mMetadata.swap(mMetadata); + fail("Unreachable -- swap after close should throw IllegalStateException"); + } catch (IllegalStateException e) { + // good: we expect calling this method after close to fail + } + + try { + mMetadata.readFromParcel(mParcel); + fail("Unreachable -- readFromParcel after close should throw IllegalStateException"); + } catch (IllegalStateException e) { + // good: we expect calling this method after close to fail + } + + try { + mMetadata.writeToParcel(mParcel, /*flags*/0); + fail("Unreachable -- writeToParcel after close should throw IllegalStateException"); + } catch (IllegalStateException e) { + // good: we expect calling this method after close to fail + } + } +} |