innerTestWriteOverLimit(size, size+1);
}
}
private void innerTestWriteOverLimit(long sz, int choppedBytes) throws IOException {
RandomAccessBuffer raf = construct(sz);
assertEquals(raf.size(), sz);
long startAt = sz - choppedBytes;
byte[] buf = new byte[choppedBytes];
if(sz != 0 && choppedBytes < sz) {
if(startAt >= 0)
readWriteMustSucceed(raf, startAt, buf, 0, buf.length); // Read, write up to the end work.
else
try {
readWriteMustSucceed(raf, startAt, buf, 0, buf.length); // Read, write up to the end work.
fail("Should fail to read at negative index");
} catch (IllegalArgumentException e) {
// Ok.
}
}
if(startAt+1 >= 0)
readWriteMustFail(raf, startAt+1, buf, 0, buf.length); // Read, write over the end fail.
else
try {
readWriteMustSucceed(raf, startAt+1, buf, 0, buf.length); // Read, write up to the end work.
fail("Should fail to read at negative index");
} catch (IllegalArgumentException e) {
// Ok.
}
readWriteMustFail(raf, sz, buf, 0, buf.length); // Read, write at the end fail.
readWriteMustFail(raf, sz+1, buf, 0, buf.length); // One byte into end
readWriteMustFail(raf, sz+1025, buf, 0, buf.length); // 1KB in
readWriteMustFail(raf, sz+buf.length, buf, 0, buf.length);
raf.close();
raf.free();
}