Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
32   77   2   16
0   51   0.06   2
2     1  
1    
 
  TestIndexInput       Line # 24 32 2 100% 1.0
 
  (2)
 
1    package org.apache.lucene.index;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import junit.framework.TestCase;
20    import org.apache.lucene.store.IndexInput;
21   
22    import java.io.IOException;
23   
 
24    public class TestIndexInput extends TestCase {
 
25  1 toggle public void testRead() throws IOException {
26  1 IndexInput is = new MockIndexInput(new byte[]{(byte) 0x80, 0x01,
27    (byte) 0xFF, 0x7F,
28    (byte) 0x80, (byte) 0x80, 0x01,
29    (byte) 0x81, (byte) 0x80, 0x01,
30    0x06, 'L', 'u', 'c', 'e', 'n', 'e'});
31  1 assertEquals(128, is.readVInt());
32  1 assertEquals(16383, is.readVInt());
33  1 assertEquals(16384, is.readVInt());
34  1 assertEquals(16385, is.readVInt());
35  1 assertEquals("Lucene", is.readString());
36    }
37   
38    /**
39    * Expert
40    *
41    * @throws IOException
42    */
 
43  1 toggle public void testSkipChars() throws IOException {
44  1 byte[] bytes = new byte[]{(byte) 0x80, 0x01,
45    (byte) 0xFF, 0x7F,
46    (byte) 0x80, (byte) 0x80, 0x01,
47    (byte) 0x81, (byte) 0x80, 0x01,
48    0x06, 'L', 'u', 'c', 'e', 'n', 'e',
49    };
50  1 String utf8Str = "\u0634\u1ea1";
51  1 byte [] utf8Bytes = utf8Str.getBytes("UTF-8");
52  1 byte [] theBytes = new byte[bytes.length + 1 + utf8Bytes.length];
53  1 System.arraycopy(bytes, 0, theBytes, 0, bytes.length);
54  1 theBytes[bytes.length] = (byte)utf8Str.length();//Add in the number of chars we are storing, which should fit in a byte for this test
55  1 System.arraycopy(utf8Bytes, 0, theBytes, bytes.length + 1, utf8Bytes.length);
56  1 IndexInput is = new MockIndexInput(theBytes);
57  1 assertEquals(128, is.readVInt());
58  1 assertEquals(16383, is.readVInt());
59  1 assertEquals(16384, is.readVInt());
60  1 assertEquals(16385, is.readVInt());
61  1 int charsToRead = is.readVInt();//number of chars in the Lucene string
62  1 assertTrue(0x06 + " does not equal: " + charsToRead, 0x06 == charsToRead);
63  1 is.skipChars(3);
64  1 char [] chars = new char[3];//there should be 6 chars remaining
65  1 is.readChars(chars, 0, 3);
66  1 String tmpStr = new String(chars);
67  1 assertTrue(tmpStr + " is not equal to " + "ene", tmpStr.equals("ene" ) == true);
68    //Now read the UTF8 stuff
69  1 charsToRead = is.readVInt() - 1;//since we are skipping one
70  1 is.skipChars(1);
71  1 assertTrue(utf8Str.length() - 1 + " does not equal: " + charsToRead, utf8Str.length() - 1 == charsToRead);
72  1 chars = new char[charsToRead];
73  1 is.readChars(chars, 0, charsToRead);
74  1 tmpStr = new String(chars);
75  1 assertTrue(tmpStr + " is not equal to " + utf8Str.substring(1), tmpStr.equals(utf8Str.substring(1)) == true);
76    }
77    }