primitive tests

This commit is contained in:
David Renshaw 2014-05-24 22:03:39 -04:00
parent 6ba7d63959
commit adfa3cf29d
2 changed files with 15 additions and 5 deletions

View file

@ -42,9 +42,9 @@ public final class StructReader {
} }
} }
public final byte getShortField(int offset) { public final short getShortField(int offset) {
if ((offset + 1) * 16 <= this.dataSize) { if ((offset + 1) * 16 <= this.dataSize) {
return this.segment.buffer.get(this.data + offset * 2); return this.segment.buffer.getShort(this.data + offset * 2);
} else { } else {
return 0; return 0;
} }

View file

@ -11,9 +11,8 @@ public class LayoutTest {
@Test @Test
public void simpleRawDataStruct() { public void simpleRawDataStruct() {
byte[] data = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, byte[] data = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, (byte)0x89, (byte)0xab,
(byte)(0x89 & 0xff), (byte)(0xab & 0xff), (byte)0xcd, (byte)0xef};
(byte)(0xcd & 0xff), (byte)(0xef & 0xff)};
ByteBuffer buffer = ByteBuffer.wrap(data); ByteBuffer buffer = ByteBuffer.wrap(data);
buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN); buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN);
@ -21,6 +20,17 @@ public class LayoutTest {
StructReader reader = pointerReader.getStruct(); StructReader reader = pointerReader.getStruct();
assertThat(reader.getLongField(0), equalTo(0xefcdab8967452301L)); assertThat(reader.getLongField(0), equalTo(0xefcdab8967452301L));
assertThat(reader.getLongField(1), equalTo(0L));
assertThat(reader.getIntField(0), equalTo(0x67452301));
assertThat(reader.getIntField(1), equalTo(0xefcdab89));
assertThat(reader.getIntField(2), equalTo(0));
assertThat(reader.getShortField(0), equalTo((short) 0x2301));
assertThat(reader.getShortField(1), equalTo((short)0x6745));
assertThat(reader.getShortField(2), equalTo((short)0xab89));
assertThat(reader.getShortField(3), equalTo((short)0xefcd));
assertThat(reader.getShortField(4), equalTo((short)0));
// TODO masking
} }