mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add test: MutableFieldTest
This commit is contained in:
1 parent
03672a15dc
commit
36c735bc3f
1 file changed
+77
@@ -0,0 +1,77 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 21:37 2021/3/25
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class MutableFieldTest {
|
||||
@Test
|
||||
public void TestMutableField_WireEncode() throws BlockException, EncoderException, ComponentException {
|
||||
MutableProtectField mutableP=new MutableProtectField();
|
||||
byte[] bufP={(byte)1, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block blockP=new Block(bufP,false);
|
||||
byte[] buf1P={(byte)2,(byte)0};
|
||||
Block block1P=new Block(buf1P,false);
|
||||
mutableP.addBlock(blockP);
|
||||
mutableP.addBlock(block1P);
|
||||
MutableDangerousField mutableD=new MutableDangerousField();
|
||||
byte[] buf={(byte)3, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)4,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableD.addBlock(block);
|
||||
mutableD.addBlock(block1);
|
||||
|
||||
MutableField mutableField=new MutableField();
|
||||
mutableField.mutableProtectField=mutableP;
|
||||
mutableField.mutableDangerousField=mutableD;
|
||||
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
mutableField.wireEncode(encoder);
|
||||
byte[] buff=encoder.getBuffer();
|
||||
System.out.println(Arrays.toString(buff));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableField_WireDecode() throws EncoderException, ComponentException, BlockException {
|
||||
MutableProtectField mutableP=new MutableProtectField();
|
||||
byte[] bufP={(byte)1, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block blockP=new Block(bufP,false);
|
||||
byte[] buf1P={(byte)2,(byte)0};
|
||||
Block block1P=new Block(buf1P,false);
|
||||
mutableP.addBlock(blockP);
|
||||
mutableP.addBlock(block1P);
|
||||
MutableDangerousField mutableD=new MutableDangerousField();
|
||||
byte[] buf={(byte)3, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)4,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableD.addBlock(block);
|
||||
mutableD.addBlock(block1);
|
||||
|
||||
MutableField mutableField=new MutableField();
|
||||
mutableField.mutableProtectField=mutableP;
|
||||
mutableField.mutableDangerousField=mutableD;
|
||||
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
mutableField.wireEncode(encoder);
|
||||
byte[] buff=encoder.getBuffer();
|
||||
System.out.println(Arrays.toString(buff));
|
||||
|
||||
Block block2=new Block(buff,false);
|
||||
MutableField mutableField1=new MutableField();
|
||||
mutableField1.wireDecode(block2);
|
||||
System.out.println(mutableField1.mutableProtectField.getBlocks().length());
|
||||
System.out.println(mutableField1.mutableDangerousField.getBlocks().length());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user