01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.io;
05:
06: import java.io.IOException;
07: import java.util.Arrays;
08:
09: import junit.framework.TestCase;
10:
11: public class BasicStreamTest extends TestCase {
12:
13: public void testBasic() throws IOException {
14: TCByteBufferOutputStream os = new TCByteBufferOutputStream();
15:
16: os.write(new byte[] { -5, 5 });
17: os.write(42);
18: os.writeBoolean(true);
19: os.writeBoolean(false);
20: os.writeByte(11);
21: os.writeChar('t');
22: os.writeDouble(3.14D);
23: os.writeFloat(2.78F);
24: os.writeInt(12345678);
25: os.writeLong(Long.MIN_VALUE);
26: os.writeShort(Short.MAX_VALUE);
27: os.writeString("yo yo yo");
28: os.writeString(null);
29: os.writeString(createString(100000));
30:
31: TCByteBufferInputStream is = new TCByteBufferInputStream(os
32: .toArray());
33: byte[] b = new byte[2];
34: Arrays.fill(b, (byte) 69); // these values will be overwritten
35: int read = is.read(b);
36: assertEquals(2, read);
37: assertTrue(Arrays.equals(new byte[] { -5, 5 }, b));
38: assertEquals(42, is.read());
39: assertEquals(true, is.readBoolean());
40: assertEquals(false, is.readBoolean());
41: assertEquals(11, is.readByte());
42: assertEquals('t', is.readChar());
43: assertEquals(Double.doubleToLongBits(3.14D), Double
44: .doubleToLongBits(is.readDouble()));
45: assertEquals(Float.floatToIntBits(2.78F), Float
46: .floatToIntBits(is.readFloat()));
47: assertEquals(12345678, is.readInt());
48: assertEquals(Long.MIN_VALUE, is.readLong());
49: assertEquals(Short.MAX_VALUE, is.readShort());
50: assertEquals("yo yo yo", is.readString());
51: assertEquals(null, is.readString());
52: assertEquals(createString(100000), is.readString());
53: }
54:
55: private static String createString(int length) {
56: char[] chars = new char[length];
57: Arrays.fill(chars, 't');
58: return new String(chars);
59: }
60:
61: }
|