use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.
the class EncodedImageTest method testIsJpegCompleteAt_Complete.
@Test
public void testIsJpegCompleteAt_Complete() {
byte[] encodedBytes = new byte[ENCODED_BYTES_LENGTH];
encodedBytes[ENCODED_BYTES_LENGTH - 2] = (byte) JfifUtil.MARKER_FIRST_BYTE;
encodedBytes[ENCODED_BYTES_LENGTH - 1] = (byte) JfifUtil.MARKER_EOI;
PooledByteBuffer buf = new TrivialPooledByteBuffer(encodedBytes);
EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf));
encodedImage.setImageFormat(DefaultImageFormats.JPEG);
assertTrue(encodedImage.isCompleteAt(ENCODED_BYTES_LENGTH));
}
use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.
the class EncodedImageTest method checkWebpImage.
private void checkWebpImage(final String imagePath, final ImageFormat imageFormat, final int expectedWidth, final int expectedHeight) throws IOException {
PooledByteBuffer buf = new TrivialPooledByteBuffer(ByteStreams.toByteArray(EncodedImageTest.class.getResourceAsStream(imagePath)));
EncodedImage encodedImage = new EncodedImage(CloseableReference.of(buf));
encodedImage.parseMetaData();
assertSame(imageFormat, encodedImage.getImageFormat());
assertEquals(expectedWidth, encodedImage.getWidth());
assertEquals(expectedHeight, encodedImage.getHeight());
assertEquals(0, encodedImage.getRotationAngle());
}
use of com.facebook.imagepipeline.testing.TrivialPooledByteBuffer in project fresco by facebook.
the class ResizeAndRotateProducerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFakeClockForWorker = new FakeClock();
mFakeClockForScheduled = new FakeClock();
mFakeClockForWorker.incrementBy(1000);
mFakeClockForScheduled.incrementBy(1000);
PowerMockito.mockStatic(SystemClock.class);
when(SystemClock.uptimeMillis()).thenAnswer(new Answer<Long>() {
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
return mFakeClockForWorker.now();
}
});
when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("http://testuri"));
mTestExecutorService = new TestExecutorService(mFakeClockForWorker);
mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClockForScheduled);
mUiThreadImmediateExecutorService = mock(UiThreadImmediateExecutorService.class);
when(mUiThreadImmediateExecutorService.schedule(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return mTestScheduledExecutorService.schedule((Runnable) invocation.getArguments()[0], (long) invocation.getArguments()[1], (TimeUnit) invocation.getArguments()[2]);
}
});
PowerMockito.mockStatic(UiThreadImmediateExecutorService.class);
when(UiThreadImmediateExecutorService.getInstance()).thenReturn(mUiThreadImmediateExecutorService);
PowerMockito.mockStatic(JpegTranscoder.class);
PowerMockito.when(JpegTranscoder.isRotationAngleAllowed(anyInt())).thenCallRealMethod();
mTestExecutorService = new TestExecutorService(mFakeClockForWorker);
when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
when(mProducerContext.getListener()).thenReturn(mProducerListener);
when(mProducerListener.requiresExtraMap(anyString())).thenReturn(true);
mIntermediateResult = CloseableReference.of(mock(PooledByteBuffer.class));
mFinalResult = CloseableReference.of(mock(PooledByteBuffer.class));
mResizeAndRotateProducerConsumer = null;
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mResizeAndRotateProducerConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
return null;
}
}).when(mInputProducer).produceResults(any(Consumer.class), any(ProducerContext.class));
doReturn(mPooledByteBufferOutputStream).when(mPooledByteBufferFactory).newOutputStream();
mPooledByteBuffer = new TrivialPooledByteBuffer(new byte[] { 1 }, 0);
doReturn(mPooledByteBuffer).when(mPooledByteBufferOutputStream).toByteBuffer();
}
Aggregations