mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
fixed some test error
This commit is contained in:
1 parent
fc3671ea00
commit
5785f29ec3
12 files changed
+118
-59
No files matched your search
@@ -16,7 +16,7 @@ import static org.junit.Assert.*;
|
||||
public class BlockTest {
|
||||
|
||||
@Test
|
||||
public void TestCreateBlockByTypeLengthBuffer() throws VlIntException, EncoderException {
|
||||
public void TestCreateBlockByTypeLengthBuffer() throws VlIntException, EncoderException, BlockException {
|
||||
byte[] buf = new byte[10000];
|
||||
Block block = Block.createBlockByTypeLengthBuffer(new VlInt(241), new VlInt(8000),ByteHelper.getLenBytes(buf, new VlInt(0),8000),true);
|
||||
//测试type与size
|
||||
@@ -42,7 +42,7 @@ public class BlockTest {
|
||||
|
||||
//error:block.Size().size()错误。
|
||||
@Test
|
||||
public void TestCreateBlockByBuffer() throws VlIntException, EncoderException {
|
||||
public void TestCreateBlockByBuffer() throws VlIntException, EncoderException, BlockException {
|
||||
byte[] buf = new byte[10000];
|
||||
buf[0] = (byte)212;
|
||||
buf[1] = (byte)241;
|
||||
@@ -54,12 +54,12 @@ public class BlockTest {
|
||||
System.out.println("测试block.Size().size()");
|
||||
assertEquals(block.getLength().getVlIntValue2Int(),8000);
|
||||
//block.Size()返回一个SizeT,再调用SizeT.size()
|
||||
assertEquals(block.Size().size(),8004);
|
||||
assertEquals(block.Size().getVlIntValue2Int(),8004);
|
||||
assertTrue(block.hasValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestBuildByBlock() throws VlIntException, EncoderException {
|
||||
public void TestBuildByBlock() throws VlIntException, EncoderException, BlockException {
|
||||
//Block构造方法测试
|
||||
byte[] buf = new byte[10000];
|
||||
Block block1 = Block.createBlockByTypeLengthBuffer(new VlInt(241), new VlInt(8000),ByteHelper.getLenBytes(buf, new VlInt(0),8000),true);
|
||||
@@ -85,7 +85,7 @@ public class BlockTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestBuildByTypeLengthBuffer() throws VlIntException, EncoderException {
|
||||
public void TestBuildByTypeLengthBuffer() throws VlIntException, EncoderException, BlockException {
|
||||
//Block构造方法测试
|
||||
byte[] buf = new byte[10000];
|
||||
Block block = new Block(new VlInt(241),new VlInt(8000),ByteHelper.getLenBytes(buf,new VlInt(0),8000),true);
|
||||
@@ -109,31 +109,44 @@ public class BlockTest {
|
||||
assertEquals(rawBuf.length,8006);
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
byte a=(byte)254;
|
||||
System.out.println(a);
|
||||
}
|
||||
//error
|
||||
//TODO 错误处理
|
||||
@Test
|
||||
public void TestParseSubElements() throws EncoderException {
|
||||
public void TestParseSubElements() throws EncoderException, BlockException, VlIntException {
|
||||
byte[] buf = new byte[10000];
|
||||
for (int i = 0; i < 240; i++) {
|
||||
for (int i = 0; i < 24; i++) {
|
||||
buf[i*8] = (byte)(i+1);
|
||||
buf[i*8+1] = 6;
|
||||
}
|
||||
Block block = new Block(new VlInt(241),new VlInt(240*8),ByteHelper.getLenBytes(buf,new VlInt(0),240*8),true);
|
||||
Block block = new Block(new VlInt(241),new VlInt(24*8),ByteHelper.getLenBytes(buf,new VlInt(0),24*8),true);
|
||||
if(block.isValid()){
|
||||
System.out.println("true");
|
||||
}
|
||||
block.parseSubElements();
|
||||
//TODO 错误处理
|
||||
|
||||
ElementContainer elementContainer = block.getSubElements();
|
||||
//测试解析数据正确性
|
||||
for (int i = 0; i < elementContainer.length(); i++) {
|
||||
assertEquals(elementContainer.getBlock(i).getType(),new VlInt(i+1));
|
||||
assertEquals(elementContainer.getBlock(i).getLength(),new VlInt(6));
|
||||
// System.out.println(elementContainer.getBlock(i).getType().equals(new VlInt(i+1)));
|
||||
// System.out.println(elementContainer.getBlock(i).getLength().equals(new VlInt(6)));
|
||||
assertArrayEquals(elementContainer.getBlock(i).getType().getVlIntBytes(),new VlInt(i+1).getVlIntBytes());
|
||||
assertArrayEquals(elementContainer.getBlock(i).getLength().getVlIntBytes(),new VlInt(6).getVlIntBytes());
|
||||
assertEquals(elementContainer.getBlock(i).getType().getVlIntValue2Int(),new VlInt(i+1).getVlIntValue2Int());
|
||||
assertEquals(elementContainer.getBlock(i).getLength().getVlIntValue2Int(),new VlInt(6).getVlIntValue2Int());
|
||||
assertEquals(elementContainer.getBlock(i).getType().size(),new VlInt(i+1).size());
|
||||
assertEquals(elementContainer.getBlock(i).getLength().size(),new VlInt(6).size());
|
||||
}
|
||||
}
|
||||
|
||||
//error
|
||||
//TODO 没测完
|
||||
@Test
|
||||
public void TestSubElements() throws EncoderException {
|
||||
public void TestSubElements() throws EncoderException, BlockException {
|
||||
byte[] buf = new byte[10000];
|
||||
Block block = new Block();
|
||||
block.setType(new VlInt(7));
|
||||
@@ -144,6 +157,5 @@ public class BlockTest {
|
||||
// System.out.println("block.hasValue() = "+block.hasValue());
|
||||
// System.out.println("block.hasSubElement() = "+block.hasSubElement());
|
||||
ElementContainer elements = block.getSubElements();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import static org.junit.Assert.*;
|
||||
public class EncoderTest {
|
||||
int MaxPacketSize = 8800;
|
||||
@Test
|
||||
public void TestEmpty() {
|
||||
public void TestEmpty() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize),new SizeT(0));
|
||||
@@ -38,7 +38,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestEncoder_PrependByte(){
|
||||
public void TestEncoder_PrependByte() throws EncoderException, VlIntException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize),new SizeT(0));
|
||||
@@ -78,7 +78,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestEncoder_AppendByte(){
|
||||
public void TestEncoder_AppendByte() throws EncoderException, VlIntException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(MaxPacketSize));
|
||||
@@ -109,7 +109,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestEncoder_PrependByteArray(){
|
||||
public void TestEncoder_PrependByteArray() throws EncoderException, VlIntException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize),new SizeT(0));
|
||||
@@ -142,7 +142,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestEncoder_AppendByteArray(){
|
||||
public void TestEncoder_AppendByteArray() throws EncoderException, VlIntException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(MaxPacketSize));
|
||||
@@ -179,7 +179,7 @@ public class EncoderTest {
|
||||
|
||||
//error
|
||||
@Test
|
||||
public void TestPrependVarNumber(){
|
||||
public void TestPrependVarNumber() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize),new SizeT(0));
|
||||
@@ -228,7 +228,7 @@ public class EncoderTest {
|
||||
assertEquals(num3,4294967296L);
|
||||
|
||||
// TODO 测试添加64位整型所能表示的最大值
|
||||
// uint64最大值在java中无法表示
|
||||
// uint64最大值在java中无法表示=>用Long.MaxValue
|
||||
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public class EncoderTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void TestAppendVarNumber(){
|
||||
public void TestAppendVarNumber() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(MaxPacketSize));
|
||||
@@ -285,7 +285,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestPrependNonNegativeInteger(){
|
||||
public void TestPrependNonNegativeInteger() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(0));
|
||||
@@ -326,7 +326,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestAppendNonNegativeInteger(){
|
||||
public void TestAppendNonNegativeInteger() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(MaxPacketSize));
|
||||
@@ -373,7 +373,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestPrependByteArrayBlock(){
|
||||
public void TestPrependByteArrayBlock() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(0));
|
||||
@@ -410,7 +410,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestAppendByteArrayBlock(){
|
||||
public void TestAppendByteArrayBlock() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(MaxPacketSize));
|
||||
@@ -447,7 +447,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestPrependBlock(){
|
||||
public void TestPrependBlock() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(0));
|
||||
@@ -478,7 +478,7 @@ public class EncoderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestAppendBlock(){
|
||||
public void TestAppendBlock() throws EncoderException {
|
||||
Encoder encoder = new Encoder();
|
||||
Encoder estimator = new Encoder();
|
||||
encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(MaxPacketSize));
|
||||
|
||||
@@ -2,6 +2,7 @@ package others;
|
||||
|
||||
import component.CanBePrefix;
|
||||
import encoding.Block;
|
||||
import encoding.BlockException;
|
||||
import encoding.EncoderException;
|
||||
import encoding.SelfEncodingBase;
|
||||
|
||||
@@ -13,7 +14,7 @@ import encoding.SelfEncodingBase;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TestCallBack {
|
||||
public static void main(String[] args) throws EncoderException {
|
||||
public static void main(String[] args) throws EncoderException, BlockException {
|
||||
CanBePrefix canBePrefix=new CanBePrefix();
|
||||
Block block=new SelfEncodingBase().selfWireEncode(canBePrefix);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user