Methods Summary |
---|
private void | checkReadBytesWithOffsetAndLength_WithString1(int offset, int length)
byte[] temp = new byte[TEST_STRING1.length];
byte[] expected = new byte[length];
byte[] actual = new byte[length];
System.arraycopy(TEST_STRING1, offset, expected, 0, length);
InputStream is = new LimitedLengthInputStream(mTestStream1, offset, length);
assertEquals(length, is.read(temp, 0, temp.length));
System.arraycopy(temp, 0, actual, 0, length);
assertTrue(Arrays.equals(expected, actual));
assertEquals(-1, is.read(temp, 0, temp.length));
|
private void | checkReadBytes_WithString1(int offset, int length)
byte[] temp = new byte[TEST_STRING1.length];
byte[] expected = new byte[length];
byte[] actual = new byte[length];
System.arraycopy(TEST_STRING1, offset, expected, 0, length);
InputStream is = new LimitedLengthInputStream(mTestStream1, offset, length);
assertEquals(length, is.read(temp));
System.arraycopy(temp, 0, actual, 0, length);
assertTrue(Arrays.equals(expected, actual));
assertEquals(-1, is.read(temp));
|
private void | checkSingleByteRead_WithString1(int offset, int length)
InputStream is = new LimitedLengthInputStream(mTestStream1, offset, length);
for (int i = 0; i < length; i++) {
assertEquals(TEST_STRING1[offset + i], is.read());
}
assertEquals(-1, is.read());
|
protected void | setUp()
super.setUp();
mTestStream1 = new ByteArrayInputStream(TEST_STRING1);
|
public void | testConstructor_NegativeLength_Failure()
try {
InputStream is = new LimitedLengthInputStream(mTestStream1, 0, -1);
fail("Should throw IOException on negative length");
} catch (IOException e) {
// success
}
|
public void | testConstructor_NegativeOffset_Failure()
try {
InputStream is = new LimitedLengthInputStream(mTestStream1, -1, TEST_STRING1.length);
fail("Should throw IOException on negative index");
} catch (IOException e) {
// success
}
|
public void | testConstructor_NullInputStream_Failure()
try {
InputStream is = new LimitedLengthInputStream(null, 0, 1);
fail("Should throw IOException on null input stream");
} catch (IOException e) {
// success
}
|
public void | testConstructor_OffsetLengthOverflow_Fail()
try {
InputStream is = new LimitedLengthInputStream(mTestStream1, Long.MAX_VALUE - 1,
Long.MAX_VALUE - 1);
fail("Should fail when offset + length is > Long.MAX_VALUE");
} catch (IOException e) {
// success
}
|
public void | testReadBytesWithOffsetAndLength_NonZeroOffset_FullLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(3, TEST_STRING1.length - 3);
|
public void | testReadBytesWithOffsetAndLength_NonZeroOffset_PartialLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(3, 2);
|
public void | testReadBytesWithOffsetAndLength_ZeroOffset_FullLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(0, TEST_STRING1.length);
|
public void | testReadBytesWithOffsetAndLength_ZeroOffset_PartialLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(0, 2);
|
public void | testReadBytesWithOffsetAndLength_ZeroOffset_PastEnd_Success()
byte[] temp = new byte[TEST_STRING1.length + 10];
InputStream is = new LimitedLengthInputStream(mTestStream1, 0, TEST_STRING1.length + 10);
assertEquals(TEST_STRING1.length, is.read(temp, 0, TEST_STRING1.length + 10));
byte[] actual = new byte[TEST_STRING1.length];
System.arraycopy(temp, 0, actual, 0, actual.length);
assertTrue(Arrays.equals(TEST_STRING1, actual));
|
public void | testReadBytes_NonZeroOffset_FullLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(3, TEST_STRING1.length - 3);
|
public void | testReadBytes_NonZeroOffset_PartialLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(3, 2);
|
public void | testReadBytes_ZeroOffset_FullLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(0, TEST_STRING1.length);
|
public void | testReadBytes_ZeroOffset_PartialLength_Success()
checkReadBytesWithOffsetAndLength_WithString1(0, 2);
|
public void | testSingleByteRead_NonZeroOffset_FullLength_Success()
checkSingleByteRead_WithString1(3, TEST_STRING1.length - 3);
|
public void | testSingleByteRead_NonZeroOffset_PartialLength_Success()
checkSingleByteRead_WithString1(3, 2);
|
public void | testSingleByteRead_ZeroOffset_FullLength_Success()
checkSingleByteRead_WithString1(0, TEST_STRING1.length);
|
public void | testSingleByteRead_ZeroOffset_PartialLength_Success()
checkSingleByteRead_WithString1(0, 2);
|