add test: IdentifierComponentTest

This commit is contained in:
free will committed 2021-03-29 15:26:20 +08:00
1 parent 36c735bc3f
commit 186d7a48f7
5 files changed
+257 -8

No files matched your search

@@ -0,0 +1,128 @@
package component;
import encoding.Block;
import encoding.BlockException;
import encoding.VlInt;
import org.junit.Test;
import util.ByteHelper;
import java.util.Arrays;
/*
* @Author: Wang Feng
* @Description:
* @Version: 1.0.0
* @Date: 9:07 2021/3/26
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class IdentifierComponentTest {
//判断空字符串能否正常运行
@Test
public void TestCreateIdentifierComponentByString(){
String str="";
IdentifierComponent got=new IdentifierComponent(str);
byte gotMaker=got.getMarker();
String gotStr=got.getString();
long gotInt=got.getNonNegativeInteger();
byte[] gotByte=got.getByteArray();
System.out.println("maker: "+gotMaker+" ,str: "+gotStr
+" ,int: "+gotInt+" ,byte: "+Arrays.toString(gotByte)+" ,value: "
+ Arrays.toString(got.getBlock().getValue()));
System.out.println("isStr: "+got.isString()+" ,isInt: "+got.isNonNegativeInteger()
+" ,isByte: "+got.isByteArray());
}
//测试最大值是否正常运行
@Test
public void TestCreateIdentifierComponentByNonNegativeInteger(){
long l=Long.MAX_VALUE;
// System.out.println(ByteHelper);
IdentifierComponent got=new IdentifierComponent(l);
byte gotMaker=got.getMarker();
String gotStr=got.getString();
long gotInt=got.getNonNegativeInteger();
byte[] gotByte=got.getByteArray();
System.out.println("maker: "+gotMaker+" ,str: "+gotStr
+" ,int: "+gotInt+" ,byte: "+Arrays.toString(gotByte)+" ,value: "
+ Arrays.toString(got.getBlock().getValue()));
System.out.println("isStr: "+got.isString()+" ,isInt: "+got.isNonNegativeInteger()
+" ,isByte: "+got.isByteArray());
}
// 根据一个字节数组构造一个 IdentifierComponent
@Test
public void CreateIdentifierComponentByByteArray(){
byte[] genbyte={};
IdentifierComponent got=new IdentifierComponent(genbyte);
byte gotMaker=got.getMarker();
String gotStr=got.getString();
long gotInt=got.getNonNegativeInteger();
byte[] gotByte=got.getByteArray();
System.out.println("maker: "+gotMaker+" ,str: "+gotStr
+" ,int: "+gotInt+" ,byte: "+Arrays.toString(gotByte)+" ,value: "
+ Arrays.toString(got.getBlock().getValue()));
System.out.println("isStr: "+got.isString()+" ,isInt: "+got.isNonNegativeInteger()
+" ,isByte: "+got.isByteArray());
}
@Test
public void TestCreateIdentifierComponentByBlock() throws BlockException, ComponentException {
byte[] buf=new byte[8001];
buf[0]=0x02;
Block block=new Block(new VlInt(241),new VlInt(8001),buf,true);
IdentifierComponent got=new IdentifierComponent(block);
byte gotMaker=got.getMarker();
String gotStr=got.getString();
long gotInt=got.getNonNegativeInteger();
byte[] gotByte=got.getByteArray();
System.out.println("maker: "+gotMaker+" ,str: "+gotStr
+" ,int: "+gotInt+" ,byte length: "+gotByte.length+" ,byte: "
+Arrays.toString(gotByte)+" ,value: "
+ Arrays.toString(got.getBlock().getValue()));
System.out.println("isStr: "+got.isString()+" ,isInt: "+got.isNonNegativeInteger()
+" ,isByte: "+got.isByteArray());
}
@Test
public void TestIdentifier_WireDecode() throws BlockException, ComponentException {
TestCreateIdentifierComponentByBlock();
}
@Test
public void TestCreateVersionNumberIdentifierComponent(){
long genInt=Long.MAX_VALUE;
IdentifierComponent got=new IdentifierComponent();
got.buildVersionNumberIdentifierComponent(genInt);
byte gotMaker=got.getMarker();
String gotStr=got.getString();
long gotInt=got.getNonNegativeInteger();
byte[] gotByte=got.getByteArray();
System.out.println("maker: "+gotMaker+" ,str: "+gotStr
+" ,int: "+gotInt
// +" ,byte length: " +gotByte.length
+" ,byte: "+Arrays.toString(gotByte)
+" ,value: " + Arrays.toString(got.getBlock().getValue()));
System.out.println("isStr: "+got.isString()+" ,isInt: "+got.isNonNegativeInteger()
+" ,isByte: "+got.isByteArray()+" ,isVersion: "+got.isVersionNumber()
+" ,isFrame: "+got.isFragmentNumber());
}
@Test
public void TestCreateFragmentNumberIdentifierComponent(){
long genInt=Long.MAX_VALUE;
IdentifierComponent got=new IdentifierComponent();
got.buildFragmentNumberIdentifierComponent(genInt);
byte gotMaker=got.getMarker();
String gotStr=got.getString();
long gotInt=got.getNonNegativeInteger();
byte[] gotByte=got.getByteArray();
System.out.println("maker: "+gotMaker+" ,str: "+gotStr
+" ,int: "+gotInt
// +" ,byte length: " +gotByte.length
+" ,byte: "+Arrays.toString(gotByte)
+" ,value: " + Arrays.toString(got.getBlock().getValue()));
System.out.println("isStr: "+got.isString()+" ,isInt: "+got.isNonNegativeInteger()
+" ,isByte: "+got.isByteArray()+" ,isVersion: "+got.isVersionNumber()
+" ,isFrame: "+got.isFragmentNumber());
}
}