Repository: commons-compress Updated Branches: refs/heads/master d8e4e255d -> d5f61b439
explicit tests for new BitInputStream methods Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/271e0a76 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/271e0a76 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/271e0a76 Branch: refs/heads/master Commit: 271e0a76d4e41171ace14bb802c990d4998dd621 Parents: d8e4e25 Author: Stefan Bodewig <[email protected]> Authored: Sun Jan 21 13:28:47 2018 +0100 Committer: Stefan Bodewig <[email protected]> Committed: Sun Jan 21 13:28:47 2018 +0100 ---------------------------------------------------------------------- .../compress/utils/BitInputStreamTest.java | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/271e0a76/src/test/java/org/apache/commons/compress/utils/BitInputStreamTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/compress/utils/BitInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/BitInputStreamTest.java index e39a0d7..92de71b 100644 --- a/src/test/java/org/apache/commons/compress/utils/BitInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/BitInputStreamTest.java @@ -171,6 +171,41 @@ public class BitInputStreamTest { } } + @Test + public void alignWithByteBoundaryWhenAtBoundary() throws Exception { + try (final BitInputStream bis = new BitInputStream(getStream(), ByteOrder.LITTLE_ENDIAN)) { + assertEquals(0xF8, bis.readBits(8)); + bis.alignWithByteBoundary(); + assertEquals(0, bis.readBits(4)); + } + } + + @Test + public void alignWithByteBoundaryWhenNotAtBoundary() throws Exception { + try (final BitInputStream bis = new BitInputStream(getStream(), ByteOrder.LITTLE_ENDIAN)) { + assertEquals(0x08, bis.readBits(4)); + assertEquals(4, bis.bitsCached()); + bis.alignWithByteBoundary(); + assertEquals(0, bis.bitsCached()); + assertEquals(0, bis.readBits(4)); + } + } + + @Test + public void availableWithoutCache() throws Exception { + try (final BitInputStream bis = new BitInputStream(getStream(), ByteOrder.LITTLE_ENDIAN)) { + assertEquals(32, bis.bitsAvailable()); + } + } + + @Test + public void availableWithCache() throws Exception { + try (final BitInputStream bis = new BitInputStream(getStream(), ByteOrder.LITTLE_ENDIAN)) { + assertEquals(0x08, bis.readBits(4)); + assertEquals(28, bis.bitsAvailable()); + } + } + private ByteArrayInputStream getStream() { return new ByteArrayInputStream(new byte[] { (byte) 0xF8, // 11111000
