1 /*
2  * Copyright (C) 2015 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.BatteryUsageItem;
19 
20 import junit.framework.TestCase;
21 
22 import java.util.Arrays;
23 import java.util.List;
24 
25 /**
26  * Unit tests for {@link BatteryUsageParser}
27  */
28 public class BatteryUsageParserTest extends TestCase {
29 
30     private static final double EPSILON = 1e-3;
31     /**
32      * Test that normal input is parsed.
33      */
testBatteryUsageParser()34     public void testBatteryUsageParser() {
35         List<String> inputBlock = Arrays.asList(
36                 "    Capacity: 3220, Computed drain: 11.0, actual drain: 0",
37                 "    Screen: 8.93",
38                 "    Idle: 1.23",
39                 "    Uid 0: 0.281",
40                 "    Uid u0a36: 0.200",
41                 "    Uid 1000: 0.165",
42                 "    Uid 1013: 0.0911",
43                 "    Uid u0a16: 0.0441");
44 
45         BatteryUsageItem usage = new BatteryUsageParser().parse(inputBlock);
46 
47         assertEquals(3220, usage.getBatteryCapacity());
48         assertEquals(7, usage.getBatteryUsage().size());
49 
50         assertEquals("Screen", usage.getBatteryUsage().get(0).getName());
51         assertEquals(8.93, usage.getBatteryUsage().get(0).getUsage(), EPSILON);
52         assertEquals("Uid u0a16", usage.getBatteryUsage().get(6).getName());
53         assertEquals(0.0441, usage.getBatteryUsage().get(6).getUsage());
54     }
55 }
56 
57