diff options
Diffstat (limited to 'media/tests/MediaFrameworkTest/src')
5 files changed, 0 insertions, 468 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java index e9fbca7..62af3f3 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java @@ -48,7 +48,6 @@ public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner { addMediaRecorderStateUnitTests(suite); addMediaPlayerStateUnitTests(suite); addMediaScannerUnitTests(suite); - addCameraUnitTests(suite); return suite; } @@ -57,13 +56,6 @@ public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner { return MediaFrameworkUnitTestRunner.class.getClassLoader(); } - private void addCameraUnitTests(TestSuite suite) { - suite.addTestSuite(CameraUtilsDecoratorTest.class); - suite.addTestSuite(CameraUtilsRuntimeExceptionTest.class); - suite.addTestSuite(CameraUtilsUncheckedThrowTest.class); - suite.addTestSuite(CameraUtilsBinderDecoratorTest.class); - } - // Running all unit tests checking the state machine may be time-consuming. private void addMediaMetadataRetrieverStateUnitTests(TestSuite suite) { suite.addTestSuite(MediaMetadataRetrieverTest.class); diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsBinderDecoratorTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsBinderDecoratorTest.java deleted file mode 100644 index 7c48992..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsBinderDecoratorTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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.hardware.photography.CameraAccessException; -import android.hardware.photography.utils.CameraBinderDecorator; -import android.hardware.photography.utils.CameraRuntimeException; -import android.os.DeadObjectException; -import android.os.RemoteException; -import android.os.TransactionTooLargeException; -import android.test.suitebuilder.annotation.SmallTest; - -import static org.mockito.Mockito.*; -import static android.hardware.photography.utils.CameraBinderDecorator.*; -import static android.hardware.photography.CameraAccessException.*; - -import junit.framework.Assert; - -public class CameraUtilsBinderDecoratorTest extends junit.framework.TestCase { - - private interface ICameraBinderStereotype { - - double doNothing(); - - // int is a 'status_t' - int doSomethingPositive(); - - int doSomethingNoError(); - - int doSomethingPermissionDenied(); - - int doSomethingAlreadyExists(); - - int doSomethingBadValue(); - - int doSomethingDeadObject() throws CameraRuntimeException; - - int doSomethingBadPolicy() throws CameraRuntimeException; - - int doSomethingDeviceBusy() throws CameraRuntimeException; - - int doSomethingNoSuchDevice() throws CameraRuntimeException; - - int doSomethingUnknownErrorCode(); - - int doSomethingThrowDeadObjectException() throws RemoteException; - - int doSomethingThrowTransactionTooLargeException() throws RemoteException; - } - - private static final double SOME_ARBITRARY_DOUBLE = 1.0; - private static final int SOME_ARBITRARY_POSITIVE_INT = 5; - private static final int SOME_ARBITRARY_NEGATIVE_INT = -0xC0FFEE; - - @SmallTest - public void testStereotypes() { - - ICameraBinderStereotype mock = mock(ICameraBinderStereotype.class); - try { - when(mock.doNothing()).thenReturn(SOME_ARBITRARY_DOUBLE); - when(mock.doSomethingPositive()).thenReturn(SOME_ARBITRARY_POSITIVE_INT); - when(mock.doSomethingNoError()).thenReturn(NO_ERROR); - when(mock.doSomethingPermissionDenied()).thenReturn(PERMISSION_DENIED); - when(mock.doSomethingAlreadyExists()).thenReturn(ALREADY_EXISTS); - when(mock.doSomethingBadValue()).thenReturn(BAD_VALUE); - when(mock.doSomethingDeadObject()).thenReturn(DEAD_OBJECT); - when(mock.doSomethingBadPolicy()).thenReturn(EACCES); - when(mock.doSomethingDeviceBusy()).thenReturn(EBUSY); - when(mock.doSomethingNoSuchDevice()).thenReturn(ENODEV); - when(mock.doSomethingUnknownErrorCode()).thenReturn(SOME_ARBITRARY_NEGATIVE_INT); - when(mock.doSomethingThrowDeadObjectException()).thenThrow(new DeadObjectException()); - when(mock.doSomethingThrowTransactionTooLargeException()).thenThrow( - new TransactionTooLargeException()); - } catch (RemoteException e) { - Assert.fail("Unreachable"); - } - - ICameraBinderStereotype decoratedMock = CameraBinderDecorator.newInstance(mock); - - // ignored by decorator because return type is double, not int - assertEquals(SOME_ARBITRARY_DOUBLE, decoratedMock.doNothing()); - - // pass through for positive values - assertEquals(SOME_ARBITRARY_POSITIVE_INT, decoratedMock.doSomethingPositive()); - - // pass through NO_ERROR - assertEquals(NO_ERROR, decoratedMock.doSomethingNoError()); - - try { - decoratedMock.doSomethingPermissionDenied(); - Assert.fail("Should've thrown SecurityException"); - } catch (SecurityException e) { - } - - assertEquals(ALREADY_EXISTS, decoratedMock.doSomethingAlreadyExists()); - - try { - decoratedMock.doSomethingBadValue(); - Assert.fail("Should've thrown IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - - try { - decoratedMock.doSomethingDeadObject(); - Assert.fail("Should've thrown CameraRuntimeException"); - } catch (CameraRuntimeException e) { - assertEquals(CAMERA_DISCONNECTED, e.getReason()); - } - - try { - decoratedMock.doSomethingBadPolicy(); - Assert.fail("Should've thrown CameraRuntimeException"); - } catch (CameraRuntimeException e) { - assertEquals(CAMERA_DISABLED, e.getReason()); - } - - try { - decoratedMock.doSomethingDeviceBusy(); - Assert.fail("Should've thrown CameraRuntimeException"); - } catch (CameraRuntimeException e) { - assertEquals(CAMERA_IN_USE, e.getReason()); - } - - try { - decoratedMock.doSomethingNoSuchDevice(); - Assert.fail("Should've thrown CameraRuntimeException"); - } catch (CameraRuntimeException e) { - assertEquals(CAMERA_DISCONNECTED, e.getReason()); - } - - try { - decoratedMock.doSomethingUnknownErrorCode(); - Assert.fail("Should've thrown UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - assertEquals(String.format("Unknown error %d", - SOME_ARBITRARY_NEGATIVE_INT), e.getMessage()); - } - - try { - decoratedMock.doSomethingThrowDeadObjectException(); - Assert.fail("Should've thrown CameraRuntimeException"); - } catch (CameraRuntimeException e) { - assertEquals(CAMERA_DISCONNECTED, e.getReason()); - } catch (RemoteException e) { - Assert.fail("Should not throw a DeadObjectException directly, but rethrow"); - } - - try { - decoratedMock.doSomethingThrowTransactionTooLargeException(); - Assert.fail("Should've thrown UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - assertTrue(e.getCause() instanceof TransactionTooLargeException); - } catch (RemoteException e) { - Assert.fail("Should not throw a TransactionTooLargeException directly, but rethrow"); - } - } - -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsDecoratorTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsDecoratorTest.java deleted file mode 100644 index bae17fa..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsDecoratorTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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.test.suitebuilder.annotation.SmallTest; -import android.hardware.photography.utils.*; -import android.hardware.photography.utils.Decorator.DecoratorListener; - -import junit.framework.Assert; - -import java.lang.reflect.Method; - -/** - * adb shell am instrument -e class 'com.android.mediaframeworktest.unit.CameraUtilsDecoratorTest' \ - * -w com.android.mediaframeworktest/.MediaFrameworkUnitTestRunner - */ -public class CameraUtilsDecoratorTest extends junit.framework.TestCase { - private DummyListener mDummyListener; - private DummyInterface mIface; - - @Override - public void setUp() { - mDummyListener = new DummyListener(); - mIface = Decorator.newInstance(new DummyImpl(), mDummyListener); - } - - interface DummyInterface { - int addValues(int x, int y, int z); - - void raiseException() throws Exception; - - void raiseUnsupportedOperationException() throws UnsupportedOperationException; - } - - class DummyImpl implements DummyInterface { - @Override - public int addValues(int x, int y, int z) { - return x + y + z; - } - - @Override - public void raiseException() throws Exception { - throw new Exception("Test exception"); - } - - @Override - public void raiseUnsupportedOperationException() throws UnsupportedOperationException { - throw new UnsupportedOperationException("Test exception"); - } - } - - class DummyListener implements DecoratorListener { - - public boolean beforeCalled = false; - public boolean afterCalled = false; - public boolean catchCalled = false; - public boolean finallyCalled = false; - public Object resultValue = null; - - public boolean raiseException = false; - - @Override - public void onBeforeInvocation(Method m, Object[] args) { - beforeCalled = true; - } - - @Override - public void onAfterInvocation(Method m, Object[] args, Object result) { - afterCalled = true; - resultValue = result; - - if (raiseException) { - throw new UnsupportedOperationException("Test exception"); - } - } - - @Override - public boolean onCatchException(Method m, Object[] args, Throwable t) { - catchCalled = true; - return false; - } - - @Override - public void onFinally(Method m, Object[] args) { - finallyCalled = true; - } - - }; - - @SmallTest - public void testDecorator() { - - // TODO rewrite this using mocks - - assertTrue(mIface.addValues(1, 2, 3) == 6); - assertTrue(mDummyListener.beforeCalled); - assertTrue(mDummyListener.afterCalled); - - int resultValue = (Integer)mDummyListener.resultValue; - assertTrue(resultValue == 6); - assertTrue(mDummyListener.finallyCalled); - assertFalse(mDummyListener.catchCalled); - } - - @SmallTest - public void testDecoratorExceptions() { - - boolean gotExceptions = false; - try { - mIface.raiseException(); - } catch (Exception e) { - gotExceptions = true; - assertTrue(e.getMessage() == "Test exception"); - } - assertTrue(gotExceptions); - assertTrue(mDummyListener.beforeCalled); - assertFalse(mDummyListener.afterCalled); - assertTrue(mDummyListener.catchCalled); - assertTrue(mDummyListener.finallyCalled); - } - - @SmallTest - public void testDecoratorUnsupportedOperationException() { - - boolean gotExceptions = false; - try { - mIface.raiseUnsupportedOperationException(); - } catch (UnsupportedOperationException e) { - gotExceptions = true; - assertTrue(e.getMessage() == "Test exception"); - } - assertTrue(gotExceptions); - assertTrue(mDummyListener.beforeCalled); - assertFalse(mDummyListener.afterCalled); - assertTrue(mDummyListener.catchCalled); - assertTrue(mDummyListener.finallyCalled); - } - - @SmallTest - public void testDecoratorRaisesException() { - - boolean gotExceptions = false; - try { - mDummyListener.raiseException = true; - mIface.addValues(1, 2, 3); - Assert.fail("unreachable"); - } catch (UnsupportedOperationException e) { - gotExceptions = true; - assertTrue(e.getMessage() == "Test exception"); - } - assertTrue(gotExceptions); - assertTrue(mDummyListener.beforeCalled); - assertTrue(mDummyListener.afterCalled); - assertFalse(mDummyListener.catchCalled); - assertTrue(mDummyListener.finallyCalled); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsRuntimeExceptionTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsRuntimeExceptionTest.java deleted file mode 100644 index 8c2dd4d..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsRuntimeExceptionTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.hardware.photography.CameraAccessException; -import android.hardware.photography.utils.CameraRuntimeException; -import android.hardware.photography.utils.UncheckedThrow; -import android.test.suitebuilder.annotation.SmallTest; - -import junit.framework.Assert; - -public class CameraUtilsRuntimeExceptionTest extends junit.framework.TestCase { - - @SmallTest - public void testCameraRuntimeException1() { - try { - CameraRuntimeException runtimeExc = new CameraRuntimeException(12345); - throw runtimeExc.asChecked(); - } catch (CameraAccessException e) { - assertEquals(12345, e.getReason()); - assertNull(e.getMessage()); - assertNull(e.getCause()); - } - } - - @SmallTest - public void testCameraRuntimeException2() { - try { - CameraRuntimeException runtimeExc = new CameraRuntimeException(12345, "Hello"); - throw runtimeExc.asChecked(); - } catch (CameraAccessException e) { - assertEquals(12345, e.getReason()); - assertEquals("Hello", e.getMessage()); - assertNull(e.getCause()); - } - } - - @SmallTest - public void testCameraRuntimeException3() { - Throwable cause = new IllegalStateException("For great justice"); - try { - CameraRuntimeException runtimeExc = new CameraRuntimeException(12345, cause); - throw runtimeExc.asChecked(); - } catch (CameraAccessException e) { - assertEquals(12345, e.getReason()); - assertNull(e.getMessage()); - assertEquals(cause, e.getCause()); - } - } - - @SmallTest - public void testCameraRuntimeException4() { - Throwable cause = new IllegalStateException("For great justice"); - try { - CameraRuntimeException runtimeExc = new CameraRuntimeException(12345, "Hello", cause); - throw runtimeExc.asChecked(); - } catch (CameraAccessException e) { - assertEquals(12345, e.getReason()); - assertEquals("Hello", e.getMessage()); - assertEquals(cause, e.getCause()); - } - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsUncheckedThrowTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsUncheckedThrowTest.java deleted file mode 100644 index cbe123c..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/CameraUtilsUncheckedThrowTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.hardware.photography.CameraAccessException; -import android.hardware.photography.utils.UncheckedThrow; -import android.test.suitebuilder.annotation.SmallTest; - -import junit.framework.Assert; - -public class CameraUtilsUncheckedThrowTest extends junit.framework.TestCase { - - private void fakeNeverThrowsCameraAccess() throws CameraAccessException { - } - - @SmallTest - public void testUncheckedThrow() { - try { - UncheckedThrow.throwAnyException(new CameraAccessException( - CameraAccessException.CAMERA_DISCONNECTED)); - Assert.fail("unreachable"); - fakeNeverThrowsCameraAccess(); - } catch (CameraAccessException e) { - } - } -} |