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 import com.android.cts.content.R;
     20 
     21 
     22 import android.content.pm.ApplicationInfo;
     23 import android.content.pm.PackageManager.NameNotFoundException;
     24 import android.os.Parcel;
     25 import android.test.AndroidTestCase;
     26 import android.util.StringBuilderPrinter;
     27 
     28 /**
     29  * Test {@link ApplicationInfo}.
     30  */
     31 public class ApplicationInfoTest extends AndroidTestCase {
     32     private ApplicationInfo mApplicationInfo;
     33     private String mPackageName;
     34 
     35     @Override
     36     protected void setUp() throws Exception {
     37         super.setUp();
     38         mPackageName = getContext().getPackageName();
     39     }
     40 
     41     public void testConstructor() {
     42         ApplicationInfo info = new ApplicationInfo();
     43         // simple test to ensure packageName is copied by copy constructor
     44         // TODO: consider expanding to check all member variables
     45         info.packageName = mPackageName;
     46         ApplicationInfo copy = new ApplicationInfo(info);
     47         assertEquals(info.packageName, copy.packageName);
     48     }
     49 
     50     public void testWriteToParcel() throws NameNotFoundException {
     51         mApplicationInfo = mContext.getPackageManager().getApplicationInfo(mPackageName, 0);
     52 
     53         Parcel p = Parcel.obtain();
     54         mApplicationInfo.writeToParcel(p, 0);
     55 
     56         p.setDataPosition(0);
     57         ApplicationInfo info = ApplicationInfo.CREATOR.createFromParcel(p);
     58         assertEquals(mApplicationInfo.taskAffinity, info.taskAffinity);
     59         assertEquals(mApplicationInfo.permission, info.permission);
     60         assertEquals(mApplicationInfo.processName, info.processName);
     61         assertEquals(mApplicationInfo.className, info.className);
     62         assertEquals(mApplicationInfo.theme, info.theme);
     63         assertEquals(mApplicationInfo.flags, info.flags);
     64         assertEquals(mApplicationInfo.sourceDir, info.sourceDir);
     65         assertEquals(mApplicationInfo.publicSourceDir, info.publicSourceDir);
     66         assertEquals(mApplicationInfo.sharedLibraryFiles, info.sharedLibraryFiles);
     67         assertEquals(mApplicationInfo.dataDir, info.dataDir);
     68         assertEquals(mApplicationInfo.uid, info.uid);
     69         assertEquals(mApplicationInfo.enabled, info.enabled);
     70         assertEquals(mApplicationInfo.manageSpaceActivityName, info.manageSpaceActivityName);
     71         assertEquals(mApplicationInfo.descriptionRes, info.descriptionRes);
     72     }
     73 
     74     public void testToString() {
     75         mApplicationInfo = new ApplicationInfo();
     76         assertNotNull(mApplicationInfo.toString());
     77     }
     78 
     79     public void testDescribeContents() throws NameNotFoundException {
     80        mApplicationInfo = mContext.getPackageManager().getApplicationInfo(mPackageName, 0);
     81 
     82         assertEquals(0, mApplicationInfo.describeContents());
     83     }
     84 
     85     public void testDump() {
     86         mApplicationInfo = new ApplicationInfo();
     87 
     88         StringBuilder sb = new StringBuilder();
     89         assertEquals(0, sb.length());
     90         StringBuilderPrinter p = new StringBuilderPrinter(sb);
     91 
     92         String prefix = "";
     93         mApplicationInfo.dump(p, prefix);
     94         assertNotNull(sb.toString());
     95         assertTrue(sb.length() > 0);
     96     }
     97 
     98     public void testLoadDescription() throws NameNotFoundException {
     99         mApplicationInfo = mContext.getPackageManager().getApplicationInfo(mPackageName, 0);
    100 
    101         assertNull(mApplicationInfo.loadDescription(mContext.getPackageManager()));
    102 
    103         mApplicationInfo.descriptionRes = R.string.hello_world;
    104         assertEquals(mContext.getResources().getString(R.string.hello_world),
    105                 mApplicationInfo.loadDescription(mContext.getPackageManager()));
    106     }
    107 }
    108