Search in sources :

Example 11 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class KitKatPurgeableDecoderTest method setUp.

@Before
public void setUp() {
    mFlexByteArrayPool = mock(FlexByteArrayPool.class);
    mBitmap = MockBitmapFactory.create();
    mBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_SIZE);
    mockStatic(BitmapCounterProvider.class);
    when(BitmapCounterProvider.get()).thenReturn(mBitmapCounter);
    mockStatic(BitmapFactory.class);
    when(BitmapFactory.decodeByteArray(any(byte[].class), anyInt(), anyInt(), any(BitmapFactory.Options.class))).thenReturn(mBitmap);
    mInputBuf = new byte[LENGTH];
    PooledByteBuffer input = new TrivialPooledByteBuffer(mInputBuf, POINTER);
    mByteBufferRef = CloseableReference.of(input);
    mEncodedImage = new EncodedImage(mByteBufferRef);
    mDecodeBuf = new byte[LENGTH + 2];
    mDecodeBufRef = CloseableReference.of(mDecodeBuf, mock(ResourceReleaser.class));
    when(mFlexByteArrayPool.get(Integer.valueOf(LENGTH))).thenReturn(mDecodeBufRef);
    mockStatic(Bitmaps.class);
    mKitKatPurgeableDecoder = new KitKatPurgeableDecoder(mFlexByteArrayPool);
}
Also used : BitmapCounter(com.facebook.imagepipeline.memory.BitmapCounter) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) FlexByteArrayPool(com.facebook.imagepipeline.memory.FlexByteArrayPool) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Before(org.junit.Before)

Example 12 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNullResult.

@Test
public void testOnNullResult() {
    mAddMetaDataConsumer.onNewResult(null, true);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(true));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertEquals(encodedImage, null);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 13 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNewResultNotLast_DimensionsNotFound.

@Test
public void testOnNewResultNotLast_DimensionsNotFound() {
    int rotationAngle = 180;
    int orientation = 1;
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.JPEG);
    when(JfifUtil.getAutoRotateAngleFromOrientation(orientation)).thenReturn(rotationAngle);
    when(JfifUtil.getOrientation(any(InputStream.class))).thenReturn(orientation);
    when(BitmapUtil.decodeDimensions(any(InputStream.class))).thenReturn(null);
    mAddMetaDataConsumer.onNewResult(mIntermediateResult, false);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(false));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertTrue(EncodedImage.isValid(encodedImage));
    assertEquals(-1, encodedImage.getRotationAngle());
    assertEquals(-1, encodedImage.getWidth());
    assertEquals(-1, encodedImage.getHeight());
}
Also used : InputStream(java.io.InputStream) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 14 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNewResultNotLastAndJpeg.

@Test
public void testOnNewResultNotLastAndJpeg() {
    int rotationAngle = 180;
    int orientation = 1;
    int width = 10;
    int height = 20;
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.JPEG);
    when(JfifUtil.getAutoRotateAngleFromOrientation(orientation)).thenReturn(rotationAngle);
    when(JfifUtil.getOrientation(any(InputStream.class))).thenReturn(orientation);
    when(BitmapUtil.decodeDimensions(any(InputStream.class))).thenReturn(new Pair(width, height));
    mAddMetaDataConsumer.onNewResult(mFinalResult, true);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(true));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertTrue(EncodedImage.isValid(encodedImage));
    assertEquals(DefaultImageFormats.JPEG, encodedImage.getImageFormat());
    assertEquals(rotationAngle, encodedImage.getRotationAngle());
    assertEquals(width, encodedImage.getWidth());
    assertEquals(height, encodedImage.getHeight());
}
Also used : InputStream(java.io.InputStream) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Pair(android.util.Pair)

Example 15 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class AddImageTransformMetaDataProducerTest method testOnNewResultLastNotJpeg.

@Test
public void testOnNewResultLastNotJpeg() {
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.WEBP_SIMPLE);
    mAddMetaDataConsumer.onNewResult(mFinalResult, true);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(true));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertTrue(EncodedImage.isValid(encodedImage));
    assertEquals(DefaultImageFormats.WEBP_SIMPLE, encodedImage.getImageFormat());
    assertEquals(0, encodedImage.getRotationAngle());
    assertEquals(-1, encodedImage.getWidth());
    assertEquals(-1, encodedImage.getHeight());
}
Also used : InputStream(java.io.InputStream) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Aggregations

EncodedImage (com.facebook.imagepipeline.image.EncodedImage)91 Test (org.junit.Test)24 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)19 CacheKey (com.facebook.cache.common.CacheKey)9 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 InputStream (java.io.InputStream)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Bitmap (android.graphics.Bitmap)7 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)7 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)6 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)6 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)6 FakeClock (com.facebook.imagepipeline.testing.FakeClock)6 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)6 Before (org.junit.Before)6 Rect (android.graphics.Rect)5 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)5 ArrayList (java.util.ArrayList)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5