Home | History | Annotate | Download | only in parser
      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.MemInfoItem;
     19 import com.android.loganalysis.util.ArrayUtil;
     20 
     21 import junit.framework.TestCase;
     22 
     23 import java.util.Arrays;
     24 import java.util.List;
     25 
     26 /**
     27  * Unit tests for {@link MemInfoParser}
     28  */
     29 public class MemInfoParserTest extends TestCase {
     30 
     31     /**
     32      * Test that normal input is parsed.
     33      */
     34     public void testMemInfoParser() {
     35         List<String> inputBlock = Arrays.asList(
     36                 "MemTotal:         353332 kB",
     37                 "MemFree:           65420 kB",
     38                 "Buffers:           20800 kB",
     39                 "Cached:            86204 kB",
     40                 "SwapCached:            0 kB",
     41                 "Long:           34359640152 kB",
     42                 "ExtraLongIgnore: 12345678901234567890 kB");
     43 
     44         MemInfoItem item = new MemInfoParser().parse(inputBlock);
     45 
     46         assertEquals(6, item.size());
     47         assertEquals((Long)353332l, item.get("MemTotal"));
     48         assertEquals((Long)65420l, item.get("MemFree"));
     49         assertEquals((Long)20800l, item.get("Buffers"));
     50         assertEquals((Long)86204l, item.get("Cached"));
     51         assertEquals((Long)0l, item.get("SwapCached"));
     52         assertEquals((Long)34359640152l, item.get("Long"));
     53         assertNull(item.get("ExtraLongIgnore"));
     54         assertEquals(ArrayUtil.join("\n", inputBlock), item.getText());
     55     }
     56 
     57     /**
     58      * Test that an empty input returns {@code null}.
     59      */
     60     public void testEmptyInput() {
     61         MemInfoItem item = new MemInfoParser().parse(Arrays.asList(""));
     62         assertNull(item);
     63     }
     64 }
     65