1 /* 2 * Copyright (C) 2014 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 android.media.tv.cts; 18 19 import android.content.Context; 20 import android.media.tv.TvInputInfo; 21 import android.media.tv.TvInputManager; 22 import android.test.AndroidTestCase; 23 24 import java.util.List; 25 26 /** 27 * Test for {@link android.media.tv.TvInputManager}. 28 */ 29 public class TvInputManagerTest extends AndroidTestCase { 30 private static final String[] VALID_TV_INPUT_SERVICES = { 31 StubTunerTvInputService.class.getName() 32 }; 33 private static final String[] INVALID_TV_INPUT_SERVICES = { 34 NoMetadataTvInputService.class.getName(), NoPermissionTvInputService.class.getName() 35 }; 36 37 private String mStubId; 38 private TvInputManager mManager; 39 40 private static TvInputInfo getInfoForClassName(List<TvInputInfo> list, String name) { 41 for (TvInputInfo info : list) { 42 if (info.getServiceInfo().name.equals(name)) { 43 return info; 44 } 45 } 46 return null; 47 } 48 49 @Override 50 public void setUp() throws Exception { 51 if (!Utils.hasTvInputFramework(getContext())) { 52 return; 53 } 54 mManager = (TvInputManager) mContext.getSystemService(Context.TV_INPUT_SERVICE); 55 mStubId = getInfoForClassName( 56 mManager.getTvInputList(), StubTunerTvInputService.class.getName()).getId(); 57 } 58 59 public void testGetInputState() throws Exception { 60 if (!Utils.hasTvInputFramework(getContext())) { 61 return; 62 } 63 assertEquals(mManager.getInputState(mStubId), TvInputManager.INPUT_STATE_CONNECTED); 64 } 65 66 public void testGetTvInputInfo() throws Exception { 67 if (!Utils.hasTvInputFramework(getContext())) { 68 return; 69 } 70 assertEquals(mManager.getTvInputInfo(mStubId), getInfoForClassName( 71 mManager.getTvInputList(), StubTunerTvInputService.class.getName())); 72 } 73 74 public void testGetTvInputList() throws Exception { 75 if (!Utils.hasTvInputFramework(getContext())) { 76 return; 77 } 78 List<TvInputInfo> list = mManager.getTvInputList(); 79 for (String name : VALID_TV_INPUT_SERVICES) { 80 assertNotNull("getTvInputList() doesn't contain valid input: " + name, 81 getInfoForClassName(list, name)); 82 } 83 for (String name : INVALID_TV_INPUT_SERVICES) { 84 assertNull("getTvInputList() contains invalind input: " + name, 85 getInfoForClassName(list, name)); 86 } 87 } 88 } 89