Search in sources :

Example 21 with TrivialPooledByteBuffer

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));
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Example 22 with TrivialPooledByteBuffer

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());
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Example 23 with TrivialPooledByteBuffer

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();
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) TestScheduledExecutorService(com.facebook.imagepipeline.testing.TestScheduledExecutorService) UiThreadImmediateExecutorService(com.facebook.common.executors.UiThreadImmediateExecutorService) TimeUnit(java.util.concurrent.TimeUnit) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Aggregations

TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)23 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)9 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)8 Test (org.junit.Test)8 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)6 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)6 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)6 Bitmap (android.graphics.Bitmap)5 Rect (android.graphics.Rect)5 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)4 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)4 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)4 Before (org.junit.Before)4 GifImage (com.facebook.animated.gif.GifImage)3 WebPImage (com.facebook.animated.webp.WebPImage)3 BitmapCounter (com.facebook.imagepipeline.memory.BitmapCounter)2 BitmapFactory (android.graphics.BitmapFactory)1 UiThreadImmediateExecutorService (com.facebook.common.executors.UiThreadImmediateExecutorService)1 BitmapPool (com.facebook.imagepipeline.memory.BitmapPool)1 FlexByteArrayPool (com.facebook.imagepipeline.memory.FlexByteArrayPool)1