Search in sources :

Example 1 with SingleUsePostprocessorConsumer

use of com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer in project fresco by facebook.

the class SingleUsePostprocessorProducerTest method testSuccess.

@Test
public void testSuccess() {
    SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
    doReturn(mDestinationCloseableBitmapRef).when(mPostprocessor).process(mSourceBitmap, mPlatformBitmapFactory);
    postprocessorConsumer.onNewResult(mSourceCloseableImageRef, Consumer.IS_LAST);
    mSourceCloseableImageRef.close();
    mTestExecutorService.runUntilIdle();
    mInOrder.verify(mProducerListener).onProducerStart(mProducerContext, PostprocessorProducer.NAME);
    mInOrder.verify(mPostprocessor).process(mSourceBitmap, mPlatformBitmapFactory);
    mInOrder.verify(mProducerListener).requiresExtraMap(mProducerContext, PostprocessorProducer.NAME);
    mInOrder.verify(mProducerListener).onProducerFinishWithSuccess(mProducerContext, PostprocessorProducer.NAME, mExtraMap);
    mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.IS_LAST));
    mInOrder.verifyNoMoreInteractions();
    assertEquals(1, mResults.size());
    CloseableReference<CloseableImage> res0 = mResults.get(0);
    assertTrue(CloseableReference.isValid(res0));
    assertSame(mDestinationBitmap, ((CloseableStaticBitmap) res0.get()).getUnderlyingBitmap());
    res0.close();
    verify(mBitmapResourceReleaser).release(mDestinationBitmap);
    verify(mSourceCloseableStaticBitmap).close();
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) SingleUsePostprocessorConsumer(com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer)

Example 2 with SingleUsePostprocessorConsumer

use of com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer in project fresco by facebook.

the class SingleUsePostprocessorProducerTest method testIntermediateImageIsNotProcessed.

@Test
public void testIntermediateImageIsNotProcessed() {
    SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
    postprocessorConsumer.onNewResult(mSourceCloseableImageRef, Consumer.NO_FLAGS);
    mSourceCloseableImageRef.close();
    mTestExecutorService.runUntilIdle();
    mInOrder.verifyNoMoreInteractions();
    assertEquals(0, mResults.size());
    verify(mSourceCloseableStaticBitmap).close();
}
Also used : SingleUsePostprocessorConsumer(com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer)

Example 3 with SingleUsePostprocessorConsumer

use of com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer in project fresco by facebook.

the class AnimatedSingleUsePostprocessorProducerTest method testNonStaticBitmapIsPassedOn.

@Test
public void testNonStaticBitmapIsPassedOn() {
    SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
    CloseableAnimatedImage sourceCloseableAnimatedImage = mock(CloseableAnimatedImage.class);
    CloseableReference<CloseableImage> sourceCloseableImageRef = CloseableReference.<CloseableImage>of(sourceCloseableAnimatedImage);
    postprocessorConsumer.onNewResult(sourceCloseableImageRef, Consumer.IS_LAST);
    sourceCloseableImageRef.close();
    mTestExecutorService.runUntilIdle();
    mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.IS_LAST));
    mInOrder.verifyNoMoreInteractions();
    assertEquals(1, mResults.size());
    CloseableReference<CloseableImage> res0 = mResults.get(0);
    assertTrue(CloseableReference.isValid(res0));
    assertSame(sourceCloseableAnimatedImage, res0.get());
    res0.close();
    verify(sourceCloseableAnimatedImage).close();
}
Also used : CloseableAnimatedImage(com.facebook.imagepipeline.image.CloseableAnimatedImage) CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) SingleUsePostprocessorConsumer(com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer)

Example 4 with SingleUsePostprocessorConsumer

use of com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer in project fresco by facebook.

the class SingleUsePostprocessorProducerTest method testFailure.

@Test
public void testFailure() {
    SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
    doThrow(new RuntimeException()).when(mPostprocessor).process(eq(mSourceBitmap), eq(mPlatformBitmapFactory));
    postprocessorConsumer.onNewResult(mSourceCloseableImageRef, Consumer.IS_LAST);
    mSourceCloseableImageRef.close();
    mTestExecutorService.runUntilIdle();
    mInOrder.verify(mProducerListener).onProducerStart(mProducerContext, PostprocessorProducer.NAME);
    mInOrder.verify(mPostprocessor).process(mSourceBitmap, mPlatformBitmapFactory);
    mInOrder.verify(mProducerListener).requiresExtraMap(mProducerContext, PostprocessorProducer.NAME);
    mInOrder.verify(mProducerListener).onProducerFinishWithFailure(eq(mProducerContext), eq(PostprocessorProducer.NAME), any(RuntimeException.class), eq(mExtraMap));
    mInOrder.verify(mConsumer).onFailure(nullable(Throwable.class));
    mInOrder.verifyNoMoreInteractions();
    assertEquals(0, mResults.size());
    verify(mSourceCloseableStaticBitmap).close();
}
Also used : SingleUsePostprocessorConsumer(com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer)

Aggregations

SingleUsePostprocessorConsumer (com.facebook.imagepipeline.producers.PostprocessorProducer.SingleUsePostprocessorConsumer)4 CloseableReference (com.facebook.common.references.CloseableReference)2 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)2 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)1