29import static jau.test.util.BitDemoData.toBinaryString;
30import static jau.test.util.BitDemoData.toHexBinaryString;
32import java.io.IOException;
33import java.nio.ByteBuffer;
35import org.jau.io.Bitstream;
36import org.jau.io.Buffers;
37import org.junit.Assert;
38import org.junit.FixMethodOrder;
40import org.junit.runners.MethodSorters;
42import jau.test.junit.util.JunitTracer;
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
57 test01Int8BitsAlignedImpl((
byte)0);
58 test01Int8BitsAlignedImpl((
byte)1);
59 test01Int8BitsAlignedImpl((
byte)7);
60 test01Int8BitsAlignedImpl(Byte.MIN_VALUE);
61 test01Int8BitsAlignedImpl(Byte.MAX_VALUE);
62 test01Int8BitsAlignedImpl((
byte)0xff);
64 void test01Int8BitsAlignedImpl(
final byte val8)
throws IOException {
66 final ByteBuffer bb = ByteBuffer.allocate(Buffers.SIZEOF_BYTE);
67 System.err.println(
"XXX Test01Int8BitsAligned: value "+val8+
", "+toHexBinaryString(val8, 8));
70 final Bitstream.ByteBufferStream bbs =
new Bitstream.ByteBufferStream(bb);
71 final Bitstream<ByteBuffer> bs =
new Bitstream<ByteBuffer>(bbs,
false );
73 final byte r8 = (byte) bs.readUInt8();
74 System.err.println(
"Read8.1 "+r8+
", "+toHexBinaryString(r8, 8));
75 Assert.assertEquals(val8, r8);
79 bs.setStream(bs.getSubStream(),
true );
81 bs.setStream(bs.getSubStream(),
false );
83 final byte r8 = (byte) bs.readUInt8();
84 System.err.println(
"Read8.2 "+r8+
", "+toHexBinaryString(r8, 8));
85 Assert.assertEquals(val8, r8);
91 test02Int8BitsUnalignedImpl(0);
92 test02Int8BitsUnalignedImpl(1);
93 test02Int8BitsUnalignedImpl(7);
94 test02Int8BitsUnalignedImpl(8);
95 test02Int8BitsUnalignedImpl(15);
96 test02Int8BitsUnalignedImpl(24);
97 test02Int8BitsUnalignedImpl(25);
99 void test02Int8BitsUnalignedImpl(
final int preBits)
throws IOException {
100 test02Int8BitsUnalignedImpl(preBits, (
byte)0);
101 test02Int8BitsUnalignedImpl(preBits, (
byte)1);
102 test02Int8BitsUnalignedImpl(preBits, (
byte)7);
103 test02Int8BitsUnalignedImpl(preBits, Byte.MIN_VALUE);
104 test02Int8BitsUnalignedImpl(preBits, Byte.MAX_VALUE);
105 test02Int8BitsUnalignedImpl(preBits, (
byte)0xff);
107 void test02Int8BitsUnalignedImpl(
final int preBits,
final byte val8)
throws IOException {
108 final int preBytes = ( preBits + 7 ) >>> 3;
109 final int byteCount = preBytes + Buffers.SIZEOF_BYTE;
110 final ByteBuffer bb = ByteBuffer.allocate(byteCount);
111 System.err.println(
"XXX Test02Int8BitsUnaligned: preBits "+preBits+
", value "+val8+
", "+toHexBinaryString(val8, 8));
114 final Bitstream.ByteBufferStream bbs =
new Bitstream.ByteBufferStream(bb);
115 final Bitstream<ByteBuffer> bs =
new Bitstream<ByteBuffer>(bbs,
true );
116 bs.writeBits31(preBits, 0);
118 bs.setStream(bs.getSubStream(),
false );
120 final int rPre = (short) bs.readBits31(preBits);
121 final byte r8 = (byte) bs.readUInt8();
122 System.err.println(
"ReadPre "+rPre+
", "+toBinaryString(rPre, preBits));
123 System.err.println(
"Read8 "+r8+
", "+toHexBinaryString(r8, 8));
124 Assert.assertEquals(val8, r8);
127 public static void main(
final String args[])
throws IOException {
129 org.junit.runner.JUnitCore.
main(tstname);
Test Bitstream w/ int8 read/write access w/ semantics as well as with aligned and unaligned access.
void test02Int8BitsUnaligned()
void test01Int8BitsAligned()
static void main(final String args[])