102103104105106107108109110111112
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);
109110111112113114115116117118119
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());
114115116117118119120121122123124
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);
157158159160161162163164165166167
} } public void testAppendOneByte() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(4); assertEquals(4, buffer.capacity()); byte[] tmp = new byte[] { 1, 127, -1, -128, 1, -2}; for (int i = 0; i < tmp.length; i++) { buffer.append(tmp[i]); }
163164165166167168169170171172173
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)); }
949596979899100101102103104
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()); }