1 /* 2 * Copyright (C) 2008 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 17 package com.android.mediaframeworktest.unit; 18 19 import android.media.MediaRecorder; 20 import android.test.AndroidTestCase; 21 import android.test.suitebuilder.annotation.MediumTest; 22 import android.test.suitebuilder.annotation.Suppress; 23 import android.util.Log; 24 25 /** 26 * Unit test class to test the set of valid and invalid states that 27 * MediaRecorder.stop() method can be called. 28 */ 29 public class MediaRecorderStopStateUnitTest extends AndroidTestCase implements MediaRecorderMethodUnderTest { 30 private MediaRecorderStateUnitTestTemplate mTestTemplate = new MediaRecorderStateUnitTestTemplate(); 31 private static final String TAG = "MediaRecorderStopStateUnitTest"; 32 private static final int SLEEP_TIME_BEFORE_STOP = 1000; 33 34 /** 35 * 1. It is valid to call stop() in the following states: 36 * {Recording}. 37 * 2. It is invalid to call stop() in the following states: 38 * {Initial, Initialized, DataSourceConfigured, Prepared, Error} 39 * 40 * @param stateErrors the MediaRecorderStateErrors to check against. 41 */ 42 public void checkStateErrors(MediaRecorderStateErrors stateErrors) { 43 // Valid states. 44 assertTrue(!stateErrors.errorInRecordingState); 45 46 // Invalid states. 47 assertTrue(stateErrors.errorInInitialState); 48 assertTrue(stateErrors.errorInInitialStateAfterReset); 49 assertTrue(stateErrors.errorInInitialStateAfterStop); 50 assertTrue(stateErrors.errorInInitializedState); 51 assertTrue(stateErrors.errorInErrorState); 52 assertTrue(stateErrors.errorInDataSourceConfiguredState); 53 assertTrue(stateErrors.errorInPreparedState); 54 } 55 56 public void invokeMethodUnderTest(MediaRecorder recorder) { 57 // Wait for some time before stopping the media recorder. 58 // This will fix the assertion caused by stopping it immediatedly 59 // after it is started 60 try { 61 Thread.sleep(SLEEP_TIME_BEFORE_STOP); 62 } catch(Exception e) { 63 Log.v(TAG, "sleep was interrupted and terminated prematurely"); 64 } 65 66 recorder.stop(); 67 } 68 69 @MediumTest 70 public void testStop() { 71 mTestTemplate.runTestOnMethod(this); 72 } 73 74 @Override 75 public String toString() { 76 return "stop()"; 77 } 78 } 79