diff options
Diffstat (limited to 'media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit')
28 files changed, 0 insertions, 2637 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java deleted file mode 100644 index 61a8a29..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (C) 2008 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.util.Log; -import android.media.MediaMetadataRetriever; -import android.graphics.Bitmap; -import java.io.FileOutputStream; -import android.test.AndroidTestCase; -import com.android.mediaframeworktest.MediaNames; -import android.test.suitebuilder.annotation.*; - -/** - * WARNING: - * Currently, captureFrame() does not work, due to hardware access permission problem. - * We are currently only testing the metadata/album art retrieval features. - */ -public class MediaMetadataRetrieverTest extends AndroidTestCase { - - private static final String TAG = "MediaMetadataRetrieverTest"; - - // Test album art extraction. - @MediumTest - public static void testAlbumArt() throws Exception { - Log.v(TAG, "testAlbumArt starts."); - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - for (int i = 0, n = MediaNames.ALBUMART_TEST_FILES.length; i < n; ++i) { - try { - Log.v(TAG, "File " + i + ": " + MediaNames.ALBUMART_TEST_FILES[i]); - retriever.setDataSource(MediaNames.ALBUMART_TEST_FILES[i]); - byte[] albumArt = retriever.extractAlbumArt(); - - // TODO: - // A better test would be to compare the retrieved album art with the - // known result. - if (albumArt == null) { // Do we have expect in JUnit? - fail("Fails to extract album art for " + MediaNames.ALBUMART_TEST_FILES[i]); - } - } catch(Exception e) { - throw new Exception("Fails to setDataSource for " + MediaNames.ALBUMART_TEST_FILES[i], e); - } - Thread.yield(); // Don't be evil - } - retriever.release(); - Log.v(TAG, "testAlbumArt completes."); - } - - // Test frame capture - // Suppressing until 1259652 is fixed. - @Suppress - public static void disableTestThumbnailCapture() throws Exception { - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - Log.v(TAG, "Thumbnail processing starts"); - long startedAt = System.currentTimeMillis(); - for(int i = 0, n = MediaNames.THUMBNAIL_CAPTURE_TEST_FILES.length; i < n; ++i) { - try { - Log.v(TAG, "File " + i + ": " + MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i]); - retriever.setDataSource(MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i]); - Bitmap bitmap = retriever.captureFrame(); - assertTrue(bitmap != null); - try { - java.io.OutputStream stream = new FileOutputStream(MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i] + ".jpg"); - bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream); - stream.close(); - } catch (Exception e) { - throw new Exception("Fails to convert the bitmap to a JPEG file for " + MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i], e); - } - } catch(Exception e) { - throw new Exception("Fails to setDataSource for file " + MediaNames.THUMBNAIL_CAPTURE_TEST_FILES[i], e); - } - Thread.yield(); // Don't be evil - } - long endedAt = System.currentTimeMillis(); - Log.v(TAG, "Average processing time per thumbnail: " + (endedAt - startedAt)/MediaNames.THUMBNAIL_CAPTURE_TEST_FILES.length + " ms"); - retriever.release(); - } - - @LargeTest - public static void testMetadataRetrieval() throws Exception { - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - for(int i = 0, n = MediaNames.METADATA_RETRIEVAL_TEST_FILES.length; i < n; ++i) { - try { - retriever.setDataSource(MediaNames.METADATA_RETRIEVAL_TEST_FILES[i]); - extractAllSupportedMetadataValues(retriever); - } catch(Exception e) { - throw new Exception("Fails to setDataSource for file " + MediaNames.METADATA_RETRIEVAL_TEST_FILES[i], e); - } - Thread.yield(); // Don't be evil - } - retriever.release(); - } - - // If the specified call order and valid media file is used, no exception - // should be thrown. - @MediumTest - public static void testBasicNormalMethodCallSequence() throws Exception { - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - try { - retriever.setDataSource(MediaNames.TEST_PATH_1); - /* - * captureFrame() fails due to lack of permission to access hardware decoder devices - Bitmap bitmap = retriever.captureFrame(); - assertTrue(bitmap != null); - try { - java.io.OutputStream stream = new FileOutputStream("/sdcard/thumbnailout.jpg"); - bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream); - stream.close(); - } catch (Exception e) { - throw new Exception("Fails to convert the bitmap to a JPEG file for " + MediaNames.TEST_PATH_1, e); - } - */ - extractAllSupportedMetadataValues(retriever); - } catch(Exception e) { - throw new Exception("Fails to setDataSource for " + MediaNames.TEST_PATH_1, e); - } - retriever.release(); - } - - // If setDataSource() has not been called, both captureFrame() and extractMetadata() must - // return null. - @MediumTest - public static void testBasicAbnormalMethodCallSequence() { - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM) == null); - assertTrue(retriever.captureFrame() == null); - } - - // Test setDataSource() - @MediumTest - public static void testSetDataSource() { - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - - // Null pointer argument - try { - String path = null; - retriever.setDataSource(path); - fail("IllegalArgumentException must be thrown."); - } catch(Exception e) { - assertTrue(e instanceof IllegalArgumentException); - } - - // Use mem:// path - try { - retriever.setDataSource(MediaNames.TEST_PATH_5); - fail("IllegalArgumentException must be thrown."); - } catch(Exception e) { - assertTrue(e instanceof IllegalArgumentException); - } - - // The pathname does not correspond to any existing file - try { - retriever.setDataSource(MediaNames.TEST_PATH_4); - fail("Runtime exception must be thrown."); - } catch(Exception e) { - assertTrue(e instanceof RuntimeException); - } - - // The pathname does correspond to a file, but this file - // is not a valid media file - try { - retriever.setDataSource(MediaNames.TEST_PATH_3); - fail("Runtime exception must be thrown."); - } catch(Exception e) { - assertTrue(e instanceof RuntimeException); - } - - retriever.release(); - } - - // Due to the lack of permission to access hardware decoder, any calls - // attempting to capture a frame will fail. These are commented out for now - // until we find a solution to this access permission problem. - @MediumTest - public static void testIntendedUsage() { - // By default, capture frame and retrieve metadata - MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - // retriever.setDataSource(MediaNames.TEST_PATH_1); - // assertTrue(retriever.captureFrame() != null); - // assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) != null); - - // Do not capture frame or retrieve metadata - retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY & MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - retriever.setDataSource(MediaNames.TEST_PATH_1); - assertTrue(retriever.captureFrame() == null); - assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) == null); - - // Capture frame only - // retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY); - // retriever.setDataSource(MediaNames.TEST_PATH_1); - // assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) == null); - - // Retriever metadata only - retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - retriever.setDataSource(MediaNames.TEST_PATH_1); - assertTrue(retriever.captureFrame() == null); - - // Capture frame and retrieve metadata - // retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY | MediaMetadataRetriever.MODE_GET_METADATA_ONLY); - // retriever.setDataSource(MediaNames.TEST_PATH_1); - // assertTrue(retriever.captureFrame() != null); - // assertTrue(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS) != null); - retriever.release(); - } - - // TODO: - // Encode and test for the correct mix of metadata elements on a per-file basis? - // We should be able to compare the actual returned metadata with the expected metadata - // with each given sample test file. - private static void extractAllSupportedMetadataValues(MediaMetadataRetriever retriever) { - String value = null; - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)) == null? "not found": value); - Log.v(TAG, (value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR)) == null? "not found": value); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java deleted file mode 100644 index 032b469..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest;; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.getCurrentPosition() method can be called. - */ -public class MediaPlayerGetCurrentPositionStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call getCurrentPosition() in the following states: - * {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}. - * 2. It is invalid to call getCurrentPosition() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInStoppedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.getCurrentPosition(); - } - - @LargeTest - public void testGetCurrentPosition() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "getCurrentPosition()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java deleted file mode 100644 index 5f7abe5..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.getDuration() method can be called. - */ -public class MediaPlayerGetDurationStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call getDuration() in the following states: - * {Prepared, Started, Paused, Stopped, PlaybackCompleted}. - * 2. It is invalid to call getDuration() in the following states: - * {Idle, Initialized, Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInStoppedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - - // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInErrorState); - assertTrue(stateErrors.errorInIdleStateAfterReset); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.getDuration(); - } - - @LargeTest - public void testGetDuration() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "getDuration()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoHeightStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoHeightStateUnitTest.java deleted file mode 100644 index 6d3c083..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoHeightStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.getVideoHeight() method can be called. - */ -public class MediaPlayerGetVideoHeightStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call getVideoHeight() in the following states: - * {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}. - * 2. It is invalid to call getVideoHeight() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInStoppedState); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.getVideoHeight(); - } - - @LargeTest - public void testGetVideoHeight() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "getVideoHeight()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoWidthStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoWidthStateUnitTest.java deleted file mode 100644 index 198439c..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoWidthStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.getVideoWidth() method can be called. - */ -public class MediaPlayerGetVideoWidthStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call getVideoWidth() in the following states: - * {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}. - * 2. It is invalid to call getVideoWidth() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInStoppedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.getVideoWidth(); - } - - @LargeTest - public void testGetVideoWidth() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "getVideoWidth()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerIsPlayingStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerIsPlayingStateUnitTest.java deleted file mode 100644 index b9c63fd..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerIsPlayingStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.isPlaying() method can be called. - */ -public class MediaPlayerIsPlayingStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call isPlaying() in the following states: - * {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}. - * 2. It is invalid to call isPlaying() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInStoppedState); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.isPlaying(); - } - - @LargeTest - public void testIsPlaying() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "isPlaying()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerMethodUnderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerMethodUnderTest.java deleted file mode 100644 index 91ed694..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerMethodUnderTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; - -/** - * All MediaPlayer method unit test subclass must implement this interface. - */ -interface MediaPlayerMethodUnderTest { - public void checkStateErrors(MediaPlayerStateErrors stateErrors); - public void invokeMethodUnderTest(MediaPlayer player); -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java deleted file mode 100644 index 0a18a39..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.pause() method can be called. - */ -public class MediaPlayerPauseStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call pause() in the following states: - * {Started, Paused}. - * 2. It is invalid to call pause() in the following states: - * {Idle, Initialized, Prepared, Stopped, PlaybackCompleted, Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - - // Invalid states. - assertTrue(stateErrors.errorInPreparedState); - assertTrue(stateErrors.errorInPreparedStateAfterStop); - assertTrue(stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleState); // noError() won't be called - assertTrue(stateErrors.errorInIdleStateAfterReset); - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInStoppedState); - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.pause(); - } - - @LargeTest - public void testPause() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "pause()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerResetStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerResetStateUnitTest.java deleted file mode 100644 index 2497cd7..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerResetStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.reset() method can be called. - */ -public class MediaPlayerResetStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call reset() in the following states: - * {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted}. - * 2. It is invalid to call reset() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInStoppedState); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.reset(); - } - - @LargeTest - public void testReset() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "reset()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java deleted file mode 100644 index 46bba9b..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.seekTo() method can be called. - */ -public class MediaPlayerSeekToStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call seekTo() in the following states: - * {Prepared, Started, Paused, PlaybackComplted}. - * 2. It is invalid to call seekTo() in the following states: - * {Idle, Initialized, Stopped, Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - - // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called - assertTrue(stateErrors.errorInIdleStateAfterReset); - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInStoppedState); - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.seekTo(0); - } - - @LargeTest - public void testSeekTo() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "seekTo()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java deleted file mode 100644 index 3153792..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.media.AudioManager; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.setAudioStreamType() method can be called. - */ -public class MediaPlayerSetAudioStreamTypeStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call setAudioStreamType() in the following states: - * {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackComplted}. - * 2. It is invalid to call setAudioStreamType() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInIdleState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInStoppedState); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.setAudioStreamType(AudioManager.STREAM_MUSIC); - } - - @LargeTest - public void testSetAudioSystemType() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "setAudioStreamType()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetLoopingStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetLoopingStateUnitTest.java deleted file mode 100644 index 17c9d8c..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetLoopingStateUnitTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.setLooping() method can be called. - */ -public class MediaPlayerSetLoopingStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - private boolean looping = false; - - /** - * 1. It is valid to call setLooping() in the following states: - * {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackComplted}. - * 2. It is invalid to call setLooping() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInStoppedState); - assertTrue(!stateErrors.errorInIdleState); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - looping = !looping; // Flip the looping mode. - player.setLooping(looping); - } - - @LargeTest - public void testSetLooping() { - mTestTemplate.runTestOnMethod(this); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetVolumeStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetVolumeStateUnitTest.java deleted file mode 100644 index a149565..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetVolumeStateUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.setVolume() method can be called. - */ -public class MediaPlayerSetVolumeStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call setVolume() in the following states: - * {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackComplted}. - * 2. It is invalid to call setVolume() in the following states: - * {Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInIdleStateAfterReset); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInStoppedState); - assertTrue(!stateErrors.errorInIdleState); - - // Invalid states. - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.setVolume(0.5f, 0.5f); - } - - @LargeTest - public void testSetVolume() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "setVolume()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java deleted file mode 100644 index 6debbb4..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.start() method can be called. - */ -public class MediaPlayerStartStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call start() in the following states: - * {Prepared, Started, Paused, PlaybackComplted}. - * 2. It is invalid to call start() in the following states: - * {Idle, Initialized, Stopped, Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInPausedState); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - - // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // onError() won't be called - assertTrue(stateErrors.errorInErrorState); - assertTrue(stateErrors.errorInIdleStateAfterReset); - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInStoppedState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.start(); - } - - @LargeTest - public void testStart() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "start()"; - } - -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateErrors.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateErrors.java deleted file mode 100644 index 5be6fe3..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateErrors.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2008 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; - -class MediaPlayerStateErrors { - public static final int MEDIA_PLAYER_ERROR = 100; - public static enum MediaPlayerState { - IDLE, - IDLE_AFTER_RESET, - INITIALIZED, - PREPARED, - PREPARED_AFTER_STOP, - STARTED, - STARTED_AFTER_PAUSE, - PAUSED, - STOPPED, - PLAYBACK_COMPLETED, - ERROR, - } - - // Error occurs in the states below? - public boolean errorInIdleState = false; - public boolean errorInIdleStateAfterReset = false; - public boolean errorInInitializedState = false; - public boolean errorInPreparedState = false; - public boolean errorInStartedState = false; - public boolean errorInPausedState = false; - public boolean errorInStartedStateAfterPause = false; - public boolean errorInStoppedState = false; - public boolean errorInPreparedStateAfterStop = false; - public boolean errorInPlaybackCompletedState = false; - public boolean errorInErrorState = false; -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateUnitTestTemplate.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateUnitTestTemplate.java deleted file mode 100644 index 6abfbb2..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateUnitTestTemplate.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Copyright (C) 2008 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.util.Log; -import android.os.Looper; -import android.os.Handler; -import android.os.Message; -import android.media.MediaPlayer; -import android.test.AndroidTestCase; -import com.android.mediaframeworktest.MediaNames; - -/** - * A template class for running a method under test in all possible - * states of a MediaPlayer object. - * - * @see com.android.mediaframeworktest.unit.MediaPlayerSeekToStateUnitTest - * for an example of using this class. - * - * A typical concrete unit test class would implement the - * MediaPlayerMethodUnderTest interface and have a reference to an object of - * this class. Then it calls runTestOnMethod() to actually perform the unit - * tests. - * - */ -class MediaPlayerStateUnitTestTemplate extends AndroidTestCase { - private static final String TEST_PATH = MediaNames.TEST_PATH_1; - private static final String TAG = "MediaPlayerSeekToStateUnitTest"; - private static final int SEEK_TO_END = 135110; // Milliseconds. - private static int WAIT_FOR_COMMAND_TO_COMPLETE = 1000; // Milliseconds. - - private MediaPlayerStateErrors mStateErrors = new MediaPlayerStateErrors(); - private MediaPlayer mMediaPlayer = null; - private boolean mInitialized = false; - private boolean mOnCompletionHasBeenCalled = false; - private MediaPlayerStateErrors.MediaPlayerState mMediaPlayerState = null; - private Looper mLooper = null; - private final Object lock = new Object(); - private MediaPlayerMethodUnderTest mMethodUnderTest = null; - - // An Handler object is absolutely necessary for receiving callback - // messages from MediaPlayer objects. - private Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - /* - switch(msg.what) { - case MediaPlayerStateErrors.MEDIA_PLAYER_ERROR: - Log.v(TAG, "handleMessage: received MEDIA_PLAYER_ERROR message"); - break; - default: - Log.v(TAG, "handleMessage: received unknown message"); - break; - } - */ - } - }; - - /** - * Runs the given method under test in all possible states of a MediaPlayer - * object. - * - * @param testMethod the method under test. - */ - public void runTestOnMethod(MediaPlayerMethodUnderTest testMethod) { - mMethodUnderTest = testMethod; - if (mMethodUnderTest != null) { // Method under test has been set? - initializeMessageLooper(); - synchronized(lock) { - try { - lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE); - } catch(Exception e) { - Log.v(TAG, "runTestOnMethod: wait was interrupted."); - } - } - assertTrue(mInitialized); // mMediaPlayer has been initialized? - checkMethodUnderTestInAllPossibleStates(); - terminateMessageLooper(); // Release message looper thread. - assertTrue(mOnCompletionHasBeenCalled); - mMethodUnderTest.checkStateErrors(mStateErrors); - cleanUp(); - } - } - - /* - * Initializes the message looper so that the MediaPlayer object can - * receive the callback messages. - */ - private void initializeMessageLooper() { - new Thread() { - @Override - public void run() { - // Set up a looper to be used by mMediaPlayer. - Looper.prepare(); - - // Save the looper so that we can terminate this thread - // after we are done with it. - mLooper = Looper.myLooper(); - - mMediaPlayer = new MediaPlayer(); - mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { - public boolean onError(MediaPlayer player, int what, int extra) { - Log.v(TAG, "onError has been called."); - synchronized(lock) { - Log.v(TAG, "notify lock."); - setStateError(mMediaPlayerState, true); - if (mMediaPlayerState != MediaPlayerStateErrors.MediaPlayerState.ERROR) { - notifyStateError(); - } - lock.notify(); - } - return true; - } - }); - mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { - public void onCompletion(MediaPlayer player) { - Log.v(TAG, "onCompletion has been called."); - synchronized(lock) { - if (mMediaPlayerState == MediaPlayerStateErrors.MediaPlayerState.PLAYBACK_COMPLETED) { - mOnCompletionHasBeenCalled = true; - } - lock.notify(); - } - } - }); - synchronized(lock) { - mInitialized = true; - lock.notify(); - } - Looper.loop(); // Blocks forever until Looper.quit() is called. - Log.v(TAG, "initializeMessageLooper: quit."); - } - }.start(); - } - - /* - * Calls method under test in the given state of the MediaPlayer object. - * - * @param state the MediaPlayer state in which the method under test is called. - */ - private void callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState state) { - Log.v(TAG, "call " + mMethodUnderTest + ": started in state " + state); - setMediaPlayerToState(state); - mMethodUnderTest.invokeMethodUnderTest(mMediaPlayer); - synchronized(lock) { - try { - lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE); - } catch(Exception e) { - Log.v(TAG, "callMediaPlayerMethodUnderTestInState: wait is interrupted in state " + state); - } - } - Log.v(TAG, "call " + mMethodUnderTest + ": ended in state " + state); - } - - /* - * The following setMediaPlayerToXXXStateXXX methods sets the MediaPlayer - * object to the corresponding state, given the assumption that reset() - * always resets the MediaPlayer object to Idle (after reset) state. - */ - private void setMediaPlayerToIdleStateAfterReset() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - mMediaPlayer.reset(); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToIdleStateAfterReset: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToInitializedState() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToInitializedState: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToPreparedState() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToPreparedState: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToPreparedStateAfterStop() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - mMediaPlayer.start(); - mMediaPlayer.stop(); - mMediaPlayer.prepare(); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToPreparedStateAfterStop: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToStartedState() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - mMediaPlayer.start(); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToStartedState: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToStartedStateAfterPause() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - mMediaPlayer.start(); - mMediaPlayer.pause(); - - // pause() is an asynchronous call and returns immediately, but - // PV player engine may take quite a while to actually set the - // player state to Paused; if we call start() right after pause() - // without waiting, start() may fail. - try { - Thread.sleep(MediaNames.PAUSE_WAIT_TIME); - } catch(Exception ie) { - Log.v(TAG, "sleep was interrupted and terminated prematurely"); - } - - mMediaPlayer.start(); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToStartedStateAfterPause: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToPausedState() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - mMediaPlayer.start(); - mMediaPlayer.pause(); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToPausedState: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToStoppedState() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - mMediaPlayer.start(); - mMediaPlayer.stop(); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToStoppedState: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - } - - private void setMediaPlayerToPlaybackCompletedState() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.prepare(); - mMediaPlayer.seekTo(SEEK_TO_END); - mMediaPlayer.start(); - synchronized(lock) { - try { - lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToPlaybackCompletedState: wait was interrupted."); - } - } - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToPlaybackCompletedState: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(false); - } - Log.v(TAG, "setMediaPlayerToPlaybackCompletedState: done."); - } - - /* - * There are a lot of ways to force the MediaPlayer object to enter - * the Error state. The impact (such as onError is called or not) highly - * depends on how the Error state is entered. - */ - private void setMediaPlayerToErrorState() { - try { - mMediaPlayer.reset(); - mMediaPlayer.setDataSource(TEST_PATH); - mMediaPlayer.start(); - synchronized(lock) { - try { - lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE); - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToErrorState: wait was interrupted."); - } - } - } catch(Exception e) { - Log.v(TAG, "setMediaPlayerToErrorState: Exception " + e.getClass().getName() + " was thrown."); - assertTrue(e instanceof IllegalStateException); - } - Log.v(TAG, "setMediaPlayerToErrorState: done."); - } - - /* - * Sets the state of the MediaPlayer object to the specified one. - * - * @param state the state of the MediaPlayer object. - */ - private void setMediaPlayerToState(MediaPlayerStateErrors.MediaPlayerState state) { - mMediaPlayerState = state; - switch(state) { - case IDLE: - // Does nothing. - break; - case IDLE_AFTER_RESET: - setMediaPlayerToIdleStateAfterReset(); - break; - case INITIALIZED: - setMediaPlayerToInitializedState(); - break; - case PREPARED: - setMediaPlayerToPreparedState(); - break; - case PREPARED_AFTER_STOP: - setMediaPlayerToPreparedStateAfterStop(); - break; - case STARTED: - setMediaPlayerToStartedState(); - break; - case STARTED_AFTER_PAUSE: - setMediaPlayerToStartedStateAfterPause(); - break; - case PAUSED: - setMediaPlayerToPausedState(); - break; - case STOPPED: - setMediaPlayerToStoppedState(); - break; - case PLAYBACK_COMPLETED: - setMediaPlayerToPlaybackCompletedState(); - break; - case ERROR: - setMediaPlayerToErrorState(); - break; - } - } - - /* - * Sets the error value of the corresponding state to the given error. - * - * @param state the state of the MediaPlayer object. - * @param error the value of the state error to be set. - */ - private void setStateError(MediaPlayerStateErrors.MediaPlayerState state, boolean error) { - switch(state) { - case IDLE: - mStateErrors.errorInIdleState = error; - break; - case IDLE_AFTER_RESET: - mStateErrors.errorInIdleStateAfterReset = error; - break; - case INITIALIZED: - mStateErrors.errorInInitializedState = error; - break; - case PREPARED: - mStateErrors.errorInPreparedState = error; - break; - case PREPARED_AFTER_STOP: - mStateErrors.errorInPreparedStateAfterStop = error; - break; - case STARTED: - mStateErrors.errorInStartedState = error; - break; - case STARTED_AFTER_PAUSE: - mStateErrors.errorInStartedStateAfterPause = error; - break; - case PAUSED: - mStateErrors.errorInPausedState = error; - break; - case STOPPED: - mStateErrors.errorInStoppedState = error; - break; - case PLAYBACK_COMPLETED: - mStateErrors.errorInPlaybackCompletedState = error; - break; - case ERROR: - mStateErrors.errorInErrorState = error; - break; - } - } - - private void notifyStateError() { - mHandler.sendMessage(mHandler.obtainMessage(MediaPlayerStateErrors.MEDIA_PLAYER_ERROR)); - } - - private void checkIdleState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.IDLE); - } - - private void checkIdleStateAfterReset() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.IDLE_AFTER_RESET); - } - - private void checkInitializedState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.INITIALIZED); - } - - private void checkPreparedState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.PREPARED); - } - - private void checkPreparedStateAfterStop() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.PREPARED_AFTER_STOP); - } - - private void checkStartedState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.STARTED); - } - - private void checkPausedState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.PAUSED); - } - - private void checkStartedStateAfterPause() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.STARTED_AFTER_PAUSE); - } - - private void checkStoppedState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.STOPPED); - } - - private void checkPlaybackCompletedState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.PLAYBACK_COMPLETED); - } - - private void checkErrorState() { - callMediaPlayerMethodUnderTestInState(MediaPlayerStateErrors.MediaPlayerState.ERROR); - } - - /* - * Checks the given method under test in all possible states of the MediaPlayer object. - */ - private void checkMethodUnderTestInAllPossibleStates() { - // Must be called first. - checkIdleState(); - - // The sequence of the following method calls should not - // affect the test results. - checkErrorState(); - checkIdleStateAfterReset(); - checkInitializedState(); - checkStartedState(); - checkStartedStateAfterPause(); - checkPausedState(); - checkPreparedState(); - - checkPreparedStateAfterStop(); - - checkPlaybackCompletedState(); - checkStoppedState(); - } - - /* - * Terminates the message looper thread. - */ - private void terminateMessageLooper() { - mLooper.quit(); - mMediaPlayer.release(); - } - - /* - * Cleans up all the internal object references. - */ - private void cleanUp() { - mMediaPlayer = null; - mMediaPlayerState = null; - mLooper = null; - mStateErrors = null; - mMethodUnderTest = null; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java deleted file mode 100644 index 3427f86..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaPlayer; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaPlayer.stop() method can be called. - */ -public class MediaPlayerStopStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest { - private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate(); - - /** - * 1. It is valid to call stop() in the following states: - * {Prepared, Started, Stopped, Paused, PlaybackCompleted}. - * 2. It is invalid to call stop() in the following states: - * {Idle, Initialized, Error} - * - * @param stateErrors the MediaPlayerStateErrors to check against. - */ - public void checkStateErrors(MediaPlayerStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInStartedState); - assertTrue(!stateErrors.errorInStartedStateAfterPause); - assertTrue(!stateErrors.errorInStoppedState); - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInPreparedStateAfterStop); - assertTrue(!stateErrors.errorInPlaybackCompletedState); - assertTrue(!stateErrors.errorInPausedState); - - // Invalid states. - assertTrue(!stateErrors.errorInIdleState); // noError() won't be called - assertTrue(stateErrors.errorInIdleStateAfterReset); - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaPlayer player) { - player.stop(); - } - - @LargeTest - public void testStop() { - mTestTemplate.runTestOnMethod(this); - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderMethodUnderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderMethodUnderTest.java deleted file mode 100644 index 3f46f74..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderMethodUnderTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; - -/** - * All MediaRecorder method unit test subclass must implement this interface. - */ -interface MediaRecorderMethodUnderTest { - public void checkStateErrors(MediaRecorderStateErrors stateErrors); - public void invokeMethodUnderTest(MediaRecorder player); -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java deleted file mode 100644 index 134144d..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import java.io.IOException; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.prepare() method can be called. - */ -public class MediaRecorderPrepareStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - - /** - * 1. It is valid to call prepare() in the following states: - * {DataSourceConfigured}. - * 2. It is invalid to call prepare() in the following states: - * {Prepared, Initial, Initialized, Recording, Error} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInDataSourceConfiguredState); - - // Invalid states. - assertTrue(stateErrors.errorInPreparedState); - assertTrue(stateErrors.errorInRecordingState); - assertTrue(stateErrors.errorInInitialState); - assertTrue(stateErrors.errorInInitialStateAfterReset); - assertTrue(stateErrors.errorInInitialStateAfterStop); - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - try { - recorder.prepare(); - } catch (IOException exception) { - throw new RuntimeException(); - } - } - - @MediumTest - public void testPrepare() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "prepare()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderResetStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderResetStateUnitTest.java deleted file mode 100644 index cae9e31..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderResetStateUnitTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.reset() method can be called. - */ -public class MediaRecorderResetStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - - /** - * 1. It is valid to call reset() in the following states: - * {Prepared, Initial, Initialized, DataSourceConfigured, Recording, Error}. - * 2. It is invalid to call reset() in the following states: - * {} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInRecordingState); - assertTrue(!stateErrors.errorInInitialState); - assertTrue(!stateErrors.errorInInitialStateAfterReset); - assertTrue(!stateErrors.errorInInitialStateAfterStop); - assertTrue(!stateErrors.errorInInitializedState); - assertTrue(!stateErrors.errorInErrorState); - assertTrue(!stateErrors.errorInDataSourceConfiguredState); - - // Invalid states. - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - recorder.reset(); - } - - @MediumTest - public void testReset() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "reset()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioEncoderStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioEncoderStateUnitTest.java deleted file mode 100644 index 4b5a818..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioEncoderStateUnitTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.setAudioEncoder() method can be called. - */ -public class MediaRecorderSetAudioEncoderStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - - /** - * 1. It is valid to call setAudioEncoder() in the following states: - * {DataSourceConfigured}. - * 2. It is invalid to call setAudioEncoder() in the following states: - * {Initial, Initialized, Prepared, Recording, Error} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInDataSourceConfiguredState); - - // Invalid states. - assertTrue(stateErrors.errorInPreparedState); - assertTrue(stateErrors.errorInRecordingState); - assertTrue(stateErrors.errorInErrorState); - assertTrue(stateErrors.errorInInitialState); - assertTrue(stateErrors.errorInInitialStateAfterReset); - assertTrue(stateErrors.errorInInitialStateAfterStop); - assertTrue(stateErrors.errorInInitializedState); - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - recorder.setAudioEncoder(MediaRecorderStateUnitTestTemplate.AUDIO_ENCODER); - } - - @MediumTest - public void testSetAudioEncoder() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "setAudioEncoder()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioSourceStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioSourceStateUnitTest.java deleted file mode 100644 index f8ab48cf..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioSourceStateUnitTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.setAudioSource() method can be called. - */ -public class MediaRecorderSetAudioSourceStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - - /** - * 1. It is valid to call setAudioSource() in the following states: - * {Initial, Initialized}. - * 2. It is invalid to call setAudioSource() in the following states: - * {Prepared, DataSourceConfigured, Recording, Error} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInInitialState); - assertTrue(!stateErrors.errorInInitialStateAfterReset); - assertTrue(!stateErrors.errorInInitialStateAfterStop); - assertTrue(!stateErrors.errorInInitializedState); - - // Invalid states. - assertTrue(stateErrors.errorInPreparedState); - assertTrue(stateErrors.errorInRecordingState); - assertTrue(stateErrors.errorInDataSourceConfiguredState); - assertTrue(stateErrors.errorInErrorState); - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - recorder.setAudioSource(MediaRecorderStateUnitTestTemplate.AUDIO_SOURCE); - } - - @MediumTest - public void testSetAudioSource() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "setAudioSource()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java deleted file mode 100644 index 712a758..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.setOutputFile() method can be called. - */ -public class MediaRecorderSetOutputFileStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - /** - * 1. It is valid to call setOutputFile() in the following states: - * {DataSourceConfigured, Initial, Initialized, Prepared, Recording, Error}. - * 2. It is invalid to call setOutputFile() in the following states: - * {} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInDataSourceConfiguredState); - assertTrue(!stateErrors.errorInPreparedState); - assertTrue(!stateErrors.errorInRecordingState); - assertTrue(!stateErrors.errorInErrorState); - assertTrue(!stateErrors.errorInInitialState); - assertTrue(!stateErrors.errorInInitialStateAfterReset); - assertTrue(!stateErrors.errorInInitialStateAfterStop); - assertTrue(!stateErrors.errorInInitializedState); - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - recorder.setOutputFile(MediaRecorderStateUnitTestTemplate.RECORD_OUTPUT_PATH); - } - - @MediumTest - public void testSetOutputFile() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "setOutputFile()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFormatStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFormatStateUnitTest.java deleted file mode 100644 index cacdd87..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFormatStateUnitTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.setOutputFormat() method can be called. - */ -public class MediaRecorderSetOutputFormatStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - - /** - * 1. It is valid to call setOutputFormat() in the following states: - * {Initialized}. - * 2. It is invalid to call setOutputFormat() in the following states: - * {Initial, Prepared, DataSourceConfigured, Recording, Error} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInInitializedState); - - // Invalid states. - assertTrue(stateErrors.errorInInitialState); - assertTrue(stateErrors.errorInInitialStateAfterReset); - assertTrue(stateErrors.errorInInitialStateAfterStop); - assertTrue(stateErrors.errorInPreparedState); - assertTrue(stateErrors.errorInRecordingState); - assertTrue(stateErrors.errorInErrorState); - assertTrue(stateErrors.errorInDataSourceConfiguredState); - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - recorder.setOutputFormat(MediaRecorderStateUnitTestTemplate.OUTPUT_FORMAT); - } - - @MediumTest - public void testSetOutputFormat() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "setOutputFormat()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStartStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStartStateUnitTest.java deleted file mode 100644 index d1232fc..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStartStateUnitTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.start() method can be called. - */ -public class MediaRecorderStartStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - - /** - * 1. It is valid to call start() in the following states: - * {Prepared}. - * 2. It is invalid to call start() in the following states: - * {Initial, Initialized, DataSourceConfigured, Recording, Error} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInPreparedState); - - // Invalid states. - assertTrue(stateErrors.errorInRecordingState); - assertTrue(stateErrors.errorInInitialState); - assertTrue(stateErrors.errorInInitialStateAfterReset); - assertTrue(stateErrors.errorInInitialStateAfterStop); - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInErrorState); - assertTrue(stateErrors.errorInDataSourceConfiguredState); - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - recorder.start(); - } - - @MediumTest - public void testStart() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "start()"; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateErrors.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateErrors.java deleted file mode 100644 index 2d6e5a2..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateErrors.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008 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; - -class MediaRecorderStateErrors { - public static enum MediaRecorderState { - INITIAL, - INITIAL_AFTER_RESET, - INITIAL_AFTER_STOP, - INITIALIZED, - DATASOURCECONFIGURED, - PREPARED, - RECORDING, - ERROR, - } - - // Error occurs in the states below? - public boolean errorInInitialState = false; - public boolean errorInInitialStateAfterReset = false; - public boolean errorInInitialStateAfterStop = false; - public boolean errorInInitializedState = false; - public boolean errorInDataSourceConfiguredState = false; - public boolean errorInPreparedState = false; - public boolean errorInRecordingState = false; - public boolean errorInErrorState = false; -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java deleted file mode 100644 index 9edc9aa..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright (C) 2008 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.util.Log; -import android.media.MediaRecorder; -import android.test.AndroidTestCase; - -/** - * A template class for running a method under test in all possible - * states of a MediaRecorder object. - * - * @see com.android.mediaframeworktest.unit.MediaRecorderStopStateUnitTest - * for an example of using this class. - * - * A typical concrete unit test class would implement the - * MediaRecorderMethodUnderTest interface and have a reference to an object of - * this class. Then it calls runTestOnMethod() to actually perform the unit - * tests. It is recommended that the toString() method of the concrete unit test - * class be overridden to use the actual method name under test for logging - * purpose. - * - */ -class MediaRecorderStateUnitTestTemplate extends AndroidTestCase { - public static final String RECORD_OUTPUT_PATH = "/sdcard/recording.3gp"; - public static final int OUTPUT_FORMAT= MediaRecorder.OutputFormat.THREE_GPP; - public static final int AUDIO_ENCODER = MediaRecorder.AudioEncoder.AMR_NB; - public static final int AUDIO_SOURCE = MediaRecorder.AudioSource.MIC; - private static final String TAG = "MediaRecorderStateUnitTest"; - private MediaRecorderStateErrors mStateErrors = new MediaRecorderStateErrors(); - private MediaRecorder mMediaRecorder = new MediaRecorder(); - private MediaRecorderStateErrors.MediaRecorderState mMediaRecorderState = null; - private MediaRecorderMethodUnderTest mMethodUnderTest = null; - - /** - * Runs the given method under test in all possible states of a MediaRecorder - * object. - * - * @param testMethod the method under test. - */ - public void runTestOnMethod(MediaRecorderMethodUnderTest testMethod) { - mMethodUnderTest = testMethod; - if (mMethodUnderTest != null) { // Method under test has been set? - checkMethodUnderTestInAllPossibleStates(); - mMethodUnderTest.checkStateErrors(mStateErrors); - cleanUp(); - } - } - - /* - * Calls method under test in the given state of the MediaRecorder object. - * - * @param state the MediaRecorder state in which the method under test is called. - */ - private void callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState state) { - Log.v(TAG, "call " + mMethodUnderTest + ": started in state " + state); - setMediaRecorderToState(state); - try { - mMethodUnderTest.invokeMethodUnderTest(mMediaRecorder); - } catch(Exception e) { - setStateError(mMediaRecorderState, true); - } - Log.v(TAG, "call " + mMethodUnderTest + ": ended in state " + state); - } - - /* - * The following setMediaRecorderToXXXStateXXX methods sets the MediaRecorder - * object to the corresponding state, given the assumption that reset() - * always resets the MediaRecorder object to Initial (after reset) state. - */ - private void setMediaRecorderToInitialStateAfterReset() { - try { - mMediaRecorder.reset(); - } catch(Exception e) { - fail("setMediaRecorderToInitialStateAfterReset: Exception " + e.getClass().getName() + " was thrown."); - } - } - - // FIXME: - // In the past, stop() == reset(). - // However, this is no longer true. The plan is to have a STOPPED state. - // and from STOPPED state, start can be called without the need to - // do the recording configuration again. - private void setMediaRecorderToInitialStateAfterStop() { - try { - mMediaRecorder.reset(); -/* - mMediaRecorder.setAudioSource(AUDIO_SOURCE); - mMediaRecorder.setOutputFormat(OUTPUT_FORMAT); - mMediaRecorder.setAudioEncoder(AUDIO_ENCODER); - mMediaRecorder.setOutputFile(RECORD_OUTPUT_PATH); - mMediaRecorder.prepare(); - mMediaRecorder.start(); - mMediaRecorder.stop(); -*/ - } catch(Exception e) { - fail("setMediaRecorderToInitialStateAfterReset: Exception " + e.getClass().getName() + " was thrown."); - } - } - - private void setMediaRecorderToInitializedState() { - try { - mMediaRecorder.reset(); - if (mMethodUnderTest.toString() != "setAudioSource()") { - mMediaRecorder.setAudioSource(AUDIO_SOURCE); - } - } catch(Exception e) { - fail("setMediaRecorderToInitializedState: Exception " + e.getClass().getName() + " was thrown."); - } - } - - private void setMediaRecorderToPreparedState() { - try { - mMediaRecorder.reset(); - mMediaRecorder.setAudioSource(AUDIO_SOURCE); - mMediaRecorder.setOutputFormat(OUTPUT_FORMAT); - mMediaRecorder.setAudioEncoder(AUDIO_ENCODER); - mMediaRecorder.setOutputFile(RECORD_OUTPUT_PATH); - mMediaRecorder.prepare(); - } catch(Exception e) { - fail("setMediaRecorderToPreparedState: Exception " + e.getClass().getName() + " was thrown."); - } - } - - private void setMediaRecorderToRecordingState() { - try { - mMediaRecorder.reset(); - mMediaRecorder.setAudioSource(AUDIO_SOURCE); - mMediaRecorder.setOutputFormat(OUTPUT_FORMAT); - mMediaRecorder.setAudioEncoder(AUDIO_ENCODER); - mMediaRecorder.setOutputFile(RECORD_OUTPUT_PATH); - mMediaRecorder.prepare(); - mMediaRecorder.start(); - } catch(Exception e) { - fail("setMediaRecorderToRecordingState: Exception " + e.getClass().getName() + " was thrown."); - } - } - - private void setMediaRecorderToDataSourceConfiguredState() { - try { - mMediaRecorder.reset(); - mMediaRecorder.setAudioSource(AUDIO_SOURCE); - mMediaRecorder.setOutputFormat(OUTPUT_FORMAT); - - /* Skip setAudioEncoder() and setOutputFile() calls if - * the method under test is setAudioEncoder() since this - * method can only be called once even in the DATASOURCECONFIGURED state - */ - if (mMethodUnderTest.toString() != "setAudioEncoder()") { - mMediaRecorder.setAudioEncoder(AUDIO_ENCODER); - } - - if (mMethodUnderTest.toString() != "setOutputFile()") { - mMediaRecorder.setOutputFile(RECORD_OUTPUT_PATH); - } - } catch(Exception e) { - fail("setMediaRecorderToDataSourceConfiguredState: Exception " + e.getClass().getName() + " was thrown."); - } - } - - /* - * There are a lot of ways to force the MediaRecorder object to enter - * the Error state. We arbitrary choose one here. - */ - private void setMediaRecorderToErrorState() { - try { - mMediaRecorder.reset(); - - /* Skip setAudioSource() if the method under test is setAudioEncoder() - * Because, otherwise, it is valid to call setAudioEncoder() after - * start() since start() will fail, and then the mMediaRecorder - * won't be set to the Error state - */ - if (mMethodUnderTest.toString() != "setAudioEncoder()") { - mMediaRecorder.setAudioSource(AUDIO_SOURCE); - } - - /* Skip setOutputFormat if the method under test is setOutputFile() - * Because, otherwise, it is valid to call setOutputFile() after - * start() since start() will fail, and then the mMediaRecorder - * won't be set to the Error state - */ - if (mMethodUnderTest.toString() != "setOutputFile()") { - mMediaRecorder.setOutputFormat(OUTPUT_FORMAT); - } - - mMediaRecorder.start(); - } catch(Exception e) { - if (!(e instanceof IllegalStateException)) { - fail("setMediaRecorderToErrorState: Exception " + e.getClass().getName() + " was thrown."); - } - } - Log.v(TAG, "setMediaRecorderToErrorState: done."); - } - - /* - * Sets the state of the MediaRecorder object to the specified one. - * - * @param state the state of the MediaRecorder object. - */ - private void setMediaRecorderToState(MediaRecorderStateErrors.MediaRecorderState state) { - mMediaRecorderState = state; - switch(state) { - case INITIAL: - // Does nothing. - break; - case INITIAL_AFTER_RESET: - setMediaRecorderToInitialStateAfterReset(); - break; - case INITIAL_AFTER_STOP: - setMediaRecorderToInitialStateAfterStop(); - break; - case INITIALIZED: - setMediaRecorderToInitializedState(); - break; - case DATASOURCECONFIGURED: - setMediaRecorderToDataSourceConfiguredState(); - break; - case PREPARED: - setMediaRecorderToPreparedState(); - break; - case RECORDING: - setMediaRecorderToRecordingState(); - break; - case ERROR: - setMediaRecorderToErrorState(); - break; - } - } - - /* - * Sets the error value of the corresponding state to the given error. - * - * @param state the state of the MediaRecorder object. - * @param error the value of the state error to be set. - */ - private void setStateError(MediaRecorderStateErrors.MediaRecorderState state, boolean error) { - switch(state) { - case INITIAL: - mStateErrors.errorInInitialState = error; - break; - case INITIAL_AFTER_RESET: - mStateErrors.errorInInitialStateAfterReset = error; - break; - case INITIAL_AFTER_STOP: - mStateErrors.errorInInitialStateAfterStop = error; - break; - case INITIALIZED: - mStateErrors.errorInInitializedState = error; - break; - case DATASOURCECONFIGURED: - mStateErrors.errorInDataSourceConfiguredState = error; - break; - case PREPARED: - mStateErrors.errorInPreparedState = error; - break; - case RECORDING: - mStateErrors.errorInRecordingState = error; - break; - case ERROR: - mStateErrors.errorInErrorState = error; - break; - } - } - - private void checkInitialState() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.INITIAL); - } - - private void checkInitialStateAfterReset() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.INITIAL_AFTER_RESET); - } - - private void checkInitialStateAfterStop() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.INITIAL_AFTER_STOP); - } - - private void checkInitializedState() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.INITIALIZED); - } - - private void checkPreparedState() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.PREPARED); - } - - private void checkRecordingState() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.RECORDING); - } - - private void checkDataSourceConfiguredState() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.DATASOURCECONFIGURED); - } - - private void checkErrorState() { - callMediaRecorderMethodUnderTestInState(MediaRecorderStateErrors.MediaRecorderState.ERROR); - } - - /* - * Checks the given method under test in all possible states of the MediaRecorder object. - */ - private void checkMethodUnderTestInAllPossibleStates() { - // Must be called first. - checkInitialState(); - - // The sequence of the following method calls should not - // affect the test results. - checkErrorState(); - checkInitialStateAfterReset(); - checkInitialStateAfterStop(); - checkInitializedState(); - checkRecordingState(); - checkDataSourceConfiguredState(); - checkPreparedState(); - } - - /* - * Cleans up all the internal object references. - */ - private void cleanUp() { - mMediaRecorder.release(); - mMediaRecorder = null; - mMediaRecorderState = null; - mStateErrors = null; - mMethodUnderTest = null; - } -} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStopStateUnitTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStopStateUnitTest.java deleted file mode 100644 index 8737595..0000000 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStopStateUnitTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008 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.media.MediaRecorder; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; - -/** - * Unit test class to test the set of valid and invalid states that - * MediaRecorder.stop() method can be called. - */ -public class MediaRecorderStopStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { - private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); - - /** - * 1. It is valid to call stop() in the following states: - * {Recording}. - * 2. It is invalid to call stop() in the following states: - * {Initial, Initialized, DataSourceConfigured, Prepared, Error} - * - * @param stateErrors the MediaRecorderStateErrors to check against. - */ - public void checkStateErrors(MediaRecorderStateErrors stateErrors) { - // Valid states. - assertTrue(!stateErrors.errorInRecordingState); - - // Invalid states. - assertTrue(stateErrors.errorInInitialState); - assertTrue(stateErrors.errorInInitialStateAfterReset); - assertTrue(stateErrors.errorInInitialStateAfterStop); - assertTrue(stateErrors.errorInInitializedState); - assertTrue(stateErrors.errorInErrorState); - assertTrue(stateErrors.errorInDataSourceConfiguredState); - assertTrue(stateErrors.errorInPreparedState); - } - - public void invokeMethodUnderTest(MediaRecorder recorder) { - recorder.stop(); - } - - @MediumTest - public void testStop() { - mTestTemplate.runTestOnMethod(this); - } - - @Override - public String toString() { - return "stop()"; - } -} |