diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
commit | 9066cfe9886ac131c34d59ed0e2d287b0e3c0087 (patch) | |
tree | d88beb88001f2482911e3d28e43833b50e4b4e97 /media/tests | |
parent | d83a98f4ce9cfa908f5c54bbd70f03eec07e7553 (diff) | |
download | frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.zip frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.gz frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'media/tests')
53 files changed, 7283 insertions, 0 deletions
diff --git a/media/tests/MediaFrameworkTest/Android.mk b/media/tests/MediaFrameworkTest/Android.mk new file mode 100644 index 0000000..9c45e6e --- /dev/null +++ b/media/tests/MediaFrameworkTest/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_JAVA_LIBRARIES := android.test.runner + +LOCAL_PACKAGE_NAME := mediaframeworktest + +include $(BUILD_PACKAGE) diff --git a/media/tests/MediaFrameworkTest/AndroidManifest.xml b/media/tests/MediaFrameworkTest/AndroidManifest.xml new file mode 100644 index 0000000..a32f590 --- /dev/null +++ b/media/tests/MediaFrameworkTest/AndroidManifest.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.mediaframeworktest"> + + <uses-permission android:name="android.permission.RECORD_AUDIO" /> + <application> + <uses-library android:name="android.test.runner" /> + <activity android:label="@string/app_name" + android:name="MediaFrameworkTest"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + </application> + <instrumentation android:name=".MediaFrameworkTestRunner" + android:targetPackage="com.android.mediaframeworktest" + android:label="MediaFramework tests InstrumentationRunner"> + </instrumentation> + + <instrumentation android:name=".MediaFrameworkPerfTestRunner" + android:targetPackage="com.android.mediaframeworktest" + android:label="MediaFramework Performance tests InstrumentationRunner"> + </instrumentation> + + <instrumentation android:name=".MediaFrameworkUnitTestRunner" + android:targetPackage="com.android.mediaframeworktest" + android:label="MediaFramework unit tests InstrumentationRunner"> + </instrumentation> + + <instrumentation android:name=".MediaRecorderStressTestRunner" + android:targetPackage="com.android.mediaframeworktest" + android:label="MediaRecorder stress tests InstrumentationRunner"> + </instrumentation> + +</manifest> diff --git a/media/tests/MediaFrameworkTest/res/drawable/icon.png b/media/tests/MediaFrameworkTest/res/drawable/icon.png Binary files differnew file mode 100644 index 0000000..64e3601 --- /dev/null +++ b/media/tests/MediaFrameworkTest/res/drawable/icon.png diff --git a/media/tests/MediaFrameworkTest/res/layout/movie_view.xml b/media/tests/MediaFrameworkTest/res/layout/movie_view.xml new file mode 100644 index 0000000..35fedfa --- /dev/null +++ b/media/tests/MediaFrameworkTest/res/layout/movie_view.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical"> + + <FrameLayout + android:layout_width="fill_parent" + android:layout_height="0px" + android:layout_weight="1"> + + <VideoView + android:id="@+id/surface_view" + android:layout_width="320px" + android:layout_height="240px" + /> + </FrameLayout> + + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <EditText android:id="@+id/url" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="0" + android:singleLine="true" + android:paddingBottom="8dip"> + <requestFocus /> + </EditText> + + <Button android:id="@+id/open" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0" + android:text="@string/open_url"> + </Button> + + </LinearLayout> + +</LinearLayout> diff --git a/media/tests/MediaFrameworkTest/res/layout/surface_view.xml b/media/tests/MediaFrameworkTest/res/layout/surface_view.xml new file mode 100644 index 0000000..c25e476 --- /dev/null +++ b/media/tests/MediaFrameworkTest/res/layout/surface_view.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2007 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical"> + + <FrameLayout + android:layout_width="fill_parent" + android:layout_height="0px" + android:layout_weight="1"> + + <SurfaceView + android:id="@+id/surface_view" + android:layout_width="320dip" + android:layout_height="240dip" + android:layout_centerInParent="true" + /> + + <VideoView + android:id="@+id/video_view" + android:layout_width="320px" + android:layout_height="240px" + /> + + </FrameLayout> + +</LinearLayout> + diff --git a/media/tests/MediaFrameworkTest/res/raw/shortmp3.mp3 b/media/tests/MediaFrameworkTest/res/raw/shortmp3.mp3 Binary files differnew file mode 100644 index 0000000..3af32a15 --- /dev/null +++ b/media/tests/MediaFrameworkTest/res/raw/shortmp3.mp3 diff --git a/media/tests/MediaFrameworkTest/res/raw/testmidi.mid b/media/tests/MediaFrameworkTest/res/raw/testmidi.mid Binary files differnew file mode 100644 index 0000000..df84e20 --- /dev/null +++ b/media/tests/MediaFrameworkTest/res/raw/testmidi.mid diff --git a/media/tests/MediaFrameworkTest/res/raw/testmp3.mp3 b/media/tests/MediaFrameworkTest/res/raw/testmp3.mp3 Binary files differnew file mode 100644 index 0000000..89c44b0 --- /dev/null +++ b/media/tests/MediaFrameworkTest/res/raw/testmp3.mp3 diff --git a/media/tests/MediaFrameworkTest/res/values/strings.xml b/media/tests/MediaFrameworkTest/res/values/strings.xml new file mode 100644 index 0000000..a24309f --- /dev/null +++ b/media/tests/MediaFrameworkTest/res/values/strings.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">mediaPlayerApiTest</string> + <string name="open_url">Open</string> +</resources> diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkPerfTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkPerfTestRunner.java new file mode 100755 index 0000000..eaaa798 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkPerfTestRunner.java @@ -0,0 +1,51 @@ +/* + * 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; + +import com.android.mediaframeworktest.performance.MediaPlayerPerformance; + +import junit.framework.TestSuite; + +import android.test.InstrumentationTestRunner; +import android.test.InstrumentationTestSuite; + + +/** + * Instrumentation Test Runner for all MediaPlayer tests. + * + * Running all tests: + * + * adb shell am instrument \ + * -w com.android.smstests.MediaPlayerInstrumentationTestRunner + */ + +public class MediaFrameworkPerfTestRunner extends InstrumentationTestRunner { + + + @Override + public TestSuite getAllTests() { + TestSuite suite = new InstrumentationTestSuite(this); + suite.addTestSuite(MediaPlayerPerformance.class); + return suite; + } + + @Override + public ClassLoader getLoader() { + return MediaFrameworkTestRunner.class.getClassLoader(); + } +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java new file mode 100644 index 0000000..e65cf41 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTest.java @@ -0,0 +1,149 @@ +/* + * 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; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.res.AssetFileDescriptor; +import android.graphics.Color; +import android.media.MediaPlayer; +import android.net.Uri; +import android.os.Bundle; +import android.provider.Downloads; +import android.util.Log; +import android.util.Log; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.View.OnClickListener; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.MediaController; +import android.widget.VideoView; +import com.android.mediaframeworktest.MediaNames; + +import java.io.File; +import java.io.FileDescriptor; + + +public class MediaFrameworkTest extends Activity { + + //public static Surface video_sf; + public static SurfaceView mSurfaceView; + private MediaController mMediaController; + private String urlpath; + private MediaPlayer mpmidi; + private MediaPlayer mpmp3; + private String testfilepath = "/sdcard/awb.awb"; + + public static AssetFileDescriptor midiafd; + public static AssetFileDescriptor mp3afd; + + + public MediaFrameworkTest() { + } + + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + setContentView(R.layout.surface_view); + mSurfaceView = (SurfaceView)findViewById(R.id.surface_view); + ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams(); + lp.width = 320; + lp.height = 240; + mSurfaceView.setLayoutParams(lp); + mSurfaceView.getHolder().setFixedSize(320, 240); + mSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); + + //Get the midi fd + midiafd = this.getResources().openRawResourceFd(R.raw.testmidi); + + //Get the mp3 fd + mp3afd = this.getResources().openRawResourceFd(R.raw.testmp3); + } + + public void startPlayback(String filename){ + String mimetype = "audio/mpeg"; + Uri path = Uri.parse(filename); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(path, mimetype); + startActivity(intent); + } + + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { + switch (keyCode) { + case KeyEvent.KEYCODE_0: + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(MediaNames.VIDEO_RTSP3GP); + Log.v("emily","awb " + testfilepath); + mp.setDisplay(mSurfaceView.getHolder()); + mp.prepare(); + mp.start(); + }catch (Exception e){} + break; + + //start the music player intent with the test URL from PV + case KeyEvent.KEYCODE_1: + startPlayback(MediaNames.STREAM_MP3_1); + break; + + case KeyEvent.KEYCODE_2: + startPlayback(MediaNames.STREAM_MP3_2); + break; + + case KeyEvent.KEYCODE_3: + startPlayback(MediaNames.STREAM_MP3_3); + break; + + case KeyEvent.KEYCODE_4: + startPlayback(MediaNames.STREAM_MP3_4); + break; + + case KeyEvent.KEYCODE_5: + startPlayback(MediaNames.STREAM_MP3_5); + break; + + case KeyEvent.KEYCODE_6: + startPlayback(MediaNames.STREAM_MP3_6); + break; + + case KeyEvent.KEYCODE_7: + startPlayback(MediaNames.STREAM_MP3_7); + break; + + case KeyEvent.KEYCODE_8: + startPlayback(MediaNames.STREAM_MP3_8); + break; + + case KeyEvent.KEYCODE_9: + startPlayback(MediaNames.STREAM_MP3_9); + break; + + + + } + return super.onKeyDown(keyCode, event); + + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java new file mode 100755 index 0000000..73688cc --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkTestRunner.java @@ -0,0 +1,62 @@ +/* + * 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; + +import com.android.mediaframeworktest.functional.MediaPlayerApiTest; +import com.android.mediaframeworktest.functional.SimTonesTest; +import com.android.mediaframeworktest.functional.MediaMetadataTest; +import com.android.mediaframeworktest.functional.CameraTest; +import com.android.mediaframeworktest.functional.MediaRecorderTest; +import com.android.mediaframeworktest.functional.MediaAudioTrackTest; + +import junit.framework.TestSuite; + +import android.test.InstrumentationTestRunner; +import android.test.InstrumentationTestSuite; + + +/** + * Instrumentation Test Runner for all MediaPlayer tests. + * + * Running all tests: + * + * adb shell am instrument \ + * -w com.android.smstests.MediaPlayerInstrumentationTestRunner + */ + +public class MediaFrameworkTestRunner extends InstrumentationTestRunner { + + + @Override + public TestSuite getAllTests() { + TestSuite suite = new InstrumentationTestSuite(this); + suite.addTestSuite(MediaPlayerApiTest.class); + suite.addTestSuite(SimTonesTest.class); + suite.addTestSuite(MediaMetadataTest.class); + suite.addTestSuite(CameraTest.class); + suite.addTestSuite(MediaRecorderTest.class); + //suite.addTestSuite(MediaAudioTrackTest.class); + return suite; + } + + @Override + public ClassLoader getLoader() { + return MediaFrameworkTestRunner.class.getClassLoader(); + } +} + + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java new file mode 100755 index 0000000..81d59da --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaFrameworkUnitTestRunner.java @@ -0,0 +1,91 @@ +/* + * 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; + +import android.test.InstrumentationTestRunner; +import android.test.InstrumentationTestSuite; +import com.android.mediaframeworktest.unit.*; + +import junit.framework.TestSuite; + +/** + * Instrumentation Test Runner for all media framework unit tests. + * + * Make sure that MediaFrameworkUnitTestRunner has been added to + * AndroidManifest.xml file, and then "make -j4 mediaframeworktest; adb sync" + * to build and upload mediaframeworktest to the phone or emulator. + * + * Example on running all unit tests for a single class: + * adb shell am instrument -e class \ + * com.android.mediaframeworktest.unit.MediaMetadataRetrieverUnitTest \ + * -w com.android.mediaframeworktest/.MediaFrameworkUnitTestRunner + * + * Example on running all unit tests for the media framework: + * adb shell am instrument \ + * -w com.android.mediaframeworktest/.MediaFrameworkUnitTestRunner + */ + +public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner { + + @Override + public TestSuite getAllTests() { + TestSuite suite = new InstrumentationTestSuite(this); + addMediaMetadataRetrieverStateUnitTests(suite); + addMediaRecorderStateUnitTests(suite); + addMediaPlayerStateUnitTests(suite); + return suite; + } + + @Override + public ClassLoader getLoader() { + return MediaFrameworkUnitTestRunner.class.getClassLoader(); + } + + // Running all unit tests checking the state machine may be time-consuming. + private void addMediaMetadataRetrieverStateUnitTests(TestSuite suite) { + suite.addTestSuite(MediaMetadataRetrieverTest.class); + } + + // Running all unit tests checking the state machine may be time-consuming. + private void addMediaRecorderStateUnitTests(TestSuite suite) { + suite.addTestSuite(MediaRecorderPrepareStateUnitTest.class); + suite.addTestSuite(MediaRecorderResetStateUnitTest.class); + suite.addTestSuite(MediaRecorderSetAudioEncoderStateUnitTest.class); + suite.addTestSuite(MediaRecorderSetAudioSourceStateUnitTest.class); + suite.addTestSuite(MediaRecorderSetOutputFileStateUnitTest.class); + suite.addTestSuite(MediaRecorderSetOutputFormatStateUnitTest.class); + suite.addTestSuite(MediaRecorderStartStateUnitTest.class); + suite.addTestSuite(MediaRecorderStopStateUnitTest.class); + } + + // Running all unit tests checking the state machine may be time-consuming. + private void addMediaPlayerStateUnitTests(TestSuite suite) { + suite.addTestSuite(MediaPlayerGetDurationStateUnitTest.class); + suite.addTestSuite(MediaPlayerSeekToStateUnitTest.class); + suite.addTestSuite(MediaPlayerGetCurrentPositionStateUnitTest.class); + suite.addTestSuite(MediaPlayerGetVideoWidthStateUnitTest.class); + suite.addTestSuite(MediaPlayerGetVideoHeightStateUnitTest.class); + suite.addTestSuite(MediaPlayerIsPlayingStateUnitTest.class); + suite.addTestSuite(MediaPlayerResetStateUnitTest.class); + suite.addTestSuite(MediaPlayerPauseStateUnitTest.class); + suite.addTestSuite(MediaPlayerStartStateUnitTest.class); + suite.addTestSuite(MediaPlayerStopStateUnitTest.class); + suite.addTestSuite(MediaPlayerSetLoopingStateUnitTest.class); + suite.addTestSuite(MediaPlayerSetAudioStreamTypeStateUnitTest.class); + suite.addTestSuite(MediaPlayerSetVolumeStateUnitTest.class); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaNames.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaNames.java new file mode 100755 index 0000000..5e9c488 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaNames.java @@ -0,0 +1,497 @@ +/* + * 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; + +/** + * + * This class has the names of the all the activity name and variables + * in the instrumentation test. + * + */ +public class MediaNames { + + //Audio files + public static final String MP3CBR = "/sdcard/media_api/music/MP3CBR.mp3"; + public static final String MP3VBR = "/sdcard/media_api/music/MP3VBR.mp3"; + public static final String SHORTMP3 = "/sdcard/media_api/music/SHORTMP3.mp3"; + public static final String MIDI = "/sdcard/media_api/music/MIDI.mid"; + public static final String WMA9 = "/sdcard/media_api/music/WMA9.wma"; + public static final String WMA10 = "/sdcard/media_api/music/WMA10.wma"; + public static final String WAV = "/sdcard/media_api/music/complicated_wav.wav"; + public static final String AMR = "/sdcard/media_api/music/AMRNB.amr"; + public static final String OGG = "/sdcard/media_api/music/Mists_of_Time-4T.ogg"; + public static final String OGGSHORT = "/sdcard/media_api/music/Skippy.ogg"; + + public static final int MP3CBR_LENGTH = 231116; + public static final int MP3VBR_LENGTH = 126407; + public static final int SHORTMP3_LENGTH = 286; + public static final int MIDI_LENGTH = 210528; + public static final int WMA9_LENGTH = 126559; + public static final int WMA10_LENGTH = 126559; + public static final int AMR_LENGTH = 126540; + public static final int OGG_LENGTH = 40000; + public static final int SEEK_TIME = 10000; + + public static final long PAUSE_WAIT_TIME = 3000; + public static final long WAIT_TIME = 2000; + public static final long WAIT_LONG = 4000; + + //Streaming Video + public static final String VIDEO_HTTP3GP = "http://pvs.pv.com/jj/lipsync0.3gp"; + public static final String VIDEO_RTSP3GP = "rtsp://63.241.31.203/public/jj/md.3gp"; + public static final String VIDEO_RTSP3GP2 = "rtsp://pvs.pv.com/public/live_dvd1.3gp"; + public static final String VIDEO_RTSP3GP3 = + "rtsp://ehug.rtsp-youtube.l.google.com/" + + "Ci4LENy73wIaJQmeRVCJq4HuQBMYDSANFEIJbXYtZ29vZ2xlSARSB2RldGFpbHMM/0/0/0/video.3gp"; + //public static final String VIDEO_RTSP3GP = "rtsp://193.159.241.21/sp/alizee05.3gp"; + + //local video + public static final String VIDEO_MP4 = "/sdcard/media_api/video/gingerkids.MP4"; + public static final String VIDEO_LONG_3GP = "/sdcard/media_api/video/radiohead.3gp"; + public static final String VIDEO_SHORT_3GP = "/sdcard/media_api/video/short.3gp"; + public static final String VIDEO_LARGE_SIZE_3GP = "/sdcard/media_api/video/border_large.3gp"; + public static final String VIDEO_H263_AAC = "/sdcard/media_api/video/H263_AAC.3gp"; + public static final String VIDEO_H263_AMR = "/sdcard/media_api/video/H263_AMR.3gp"; + public static final String VIDEO_H264_AAC = "/sdcard/media_api/video/H264_AAC.3gp"; + public static final String VIDEO_H264_AMR = "/sdcard/media_api/video/H264_AMR.3gp"; + public static final String VIDEO_WMV = "/sdcard/media_api/video/bugs.wmv"; + public static final String VIDEO_HIGHRES_H263 = "/sdcard/media_api/video/h263_qcif_30fps.3gp"; + public static final String VIDEO_HIGHRES_MP4 = "/sdcard/media_api/video/mpeg4_qvga_24fps.3gp"; + + //ringtone + public static final String ringtone = "/sdcard/media_api/ringtones/F1_NewVoicemail.mp3"; + + //streaming mp3 + public static final String STREAM_LARGE_MP3 = + "http://wms.pv.com:7070/MediaDownloadContent/mp3/BuenaVista_04_Pueblo_Nuevo.mp3"; + public static final String STREAM_SMALL_MP3 = + "http://wms.pv.com:7070/MediaDownloadContent/mp3/ID3V2_TestFile.mp3"; + public static final String STREAM_REGULAR_MP3 = + "http://wms.pv.com:7070/MediaDownloadContent/mp3/ElectricCosmo.mp3"; + + //streaming mp3 + public static final String STREAM_MP3_1 = + "http://wms.pv.com:7070/MediaDownloadContent/mp3/chadthi_jawani_128kbps.mp3"; + public static final String STREAM_MP3_2 = + "http://wms.pv.com:7070/MediaDownloadContent/mp3/dualStereo.mp3"; + public static final String STREAM_MP3_3 = + "http://wms.pv.com:7070/mediadownloadcontent/UserUploads/15%20Keep%20Holding%20On.mp3"; + public static final String STREAM_MP3_4 = + "http://wms.pv.com:7070/mediadownloadcontent/UserUploads/1%20-%20Apologize.mp3"; + public static final String STREAM_MP3_5 = + "http://wms.pv.com:7070/mediadownloadcontent/UserUploads/" + + "03%20You're%20Gonna%20Miss%20This.mp3"; + public static final String STREAM_MP3_6 = + "http://wms.pv.com:7070/mediadownloadcontent/UserUploads" + + "/02%20Looney%20Tunes%20%C3%82%C2%B7%20Light%20Cavalry%20Overture%20(LP%20Version).mp3"; + public static final String STREAM_MP3_7 = + "http://wms.pv.com:7070/mediadownloadcontent/UserUploads" + + "/01%20Love%20Song%20(Album%20Version).mp3"; + public static final String STREAM_MP3_8 = + "http://wms.pv.com:7070/MediaDownloadContent/UserUploads/1%20-%20Apologize.mp3"; + public static final String STREAM_MP3_9 = + "http://wms.pv.com:7070/MediaDownloadContent/UserUploads" + + "/1%20-%20Smile%20(Explicit%20Version).mp3"; + public static final String STREAM_MP3_10 = + "http://wms.pv.com:7070/MediaDownloadContent/UserUploads/beefcake.mp3"; + + //Sonivox + public static String MIDIFILES[] = { + "/sdcard/media_api/music/Leadsol.mxmf", + "/sdcard/media_api/music/abba.imy", "/sdcard/media_api/music/ants.mid", + "/sdcard/media_api/music/greensleeves.rtttl", "/sdcard/media_api/music/test.ota"}; + + //Performance measurement + public static String[] WAVFILES = { + "/sdcard/media_api/music_perf/WAV/M1F1-AlawWE-AFsp.wav", + "/sdcard/media_api/music_perf/WAV/M1F1-float64-AFsp.wav", + "/sdcard/media_api/music_perf/WAV/song.wav", + "/sdcard/media_api/music_perf/WAV/WAVEtest.wav", + "/sdcard/media_api/music_perf/WAV/WAVEtest_out.wav", + "/sdcard/media_api/music_perf/WAV/test_out.wav"}; + + public static String[] AMRNBFILES = { + "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_5.9kbps_6.24kbps_8khz_mono_NMC.amr", + "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_5.15kbps_5.46kbps_8khz_mono_NMC.amr", + "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_7.4kbps_7.80kbps_8khz_mono_NMC.amr", + "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_7.95kbps_9.6kbps_8khz_mono_NMC.amr", + "/sdcard/media_api/music_perf/AMR/AI_AMR-NB_10.2kbps_10.48kbps_8khz_mono_NMC.amr"}; + + public static String[] AMRWBFILES = { + "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_15.85kbps_16kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_18.25kbps_18kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_19.85kbps_20kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_23.05kbps_23kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/NIN_AMR-WB_23.85kbps_24kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/PD_AMR-WB_19.85kbps_20kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/PD_AMR-WB_23.05kbps_23kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/PD_AMR-WB_23.85kbps_24kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/WC_AMR-WB_23.05kbps_23kbps.amr", + "/sdcard/media_api/music_perf/AMRWB/WC_AMR-WB_23.85kbps_24kbps.amr", }; + + public static String[] MP3FILES = { + "/sdcard/media_api/music_perf/MP3/NIN_56kbps_32khz_stereo_VBR_MCA.MP3", + "/sdcard/media_api/music_perf/MP3/NIN_80kbps_32khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_80kbps_44.1khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_80kbps_48khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_112kbps_32khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_112kbps_44.1khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_112kbps_48khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_192kbps_32khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_192kbps_44.1khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_192kbps_48khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_256kbps_44.1khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/NIN_256kbps_48khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/PD_112kbps_32khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/PD_112kbps_44.1khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/PD_112kbps_48khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/PD_192kbps_32khz_mono_CBR_DPA.mp3", + "/sdcard/media_api/music_perf/MP3/PD_256kbps_44.1khz_mono_CBR_DPA.mp3", + "/sdcard/media_api/music_perf/MP3/PD_256kbps_48khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/music_perf/MP3/WC_256kbps_44.1khz_mono_CBR_DPA.mp3", + "/sdcard/media_api/music_perf/MP3/WC_256kbps_48khz_mono_CBR_DPA.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/Apologize.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/Because_Of_You.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/Complicated.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/Glamorous.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/Im_With_You.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/Smile.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/Suddenly_I_See.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/When You Say Nothing At All.mp3", + "/sdcard/media_api/music_perf/regular_album_photo/my_happy_ending.mp3"}; + + public static String[] AACFILES = { + "/sdcard/media_api/music_perf/AAC/AI_AAC_24kbps_12khz_Mono_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/AI_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/AI_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/AI_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/AI_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/AI_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/NIN_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/NIN_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/NIN_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/NIN_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/NIN_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PD_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PD_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PD_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PD_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PD_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PV_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PV_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PV_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PV_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/PV_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/WC_AAC_56kbps_22.05khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/WC_AAC_56kbps_32khz_Stereo_CBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/WC_AAC_56kbps_44.1khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/WC_AAC_80kbps_32khz_Stereo_1pCBR_SSE.mp4", + "/sdcard/media_api/music_perf/AAC/WC_AAC_80kbps_32khz_Stereo_CBR_SSE.mp4", + }; + + public static String[] VIDEOFILES = { "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_10fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4", + "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_12fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4", + "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_15fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4", + "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_5fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4", + "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_5fps_SQCIF_128x96+AAC_8kbps_8khz_mono_SSE.mp4", + "/sdcard/media_api/video_perf/AI_CTO_Mpeg4_32kbps_7.5fps_SQCIF_128x96+AAC_8kbps_8khz_mono_QTE.mp4", + "/sdcard/media_api/video_perf/AI_WMV_1024kbps_20fps_QCIF_176x144_noaudio_SSE.wmv", + "/sdcard/media_api/video_perf/AI_WMV_1024kbps_25fps_QCIF_176x144_noaudio_SSE.wmv", + "/sdcard/media_api/video_perf/Chicken.wmv", + "/sdcard/media_api/video_perf/MP_qcif_15fps_100kbps_48kHz_192kbps_30secs.wmv", + "/sdcard/media_api/video_perf/NIN_CTO_H264_123kbps_5fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_H264_96kbps_10.2fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_H264_96kbps_12fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_H264_96kbps_15fps_QCIF_176x144+AMR_12.2kbps_8khz_mono_QTE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_123kbps_15fps_QCIF_176x144+AAC_32kbps_22khz_mono_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_123kbps_7.5fps_QCIF_176x144+AAC_32kbps_22khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_10fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_12fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_15fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_5fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_CTO_Mpeg4_128kbps_7.5fps_QCIF_176x144+AAC+_32kbps_48khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_H263_128kbps_10fps_QCIF_174x144_noaudio_SSE.mp4", + "/sdcard/media_api/video_perf/NIN_H263_128kbps_15fps_QCIF_174x144_noaudio_SSE.mp4", + "/sdcard/media_api/video_perf/NIN_H263_48kbps_10fps_QCIF_174x144_noaudio_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_H263_48kbps_12fps_QCIF_174x144_noaudio_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_H264_123kbps_15fps_QCIF_176x144+AAC_32kbps_22khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/NIN_H264_123kbps_7.5fps_QCIF_176x144+AAC_32kbps_22khz_stereo_SSE.3gp", + "/sdcard/media_api/video_perf/PV_H264_2000kbps_20fps_CIF_352x288+AAC_96kbps_48khz_stereo_SSE.mp4", + "/sdcard/media_api/video_perf/PV_H264_2000kbps_25fps_CIF_352x288+AAC_96kbps_48khz_stereo_SSE.mp4", + "/sdcard/media_api/video_perf/PV_H264_2000kbps_30fps_CIF_352x288+AAC_128kbps_48khz_stereo_SSE.mp4", + "/sdcard/media_api/video_perf/Stevie-1.wmv", + "/sdcard/media_api/video_perf/WC_H264_1600kbps_20fps_QCIF_176x144+AAC_96kbps_48khz_mono_SSE.mp4", + "/sdcard/media_api/video_perf/WC_H264_1600kbps_25fps_QCIF_176x144+AAC_96kbps_48khz_mono_SSE.mp4", + "/sdcard/media_api/video_perf/WC_H264_1600kbps_30fps_QCIF_176x144+AAC_96kbps_48khz_mono_SSE.mp4", + "/sdcard/media_api/video_perf/bugs.wmv", + "/sdcard/media_api/video_perf/niceday.wmv", + "/sdcard/media_api/video_perf/eaglesatopnflpe.wmv", + + }; + + //wma - only support up to wma 9 + public static String[] WMASUPPORTED = { + "/sdcard/media_api/music_perf/WMASUPPORTED/AI_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/AI_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/NIN_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/NIN_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/PD_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/PD_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/PV_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/PV_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/WC_WMA9.2_32kbps_44.1khz_mono_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMASUPPORTED/WC_WMA9.2_48kbps_44.1khz_mono_CBR_DPA.wma" + + }; + + public static String[] WMAUNSUPPORTED = { + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_127kbps_48khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_44.1khz_stereo_2pVBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_48khz_stereo_2pVBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_88khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_128kbps_96khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_192kbps_44.1khz_stereo_2pVBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_192kbps_88khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_192kbps_96khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_44khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_48khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_88khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_256kbps_96khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_384kbps_44khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_384kbps_48khz_stereo_CBR_DPA.wma", + "/sdcard/media_api/music_perf/WMAUNSUPPORTED/AI_WMA10_384kbps_88khz_stereo_CBR_DPA.wma" + }; + + //Media Recorder + public static final String RECORDER_OUTPUT = "/sdcard/media_api/recorderOutput.amr"; + + //video thumbnail + public static final String THUMBNAIL_OUTPUT = "/sdcard/media_api/videoThumbnail.png"; + public static final String GOLDEN_THUMBNAIL_OUTPUT = "/sdcard/media_api/goldenThumbnail.png"; + + //Metadata Utility + public static final String[] THUMBNAIL_CAPTURE_TEST_FILES = { + "/sdcard/media_api/metadata/test.mp4", + "/sdcard/media_api/metadata/test1.3gp", + "/sdcard/media_api/metadata/test2.3gp", + "/sdcard/media_api/metadata/test3.3gp", + "/sdcard/media_api/metadata/test4.3gp", + "/sdcard/media_api/metadata/test5.3gp", + "/sdcard/media_api/metadata/test6.3gp", + "/sdcard/media_api/metadata/test7.3gp", + "/sdcard/media_api/metadata/test8.3gp", + "/sdcard/media_api/metadata/test9.3gp", + "/sdcard/media_api/metadata/test10.3gp", + "/sdcard/media_api/metadata/test11.3gp", + "/sdcard/media_api/metadata/test12.3gp", + "/sdcard/media_api/metadata/test13.3gp", + "/sdcard/media_api/metadata/test14.3gp", + "/sdcard/media_api/metadata/test15.3gp", + "/sdcard/media_api/metadata/test16.3gp", + "/sdcard/media_api/metadata/test17.3gp", + "/sdcard/media_api/metadata/test18.3gp", + "/sdcard/media_api/metadata/test19.3gp", + "/sdcard/media_api/metadata/test20.3gp", + "/sdcard/media_api/metadata/test21.3gp", + "/sdcard/media_api/metadata/test22.3gp", + "/sdcard/media_api/metadata/test23.3gp", + "/sdcard/media_api/metadata/test24.3gp", + "/sdcard/media_api/metadata/test25.3gp", + "/sdcard/media_api/metadata/test26.3gp", + "/sdcard/media_api/metadata/test27.3gp", + "/sdcard/media_api/metadata/test28.3gp", + "/sdcard/media_api/metadata/test29.3gp", + "/sdcard/media_api/metadata/test30.3gp", + "/sdcard/media_api/metadata/test31.3gp", + "/sdcard/media_api/metadata/test32.3gp", + "/sdcard/media_api/metadata/test33.3gp", + "/sdcard/media_api/metadata/test35.mp4", + "/sdcard/media_api/metadata/test36.m4v", + "/sdcard/media_api/metadata/test34.wmv", + "/sdcard/media_api/metadata/test_metadata.mp4", + }; + + public static final String[] METADATA_RETRIEVAL_TEST_FILES = { + // Raw AAC is not supported + // "/sdcard/media_api/test_raw.aac", + // "/sdcard/media_api/test_adts.aac", + // "/sdcard/media_api/test_adif.aac", + "/sdcard/media_api/metadata/test_metadata.mp4", + "/sdcard/media_api/metadata/WMA10.wma", + "/sdcard/media_api/metadata/Leadsol_out.wav", + "/sdcard/media_api/metadata/test_aac.mp4", + "/sdcard/media_api/metadata/test_amr.mp4", + "/sdcard/media_api/metadata/test_avc_amr.mp4", + "/sdcard/media_api/metadata/test_metadata.mp4", + "/sdcard/media_api/metadata/test_vbr.mp3", + "/sdcard/media_api/metadata/test_cbr.mp3", + "/sdcard/media_api/metadata/metadata_test1.mp3", + "/sdcard/media_api/metadata/test33.3gp", + "/sdcard/media_api/metadata/test35.mp4", + "/sdcard/media_api/metadata/test36.m4v", + "/sdcard/media_api/metadata/test_m4v_amr.mp4", + "/sdcard/media_api/metadata/test_h263_amr.mp4", + "/sdcard/media_api/metadata/test34.wmv", + }; + + public static final String[] ALBUMART_TEST_FILES = { + "/sdcard/media_api/album_photo/test_22_16_mp3.mp3", + "/sdcard/media_api/album_photo/PD_256kbps_48khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/album_photo/PD_256kbps_44.1khz_mono_CBR_DPA.mp3", + "/sdcard/media_api/album_photo/PD_192kbps_32khz_mono_CBR_DPA.mp3", + "/sdcard/media_api/album_photo/NIN_256kbps_48khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/album_photo/NIN_256kbps_44.1khz_mono_CBR_MCA.mp3", + "/sdcard/media_api/album_photo/NIN_112kbps(96kbps)_48khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/album_photo/NIN_112kbps(96kbps)_44.1khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/album_photo/lightGreen1.mp3", + "/sdcard/media_api/album_photo/babyBlue2 1.mp3", + "/sdcard/media_api/album_photo/2-01 01 NIN_56kbps(64kbps)_32khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/album_photo/02_NIN_112kbps(80kbps)_32khz_stereo_VBR_MCA.mp3", + "/sdcard/media_api/album_photo/No_Woman_No_Cry_128K.wma", + "/sdcard/media_api/album_photo/Beethoven_2.wma", + }; + + //TEST_PATH_1: is a video and contains metadata for key "num-tracks" + // TEST_PATH_2: any valid media file. + // TEST_PATH_3: invalid media file + public static final String TEST_PATH_1 = "/sdcard/media_api/metadata/test.mp4"; + public static final String TEST_PATH_3 = "/sdcard/media_api/data.txt"; + public static final String TEST_PATH_4 = "somenonexistingpathname"; + public static final String TEST_PATH_5 = "mem://012345"; + + //Meta data expected result + //The expected tag result in the following order + //cd_track_number, album, artist, author, composer, date, genre + //title, years, duration + public static final String META_DATA_MP3 [][] = { + {"/sdcard/media_api/metaDataTestMedias/MP3/ID3V1_ID3V2.mp3", "1/10", "ID3V2.3 Album", "ID3V2.3 Artist", + "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, "Blues", + "ID3V2.3 Title", "1234", "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/ID3V2.mp3", "1/10", "ID3V2.3 Album", "ID3V2.3 Artist", + "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, "Blues", + "ID3V2.3 Title", "1234", "313", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/ID3V1.mp3", null, "test ID3V1 Album", "test ID3V1 Artist", + null, null, null, null, "test ID3V1 Title", "1234", "231332", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V1.mp3" , null, null, null, + null, null, null, null, null, null, "231330", "1"}, + //The corrupted TALB field in id3v2 would not switch to id3v1 tag automatically + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TALB.mp3", "01", null, "ID3V2.3 Artist", + "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, + "Blues", "ID3V2.3 Title", "1234", "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TCOM.mp3", "01", "ID3V2.3 Album", + "ID3V2.3 Artist", "ID3V2.3 Lyricist", null, null, + "Blues", "ID3V2.3 Title", "1234", "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TCOM_2.mp3", "01", "ID3V2.3 Album", + "ID3V2.3 Artist", null, null, null, "Blues", "ID3V2.3 Title", "1234", "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TRCK.mp3", "dd", "ID3V2.3 Album", + "ID3V2.3 Artist", "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, + "Blues", "ID3V2.3 Title", "1234", "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TRCK_2.mp3", "01", "ID3V2.3 Album", + "ID3V2.3 Artist", null, null, null, null, "ID3V2.3 Title", null, "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TYER.mp3", "01", "ID3V2.3 Album", + "ID3V2.3 Artist", null, null, null, null, "ID3V2.3 Title", "9999", "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TYER_2.mp3", "01", "ID3V2.3 Album", + "ID3V2.3 Artist", "ID3V2.3 Lyricist", "ID3V2.3 Composer", null, + "Blues", "ID3V2.3 Title", null, "321", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP3/Corrupted_ID3V2_TIT.mp3", null, null, null, + null, null, null, null, null, null, "577", "1"} + }; + + public static final String META_DATA_OTHERS [][] = { + {"/sdcard/media_api/metaDataTestMedias/3GP/cat.3gp", null, null, null, + null, null, "20080309T002415.000Z", null, + null, null, "1404928", "2"}, + {"/sdcard/media_api/metaDataTestMedias/AMR/AMR_NB.amr", null, null, null, + null, null, null, null, + null, null, "126540", "1"}, + {"/sdcard/media_api/metaDataTestMedias/AMRWB/AMR_WB.amr", null, null, null, + null, null, null, null, + null, null, "231180", "1"}, + {"/sdcard/media_api/metaDataTestMedias/M4A/Jaws Of Life_ver1.m4a", null, "Suspended Animation", + "John Petrucci", null, null, "20070510T125223.000Z", + null, null, "2005", "231180", "1"}, + {"/sdcard/media_api/metaDataTestMedias/M4V/sample_iPod.m4v", null, null, + null, null, null, "20051220T202015.000Z", + null, null, null, "3771392", "2"}, + {"/sdcard/media_api/metaDataTestMedias/MIDI/MIDI.mid", null, "Suspended Animation", + "John Petrucci", null, null, "20070510T125223.000Z", + null, null, "2005", "231180", "1"}, + {"/sdcard/media_api/metaDataTestMedias/MP4/kung_fu_panda_h264.mp4", null, "mp4 album Kung Fu Panda", + "mp4 artist Kung Fu Panda", null, null, "20080517T091451.000Z", + "Kung Fu Panda", "Kung Fu Panda", "2008", "5667840", "2"}, + {"/sdcard/media_api/metaDataTestMedias/OGG/Ring_Classic_02.ogg", null, "Suspended Animation", + "John Petrucci", null, null, "20070510T125223.000Z", + null, null, "2005", "231180", "1"}, + {"/sdcard/media_api/metaDataTestMedias/OGG/When You Say Nothing At All.ogg", + null, "Suspended Animation", "John Petrucci", + null, null, "20070510T125223.000Z", null, null, "2005", "231180", "1"}, + {"/sdcard/media_api/metaDataTestMedias/WAV/Im With You.wav", null, null, + null, null, null, null, + null, null, null, "224000", "1"}, + {"/sdcard/media_api/metaDataTestMedias/WMA/WMA9.wma", "6", "Ten Songs in the Key of Betrayal", + "Alien Crime Syndicate", "Alien Crime Syndicate", + "wma 9 Composer", "20040521T175729.483Z", + "Rock", "Run for the Money", "2004", "134479", "1"}, + {"/sdcard/media_api/metaDataTestMedias/WMA/WMA10.wma", "09", "wma 10 Album", + "wma 10 Album Artist", "wma 10 Artist", "wma 10 Composer", "20070705T063625.097Z", + "Acid Jazz", "wma 10 Title", "2010", "126574", "1"}, + {"/sdcard/media_api/metaDataTestMedias/WMV/bugs.wmv", "8", "wmv 9 Album", + null, "wmv 9 Artist ", null, "20051122T155247.540Z", + null, "Looney Tunes - Hare-Breadth Hurry", "2005", "193482", "2"}, + {"/sdcard/media_api/metaDataTestMedias/WMV/clips_ver7.wmv", "50", "wmv 7 Album", + null, "Hallau Shoots & Company", null, "20020226T170045.891Z", + null, "CODEC Shootout", "1986", "43709", "2"} + }; + + //output recorded video + + public static final String RECORDED_HVGA_H263 = "/sdcard/HVGA_H263.3gp"; + public static final String RECORDED_QVGA_H263 = "/sdcard/QVGA_H263.3gp"; + public static final String RECORDED_SQVGA_H263 = "/sdcard/SQVGA_H263.3gp"; + public static final String RECORDED_CIF_H263 = "/sdcard/CIF_H263.3gp"; + public static final String RECORDED_QCIF_H263 = "/sdcard/QCIF_H263.3gp"; + + public static final String RECORDED_HVGA_MP4 = "/sdcard/HVGA_mp4.mp4"; + public static final String RECORDED_QVGA_MP4 = "/sdcard/QVGA_mp4.mp4"; + public static final String RECORDED_SQVGA_MP4 = "/sdcard/SQVGA_mp4.mp4"; + public static final String RECORDED_CIF_MP4 = "/sdcard/CIF_mp4.mp4"; + public static final String RECORDED_QCIF_MP4 = "/sdcard/QCIF_mp4.mp4"; + + public static final String RECORDED_VIDEO_3GP = "/sdcard/temp.3gp"; + + public static final String INVALD_VIDEO_PATH = "/sdcard/media_api/filepathdoesnotexist" + + "/filepathdoesnotexist/temp.3gp"; + + + public static final long RECORDED_TIME = 5000; + public static final long VALID_VIDEO_DURATION = 2000; + + //Videos for the mediaplayer stress test + public static String[] H263_STRESS = { + "/sdcard/media_api/video_stress/h263/H263_CIF.3gp", + "/sdcard/media_api/video_stress/h263/H263_QCIF.3gp", + "/sdcard/media_api/video_stress/h263/H263_QVGA.3gp", + "/sdcard/media_api/video_stress/h263/H263_SQVGA.3gp" + }; + + public static String[] MPEG4_STRESS = { + "/sdcard/media_api/video_stress/h263/mpeg4_CIF.mp4", + "/sdcard/media_api/video_stress/h263/mpeg4_QCIF.3gp", + "/sdcard/media_api/video_stress/h263/mpeg4_QVGA.3gp", + "/sdcard/media_api/video_stress/h263/mpeg4_SQVGA.mp4" + }; +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java new file mode 100755 index 0000000..12eacd3 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaRecorderStressTestRunner.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest; + +import android.test.InstrumentationTestRunner; +import android.test.InstrumentationTestSuite; +import com.android.mediaframeworktest.stress.MediaRecorderStressTest; + +import junit.framework.TestSuite; + +public class MediaRecorderStressTestRunner extends InstrumentationTestRunner { + + @Override + public TestSuite getAllTests() { + TestSuite suite = new InstrumentationTestSuite(this); + suite.addTestSuite(MediaRecorderStressTest.class); + return suite; + } + + @Override + public ClassLoader getLoader() { + return MediaRecorderStressTestRunner.class.getClassLoader(); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java new file mode 100644 index 0000000..59803f7 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CameraTest.java @@ -0,0 +1,262 @@ +/* + * 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.functional; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import java.io.*; + +import android.content.Context; +import android.hardware.Camera; +import android.hardware.Camera.PictureCallback; +import android.hardware.Camera.PreviewCallback; +import android.hardware.Camera.ShutterCallback; +import android.test.ActivityInstrumentationTestCase; +import android.util.Log; +import android.view.SurfaceHolder; + +import android.os.Looper; + +import android.test.suitebuilder.annotation.LargeTest; + +/** + * Junit / Instrumentation test case for the camera api + + */ +public class CameraTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> { + private String TAG = "CameraTest"; + + private boolean rawPreviewCallbackResult = false; + private boolean shutterCallbackResult = false; + private boolean rawPictureCallbackResult = false; + private boolean jpegPictureCallbackResult = false; + + private static int WAIT_FOR_COMMAND_TO_COMPLETE = 10000; // Milliseconds. + + private RawPreviewCallback mRawPreviewCallback = new RawPreviewCallback(); + private TestShutterCallback mShutterCallback = new TestShutterCallback(); + private RawPictureCallback mRawPictureCallback = new RawPictureCallback(); + private JpegPictureCallback mJpegPictureCallback = new JpegPictureCallback(); + + private boolean mInitialized = false; + private Looper mLooper = null; + private final Object lock = new Object(); + private final Object previewDone = new Object(); + + Camera mCamera; + Context mContext; + + public CameraTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + /* + * Initializes the message looper so that the Camera object can + * receive the callback messages. + */ + private void initializeMessageLooper() { + Log.v(TAG, "start looper"); + new Thread() { + @Override + public void run() { + // Set up a looper to be used by camera. + Looper.prepare(); + Log.v(TAG, "start loopRun"); + // Save the looper so that we can terminate this thread + // after we are done with it. + mLooper = Looper.myLooper(); + mCamera = Camera.open(); + synchronized (lock) { + mInitialized = true; + lock.notify(); + } + Looper.loop(); // Blocks forever until Looper.quit() is called. + Log.v(TAG, "initializeMessageLooper: quit."); + } + }.start(); + } + + /* + * Terminates the message looper thread. + */ + private void terminateMessageLooper() { + mLooper.quit(); + mCamera.release(); + } + + //Implement the previewCallback + private final class RawPreviewCallback implements PreviewCallback { + public void onPreviewFrame(byte [] rawData, Camera camera) { + Log.v(TAG, "Preview callback start"); + int rawDataLength = 0; + if (rawData != null) { + rawDataLength = rawData.length; + } + if (rawDataLength > 0) { + rawPreviewCallbackResult = true; + } else { + rawPreviewCallbackResult = false; + } + synchronized (previewDone) { + Log.v(TAG, "notify the preview callback"); + previewDone.notify(); + } + + Log.v(TAG, "Preview callback stop"); + } + }; + + //Implement the shutterCallback + private final class TestShutterCallback implements ShutterCallback { + public void onShutter() { + shutterCallbackResult = true; + Log.v(TAG, "onShutter called"); + } + }; + + //Implement the RawPictureCallback + private final class RawPictureCallback implements PictureCallback { + public void onPictureTaken(byte [] rawData, Camera camera) { + // no support for raw data - success if we get the callback + rawPictureCallbackResult = true; + //if (rawData != null) { + // rawPictureCallbackResult = true; + //} else { + // rawPictureCallbackResult = false; + //} + Log.v(TAG, "RawPictureCallback callback"); + } + }; + + //Implement the JpegPictureCallback + private final class JpegPictureCallback implements PictureCallback { + public void onPictureTaken(byte [] rawData, Camera camera) { + try { + if (rawData != null) { + int rawDataLength = rawData.length; + File rawoutput = new File("/sdcard/test.bmp"); + FileOutputStream outstream = new FileOutputStream(rawoutput); + outstream.write(rawData); + Log.v(TAG, "JpegPictureCallback rawDataLength = " + rawDataLength); + jpegPictureCallbackResult = true; + } else { + jpegPictureCallbackResult = false; + } + Log.v(TAG, "Jpeg Picture callback"); + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + } + }; + + + private void checkTakePicture() { + SurfaceHolder mSurfaceHolder; + try { + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + mCamera.setPreviewDisplay(mSurfaceHolder); + Log.v(TAG, "Start preview"); + mCamera.startPreview(); + synchronized (previewDone) { + try { + previewDone.wait(WAIT_FOR_COMMAND_TO_COMPLETE); + Log.v(TAG, "Preview Done"); + } catch (Exception e) { + Log.v(TAG, "wait was interrupted."); + } + } + mCamera.setPreviewCallback(null); + mCamera.takePicture(mShutterCallback, mRawPictureCallback, mJpegPictureCallback); + Thread.sleep(MediaNames.WAIT_LONG); + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + } + + private void checkPreviewCallback() { + SurfaceHolder mSurfaceHolder; + try { + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + mCamera.setPreviewDisplay(mSurfaceHolder); + Log.v(TAG, "start preview"); + mCamera.startPreview(); + synchronized (previewDone) { + try { + previewDone.wait(WAIT_FOR_COMMAND_TO_COMPLETE); + Log.v(TAG, "setPreview done"); + } catch (Exception e) { + Log.v(TAG, "wait was interrupted."); + } + } + mCamera.setPreviewCallback(null); + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + } + + /* + * TODO(yslau): Need to setup the golden rawData and compare the + * the new captured rawData with the golden one. + * + * Test case 1: Take a picture and verify all the callback + * functions are called properly. + */ + @LargeTest + public void testTakePicture() throws Exception { + initializeMessageLooper(); + synchronized (lock) { + try { + lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE); + } catch(Exception e) { + Log.v(TAG, "runTestOnMethod: wait was interrupted."); + } + } + mCamera.setPreviewCallback(mRawPreviewCallback); + checkTakePicture(); + terminateMessageLooper(); + assertTrue("shutterCallbackResult", shutterCallbackResult); + assertTrue("rawPictureCallbackResult", rawPictureCallbackResult); + assertTrue("jpegPictureCallbackResult", jpegPictureCallbackResult); + } + + /* + * Test case 2: Set the preview and + * verify the RawPreviewCallback is called + */ + @LargeTest + public void testCheckPreview() throws Exception { + initializeMessageLooper(); + synchronized (lock) { + try { + lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE); + } catch(Exception e) { + Log.v(TAG, "wait was interrupted."); + } + } + mCamera.setPreviewCallback(mRawPreviewCallback); + checkPreviewCallback(); + terminateMessageLooper(); + assertTrue("RawPreviewCallbackResult", rawPreviewCallbackResult); + } + +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java new file mode 100644 index 0000000..0e88719 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/CodecTest.java @@ -0,0 +1,577 @@ +/* + * 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.functional; + + + +//import android.content.Resources; +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import android.content.res.AssetFileDescriptor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.media.MediaMetadataRetriever; +import android.media.MediaPlayer; +import android.media.MediaRecorder; +import android.os.SystemClock; +import android.util.Log; + +import java.io.IOException; +import java.io.InputStream; +/** + * Junit / Instrumentation test case for the media player api + + */ +public class CodecTest { + private static String TAG = "MediaPlayerApiTest"; + + public static String printCpuInfo(){ + String cm = "dumpsys cpuinfo"; + String cpuinfo =null; + int ch; + try{ + Process p = Runtime.getRuntime().exec(cm); + InputStream in = p.getInputStream(); + StringBuffer sb = new StringBuffer(512); + while ( ( ch = in.read() ) != -1 ){ + sb.append((char) ch); + } + cpuinfo = sb.toString(); + }catch (IOException e){ + Log.v(TAG, e.toString()); + } + return cpuinfo; + } + + + public static int getDuration(String filePath) { + Log.v(TAG, "getDuration - " + filePath); + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + mp.prepare(); + }catch (Exception e){} + int duration = mp.getDuration(); + Log.v(TAG, "Duration " + duration); + mp.release(); + Log.v(TAG, "release"); + return duration; + } + + public static boolean getCurrentPosition(String filePath){ + Log.v(TAG, "GetCurrentPosition - " + filePath); + int currentPosition = 0; + long t1=0; + long t2 =0; + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + Log.v(TAG, "start playback"); + mp.prepare(); + mp.start(); + t1=SystemClock.uptimeMillis(); + Thread.sleep(10000); + mp.pause(); + Thread.sleep(MediaNames.PAUSE_WAIT_TIME); + t2=SystemClock.uptimeMillis(); + }catch (Exception e){ + Log.v(TAG, e.toString()); + } + currentPosition = mp.getCurrentPosition(); + mp.stop(); + mp.release(); + Log.v(TAG, "mp currentPositon = " + currentPosition + " play duration = " + (t2-t1)); + //The currentposition should be within 10% of the sleep time + //For the very short mp3, it should return the length instead of 10 seconds + if (filePath.equals(MediaNames.SHORTMP3)){ + if (currentPosition < 1000 ) + return true; + } + if ((currentPosition < ((t2-t1) *1.2)) && (currentPosition > 0)) + return true; + else + return false; + } + + public static boolean seekTo(String filePath){ + Log.v(TAG, "seekTo " + filePath); + int currentPosition = 0; + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + mp.prepare(); + mp.start(); + mp.seekTo(MediaNames.SEEK_TIME); + Thread.sleep(MediaNames.WAIT_TIME); + currentPosition = mp.getCurrentPosition(); + }catch (Exception e){ + Log.v(TAG, e.getMessage()); + } + mp.stop(); + mp.release(); + Log.v(TAG, "CurrentPosition = " + currentPosition); + //The currentposition should be at least greater than the 80% of seek time + if ((currentPosition > MediaNames.SEEK_TIME *0.8)) + return true; + else + return false; + } + + public static boolean setLooping(String filePath){ + int currentPosition = 0; + int duration = 0; + long t1 =0; + long t2 =0; + Log.v (TAG, "SetLooping - " + filePath); + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + mp.prepare(); + duration = mp.getDuration(); + Log.v(TAG, "setLooping duration " + duration); + mp.setLooping(true); + mp.start(); + Thread.sleep(5000); + mp.seekTo(duration - 5000); + t1=SystemClock.uptimeMillis(); + Thread.sleep(20000); + t2=SystemClock.uptimeMillis(); + Log.v(TAG, "pause"); + //Bug# 1106852 - IllegalStateException will be thrown if pause is called + //in here + //mp.pause(); + currentPosition = mp.getCurrentPosition(); + Log.v(TAG, "looping position " + currentPosition + "duration = " + (t2-t1)); + }catch (Exception e){ + Log.v(TAG, "Exception : " + e.toString()); + } + mp.stop(); + mp.release(); + //The current position should be within 20% of the sleep time + //and should be greater than zero. + if ((currentPosition < ((t2-t1-5000)*1.2)) && currentPosition > 0) + return true; + else + return false; + } + + public static boolean pause(String filePath) throws Exception { + Log.v(TAG, "pause - " + filePath); + boolean misPlaying = true; + boolean pauseResult = false; + long t1=0; + long t2=0; + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.prepare(); + int duration = mp.getDuration(); + mp.start(); + t1=SystemClock.uptimeMillis(); + Thread.sleep(5000); + mp.pause(); + Thread.sleep(MediaNames.PAUSE_WAIT_TIME); + t2=SystemClock.uptimeMillis(); + misPlaying = mp.isPlaying(); + int curPosition = mp.getCurrentPosition(); + Log.v(TAG, filePath + " pause currentPositon " + curPosition); + Log.v(TAG, "isPlaying "+ misPlaying + " wait time " + (t2 - t1) ); + String cpuinfo = printCpuInfo(); + Log.v(TAG, cpuinfo); + if ((curPosition>0) && (curPosition < ((t2-t1) * 1.3)) && (misPlaying == false)) + pauseResult = true; + mp.stop(); + mp.release(); + return pauseResult; + } + + public static void prepareStopRelease(String filePath) throws Exception { + Log.v(TAG, "prepareStopRelease" + filePath); + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.prepare(); + mp.stop(); + mp.release(); + } + + public static void preparePauseRelease(String filePath) throws Exception { + Log.v(TAG, "preparePauseRelease" + filePath); + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.prepare(); + mp.pause(); + mp.release(); + } + + public static int videoHeight(String filePath) throws Exception { + Log.v(TAG, "videoHeight - " + filePath); + int videoHeight = 0; + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); + mp.prepare(); + videoHeight = mp.getVideoHeight(); + mp.release(); + return videoHeight; + } + + public static int videoWidth(String filePath) throws Exception { + Log.v(TAG, "videoWidth - " + filePath); + int videoWidth = 0; + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); + mp.prepare(); + videoWidth = mp.getVideoWidth(); + mp.release(); + return videoWidth; + } + + //This also test the streaming video which may take a long + //time to start the playback. + public static boolean videoSeekTo(String filePath) throws Exception { + Log.v(TAG, "videoSeekTo - " + filePath); + int currentPosition = 0; + int duration = 0; + boolean videoResult = false; + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); + mp.prepare(); + mp.start(); + if (filePath.equals(MediaNames.VIDEO_SHORT_3GP)){ + mp.pause(); + Thread.sleep(MediaNames.PAUSE_WAIT_TIME); + mp.seekTo(0); + mp.start(); + Thread.sleep(1000); + currentPosition = mp.getCurrentPosition(); + Log.v(TAG,"short position " + currentPosition); + if (currentPosition > 100 ) + return true; + else + return false; + } + Thread.sleep(5000); + duration = mp.getDuration(); + Log.v(TAG, "video duration " + duration); + mp.pause(); + Thread.sleep(MediaNames.PAUSE_WAIT_TIME); + mp.seekTo(duration - 20000 ); + mp.start(); + Thread.sleep(1000); + mp.pause(); + Thread.sleep(MediaNames.PAUSE_WAIT_TIME); + mp.seekTo(duration/2); + mp.start(); + Thread.sleep(10000); + currentPosition = mp.getCurrentPosition(); + Log.v(TAG, "video currentPosition " + currentPosition); + mp.release(); + if (currentPosition > (duration /2 )*0.9) + return true; + else + return false; + + } + + public static boolean seekToEnd(String filePath){ + Log.v(TAG, "seekToEnd - " + filePath); + int duration = 0; + int currentPosition = 0; + boolean isPlaying = false; + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + Log.v(TAG, "start playback"); + mp.prepare(); + duration = mp.getDuration(); + mp.seekTo(duration - 3000); + mp.start(); + Thread.sleep(6000); + }catch (Exception e){} + isPlaying = mp.isPlaying(); + currentPosition = mp.getCurrentPosition(); + Log.v(TAG, "seekToEnd currentPosition= " + currentPosition + " isPlaying = " + isPlaying); + mp.stop(); + mp.release(); + Log.v(TAG, "duration = " + duration); + if (currentPosition < 0.9 * duration || isPlaying) + return false; + else + return true; + } + + public static boolean shortMediaStop(String filePath){ + Log.v(TAG, "shortMediaStop - " + filePath); + //This test is only for the short media file + int duration = 0; + int currentPosition = 0; + boolean isPlaying = false; + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + Log.v(TAG, "start playback"); + mp.prepare(); + duration = mp.getDuration(); + mp.start(); + Thread.sleep(10000); + }catch (Exception e){} + isPlaying = mp.isPlaying(); + currentPosition = mp.getCurrentPosition(); + Log.v(TAG, "seekToEnd currentPosition= " + currentPosition + " isPlaying = " + isPlaying); + mp.stop(); + mp.release(); + Log.v(TAG, "duration = " + duration); + if (currentPosition > duration || isPlaying) + return false; + else + return true; + } + + public static boolean playToEnd(String filePath){ + Log.v(TAG, "shortMediaStop - " + filePath); + //This test is only for the short media file + int duration = 200000; + int updateDuration = 0; + int currentPosition = 0; + boolean isPlaying = false; + MediaPlayer mp = new MediaPlayer(); + try{ + Thread.sleep(5000); + mp.setDataSource(filePath); + Log.v(TAG, "start playback"); + mp.prepare(); + //duration = mp.getDuration(); + mp.start(); + Thread.sleep(50000); + }catch (Exception e){} + isPlaying = mp.isPlaying(); + currentPosition = mp.getCurrentPosition(); + //updateDuration = mp.getDuration(); + Log.v(TAG, "seekToEnd currentPosition= " + currentPosition + " isPlaying = " + isPlaying); + mp.stop(); + mp.release(); + //Log.v(TAG, "duration = " + duration); + //Log.v(TAG, "Update duration = " + updateDuration); + if (currentPosition > duration || isPlaying) + return false; + else + return true; + } + + public static boolean seektoBeforeStart(String filePath){ + Log.v(TAG, "seektoBeforeStart - " + filePath); + //This test is only for the short media file + int duration = 0; + int currentPosition = 0; + + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + mp.prepare(); + duration = mp.getDuration(); + mp.seekTo(duration - 10000); + mp.start(); + currentPosition=mp.getCurrentPosition(); + mp.stop(); + mp.release(); + }catch (Exception e){} + if (currentPosition < duration/2) + return false; + else + return true; + } + + public static boolean mediaRecorderRecord(String filePath){ + Log.v(TAG, "SoundRecording - " + filePath); + //This test is only for the short media file + int duration = 0; + try{ + MediaRecorder mRecorder = new MediaRecorder(); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + mRecorder.setOutputFile(filePath); + mRecorder.prepare(); + mRecorder.start(); + Thread.sleep(500); + mRecorder.stop(); + Log.v(TAG, "sound recorded"); + mRecorder.release(); + }catch (Exception e){ + Log.v(TAG, e.toString()); + } + + //Verify the recorded file + MediaPlayer mp = new MediaPlayer(); + try{ + mp.setDataSource(filePath); + mp.prepare(); + duration = mp.getDuration(); + Log.v(TAG,"Duration " + duration); + mp.release(); + }catch (Exception e){} + //Check the record media file length is greate than zero + if (duration > 0) + return true; + else + return false; + + } + + //Test for mediaMeta Data Thumbnail + public static boolean getThumbnail(String filePath, String goldenPath){ + Log.v(TAG, "getThumbnail - " + filePath); + + int goldenHeight = 0; + int goldenWidth = 0; + int outputWidth = 0; + int outputHeight = 0; + + //This test is only for the short media file + try{ + BitmapFactory mBitmapFactory = new BitmapFactory(); + + MediaMetadataRetriever mMediaMetadataRetriever = new MediaMetadataRetriever(); + try { + mMediaMetadataRetriever.setDataSource(filePath); + } catch(Exception e) { + e.printStackTrace(); + return false; + } + Bitmap outThumbnail = mMediaMetadataRetriever.captureFrame(); + + //Verify the thumbnail + Bitmap goldenBitmap = mBitmapFactory.decodeFile(goldenPath); + + outputWidth = outThumbnail.getWidth(); + outputHeight = outThumbnail.getHeight(); + goldenHeight = goldenBitmap.getHeight(); + goldenWidth = goldenBitmap.getWidth(); + + //check the image dimension + if ((outputWidth != goldenWidth) || (outputHeight != goldenHeight)) + return false; + + //Check one line of pixel + int x = goldenHeight/2; + for (int j=0; j<goldenWidth; j++){ + if (goldenBitmap.getPixel(x, j) != outThumbnail.getPixel(x, j)){ + Log.v(TAG, "pixel = " + goldenBitmap.getPixel(x, j)); + return false; + } + } + }catch (Exception e){} + return true; + } + + //Load midi file from resources + public static boolean resourcesPlayback(AssetFileDescriptor afd, int expectedDuration){ + int duration = 0; + try{ + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength()); + mp.prepare(); + mp.start(); + duration = mp.getDuration(); + Thread.sleep(5000); + mp.release(); + }catch (Exception e){ + Log.v(TAG,e.getMessage()); + } + if (duration > expectedDuration) + return true; + else + return false; + } + + public static boolean prepareAsyncReset(String filePath){ + //preparesAsync + try{ + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.prepareAsync(); + mp.reset(); + mp.release(); + }catch (Exception e){ + Log.v(TAG,e.getMessage()); + return false; + } + return true; + } + + + public static boolean isLooping(String filePath) { + MediaPlayer mp = null; + + try { + mp = new MediaPlayer(); + if (mp.isLooping()) { + Log.v(TAG, "MediaPlayer.isLooping() returned true after ctor"); + return false; + } + mp.setDataSource(filePath); + mp.prepare(); + + mp.setLooping(true); + if (!mp.isLooping()) { + Log.v(TAG, "MediaPlayer.isLooping() returned false after setLooping(true)"); + return false; + } + + mp.setLooping(false); + if (mp.isLooping()) { + Log.v(TAG, "MediaPlayer.isLooping() returned true after setLooping(false)"); + return false; + } + }catch (Exception e){ + Log.v(TAG, "Exception : " + e.toString()); + return false; + } finally { + if (mp != null) + mp.release(); + } + + return true; + } + + public static boolean isLoopingAfterReset(String filePath) { + MediaPlayer mp = null; + try { + mp = new MediaPlayer(); + mp.setDataSource(filePath); + mp.prepare(); + + mp.setLooping(true); + mp.reset(); + if (mp.isLooping()) { + Log.v(TAG, "MediaPlayer.isLooping() returned true after reset()"); + return false; + } + }catch (Exception e){ + Log.v(TAG, "Exception : " + e.toString()); + return false; + } finally { + if (mp != null) + mp.release(); + } + + return true; + } +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java new file mode 100644 index 0000000..24edb65 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaAudioTrackTest.java @@ -0,0 +1,897 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mediaframeworktest.functional; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import android.media.AudioFormat; +import android.media.AudioManager; +import android.media.AudioTrack; +import android.content.Context; +import android.test.ActivityInstrumentationTestCase2; +import android.util.Log; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; + +/** + * Junit / Instrumentation test case for the media AudioTrack api + + */ +public class MediaAudioTrackTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { + private String TAG = "MediaAudioTrackTest"; + + public MediaAudioTrackTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + private static void assumeTrue(String message, boolean cond) { + assertTrue("(assume)"+message, cond); + } + + private void log(String testName, String message) { + Log.v(TAG, "["+testName+"] "+message); + } + + private void loge(String testName, String message) { + Log.e(TAG, "["+testName+"] "+message); + } + + //----------------------------------------------------------------- + // private class to hold test reslts + public class TestResults { + public boolean mResult = false; + public String mResultLog = ""; + public TestResults(boolean b, String s) { mResult = b; mResultLog = s; } + } + + //----------------------------------------------------------------- + // generic test methods + public TestResults constructorTestMultiSampleRate( + // parameters tested by this method + int _inTest_streamType, int _inTest_mode, + int _inTest_config, int _inTest_format, + // parameter-dependent expected results + int _expected_stateForMode) { + + int[] testSampleRates = {8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000}; + String failedRates = "Failure for rate(s): "; + boolean localRes, finalRes = true; + + for (int i = 0 ; i < testSampleRates.length ; i++) { + //Log.v("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] testing "+ testSampleRates[i]); + AudioTrack track = null; + try { + track = new AudioTrack( + _inTest_streamType, + testSampleRates[i], + _inTest_config, + _inTest_format, + AudioTrack.getMinBufferSize(testSampleRates[i], + _inTest_config, _inTest_format), + _inTest_mode); + } catch(IllegalArgumentException iae) { + Log.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] exception at SR " + + testSampleRates[i]+": \n" + iae); + localRes = false; + } + if (track != null) { + localRes = (track.getState() == _expected_stateForMode); + track.release(); + } + else { + localRes = false; + } + + if (!localRes) { + //log the error for the test runner + failedRates += Integer.toString(testSampleRates[i]) + "Hz "; + //log the error for logcat + log("constructorTestMultiSampleRate", "failed to construct " + +"AudioTrack(streamType="+_inTest_streamType + +", sampleRateInHz=" + testSampleRates[i] + +", channelConfig=" + _inTest_config + +", audioFormat=" + _inTest_format + +", bufferSizeInBytes=" + AudioTrack.getMinBufferSize(testSampleRates[i], + _inTest_config, AudioFormat.ENCODING_PCM_16BIT) + +", mode="+ _inTest_mode ); + //mark test as failed + finalRes = false; + } + } + return new TestResults(finalRes, failedRates); + } + + //----------------------------------------------------------------- + // AUDIOTRACK TESTS: + //---------------------------------- + + //----------------------------------------------------------------- + // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 16bit PCM + //---------------------------------- + + //Test case 1: constructor for streaming AudioTrack, mono, 16bit at misc valid sample rates + @LargeTest + public void testConstructorMono16MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorMono16MusicStream: " + res.mResultLog, res.mResult); + } + + + //Test case 2: constructor for streaming AudioTrack, stereo, 16bit at misc valid sample rates + @LargeTest + public void testConstructorStereo16MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorStereo16MusicStream: " + res.mResultLog, res.mResult); + } + + + //Test case 3: constructor for static AudioTrack, mono, 16bit at misc valid sample rates + @LargeTest + public void testConstructorMono16MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorMono16MusicStatic: " + res.mResultLog, res.mResult); + } + + + //Test case 4: constructor for static AudioTrack, stereo, 16bit at misc valid sample rates + @LargeTest + public void testConstructorStereo16MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorStereo16MusicStatic: " + res.mResultLog, res.mResult); + } + + + //----------------------------------------------------------------- + // AudioTrack constructor and AudioTrack.getMinBufferSize(...) for 8bit PCM + //---------------------------------- + + //Test case 1: constructor for streaming AudioTrack, mono, 8bit at misc valid sample rates + @LargeTest + public void testConstructorMono8MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorMono8MusicStream: " + res.mResultLog, res.mResult); + } + + //Test case 2: constructor for streaming AudioTrack, stereo, 8bit at misc valid sample rates + @LargeTest + public void testConstructorStereo8MusicStream() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STREAM, + AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_INITIALIZED); + + assertTrue("testConstructorStereo8MusicStream: " + res.mResultLog, res.mResult); + } + + //Test case 3: constructor for static AudioTrack, mono, 8bit at misc valid sample rates + @LargeTest + public void testConstructorMono8MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorMono8MusicStatic: " + res.mResultLog, res.mResult); + } + + //Test case 4: constructor for static AudioTrack, stereo, 8bit at misc valid sample rates + @LargeTest + public void testConstructorStereo8MusicStatic() throws Exception { + + TestResults res = constructorTestMultiSampleRate( + AudioManager.STREAM_MUSIC, AudioTrack.MODE_STATIC, + AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_8BIT, + AudioTrack.STATE_NO_STATIC_DATA); + + assertTrue("testConstructorStereo8MusicStatic: " + res.mResultLog, res.mResult); + } + + + //----------------------------------------------------------------- + // AudioTrack constructor for all stream types + //---------------------------------- + + //Test case 1: constructor for all stream types + @LargeTest + public void testConstructorStreamType() throws Exception { + // constants for test + final int TYPE_TEST_SR = 22050; + final int TYPE_TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TYPE_TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TYPE_TEST_MODE = AudioTrack.MODE_STREAM; + final int[] STREAM_TYPES = { AudioManager.STREAM_ALARM, AudioManager.STREAM_BLUETOOTH_SCO, + AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION, + AudioManager.STREAM_RING, AudioManager.STREAM_SYSTEM, + AudioManager.STREAM_VOICE_CALL }; + final String[] STREAM_NAMES = { "STREAM_ALARM", "STREAM_BLUETOOTH_SCO", "STREAM_MUSIC", + "STREAM_NOTIFICATION", "STREAM_RING", "STREAM_SYSTEM", "STREAM_VOICE_CALL" }; + + boolean localTestRes = true; + AudioTrack track = null; + // test: loop constructor on all stream types + for (int i = 0 ; i < STREAM_TYPES.length ; i++) + { + try { + //-------- initialization -------------- + track = new AudioTrack(STREAM_TYPES[i], + TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT, + AudioTrack.getMinBufferSize(TYPE_TEST_SR, TYPE_TEST_CONF, TYPE_TEST_FORMAT), + TYPE_TEST_MODE); + } catch (IllegalArgumentException iae) { + loge("testConstructorStreamType", "exception for stream type " + + STREAM_NAMES[i] + ": "+ iae); + localTestRes = false; + } + //-------- test -------------- + if (track != null) { + if (track.getState() != AudioTrack.STATE_INITIALIZED) { + localTestRes = false; + Log.e("MediaAudioTrackTest", + "[ testConstructorStreamType ] failed for stream type "+STREAM_NAMES[i]); + } + //-------- tear down -------------- + track.release(); + } + else { + localTestRes = false; + } + } + + assertTrue("testConstructorStreamType", localTestRes); + } + + + //----------------------------------------------------------------- + // Playback head position + //---------------------------------- + + //Test case 1: getPlaybackHeadPosition() at 0 after initialization + @LargeTest + public void testPlaybackHeadPositionAfterInit() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterInit"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT), TEST_MODE); + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 2: getPlaybackHeadPosition() increases after play() + @LargeTest + public void testPlaybackHeadPositionIncrease() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionIncrease"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition()); + assertTrue(TEST_NAME, track.getPlaybackHeadPosition() > 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: getPlaybackHeadPosition() is 0 after flush(); + @LargeTest + public void testPlaybackHeadPositionAfterFlush() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterFlush"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + track.stop(); + track.flush(); + log(TEST_NAME, "position ="+ track.getPlaybackHeadPosition()); + assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: getPlaybackHeadPosition() is 0 after stop(); + @LargeTest + public void testPlaybackHeadPositionAfterStop() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterStop"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + track.stop(); + Thread.sleep(100); // TODO: what is a sensible value? + int pos = track.getPlaybackHeadPosition(); + log(TEST_NAME, "position ="+ pos); + assertTrue(TEST_NAME, pos == 0); + //-------- tear down -------------- + track.release(); + } + + //Test case 4: getPlaybackHeadPosition() is > 0 after play(); pause(); + @LargeTest + public void testPlaybackHeadPositionAfterPause() throws Exception { + // constants for test + final String TEST_NAME = "testPlaybackHeadPositionAfterPause"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + Thread.sleep(100); + track.pause(); + int pos = track.getPlaybackHeadPosition(); + log(TEST_NAME, "position ="+ pos); + assertTrue(TEST_NAME, pos > 0); + //-------- tear down -------------- + track.release(); + } + + + //----------------------------------------------------------------- + // Playback properties + //---------------------------------- + + //Test case 1: setStereoVolume() with max volume returns SUCCESS + @LargeTest + public void testSetStereoVolumeMax() throws Exception { + // constants for test + final String TEST_NAME = "testSetStereoVolumeMax"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + float maxVol = AudioTrack.getMaxVolume(); + assertTrue(TEST_NAME, track.setStereoVolume(maxVol, maxVol) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 2: setStereoVolume() with min volume returns SUCCESS + @LargeTest + public void testSetStereoVolumeMin() throws Exception { + // constants for test + final String TEST_NAME = "testSetStereoVolumeMin"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + float minVol = AudioTrack.getMinVolume(); + assertTrue(TEST_NAME, track.setStereoVolume(minVol, minVol) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: setStereoVolume() with mid volume returns SUCCESS + @LargeTest + public void testSetStereoVolumeMid() throws Exception { + // constants for test + final String TEST_NAME = "testSetStereoVolumeMid"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + float midVol = (AudioTrack.getMaxVolume() - AudioTrack.getMinVolume()) / 2; + assertTrue(TEST_NAME, track.setStereoVolume(midVol, midVol) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 4: setPlaybackRate() with half the content rate returns SUCCESS + @LargeTest + public void testSetPlaybackRate() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRate"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.play(); + assertTrue(TEST_NAME, track.setPlaybackRate((int)(TEST_SR/2)) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 5: setPlaybackRate(0) returns bad value error + @LargeTest + public void testSetPlaybackRateZero() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRateZero"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setPlaybackRate(0) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 6: setPlaybackRate() accepts values twice the output sample rate + @LargeTest + public void testSetPlaybackRateTwiceOutputSR() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRateTwiceOutputSR"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE); + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.play(); + assertTrue(TEST_NAME, track.setPlaybackRate(2*outputSR) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } +/* + //Test case 7: setPlaybackRate() clips values over twice the output sample rate + @LargeTest + public void testSetPlaybackRateClip() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRateClip"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize/2]; + int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE); + //-------- test -------------- + track.write(data, 0, data.length); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.play(); + track.setPlaybackRate(3*outputSR); + assertTrue(TEST_NAME, track.getSampleRate() == 2*outputSR); + //-------- tear down -------------- + track.release(); + } +*/ + //Test case 8: setPlaybackRate() invalid operation if track not initialized + @LargeTest + public void testSetPlaybackRateUninit() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackRateUninit"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); + assertTrue(TEST_NAME, track.setPlaybackRate(TEST_SR/2) == AudioTrack.ERROR_INVALID_OPERATION); + //-------- tear down -------------- + track.release(); + } + + //----------------------------------------------------------------- + // Playback progress + //---------------------------------- + + //Test case 1: setPlaybackHeadPosition() on playing track + @LargeTest + public void testSetPlaybackHeadPositionPlaying() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionPlaying"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + assertTrue(TEST_NAME, + track.setPlaybackHeadPosition(10) == AudioTrack.ERROR_INVALID_OPERATION); + //-------- tear down -------------- + track.release(); + } + + //Test case 2: setPlaybackHeadPosition() on stopped track + @LargeTest + public void testSetPlaybackHeadPositionStopped() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionStopped"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + track.stop(); + assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED); + assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 3: setPlaybackHeadPosition() on paused track + @LargeTest + public void testSetPlaybackHeadPositionPaused() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionPaused"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + track.pause(); + assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_PAUSED); + assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 4: setPlaybackHeadPosition() beyond what has been written + @LargeTest + public void testSetPlaybackHeadPositionTooFar() throws Exception { + // constants for test + final String TEST_NAME = "testSetPlaybackHeadPositionTooFar"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + // make up a frame index that's beyond what has been written: go from buffer size to frame + // count (given the audio track properties), and add 77. + int frameIndexTooFar = (2*minBuffSize/2) + 77; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + track.write(data, 0, data.length); + track.write(data, 0, data.length); + track.play(); + track.stop(); + assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED); + assertTrue(TEST_NAME, track.setPlaybackHeadPosition(frameIndexTooFar) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + + //Test case 5: setLoopPoints() fails for MODE_STREAM + @LargeTest + public void testSetLoopPointsStream() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsStream"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STREAM; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + 2*minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setLoopPoints(2, 50, 2) == AudioTrack.ERROR_INVALID_OPERATION); + //-------- tear down -------------- + track.release(); + } + + //Test case 6: setLoopPoints() fails start > end + @LargeTest + public void testSetLoopPointsStartAfterEnd() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsStartAfterEnd"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setLoopPoints(50, 0, 2) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } + + //Test case 6: setLoopPoints() success + @LargeTest + public void testSetLoopPointsSuccess() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsSuccess"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + //-------- test -------------- + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, track.setLoopPoints(0, 50, 2) == AudioTrack.SUCCESS); + //-------- tear down -------------- + track.release(); + } + + //Test case 7: setLoopPoints() fails with loop length bigger than content + @LargeTest + public void testSetLoopPointsLoopTooLong() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsLoopTooLong"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + int dataSizeInFrames = minBuffSize/2; + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.setLoopPoints(10, dataSizeInFrames+20, 2) == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } +/* + //Test case 7: setLoopPoints() fails with start beyond what can be written for the track + @LargeTest + public void testSetLoopPointsStartTooFar() throws Exception { + // constants for test + final String TEST_NAME = "testSetLoopPointsStartTooFar"; + final int TEST_SR = 22050; + final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO; + final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT; + final int TEST_MODE = AudioTrack.MODE_STATIC; + final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC; + + //-------- initialization -------------- + int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT); + AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, + minBuffSize, TEST_MODE); + byte data[] = new byte[minBuffSize]; + int dataSizeInFrames = minBuffSize/2;//16bit data + //-------- test -------------- + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA); + track.write(data, 0, data.length); + assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED); + assertTrue(TEST_NAME, + track.setLoopPoints(dataSizeInFrames+20, dataSizeInFrames+50, 2) + == AudioTrack.ERROR_BAD_VALUE); + //-------- tear down -------------- + track.release(); + } +*/ + +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMetadataTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMetadataTest.java new file mode 100644 index 0000000..364e1af --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaMetadataTest.java @@ -0,0 +1,255 @@ +/* + * 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.functional; + +import android.media.MediaMetadataRetriever; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.util.Log; + +import com.android.mediaframeworktest.MediaNames; +/** + * This metadata test suite test the basic functionality of the + * MediaMetadataRetriever + * + */ +public class MediaMetadataTest extends AndroidTestCase { + + private static final String TAG = "MediaMetadataTest"; + + public static enum METADATA_EXPECTEDRESULT{ + FILE_PATH,CD_TRACK, ALBUM, + ARTIST, AUTHOR, COMPOSER, + DATE, GENRE, TITLE, + YEAR, DURATION, NUM_TRACKS + } + + public static enum MP3_TEST_FILE{ + ID3V1V2, ID3V2, ID3V1, + CORRUPTED_ID3V1, CORRUPTED_ID3V2_TALB, CORRUPTED_ID3V2_TCOM, + CORRUPTED_ID3V2_TCOM_2, CORRUPTED_ID3V2_TRCK, CORRUPTED_D3V2_TRCK_2, + CORRUPTED_ID3V2_TYER, CORRUPTED_ID3V2_TYER_2, CORRUPTED_ID3V2_TIT + } + + public static enum NON_MP3_TEST_FILE{ + THREE3GP, AMRNB, AMRWB, M4A1, M4V, MIDI, + H264, OGG1, OGG2, WAV, WMA9, WMA10, WMV9, WMV7 + } + + public static METADATA_EXPECTEDRESULT meta; + public static MP3_TEST_FILE mp3_test_file; + public static NON_MP3_TEST_FILE non_mp3_test_file; + + @MediumTest + public static void testID3V1V2Metadata() throws Exception { + validateMetatData(mp3_test_file.ID3V1V2.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testID3V2Metadata() throws Exception { + validateMetatData(mp3_test_file.ID3V2.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testID3V1Metadata() throws Exception { + validateMetatData(mp3_test_file.ID3V1.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorruptedID3V1Metadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V1.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TALBMetadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TALB.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TCOMMetadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TCOM.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TCOMM2etadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TCOM_2.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TRCKMetadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TRCK.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TRCK2Metadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_D3V2_TRCK_2.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TYERMetadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TYER.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TYER2Metadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TYER_2.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void testCorrupted_ID3V2_TITMetadata() throws Exception { + validateMetatData(mp3_test_file.CORRUPTED_ID3V2_TIT.ordinal(), MediaNames.META_DATA_MP3); + } + + @MediumTest + public static void test3gp_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.THREE3GP.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testAmr_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.AMRNB.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testAmrWb_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.AMRWB.ordinal(), MediaNames.META_DATA_OTHERS); + } + + //Bug# 1440173 - skip this test case now + @Suppress + @MediumTest + public static void testM4A1_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.M4A1.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testM4v_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.M4V.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testH264_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.H264.ordinal(), MediaNames.META_DATA_OTHERS); + } + //bug# 1440489 + @Suppress + @MediumTest + public static void testOgg1_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.OGG1.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @Suppress + @MediumTest + public static void testOgg2_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.OGG2.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @Suppress + @MediumTest + public static void testMidi_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.MIDI.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testWav_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.WAV.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testWma9_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.WMA9.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testWma10_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.WMA10.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testWmv9_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.WMV9.ordinal(), MediaNames.META_DATA_OTHERS); + } + + @MediumTest + public static void testWmv10_Metadata() throws Exception { + validateMetatData(non_mp3_test_file.WMV7.ordinal(), MediaNames.META_DATA_OTHERS); + } + + private static void validateMetatData(int fileIndex, String meta_data_file[][]) { + String value = null; + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); + try { + retriever.setDataSource(meta_data_file[fileIndex][0]); + Log.v(TAG, "filePath = "+ meta_data_file[fileIndex][0]); + } catch(Exception e) { + Log.v(TAG, "Failed: "+meta_data_file[fileIndex][0] + " " + e.toString()); + //Set the test case failure whenever it failed to setDataSource + assertTrue("Failed to setDataSource ", false); + } + + //METADATA_KEY_CD_TRACK_NUMBER should return the TCRK value + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER); + Log.v(TAG, "CD_TRACK_NUMBER : " + value); + assertEquals(TAG, meta_data_file[fileIndex][meta.CD_TRACK.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); + Log.v(TAG, "Album : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.ALBUM.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); + Log.v(TAG, "Artist : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.ARTIST.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_AUTHOR); + Log.v(TAG, "Author : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.AUTHOR.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER); + Log.v(TAG, "Composer : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.COMPOSER.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE); + Log.v(TAG, "Date : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.DATE.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE); + Log.v(TAG, "Genre : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.GENRE.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); + Log.v(TAG, "Title : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.TITLE.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); + Log.v(TAG, "Year : "+ value); + assertEquals(TAG, meta_data_file[fileIndex][meta.YEAR.ordinal()], value); + + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + Log.v(TAG, "Expected = " + meta_data_file[fileIndex][meta.DURATION.ordinal()] + "reult = " + value); + assertEquals(TAG, meta_data_file[fileIndex][meta.DURATION.ordinal()], value); + + //METADATA_KEY_NUM_TRACKS should return the total number of tracks in the media + //include the video and audio + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS); + Log.v(TAG, "Track : "+ value); + assertEquals(TAG,meta_data_file[fileIndex][meta.NUM_TRACKS.ordinal()], value); + + retriever.release(); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java new file mode 100644 index 0000000..dd94164 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaPlayerApiTest.java @@ -0,0 +1,433 @@ +/* + * 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.functional; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import android.content.Context; +import android.test.ActivityInstrumentationTestCase; +import android.util.Log; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; + +/** + * Junit / Instrumentation test case for the media player api + + */ +public class MediaPlayerApiTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> { + private boolean duratoinWithinTolerence = false; + private String TAG = "MediaPlayerApiTest"; + + Context mContext; + + public MediaPlayerApiTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + protected void setUp() throws Exception { + super.setUp(); + + } + + public boolean verifyDuration(int duration, int expectedDuration){ + if ((duration > expectedDuration * 1.1) || (duration < expectedDuration * 0.9)) + return false; + else + return true; + } + + + //Audio + //Wait for PV bugs for MP3 duration + @MediumTest + public void testMP3CBRGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.MP3CBR); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3CBR_LENGTH); + assertTrue("MP3CBR getDuration", duratoinWithinTolerence); + } + + @MediumTest + public void testMP3VBRGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.MP3VBR); + Log.v(TAG, "getDuration"); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3VBR_LENGTH); + assertTrue("MP3VBR getDuration", duratoinWithinTolerence); + } + + @MediumTest + public void testMIDIGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.MIDI); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.MIDI_LENGTH); + assertTrue("MIDI getDuration", duratoinWithinTolerence); + } + + @MediumTest + public void testWMA9GetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.WMA9); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.WMA9_LENGTH); + assertTrue("WMA9 getDuration", duratoinWithinTolerence); + } + + @MediumTest + public void testAMRGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.AMR); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.AMR_LENGTH); + assertTrue("AMR getDuration", duratoinWithinTolerence); + } + + /* + public void testOGGGetDuration() throws Exception { + int duration = CodecTest.getDuration(MediaNames.OGG); + duratoinWithinTolerence = verifyDuration(duration, MediaNames.OGG_LENGTH); + assertTrue("OGG getDuration", duratoinWithinTolerence); + }*/ + + + //Test cases for GetCurrentPosition + @LargeTest + public void testMP3CBRGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3CBR); + assertTrue("MP3CBR GetCurrentPosition", currentPosition); + } + + @LargeTest + public void testMP3VBRGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3VBR); + assertTrue("MP3VBR GetCurrentPosition", currentPosition); + } + + @LargeTest + public void testMIDIGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MIDI); + assertTrue("MIDI GetCurrentPosition", currentPosition); + } + + @LargeTest + public void testWMA9GetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.WMA9); + assertTrue("WMA9 GetCurrentPosition", currentPosition); + } + + @LargeTest + public void testAMRGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.AMR); + assertTrue("AMR GetCurrentPosition", currentPosition); + } + + /* + public void testOGGGetCurrentPosition() throws Exception { + boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.OGG); + assertTrue("OGG GetCurrentPosition", currentPosition); + */ + + //Test cases for pause + @LargeTest + public void testMP3CBRPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.MP3CBR); + assertTrue("MP3CBR Pause", isPaused); + } + + @LargeTest + public void testMP3VBRPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.MP3VBR); + assertTrue("MP3VBR Pause", isPaused); + } + + @LargeTest + public void testMIDIPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.MIDI); + assertTrue("MIDI Pause", isPaused); + } + + @LargeTest + public void testWMA9Pause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.WMA9); + assertTrue("WMA9 Pause", isPaused); + } + + @LargeTest + public void testAMRPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.AMR); + assertTrue("AMR Pause", isPaused); + } + + /* + public void testOGGPause() throws Exception { + boolean isPaused = CodecTest.pause(MediaNames.OGG); + assertTrue("OGG Pause", isPaused); + }*/ + + @MediumTest + public void testMP3CBRPrepareStopRelease() throws Exception { + CodecTest.prepareStopRelease(MediaNames.MP3CBR); + assertTrue("MP3CBR prepareStopRelease", true); + } + + @MediumTest + public void testMIDIPrepareStopRelease() throws Exception { + CodecTest.prepareStopRelease(MediaNames.MIDI); + assertTrue("MIDI prepareStopRelease", true); + } + + //One test case for seek before start + @MediumTest + public void testMP3CBRSeekBeforeStart() throws Exception { + boolean seekBeforePlay = CodecTest.seektoBeforeStart(MediaNames.MP3CBR); + assertTrue("MP3CBR SeekBeforePlay", seekBeforePlay); + } + + //Skip test - Bug# 1120249 + /* + public void testMP3CBRpreparePauseRelease() throws Exception { + CodecTest.preparePauseRelease(MediaNames.MP3CBR); + assertTrue("MP3CBR preparePauseRelease", true); + } + + public void testMIDIpreparePauseRelease() throws Exception { + CodecTest.preparePauseRelease(MediaNames.MIDI); + assertTrue("MIDI preparePauseRelease", true); + } + */ + + + //Test cases for setLooping + @LargeTest + public void testMP3CBRSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.MP3CBR); + assertTrue("MP3CBR setLooping", isLoop); + } + + @LargeTest + public void testMP3VBRSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.MP3VBR); + Log.v(TAG, "setLooping"); + assertTrue("MP3VBR setLooping", isLoop); + } + + @LargeTest + public void testMIDISetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.MIDI); + assertTrue("MIDI setLooping", isLoop); + } + + @LargeTest + public void testWMA9SetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.WMA9); + assertTrue("WMA9 setLooping", isLoop); + } + + @LargeTest + public void testAMRSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.AMR); + assertTrue("AMR setLooping", isLoop); + } + + /* + public void testOGGSetLooping() throws Exception { + boolean isLoop = CodecTest.setLooping(MediaNames.OGG); + assertTrue("OGG setLooping", isLoop); + } */ + + //Test cases for seekTo + @LargeTest + public void testMP3CBRSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.MP3CBR); + assertTrue("MP3CBR seekTo", isLoop); + } + + @LargeTest + public void testMP3VBRSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.MP3VBR); + Log.v(TAG, "seekTo"); + assertTrue("MP3VBR seekTo", isLoop); + } + + @LargeTest + public void testMIDISeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.MIDI); + assertTrue("MIDI seekTo", isLoop); + } + + @LargeTest + public void testWMA9SeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.WMA9); + assertTrue("WMA9 seekTo", isLoop); + } + + @LargeTest + public void testAMRSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.AMR); + assertTrue("AMR seekTo", isLoop); + } + + /* + public void testOGGSeekTo() throws Exception { + boolean isLoop = CodecTest.seekTo(MediaNames.OGG); + assertTrue("OGG seekTo", isLoop); + }*/ + + + //Jump to the end of the files + @LargeTest + public void testMP3CBRSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3CBR); + assertTrue("MP3CBR seekToEnd", isEnd); + } + + @LargeTest + public void testMP3VBRSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3VBR); + Log.v(TAG, "seekTo"); + assertTrue("MP3VBR seekToEnd", isEnd); + } + + @LargeTest + public void testMIDISeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.MIDI); + assertTrue("MIDI seekToEnd", isEnd); + } + + @LargeTest + public void testWMA9SeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.WMA9); + assertTrue("WMA9 seekToEnd", isEnd); + } + + @LargeTest + public void testAMRSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.AMR); + assertTrue("AMR seekToEnd", isEnd); + } + + /* + public void testOGGSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.OGG); + assertTrue("OGG seekToEnd", isEnd); + }*/ + + @LargeTest + public void testWAVSeekToEnd() throws Exception { + boolean isEnd = CodecTest.seekToEnd(MediaNames.WAV); + assertTrue("WAV seekToEnd", isEnd); + } + + @MediumTest + public void testLargeVideoHeigth() throws Exception { + int height = 0; + height = CodecTest.videoHeight(MediaNames.VIDEO_LARGE_SIZE_3GP); + Log.v(TAG, "Video height = " + height); + assertEquals("streaming video height", 240, height); + } + + @MediumTest + public void testLargeVideoWidth() throws Exception { + int width = 0; + width = CodecTest.videoWidth(MediaNames.VIDEO_LARGE_SIZE_3GP); + Log.v(TAG, "Video width = " + width); + assertEquals("streaming video width", 320, width); + } + + @LargeTest + public void testVideoMP4SeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_MP4); + assertTrue("Local MP4 SeekTo", isSeek); + } + + @LargeTest + public void testVideoLong3gpSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_LONG_3GP); + assertTrue("Local 3gp SeekTo", isSeek); + } + + @LargeTest + public void testVideoH263AACSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AAC); + assertTrue("H263AAC SeekTo", isSeek); + } + + @LargeTest + public void testVideoH263AMRSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AMR); + assertTrue("H263AMR SeekTo", isSeek); + } + + @LargeTest + public void testVideoH264AACSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AAC); + assertTrue("H264AAC SeekTo", isSeek); + } + + @LargeTest + public void testVideoH264AMRSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AMR); + assertTrue("H264AMR SeekTo", isSeek); + } + + @LargeTest + public void testVideoWMVSeekTo() throws Exception { + boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WMV); + assertTrue("WMV SeekTo", isSeek); + } + + @LargeTest + public void testSoundRecord() throws Exception { + boolean isRecordered = CodecTest.mediaRecorderRecord(MediaNames.RECORDER_OUTPUT); + assertTrue("Recorder", isRecordered); + } + + @LargeTest + public void testGetThumbnail() throws Exception { + boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT); + assertTrue("Get Thumbnail", getThumbnail); + } + + //Play a mid file which the duration is around 210 seconds + @LargeTest + public void testMidiResources() throws Exception { + boolean midiResources = CodecTest.resourcesPlayback(MediaFrameworkTest.midiafd,180000); + assertTrue("Play midi from resources", midiResources); + } + + @LargeTest + public void testMp3Resources() throws Exception { + boolean mp3Resources = CodecTest.resourcesPlayback(MediaFrameworkTest.mp3afd,25000); + assertTrue("Play mp3 from resources", mp3Resources); + } + + //Bug# 1422662 + @Suppress + @MediumTest + public void testPrepareAsyncReset() throws Exception { + boolean isReset = CodecTest.prepareAsyncReset(MediaNames.STREAM_LARGE_MP3); + assertTrue("PrepareAsync Reset", isReset); + } + + @MediumTest + public void testIsLooping() throws Exception { + boolean isLooping = CodecTest.isLooping(MediaNames.AMR); + assertTrue("isLooping", isLooping); + } + + @MediumTest + public void testIsLoopingAfterReset() throws Exception { + boolean isLooping = CodecTest.isLoopingAfterReset(MediaNames.AMR); + assertTrue("isLooping after reset", isLooping); + } +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java new file mode 100644 index 0000000..65451c5 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java @@ -0,0 +1,339 @@ +/* + * 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.functional; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import java.io.*; + +import android.content.Context; +import android.media.MediaPlayer; +import android.media.MediaRecorder; +import android.test.ActivityInstrumentationTestCase; +import android.util.Log; +import android.view.SurfaceHolder; +import android.view.SurfaceView; + + +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.Suppress; + + +/** + * Junit / Instrumentation test case for the media recorder api + */ +public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> { + private String TAG = "MediaRecorderTest"; + private int mOutputDuration =0; + private int mOutputVideoWidth = 0; + private int mOutputVideoHeight= 0 ; + + private SurfaceHolder mSurfaceHolder = null; + private MediaRecorder mRecorder; + Context mContext; + + public MediaRecorderTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + + } + + protected void setUp() throws Exception { + super.setUp(); + Log.v(TAG,"create the media recorder"); + mRecorder = new MediaRecorder(); + } + + private void recordVideo(int frameRate, int width, int height, + int videoFormat, int outFormat, String outFile, boolean videoOnly) { + Log.v(TAG,"startPreviewAndPrepareRecording"); + try { + if (!videoOnly) { + Log.v(TAG, "setAudioSource"); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + } + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setOutputFormat(outFormat); + Log.v(TAG, "output format " + outFormat); + mRecorder.setOutputFile(outFile); + mRecorder.setVideoFrameRate(frameRate); + mRecorder.setVideoSize(width, height); + Log.v(TAG, "setEncoder"); + mRecorder.setVideoEncoder(videoFormat); + if (!videoOnly) { + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + } + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + Log.v(TAG, "setPreview"); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + Log.v(TAG, "prepare"); + mRecorder.prepare(); + Log.v(TAG, "start"); + mRecorder.start(); + Thread.sleep(MediaNames.RECORDED_TIME); + Log.v(TAG, "stop"); + mRecorder.stop(); + mRecorder.release(); + } catch (Exception e) { + Log.v("record video failed ", e.toString()); + mRecorder.release(); + } + } + + + private boolean invalidRecordSetting(int frameRate, int width, int height, + int videoFormat, int outFormat, String outFile, boolean videoOnly) { + try { + if (!videoOnly) { + Log.v(TAG, "setAudioSource"); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + } + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setOutputFormat(outFormat); + Log.v(TAG, "output format " + outFormat); + mRecorder.setOutputFile(outFile); + mRecorder.setVideoFrameRate(frameRate); + mRecorder.setVideoSize(width, height); + Log.v(TAG, "setEncoder"); + mRecorder.setVideoEncoder(videoFormat); + if (!videoOnly) { + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + } + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + Log.v(TAG, "setPreview"); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + Log.v(TAG, "prepare"); + mRecorder.prepare(); + Log.v(TAG, "start"); + mRecorder.start(); + Thread.sleep(MediaNames.RECORDED_TIME); + Log.v(TAG, "stop"); + mRecorder.stop(); + mRecorder.release(); + } catch (Exception e) { + Log.v("record video failed ", e.toString()); + mRecorder.release(); + Log.v(TAG, "reset and release"); + return true; + } + return false; + } + + + + private void getOutputVideoProperty(String outputFilePath) { + MediaPlayer mediaPlayer = new MediaPlayer(); + try { + mediaPlayer.setDataSource(outputFilePath); + Log.v(TAG, "file Path = " + outputFilePath); + mediaPlayer.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); + Log.v(TAG, "before player prepare"); + mediaPlayer.prepare(); + Log.v(TAG, "before getduration"); + mOutputDuration = mediaPlayer.getDuration(); + Log.v(TAG, "get video dimension"); + mOutputVideoHeight = mediaPlayer.getVideoHeight(); + mOutputVideoWidth = mediaPlayer.getVideoWidth(); + mediaPlayer.release(); + } catch (Exception e) { + Log.v(TAG, e.toString()); + mediaPlayer.release(); + } + } + + private void removeFile(String filePath) { + File fileRemove = new File(filePath); + fileRemove.delete(); + } + + private boolean validateVideo(String filePath, int width, int height) { + boolean validVideo = false; + getOutputVideoProperty(filePath); + if (mOutputVideoWidth == width && mOutputVideoHeight == height && + mOutputDuration > MediaNames.VALID_VIDEO_DURATION ) { + validVideo = true; + } + Log.v(TAG, "width = " + mOutputVideoWidth + " height = " + mOutputVideoHeight + " Duration = " + mOutputDuration); + removeFile(filePath); + return validVideo; + } + + + //Format: HVGA h263 + @Suppress + public void testHVGAH263() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 480, 320, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_HVGA_H263, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_HVGA_H263, 480, 320); + assertTrue("HVGAH263", videoRecordedResult); + } + + //Format: QVGA h263 + @LargeTest + public void testQVGAH263() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 320, 240, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_QVGA_H263, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_QVGA_H263, 320, 240); + assertTrue("QVGAH263", videoRecordedResult); + } + + //Format: SQVGA h263 + @LargeTest + public void testSQVGAH263() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 240, 160, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_SQVGA_H263, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_SQVGA_H263, 240, 160); + assertTrue("SQVGAH263", videoRecordedResult); + } + + //Format: QCIF h263 + @LargeTest + public void testQCIFH263() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 176, 144, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_QCIF_H263, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_QCIF_H263, 176, 144); + assertTrue("QCIFH263", videoRecordedResult); + } + + //Format: CIF h263 + @LargeTest + public void testCIFH263() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 352, 288, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_CIF_H263, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_CIF_H263, 352, 288); + assertTrue("CIFH263", videoRecordedResult); + } + + + + @LargeTest + public void testVideoOnly() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 176, 144, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true); + videoRecordedResult = validateVideo(MediaNames.RECORDED_VIDEO_3GP, 176, 144); + assertTrue("QCIFH263 Video Only", videoRecordedResult); + } + + @Suppress + public void testPortraitH263() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 144, 176, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true); + videoRecordedResult = validateVideo(MediaNames.RECORDED_VIDEO_3GP, 144, 176); + assertTrue("PortraitH263", videoRecordedResult); + } + + @Suppress + public void testHVGAMP4() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 480, 320, MediaRecorder.VideoEncoder.MPEG_4_SP, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_HVGA_MP4, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_HVGA_MP4, 480, 320); + assertTrue("HVGAMP4", videoRecordedResult); + } + + @LargeTest + public void testQVGAMP4() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 320, 240, MediaRecorder.VideoEncoder.MPEG_4_SP, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_QVGA_MP4, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_QVGA_MP4, 320, 240); + assertTrue("QVGAMP4", videoRecordedResult); + } + + @LargeTest + public void testSQVGAMP4() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 240, 160, MediaRecorder.VideoEncoder.MPEG_4_SP, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_SQVGA_MP4, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_SQVGA_MP4, 240, 160); + assertTrue("SQVGAMP4", videoRecordedResult); + } + + //Format: QCIF MP4 + @LargeTest + public void testQCIFMP4() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 176, 144, MediaRecorder.VideoEncoder.MPEG_4_SP, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_QCIF_MP4, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_QCIF_MP4, 176, 144); + assertTrue("QCIFMP4", videoRecordedResult); + } + + + //Format: CIF MP4 + @LargeTest + public void testCIFMP4() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 352, 288, MediaRecorder.VideoEncoder.MPEG_4_SP, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_CIF_MP4, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_CIF_MP4, 352, 288); + assertTrue("CIFMP4", videoRecordedResult); + } + + + //Format: CIF MP4 output format 3gpp + @LargeTest + public void testCIFMP43GPP() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 352, 288, MediaRecorder.VideoEncoder.MPEG_4_SP, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_VIDEO_3GP, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_VIDEO_3GP, 352, 288); + assertTrue("CIFMP4 3GPP", videoRecordedResult); + } + + @LargeTest + public void testQCIFH2633GPP() throws Exception { + boolean videoRecordedResult = false; + recordVideo(15, 176, 144, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_VIDEO_3GP, false); + videoRecordedResult = validateVideo(MediaNames.RECORDED_VIDEO_3GP, 176, 144); + assertTrue("QCIFH263 3GPP", videoRecordedResult); + } + + @LargeTest + public void testInvalidVideoPath() throws Exception { + boolean isTestInvalidVideoPathSuccessful = false; + isTestInvalidVideoPathSuccessful = invalidRecordSetting(15, 176, 144, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.INVALD_VIDEO_PATH, false); + assertTrue("Invalid outputFile Path", isTestInvalidVideoPathSuccessful); + } + + @Suppress + public void testInvalidVideoSize() throws Exception { + boolean isTestInvalidVideoSizeSuccessful = false; + isTestInvalidVideoSizeSuccessful = invalidRecordSetting(15, 800, 600, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_VIDEO_3GP, false); + assertTrue("Invalid video Size", isTestInvalidVideoSizeSuccessful); + } + + @LargeTest + public void testInvalidFrameRate() throws Exception { + boolean isTestInvalidFrameRateSuccessful = false; + isTestInvalidFrameRateSuccessful = invalidRecordSetting(50, 176, 144, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.THREE_GPP, MediaNames.RECORDED_VIDEO_3GP, false); + assertTrue("Invalid FrameRate", isTestInvalidFrameRateSuccessful); + } + +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java new file mode 100644 index 0000000..241f8d6 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/SimTonesTest.java @@ -0,0 +1,73 @@ +/* + * 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.functional; + +// import android.content.Resources; +import com.android.mediaframeworktest.MediaFrameworkTest; + +import android.content.Context; +import android.test.ActivityInstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; + +/** + * Junit / Instrumentation test case for the SIM tone generator + * + */ +public class SimTonesTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> { + private String TAG = "SimTonesTest"; + + Context mContext; + + public SimTonesTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + @LargeTest + public void testDtmfTones() throws Exception { + boolean result = TonesAutoTest.tonesDtmfTest(); + assertTrue("DTMF Tones", result); + } + + @LargeTest + public void testSupervisoryTones() throws Exception { + boolean result = TonesAutoTest.tonesSupervisoryTest(); + assertTrue("Supervisory Tones", result); + } + + @LargeTest + public void testProprietaryTones() throws Exception { + boolean result = TonesAutoTest.tonesProprietaryTest(); + assertTrue("Proprietary Tones", result); + } + + @LargeTest + public void testSimultaneousTones() throws Exception { + boolean result = TonesAutoTest.tonesSimultaneousTest(); + assertTrue("Simultaneous Tones", result); + } + + @LargeTest + public void testStressTones() throws Exception { + boolean result = TonesAutoTest.tonesStressTest(); + assertTrue("Stress Tones", result); + } +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java new file mode 100644 index 0000000..da18e74 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/TonesAutoTest.java @@ -0,0 +1,180 @@ +/* + * 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.functional; + + +//import android.content.Resources; +import android.util.Log; + +import android.media.ToneGenerator; +import android.media.AudioManager; + +/** + * Junit / Instrumentation test case for the Sim tones tests + + */ + public class TonesAutoTest { + private static String TAG = "TonesAutoTest"; + + // Test all DTMF tones one by one + public static boolean tonesDtmfTest() throws Exception { + Log.v(TAG, "DTMF tones test"); + ToneGenerator toneGen; + int type; + boolean result = true; + + toneGen = new ToneGenerator(AudioManager.STREAM_MUSIC, 100); + + for (type = ToneGenerator.TONE_DTMF_0; type <= ToneGenerator.TONE_DTMF_D; type++) { + if (toneGen.startTone(type)) { + Thread.sleep(200); + toneGen.stopTone(); + Thread.sleep(100); + } else { + result = false; + break; + } + } + + toneGen.release(); + return result; + } + + // Test all supervisory tones one by one + public static boolean tonesSupervisoryTest() throws Exception { + Log.v(TAG, "Supervisory tones test"); + ToneGenerator toneGen; + int type; + boolean result = true; + + toneGen = new ToneGenerator(AudioManager.STREAM_MUSIC, 100); + + for (type = ToneGenerator.TONE_SUP_DIAL; + type <= ToneGenerator.TONE_SUP_RINGTONE; type++) { + if (toneGen.startTone(type)) { + Thread.sleep(2000); + toneGen.stopTone(); + Thread.sleep(200); + } else { + result = false; + break; + } + } + + toneGen.release(); + return result; + } + + // Test all proprietary tones one by one + public static boolean tonesProprietaryTest() throws Exception { + Log.v(TAG, "Proprietary tones test"); + ToneGenerator toneGen; + int type; + boolean result = true; + + toneGen = new ToneGenerator(AudioManager.STREAM_MUSIC, 100); + + for (type = ToneGenerator.TONE_PROP_BEEP; type <= ToneGenerator.TONE_PROP_BEEP2; type++) { + if (toneGen.startTone(type)) { + Thread.sleep(1000); + toneGen.stopTone(); + Thread.sleep(100); + } else { + result = false; + break; + } + } + + toneGen.release(); + return result; + } + + // Test playback of 2 tones simultaneously + public static boolean tonesSimultaneousTest() throws Exception { + Log.v(TAG, "Simultaneous tones test"); + ToneGenerator toneGen1; + ToneGenerator toneGen2; + int type; + boolean result = true; + + toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 100); + toneGen2 = new ToneGenerator(AudioManager.STREAM_MUSIC, 50); + + if (toneGen1.startTone(ToneGenerator.TONE_DTMF_1)) { + Thread.sleep(100); + if (toneGen2.startTone(ToneGenerator.TONE_DTMF_2)) { + Thread.sleep(500); + toneGen1.stopTone(); + Thread.sleep(100); + toneGen2.stopTone(); + } else { + toneGen1.stopTone(); + result = false; + } + } else { + result = false; + } + + toneGen1.release(); + toneGen2.release(); + return result; + } + + // Test start of new tone without stopping previous one + public static boolean tonesStressTest() throws Exception { + Log.v(TAG, "Stress tones test"); + ToneGenerator toneGen; + int type; + boolean result = true; + + toneGen = new ToneGenerator(AudioManager.STREAM_MUSIC, 100); + + for (type = ToneGenerator.TONE_DTMF_1; type <= ToneGenerator.TONE_DTMF_9; type++) { + if (toneGen.startTone(type)) { + Thread.sleep(200); + } else { + result = false; + break; + } + } + + toneGen.release(); + return result; + } + + // Perform all tones tests + public static boolean tonesAllTest() throws Exception { + Log.v(TAG, "All tones tests"); + + if (!tonesDtmfTest()) { + return false; + } + if (!tonesSupervisoryTest()) { + return false; + } + if (!tonesProprietaryTest()) { + return false; + } + if (!tonesSimultaneousTest()) { + return false; + } + if (!tonesStressTest()) { + return false; + } + return true; + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java new file mode 100644 index 0000000..2f0173d --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/performance/MediaPlayerPerformance.java @@ -0,0 +1,376 @@ +/* + * 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.performance; + +import com.android.mediaframeworktest.MediaFrameworkTest; +import com.android.mediaframeworktest.MediaNames; + +import android.database.sqlite.SQLiteDatabase; +import android.media.MediaPlayer; +import android.media.MediaRecorder; +import android.os.SystemClock; +import android.test.ActivityInstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.Suppress; +import android.util.Log; +import android.view.SurfaceHolder; + +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.io.File; +import java.io.FileWriter; +import java.io.BufferedWriter; + +import android.media.MediaMetadataRetriever; + +/** + * Junit / Instrumentation - performance measurement for media player and + * recorder + */ +public class MediaPlayerPerformance extends ActivityInstrumentationTestCase<MediaFrameworkTest> { + + private String TAG = "MediaFrameworkPerformance"; + + private SQLiteDatabase mDB; + private SurfaceHolder mSurfaceHolder = null; + private static final int NUM_STRESS_LOOP = 10; + private static final int NUM_PLAYBACk_IN_EACH_LOOP = 20; + private static final long MEDIA_STRESS_WAIT_TIME = 5000; //5 seconds + private static final String H263_VIDEO_PLAYBACK_MEMOUT = + "/sdcard/h263VideoPlaybackMemOut.txt"; + private static final String H264_VIDEO_PLAYBACK_MEMOUT = + "/sdcard/h264VideoPlaybackMemOut.txt"; + private static final String WMV_VIDEO_PLAYBACK_MEMOUT = + "/sdcard/WmvVideoPlaybackMemOut.txt"; + private static final String H263_VIDEO_ONLY_RECORD_MEMOUT = + "/sdcard/recordH263VideoOnlyMemOut.txt"; + private static final String MP4_VIDEO_ONLY_RECORD_MEMOUT = + "/sdcard/recordMPEG4VideoOnlyMemOut.txt"; + private static final String H263_VIDEO_AUDIO_RECORD_MEMOUT = + "/sdcard/recordVideoH263AudioMemOut.txt"; + private static final String AUDIO_ONLY_RECORD_MEMOUT = + "/sdcard/recordAudioOnlyMemOut.txt"; + + + public MediaPlayerPerformance() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + public void createDB() { + mDB = SQLiteDatabase.openOrCreateDatabase("/sdcard/perf.db", null); + mDB.execSQL("CREATE TABLE perfdata (_id INTEGER PRIMARY KEY," + + "file TEXT," + "setdatatime LONG," + "preparetime LONG," + + "playtime LONG" + ");"); + } + + public void audioPlaybackStartupTime(String[] testFile) { + long t1 = 0; + long t2 = 0; + long t3 = 0; + long t4 = 0; + long setDataSourceDuration = 0; + long prepareDuration = 0; + long startDuration = 0; + long totalSetDataTime = 0; + long totalPrepareTime = 0; + long totalStartDuration = 0; + + int numberOfFiles = testFile.length; + Log.v(TAG, "File length " + numberOfFiles); + for (int k = 0; k < numberOfFiles; k++) { + MediaPlayer mp = new MediaPlayer(); + try { + t1 = SystemClock.uptimeMillis(); + FileInputStream fis = new FileInputStream(testFile[k]); + FileDescriptor fd = fis.getFD(); + mp.setDataSource(fd); + fis.close(); + t2 = SystemClock.uptimeMillis(); + mp.prepare(); + t3 = SystemClock.uptimeMillis(); + mp.start(); + t4 = SystemClock.uptimeMillis(); + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + setDataSourceDuration = t2 - t1; + prepareDuration = t3 - t2; + startDuration = t4 - t3; + totalSetDataTime = totalSetDataTime + setDataSourceDuration; + totalPrepareTime = totalPrepareTime + prepareDuration; + totalStartDuration = totalStartDuration + startDuration; + mDB.execSQL("INSERT INTO perfdata (file, setdatatime, preparetime," + + " playtime) VALUES (" + '"' + testFile[k] + '"' + ',' + + setDataSourceDuration + ',' + prepareDuration + + ',' + startDuration + ");"); + Log.v(TAG, "File name " + testFile[k]); + mp.stop(); + mp.release(); + } + Log.v(TAG, "setDataSource average " + totalSetDataTime / numberOfFiles); + Log.v(TAG, "prepare average " + totalPrepareTime / numberOfFiles); + Log.v(TAG, "start average " + totalStartDuration / numberOfFiles); + + } + + @Suppress + public void testStartUpTime() throws Exception { + createDB(); + audioPlaybackStartupTime(MediaNames.MP3FILES); + audioPlaybackStartupTime(MediaNames.AACFILES); + + } + + public void wmametadatautility(String[] testFile) { + long t1 = 0; + long t2 = 0; + long sum = 0; + long duration = 0; + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + String value; + for (int i = 0, n = testFile.length; i < n; ++i) { + try { + t1 = SystemClock.uptimeMillis(); + retriever.setDataSource(testFile[i]); + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER); + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE); + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); + value = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); + value = + retriever + .extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER); + t2 = SystemClock.uptimeMillis(); + duration = t2 - t1; + Log.v(TAG, "Time taken = " + duration); + sum = sum + duration; + } catch (Exception e) { + Log.v(TAG, e.getMessage()); + } + + } + Log.v(TAG, "Average duration = " + sum / testFile.length); + } + + + // Note: This test is to assume the mediaserver's pid is 34 + public void mediaStressPlayback(String testFilePath) { + for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) { + MediaPlayer mp = new MediaPlayer(); + try { + mp.setDataSource(testFilePath); + mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); + mp.prepare(); + mp.start(); + Thread.sleep(MEDIA_STRESS_WAIT_TIME); + mp.release(); + } catch (Exception e) { + mp.release(); + Log.v(TAG, e.toString()); + } + } + } + + // Note: This test is to assume the mediaserver's pid is 34 + private void stressVideoRecord(int frameRate, int width, int height, int videoFormat, + int outFormat, String outFile, boolean videoOnly) { + // Video recording + for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) { + MediaRecorder mRecorder = new MediaRecorder(); + try { + if (!videoOnly) { + Log.v(TAG, "setAudioSource"); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + } + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setOutputFormat(outFormat); + Log.v(TAG, "output format " + outFormat); + mRecorder.setOutputFile(outFile); + mRecorder.setVideoFrameRate(frameRate); + mRecorder.setVideoSize(width, height); + Log.v(TAG, "setEncoder"); + mRecorder.setVideoEncoder(videoFormat); + if (!videoOnly) { + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + } + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + mRecorder.prepare(); + mRecorder.start(); + Thread.sleep(MEDIA_STRESS_WAIT_TIME); + mRecorder.stop(); + mRecorder.release(); + } catch (Exception e) { + Log.v("record video failed ", e.toString()); + mRecorder.release(); + } + } + } + + public void stressAudioRecord(String filePath) { + // This test is only for the short media file + for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) { + MediaRecorder mRecorder = new MediaRecorder(); + try { + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + mRecorder.setOutputFile(filePath); + mRecorder.prepare(); + mRecorder.start(); + Thread.sleep(MEDIA_STRESS_WAIT_TIME); + mRecorder.stop(); + mRecorder.release(); + } catch (Exception e) { + Log.v(TAG, e.toString()); + mRecorder.release(); + } + } + } + + //Write the ps output to the file + public void getMemoryWriteToLog(Writer output) { + String cm = "ps mediaserver"; + String memoryUsage = null; + int ch; + try { + Process p = Runtime.getRuntime().exec(cm); + InputStream in = p.getInputStream(); + StringBuffer sb = new StringBuffer(512); + while ((ch = in.read()) != -1) { + sb.append((char) ch); + } + memoryUsage = sb.toString(); + } catch (IOException e) { + Log.v(TAG, e.toString()); + } + + String[] poList = memoryUsage.split("\r|\n|\r\n"); + String memusage = poList[1].concat("\n"); + Log.v(TAG, memusage); + try { + //Write to file output + output.write(memusage); + } catch (Exception e) { + e.toString(); + } + } + + + @Suppress + public void testWmaParseTime() throws Exception { + // createDB(); + wmametadatautility(MediaNames.WMASUPPORTED); + } + + + // Test case 1: Capture the memory usage after every 20 h263 playback + @LargeTest + public void testH263VideoPlaybackMemoryUsage() throws Exception { + File h263MemoryOut = new File(H263_VIDEO_PLAYBACK_MEMOUT); + Writer output = new BufferedWriter(new FileWriter(h263MemoryOut)); + for (int i = 0; i < NUM_STRESS_LOOP; i++) { + mediaStressPlayback(MediaNames.VIDEO_HIGHRES_H263); + getMemoryWriteToLog(output); + } + output.close(); + } + + // Test case 2: Capture the memory usage after every 20 h264 playback + @LargeTest + public void testH264VideoPlaybackMemoryUsage() throws Exception { + File h264MemoryOut = new File(H264_VIDEO_PLAYBACK_MEMOUT); + Writer output = new BufferedWriter(new FileWriter(h264MemoryOut)); + for (int i = 0; i < NUM_STRESS_LOOP; i++) { + mediaStressPlayback(MediaNames.VIDEO_H264_AMR); + getMemoryWriteToLog(output); + } + output.close(); + } + + // Test case 3: Capture the memory usage after each 20 WMV playback + @LargeTest + public void testWMVVideoPlaybackMemoryUsage() throws Exception { + File wmvMemoryOut = new File(WMV_VIDEO_PLAYBACK_MEMOUT); + Writer output = new BufferedWriter(new FileWriter(wmvMemoryOut)); + for (int i = 0; i < NUM_STRESS_LOOP; i++) { + mediaStressPlayback(MediaNames.VIDEO_WMV); + getMemoryWriteToLog(output); + } + output.close(); + } + + // Test case 4: Capture the memory usage after every 20 video only recorded + @LargeTest + public void testH263RecordVideoOnlyMemoryUsage() throws Exception { + File videoH263RecordOnlyMemoryOut = new File(H263_VIDEO_ONLY_RECORD_MEMOUT); + Writer output = new BufferedWriter(new FileWriter(videoH263RecordOnlyMemoryOut)); + for (int i = 0; i < NUM_STRESS_LOOP; i++) { + stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true); + getMemoryWriteToLog(output); + } + output.close(); + } + + // Test case 5: Capture the memory usage after every 20 video only recorded + @LargeTest + public void testMpeg4RecordVideoOnlyMemoryUsage() throws Exception { + File videoMp4RecordOnlyMemoryOut = new File(MP4_VIDEO_ONLY_RECORD_MEMOUT); + Writer output = new BufferedWriter(new FileWriter(videoMp4RecordOnlyMemoryOut)); + for (int i = 0; i < NUM_STRESS_LOOP; i++) { + stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.MPEG_4_SP, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, true); + getMemoryWriteToLog(output); + } + output.close(); + } + + // Test case 6: Capture the memory usage after every 20 video and audio recorded + @LargeTest + public void testRecordVidedAudioMemoryUsage() throws Exception { + File videoRecordAudioMemoryOut = new File(H263_VIDEO_AUDIO_RECORD_MEMOUT); + Writer output = new BufferedWriter(new FileWriter(videoRecordAudioMemoryOut)); + for (int i = 0; i < NUM_STRESS_LOOP; i++) { + stressVideoRecord(20, 352, 288, MediaRecorder.VideoEncoder.H263, + MediaRecorder.OutputFormat.MPEG_4, MediaNames.RECORDED_VIDEO_3GP, false); + getMemoryWriteToLog(output); + } + output.close(); + } + + // Test case 7: Capture the memory usage after every 20 audio only recorded + @LargeTest + public void testRecordAudioOnlyMemoryUsage() throws Exception { + File audioOnlyMemoryOut = new File(AUDIO_ONLY_RECORD_MEMOUT); + Writer output = new BufferedWriter(new FileWriter(audioOnlyMemoryOut)); + for (int i = 0; i < NUM_STRESS_LOOP; i++) { + stressAudioRecord(MediaNames.RECORDER_OUTPUT); + getMemoryWriteToLog(output); + } + output.close(); + } +} diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java new file mode 100644 index 0000000..dbf937c --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2009 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.stress; + +import com.android.mediaframeworktest.MediaFrameworkTest; + +import android.hardware.Camera; +import android.media.MediaPlayer; +import android.media.MediaRecorder; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.LargeTest; +import android.util.Log; +import android.view.SurfaceHolder; + +/** + * Junit / Instrumentation test case for the media player api + + */ +public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { + + + private String TAG = "MediaRecorderStressTest"; + private MediaRecorder mRecorder; + private Camera mCamera; + + private static final int NUMBER_OF_CAMERA_STRESS_LOOPS = 100; + private static final int NUMBER_OF_RECORDER_STRESS_LOOPS = 100; + private static final int NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS = 50; + private static final int NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER = 200; + private static final long WAIT_TIME_CAMERA_TEST = 3000; // 3 second + private static final long WAIT_TIME_RECORDER_TEST = 60000; // 6 second + private static final long WAIT_TIME_RECORD = 100000; // 10 seconds + private static final long WAIT_TIME_PLAYBACK = 60000; // 6 second + private static final String OUTPUT_FILE = "/sdcard/temp"; + private static final String OUTPUT_FILE_EXT = ".3gp"; + + public MediaRecorderStressTest() { + super("com.android.mediaframeworktest", MediaFrameworkTest.class); + } + + protected void setUp() throws Exception { + getActivity(); + super.setUp(); + } + + //Test case for stressing the camera preview. + @LargeTest + public void testStressCamera() throws Exception { + SurfaceHolder mSurfaceHolder; + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + try { + Log.v(TAG, "Start preview"); + for (int i = 0; i< NUMBER_OF_CAMERA_STRESS_LOOPS; i++){ + mCamera = Camera.open(); + mCamera.setPreviewDisplay(mSurfaceHolder); + mCamera.startPreview(); + Thread.sleep(WAIT_TIME_CAMERA_TEST); + mCamera.stopPreview(); + mCamera.release(); + } + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + } + + //Test case for stressing the camera preview. + @LargeTest + public void testStressRecorder() throws Exception { + String filename; + SurfaceHolder mSurfaceHolder; + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + try { + Log.v(TAG, "Start preview"); + for (int i = 0; i < NUMBER_OF_RECORDER_STRESS_LOOPS; i++){ + Log.v(TAG, "counter = " + i); + filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT; + Log.v(TAG, filename); + mRecorder = new MediaRecorder(); + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + mRecorder.setOutputFile(filename); + mRecorder.setVideoFrameRate(20); + mRecorder.setVideoSize(176,144); + Log.v(TAG, "setEncoder"); + mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + Log.v(TAG, "setPreview"); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + Log.v(TAG, "prepare"); + mRecorder.prepare(); + Log.v(TAG, "before release"); + Thread.sleep(WAIT_TIME_RECORDER_TEST); + mRecorder.reset(); + mRecorder.release(); + } + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + } + + + //Stress test case for switching camera and video recorder preview. + @LargeTest + public void testStressCameraSwitchRecorder() throws Exception { + String filename; + SurfaceHolder mSurfaceHolder; + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + try { + Log.v(TAG, "Start preview"); + for (int i = 0; i < NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER; i++){ + mCamera = Camera.open(); + mCamera.setPreviewDisplay(mSurfaceHolder); + mCamera.startPreview(); + Thread.sleep(WAIT_TIME_CAMERA_TEST); + mCamera.stopPreview(); + mCamera.release(); + mCamera = null; + Log.v(TAG, "release camera"); + filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT; + Log.v(TAG, filename); + mRecorder = new MediaRecorder(); + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + mRecorder.setOutputFile(filename); + mRecorder.setVideoFrameRate(20); + mRecorder.setVideoSize(176,144); + Log.v(TAG, "Media recorder setEncoder"); + mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); + Log.v(TAG, "mediaRecorder setPreview"); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + Log.v(TAG, "prepare"); + mRecorder.prepare(); + Log.v(TAG, "before release"); + Thread.sleep(WAIT_TIME_CAMERA_TEST); + mRecorder.release(); + Log.v(TAG, "release video recorder"); + } + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + } + + //Stress test case for record a video and play right away. + @LargeTest + public void testStressRecordVideoAndPlayback() throws Exception { + String filename; + SurfaceHolder mSurfaceHolder; + mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); + try { + for (int i = 0; i < NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS; i++){ + filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT; + Log.v(TAG, filename); + mRecorder = new MediaRecorder(); + mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + mRecorder.setOutputFile(filename); + mRecorder.setVideoFrameRate(20); + mRecorder.setVideoSize(352,288); + mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + Log.v(TAG, "mediaRecorder setPreview"); + mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); + mRecorder.prepare(); + mRecorder.start(); + Thread.sleep(WAIT_TIME_RECORD); + Log.v(TAG, "Before stop"); + mRecorder.stop(); + mRecorder.release(); + //start the playback + MediaPlayer mp = new MediaPlayer(); + mp.setDataSource(filename); + mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder()); + mp.prepare(); + mp.start(); + Thread.sleep(WAIT_TIME_PLAYBACK); + mp.release(); + } + } catch (Exception e) { + Log.v(TAG, e.toString()); + } + } +} + diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java new file mode 100644 index 0000000..61a8a29 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java @@ -0,0 +1,242 @@ +/* + * 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 new file mode 100644 index 0000000..032b469 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetCurrentPositionStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..5f7abe5 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetDurationStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..6d3c083 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoHeightStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..198439c --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerGetVideoWidthStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..b9c63fd --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerIsPlayingStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..91ed694 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerMethodUnderTest.java @@ -0,0 +1,27 @@ +/* + * 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 new file mode 100644 index 0000000..0a18a39 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerPauseStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..2497cd7 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerResetStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..46bba9b --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSeekToStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..3153792 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetAudioStreamTypeStateUnitTest.java @@ -0,0 +1,69 @@ +/* + * 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 new file mode 100644 index 0000000..17c9d8c --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetLoopingStateUnitTest.java @@ -0,0 +1,65 @@ +/* + * 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 new file mode 100644 index 0000000..a149565 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerSetVolumeStateUnitTest.java @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 0000000..6debbb4 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStartStateUnitTest.java @@ -0,0 +1,69 @@ +/* + * 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 new file mode 100644 index 0000000..5be6fe3 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateErrors.java @@ -0,0 +1,47 @@ +/* + * 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 new file mode 100644 index 0000000..6abfbb2 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStateUnitTestTemplate.java @@ -0,0 +1,506 @@ +/* + * 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 new file mode 100644 index 0000000..3427f86 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaPlayerStopStateUnitTest.java @@ -0,0 +1,63 @@ +/* + * 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 new file mode 100644 index 0000000..3f46f74 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderMethodUnderTest.java @@ -0,0 +1,27 @@ +/* + * 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 new file mode 100644 index 0000000..134144d --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderPrepareStateUnitTest.java @@ -0,0 +1,71 @@ +/* + * 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 new file mode 100644 index 0000000..cae9e31 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderResetStateUnitTest.java @@ -0,0 +1,66 @@ +/* + * 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 new file mode 100644 index 0000000..4b5a818 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioEncoderStateUnitTest.java @@ -0,0 +1,66 @@ +/* + * 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 new file mode 100644 index 0000000..f8ab48cf --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetAudioSourceStateUnitTest.java @@ -0,0 +1,66 @@ +/* + * 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 new file mode 100644 index 0000000..712a758 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFileStateUnitTest.java @@ -0,0 +1,63 @@ +/* + * 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 new file mode 100644 index 0000000..cacdd87 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderSetOutputFormatStateUnitTest.java @@ -0,0 +1,66 @@ +/* + * 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 new file mode 100644 index 0000000..d1232fc --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStartStateUnitTest.java @@ -0,0 +1,66 @@ +/* + * 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 new file mode 100644 index 0000000..2d6e5a2 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateErrors.java @@ -0,0 +1,40 @@ +/* + * 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 new file mode 100644 index 0000000..9edc9aa --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStateUnitTestTemplate.java @@ -0,0 +1,340 @@ +/* + * 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 new file mode 100644 index 0000000..8737595 --- /dev/null +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaRecorderStopStateUnitTest.java @@ -0,0 +1,66 @@ +/* + * 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()"; + } +} |