Search in sources :

Example 31 with BinaryFrame

use of org.eclipse.jetty.websocket.common.frames.BinaryFrame in project jetty.project by eclipse.

the class TestABCase1_2 method testGenerate128ByteBinaryCase1_2_5.

@Test
public void testGenerate128ByteBinaryCase1_2_5() {
    int length = 128;
    ByteBuffer bb = ByteBuffer.allocate(length);
    for (int i = 0; i < length; ++i) {
        bb.put("*".getBytes());
    }
    bb.flip();
    WebSocketFrame binaryFrame = new BinaryFrame().setPayload(bb);
    ByteBuffer actual = UnitGenerator.generate(binaryFrame);
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x82 });
    // no masking
    byte b = 0x00;
    b |= 0x7E;
    expected.put(b);
    expected.put((byte) (length >> 8));
    expected.put((byte) (length & 0xFF));
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    BufferUtil.flipToFlush(expected, 0);
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 32 with BinaryFrame

use of org.eclipse.jetty.websocket.common.frames.BinaryFrame in project jetty.project by eclipse.

the class TestABCase1_2 method testGenerate65535ByteBinaryCase1_2_6.

@Test
public void testGenerate65535ByteBinaryCase1_2_6() {
    int length = 65535;
    ByteBuffer bb = ByteBuffer.allocate(length);
    for (int i = 0; i < length; ++i) {
        bb.put("*".getBytes());
    }
    bb.flip();
    WebSocketFrame binaryFrame = new BinaryFrame().setPayload(bb);
    ByteBuffer actual = UnitGenerator.generate(binaryFrame);
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x82 });
    // no masking
    byte b = 0x00;
    b |= 0x7E;
    expected.put(b);
    expected.put(new byte[] { (byte) 0xff, (byte) 0xff });
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    BufferUtil.flipToFlush(expected, 0);
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 33 with BinaryFrame

use of org.eclipse.jetty.websocket.common.frames.BinaryFrame in project jetty.project by eclipse.

the class TestABCase1_2 method testGenerate65536ByteBinaryCase1_2_7.

@Test
public void testGenerate65536ByteBinaryCase1_2_7() {
    int length = 65536;
    ByteBuffer bb = ByteBuffer.allocate(length);
    for (int i = 0; i < length; ++i) {
        bb.put("*".getBytes());
    }
    bb.flip();
    WebSocketFrame binaryFrame = new BinaryFrame().setPayload(bb);
    ByteBuffer actual = UnitGenerator.generate(binaryFrame);
    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());
    }
    BufferUtil.flipToFlush(expected, 0);
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)33 Test (org.junit.Test)29 ByteBuffer (java.nio.ByteBuffer)25 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)25 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)16 ArrayList (java.util.ArrayList)15 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)15 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)5 Stress (org.eclipse.jetty.toolchain.test.annotation.Stress)4 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)4 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)3 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)2 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)2 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)2 AnnotatedFramesSocket (examples.AnnotatedFramesSocket)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Random (java.util.Random)1 RuntimeIOException (org.eclipse.jetty.io.RuntimeIOException)1 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)1