Home | History | Annotate | Download | only in cts
      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.ComponentName;
     21 import android.content.pm.PackageManager;
     22 import android.content.pm.ServiceInfo;
     23 import android.content.pm.PackageManager.NameNotFoundException;
     24 import android.os.Parcel;
     25 import android.test.AndroidTestCase;
     26 
     27 public class ServiceInfoTest extends AndroidTestCase {
     28     private static final String PACKAGE_NAME = "android.content.cts";
     29     private static final String SERVICE_NAME = "android.content.pm.cts.TestPmService";
     30 
     31     public void testServiceInfo() throws NameNotFoundException {
     32         PackageManager pm = getContext().getPackageManager();
     33         ComponentName componentName = new ComponentName(PACKAGE_NAME, SERVICE_NAME);
     34         Parcel p = Parcel.obtain();
     35 
     36         // Test ServiceInfo()
     37         new ServiceInfo();
     38 
     39         ServiceInfo serviceInfo = pm.getServiceInfo(componentName, 0);
     40         // Test ServiceInfo(ServiceInfo orig)
     41         ServiceInfo infoFromExisted = new ServiceInfo(serviceInfo);
     42         checkInfoSame(serviceInfo, infoFromExisted);
     43         // Test toString, describeContents
     44         assertNotNull(serviceInfo.toString());
     45         assertEquals(0, serviceInfo.describeContents());
     46 
     47         // Test writeToParcel
     48         serviceInfo.writeToParcel(p, 0);
     49         p.setDataPosition(0);
     50         ServiceInfo infoFromParcel = ServiceInfo.CREATOR.createFromParcel(p);
     51         checkInfoSame(serviceInfo, infoFromParcel);
     52     }
     53 
     54     private void checkInfoSame(ServiceInfo expected, ServiceInfo actual) {
     55         assertEquals(expected.name, actual.name);
     56         assertEquals(expected.permission, actual.permission);
     57     }
     58 }
     59