Search in sources :

Example 6 with EncodedImage

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

the class LocalContentUriThumbnailFetchProducerTest method mockThumbnailFile.

private void mockThumbnailFile() throws Exception {
    PowerMockito.whenNew(File.class).withArguments(THUMBNAIL_FILE_NAME).thenReturn(mThumbnailFile);
    when(mThumbnailFile.exists()).thenReturn(true);
    when(mThumbnailFile.length()).thenReturn(THUMBNAIL_FILE_SIZE);
    PowerMockito.whenNew(FileInputStream.class).withArguments(THUMBNAIL_FILE_NAME).thenReturn(mock(FileInputStream.class));
    EncodedImage encodedImage = mock(EncodedImage.class);
    when(encodedImage.getSize()).thenReturn((int) THUMBNAIL_FILE_SIZE);
    PowerMockito.whenNew(EncodedImage.class).withAnyArguments().thenReturn(encodedImage);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) FileInputStream(java.io.FileInputStream)

Example 7 with EncodedImage

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

the class LocalExifThumbnailProducerTest method setUp.

@Before
public void setUp() throws IOException {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(JfifUtil.class, BitmapUtil.class);
    mTestExecutorService = new TestExecutorService(new FakeClock());
    mTestLocalExifThumbnailProducer = new TestLocalExifThumbnailProducer(mTestExecutorService, mPooledByteBufferFactory, mContentResolver);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mImageRequest.getSourceUri()).thenReturn(mUri);
    when(mProducerContext.getListener()).thenReturn(mProducerListener);
    mThumbnailBytes = new byte[100];
    when(mExifInterface.hasThumbnail()).thenReturn(true);
    when(mExifInterface.getThumbnail()).thenReturn(mThumbnailBytes);
    when(mPooledByteBufferFactory.newByteBuffer(mThumbnailBytes)).thenReturn(mThumbnailByteBuffer);
    when(mExifInterface.getAttribute(ExifInterface.TAG_ORIENTATION)).thenReturn(Integer.toString(ORIENTATION));
    when(JfifUtil.getAutoRotateAngleFromOrientation(ORIENTATION)).thenReturn(ANGLE);
    when(BitmapUtil.decodeDimensions(any(InputStream.class))).thenReturn(new Pair(WIDTH, HEIGHT));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCapturedEncodedImage = EncodedImage.cloneOrNull((EncodedImage) invocation.getArguments()[0]);
            return null;
        }
    }).when(mConsumer).onNewResult(notNull(EncodedImage.class), anyBoolean());
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) InputStream(java.io.InputStream) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Pair(android.util.Pair)

Example 8 with EncodedImage

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

the class LocalFileFetchProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalFileFetchProducer = new LocalFileFetchProducer(mExecutor, mPooledByteBufferFactory);
    mFile = new File(RuntimeEnvironment.application.getExternalFilesDir(null), TEST_FILENAME);
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(mFile));
    bos.write(new byte[INPUT_STREAM_LENGTH], 0, INPUT_STREAM_LENGTH);
    bos.close();
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    when(mImageRequest.getSourceFile()).thenReturn(mFile);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCapturedEncodedImage = EncodedImage.cloneOrNull((EncodedImage) invocation.getArguments()[0]);
            return null;
        }
    }).when(mConsumer).onNewResult(notNull(EncodedImage.class), anyBoolean());
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 9 with EncodedImage

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

the class ArtDecoderTest method setUp.

@Before
public void setUp() throws Exception {
    final Random random = new Random();
    random.setSeed(RANDOM_SEED);
    mEncodedBytes = new byte[ENCODED_BYTES_LENGTH];
    random.nextBytes(mEncodedBytes);
    mPooledByteBuffer = new TrivialPooledByteBuffer(mEncodedBytes);
    mBitmapPool = mock(BitmapPool.class);
    mArtDecoder = new ArtDecoder(mBitmapPool, 1, new Pools.SynchronizedPool(1));
    mByteBufferRef = CloseableReference.of(mPooledByteBuffer);
    mEncodedImage = new EncodedImage(mByteBufferRef);
    mEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
    mBitmap = MockBitmapFactory.create();
    doReturn(mBitmap).when(mBitmapPool).get(MockBitmapFactory.DEFAULT_BITMAP_SIZE);
    mBitmapFactoryDefaultAnswer = new Answer<Bitmap>() {

        @Override
        public Bitmap answer(InvocationOnMock invocation) throws Throwable {
            final BitmapFactory.Options options = (BitmapFactory.Options) invocation.getArguments()[2];
            options.outWidth = MockBitmapFactory.DEFAULT_BITMAP_WIDTH;
            options.outHeight = MockBitmapFactory.DEFAULT_BITMAP_HEIGHT;
            verifyBitmapFactoryOptions(options);
            return options.inJustDecodeBounds ? null : mBitmap;
        }
    };
    whenBitmapFactoryDecodeStream().thenAnswer(mBitmapFactoryDefaultAnswer);
    ByteBuffer buf = mArtDecoder.mDecodeBuffers.acquire();
    mTempStorage = buf.array();
    mArtDecoder.mDecodeBuffers.release(buf);
}
Also used : BitmapPool(com.facebook.imagepipeline.memory.BitmapPool) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) ByteBuffer(java.nio.ByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) Bitmap(android.graphics.Bitmap) Random(java.util.Random) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) MockBitmapFactory(com.facebook.imagepipeline.testing.MockBitmapFactory) BitmapFactory(android.graphics.BitmapFactory) Before(org.junit.Before)

Example 10 with EncodedImage

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

the class GingerbreadPurgeableDecoderTest method setUp.

@Before
public void setUp() {
    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.decodeFileDescriptor(any(FileDescriptor.class), any(Rect.class), 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));
    mockStatic(Bitmaps.class);
    mGingerbreadPurgeableDecoder = new GingerbreadPurgeableDecoder();
}
Also used : BitmapCounter(com.facebook.imagepipeline.memory.BitmapCounter) Rect(android.graphics.Rect) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) FileDescriptor(java.io.FileDescriptor) Before(org.junit.Before)

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