159160161162163164165166167168169
byte[] tmp = new byte[] { 1, 127, -1, -128, 1, -2}; for (int i = 0; i < tmp.length; i++) { buffer.append(tmp[i]); } assertEquals(8, buffer.capacity()); assertEquals(6, buffer.length()); for (int i = 0; i < tmp.length; i++) { assertEquals(tmp[i], buffer.byteAt(i)); }
192193194195196197198199200201202
} public void testEnsureCapacity() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(4); buffer.ensureCapacity(2); assertEquals(4, buffer.capacity()); buffer.ensureCapacity(8); assertEquals(8, buffer.capacity()); } public void testIndexOf() throws Exception {
194195196197198199200201202203204
public void testEnsureCapacity() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(4); buffer.ensureCapacity(2); assertEquals(4, buffer.capacity()); buffer.ensureCapacity(8); assertEquals(8, buffer.capacity()); } public void testIndexOf() throws Exception { final byte COLON = (byte) ':'; final byte COMMA = (byte) ',';
5657585960616263646566
return new TestSuite(TestByteArrayBuffer.class); } public void testConstructor() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(16); assertEquals(16, buffer.capacity()); assertEquals(0, buffer.length()); assertNotNull(buffer.buffer()); assertEquals(16, buffer.buffer().length); try { new ByteArrayBuffer(-1);
7071727374757677787980
} } public void testSimpleAppend() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(16); assertEquals(16, buffer.capacity()); assertEquals(0, buffer.length()); byte[] b1 = buffer.toByteArray(); assertNotNull(b1); assertEquals(0, b1.length); assertTrue(buffer.isEmpty());
8081828384858687888990
assertTrue(buffer.isEmpty()); assertFalse(buffer.isFull()); byte[] tmp = new byte[] { 1, 2, 3, 4}; buffer.append(tmp, 0, tmp.length); assertEquals(16, buffer.capacity()); assertEquals(4, buffer.length()); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); byte[] b2 = buffer.toByteArray();
93949596979899100101102103
for (int i = 0; i < tmp.length; i++) { assertEquals(tmp[i], b2[i]); assertEquals(tmp[i], buffer.byteAt(i)); } buffer.clear(); assertEquals(16, buffer.capacity()); assertEquals(0, buffer.length()); assertTrue(buffer.isEmpty()); assertFalse(buffer.isFull()); }
101102103104105106107108109110111
assertFalse(buffer.isFull()); } public void testExpandAppend() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(4); assertEquals(4, buffer.capacity()); byte[] tmp = new byte[] { 1, 2, 3, 4}; buffer.append(tmp, 0, 2); buffer.append(tmp, 0, 4); buffer.append(tmp, 0, 0);
108109110111112113114115116117118
byte[] tmp = new byte[] { 1, 2, 3, 4}; buffer.append(tmp, 0, 2); buffer.append(tmp, 0, 4); buffer.append(tmp, 0, 0); assertEquals(8, buffer.capacity()); assertEquals(6, buffer.length()); buffer.append(tmp, 0, 4); assertEquals(16, buffer.capacity());
113114115116117118119120121122123
assertEquals(8, buffer.capacity()); assertEquals(6, buffer.length()); buffer.append(tmp, 0, 4); assertEquals(16, buffer.capacity()); assertEquals(10, buffer.length()); } public void testInvalidAppend() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(4);