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.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.setLooping() method can be called.
26 */
27public class MediaPlayerSetLoopingStateUnitTest extends AndroidTestCase implements MediaPlayerMethodUnderTest {
28    private MediaPlayerStateUnitTestTemplate mTestTemplate = new MediaPlayerStateUnitTestTemplate();
29    private boolean looping = false;
30
31    /**
32     * 1. It is valid to call setLooping() in the following states:
33     *    {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackComplted}.
34     * 2. It is invalid to call setLooping() 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.errorInStartedState);
42        assertTrue(!stateErrors.errorInStartedStateAfterPause);
43        assertTrue(!stateErrors.errorInPausedState);
44        assertTrue(!stateErrors.errorInPreparedState);
45        assertTrue(!stateErrors.errorInPreparedStateAfterStop);
46        assertTrue(!stateErrors.errorInPlaybackCompletedState);
47        assertTrue(!stateErrors.errorInIdleStateAfterReset);
48        assertTrue(!stateErrors.errorInInitializedState);
49        assertTrue(!stateErrors.errorInStoppedState);
50        assertTrue(!stateErrors.errorInIdleState);
51
52        // Invalid states.
53        assertTrue(stateErrors.errorInErrorState);
54    }
55
56    public void invokeMethodUnderTest(MediaPlayer player) {
57        looping = !looping;  // Flip the looping mode.
58        player.setLooping(looping);
59    }
60
61    @LargeTest
62    public void testSetLooping() {
63        mTestTemplate.runTestOnMethod(this);
64    }
65}
66