1 /*
2  * Copyright (C) 2017 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 package com.android.loganalysis.parser;
17 
18 import com.android.loganalysis.item.AppVersionItem;
19 import com.android.loganalysis.item.DumpsysPackageStatsItem;
20 
21 import junit.framework.TestCase;
22 
23 import java.util.Arrays;
24 import java.util.List;
25 
26 /** Unit tests for {@link DumpsysPackageStatsParser} */
27 public class DumpsysPackageStatsParserTest extends TestCase {
28 
29     /** Test that normal input is parsed. */
testDumpsysPackageStatsParser()30     public void testDumpsysPackageStatsParser() {
31         List<String> inputBlock =
32                 Arrays.asList(
33                         "DUMP OF SERVICE package:",
34                         "Package [com.google.android.calculator] (e075c9d):",
35                         "  userId=10071",
36                         "  secondaryCpuAbi=null",
37                         "  versionCode=73000302 minSdk=10000 targetSdk=10000",
38                         "  versionName=7.3 (3821978)",
39                         "  splits=[base]",
40                         " Package [com.google.android.googlequicksearchbox] (607929e):",
41                         "  userId=10037",
42                         "  pkg=Package{af43294 com.google.android.googlequicksearchbox}",
43                         "  versionCode=300734793 minSdk=10000 targetSdk=10000",
44                         "  versionName=6.16.35.26.arm64",
45                         "  apkSigningVersion=2");
46 
47         final DumpsysPackageStatsItem packagestats =
48                 new DumpsysPackageStatsParser().parse(inputBlock);
49         assertEquals(2, packagestats.size());
50         assertNotNull(packagestats.get("com.google.android.calculator"));
51         final AppVersionItem calculator = packagestats.get("com.google.android.calculator");
52         assertEquals(73000302, calculator.getVersionCode());
53         assertEquals("7.3 (3821978)", calculator.getVersionName());
54         assertNotNull(packagestats.get("com.google.android.googlequicksearchbox"));
55         final AppVersionItem googlequicksearchbox =
56                 packagestats.get("com.google.android.googlequicksearchbox");
57         assertEquals(300734793, googlequicksearchbox.getVersionCode());
58         assertEquals("6.16.35.26.arm64", googlequicksearchbox.getVersionName());
59     }
60 }
61