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.ComponentName; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.pm.PackageManager; 23 import android.media.tv.TvInputInfo; 24 import android.media.tv.TvInputManager; 25 import android.test.AndroidTestCase; 26 27 /** 28 * Test for {@link android.media.tv.TvInputInfo}. 29 */ 30 public class TvInputInfoTest extends AndroidTestCase { 31 private TvInputInfo mStubInfo; 32 private PackageManager mPackageManager; 33 34 @Override 35 public void setUp() throws Exception { 36 if (!Utils.hasTvInputFramework(getContext())) { 37 return; 38 } 39 TvInputManager manager = 40 (TvInputManager) getContext().getSystemService(Context.TV_INPUT_SERVICE); 41 for (TvInputInfo info : manager.getTvInputList()) { 42 if (info.getServiceInfo().name.equals( 43 StubTunerTvInputService.class.getName())) { 44 mStubInfo = info; 45 break; 46 } 47 } 48 mPackageManager = getContext().getPackageManager(); 49 } 50 51 public void testGetIntentForSettingsActivity() throws Exception { 52 if (!Utils.hasTvInputFramework(getContext())) { 53 return; 54 } 55 Intent intent = mStubInfo.createSettingsIntent(); 56 57 assertEquals(intent.getComponent(), new ComponentName(getContext(), 58 TvInputSettingsActivityStub.class)); 59 String inputId = intent.getStringExtra(TvInputInfo.EXTRA_INPUT_ID); 60 assertEquals(mStubInfo.getId(), inputId); 61 } 62 63 public void testGetIntentForSetupActivity() throws Exception { 64 if (!Utils.hasTvInputFramework(getContext())) { 65 return; 66 } 67 Intent intent = mStubInfo.createSetupIntent(); 68 69 assertEquals(intent.getComponent(), new ComponentName(getContext(), 70 TvInputSetupActivityStub.class)); 71 String inputId = intent.getStringExtra(TvInputInfo.EXTRA_INPUT_ID); 72 assertEquals(mStubInfo.getId(), inputId); 73 } 74 75 public void testTunerHasNoParentId() throws Exception { 76 if (!Utils.hasTvInputFramework(getContext())) { 77 return; 78 } 79 assertNull(mStubInfo.getParentId()); 80 } 81 82 public void testGetTypeForTuner() throws Exception { 83 if (!Utils.hasTvInputFramework(getContext())) { 84 return; 85 } 86 assertEquals(mStubInfo.getType(), TvInputInfo.TYPE_TUNER); 87 } 88 89 public void testTunerIsNotPassthroughInput() throws Exception { 90 if (!Utils.hasTvInputFramework(getContext())) { 91 return; 92 } 93 assertFalse(mStubInfo.isPassthroughInput()); 94 } 95 96 public void testLoadIcon() throws Exception { 97 if (!Utils.hasTvInputFramework(getContext())) { 98 return; 99 } 100 assertEquals(mStubInfo.loadIcon(getContext()).getConstantState(), 101 mStubInfo.getServiceInfo().loadIcon(mPackageManager).getConstantState()); 102 } 103 104 public void testLoadLabel() throws Exception { 105 if (!Utils.hasTvInputFramework(getContext())) { 106 return; 107 } 108 assertEquals(mStubInfo.loadLabel(getContext()), 109 mStubInfo.getServiceInfo().loadLabel(mPackageManager)); 110 } 111 } 112