use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.
the class LocalResourceFetchProducerTest method testFetchLocalResource.
@Test
public void testFetchLocalResource() throws Exception {
PooledByteBuffer pooledByteBuffer = mock(PooledByteBuffer.class);
when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class), eq(TEST_DATA_LENGTH))).thenReturn(pooledByteBuffer);
when(mResources.openRawResource(eq(TEST_ID))).thenReturn(new ByteArrayInputStream(new byte[TEST_DATA_LENGTH]));
mLocalResourceFetchProducer.produceResults(mConsumer, mProducerContext);
mExecutor.runUntilIdle();
}
use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.
the class BranchOnSeparateImagesProducerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mInputProducer1 = mock(Producer.class);
mInputProducer2 = mock(Producer.class);
BranchOnSeparateImagesProducer branchOnSeparateImagesProducer = new BranchOnSeparateImagesProducer(mInputProducer1, mInputProducer2);
when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
when(mImageRequest.getPreferredWidth()).thenReturn(WIDTH);
when(mImageRequest.getPreferredHeight()).thenReturn(HEIGHT);
when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(WIDTH, HEIGHT));
when(mImageRequest.getLocalThumbnailPreviewsEnabled()).thenReturn(true);
mIntermediateResult = mock(EncodedImage.class);
mFirstProducerFinalResult = mock(EncodedImage.class);
mSecondProducerFinalResult = mock(EncodedImage.class);
PooledByteBuffer mockByteBuffer = mock(PooledByteBuffer.class);
when(mIntermediateResult.getByteBufferRef()).thenReturn(CloseableReference.of(mockByteBuffer));
when(mFirstProducerFinalResult.getByteBufferRef()).thenReturn(CloseableReference.of(mockByteBuffer));
when(mSecondProducerFinalResult.getByteBufferRef()).thenReturn(CloseableReference.of(mockByteBuffer));
mFirstProducerConsumer = null;
mSecondProducerConsumer = null;
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mFirstProducerConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
return null;
}
}).when(mInputProducer1).produceResults(any(Consumer.class), any(ProducerContext.class));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mSecondProducerConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
return null;
}
}).when(mInputProducer2).produceResults(any(Consumer.class), any(ProducerContext.class));
branchOnSeparateImagesProducer.produceResults(mConsumer, mProducerContext);
}
use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.
the class DecodeProducerTest method testNewResult_Intermediate_pJPEG.
@Test
public void testNewResult_Intermediate_pJPEG() {
setupNetworkUri();
Consumer<EncodedImage> consumer = produceResults();
InOrder inOrder = inOrder(mJobScheduler, mProgressiveJpegParser);
ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
// preview scan; schedule
when(mJobScheduler.updateJob(mEncodedImage, false)).thenReturn(true);
when(mProgressiveJpegParser.parseMoreData(any(EncodedImage.class))).thenReturn(true);
when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(PREVIEW_SCAN);
consumer.onNewResult(mEncodedImage, false);
inOrder.verify(mJobScheduler).updateJob(mEncodedImage, false);
inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
inOrder.verify(mJobScheduler).scheduleJob();
assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), mByteBufferRef.getUnderlyingReferenceTestOnly());
// no data parsed; ignore
PooledByteBuffer pooledByteBuffer2 = mockPooledByteBuffer(210);
CloseableReference<PooledByteBuffer> ref2 = CloseableReference.of(pooledByteBuffer2);
EncodedImage encodedImage2 = mockEncodedImage(ref2);
when(mJobScheduler.updateJob(encodedImage2, false)).thenReturn(true);
when(mProgressiveJpegParser.parseMoreData(encodedImage2)).thenReturn(false);
when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(PREVIEW_SCAN);
consumer.onNewResult(encodedImage2, false);
inOrder.verify(mJobScheduler).updateJob(encodedImage2, false);
inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
inOrder.verify(mJobScheduler, never()).scheduleJob();
assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref2.getUnderlyingReferenceTestOnly());
// same scan; ignore
PooledByteBuffer pooledByteBuffer3 = mockPooledByteBuffer(220);
CloseableReference<PooledByteBuffer> ref3 = CloseableReference.of(pooledByteBuffer3);
EncodedImage encodedImage3 = mockEncodedImage(ref3);
when(mJobScheduler.updateJob(encodedImage3, false)).thenReturn(true);
when(mProgressiveJpegParser.parseMoreData(encodedImage3)).thenReturn(true);
when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(PREVIEW_SCAN);
consumer.onNewResult(encodedImage3, false);
inOrder.verify(mJobScheduler).updateJob(encodedImage3, false);
inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
inOrder.verify(mJobScheduler, never()).scheduleJob();
assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref3.getUnderlyingReferenceTestOnly());
// scan not for decode; ignore
PooledByteBuffer pooledByteBuffer4 = mockPooledByteBuffer(300);
CloseableReference<PooledByteBuffer> ref4 = CloseableReference.of(pooledByteBuffer4);
EncodedImage encodedImage4 = mockEncodedImage(ref4);
when(mJobScheduler.updateJob(encodedImage4, false)).thenReturn(true);
when(mProgressiveJpegParser.parseMoreData(encodedImage4)).thenReturn(true);
when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(IGNORED_SCAN);
consumer.onNewResult(encodedImage4, false);
inOrder.verify(mJobScheduler).updateJob(encodedImage4, false);
inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
inOrder.verify(mJobScheduler, never()).scheduleJob();
assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref4.getUnderlyingReferenceTestOnly());
// good-enough scan; schedule
PooledByteBuffer pooledByteBuffer5 = mockPooledByteBuffer(500);
CloseableReference<PooledByteBuffer> ref5 = CloseableReference.of(pooledByteBuffer5);
EncodedImage encodedImage5 = mockEncodedImage(ref5);
when(mJobScheduler.updateJob(encodedImage5, false)).thenReturn(true);
when(mProgressiveJpegParser.parseMoreData(encodedImage5)).thenReturn(true);
when(mProgressiveJpegParser.getBestScanNumber()).thenReturn(GOOD_ENOUGH_SCAN);
consumer.onNewResult(encodedImage5, false);
inOrder.verify(mJobScheduler).updateJob(encodedImage5, false);
inOrder.verify(mProgressiveJpegParser).parseMoreData(argumentCaptor.capture());
inOrder.verify(mJobScheduler).scheduleJob();
assertSame(((EncodedImage) argumentCaptor.getValue()).getUnderlyingReferenceTestOnly(), ref5.getUnderlyingReferenceTestOnly());
}
use of com.facebook.common.memory.PooledByteBuffer in project fresco by facebook.
the class DecodeProducerTest method mockPooledByteBuffer.
private static PooledByteBuffer mockPooledByteBuffer(int size) {
PooledByteBuffer pooledByteBuffer = mock(PooledByteBuffer.class);
when(pooledByteBuffer.size()).thenReturn(size);
return pooledByteBuffer;
}
Aggregations