Cleaning up test cases
This commit is contained in:
parent
e32249c24f
commit
fabb2e18a2
|
@ -1,113 +1,304 @@
|
|||
package org.eclipse.jetty.websocket.ab;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.StandardByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.ByteBufferAssert;
|
||||
import org.eclipse.jetty.websocket.Debug;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.generator.Generator;
|
||||
import org.eclipse.jetty.websocket.parser.FrameParseCapture;
|
||||
import org.eclipse.jetty.websocket.parser.Parser;
|
||||
import org.eclipse.jetty.websocket.parser.TextPayloadParser;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Text Message Spec testing the {@link Generator} and {@link Parser}
|
||||
*/
|
||||
public class ABCase1_1
|
||||
{
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
private WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
|
||||
@Test
|
||||
public void testGenerate125ByteTextCase1_1_2()
|
||||
{
|
||||
int length = 125;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 16);
|
||||
generator.generate(actual,textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7F;
|
||||
expected.put(b);
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate126ByteTextCase1_1_3()
|
||||
{
|
||||
int length = 126;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 16);
|
||||
generator.generate(actual,textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
// expected.put((byte)((length>>8) & 0xFF));
|
||||
// expected.put((byte)(length & 0xFF));
|
||||
expected.putShort((short)length);
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate127ByteTextCase1_1_4()
|
||||
{
|
||||
int length = 127;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 16);
|
||||
generator.generate(actual,textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
// expected.put((byte)((length>>8) & 0xFF));
|
||||
// expected.put((byte)(length & 0xFF));
|
||||
expected.putShort((short)length);
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate128ByteTextCase1_1_5()
|
||||
{
|
||||
int length = 128;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 16);
|
||||
generator.generate(actual,textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
expected.put((byte)(length >> 8));
|
||||
expected.put((byte)(length & 0xFF));
|
||||
// expected.putShort((short)length);
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate65535ByteTextCase1_1_6()
|
||||
{
|
||||
int length = 65535;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 16);
|
||||
generator.generate(actual,textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
expected.put(new byte[]
|
||||
{ (byte)0xff, (byte)0xff });
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate65536ByteTextCase1_1_7()
|
||||
{
|
||||
int length = 65536;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 16);
|
||||
generator.generate(actual,textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
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());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateEmptyTextCase1_1_1()
|
||||
{
|
||||
TextFrame textFrame = new TextFrame("");
|
||||
textFrame.setFin(true);
|
||||
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(10);
|
||||
generator.generate(actual, textFrame);
|
||||
generator.generate(actual,textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81, (byte)0x00 });
|
||||
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyTextCase1_1_1()
|
||||
{
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81, (byte)0x00 });
|
||||
|
||||
expected.flip();
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",0,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate125ByteTextCase1_1_2()
|
||||
{
|
||||
int length = 125;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length+16);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7F;
|
||||
expected.put(b);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse125ByteTextCase1_1_2()
|
||||
{
|
||||
|
@ -120,71 +311,27 @@ public class ABCase1_1
|
|||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7F;
|
||||
expected.put(b);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate126ByteTextCase1_1_3()
|
||||
{
|
||||
int length = 126;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length+16);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
//expected.put((byte)((length>>8) & 0xFF));
|
||||
//expected.put((byte)(length & 0xFF));
|
||||
expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse126ByteTextCase1_1_3()
|
||||
{
|
||||
|
@ -199,70 +346,26 @@ public class ABCase1_1
|
|||
expected.put(b);
|
||||
expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate127ByteTextCase1_1_4()
|
||||
{
|
||||
int length = 127;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length+16);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
//expected.put((byte)((length>>8) & 0xFF));
|
||||
//expected.put((byte)(length & 0xFF));
|
||||
expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse127ByteTextCase1_1_4()
|
||||
{
|
||||
|
@ -277,70 +380,26 @@ public class ABCase1_1
|
|||
expected.put(b);
|
||||
expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate128ByteTextCase1_1_5()
|
||||
{
|
||||
int length = 128;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length+16);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
expected.put((byte)(length>>8));
|
||||
expected.put((byte)(length & 0xFF));
|
||||
//expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse128ByteTextCase1_1_5()
|
||||
{
|
||||
|
@ -355,72 +414,31 @@ public class ABCase1_1
|
|||
expected.put(b);
|
||||
expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate65535ByteTextCase1_1_6()
|
||||
{
|
||||
int length = 65535;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length+16);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
expected.put(new byte[]{ (byte)0xff, (byte)0xff});
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse65535ByteTextCase1_1_6()
|
||||
{
|
||||
//Debug.enableDebugLogging(Parser.class);
|
||||
//Debug.enableDebugLogging(TextPayloadParser.class);
|
||||
// Debug.enableDebugLogging(Parser.class);
|
||||
// Debug.enableDebugLogging(TextPayloadParser.class);
|
||||
|
||||
int length = 65535;
|
||||
|
||||
|
@ -431,13 +449,14 @@ public class ABCase1_1
|
|||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
expected.put(new byte[]{ (byte)0xff, (byte)0xff});
|
||||
expected.put(new byte[]
|
||||
{ (byte)0xff, (byte)0xff });
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
policy.setMaxTextMessageSize(length);
|
||||
|
@ -445,58 +464,15 @@ public class ABCase1_1
|
|||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerate65536ByteTextCase1_1_7()
|
||||
{
|
||||
int length = 65536;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
builder.append("*");
|
||||
}
|
||||
|
||||
TextFrame textFrame = new TextFrame(builder.toString());
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length+16);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
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());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse65536ByteTextCase1_1_7()
|
||||
{
|
||||
|
@ -509,27 +485,52 @@ public class ABCase1_1
|
|||
byte b = 0x00; // no masking
|
||||
b |= 0x7F;
|
||||
expected.put(b);
|
||||
expected.put(new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00});
|
||||
expected.put(new byte[]
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 });
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
policy.setMaxTextMessageSize(length);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyTextCase1_1_1()
|
||||
{
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x81, (byte)0x00 });
|
||||
|
||||
expected.flip();
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(TextFrame.class,1);
|
||||
|
||||
TextFrame pActual = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
ByteBufferAssert.assertSize("TextFrame.payload",0,pActual.getPayload());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,91 +1,41 @@
|
|||
package org.eclipse.jetty.websocket.ab;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.StandardByteBufferPool;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.websocket.ByteBufferAssert;
|
||||
import org.eclipse.jetty.websocket.Debug;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BinaryFrame;
|
||||
import org.eclipse.jetty.websocket.frames.TextFrame;
|
||||
import org.eclipse.jetty.websocket.generator.Generator;
|
||||
import org.eclipse.jetty.websocket.parser.FrameParseCapture;
|
||||
import org.eclipse.jetty.websocket.parser.Parser;
|
||||
import org.eclipse.jetty.websocket.parser.TextPayloadParser;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Binary Message Spec testing the {@link Generator} and {@link Parser}
|
||||
*/
|
||||
public class ABCase1_2
|
||||
{
|
||||
StandardByteBufferPool bufferPool = new StandardByteBufferPool();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
|
||||
private WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
|
||||
@Test
|
||||
public void testGenerateEmptyBinaryCase1_2_1()
|
||||
{
|
||||
BinaryFrame binaryFrame = new BinaryFrame(new byte[]{});
|
||||
binaryFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
generator.generate(actual, binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82, (byte)0x00 });
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyBinaryCase1_2_1()
|
||||
{
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82, (byte)0x00 });
|
||||
|
||||
expected.flip();
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",0,pActual.getPayload());
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
|
||||
BinaryFrame binaryFrame = new BinaryFrame( BufferUtil.toArray(bb) );
|
||||
binaryFrame.setFin(true);
|
||||
|
||||
|
@ -94,109 +44,314 @@ public class ABCase1_2
|
|||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
|
||||
generator.generate(actual, 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());
|
||||
}
|
||||
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse125ByteBinaryCase1_2_2()
|
||||
{
|
||||
int length = 125;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
expected.flip();
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerate126ByteBinaryCase1_2_3()
|
||||
{
|
||||
int length = 126;
|
||||
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
bb.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
bb.flip();
|
||||
|
||||
|
||||
BinaryFrame binaryFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
binaryFrame.setFin(true);
|
||||
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
|
||||
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
|
||||
|
||||
generator.generate(actual, binaryFrame);
|
||||
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
//expected.put((byte)((length>>8) & 0xFF));
|
||||
//expected.put((byte)(length & 0xFF));
|
||||
|
||||
//expected.put((byte)((length>>8) & 0xFF));
|
||||
//expected.put((byte)(length & 0xFF));
|
||||
expected.putShort((short)length);
|
||||
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenerate127ByteBinaryCase1_2_4()
|
||||
{
|
||||
int length = 127;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
bb.put("*".getBytes());
|
||||
|
||||
}
|
||||
|
||||
bb.flip();
|
||||
|
||||
BinaryFrame binaryFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
binaryFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
generator.generate(actual, binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
//expected.put((byte)((length>>8) & 0xFF));
|
||||
//expected.put((byte)(length & 0xFF));
|
||||
expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
BinaryFrame textFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
expected.put((byte)(length>>8));
|
||||
expected.put((byte)(length & 0xFF));
|
||||
//expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
BinaryFrame textFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
expected.put(new byte[]{ (byte)0xff, (byte)0xff});
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
BinaryFrame textFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 32);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
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());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateEmptyBinaryCase1_2_1()
|
||||
{
|
||||
BinaryFrame binaryFrame = new BinaryFrame(new byte[]{});
|
||||
binaryFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
generator.generate(actual, binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82, (byte)0x00 });
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse125ByteBinaryCase1_2_2()
|
||||
{
|
||||
int length = 125;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
expected.flip();
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse126ByteBinaryCase1_2_3()
|
||||
{
|
||||
|
@ -215,70 +370,22 @@ public class ABCase1_2
|
|||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerate127ByteBinaryCase1_2_4()
|
||||
{
|
||||
int length = 127;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.allocate(length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i)
|
||||
{
|
||||
bb.put("*".getBytes());
|
||||
|
||||
}
|
||||
|
||||
bb.flip();
|
||||
|
||||
BinaryFrame binaryFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
binaryFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
generator.generate(actual, binaryFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= length & 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
//expected.put((byte)((length>>8) & 0xFF));
|
||||
//expected.put((byte)(length & 0xFF));
|
||||
expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse127ByteBinaryCase1_2_4()
|
||||
{
|
||||
|
@ -297,68 +404,22 @@ public class ABCase1_2
|
|||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@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();
|
||||
BinaryFrame textFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
|
||||
expected.put((byte)(length>>8));
|
||||
expected.put((byte)(length & 0xFF));
|
||||
//expected.putShort((short)length);
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse128ByteBinaryCase1_2_5()
|
||||
{
|
||||
|
@ -377,69 +438,25 @@ public class ABCase1_2
|
|||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
BinaryFrame textFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 11);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
b |= 0x7E;
|
||||
expected.put(b);
|
||||
expected.put(new byte[]{ (byte)0xff, (byte)0xff});
|
||||
|
||||
for ( int i = 0 ; i < length ; ++i )
|
||||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse65535ByteBinaryCase1_2_6()
|
||||
{
|
||||
{
|
||||
int length = 65535;
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 5);
|
||||
|
@ -455,7 +472,7 @@ public class ABCase1_2
|
|||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
policy.setMaxTextMessageSize(length);
|
||||
|
@ -463,61 +480,16 @@ public class ABCase1_2
|
|||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
|
||||
BinaryFrame textFrame = new BinaryFrame(BufferUtil.toArray(bb));
|
||||
textFrame.setFin(true);
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(length + 32);
|
||||
generator.generate(actual, textFrame);
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(length + 11);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82 });
|
||||
|
||||
byte b = 0x00; // no masking
|
||||
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());
|
||||
}
|
||||
|
||||
actual.flip();
|
||||
expected.flip();
|
||||
|
||||
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse65536ByteBinaryCase1_2_7()
|
||||
{
|
||||
|
@ -536,21 +508,45 @@ public class ABCase1_2
|
|||
{
|
||||
expected.put("*".getBytes());
|
||||
}
|
||||
|
||||
|
||||
expected.flip();
|
||||
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
policy.setMaxTextMessageSize(length);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(length));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",length,pActual.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyBinaryCase1_2_1()
|
||||
{
|
||||
|
||||
ByteBuffer expected = ByteBuffer.allocate(5);
|
||||
|
||||
expected.put(new byte[]
|
||||
{ (byte)0x82, (byte)0x00 });
|
||||
|
||||
expected.flip();
|
||||
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(BinaryFrame.class,1);
|
||||
|
||||
BinaryFrame pActual = (BinaryFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("BinaryFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
ByteBufferAssert.assertSize("BinaryFrame.payload",0,pActual.getPayload());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import static org.hamcrest.Matchers.*;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.Debug;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
|
@ -18,8 +17,6 @@ public class ClosePayloadParserTest
|
|||
@Test
|
||||
public void testGameOver()
|
||||
{
|
||||
Debug.enableDebugLogging(Parser.class);
|
||||
Debug.enableDebugLogging(ClosePayloadParser.class);
|
||||
String expectedReason = "Game Over";
|
||||
|
||||
byte utf[] = expectedReason.getBytes(StringUtil.__UTF8_CHARSET);
|
||||
|
|
Loading…
Reference in New Issue