diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AdvancedFrameProcessorPixelTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AdvancedFrameProcessorPixelTest.java
index e0bd109ce9..c2d44ba5ef 100644
--- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AdvancedFrameProcessorPixelTest.java
+++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/AdvancedFrameProcessorPixelTest.java
@@ -98,8 +98,8 @@ public final class AdvancedFrameProcessorPixelTest {
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -120,8 +120,8 @@ public final class AdvancedFrameProcessorPixelTest {
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -142,8 +142,8 @@ public final class AdvancedFrameProcessorPixelTest {
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -164,8 +164,8 @@ public final class AdvancedFrameProcessorPixelTest {
Bitmap actualBitmap =
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(width, height);
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/BitmapTestUtil.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/BitmapTestUtil.java
index 514b7d2c60..97cace4a37 100644
--- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/BitmapTestUtil.java
+++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/BitmapTestUtil.java
@@ -108,6 +108,8 @@ public class BitmapTestUtil {
* of pixels in the image. The bitmap resolutions must match and they must use configuration
* {@link Bitmap.Config#ARGB_8888}.
*
+ *
Tries to save a difference bitmap between expected and actual bitmaps.
+ *
* @param expected The expected {@link Bitmap}.
* @param actual The actual {@link Bitmap} produced by the test.
* @param testId The name of the test that produced the {@link Bitmap}, or {@code null} if the
@@ -148,41 +150,30 @@ public class BitmapTestUtil {
}
}
if (testId != null) {
- try {
- saveTestBitmapToCacheDirectory(
- testId, "diff", differencesBitmap, /* throwOnFailure= */ false);
- } catch (IOException impossible) {
- throw new IllegalStateException(impossible);
- }
+ maybeSaveTestBitmapToCacheDirectory(testId, "diff", differencesBitmap);
}
return (float) sumMaximumAbsoluteDifferences / (width * height);
}
/**
- * Saves the {@link Bitmap} to the {@link Context#getCacheDir() cache directory} as a PNG.
+ * Tries to save the {@link Bitmap} to the {@link Context#getCacheDir() cache directory} as a PNG.
*
- *
File name will be {@code _.png}. If {@code throwOnFailure} is {@code
- * false}, any {@link IOException} will be caught and logged.
+ * File name will be {@code _.png}. If the file failed to write, any
+ * {@link IOException} will be caught and logged.
*
* @param testId Name of the test that produced the {@link Bitmap}.
* @param bitmapLabel Label to identify the bitmap.
* @param bitmap The {@link Bitmap} to save.
- * @param throwOnFailure Whether to throw an exception if the bitmap can't be saved.
- * @throws IOException If the bitmap can't be saved and {@code throwOnFailure} is {@code true}.
*/
- public static void saveTestBitmapToCacheDirectory(
- String testId, String bitmapLabel, Bitmap bitmap, boolean throwOnFailure) throws IOException {
+ public static void maybeSaveTestBitmapToCacheDirectory(
+ String testId, String bitmapLabel, Bitmap bitmap) {
File file =
new File(
getApplicationContext().getExternalCacheDir(), testId + "_" + bitmapLabel + ".png");
try (FileOutputStream outputStream = new FileOutputStream(file)) {
bitmap.compress(Bitmap.CompressFormat.PNG, /* quality= */ 100, outputStream);
} catch (IOException e) {
- if (throwOnFailure) {
- throw e;
- } else {
- Log.e(TAG, "Could not write Bitmap to file path: " + file.getAbsolutePath(), e);
- }
+ Log.e(TAG, "Could not write Bitmap to file path: " + file.getAbsolutePath(), e);
}
}
diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java
index b8cfb3c8c8..a22b2a0b7c 100644
--- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java
+++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/FrameProcessorChainPixelTest.java
@@ -95,8 +95,8 @@ public final class FrameProcessorChainPixelTest {
Bitmap actualBitmap = processFirstFrameAndEnd();
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -116,8 +116,8 @@ public final class FrameProcessorChainPixelTest {
Bitmap actualBitmap = processFirstFrameAndEnd();
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -140,8 +140,8 @@ public final class FrameProcessorChainPixelTest {
Bitmap actualBitmap = processFirstFrameAndEnd();
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -164,8 +164,8 @@ public final class FrameProcessorChainPixelTest {
Bitmap actualBitmap = processFirstFrameAndEnd();
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -184,8 +184,8 @@ public final class FrameProcessorChainPixelTest {
Bitmap actualBitmap = processFirstFrameAndEnd();
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -204,8 +204,8 @@ public final class FrameProcessorChainPixelTest {
Bitmap actualBitmap = processFirstFrameAndEnd();
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/PresentationFrameProcessorPixelTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/PresentationFrameProcessorPixelTest.java
index 3425ca1d7e..b1faa05ccc 100644
--- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/PresentationFrameProcessorPixelTest.java
+++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/PresentationFrameProcessorPixelTest.java
@@ -109,8 +109,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -136,8 +136,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -163,8 +163,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -192,8 +192,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -221,8 +221,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -250,8 +250,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -279,8 +279,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -308,8 +308,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
@@ -337,8 +337,8 @@ public final class PresentationFrameProcessorPixelTest {
BitmapTestUtil.createArgb8888BitmapFromCurrentGlFramebuffer(
outputSize.getWidth(), outputSize.getHeight());
- BitmapTestUtil.saveTestBitmapToCacheDirectory(
- testId, /* bitmapLabel= */ "actual", actualBitmap, /* throwOnFailure= */ false);
+ BitmapTestUtil.maybeSaveTestBitmapToCacheDirectory(
+ testId, /* bitmapLabel= */ "actual", actualBitmap);
// TODO(b/207848601): switch to using proper tooling for testing against golden data.
float averagePixelAbsoluteDifference =
BitmapTestUtil.getAveragePixelAbsoluteDifferenceArgb8888(
diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java
index 33e9e6347e..497247daf0 100644
--- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java
+++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java
@@ -68,7 +68,7 @@ public class TransformationTest {
@Test
public void transformToSpecificBitrate() throws Exception {
- String testId = TAG + "_transformWithSpecificBitrate";
+ String testId = TAG + "_transformToSpecificBitrate";
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer =
new Transformer.Builder(context)