Search in sources :

Example 16 with EncodedImage

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

the class AddImageTransformMetaDataProducerTest method testOnNewResultLastAndJpeg.

@Test
public void testOnNewResultLastAndJpeg() {
    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());
}
Also used : InputStream(java.io.InputStream) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Pair(android.util.Pair)

Example 17 with EncodedImage

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

the class JobSchedulerTest method testSchedule_TooSoon.

@Test
public void testSchedule_TooSoon() {
    EncodedImage encodedImage1 = fakeEncodedImage();
    mJobScheduler.updateJob(encodedImage1, false);
    mJobScheduler.scheduleJob();
    mFakeClockForTime.incrementBy(1234);
    mFakeClockForWorker.incrementBy(1234);
    mFakeClockForScheduled.incrementBy(1234);
    EncodedImage encodedImage2 = fakeEncodedImage();
    mJobScheduler.updateJob(encodedImage2, true);
    mFakeClockForTime.incrementBy(INTERVAL - 5);
    mFakeClockForWorker.incrementBy(INTERVAL - 5);
    mFakeClockForScheduled.incrementBy(INTERVAL - 5);
    mJobScheduler.scheduleJob();
    mFakeClockForTime.incrementBy(0);
    mFakeClockForWorker.incrementBy(0);
    mFakeClockForScheduled.incrementBy(0);
    assertEquals(1, mTestScheduledExecutorService.getPendingCount());
    assertEquals(5, mTestScheduledExecutorService.getScheduledQueue().getNextPendingCommandDelay());
    assertEquals(0, mTestExecutorService.getPendingCount());
    assertEquals(1, mTestJobRunnable.jobs.size());
    mFakeClockForTime.incrementBy(5);
    mFakeClockForWorker.incrementBy(5);
    mFakeClockForScheduled.incrementBy(5);
    assertEquals(0, mTestScheduledExecutorService.getPendingCount());
    assertEquals(1, mTestExecutorService.getPendingCount());
    assertEquals(1, mTestJobRunnable.jobs.size());
    mFakeClockForTime.incrementBy(0);
    mFakeClockForWorker.incrementBy(0);
    mFakeClockForScheduled.incrementBy(0);
    assertEquals(0, mTestScheduledExecutorService.getPendingCount());
    assertEquals(0, mTestExecutorService.getPendingCount());
    assertEquals(2, mTestJobRunnable.jobs.size());
    assertJobsEqual(mTestJobRunnable.jobs.get(1), encodedImage2, true);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with EncodedImage

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

the class JobSchedulerTest method fakeEncodedImage.

private EncodedImage fakeEncodedImage() {
    PooledByteBuffer buf = mock(PooledByteBuffer.class);
    CloseableReference<PooledByteBuffer> ref = CloseableReference.of(buf);
    return new EncodedImage(ref);
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 19 with EncodedImage

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

the class JobSchedulerTest method testSchedule_Last_Idle.

@Test
public void testSchedule_Last_Idle() throws Exception {
    EncodedImage encodedImage = fakeEncodedImage();
    mJobScheduler.updateJob(encodedImage, true);
    assertEquals(JobScheduler.JobState.IDLE, mJobScheduler.mJobState);
    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, true);
    mTestJobRunnable.jobs.get(0).encodedImage.close();
    encodedImage.close();
    assertNull(encodedImage.getByteBufferRef());
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with EncodedImage

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

the class JobSchedulerTest method testSchedule_Last_Queued.

@Test
public void testSchedule_Last_Queued() {
    mJobScheduler.updateJob(fakeEncodedImage(), true);
    assertTrue(mJobScheduler.scheduleJob());
    EncodedImage encodedImage2 = fakeEncodedImage();
    mJobScheduler.updateJob(encodedImage2, true);
    assertEquals(JobScheduler.JobState.QUEUED, mJobScheduler.mJobState);
    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), encodedImage2, true);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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