Search in sources :

Example 31 with EncodedImage

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

the class ThumbnailBranchProducerTest method testFinalProducerUsedIfFirstTwoReturnNullOrFailure.

@Test
public void testFinalProducerUsedIfFirstTwoReturnNullOrFailure() {
    mockRequestWithResizeOptions(THUMBNAIL_WIDTHS[0] - 50, THUMBNAIL_HEIGHTS[0] - 50);
    EncodedImage thirdImage = mockEncodedImage(THUMBNAIL_WIDTHS[2], THUMBNAIL_HEIGHTS[2], 0);
    mockProducersToProduce(THROW_FAILURE, null, thirdImage);
    mProducer.produceResults(mImageConsumer, mProducerContext);
    verify(mImageConsumer).onNewResult(thirdImage, true);
    verifyAllProducersRequestedForResults();
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Test(org.junit.Test)

Example 32 with EncodedImage

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

the class ThumbnailBranchProducerTest method mockProducersToProduce.

private void mockProducersToProduce(final EncodedImage... images) {
    for (int i = 0; i < images.length; i++) {
        final EncodedImage image = images[i];
        whenProduceResultsCalledTrigger(mThumbnailProducers[i], new ConsumerCallback() {

            @Override
            public void callback(Consumer<EncodedImage> consumer) {
                if (image == THROW_FAILURE) {
                    consumer.onFailure(new IOException("IMAGE FAILED"));
                } else {
                    consumer.onNewResult(image, true);
                }
            }
        });
    }
}
Also used : IOException(java.io.IOException) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 33 with EncodedImage

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

the class ThumbnailSizeCheckerTest method testWithImageNotBigEnoughForResizeOptions.

private static void testWithImageNotBigEnoughForResizeOptions(int[] imageWidths, int[] imageHeights, int startRotation, int additionalRequestWidth, int additionalRequestHeight) {
    for (int rotation = startRotation; rotation < 360; rotation += 180) {
        for (int i = 0; i < TEST_COUNT; i++) {
            ResizeOptions resizeOptions = new ResizeOptions(REQUEST_WIDTHS[i] + additionalRequestWidth, REQUEST_HEIGHTS[i] + additionalRequestHeight);
            EncodedImage encodedImage = mockImage(imageWidths[i], imageHeights[i], rotation);
            assertFalse(ThumbnailSizeChecker.isImageBigEnough(encodedImage, resizeOptions));
        }
    }
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 34 with EncodedImage

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

the class ThumbnailSizeCheckerTest method mockImage.

private static EncodedImage mockImage(int width, int height, int rotation) {
    EncodedImage image = mock(EncodedImage.class);
    when(image.getWidth()).thenReturn(width);
    when(image.getHeight()).thenReturn(height);
    when(image.getRotationAngle()).thenReturn(rotation);
    return image;
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 35 with EncodedImage

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

the class ThumbnailSizeCheckerTest method testWithImageBigEnoughForResizeOptions.

private static void testWithImageBigEnoughForResizeOptions(int[] imageWidths, int[] imageHeights, int startRotation) {
    for (int rotation = startRotation; rotation < 360; rotation += 180) {
        for (int i = 0; i < TEST_COUNT; i++) {
            EncodedImage encodedImage = mockImage(imageWidths[i], imageHeights[i], rotation);
            ResizeOptions resizeOptions = new ResizeOptions(REQUEST_WIDTHS[i], REQUEST_HEIGHTS[i]);
            assertTrue(ThumbnailSizeChecker.isImageBigEnough(encodedImage, resizeOptions));
        }
    }
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) 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