MediaAudioManagerTest.java revision db6028508c8eb31a0de1dcdfc410ddfe6df7c5ad
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16
17package com.android.mediaframeworktest.functional.audio;
18
19import com.android.mediaframeworktest.MediaFrameworkTest;
20import android.content.Context;
21import android.media.AudioManager;
22import android.test.ActivityInstrumentationTestCase2;
23import android.test.suitebuilder.annotation.MediumTest;
24
25/**
26 * Junit / Instrumentation test case for the media AudioManager api
27 */
28
29public class MediaAudioManagerTest extends ActivityInstrumentationTestCase2<MediaFrameworkTest> {
30
31    private String TAG = "MediaAudioManagerTest";
32    private AudioManager mAudioManager;
33    private int[] ringtoneMode = {AudioManager.RINGER_MODE_NORMAL,
34             AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE};
35
36    public MediaAudioManagerTest() {
37        super("com.android.mediaframeworktest", MediaFrameworkTest.class);
38    }
39
40    @Override
41    protected void setUp() throws Exception {
42        super.setUp();
43        mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
44     }
45
46     @Override
47     protected void tearDown() throws Exception {
48         super.tearDown();
49     }
50
51     public boolean validateSetRingTone(int i) {
52         int getRingtone = mAudioManager.getRingerMode();
53         if (i != getRingtone)
54             return false;
55         else
56             return true;
57     }
58
59     // Test case 1: Simple test case to validate the set ringtone mode
60     @MediumTest
61     public void testSetRingtoneMode() throws Exception {
62         boolean result = false;
63
64         for (int i = 0; i < ringtoneMode.length; i++) {
65             mAudioManager.setRingerMode(ringtoneMode[i]);
66             result = validateSetRingTone(ringtoneMode[i]);
67             assertTrue("SetRingtoneMode : " + ringtoneMode[i], result);
68         }
69     }
70 }
71