@Test public void write_withZeroLengthBufferAndZeroOffsetAndLength_doesNothing() throws IOException { os.write(new byte[0], 0, 0); assertThat(inner.toByteArray()).hasLength(0); }
@Test public void write_withZeroLengthBuffer_doesNothing() throws IOException { os.write(new byte[0]); assertThat(inner.toByteArray()).hasLength(0); }
@Test public void getExact_withEmptyPool_returnsExactArray() { byte[] result = pool.getExact(MAX_PUT_SIZE, byte[].class); assertThat(result).hasLength(MAX_PUT_SIZE); }
@Test public void get_withEmptyPool_returnsExactArray() { assertThat(pool.get(MAX_PUT_SIZE, byte[].class)).hasLength(MAX_PUT_SIZE); }
@Test public void get_withPoolContainingSmallerArray_returnsExactArray() { pool.put(new byte[MAX_PUT_SIZE - 1]); assertThat(pool.get(MAX_PUT_SIZE, byte[].class)).hasLength(MAX_PUT_SIZE); }
@Test public void getExact_withPoolContainingLargerArray_returnsExactArray() { pool.put(new byte[MAX_PUT_SIZE]); int expectedSize = MAX_PUT_SIZE - 1; assertThat(pool.getExact(expectedSize, byte[].class)).hasLength(expectedSize); }
@Test public void getExact_withPoolContainingSmallerArray_returnsExactArray() { pool.put(new byte[MAX_PUT_SIZE - 1]); assertThat(pool.getExact(MAX_PUT_SIZE, byte[].class)).hasLength(MAX_PUT_SIZE); }
@Test public void get_withPoolMoreThanHalfFull_sizeLessThanHalfArrayInPool_returnsNewArray() { pool = new LruArrayPool(100); for (int i = 0; i < 3; i++) { byte[] toPut = new byte[100 / 3]; pool.put(toPut); } int requestedSize = 100 / 3 / LruArrayPool.MAX_OVER_SIZE_MULTIPLE; byte[] received = pool.get(requestedSize, byte[].class); assertThat(received).hasLength(requestedSize); }
private static void assertSegment( Segment segment, byte[] data, int length, long byteOffset, Runnable runnable, IOException exception) { if (data != null) { assertThat(segment.data).isEqualTo(data); assertThat(data).hasLength(length); } else { assertThat(segment.data).isNull(); } assertThat(segment.length).isEqualTo(length); assertThat(segment.byteOffset).isEqualTo(byteOffset); assertThat(segment.action).isEqualTo(runnable); assertThat(segment.isActionSegment()).isEqualTo(runnable != null); assertThat(segment.exception).isEqualTo(exception); assertThat(segment.isErrorSegment()).isEqualTo(exception != null); } }
@Test public void testDecodeApicFrame() { byte[] rawId3 = buildSingleFrameTag("APIC", new byte[] {3, 105, 109, 97, 103, 101, 47, 106, 112, 101, 103, 0, 16, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}); Id3Decoder decoder = new Id3Decoder(); Metadata metadata = decoder.decode(rawId3, rawId3.length); assertThat(metadata.length()).isEqualTo(1); ApicFrame apicFrame = (ApicFrame) metadata.get(0); assertThat(apicFrame.mimeType).isEqualTo("image/jpeg"); assertThat(apicFrame.pictureType).isEqualTo(16); assertThat(apicFrame.description).isEqualTo("Hello World"); assertThat(apicFrame.pictureData).hasLength(10); assertThat(apicFrame.pictureData).isEqualTo(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}); }
@Test public void testReadSetupHeadersWithIOExceptions() throws IOException, InterruptedException { byte[] data = OggTestData.getVorbisHeaderPages(); ExtractorInput input = new FakeExtractorInput.Builder().setData(data).setSimulateIOErrors(true) .setSimulateUnknownLength(true).setSimulatePartialReads(true).build(); VorbisReader reader = new VorbisReader(); VorbisReader.VorbisSetup vorbisSetup = readSetupHeaders(reader, input); assertThat(vorbisSetup.idHeader).isNotNull(); assertThat(vorbisSetup.commentHeader).isNotNull(); assertThat(vorbisSetup.setupHeaderData).isNotNull(); assertThat(vorbisSetup.modes).isNotNull(); assertThat(vorbisSetup.commentHeader.length).isEqualTo(45); assertThat(vorbisSetup.idHeader.data).hasLength(30); assertThat(vorbisSetup.setupHeaderData).hasLength(3597); assertThat(vorbisSetup.idHeader.bitrateMax).isEqualTo(-1); assertThat(vorbisSetup.idHeader.bitrateMin).isEqualTo(-1); assertThat(vorbisSetup.idHeader.bitrateNominal).isEqualTo(66666); assertThat(vorbisSetup.idHeader.blockSize0).isEqualTo(512); assertThat(vorbisSetup.idHeader.blockSize1).isEqualTo(1024); assertThat(vorbisSetup.idHeader.channels).isEqualTo(2); assertThat(vorbisSetup.idHeader.framingFlag).isTrue(); assertThat(vorbisSetup.idHeader.sampleRate).isEqualTo(22050); assertThat(vorbisSetup.idHeader.version).isEqualTo(0); assertThat(vorbisSetup.commentHeader.vendor).isEqualTo("Xiph.Org libVorbis I 20030909"); assertThat(vorbisSetup.iLogModes).isEqualTo(1); assertThat(vorbisSetup.setupHeaderData[vorbisSetup.setupHeaderData.length - 1]) .isEqualTo(data[data.length - 1]); assertThat(vorbisSetup.modes[0].blockFlag).isFalse(); assertThat(vorbisSetup.modes[1].blockFlag).isTrue(); }
@Test public void testPeekId3Data_returnId3Tag_ifId3TagPresent() throws IOException, InterruptedException { Id3Peeker id3Peeker = new Id3Peeker(); byte[] rawId3 = Id3DecoderTest.buildSingleFrameTag( "APIC", new byte[] { 3, 105, 109, 97, 103, 101, 47, 106, 112, 101, 103, 0, 16, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }); FakeExtractorInput input = new FakeExtractorInput.Builder().setData(rawId3).build(); Metadata metadata = id3Peeker.peekId3Data(input, /* id3FramePredicate= */ null); assertThat(metadata.length()).isEqualTo(1); ApicFrame apicFrame = (ApicFrame) metadata.get(0); assertThat(apicFrame.mimeType).isEqualTo("image/jpeg"); assertThat(apicFrame.pictureType).isEqualTo(16); assertThat(apicFrame.description).isEqualTo("Hello World"); assertThat(apicFrame.pictureData).hasLength(10); assertThat(apicFrame.pictureData).isEqualTo(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}); }
@Test public void testDecodeMultiFrames() { byte[] rawId3 = buildMultiFramesTag( new FrameSpec( "COMM", new byte[] { 3, 101, 110, 103, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 0, 116, 101, 120, 116, 0 }), new FrameSpec( "APIC", new byte[] { 3, 105, 109, 97, 103, 101, 47, 106, 112, 101, 103, 0, 16, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 })); Id3Decoder decoder = new Id3Decoder(); Metadata metadata = decoder.decode(rawId3, rawId3.length); assertThat(metadata.length()).isEqualTo(2); CommentFrame commentFrame = (CommentFrame) metadata.get(0); ApicFrame apicFrame = (ApicFrame) metadata.get(1); assertThat(commentFrame.language).isEqualTo("eng"); assertThat(commentFrame.description).isEqualTo("description"); assertThat(commentFrame.text).isEqualTo("text"); assertThat(apicFrame.mimeType).isEqualTo("image/jpeg"); assertThat(apicFrame.pictureType).isEqualTo(16); assertThat(apicFrame.description).isEqualTo("Hello World"); assertThat(apicFrame.pictureData).hasLength(10); assertThat(apicFrame.pictureData).isEqualTo(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}); }