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.PackageStats; 21 import android.os.Parcel; 22 import android.platform.test.annotations.AppModeFull; 23 import android.test.AndroidTestCase; 24 25 @AppModeFull // TODO(Instant) Figure out which APIs should work. 26 public class PackageStatsTest extends AndroidTestCase { 27 private static final String PACKAGE_NAME = "android.content.cts"; 28 testPackageStats()29 public void testPackageStats() { 30 // Set mock data to make sure the functionality of constructor 31 long codeSize = 10000; 32 long cacheSize = 10240; 33 long dataSize = 4096; 34 35 // Test PackageStats(String pkgName), PackageStats(PackageStats pStats) 36 PackageStats stats = new PackageStats(PACKAGE_NAME); 37 assertEquals(PACKAGE_NAME, stats.packageName); 38 stats.cacheSize = codeSize; 39 stats.codeSize = cacheSize; 40 stats.dataSize = dataSize; 41 PackageStats infoFromExisted = new PackageStats(stats); 42 checkInfoSame(stats, infoFromExisted); 43 44 // Test toString, describeContents 45 assertNotNull(stats.toString()); 46 assertEquals(0, stats.describeContents()); 47 48 // Test writeToParcel, PackageStats(Parcel source) 49 Parcel p = Parcel.obtain(); 50 stats.writeToParcel(p, 0); 51 p.setDataPosition(0); 52 // CREATOR invokes public PackageStats(Parcel source) 53 PackageStats infoFromParcel = PackageStats.CREATOR.createFromParcel(p); 54 checkInfoSame(stats, infoFromParcel); 55 p.recycle(); 56 } 57 checkInfoSame(PackageStats expected, PackageStats actual)58 private void checkInfoSame(PackageStats expected, PackageStats actual) { 59 assertEquals(expected.packageName, actual.packageName); 60 assertEquals(expected.cacheSize, actual.cacheSize); 61 assertEquals(expected.dataSize, actual.dataSize); 62 assertEquals(expected.codeSize, actual.codeSize); 63 } 64 } 65