Skip to content

Commit

Permalink
Reduce some test paths
Browse files Browse the repository at this point in the history
The emulator tests are a bit slow and fails with so many cases.
Reduce the number of scaling tests and run them only when config
is ARGB_8888.
  • Loading branch information
vigneshvg committed Oct 21, 2023
1 parent 370324a commit 1809d89
Showing 1 changed file with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ByteBuffer getBuffer() throws IOException {

private static final int AVIF_RESULT_OK = 0;

private static final float[] SCALE_FACTORS = {0.5f, 1.3f, 2.0f};
private static final float[] SCALE_FACTORS = {0.5f, 1.3f};

private static final Image[] IMAGES = {
// Parameter ordering for still images: directory, filename, width, height, depth, alphaPresent,
Expand Down Expand Up @@ -160,24 +160,27 @@ public void testDecodeUtilityClass() throws IOException {
assertThat(bitmap).isNotNull();
assertThat(AvifDecoder.decode(buffer, buffer.remaining(), bitmap)).isTrue();

// Test scaling.
for (float scale_factor : SCALE_FACTORS) {
// Scale both width and height.
bitmap =
Bitmap.createBitmap(
(int) (info.width * scale_factor), (int) (info.height * scale_factor), config);
assertThat(bitmap).isNotNull();
assertThat(AvifDecoder.decode(buffer, buffer.remaining(), bitmap)).isTrue();
// Test scaling. These tests can be a bit slow on emulators, so only run them when config is
// ARGB_8888.
if (config == Config.ARGB_8888) {
for (float scale_factor : SCALE_FACTORS) {
// Scale both width and height.
bitmap =
Bitmap.createBitmap(
(int) (info.width * scale_factor), (int) (info.height * scale_factor), config);
assertThat(bitmap).isNotNull();
assertThat(AvifDecoder.decode(buffer, buffer.remaining(), bitmap)).isTrue();

// Scale width only.
bitmap = Bitmap.createBitmap((int) (info.width * scale_factor), info.height, config);
assertThat(bitmap).isNotNull();
assertThat(AvifDecoder.decode(buffer, buffer.remaining(), bitmap)).isTrue();
// Scale width only.
bitmap = Bitmap.createBitmap((int) (info.width * scale_factor), info.height, config);
assertThat(bitmap).isNotNull();
assertThat(AvifDecoder.decode(buffer, buffer.remaining(), bitmap)).isTrue();

// Scale height only.
bitmap = Bitmap.createBitmap(info.width, (int) (info.height * scale_factor), config);
assertThat(bitmap).isNotNull();
assertThat(AvifDecoder.decode(buffer, buffer.remaining(), bitmap)).isTrue();
// Scale height only.
bitmap = Bitmap.createBitmap(info.width, (int) (info.height * scale_factor), config);
assertThat(bitmap).isNotNull();
assertThat(AvifDecoder.decode(buffer, buffer.remaining(), bitmap)).isTrue();
}
}
}

Expand Down Expand Up @@ -225,8 +228,9 @@ public void testDecodeRegularClass() throws IOException {
assertThat(decoder.nthFrame(image.frameCount, bitmap)).isNotEqualTo(AVIF_RESULT_OK);

// The following block of code that tests scaling assumes that the animated image under test
// has at least 10 frames.
if (image.frameCount >= 10) {
// has at least 7 frames. These tests can be a bit slow on emulators, so only run them when
// config is ARGB_8888.
if (image.frameCount >= 7 && config == Config.ARGB_8888) {
// Reset the decoder to the first frame.
assertThat(decoder.nthFrame(0, bitmap)).isEqualTo(AVIF_RESULT_OK);
for (float scale_factor : SCALE_FACTORS) {
Expand Down

0 comments on commit 1809d89

Please sign in to comment.