diff options
Diffstat (limited to 'src/junit/com/jogamp/common')
5 files changed, 61 insertions, 44 deletions
diff --git a/src/junit/com/jogamp/common/util/BitstreamData.java b/src/junit/com/jogamp/common/util/BitstreamData.java index 5a8bd46..a434053 100644 --- a/src/junit/com/jogamp/common/util/BitstreamData.java +++ b/src/junit/com/jogamp/common/util/BitstreamData.java @@ -115,9 +115,4 @@ public class BitstreamData { final int nibbles = 0 == bitCount ? 2 : ( bitCount + 3 ) / 4; return String.format("[%0"+nibbles+"X, %s]", v, toBinaryString(v, bitCount)); } - public static String toUnsignedBinaryString(final int int32) { - final long l = Bitstream.toUInt32Long(int32); - final int i = Bitstream.toUInt32Int(int32); - return "(long)"+l+", (int)"+i+", "+toHexBinaryString(l, 32); - } } diff --git a/src/junit/com/jogamp/common/util/TestBitstream00.java b/src/junit/com/jogamp/common/util/TestBitstream00.java index 767117b..d0c5613 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream00.java +++ b/src/junit/com/jogamp/common/util/TestBitstream00.java @@ -95,11 +95,12 @@ public class TestBitstream00 extends JunitTracer { @Test public void test01Uint32Conversion() { testUInt32Conversion(1, 1); + testUInt32Conversion(-2, -1); testUInt32Conversion(Integer.MAX_VALUE, Integer.MAX_VALUE); testUInt32Conversion(0xffff0000, -1); testUInt32Conversion(0xffffffff, -1); } - void testUInt32Conversion(final int int32, final int expUint32Int) { + void testUInt32Conversion(final int int32, final int expUInt32Int) { final String int32_hStr = toHexString(int32); final long l = Bitstream.toUInt32Long(int32); final String l_hStr = toHexString(l); @@ -107,7 +108,7 @@ public class TestBitstream00 extends JunitTracer { final String i_hStr = toHexString(i); System.err.printf("int32_t %012d %10s -> (long) %012d %10s, (int) %012d %10s%n", int32, int32_hStr, l, l_hStr, i, i_hStr); Assert.assertEquals(int32_hStr, l_hStr); - Assert.assertEquals(expUint32Int, i); + Assert.assertEquals(expUInt32Int, i); } @Test diff --git a/src/junit/com/jogamp/common/util/TestBitstream02.java b/src/junit/com/jogamp/common/util/TestBitstream02.java index dc7333c..b518df8 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream02.java +++ b/src/junit/com/jogamp/common/util/TestBitstream02.java @@ -71,7 +71,7 @@ public class TestBitstream02 extends JunitTracer { final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, false /* outputMode */); { - final byte r8 = (byte) bs.readInt8(true /* msbFirst */); + final byte r8 = (byte) bs.readUInt8(true /* msbFirst */); System.err.println("Read8.1 "+r8+", "+toHexBinaryString(r8, 8)); Assert.assertEquals(val8, r8); } @@ -81,7 +81,7 @@ public class TestBitstream02 extends JunitTracer { bs.writeInt8(true /* msbFirst */, val8); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() { - final byte r8 = (byte) bs.readInt8(true /* msbFirst */); + final byte r8 = (byte) bs.readUInt8(true /* msbFirst */); System.err.println("Read8.2 "+r8+", "+toHexBinaryString(r8, 8)); Assert.assertEquals(val8, r8); } @@ -119,7 +119,7 @@ public class TestBitstream02 extends JunitTracer { bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() final int rPre = (short) bs.readBits31(true /* msbFirst */, preBits); - final byte r8 = (byte) bs.readInt8(true /* msbFirst */); + final byte r8 = (byte) bs.readUInt8(true /* msbFirst */); System.err.println("ReadPre "+rPre+", "+toBinaryString(rPre, preBits)); System.err.println("Read8 "+r8+", "+toHexBinaryString(r8, 8)); Assert.assertEquals(val8, r8); diff --git a/src/junit/com/jogamp/common/util/TestBitstream03.java b/src/junit/com/jogamp/common/util/TestBitstream03.java index 7eb89e7..3647924 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream03.java +++ b/src/junit/com/jogamp/common/util/TestBitstream03.java @@ -47,7 +47,7 @@ import org.junit.runners.MethodSorters; * Test {@link Bitstream} w/ int16 read/write access w/ semantics * as well as with aligned and unaligned access. * <ul> - * <li>{@link Bitstream#readInt16(boolean, boolean)}</li> + * <li>{@link Bitstream#readUInt16(boolean, boolean)}</li> * <li>{@link Bitstream#writeInt16(boolean, boolean, short)}</li> * </ul> */ @@ -82,7 +82,7 @@ public class TestBitstream03 extends JunitTracer { final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, false /* outputMode */); { - final short r16 = (short) bs.readInt16(true /* msbFirst */, bigEndian); + final short r16 = (short) bs.readUInt16(true /* msbFirst */, bigEndian); System.err.println("Read16.1 "+r16+", "+toHexBinaryString(r16, 16)); Assert.assertEquals(val16, r16); } @@ -92,7 +92,7 @@ public class TestBitstream03 extends JunitTracer { bs.writeInt16(true /* msbFirst */, bigEndian, val16); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() { - final short r16 = (short) bs.readInt16(true /* msbFirst */, bigEndian); + final short r16 = (short) bs.readUInt16(true /* msbFirst */, bigEndian); System.err.println("Read16.2 "+r16+", "+toHexBinaryString(r16, 16)); Assert.assertEquals(val16, r16); } @@ -140,7 +140,7 @@ public class TestBitstream03 extends JunitTracer { bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() final int rPre = (short) bs.readBits31(true /* msbFirst */, preBits); - final short r16 = (short) bs.readInt16(true /* msbFirst */, bigEndian); + final short r16 = (short) bs.readUInt16(true /* msbFirst */, bigEndian); System.err.println("ReadPre "+rPre+", "+toBinaryString(rPre, preBits)); System.err.println("Read16 "+r16+", "+toHexBinaryString(r16, 16)); Assert.assertEquals(val16, r16); diff --git a/src/junit/com/jogamp/common/util/TestBitstream04.java b/src/junit/com/jogamp/common/util/TestBitstream04.java index dfc9c90..196db71 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream04.java +++ b/src/junit/com/jogamp/common/util/TestBitstream04.java @@ -47,7 +47,7 @@ import org.junit.runners.MethodSorters; * Test {@link Bitstream} w/ int32 read/write access w/ semantics * as well as with aligned and unaligned access. * <ul> - * <li>{@link Bitstream#readInt32(boolean, boolean)}</li> + * <li>{@link Bitstream#readUInt32(boolean, boolean)}</li> * <li>{@link Bitstream#writeInt32(boolean, boolean, int)}</li> * </ul> */ @@ -61,32 +61,40 @@ public class TestBitstream04 extends JunitTracer { test01Int32BitsImpl(ByteOrder.LITTLE_ENDIAN); } void test01Int32BitsImpl(ByteOrder byteOrder) throws IOException { - test01Int32BitsAlignedImpl(byteOrder, 0); - test01Int32BitsAlignedImpl(byteOrder, 1); - test01Int32BitsAlignedImpl(byteOrder, -1); - test01Int32BitsAlignedImpl(byteOrder, 7); - test01Int32BitsAlignedImpl(byteOrder, 0x0fffffff); - test01Int32BitsAlignedImpl(byteOrder, Integer.MIN_VALUE); - test01Int32BitsAlignedImpl(byteOrder, Integer.MAX_VALUE); - test01Int32BitsAlignedImpl(byteOrder, 0xffffffff); + test01Int32BitsAlignedImpl(byteOrder, 0, 0); + test01Int32BitsAlignedImpl(byteOrder, 1, 1); + test01Int32BitsAlignedImpl(byteOrder, -1, -1); + test01Int32BitsAlignedImpl(byteOrder, 7, 7); + test01Int32BitsAlignedImpl(byteOrder, 0x0fffffff, 0x0fffffff); + test01Int32BitsAlignedImpl(byteOrder, Integer.MIN_VALUE, -1); + test01Int32BitsAlignedImpl(byteOrder, Integer.MAX_VALUE, Integer.MAX_VALUE); + test01Int32BitsAlignedImpl(byteOrder, 0xffffffff, -1); } - void test01Int32BitsAlignedImpl(ByteOrder byteOrder, int val32) throws IOException { + void test01Int32BitsAlignedImpl(ByteOrder byteOrder, int val32, int expUInt32Int) throws IOException { // Test with buffer defined value final ByteBuffer bb = ByteBuffer.allocate(Buffers.SIZEOF_INT); if( null != byteOrder ) { bb.order(byteOrder); } final boolean bigEndian = ByteOrder.BIG_ENDIAN == bb.order(); + final String val32_hs = toHexString(val32); System.err.println("XXX Test01Int32BitsAligned: byteOrder "+byteOrder+" (bigEndian "+bigEndian+"), value "+val32+", "+toHexBinaryString(val32, 32)); - System.err.println("XXX Test01Int32BitsAligned: "+toUnsignedBinaryString(val32)); + System.err.println("XXX Test01Int32BitsAligned: "+val32+", "+val32_hs); + bb.putInt(0, val32); final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, false /* outputMode */); { - final int r32 = bs.readInt32(true /* msbFirst */, bigEndian); - System.err.println("Read32.1 "+r32+", "+toHexBinaryString(r32, 32)+", "+toUnsignedBinaryString(r32)); - Assert.assertEquals(val32, r32); + final long uint32_l = bs.readUInt32(true /* msbFirst */, bigEndian); + final int int32_l = (int)uint32_l; + final String uint32_l_hs = toHexString(uint32_l); + final int uint32_i = Bitstream.uint32LongToInt(uint32_l); + System.err.printf("Read32.1 uint32_l %012d, %10s; int32_l %012d %10s; uint32_i %012d %10s%n", + uint32_l, uint32_l_hs, int32_l, toHexString(int32_l), uint32_i, toHexString(uint32_i)); + Assert.assertEquals(val32_hs, uint32_l_hs); + Assert.assertEquals(val32, int32_l); + Assert.assertEquals(expUInt32Int, uint32_i); } // Test with written bitstream value @@ -94,9 +102,15 @@ public class TestBitstream04 extends JunitTracer { bs.writeInt32(true /* msbFirst */, bigEndian, val32); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() { - final int r32 = bs.readInt32(true /* msbFirst */, bigEndian); - System.err.println("Read32.2 "+r32+", "+toHexBinaryString(r32, 32)+", "+toUnsignedBinaryString(r32)); - Assert.assertEquals(val32, r32); + final long uint32_l = bs.readUInt32(true /* msbFirst */, bigEndian); + final int int32_l = (int)uint32_l; + final String uint32_l_hs = toHexString(uint32_l); + final int uint32_i = Bitstream.uint32LongToInt(uint32_l); + System.err.printf("Read32.2 uint32_l %012d, %10s; int32_l %012d %10s; uint32_i %012d %10s%n", + uint32_l, uint32_l_hs, int32_l, toHexString(int32_l), uint32_i, toHexString(uint32_i)); + Assert.assertEquals(val32_hs, uint32_l_hs); + Assert.assertEquals(val32, int32_l); + Assert.assertEquals(expUInt32Int, uint32_i); } } @@ -116,16 +130,16 @@ public class TestBitstream04 extends JunitTracer { test02Int32BitsUnalignedImpl(byteOrder, 25); } void test02Int32BitsUnalignedImpl(ByteOrder byteOrder, final int preBits) throws IOException { - test02Int32BitsUnalignedImpl(byteOrder, preBits, 0); - test02Int32BitsUnalignedImpl(byteOrder, preBits, 1); - test02Int32BitsUnalignedImpl(byteOrder, preBits, -1); - test02Int32BitsUnalignedImpl(byteOrder, preBits, 7); - test02Int32BitsUnalignedImpl(byteOrder, preBits, 0x0fffffff); - test02Int32BitsUnalignedImpl(byteOrder, preBits, Integer.MIN_VALUE); - test02Int32BitsUnalignedImpl(byteOrder, preBits, Integer.MAX_VALUE); - test02Int32BitsUnalignedImpl(byteOrder, preBits, 0xffffffff); + test02Int32BitsUnalignedImpl(byteOrder, preBits, 0, 0); + test02Int32BitsUnalignedImpl(byteOrder, preBits, 1, 1); + test02Int32BitsUnalignedImpl(byteOrder, preBits, -1, -1); + test02Int32BitsUnalignedImpl(byteOrder, preBits, 7, 7); + test02Int32BitsUnalignedImpl(byteOrder, preBits, 0x0fffffff, 0x0fffffff); + test02Int32BitsUnalignedImpl(byteOrder, preBits, Integer.MIN_VALUE, -1); + test02Int32BitsUnalignedImpl(byteOrder, preBits, Integer.MAX_VALUE, Integer.MAX_VALUE); + test02Int32BitsUnalignedImpl(byteOrder, preBits, 0xffffffff, -1); } - void test02Int32BitsUnalignedImpl(ByteOrder byteOrder, int preBits, int val32) throws IOException { + void test02Int32BitsUnalignedImpl(ByteOrder byteOrder, int preBits, int val32, int expUInt32Int) throws IOException { final int preBytes = ( preBits + 7 ) >>> 3; final int byteCount = preBytes + Buffers.SIZEOF_INT; final ByteBuffer bb = ByteBuffer.allocate(byteCount); @@ -133,8 +147,9 @@ public class TestBitstream04 extends JunitTracer { bb.order(byteOrder); } final boolean bigEndian = ByteOrder.BIG_ENDIAN == bb.order(); + final String val32_hs = toHexString(val32); System.err.println("XXX Test02Int32BitsUnaligned: byteOrder "+byteOrder+" (bigEndian "+bigEndian+"), preBits "+preBits+", value "+val32+", "+toHexBinaryString(val32, 32)); - System.err.println("XXX Test02Int32BitsUnaligned: "+toUnsignedBinaryString(val32)); + System.err.println("XXX Test02Int32BitsUnaligned: "+val32+", "+val32_hs); // Test with written bitstream value final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); @@ -144,10 +159,16 @@ public class TestBitstream04 extends JunitTracer { bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() final int rPre = bs.readBits31(true /* msbFirst */, preBits); - final int r32 = bs.readInt32(true /* msbFirst */, bigEndian); + final long uint32_l = bs.readUInt32(true /* msbFirst */, bigEndian); + final int int32_l = (int)uint32_l; + final String uint32_l_hs = toHexString(uint32_l); + final int uint32_i = Bitstream.uint32LongToInt(uint32_l); System.err.println("ReadPre "+rPre+", "+toBinaryString(rPre, preBits)); - System.err.println("Read32 "+r32+", "+toHexBinaryString(r32, 32)+", "+toUnsignedBinaryString(r32)); - Assert.assertEquals(val32, r32); + System.err.printf("Read32 uint32_l %012d, %10s; int32_l %012d %10s; uint32_i %012d %10s%n", + uint32_l, uint32_l_hs, int32_l, toHexString(int32_l), uint32_i, toHexString(uint32_i)); + Assert.assertEquals(val32_hs, uint32_l_hs); + Assert.assertEquals(val32, int32_l); + Assert.assertEquals(expUInt32Int, uint32_i); } public static void main(String args[]) throws IOException { |