修复bytehelper & VlInt中的已知bug

This commit is contained in:
ghy committed 2021-03-15 20:46:03 +08:00
1 parent 227d10a391
commit 2ad446ca2c
29 files changed
+315 -80

No files matched your search

+6 -8
View File
@@ -14,8 +14,7 @@ import static org.junit.Assert.*;
*/public class ByteHelperTest {
@Test
public void getTailBytes(){
ByteHelper byteHelper = new ByteHelper();
public void getTailBytes() throws ByteHelperException {
//偶数字节
byte[] buffer = new byte[]{0x00,0x01,(byte) 0x80,0x7f}; //1
byte[] test1 = new byte[]{0x01,(byte) 0x80,0x7f};
@@ -23,16 +22,15 @@ import static org.junit.Assert.*;
byte[] buffer2 = new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,(byte) 0xff, (byte) 0xff}; //65535
byte[] test2 = new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,(byte) 0xff, (byte) 0xff}; //65535
int startIndex = 1;
byte[] b = byteHelper.getTailBytes(buffer,startIndex);
byte[] b2 = byteHelper.getTailBytes(buffer2,startIndex);
byte[] b = ByteHelper.getTailBytes(buffer,startIndex);
byte[] b2 = ByteHelper.getTailBytes(buffer2,startIndex);
assertArrayEquals(b,test1);
assertArrayEquals(b2,test2);
}
//todo:对start值进行限定,应当小于Byte数组的length
@Test
public void getFirstByte() {
byte[] b0 = new byte[]{0x00,0x00,0x01};
public void getFirstByte() throws ByteHelperException {
byte[] b0 = new byte[]{0x00,0x00,1};
byte[] test = new byte[]{0x7f,0x7f,0x7f,0x7f};
VlInt start0 = new VlInt(b0);
byte firstbyte = ByteHelper.getFirstByte(test,start0);
@@ -41,7 +39,7 @@ import static org.junit.Assert.*;
@Test
public void getLenBytes() {
public void getLenBytes() throws ByteHelperException {
byte[] buffer = new byte[]{0x00,0x00,0x01, (byte) 0xff}; //255
byte[] test = new byte[]{0x00,0x00,0x01};
VlInt start = new VlInt(0);