blob: 48fd16c3f4b2af22d30fa1298fbd328fe3a9d9cd [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.mediaframeworktest.unit;
18
19import android.media.MediaPlayer;
20import android.test.AndroidTestCase;
21import android.test.suitebuilder.annotation.LargeTest;
22
23/**
24 * Unit test class to test the set of valid and invalid states that
25 * MediaPlayer.getDuration() method can be called.
26 */
27public class MediaPlayerGetDurationStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest {
28 private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate();
29
30 /**
31 * 1. It is valid to call getDuration() in the following states:
32 * {Prepared, Started, Paused, Stopped, PlaybackCompleted}.
33 * 2. It is invalid to call getDuration() in the following states:
34 * {Idle, Initialized, Error}
35 *
36 * @param stateErrors the MediaPlayerStateErrors to check against.
37 */
38 public void checkStateErrors(MediaPlayerStateErrors stateErrors) {
39 // Valid states.
40 assertTrue(!stateErrors.errorInPreparedStateAfterStop);
41 assertTrue(!stateErrors.errorInPreparedState);
42 assertTrue(!stateErrors.errorInStartedState);
43 assertTrue(!stateErrors.errorInStartedStateAfterPause);
44 assertTrue(!stateErrors.errorInPausedState);
45 assertTrue(!stateErrors.errorInStoppedState);
46 assertTrue(!stateErrors.errorInPlaybackCompletedState);
47
48 // Invalid states.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 assertTrue(stateErrors.errorInInitializedState);
50 assertTrue(stateErrors.errorInErrorState);
51 assertTrue(stateErrors.errorInIdleStateAfterReset);
James Dongf360acf2010-11-18 16:07:26 -080052 assertTrue(stateErrors.errorInIdleState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 }
54
55 public void invokeMethodUnderTest(MediaPlayer player) {
56 player.getDuration();
57 }
58
59 @LargeTest
60 public void testGetDuration() {
61 mTestTemplate.runTestOnMethod(this);
62 }
63
64 @Override
65 public String toString() {
66 return "getDuration()";
67 }
68}