1 /* 2 * Copyright (C) 2013 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.util; 17 18 import junit.framework.TestCase; 19 20 /** 21 * Unit tests for {@link LogTailUtil}. 22 */ 23 public class LogTailUtilTest extends TestCase { 24 25 /** 26 * Test that last and id tails of the log are returned correctly. 27 */ testGetPreambles()28 public void testGetPreambles() { 29 LogTailUtil preambleUtil = new LogTailUtil(500, 3, 3); 30 31 assertEquals("", preambleUtil.getLastTail()); 32 assertEquals("", preambleUtil.getIdTail(1)); 33 34 preambleUtil.addLine(1, "line 1"); 35 preambleUtil.addLine(2, "line 2"); 36 37 assertEquals("line 1\nline 2", preambleUtil.getLastTail()); 38 assertEquals("line 1", preambleUtil.getIdTail(1)); 39 40 preambleUtil.addLine(1, "line 3"); 41 preambleUtil.addLine(2, "line 4"); 42 preambleUtil.addLine(1, "line 5"); 43 preambleUtil.addLine(2, "line 6"); 44 preambleUtil.addLine(1, "line 7"); 45 preambleUtil.addLine(2, "line 8"); 46 47 assertEquals("line 6\nline 7\nline 8", preambleUtil.getLastTail()); 48 assertEquals("line 3\nline 5\nline 7", preambleUtil.getIdTail(1)); 49 } 50 51 /** 52 * Test that the ring buffer is limited to a certain size. 53 */ testRingBufferSize()54 public void testRingBufferSize() { 55 LogTailUtil preambleUtil = new LogTailUtil(5, 3, 3); 56 preambleUtil.addLine(1, "line 1"); 57 preambleUtil.addLine(2, "line 2"); 58 preambleUtil.addLine(2, "line 3"); 59 preambleUtil.addLine(2, "line 4"); 60 preambleUtil.addLine(2, "line 5"); 61 preambleUtil.addLine(2, "line 6"); 62 63 // The first line should roll off the end of the buffer. 64 assertEquals("", preambleUtil.getIdTail(1)); 65 } 66 } 67