Skip to content

Commit

Permalink
Fix broken DownsamplerEmulatorTest due to class-not-found regression
Browse files Browse the repository at this point in the history
  • Loading branch information
falhassen committed Feb 2, 2024
1 parent 8ca2db2 commit ed24370
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.Gainmap;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.util.DisplayMetrics;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.exifinterface.media.ExifInterface;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
Expand Down Expand Up @@ -481,8 +479,8 @@ private static String runScaleTest(
try {
if (VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE
&& (bitmap.getWidth() != expectedWidth
|| bitmap.getHeight() != expectedHeight
|| bitmap.hasGainmap() != hasGainmap)) {
|| bitmap.getHeight() != expectedHeight
|| bitmap.hasGainmap() != hasGainmap)) {
return "API: "
+ Build.VERSION.SDK_INT
+ ", os: "
Expand All @@ -506,7 +504,7 @@ private static String runScaleTest(
+ readableDimensAndHasGainmap(expectedWidth, expectedHeight, hasGainmap)
+ ", but Received "
+ readableDimensAndHasGainmap(
bitmap.getWidth(), bitmap.getHeight(), bitmap.hasGainmap());
bitmap.getWidth(), bitmap.getHeight(), bitmap.hasGainmap());
} else if (bitmap.getWidth() != expectedWidth || bitmap.getHeight() != expectedHeight) {
return "API: "
+ Build.VERSION.SDK_INT
Expand Down Expand Up @@ -600,7 +598,11 @@ private static InputStream openFileStream(

Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
if (hasGainmap && VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE) {
bitmap.setGainmap(createGainmap(width / 2, height / 2));
bitmap.setGainmap(
// Intentionally not directly imported due to test failures with class resolution when
// running on SDK levels < 34. Also, do not extract methods with Gainmap in the method
// signature for the same reason.
new android.graphics.Gainmap(Bitmap.createBitmap(width / 2, height / 2, Config.ALPHA_8)));
}

OutputStream os = null;
Expand Down Expand Up @@ -640,7 +642,11 @@ private static InputStream openInMemoryStream(
CompressFormat format, int width, int height, boolean hasGainmap) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
if (hasGainmap && VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE) {
bitmap.setGainmap(createGainmap(width / 2, height / 2));
// Intentionally not directly imported due to test failures with class resolution when
// running on SDK levels < 34. Also, do not extract methods with Gainmap in the method
// signature for the same reason.
bitmap.setGainmap(
new android.graphics.Gainmap(Bitmap.createBitmap(width / 2, height / 2, Config.ALPHA_8)));
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
bitmap.compress(format, 100 /*quality*/, os);
Expand All @@ -649,11 +655,6 @@ private static InputStream openInMemoryStream(
return new ByteArrayInputStream(data);
}

@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
private static Gainmap createGainmap(int width, int height) {
return new Gainmap(Bitmap.createBitmap(width, height, Config.ALPHA_8));
}

static final class Tester {
private final DownsampleStrategy strategy;
private final List<TestCase> testCases = new ArrayList<>();
Expand Down Expand Up @@ -900,15 +901,15 @@ static final class Formats {
private final CompressFormat[] formats;
private static final int[] ALL_EXIF_ORIENTATIONS =
new int[] {
ExifInterface.ORIENTATION_UNDEFINED,
ExifInterface.ORIENTATION_NORMAL,
ExifInterface.ORIENTATION_FLIP_HORIZONTAL,
ExifInterface.ORIENTATION_ROTATE_180,
ExifInterface.ORIENTATION_FLIP_VERTICAL,
ExifInterface.ORIENTATION_TRANSPOSE,
ExifInterface.ORIENTATION_ROTATE_90,
ExifInterface.ORIENTATION_TRANSVERSE,
ExifInterface.ORIENTATION_ROTATE_270
ExifInterface.ORIENTATION_UNDEFINED,
ExifInterface.ORIENTATION_NORMAL,
ExifInterface.ORIENTATION_FLIP_HORIZONTAL,
ExifInterface.ORIENTATION_ROTATE_180,
ExifInterface.ORIENTATION_FLIP_VERTICAL,
ExifInterface.ORIENTATION_TRANSPOSE,
ExifInterface.ORIENTATION_ROTATE_90,
ExifInterface.ORIENTATION_TRANSVERSE,
ExifInterface.ORIENTATION_ROTATE_270
};
private static final int[] UNDEFINED_EXIF_ORIENTATIONS =
new int[] {ExifInterface.ORIENTATION_UNDEFINED};
Expand Down

0 comments on commit ed24370

Please sign in to comment.