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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations