Basic implementation of Binary struct parsing
This commit is contained in:
parent
da54bc8db5
commit
b7bedc94cd
5 changed files with 123 additions and 6 deletions
24
test/zutil/test/ByteUtilTest.java
Executable file
24
test/zutil/test/ByteUtilTest.java
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
package zutil.test;
|
||||
|
||||
import org.junit.Test;
|
||||
import zutil.ByteUtil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2016-01-31.
|
||||
*/
|
||||
public class ByteUtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void getBits(){
|
||||
assertEquals(1, ByteUtil.getBits((byte)0b1000_0000, 7, 1));
|
||||
assertEquals(1, ByteUtil.getBits((byte)0b0001_0000, 4, 1));
|
||||
assertEquals(1, ByteUtil.getBits((byte)0b0000_0001, 0, 1));
|
||||
|
||||
assertEquals(3, ByteUtil.getBits((byte)0b0110_0000, 6, 2));
|
||||
|
||||
assertEquals((byte)0xFF, ByteUtil.getBits((byte)0b1111_1111, 7, 8));
|
||||
}
|
||||
}
|
||||
10
test/zutil/test/ConverterTest.java
Normal file → Executable file
10
test/zutil/test/ConverterTest.java
Normal file → Executable file
|
|
@ -77,4 +77,14 @@ public class ConverterTest {
|
|||
Converter.urlDecode("9i34%202y9252%25%2623%20463765(%2f%26(") );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void byteArrayToInt(){
|
||||
assertEquals(0, Converter.toInt(new byte[]{}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0b0000_0001}));
|
||||
assertEquals(1, Converter.toInt(new byte[]{0x01,0x00}));
|
||||
assertEquals(256, Converter.toInt(new byte[]{0x00,0x01,0x00}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F}));
|
||||
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F,(byte)0xFF,(byte)0xFF}));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue