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 testRandom1Bit() throws IOException { byte[] data = randomData(10000); BitReader in1 = reader(data); DummyBitstreamReader in2 = new DummyBitstreamReader(new ByteArrayInputStream(data)); for (int i = 0; i < 80000; i++) { int exp = in2.read1Bit(); assertEquals(exp, in1.read1Bit()); } }
@Test public void testRandomNBit() throws IOException { for (int bits = 1; bits <= 32; bits++) { byte[] data = randomData(bits * 10000); BitReader in1 = reader(data); DummyBitstreamReader in2 = new DummyBitstreamReader(new ByteArrayInputStream(data)); for (int i = 0; i < 80000; i++) { int exp = in2.readNBit(bits); int exp1 = in1.readNBit(bits); assertEquals(exp, exp1); } } }