h.check(true, "position: can't be larger than capacity");
}
}
private void mark(TestHarness h, BufferFactory factory)
{
Buffer buf = null;
// mark at default position
buf = factory.newInstance();
h.check(buf.mark(), buf, "mark: buf.mark()");
checkStatus(h, buf, "mark", 10, 10, true, 10, 0);
buf.position(5);
checkStatus(h, buf, "mark", 10, 10, true, 5, 5);
h.check(buf.reset(), buf, "mark: buf.reset()");
checkStatus(h, buf, "mark", 10, 10, true, 10, 0);
buf.position(6);
checkStatus(h, buf, "mark", 10, 10, true, 4, 6);
buf.reset();
checkStatus(h, buf, "mark", 10, 10, true, 10, 0);
// mark at specified position
buf = factory.newInstance();
buf.position(5);
buf.mark();
checkStatus(h, buf, "mark", 10, 10, true, 5, 5);
buf.position(6);
checkStatus(h, buf, "mark", 10, 10, true, 4, 6);
buf.reset();
checkStatus(h, buf, "mark", 10, 10, true, 5, 5);
buf.position(7);
checkStatus(h, buf, "mark", 10, 10, true, 3, 7);
buf.reset();
checkStatus(h, buf, "mark", 10, 10, true, 5, 5);
// mark should be discarded if new position is smaller than mark
buf = factory.newInstance();
buf.position(5);
buf.mark();
buf.position(4);
try
{
buf.reset();
h.check(false, "mark: mark not invalidated");
}
catch(InvalidMarkException ime)
{
h.check(true, "mark: invalidated mark");