Search in sources :

Example 16 with IncomingFramesCapture

use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.

the class TestABCase1_2 method testParse65536ByteBinaryCase1_2_7.

@Test
public void testParse65536ByteBinaryCase1_2_7() {
    int length = 65536;
    ByteBuffer expected = ByteBuffer.allocate(length + 11);
    expected.put(new byte[] { (byte) 0x82 });
    // 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();
    WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
    policy.setMaxBinaryMessageSize(length);
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.BINARY, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("BinaryFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 17 with IncomingFramesCapture

use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.

the class TestABCase1_2 method testParse126ByteBinaryCase1_2_3.

@Test
public void testParse126ByteBinaryCase1_2_3() {
    int length = 126;
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x82 });
    // no masking
    byte b = 0x00;
    b |= length & 0x7E;
    expected.put(b);
    expected.putShort((short) length);
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.BINARY, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("BinaryFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 18 with IncomingFramesCapture

use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.

the class TestABCase1_2 method testParse127ByteBinaryCase1_2_4.

@Test
public void testParse127ByteBinaryCase1_2_4() {
    int length = 127;
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x82 });
    // no masking
    byte b = 0x00;
    b |= length & 0x7E;
    expected.put(b);
    expected.putShort((short) length);
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.BINARY, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("BinaryFrame.payloadLength", pActual.getPayloadLength(), is(length));
// .assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 19 with IncomingFramesCapture

use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.

the class TestABCase2 method testParse125OctetPingCase2_4.

@Test
public void testParse125OctetPingCase2_4() {
    byte[] bytes = new byte[125];
    for (int i = 0; i < bytes.length; ++i) {
        bytes[i] = Integer.valueOf(Integer.toOctalString(i)).byteValue();
    }
    ByteBuffer expected = ByteBuffer.allocate(bytes.length + 32);
    expected.put(new byte[] { (byte) 0x89 });
    // no masking
    byte b = 0x00;
    b |= bytes.length & 0x7F;
    expected.put(b);
    expected.put(bytes);
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.PING, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("PingFrame.payloadLength", pActual.getPayloadLength(), is(bytes.length));
    Assert.assertEquals("PingFrame.payload", bytes.length, pActual.getPayloadLength());
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 20 with IncomingFramesCapture

use of org.eclipse.jetty.websocket.common.test.IncomingFramesCapture in project jetty.project by eclipse.

the class TestABCase2 method testParseEmptyPingCase2_1.

@Test
public void testParseEmptyPingCase2_1() {
    ByteBuffer expected = ByteBuffer.allocate(5);
    expected.put(new byte[] { (byte) 0x89, (byte) 0x00 });
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.PING, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("PingFrame.payloadLength", pActual.getPayloadLength(), is(0));
    Assert.assertEquals("PingFrame.payload", 0, pActual.getPayloadLength());
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Aggregations

IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)62 ByteBuffer (java.nio.ByteBuffer)60 Test (org.junit.Test)59 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)53 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)28 Parser (org.eclipse.jetty.websocket.common.Parser)27 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)26 WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)24 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)21 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)9 ArrayList (java.util.ArrayList)8 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)8 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)7 MaskedByteBuffer (org.eclipse.jetty.websocket.common.util.MaskedByteBuffer)7 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)6 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)5 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)4 WebSocketException (org.eclipse.jetty.websocket.api.WebSocketException)4 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)4 AbstractExtensionTest (org.eclipse.jetty.websocket.common.extensions.AbstractExtensionTest)2