01: /*
02: * ByteBufferTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import junit.framework.*;
15: import java.io.IOException;
16: import java.io.PrintStream;
17: import java.io.Writer;
18:
19: /**
20: *
21: * @author support@sql-workbench.net
22: */
23: public class ByteBufferTest extends TestCase {
24:
25: public ByteBufferTest(String testName) {
26: super (testName);
27: }
28:
29: public void testByteBuffer() {
30: try {
31: ByteBuffer buffer = new ByteBuffer();
32: int size = 1024;
33: byte[] data = new byte[size];
34: for (int i = 0; i < size; i++) {
35: data[i] = (byte) (i % 255);
36: }
37: buffer.append(data);
38: buffer.append(data);
39: assertEquals("Wrong size", size * 2, buffer.getLength());
40: byte b = buffer.getBuffer()[0];
41: assertEquals("Wrong data", 0, b);
42: b = buffer.getBuffer()[size];
43: assertEquals("Wrong data", 0, b);
44: b = buffer.getBuffer()[size + 1];
45: assertEquals("Wrong data", 1, b);
46: int l = buffer.getBuffer().length;
47: assertEquals("Wrong buffer size", 2048, l);
48: byte[] more = new byte[20];
49: buffer.append(more);
50: l = buffer.getLength();
51: assertEquals("Wrong buffer size", 2068, l);
52:
53: more = new byte[2345];
54: buffer.append(more);
55: assertEquals("Wrong buffer size", 2068 + 2345, buffer
56: .getLength());
57: } catch (Exception e) {
58: e.printStackTrace();
59: fail();
60: }
61: }
62:
63: }
|