diff options
Diffstat (limited to 'src/junit/com/jogamp')
5 files changed, 254 insertions, 97 deletions
diff --git a/src/junit/com/jogamp/common/util/TestBitstream00.java b/src/junit/com/jogamp/common/util/TestBitstream00.java index fa9c75d..920363b 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream00.java +++ b/src/junit/com/jogamp/common/util/TestBitstream00.java @@ -129,6 +129,138 @@ public class TestBitstream00 extends SingletonJunitCase { } } + @Test + public void test10ReadWrite_13() throws UnsupportedOperationException, IllegalStateException, IOException { + // H->L : 00000011 00000010 00000001 000000110000001000000001 + // H->L rev: 10000000 01000000 11000000 100000000100000011000000 + // + // L->H : 00000001 00000010 00000011 000000010000001000000011 + // L->H rev: 11000000 01000000 10000000 110000000100000010000000 + test10ReadWrite1_31Impl(8, 8, 8, 0x030201, "000000110000001000000001"); + + // H->L: 00011 000010 00001 0001100001000001 + // L->H: 10000 010000 11000 1000001000011000 + test10ReadWrite1_31Impl(5, 6, 5, 0x1841, "0001100001000001"); + } + void test10ReadWrite1_31Impl(final int c1, final int c2, final int c3, final int v, final String vStrHigh2LowExp) + throws UnsupportedOperationException, IllegalStateException, IOException + { + // final Bitstream<ByteBuffer> source = new Bitstream<ByteBuffer>(); + final int bitCount = c1+c2+c3; + final int byteCount = ( bitCount + 7 ) / 8; + final String vStrHigh2Low0 = Bitstream.toBinString(true, v, bitCount); + System.err.printf("test10ReadWrite31 bits %d:%d:%d = %d = %d bytes%n", + c1, c2, c3, bitCount, byteCount); + System.err.printf("test10ReadWrite31 %s%n", Bitstream.toHexBinString(true, v, bitCount)); + System.err.printf("test10ReadWrite31 %s%n", Bitstream.toHexBinString(false, v, bitCount)); + Assert.assertEquals(vStrHigh2LowExp, vStrHigh2Low0); + + final ByteBuffer bbRead = ByteBuffer.allocate(byteCount); + for(int i=0; i<byteCount; i++) { + final int b = ( v >>> 8*i ) & 0xff; + bbRead.put(i, (byte) b); + System.err.printf("testBytes[%d]: %s%n", i, Bitstream.toHexBinString(true, b, 8)); + } + final Bitstream.ByteBufferStream bbsRead = new Bitstream.ByteBufferStream(bbRead); + final Bitstream<ByteBuffer> bsRead = new Bitstream<ByteBuffer>(bbsRead, false /* outputMode */); + + String vStrHigh2Low1C1 = ""; + String vStrHigh2Low1C2 = ""; + String vStrHigh2Low1C3 = ""; + String vStrHigh2Low1 = ""; + { + bsRead.mark(byteCount); + System.err.println("readBit (msbFirst false): "); + int b; + int i=0; + String vStrHigh2Low1T = ""; // OK for LSB, MSB segmented + while( Bitstream.EOS != ( b = bsRead.readBit(false /* msbFirst */) ) ) { + vStrHigh2Low1T = b + vStrHigh2Low1T; + if(i < c1) { + vStrHigh2Low1C1 = b + vStrHigh2Low1C1; + } else if(i < c1+c2) { + vStrHigh2Low1C2 = b + vStrHigh2Low1C2; + } else { + vStrHigh2Low1C3 = b + vStrHigh2Low1C3; + } + i++; + } + vStrHigh2Low1 = vStrHigh2Low1C3 + vStrHigh2Low1C2 + vStrHigh2Low1C1; + System.err.printf("readBit.1 %s, 0x%s%n", vStrHigh2Low1C1, Integer.toHexString(Integer.valueOf(vStrHigh2Low1C1, 2))); + System.err.printf("readBit.2 %s, 0x%s%n", vStrHigh2Low1C2, Integer.toHexString(Integer.valueOf(vStrHigh2Low1C2, 2))); + System.err.printf("readBit.3 %s, 0x%s%n", vStrHigh2Low1C3, Integer.toHexString(Integer.valueOf(vStrHigh2Low1C3, 2))); + System.err.printf("readBit.T %s, ok %b%n%n", vStrHigh2Low1T, vStrHigh2LowExp.equals(vStrHigh2Low1T)); + System.err.printf("readBit.X %s, ok %b%n%n", vStrHigh2Low1, vStrHigh2LowExp.equals(vStrHigh2Low1)); + bsRead.reset(); + } + + { + String vStrHigh2Low3T = ""; // OK for LSB, MSB segmented + System.err.println("readBits32: "); + final int b = bsRead.readBits31(bitCount); + vStrHigh2Low3T = Bitstream.toBinString(true, b, bitCount); + System.err.printf("readBits31.T %s, ok %b, %s%n%n", vStrHigh2Low3T, vStrHigh2LowExp.equals(vStrHigh2Low3T), Bitstream.toHexBinString(true, b, bitCount)); + bsRead.reset(); + } + + String vStrHigh2Low2 = ""; + { + System.err.println("readBits32: "); + final int bC1 = bsRead.readBits31(c1); + System.err.printf("readBits31.1 %s%n", Bitstream.toHexBinString(true, bC1, c1)); + final int bC2 = bsRead.readBits31(c2); + System.err.printf("readBits31.2 %s%n", Bitstream.toHexBinString(true, bC2, c2)); + final int bC3 = bsRead.readBits31(c3); + System.err.printf("readBits31.3 %s%n", Bitstream.toHexBinString(true, bC3, c3)); + final int b = bC3 << (c1+c2) | bC2 << c1 | bC1; + vStrHigh2Low2 = Bitstream.toBinString(true, b, bitCount); + System.err.printf("readBits31.X %s, ok %b, %s%n%n", vStrHigh2Low2, vStrHigh2LowExp.equals(vStrHigh2Low2), Bitstream.toHexBinString(true, b, bitCount)); + bsRead.reset(); + } + + Assert.assertEquals(vStrHigh2LowExp, vStrHigh2Low1); + Assert.assertEquals(vStrHigh2LowExp, vStrHigh2Low2); + + boolean ok = true; + { + final ByteBuffer bbWrite = ByteBuffer.allocate(byteCount); + final Bitstream.ByteBufferStream bbsWrite = new Bitstream.ByteBufferStream(bbWrite); + final Bitstream<ByteBuffer> bsWrite = new Bitstream<ByteBuffer>(bbsWrite, true /* outputMode */); + { + int b; + while( Bitstream.EOS != ( b = bsRead.readBit(false)) ) { + bsWrite.writeBit(false, b); + } + } + bsRead.reset(); + for(int i=0; i<byteCount; i++) { + final int bR = bbWrite.get(i); + final int bW = bbWrite.get(i); + System.err.printf("readWriteBit [%d]: read %s, write %s, ok %b%n", + i, Bitstream.toHexBinString(true, bR, 8), Bitstream.toHexBinString(true, bW, 8), bR==bW); + ok = ok && bR==bW; + } + Assert.assertTrue(ok); + } + { + final ByteBuffer bbWrite = ByteBuffer.allocate(byteCount); + final Bitstream.ByteBufferStream bbsWrite = new Bitstream.ByteBufferStream(bbWrite); + final Bitstream<ByteBuffer> bsWrite = new Bitstream<ByteBuffer>(bbsWrite, true /* outputMode */); + { + bsWrite.writeBits31(bitCount, bsRead.readBits31(bitCount)); + } + bsRead.reset(); + for(int i=0; i<byteCount; i++) { + final int bR = bbWrite.get(i); + final int bW = bbWrite.get(i); + System.err.printf("readWriteBits31[%d]: read %s, write %s, ok %b%n", + i, Bitstream.toHexBinString(true, bR, 8), Bitstream.toHexBinString(true, bW, 8), bR==bW); + ok = ok && bR==bW; + } + Assert.assertTrue(ok); + } + } + public static void main(final String args[]) throws IOException { final String tstname = TestBitstream00.class.getName(); org.junit.runner.JUnitCore.main(tstname); diff --git a/src/junit/com/jogamp/common/util/TestBitstream01.java b/src/junit/com/jogamp/common/util/TestBitstream01.java index 99116e6..49931a3 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream01.java +++ b/src/junit/com/jogamp/common/util/TestBitstream01.java @@ -48,44 +48,67 @@ import org.junit.runners.MethodSorters; * <li>{@link Bitstream#mark(int)}</li> * <li>{@link Bitstream#reset()}</li> * <li>{@link Bitstream#flush()}</li> - * <li>{@link Bitstream#readBits31(boolean, int)}</li> - * <li>{@link Bitstream#writeBits31(boolean, int, int)}</li> + * <li>{@link Bitstream#readBits31(int)}</li> + * <li>{@link Bitstream#writeBits31(int, int)}</li> * </ul> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestBitstream01 extends SingletonJunitCase { - Bitstream<ByteBuffer> getTestStream(final boolean msbFirst, final int preBits, final int skipBits, final int postBits) throws IOException { - final int byteCount = ( preBits + skipBits + postBits + 7 ) / 8; + Bitstream<ByteBuffer> getTestStream(final boolean msbFirstData, final boolean msbFirstWrite, + final int preBits, final int skipBits, final int postBits) throws IOException { + final int bitCount = preBits+skipBits+postBits; + final int byteCount = ( bitCount + 7 ) / 8; final ByteBuffer bbTest = ByteBuffer.allocate(byteCount); final Bitstream.ByteBufferStream bbsTest = new Bitstream.ByteBufferStream(bbTest); final Bitstream<ByteBuffer> bsTest = new Bitstream<ByteBuffer>(bbsTest, true /* outputMode */); final String sTest0; - if( msbFirst ) { + if( msbFirstData ) { sTest0 = testStringMSB.substring(0, preBits+skipBits+postBits); } else { sTest0 = testStringLSB.substring(0, preBits+skipBits+postBits); } - for(int i=0; i<preBits+skipBits+postBits; i++) { - final int bit = Integer.valueOf(sTest0.substring(i, i+1)); - bsTest.writeBit(msbFirst, bit); + if( msbFirstData == msbFirstWrite ) { + for(int i=0; i<bitCount; i++) { + final int bit = Integer.valueOf(sTest0.substring(i, i+1)); + bsTest.writeBit(msbFirstWrite, bit); + } + } else { + for(int i=bitCount-1; i >= 0; i--) { + final int bit = Integer.valueOf(sTest0.substring(i, i+1)); + bsTest.writeBit(msbFirstWrite, bit); + } } + System.err.printf("TestData: msbFirst[data %b, write %b], bits[pre %d, skip %d, post %d = %d]: <%s>%n", + msbFirstData, msbFirstWrite, preBits, skipBits, postBits, bitCount, sTest0); Assert.assertEquals(preBits+skipBits+postBits, bsTest.position()); bsTest.setStream(bsTest.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() + dumpData("TestData: ", bsTest.getSubStream(), 0, bsTest.getSubStream().limit()); return bsTest; } - String getTestStreamResultAsString(final boolean msbFirst, final int preBits, final int skipBits, final int postBits) { + String getTestStreamResultAsString(final boolean msbFirstData, final boolean msbFirstAssemble, + final int preBits, final int skipBits, final int postBits) { final String pre, post; - if( msbFirst ) { - pre = testStringMSB.substring(0, preBits); - post = testStringMSB.substring(preBits+skipBits, preBits+skipBits+postBits); + if( msbFirstData ) { + if( msbFirstAssemble ) { + pre = testStringMSB.substring(0, preBits); + post = testStringMSB.substring(preBits+skipBits, preBits+skipBits+postBits); + } else { + pre = testStringMSB.substring(postBits+skipBits, preBits+skipBits+postBits); + post = testStringMSB.substring(0, postBits); + } } else { - pre = testStringLSB.substring(0, preBits); - post = testStringLSB.substring(preBits+skipBits, preBits+skipBits+postBits); + if( msbFirstAssemble ) { + pre = testStringLSB.substring(0, preBits); + post = testStringLSB.substring(preBits+skipBits, preBits+skipBits+postBits); + } else { + pre = testStringMSB.substring(postBits+skipBits, preBits+skipBits+postBits); + post = testStringMSB.substring(0, postBits); + } } - final String r = pre + post; - System.err.println("Test: <"+pre+"> + <"+post+"> = <"+r+">"); + final String r = msbFirstAssemble ? pre + post : post + pre; + System.err.println("ResultExp: <"+pre+"> + <"+post+"> = <"+r+">"); return r; } @@ -155,9 +178,8 @@ public class TestBitstream01 extends SingletonJunitCase { // prepare bitstream System.err.println("Prepare bitstream"); - final Bitstream<ByteBuffer> bsTest = getTestStream(msbFirst, preBits, skipBits, postBits); - dumpData("Test", bsTest.getSubStream(), 0, bsTest.getSubStream().limit()); - final String sTest = getTestStreamResultAsString(msbFirst, preBits, skipBits, postBits); + final Bitstream<ByteBuffer> bsTest = getTestStream(msbFirst, msbFirst, preBits, skipBits, postBits); + final String sTest = getTestStreamResultAsString(msbFirst, true, preBits, skipBits, postBits); // init copy-bitstream final int byteCount = ( totalBits + 7 ) / 8; @@ -219,50 +241,48 @@ public class TestBitstream01 extends SingletonJunitCase { } @Test - public void test03BulkBitsMSBFirst() throws IOException { - testBulkBitsImpl(true); - } - @Test - public void test04BulkBitsLSBFirst() throws IOException { - testBulkBitsImpl(false); - } - void testBulkBitsImpl(final boolean msbFirst) throws IOException { - testBulkBitsImpl(msbFirst, 0, 0, 1); - testBulkBitsImpl(msbFirst, 0, 0, 3); - testBulkBitsImpl(msbFirst, 0, 0, 8); - testBulkBitsImpl(msbFirst, 0, 0, 10); - testBulkBitsImpl(msbFirst, 0, 0, 30); - testBulkBitsImpl(msbFirst, 0, 0, 31); - - testBulkBitsImpl(msbFirst, 3, 0, 3); - testBulkBitsImpl(msbFirst, 8, 0, 3); - testBulkBitsImpl(msbFirst, 9, 0, 3); - - testBulkBitsImpl(msbFirst, 0, 1, 1); - testBulkBitsImpl(msbFirst, 0, 1, 3); - testBulkBitsImpl(msbFirst, 0, 2, 8); - testBulkBitsImpl(msbFirst, 0, 8, 10); - testBulkBitsImpl(msbFirst, 0, 12, 20); - testBulkBitsImpl(msbFirst, 0, 23, 9); - testBulkBitsImpl(msbFirst, 0, 1, 31); - - testBulkBitsImpl(msbFirst, 1, 1, 1); - testBulkBitsImpl(msbFirst, 2, 1, 3); - testBulkBitsImpl(msbFirst, 7, 2, 8); - testBulkBitsImpl(msbFirst, 8, 8, 8); - testBulkBitsImpl(msbFirst, 15, 12, 5); - testBulkBitsImpl(msbFirst, 16, 11, 5); + public void test03BulkBits() throws IOException { + testBulkBitsImpl(0, 0, 1); + testBulkBitsImpl(0, 0, 3); + testBulkBitsImpl(0, 0, 8); + testBulkBitsImpl(0, 0, 10); + testBulkBitsImpl(0, 0, 30); + testBulkBitsImpl(0, 0, 31); + + testBulkBitsImpl(3, 0, 3); + testBulkBitsImpl(8, 0, 3); + testBulkBitsImpl(9, 0, 3); + testBulkBitsImpl(5, 0, 6); + testBulkBitsImpl(5, 0, 8); + + testBulkBitsImpl(0, 1, 1); + testBulkBitsImpl(3, 6, 4); + + testBulkBitsImpl(0, 1, 3); + testBulkBitsImpl(0, 2, 8); + testBulkBitsImpl(0, 8, 10); + testBulkBitsImpl(0, 12, 20); + testBulkBitsImpl(0, 23, 9); + testBulkBitsImpl(0, 1, 31); + + testBulkBitsImpl(1, 1, 1); + testBulkBitsImpl(2, 1, 3); + testBulkBitsImpl(7, 2, 8); + testBulkBitsImpl(8, 8, 8); + testBulkBitsImpl(15, 12, 5); + testBulkBitsImpl(16, 11, 5); + testBulkBitsImpl(5, 6, 5); + testBulkBitsImpl(5, 6, 8); } - void testBulkBitsImpl(final boolean msbFirst, final int preBits, final int skipBits, final int postBits) throws IOException { + void testBulkBitsImpl(final int preBits, final int skipBits, final int postBits) throws IOException { final int totalBits = preBits+skipBits+postBits; - System.err.println("XXX TestBulkBits: msbFirst "+msbFirst+", preBits "+preBits+", skipBits "+skipBits+", postBits "+postBits+", totalBits "+totalBits); + System.err.println("XXX TestBulkBits: preBits "+preBits+", skipBits "+skipBits+", postBits "+postBits+", totalBits "+totalBits); // prepare bitstream System.err.println("Prepare bitstream"); - final Bitstream<ByteBuffer> bsTest = getTestStream(msbFirst, preBits, skipBits, postBits); - dumpData("Test", bsTest.getSubStream(), 0, bsTest.getSubStream().limit()); - final String sTest = getTestStreamResultAsString(msbFirst, preBits, skipBits, postBits); + final Bitstream<ByteBuffer> bsTest = getTestStream(true, false, preBits, skipBits, postBits); + final String sTest = getTestStreamResultAsString(true, false, preBits, skipBits, postBits); // init copy-bitstream final int byteCount = ( totalBits + 7 ) / 8; @@ -273,18 +293,18 @@ public class TestBitstream01 extends SingletonJunitCase { // read-bitstream .. and copy bits while reading System.err.println("Reading bitstream: "+bsTest); { - final int readBitsPre = bsTest.readBits31(msbFirst, preBits); - Assert.assertEquals(readBitsPre, bsCopy.writeBits31(msbFirst, preBits, readBitsPre)); + final int readBitsPre = bsTest.readBits31(preBits); + Assert.assertEquals(readBitsPre, bsCopy.writeBits31(preBits, readBitsPre)); final int skippedReadBits = (int) bsTest.skip(skipBits); final int skippedBitsCopy = (int) bsCopy.skip(skipBits); - final int readBitsPost = bsTest.readBits31(msbFirst, postBits); - Assert.assertEquals(readBitsPost, bsCopy.writeBits31(msbFirst, postBits, readBitsPost)); - final String sReadPre = toBinaryString(readBitsPre, preBits); - final String sReadPost = toBinaryString(readBitsPost, postBits); - final String sRead = sReadPre + sReadPost; - System.err.println("Read.Test: <"+sReadPre+"> + <"+sReadPost+"> = <"+sRead+">"); + final int readBitsPost = bsTest.readBits31(postBits); + Assert.assertEquals(readBitsPost, bsCopy.writeBits31(postBits, readBitsPost)); + final String sReadPreLo = toBinaryString(readBitsPre, preBits); + final String sReadPostHi = toBinaryString(readBitsPost, postBits); + final String sRead = sReadPostHi + sReadPreLo; + System.err.println("Read.Test: <"+sReadPreLo+"> + <"+sReadPostHi+"> = <"+sRead+">"); Assert.assertEquals(skipBits, skippedReadBits); Assert.assertEquals(sTest, sRead); @@ -298,15 +318,15 @@ public class TestBitstream01 extends SingletonJunitCase { System.err.println("Reading copy-bitstream: "+bsCopy); Assert.assertEquals(0, bsCopy.position()); { - final int copyBitsPre = bsCopy.readBits31(msbFirst, preBits); + final int copyBitsPre = bsCopy.readBits31(preBits); final int skippedCopyBits = (int) bsCopy.skip(skipBits); - final int copyBitsPost = bsCopy.readBits31(msbFirst, postBits); - final String sCopyPre = toBinaryString(copyBitsPre, preBits); - final String sCopyPost = toBinaryString(copyBitsPost, postBits); - final String sCopy = sCopyPre + sCopyPost; - System.err.println("Copy.Test: <"+sCopyPre+"> + <"+sCopyPost+"> = <"+sCopy+">"); + final int copyBitsPost = bsCopy.readBits31(postBits); + final String sCopyPreLo = toBinaryString(copyBitsPre, preBits); + final String sCopyPostHi = toBinaryString(copyBitsPost, postBits); + final String sCopy = sCopyPostHi + sCopyPreLo; + System.err.println("Copy.Test: <"+sCopyPreLo+"> + <"+sCopyPostHi+"> = <"+sCopy+">"); Assert.assertEquals(skipBits, skippedCopyBits); Assert.assertEquals(sTest, sCopy); @@ -317,7 +337,7 @@ public class TestBitstream01 extends SingletonJunitCase { @Test public void test05ErrorHandling() throws IOException { // prepare bitstream - final Bitstream<ByteBuffer> bsTest = getTestStream(false, 0, 0, 0); + final Bitstream<ByteBuffer> bsTest = getTestStream(false, false, 0, 0, 0); System.err.println("01a: "+bsTest); bsTest.close(); System.err.println("01b: "+bsTest); diff --git a/src/junit/com/jogamp/common/util/TestBitstream02.java b/src/junit/com/jogamp/common/util/TestBitstream02.java index 3fb4cce..16904a2 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream02.java +++ b/src/junit/com/jogamp/common/util/TestBitstream02.java @@ -71,17 +71,17 @@ public class TestBitstream02 extends SingletonJunitCase { final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, false /* outputMode */); { - final byte r8 = (byte) bs.readUInt8(true /* msbFirst */); + final byte r8 = (byte) bs.readUInt8(); System.err.println("Read8.1 "+r8+", "+toHexBinaryString(r8, 8)); Assert.assertEquals(val8, r8); } // Test with written bitstream value bs.setStream(bs.getSubStream(), true /* outputMode */); - bs.writeInt8(true /* msbFirst */, val8); + bs.writeInt8(val8); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() { - final byte r8 = (byte) bs.readUInt8(true /* msbFirst */); + final byte r8 = (byte) bs.readUInt8(); System.err.println("Read8.2 "+r8+", "+toHexBinaryString(r8, 8)); Assert.assertEquals(val8, r8); } @@ -114,12 +114,12 @@ public class TestBitstream02 extends SingletonJunitCase { // Test with written bitstream value final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, true /* outputMode */); - bs.writeBits31(true /* msbFirst */, preBits, 0); - bs.writeInt8(true /* msbFirst */, val8); + bs.writeBits31(preBits, 0); + bs.writeInt8(val8); 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.readUInt8(true /* msbFirst */); + final int rPre = (short) bs.readBits31(preBits); + final byte r8 = (byte) bs.readUInt8(); 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 4dfb3d7..a6129d8 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream03.java +++ b/src/junit/com/jogamp/common/util/TestBitstream03.java @@ -47,8 +47,8 @@ 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#readUInt16(boolean, boolean)}</li> - * <li>{@link Bitstream#writeInt16(boolean, boolean, short)}</li> + * <li>{@link Bitstream#readUInt16(boolean)}</li> + * <li>{@link Bitstream#writeInt16(boolean, short)}</li> * </ul> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -78,21 +78,23 @@ public class TestBitstream03 extends SingletonJunitCase { final boolean bigEndian = ByteOrder.BIG_ENDIAN == bb.order(); System.err.println("XXX Test01Int16BitsAligned: byteOrder "+byteOrder+" (bigEndian "+bigEndian+"), value "+val16+", "+toHexBinaryString(val16, 16)); bb.putShort(0, val16); + dumpData("TestData.1: ", bb, 0, 2); final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, false /* outputMode */); { - final short r16 = (short) bs.readUInt16(true /* msbFirst */, bigEndian); + final short r16 = (short) bs.readUInt16(bigEndian); System.err.println("Read16.1 "+r16+", "+toHexBinaryString(r16, 16)); Assert.assertEquals(val16, r16); } // Test with written bitstream value bs.setStream(bs.getSubStream(), true /* outputMode */); - bs.writeInt16(true /* msbFirst */, bigEndian, val16); + bs.writeInt16(bigEndian, val16); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() + dumpData("TestData.2: ", bb, 0, 2); { - final short r16 = (short) bs.readUInt16(true /* msbFirst */, bigEndian); + final short r16 = (short) bs.readUInt16(bigEndian); System.err.println("Read16.2 "+r16+", "+toHexBinaryString(r16, 16)); Assert.assertEquals(val16, r16); } @@ -135,12 +137,13 @@ public class TestBitstream03 extends SingletonJunitCase { // Test with written bitstream value final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, true /* outputMode */); - bs.writeBits31(true /* msbFirst */, preBits, 0); - bs.writeInt16(true /* msbFirst */, bigEndian, val16); + bs.writeBits31(preBits, 0); + bs.writeInt16(bigEndian, val16); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() + dumpData("TestData.1: ", bb, 0, byteCount); - final int rPre = (short) bs.readBits31(true /* msbFirst */, preBits); - final short r16 = (short) bs.readUInt16(true /* msbFirst */, bigEndian); + final int rPre = (short) bs.readBits31(preBits); + final short r16 = (short) bs.readUInt16(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 277510e..47be38d 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream04.java +++ b/src/junit/com/jogamp/common/util/TestBitstream04.java @@ -47,8 +47,8 @@ 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#readUInt32(boolean, boolean)}</li> - * <li>{@link Bitstream#writeInt32(boolean, boolean, int)}</li> + * <li>{@link Bitstream#readUInt32(boolean)}</li> + * <li>{@link Bitstream#writeInt32(boolean, int)}</li> * </ul> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -82,11 +82,12 @@ public class TestBitstream04 extends SingletonJunitCase { System.err.println("XXX Test01Int32BitsAligned: "+val32+", "+val32_hs); bb.putInt(0, val32); + dumpData("TestData.1: ", bb, 0, 4); final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, false /* outputMode */); { - final long uint32_l = bs.readUInt32(true /* msbFirst */, bigEndian); + final long uint32_l = bs.readUInt32(bigEndian); final int int32_l = (int)uint32_l; final String uint32_l_hs = toHexString(uint32_l); final int uint32_i = Bitstream.uint32LongToInt(uint32_l); @@ -99,10 +100,11 @@ public class TestBitstream04 extends SingletonJunitCase { // Test with written bitstream value bs.setStream(bs.getSubStream(), true /* outputMode */); - bs.writeInt32(true /* msbFirst */, bigEndian, val32); + bs.writeInt32(bigEndian, val32); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() + dumpData("TestData.2: ", bb, 0, 4); { - final long uint32_l = bs.readUInt32(true /* msbFirst */, bigEndian); + final long uint32_l = bs.readUInt32(bigEndian); final int int32_l = (int)uint32_l; final String uint32_l_hs = toHexString(uint32_l); final int uint32_i = Bitstream.uint32LongToInt(uint32_l); @@ -154,12 +156,12 @@ public class TestBitstream04 extends SingletonJunitCase { // Test with written bitstream value final Bitstream.ByteBufferStream bbs = new Bitstream.ByteBufferStream(bb); final Bitstream<ByteBuffer> bs = new Bitstream<ByteBuffer>(bbs, true /* outputMode */); - bs.writeBits31(true /* msbFirst */, preBits, 0); - bs.writeInt32(true /* msbFirst */, bigEndian, val32); + bs.writeBits31(preBits, 0); + bs.writeInt32(bigEndian, val32); bs.setStream(bs.getSubStream(), false /* outputMode */); // switch to input-mode, implies flush() - final int rPre = bs.readBits31(true /* msbFirst */, preBits); - final long uint32_l = bs.readUInt32(true /* msbFirst */, bigEndian); + final int rPre = bs.readBits31(preBits); + final long uint32_l = bs.readUInt32(bigEndian); final int int32_l = (int)uint32_l; final String uint32_l_hs = toHexString(uint32_l); final int uint32_i = Bitstream.uint32LongToInt(uint32_l); |