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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations