public void testReader5() throws Exception { BitReader in = new BitReader(NIOUtils.fetchFrom(new File("src/test/resources/h264/bitstream/data.dat"))); DummyBitstreamReader in1 = new DummyBitstreamReader( new BufferedInputStream( new FileInputStream("src/test/resources/h264/bitstream/data.dat"))); String readFileToString = new String( NIOUtils.toArray( NIOUtils.fetchFrom(new File("src/test/resources/h264/bitstream/reads.csv")))); String[] split = StringUtils.split(readFileToString, ","); for (String string : split) { String trim = string.trim(); if (StringUtils.isEmpty(trim)) continue; if ("r1".equals(trim)) assertEquals(in1.read1Bit(), in.read1Bit()); else if ("a".equals(trim)) assertEquals(in1.align(), in.align()); else if ("md".equals(trim)) assertEquals(in1.moreData(), in.moreData()); else if ("lb".equals(trim)) assertEquals(in1.lastByte(), in.lastByte()); else if ("cub".equals(trim)) assertEquals(in1.curBit(), in.curBit()); else if (trim.startsWith("s")) { int i = Integer.parseInt(trim.substring(1)); in1.skip(i); in.skip(i); } else if (trim.startsWith("c")) { int i = Integer.parseInt(trim.substring(1)); assertEquals(in1.checkNBit(i), in.checkNBit(i)); } else { int i = Integer.parseInt(trim); assertEquals(in1.readNBit(i), in.readNBit(i)); } } }
@Test public void testReader1() throws IOException { BitReader in = reader( new byte[] { b("10011000"), b("00011100"), b("11001101"), b("01010101"), b("11101001"), b("00101110"), b("00000111"), b("00011101"), b("10100100"), b("01101110"), b("10000101"), b("00001100"), b("01010111"), b("01000000") }); assertFalse(in.lastByte()); assertEquals(i("1"), in.read1Bit()); assertFalse(in.lastByte()); assertEquals(i("00110000001110011001101"), in.checkNBit(23)); assertEquals(i("001"), in.readNBit(3)); assertTrue(in.moreData()); assertFalse(in.lastByte()); assertEquals(i("1000"), in.readNBit(4)); assertTrue(in.isByteAligned()); assertEquals(0, in.curBit()); assertEquals(7, in.skip(7)); assertEquals(7, in.curBit()); assertFalse(in.lastByte()); assertEquals(i("011"), in.readNBit(3)); assertEquals(i("0011010101010"), in.checkNBit(13)); assertEquals(i("0011"), in.readNBit(4)); assertEquals(35, in.skip(35)); assertTrue(in.moreData()); assertFalse(in.lastByte()); assertEquals(i("0011"), in.checkNBit(4)); assertEquals(i("001110110"), in.readNBit(9)); assertFalse(in.lastByte()); assertEquals(i("1"), in.readNBit(1)); assertFalse(in.lastByte()); assertEquals(i("00100"), in.readNBit(5)); assertTrue(in.moreData()); assertFalse(in.lastByte()); assertEquals(i("011"), in.readNBit(3)); assertFalse(in.lastByte()); assertEquals(i("01110"), in.checkNBit(5)); assertEquals(i("01110100"), in.readNBit(8)); assertFalse(in.lastByte()); assertEquals(i("001010000110001"), in.readNBit(15)); assertTrue(in.moreData()); assertFalse(in.lastByte()); assertEquals(i("010111010"), in.readNBit(9)); assertTrue(in.lastByte()); assertFalse(in.moreData()); assertEquals(i("0"), in.read1Bit()); assertEquals(i("0"), in.read1Bit()); assertEquals(i("0"), in.readNBit(1)); assertEquals(i("00"), in.readNBit(2)); }