Ejemplo n.º 1
0
  /**
   * Similar to the server side 6.2.3 testcase. Lots of small 1 byte UTF8 Text frames, representing
   * 1 overall text message.
   */
  @Test
  public void testParseCase6_2_3() {
    String utf8 = "Hello-\uC2B5@\uC39F\uC3A4\uC3BC\uC3A0\uC3A1-UTF-8!!";
    byte msg[] = StringUtil.getUtf8Bytes(utf8);

    List<WebSocketFrame> send = new ArrayList<>();
    int len = msg.length;
    byte opcode = OpCode.TEXT;
    byte mini[];
    for (int i = 0; i < len; i++) {
      WebSocketFrame frame = new WebSocketFrame(opcode);
      mini = new byte[1];
      mini[0] = msg[i];
      frame.setPayload(mini);
      boolean isLast = (i >= (len - 1));
      frame.setFin(isLast);
      send.add(frame);
      opcode = OpCode.CONTINUATION;
    }
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());

    ByteBuffer completeBuf = UnitGenerator.generate(send);
    UnitParser parser = new UnitParser();
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(completeBuf);

    capture.assertErrorCount(0);
    capture.assertHasFrame(OpCode.TEXT, len);
    capture.assertHasFrame(OpCode.CLOSE, 1);
  }
Ejemplo n.º 2
0
 /** Parse, but be quiet about stack traces */
 private void parseQuietly(UnitParser parser, ByteBuffer buf) {
   LogShush.disableStacks(Parser.class);
   try {
     parser.parse(buf);
   } finally {
     LogShush.enableStacks(Parser.class);
   }
 }
Ejemplo n.º 3
0
  /** Similar to the server side 5.6 testcase. pong, then text, then close frames. */
  @Test
  public void testParseCase5_6() {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(WebSocketFrame.pong().setPayload("ping"));
    send.add(WebSocketFrame.text("hello, world"));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());

    ByteBuffer completeBuf = UnitGenerator.generate(send);
    UnitParser parser = new UnitParser();
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(completeBuf);

    capture.assertErrorCount(0);
    capture.assertHasFrame(OpCode.TEXT, 1);
    capture.assertHasFrame(OpCode.CLOSE, 1);
    capture.assertHasFrame(OpCode.PONG, 1);
  }