Esempio n. 1
0
  @Test
  public void testGenerate125ByteBinaryCase1_2_2() {
    int length = 125;

    ByteBuffer bb = ByteBuffer.allocate(length);

    for (int i = 0; i < length; ++i) {
      bb.put("*".getBytes());
    }

    bb.flip();

    WebSocketFrame binaryFrame = WebSocketFrame.binary().setPayload(bb);

    Generator generator = new UnitGenerator();
    ByteBuffer actual = generator.generate(binaryFrame);

    ByteBuffer expected = ByteBuffer.allocate(length + 5);

    expected.put(new byte[] {(byte) 0x82});

    byte b = 0x00; // no masking
    b |= length & 0x7F;
    expected.put(b);

    for (int i = 0; i < length; ++i) {
      expected.put("*".getBytes());
    }

    BufferUtil.flipToFlush(expected, 0);

    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
  }
Esempio n. 2
0
  @Test
  public void testGenerateEmptyBinaryCase1_2_1() {
    WebSocketFrame binaryFrame = WebSocketFrame.binary(new byte[] {});

    Generator generator = new UnitGenerator();
    ByteBuffer actual = generator.generate(binaryFrame);

    ByteBuffer expected = ByteBuffer.allocate(5);

    expected.put(new byte[] {(byte) 0x82, (byte) 0x00});

    BufferUtil.flipToFlush(expected, 0);

    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
  }