am 8b570fd4: am 4f9a2d4f: Merge "MediaPlayer test cleanup + new streaming test placeholder." into gingerbread
* commit '8b570fd47c096a3d54ccc0f9d2fa71c0805339f2':
MediaPlayer test cleanup + new streaming test placeholder.
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerStreamingTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerStreamingTest.java
new file mode 100644
index 0000000..36ed264
--- /dev/null
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerStreamingTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2011 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 android.media.cts;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.media.MediaPlayer;
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+ * Tests of MediaPlayer streaming capabilities.
+ */
+public class MediaPlayerStreamingTest extends ActivityInstrumentationTestCase2<MediaStubActivity> {
+
+ private static String TAG = "CtsMediaPlayerStreamingTest";
+
+ private Context mContext;
+ private Resources mResources;
+
+ /*
+ * InstrumentationTestRunner.onStart() calls Looper.prepare(), which creates a looper
+ * for the current thread. However, since we don't actually call loop() in the test,
+ * any messages queued with that looper will never be consumed. We instantiate the player
+ * in the constructor, before setUp(), so that its constructor does not see the
+ * nonfunctional Looper.
+ */
+ private MediaPlayer mMediaPlayer = new MediaPlayer();
+
+ public MediaPlayerStreamingTest() {
+ super(MediaStubActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mContext = getInstrumentation().getTargetContext();
+ mResources = mContext.getResources();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (mMediaPlayer != null) {
+ mMediaPlayer.release();
+ }
+ super.tearDown();
+ }
+}
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index d18d684..470cf76 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -17,36 +17,26 @@
import com.android.cts.stub.R;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
-import android.media.MediaPlayer.OnBufferingUpdateListener;
-import android.media.MediaPlayer.OnCompletionListener;
-import android.media.MediaPlayer.OnErrorListener;
-import android.media.MediaPlayer.OnPreparedListener;
-import android.media.MediaPlayer.OnSeekCompleteListener;
-import android.media.MediaPlayer.OnVideoSizeChangedListener;
+import android.media.cts.MediaPlayerTestHelpers.Monitor;
import android.net.Uri;
import android.os.Environment;
import android.os.Looper;
import android.os.PowerManager;
import android.test.ActivityInstrumentationTestCase2;
-import android.view.SurfaceHolder;
-import android.webkit.cts.CtsTestServer;
import android.util.Log;
+import android.webkit.cts.CtsTestServer;
import java.io.File;
-import java.io.FileDescriptor;
-@TestTargetClass(MediaPlayer.class)
+/**
+ * Tests for the MediaPlayer API and local video/audio playback.
+ */
public class MediaPlayerTest extends ActivityInstrumentationTestCase2<MediaStubActivity> {
private static String TAG = "CtsMediaPlayerTest";
@@ -79,6 +69,7 @@
static MediaPlayer.OnVideoSizeChangedListener mOnVideoSizeChangedListener =
new MediaPlayer.OnVideoSizeChangedListener() {
+ @Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
synchronized (sVideoSizeChanged) {
Log.v(TAG, "sizechanged notification received ...");
@@ -87,27 +78,8 @@
}
};
- private static class Monitor {
- private boolean signalled;
-
- public synchronized void reset() {
- signalled = false;
- }
-
- public synchronized void signal() {
- signalled = true;
- notifyAll();
- }
-
- public synchronized void waitForSignal() throws InterruptedException {
- while (!signalled) {
- wait();
- }
- }
- }
-
public MediaPlayerTest() {
- super("com.android.cts.stub", MediaStubActivity.class);
+ super(MediaStubActivity.class);
mSourceMediaOnSdcard = new File(Environment.getExternalStorageDirectory(),
"record_and_play.3gp").getAbsolutePath();
}
@@ -134,88 +106,15 @@
super.tearDown();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "create",
- args = {Context.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setAudioStreamType",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setWakeMode",
- args = {Context.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "isPlaying",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "start",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setLooping",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "isLooping",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getCurrentPosition",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "seekTo",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "pause",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "stop",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDataSource",
- args = {FileDescriptor.class, long.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "prepare",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getDuration",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "release",
- args = {}
- )
- })
+ public void testStreamNullSource() throws Exception {
+ try {
+ mMediaPlayer.setDataSource((String) null);
+ fail("Null URI was accepted");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
public void testPlayAudio() throws Exception {
final int mp3Duration = 34909;
final int tolerance = 70;
@@ -268,44 +167,6 @@
mp.release();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "MediaPlayer",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDisplay",
- args = {SurfaceHolder.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setScreenOnWhilePlaying",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getVideoHeight",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getVideoWidth",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setVolume",
- args = {float.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDataSource",
- args = {FileDescriptor.class}
- )
- })
-
/*
* Initializes the message looper so that the mediaPlayer object can
* receive the callback messages.
@@ -392,39 +253,6 @@
mp.release();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnBufferingUpdateListener",
- args = {OnBufferingUpdateListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDataSource",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDisplay",
- args = {SurfaceHolder.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "start",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "stop",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "prepare",
- args = {}
- )
- })
-
public void testPlayMp3Stream1() throws Throwable {
streamTest("ringer.mp3", false, false);
}
@@ -468,12 +296,13 @@
mOnBufferingUpdateCalled.reset();
mMediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
+ @Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
mOnBufferingUpdateCalled.signal();
}
});
- assertFalse(mOnBufferingUpdateCalled.signalled);
+ assertFalse(mOnBufferingUpdateCalled.isSignalled());
mMediaPlayer.prepare();
if (nolength) {
@@ -489,68 +318,6 @@
mMediaPlayer.reset();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnCompletionListener",
- args = {OnCompletionListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnErrorListener",
- args = {OnErrorListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnPreparedListener",
- args = {OnPreparedListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnSeekCompleteListener",
- args = {OnSeekCompleteListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnVideoSizeChangedListener",
- args = {OnVideoSizeChangedListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setOnInfoListener",
- args = {MediaPlayer.OnInfoListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDataSource",
- args = {FileDescriptor.class, long.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "prepare",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "start",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "stop",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "isPlaying",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "seekTo",
- args = {int.class}
- )
- })
public void testCallback() throws Throwable {
final int mp4Duration = 8484;
@@ -566,18 +333,21 @@
mMediaPlayer.setScreenOnWhilePlaying(true);
mMediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
+ @Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
mOnVideoSizeChangedCalled.signal();
}
});
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+ @Override
public void onPrepared(MediaPlayer mp) {
mOnPrepareCalled.signal();
}
});
mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
+ @Override
public void onSeekComplete(MediaPlayer mp) {
mOnSeekCompleteCalled.signal();
}
@@ -585,12 +355,14 @@
mOnCompletionCalled.reset();
mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+ @Override
public void onCompletion(MediaPlayer mp) {
mOnCompletionCalled.signal();
}
});
mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
+ @Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mOnErrorCalled.signal();
return false;
@@ -598,60 +370,34 @@
});
mMediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
+ @Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
mOnInfoCalled.signal();
return false;
}
});
- assertFalse(mOnPrepareCalled.signalled);
- assertFalse(mOnVideoSizeChangedCalled.signalled);
+ assertFalse(mOnPrepareCalled.isSignalled());
+ assertFalse(mOnVideoSizeChangedCalled.isSignalled());
mMediaPlayer.prepare();
mOnPrepareCalled.waitForSignal();
mOnVideoSizeChangedCalled.waitForSignal();
- mOnSeekCompleteCalled.signalled = false;
+ mOnSeekCompleteCalled.reset();
mMediaPlayer.seekTo(mp4Duration >> 1);
mOnSeekCompleteCalled.waitForSignal();
- assertFalse(mOnCompletionCalled.signalled);
+ assertFalse(mOnCompletionCalled.isSignalled());
mMediaPlayer.start();
while(mMediaPlayer.isPlaying()) {
Thread.sleep(SLEEP_TIME);
}
assertFalse(mMediaPlayer.isPlaying());
mOnCompletionCalled.waitForSignal();
- assertFalse(mOnErrorCalled.signalled);
+ assertFalse(mOnErrorCalled.isSignalled());
mMediaPlayer.stop();
mMediaPlayer.start();
mOnErrorCalled.waitForSignal();
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDataSource",
- args = {Context.class, Uri.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "setDataSource",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "create",
- args = {Context.class, Uri.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "create",
- args = {Context.class, Uri.class, SurfaceHolder.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- method = "prepareAsync",
- args = {}
- )
- })
public void testRecordAndPlay() throws Exception {
recordMedia();
MediaPlayer mp = new MediaPlayer();
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTestHelpers.java b/tests/tests/media/src/android/media/cts/MediaPlayerTestHelpers.java
new file mode 100644
index 0000000..a6e2bf7
--- /dev/null
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTestHelpers.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011 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 android.media.cts;
+
+/**
+ * Helper classes and methods for MediaPlayer tests.
+ */
+public final class MediaPlayerTestHelpers {
+ private MediaPlayerTestHelpers() {}
+
+ public static class Monitor {
+ private boolean signalled;
+
+ public synchronized void reset() {
+ signalled = false;
+ }
+
+ public synchronized void signal() {
+ signalled = true;
+ notifyAll();
+ }
+
+ public synchronized void waitForSignal() throws InterruptedException {
+ while (!signalled) {
+ wait();
+ }
+ }
+
+ public synchronized boolean isSignalled() {
+ return signalled;
+ }
+ }
+}