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 17 package android.content.pm.cts; 18 19 20 import android.content.pm.ConfigurationInfo; 21 import android.content.pm.PackageInfo; 22 import android.content.pm.PackageManager; 23 import android.content.pm.PackageManager.NameNotFoundException; 24 import android.os.Parcel; 25 import android.platform.test.annotations.AppModeFull; 26 import android.test.AndroidTestCase; 27 28 @AppModeFull // TODO(Instant) Figure out which APIs should work. 29 public class ConfigurationInfoTest extends AndroidTestCase { 30 public void testConfigPreferences() throws NameNotFoundException { 31 PackageManager pm = getContext().getPackageManager(); 32 33 // Test constructors 34 new ConfigurationInfo(); 35 PackageInfo pkgInfo = pm.getPackageInfo(getContext().getPackageName(), 36 PackageManager.GET_CONFIGURATIONS); 37 ConfigurationInfo[] configInfoArray = pkgInfo.configPreferences; 38 assertTrue(configInfoArray.length > 0); 39 ConfigurationInfo configInfo = configInfoArray[0]; 40 ConfigurationInfo infoFromExisted = new ConfigurationInfo(configInfo); 41 checkInfoSame(configInfo, infoFromExisted); 42 43 // Test toString, describeContents 44 assertEquals(0, configInfo.describeContents()); 45 assertNotNull(configInfo.toString()); 46 47 // Test writeToParcel 48 Parcel p = Parcel.obtain(); 49 configInfo.writeToParcel(p, 0); 50 p.setDataPosition(0); 51 ConfigurationInfo infoFromParcel = ConfigurationInfo.CREATOR.createFromParcel(p); 52 checkInfoSame(configInfo, infoFromParcel); 53 p.recycle(); 54 } 55 56 private void checkInfoSame(ConfigurationInfo expected, ConfigurationInfo actual) { 57 assertEquals(expected.reqKeyboardType, actual.reqKeyboardType); 58 assertEquals(expected.reqTouchScreen, actual.reqTouchScreen); 59 assertEquals(expected.reqInputFeatures, actual.reqInputFeatures); 60 assertEquals(expected.reqNavigation, actual.reqNavigation); 61 } 62 } 63