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.PackageManager; 21 import android.content.pm.PermissionGroupInfo; 22 import android.content.pm.PackageManager.NameNotFoundException; 23 import android.os.Parcel; 24 import android.test.AndroidTestCase; 25 26 public class PermissionGroupInfoTest extends AndroidTestCase { 27 private static final String GROUP = "android.permission-group.COST_MONEY"; 28 private static final String GROUP_NAME = "Cost money"; 29 private static final String GROUP_DESCRIPTION = "Do things that can cost you money."; 30 31 public void testPermissionGroupInfo() throws NameNotFoundException { 32 PackageManager pm = getContext().getPackageManager(); 33 Parcel p = Parcel.obtain(); 34 // Test constructors 35 new PermissionGroupInfo(); 36 PermissionGroupInfo permissionGroupInfo = pm 37 .getPermissionGroupInfo(GROUP, 0); 38 PermissionGroupInfo infoFromExisted = new PermissionGroupInfo(permissionGroupInfo); 39 checkInfoSame(permissionGroupInfo, infoFromExisted); 40 41 // Test toString, describeContents, loadDescription 42 assertNotNull(permissionGroupInfo.toString()); 43 assertEquals(0, permissionGroupInfo.describeContents()); 44 assertEquals(GROUP_NAME, permissionGroupInfo.loadLabel(pm)); 45 assertEquals(GROUP_DESCRIPTION, permissionGroupInfo.loadDescription(pm)); 46 47 // Test writeToParcel 48 permissionGroupInfo.writeToParcel(p, 0); 49 p.setDataPosition(0); 50 PermissionGroupInfo infoFromParcel = PermissionGroupInfo.CREATOR.createFromParcel(p); 51 checkInfoSame(permissionGroupInfo, infoFromParcel); 52 p.recycle(); 53 } 54 55 private void checkInfoSame(PermissionGroupInfo expected, PermissionGroupInfo actual) { 56 assertEquals(expected.descriptionRes, actual.descriptionRes); 57 assertEquals(expected.nonLocalizedDescription, actual.nonLocalizedDescription); 58 } 59 } 60