assertEquals("123",msg.readString());
}
public void testBytesConversion() throws Exception
{
StreamMessageImpl msg;
byte[] dummy = { (byte)1 , (byte)2 , (byte)3 };
// Boolean
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readBoolean(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Byte
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readByte(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Short
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readShort(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Char
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readChar(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Int
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readInt(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Long
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readLong(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Float
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readFloat(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Double
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readDouble(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// String
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
try { msg.readString(); fail("Should have failed"); } catch (MessageFormatException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Bytes
msg = new StreamMessageImpl();
msg.writeBytes(dummy);
msg.markAsReadOnly();
byte[] data = new byte[3];
assertEquals(3,msg.readBytes(data));
System.out.println(data[0]);
assertEquals(1, data[0]);
assertEquals(2, data[1]);
assertEquals(3, data[2]);
}