use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase1_1 method testGenerate125ByteTextCase1_1_2.
@Test
public void testGenerate125ByteTextCase1_1_2() {
int length = 125;
byte[] buf = new byte[length];
Arrays.fill(buf, (byte) '*');
String text = new String(buf, StandardCharsets.UTF_8);
Frame textFrame = new TextFrame().setPayload(text);
ByteBuffer actual = UnitGenerator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x81 });
// no masking
byte b = 0x00;
b |= length & 0x7F;
expected.put(b);
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class TestABCase1_1 method testGenerate65536ByteTextCase1_1_7.
@Test
public void testGenerate65536ByteTextCase1_1_7() {
int length = 65536;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; ++i) {
builder.append("*");
}
WebSocketFrame textFrame = new TextFrame().setPayload(builder.toString());
ByteBuffer actual = UnitGenerator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 11);
expected.put(new byte[] { (byte) 0x81 });
// no masking
byte b = 0x00;
b |= 0x7F;
expected.put(b);
expected.put(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 });
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class WebSocketFrameTest method testRsv2.
@Test
public void testRsv2() {
TextFrame frame = new TextFrame();
frame.setPayload("Hi");
frame.setRsv2(true);
laxGenerator.setRsv2InUse(true);
ByteBuffer actual = generateWholeFrame(laxGenerator, frame);
String expected = "A1024869";
assertFrameHex("Lax Text Frame with RSV2", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class WebSocketFrameTest method testRsv1.
@Test
public void testRsv1() {
TextFrame frame = new TextFrame();
frame.setPayload("Hi");
frame.setRsv1(true);
laxGenerator.setRsv1InUse(true);
ByteBuffer actual = generateWholeFrame(laxGenerator, frame);
String expected = "C1024869";
assertFrameHex("Lax Text Frame with RSV1", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.
the class ParserTest method testParseCase5_19.
/**
* Similar to the server side 5.19 testcase. text message, send in 5 frames/fragments, with 2 pings in the mix.
*/
@Test
public void testParseCase5_19() {
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload("f1").setFin(false));
send.add(new ContinuationFrame().setPayload(",f2").setFin(false));
send.add(new PingFrame().setPayload("pong-1"));
send.add(new ContinuationFrame().setPayload(",f3").setFin(false));
send.add(new ContinuationFrame().setPayload(",f4").setFin(false));
send.add(new PingFrame().setPayload("pong-2"));
send.add(new ContinuationFrame().setPayload(",f5").setFin(true));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
ByteBuffer completeBuf = UnitGenerator.generate(send);
UnitParser parser = new UnitParser();
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parseQuietly(completeBuf);
capture.assertErrorCount(0);
capture.assertHasFrame(OpCode.TEXT, 1);
capture.assertHasFrame(OpCode.CONTINUATION, 4);
capture.assertHasFrame(OpCode.CLOSE, 1);
capture.assertHasFrame(OpCode.PING, 2);
}
Aggregations