Skip to content

Commit a3d2a1e

Browse files
committed
added test
1 parent 36b0f5e commit a3d2a1e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

jbbp/src/test/java/com/igormaznitsa/jbbp/io/JBBPBitInputStreamTest.java

+33
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.io.EOFException;
4141
import java.io.IOException;
4242
import java.util.Random;
43+
import java.util.function.Supplier;
4344
import org.apache.commons.lang3.tuple.Pair;
4445
import org.junit.jupiter.api.Test;
4546

@@ -70,6 +71,38 @@ private static JBBPBitInputStream asInputStreamMSB0(final int... array) {
7071
JBBPBitOrder.MSB0);
7172
}
7273

74+
@Test
75+
public void testIsDetectedPartlyReadBitField() throws Exception {
76+
final Supplier<JBBPBitInputStream> oneByteStream =
77+
() -> new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1}));
78+
final Supplier<JBBPBitInputStream> oneByteStreamNoAccumulated =
79+
() -> new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1}), false);
80+
81+
JBBPBitInputStream in = oneByteStream.get();
82+
assertFalse(in.isDetectedPartlyReadBitField());
83+
in.read();
84+
assertFalse(in.isDetectedPartlyReadBitField());
85+
86+
in = oneByteStream.get();
87+
assertFalse(in.isDetectedPartlyReadBitField());
88+
in.readBits(BITS_1);
89+
assertFalse(in.isDetectedPartlyReadBitField());
90+
in.read();
91+
assertTrue(in.isDetectedPartlyReadBitField());
92+
93+
in = oneByteStreamNoAccumulated.get();
94+
assertFalse(in.isDetectedPartlyReadBitField());
95+
in.read();
96+
assertFalse(in.isDetectedPartlyReadBitField());
97+
98+
in = oneByteStreamNoAccumulated.get();
99+
assertFalse(in.isDetectedPartlyReadBitField());
100+
in.readBits(BITS_1);
101+
assertFalse(in.isDetectedPartlyReadBitField());
102+
in.read();
103+
assertTrue(in.isDetectedPartlyReadBitField());
104+
}
105+
73106
@Test
74107
public void testReadMsb0Direct() throws Exception {
75108
byte[] data = str2bin("00000001_101_00001000_00000_01_00_1011_00000");

0 commit comments

Comments
 (0)