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