Search in sources :

Example 71 with EncodedImage

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

the class JobSchedulerTest method testSchedule_Intermediate.

@Test
public void testSchedule_Intermediate() {
    EncodedImage encodedImage = fakeEncodedImage();
    mJobScheduler.updateJob(encodedImage, Consumer.NO_FLAGS);
    assertTrue(mJobScheduler.scheduleJob());
    assertEquals(0, mTestScheduledExecutorService.getPendingCount());
    assertEquals(1, mTestExecutorService.getPendingCount());
    assertEquals(0, mTestJobRunnable.jobs.size());
    mFakeClockForTime.incrementBy(1234);
    mFakeClockForWorker.incrementBy(1234);
    mFakeClockForScheduled.incrementBy(1234);
    assertEquals(1, mTestJobRunnable.jobs.size());
    assertJobsEqual(mTestJobRunnable.jobs.get(0), encodedImage, Consumer.NO_FLAGS);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 72 with EncodedImage

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

the class JobSchedulerTest method testUpdate_Intermediate.

@Test
public void testUpdate_Intermediate() {
    EncodedImage encodedImage = fakeEncodedImage();
    assertTrue(mJobScheduler.updateJob(encodedImage, Consumer.NO_FLAGS));
    assertNotSame(encodedImage, mJobScheduler.mEncodedImage);
    assertReferencesEqual(encodedImage, mJobScheduler.mEncodedImage);
    assertEquals(Consumer.NO_FLAGS, mJobScheduler.mStatus);
    assertEquals(0, mTestScheduledExecutorService.getPendingCount());
    assertEquals(0, mTestExecutorService.getPendingCount());
    assertEquals(0, mTestJobRunnable.jobs.size());
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with EncodedImage

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

the class LocalContentUriFetchProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalContentUriFetchProducer = new LocalContentUriFetchProducer(mExecutor, mPooledByteBufferFactory, mContentResolver);
    mContentUri = Uri.fromFile(mock(File.class));
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM, mConfig);
    when(mImageRequest.getSourceUri()).thenReturn(mContentUri);
    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), anyInt());
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 74 with EncodedImage

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

the class AddImageTransformMetaDataProducerTest method testOnNewResultNotLast_RotationNotFound.

@Test
public void testOnNewResultNotLast_RotationNotFound() {
    when(ImageFormatChecker.getImageFormat_WrapIOException(any(InputStream.class))).thenReturn(DefaultImageFormats.JPEG);
    when(JfifUtil.getOrientation(any(InputStream.class))).thenReturn(0);
    when(BitmapUtil.decodeDimensionsAndColorSpace(any(InputStream.class))).thenReturn(new ImageMetaData(-1, -1, null));
    mAddMetaDataConsumer.onNewResult(mIntermediateResult, Consumer.NO_FLAGS);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.NO_FLAGS));
    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) ImageMetaData(com.facebook.imageutils.ImageMetaData) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 75 with EncodedImage

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

the class AddImageTransformMetaDataProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(ImageFormatChecker.class, JfifUtil.class, BitmapUtil.class);
    mAddMetaDataProducer = new AddImageTransformMetaDataProducer(mInputProducer);
    mIntermediateResultBufferRef = CloseableReference.of(mock(PooledByteBuffer.class));
    mFinalResultBufferRef = CloseableReference.of(mock(PooledByteBuffer.class));
    mIntermediateResult = new EncodedImage(mIntermediateResultBufferRef);
    mFinalResult = new EncodedImage(mFinalResultBufferRef);
    mAddMetaDataConsumer = null;
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mAddMetaDataConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
            return null;
        }
    }).when(mInputProducer).produceResults(any(Consumer.class), any(ProducerContext.class));
    mAddMetaDataProducer.produceResults(mConsumer, mProducerContext);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Aggregations

EncodedImage (com.facebook.imagepipeline.image.EncodedImage)108 Test (org.junit.Test)32 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)20 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)12 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)12 CacheKey (com.facebook.cache.common.CacheKey)11 Rect (android.graphics.Rect)9 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)9 InputStream (java.io.InputStream)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)8 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)8 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)8 Before (org.junit.Before)8 Bitmap (android.graphics.Bitmap)7 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)7 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)7 FakeClock (com.facebook.imagepipeline.testing.FakeClock)6 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)6