1 /* 2 * Copyright (C) 2011 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.SystemPropsItem; 19 20 import junit.framework.TestCase; 21 22 import java.util.Arrays; 23 import java.util.List; 24 25 /** 26 * Unit tests for {@link SystemPropsParser} 27 */ 28 public class SystemPropsParserTest extends TestCase { 29 30 /** 31 * Test that normal input is parsed. 32 */ testSimpleParse()33 public void testSimpleParse() { 34 List<String> inputBlock = Arrays.asList( 35 "[dalvik.vm.dexopt-flags]: [m=y]", 36 "[dalvik.vm.heapgrowthlimit]: [48m]", 37 "[dalvik.vm.heapsize]: [256m]", 38 "[gsm.version.ril-impl]: [android moto-ril-multimode 1.0]"); 39 40 SystemPropsItem map = new SystemPropsParser().parse(inputBlock); 41 42 assertEquals(4, map.size()); 43 assertEquals("m=y", map.get("dalvik.vm.dexopt-flags")); 44 assertEquals("48m", map.get("dalvik.vm.heapgrowthlimit")); 45 assertEquals("256m", map.get("dalvik.vm.heapsize")); 46 assertEquals("android moto-ril-multimode 1.0", map.get("gsm.version.ril-impl")); 47 } 48 49 /** 50 * Make sure that a parse error on one line doesn't prevent the rest of the lines from being 51 * parsed 52 */ testParseError()53 public void testParseError() { 54 List<String> inputBlock = Arrays.asList( 55 "[dalvik.vm.dexopt-flags]: [m=y]", 56 "[ends with newline]: [yup", 57 "]", 58 "[dalvik.vm.heapsize]: [256m]"); 59 60 SystemPropsItem map = new SystemPropsParser().parse(inputBlock); 61 62 assertEquals(2, map.size()); 63 assertEquals("m=y", map.get("dalvik.vm.dexopt-flags")); 64 assertEquals("256m", map.get("dalvik.vm.heapsize")); 65 } 66 67 /** 68 * Test that an empty input returns {@code null}. 69 */ testEmptyInput()70 public void testEmptyInput() { 71 SystemPropsItem item = new SystemPropsParser().parse(Arrays.asList("")); 72 assertNull(item); 73 } 74 } 75 76