1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.mediaframeworktest.functional; 18 19import com.android.mediaframeworktest.MediaFrameworkTest; 20import com.android.mediaframeworktest.MediaNames; 21 22import android.test.ActivityInstrumentationTestCase2; 23import android.util.Log; 24import android.test.suitebuilder.annotation.LargeTest; 25import android.test.suitebuilder.annotation.MediumTest; 26import android.test.suitebuilder.annotation.Suppress; 27 28import android.media.MediaPlayer; 29import android.os.Parcel; 30 31import java.util.Calendar; 32import java.util.Random; 33 34// Tests for the invoke method in the MediaPlayer. 35public class MediaPlayerInvokeTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> { 36 private static final String TAG = "MediaPlayerInvokeTest"; 37 private MediaPlayer mPlayer; 38 private Random rnd; 39 40 public MediaPlayerInvokeTest() { 41 super("com.android.mediaframeworktest", MediaFrameworkTest.class); 42 rnd = new Random(Calendar.getInstance().getTimeInMillis()); 43 } 44 45 @Override 46 protected void setUp() throws Exception { 47 super.setUp(); 48 mPlayer = new MediaPlayer(); 49 } 50 51 @Override 52 protected void tearDown() throws Exception { 53 mPlayer.release(); 54 super.tearDown(); 55 } 56 57 // Generate a random number, sends it to the ping test player. 58 @Suppress 59 @MediumTest 60 public void testPing() throws Exception { 61 mPlayer.setDataSource("test:invoke_mock_media_player.so?url=ping"); 62 63 Parcel request = mPlayer.newRequest(); 64 Parcel reply = Parcel.obtain(); 65 66 int val = rnd.nextInt(); 67 request.writeInt(val); 68 assertEquals(0, mPlayer.invoke(request, reply)); 69 assertEquals(val, reply.readInt()); 70 } 71} 72