test improvement

This commit is contained in:
Jesse McConnell 2012-07-10 14:13:09 -05:00
parent b46ba628cd
commit 4fed53ce85
3 changed files with 24 additions and 22 deletions

View File

@ -145,7 +145,12 @@ public class Generator
*/
if (frame.getOpCode() == OpCode.CLOSE)
{
new CloseInfo(frame.getPayload(),true);
ByteBuffer payload = frame.getPayload();
if (payload != null)
{
new CloseInfo(payload,true);
}
}
}

View File

@ -11,6 +11,7 @@ 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.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.UnitGenerator;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Assert;
import org.junit.Test;
@ -36,7 +37,7 @@ public class TestABCase1_1
WebSocketFrame textFrame = WebSocketFrame.text(builder.toString());
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -74,7 +75,7 @@ public class TestABCase1_1
WebSocketFrame textFrame = WebSocketFrame.text(builder.toString());
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -116,7 +117,7 @@ public class TestABCase1_1
WebSocketFrame textFrame = WebSocketFrame.text(builder.toString());
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -158,7 +159,7 @@ public class TestABCase1_1
WebSocketFrame textFrame = WebSocketFrame.text(builder.toString());
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -200,7 +201,8 @@ public class TestABCase1_1
WebSocketFrame textFrame = WebSocketFrame.text(builder.toString());
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -240,7 +242,7 @@ public class TestABCase1_1
WebSocketFrame textFrame = WebSocketFrame.text(builder.toString());
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 11);
@ -271,7 +273,7 @@ public class TestABCase1_1
{
WebSocketFrame textFrame = WebSocketFrame.text("");
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(textFrame);
ByteBuffer expected = ByteBuffer.allocate(5);

View File

@ -12,6 +12,7 @@ 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.protocol.OpCode;
import org.eclipse.jetty.websocket.protocol.UnitGenerator;
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
import org.junit.Assert;
import org.junit.Test;
@ -39,7 +40,7 @@ public class TestABCase1_2
WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb));
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(binaryFrame);
@ -57,7 +58,7 @@ public class TestABCase1_2
expected.put("*".getBytes());
}
actual.flip();
// BufferUtil.flipToFlush(actual,0);
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
@ -80,7 +81,7 @@ public class TestABCase1_2
WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb));
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -101,7 +102,6 @@ public class TestABCase1_2
expected.put("*".getBytes());
}
actual.flip();
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
@ -125,7 +125,7 @@ public class TestABCase1_2
WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb));
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -146,7 +146,6 @@ public class TestABCase1_2
expected.put("*".getBytes());
}
actual.flip();
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
@ -169,7 +168,7 @@ public class TestABCase1_2
bb.flip();
WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb));
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -190,7 +189,6 @@ public class TestABCase1_2
expected.put("*".getBytes());
}
actual.flip();
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
@ -214,7 +212,7 @@ public class TestABCase1_2
WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb));
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
@ -232,7 +230,6 @@ public class TestABCase1_2
expected.put("*".getBytes());
}
actual.flip();
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
@ -256,7 +253,7 @@ public class TestABCase1_2
WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb));
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 11);
@ -275,7 +272,6 @@ public class TestABCase1_2
expected.put("*".getBytes());
}
actual.flip();
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);
@ -287,7 +283,7 @@ public class TestABCase1_2
{
WebSocketFrame binaryFrame = WebSocketFrame.binary(new byte[] {});
Generator generator = new Generator(policy);
Generator generator = new UnitGenerator();
ByteBuffer actual = generator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(5);
@ -295,7 +291,6 @@ public class TestABCase1_2
expected.put(new byte[]
{ (byte)0x82, (byte)0x00 });
actual.flip();
expected.flip();
ByteBufferAssert.assertEquals("buffers do not match",expected,actual);