| 1 |
|
package org.apache.lucene.index; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import junit.framework.TestCase; |
| 20 |
|
import org.apache.lucene.store.IndexInput; |
| 21 |
|
|
| 22 |
|
import java.io.IOException; |
| 23 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 2 |
Complexity Density: 0.06 |
|
| 24 |
|
public class TestIndexInput extends TestCase { |
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
| 25 |
1
|
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 |
|
|
| 40 |
|
|
| 41 |
|
@throws |
| 42 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
1
PASS
|
|
| 43 |
1
|
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(); |
| 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(); |
| 62 |
1
|
assertTrue(0x06 + " does not equal: " + charsToRead, 0x06 == charsToRead); |
| 63 |
1
|
is.skipChars(3); |
| 64 |
1
|
char [] chars = new char[3]; |
| 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 |
|
|
| 69 |
1
|
charsToRead = is.readVInt() - 1; |
| 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 |
|
} |