long readedBytes = tmetrics.getBytesTransferred();
assertEquals(expWrited, readedBytes);
}
public void testComplexReadWriteLine() throws Exception {
SessionOutputBufferMockup outbuffer = new SessionOutputBufferMockup();
outbuffer.write(new byte[] {'a', '\n'});
outbuffer.write(new byte[] {'\r', '\n'});
outbuffer.write(new byte[] {'\r', '\r', '\n'});
outbuffer.write(new byte[] {'\n'});
//these write operations should have no effect
outbuffer.write(null);
outbuffer.write(null, 0, 12);
outbuffer.flush();
long writedBytes = outbuffer.getMetrics().getBytesTransferred();
assertEquals(8, writedBytes);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 14; i++) {
buffer.append("a");
}
String s1 = buffer.toString();
buffer.append("\r\n");
outbuffer.write(buffer.toString().getBytes("US-ASCII"));
outbuffer.flush();
writedBytes = outbuffer.getMetrics().getBytesTransferred();
assertEquals(8 + 14 +2, writedBytes);
buffer.setLength(0);
for (int i = 0; i < 15; i++) {
buffer.append("a");
}
String s2 = buffer.toString();
buffer.append("\r\n");
outbuffer.write(buffer.toString().getBytes("US-ASCII"));
outbuffer.flush();
writedBytes = outbuffer.getMetrics().getBytesTransferred();
assertEquals(8 + 14 + 2 + 15 + 2 , writedBytes);
buffer.setLength(0);
for (int i = 0; i < 16; i++) {
buffer.append("a");
}
String s3 = buffer.toString();
buffer.append("\r\n");
outbuffer.write(buffer.toString().getBytes("US-ASCII"));
outbuffer.flush();
writedBytes = outbuffer.getMetrics().getBytesTransferred();
assertEquals(8 + 14 + 2 + 15 + 2 + 16 + 2, writedBytes);
outbuffer.write(new byte[] {'a'});
outbuffer.flush();
writedBytes = outbuffer.getMetrics().getBytesTransferred();
assertEquals(8 + 14 + 2 + 15 + 2 + 16 + 2 + 1, writedBytes);
SessionInputBufferMockup inbuffer = new SessionInputBufferMockup(
outbuffer.getData());
assertEquals("a", inbuffer.readLine());
assertEquals("", inbuffer.readLine());
assertEquals("\r", inbuffer.readLine());
assertEquals("", inbuffer.readLine());