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