• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.LocationDumpsItem;
19 import com.android.loganalysis.item.LocationDumpsItem.LocationInfoItem;
20 
21 import junit.framework.TestCase;
22 
23 import java.util.Arrays;
24 import java.util.List;
25 
26 /**
27  * Unit tests for {@link LocationServiceParser}
28  */
29 public class LocationServiceParserTest extends TestCase {
30 
31     /**
32      * Test that normal input is parsed.
33      */
testLocationClientsSize()34     public void testLocationClientsSize() {
35         List<String> inputBlock = Arrays.asList(
36                " Location Request History By Package:",
37                " Interval effective/min/max 1/0/0[s] Duration: 140[minutes] "
38                + "[com.google.android.gms, PRIORITY_NO_POWER, UserLocationProducer] "
39                + "Num requests: 2 Active: true",
40                " Interval effective/min/max 284/285/3600[s] Duration: 140[minutes] "
41                + "[com.google.android.googlequicksearchbox, PRIORITY_BALANCED_POWER_ACCURACY] "
42                + "Num requests: 5 Active: true",
43                "  Interval effective/min/max 0/0/0[s] Duration: 0[minutes] "
44                + "[com.google.android.apps.walletnfcrel, PRIORITY_BALANCED_POWER_ACCURACY] "
45                + "Num requests: 1 Active: false",
46                "  ",
47                " FLP WakeLock Count");
48 
49         LocationDumpsItem locationClients = new LocationServiceParser().parse(inputBlock);
50         assertNotNull(locationClients.getLocationClients());
51         assertEquals(locationClients.getLocationClients().size(), 3);
52     }
53 
54     /**
55      * Test that normal input is parsed.
56      */
testLocationClientParser()57     public void testLocationClientParser() {
58         List<String> inputBlock = Arrays.asList(
59                " Location Request History By Package:",
60                " Interval effective/min/max 1/0/0[s] Duration: 140[minutes] "
61                + "[com.google.android.gms, PRIORITY_NO_POWER, UserLocationProducer] "
62                + "Num requests: 2 Active: true");
63 
64         LocationDumpsItem locationClients = new LocationServiceParser().parse(inputBlock);
65         assertNotNull(locationClients.getLocationClients());
66         LocationInfoItem client = locationClients.getLocationClients().iterator().next();
67         assertEquals(client.getPackage(), "com.google.android.gms");
68         assertEquals(client.getEffectiveInterval(), 1);
69         assertEquals(client.getMinInterval(), 0);
70         assertEquals(client.getMaxInterval(), 0);
71         assertEquals(client.getPriority(), "PRIORITY_NO_POWER");
72         assertEquals(client.getDuration(), 140);
73     }
74 
75     /**
76      * Test that invalid input is parsed.
77      */
testLocationClientParserInvalidInput()78     public void testLocationClientParserInvalidInput() {
79         List<String> inputBlock = Arrays.asList(
80                 " Location Request History By Package:",
81                 " Interval effective/min/max 1/0/0[s] Duration: 140[minutes] "
82                 + "[com.google.android.gms PRIORITY_NO_POWER UserLocationProducer] "
83                 + "Num requests: 2 Active: true");
84         LocationDumpsItem locationClients = new LocationServiceParser().parse(inputBlock);
85         assertEquals(locationClients.getLocationClients().size(), 0);
86     }
87 
88 }
89 
90